import { Component , ViewEncapsulation , Input } from '@angular/core' ; import { Store } from '@ngrx/store' ; import { AppStore , ViewNodeAction , getAppSelection } from '@alfresco/aca-shared/store' ; import { Router } from '@angular/router' ; import { take } from 'rxjs/operators' ; import { SharedLinkEntry } from '@alfresco/js-api' ; @ Component ( { selector : 'app-view-node' , template : `
    <button
      *ngIf="data.iconButton"
      mat-icon-button
      [attr.aria-label]="data.title | translate"
      [attr.title]="data.title | translate"
      (click)="onClick()"
    >
      <mat-icon>visibility</mat-icon>
    </button>

    <button *ngIf="data.menuButton" mat-menu-item (click)="onClick()">
      <mat-icon>visibility</mat-icon>
      <span>{{ data.title | translate }}</span>
    </button>
  ` , encapsulation : ViewEncapsulation . None , host : { class : 'app-view-node' } } ) export class ViewNodeComponent { @ Input ( ) data : { title ? : string ; menuButton ? : boolean ; iconButton ? : boolean ; } ; constructor ( private store , private router ) { } onClick ( ) { this . store . select ( getAppSelection ) . pipe ( take ( 1 ) ) . subscribe ( ( selection ) => { let id ; if ( selection . file . entry . nodeType === 'app:filelink' ) { id = selection . file . entry . properties [ 'cm:destination' ] ; } else { id = ( selection . file as SharedLinkEntry ) . entry . nodeId || ( selection . file as any ) . entry . guid || selection . file . entry . id ; } this . store . dispatch ( new ViewNodeAction ( id , { location : this . router . url } ) ) ; } ) ; } }