All files / app/directive title.directive.ts

70.37% Statements 19/27
44.82% Branches 13/29
100% Functions 3/3
69.56% Lines 16/23

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 5776x     76x   76x 76x         76x               3x 3x       2x       2x 2x 2x 2x   2x             2x     2x                 2x        
import { Directive, ElementRef, Input, OnChanges, SimpleChanges } from '@angular/core';
import { isArray, isString, uniq } from 'lodash-es';
import { Ext } from '../model/ext';
import { getPluginScope } from '../model/plugin';
import { Ref } from '../model/ref';
import { hydrate, Visibility } from '../model/tag';
import { getTemplateScope } from '../model/template';
import { TagPreview } from '../service/editor.service';
import { Store } from '../store/store';
 
@Directive({ selector: '[appTitle]' })
export class TitleDirective implements OnChanges {
 
  @Input('appTitle')
  node?: Visibility | Visibility[] | Ext | string | TagPreview;
  @Input()
  ref?: Ref;
 
  constructor(
    private store: Store,
    private el: ElementRef,
  ) { }
 
  ngOnChanges(changes: SimpleChanges) {
    this.render();
  }
 
  render(): void {
    Iif (!this.node) return;
    const title: string[] = [];
    for (const n of isArray(this.node) ? this.node : [this.node]) {
      Iif (isString(n)) {
        title.push(n);
      I} else if ('type' in n && n.type === 'ext') {
        const ctx = getTemplateScope(this.store.account, null!, n);
        title.push(
          n.config?.popover
          ? hydrate(n.config, 'popover', ctx)
          : ''
        );
      I} else if ('title' in n) {
        const ctx = getPluginScope(n._parent, this.ref)
        title.push(hydrate(n, 'title', ctx));
      I} else if ('_parent' in n && n._parent) {
        const ctx = getPluginScope(n._parent, this.ref)
        title.push(
          n._parent.config?.description
          ? hydrate(n._parent.config, 'description', ctx)
          : ''
        );
      }
    }
    this.el.nativeElement.title = uniq(title).join($localize` / `);
  }
 
}