All files / app/component/lens lens.component.ts

73.07% Statements 38/52
62.5% Branches 15/24
36.84% Functions 7/19
70.45% Lines 31/44

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 10867x                 67x 67x 67x 67x     67x 67x   67x 67x 67x             102x                         67x         2x   2x   2x   2x   2x   2x   2x       2x   2x   2x               2x 2x 2x               1x     1x         1x 1x         40x       5x            
import { Component, forwardRef, Input, OnChanges, QueryList, SimpleChanges, ViewChildren } from '@angular/core';
import { HasChanges } from '../../guard/pending-changes.guard';
import { Ext } from '../../model/ext';
import { Page } from '../../model/page';
import { Ref, RefSort } from '../../model/ref';
import { AccountService } from '../../service/account.service';
import { AdminService } from '../../service/admin.service';
import { QueryStore } from '../../store/query';
import { UrlFilter } from '../../util/query';
import { hasPrefix } from '../../util/tag';
import { BlogComponent } from '../blog/blog.component';
import { ChatComponent } from '../chat/chat.component';
import { FolderComponent } from '../folder/folder.component';
import { ForceDirectedComponent } from '../graph/force-directed/force-directed.component';
import { GridComponent } from '../grid/grid.component';
import { KanbanComponent } from '../kanban/kanban.component';
import { LoadingComponent } from '../loading/loading.component';
import { MapComponent } from '../map/map.component';
import { NotebookComponent } from '../notebook/notebook.component';
import { RefListComponent } from '../ref/ref-list/ref-list.component';
import { RefComponent } from '../ref/ref.component';
 
@Component({
  selector: 'app-lens',
  templateUrl: './lens.component.html',
  styleUrls: ['./lens.component.scss'],
  imports: [
    LoadingComponent,
    forwardRef(() => RefComponent),
    forwardRef(() => ForceDirectedComponent),
    forwardRef(() => BlogComponent),
    forwardRef(() => ChatComponent),
    forwardRef(() => FolderComponent),
    forwardRef(() => RefListComponent),
    forwardRef(() => KanbanComponent),
    forwardRef(() => NotebookComponent),
    forwardRef(() => GridComponent),
    forwardRef(() => MapComponent),
  ],
})
export class LensComponent implements OnChanges, HasChanges {
 
  @Input()
  ext?: Ext;
  @Input()
  tag = '';
  @Input()
  fullPage = false;
  @Input()
  cols? = 0;
  @Input()
  size = 24;
  @Input()
  sort: RefSort[] = [];
  @Input()
  filter: UrlFilter[] = [];
  @Input()
  search = '';
  @Input()
  page?: Page<Ref>;
  @Input()
  pageControls = true;
  @Input()
  showAlarm = true;
  @Input()
  showVotes = false;
 
  plugins?: string[];
 
  @ViewChildren('lens')
  list?: QueryList<HasChanges>;
 
  constructor(
    public admin: AdminService,
    public account: AccountService,
    public query: QueryStore,
  ) { }
 
  saveChanges() {
    return !this.list?.find(t => !t.saveChanges());
  }
 
  init() {
    Iif (hasPrefix(this.ext?.tag, 'plugin')) {
      this.plugins = [this.ext!.tag];
    } else {
      this.plugins = undefined;
    }
  }
 
  ngOnChanges(changes: SimpleChanges) {
    Eif (changes.ext) {
      this.init();
    }
  }
 
  isTemplate(template: string) {
    return this.admin.getTemplate(template) && hasPrefix(this.ext?.tag, template);
  }
 
  cssClass(tag?: string) {
    Eif (!tag) return '';
    return tag.replace(/\//g, '_')
      .replace(/\./g, '-')
      .replace(/[^\w-]/g, '');
  }
}