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

72.54% Statements 37/51
77.77% Branches 14/18
36.84% Functions 7/19
71.73% Lines 33/46

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 108 109 110 111 112 113 114 11576x                   76x 76x 76x 76x     76x 76x   76x 76x 76x 76x               162x                             76x         4x   4x   4x   4x   4x   4x   4x       4x   4x   4x                 4x 4x 4x               1x 1x     1x         1x 1x         72x       9x            
import { Component, forwardRef, Input, OnChanges, QueryList, SimpleChanges, ViewChildren, ChangeDetectionStrategy } from '@angular/core';
import { MobxAngularModule } from 'mobx-angular';
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';
import { ViewerComponent } from '../viewer/viewer.component';
 
@Component({
  selector: 'app-lens',
  templateUrl: './lens.component.html',
  styleUrls: ['./lens.component.scss'],
  changeDetection: ChangeDetectionStrategy.Eager,
  imports: [
    MobxAngularModule,
    LoadingComponent,
    forwardRef(() => RefComponent),
    forwardRef(() => ForceDirectedComponent),
    forwardRef(() => BlogComponent),
    forwardRef(() => ChatComponent),
    forwardRef(() => FolderComponent),
    forwardRef(() => RefListComponent),
    forwardRef(() => KanbanComponent),
    forwardRef(() => NotebookComponent),
    forwardRef(() => GridComponent),
    forwardRef(() => MapComponent),
    ViewerComponent,
  ],
})
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[];
  header?: 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() {
    this.header = this.ext?.config?.header;
    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, '');
  }
}