import { DocumentListComponent , ShareDataRow } from '@alfresco/adf-content-services' ; import { ShowHeaderMode } from '@alfresco/adf-core' ; import { ContentActionRef , DocumentListPresetRef , SelectionState } from '@alfresco/adf-extensions' ; import { OnDestroy , OnInit , OnChanges , ViewChild , SimpleChanges , Directive } from '@angular/core' ; import { Store } from '@ngrx/store' ; import { MinimalNodeEntity , MinimalNodeEntryEntity , NodePaging } from '@alfresco/js-api' ; import { Observable , Subject , Subscription } from 'rxjs' ; import { takeUntil , map } from 'rxjs/operators' ; import { ContentManagementService } from '../services/content-management.service' ; import { AppStore , ReloadDocumentListAction , getCurrentFolder , getAppSelection , getDocumentDisplayMode , isInfoDrawerOpened , getSharedUrl , ViewNodeAction , ViewNodeExtras , SetSelectedNodesAction } from '@alfresco/aca-shared/store' ; import { isLocked , isLibrary , AppExtensionService } from '@alfresco/aca-shared' ; @ Directive ( ) export abstract class PageComponent implements OnInit , OnDestroy , OnChanges { onDestroy$ : Subject < boolean > = new Subject < boolean > ( ) ; @ ViewChild ( DocumentListComponent ) documentList : DocumentListComponent ; title = 'Page' ; infoDrawerOpened$ : Observable < boolean > ; node : MinimalNodeEntryEntity ; selection : SelectionState ; documentDisplayMode$ : Observable < string > ; sharedPreviewUrl$ : Observable < string > ; actions : Array < ContentActionRef > = [ ] ; viewerToolbarActions : Array < ContentActionRef > = [ ] ; canUpdateNode = false ; canUpload = false ; nodeResult : NodePaging ; showHeader = ShowHeaderMode . Data ; filterSorting = 'name-asc' ; protected subscriptions : Subscription [ ] = [ ] ; protected constructor ( protected store , protected extensions , protected content ) { } ngOnInit ( ) { this . sharedPreviewUrl$ = this . store . select ( getSharedUrl ) ; this . infoDrawerOpened$ = this . store . select ( isInfoDrawerOpened ) . pipe ( map ( ( infoDrawerState ) => { return ! this . isOutletPreviewUrl ( ) && infoDrawerState ; } ) ) ; this . documentDisplayMode$ = this . store . select ( getDocumentDisplayMode ) ; this . store . select ( getAppSelection ) . pipe ( takeUntil ( this . onDestroy$ ) ) . subscribe ( ( selection ) => { this . selection = selection ; this . canUpdateNode = this . selection . count === 1 && this . content . canUpdateNode ( selection . first ) ; } ) ; this . extensions . getAllowedToolbarActions ( ) . pipe ( takeUntil ( this . onDestroy$ ) ) . subscribe ( ( actions ) => { this . actions = actions ; } ) ; this . extensions . getViewerToolbarActions ( ) . pipe ( takeUntil ( this . onDestroy$ ) ) . subscribe ( ( actions ) => { this . viewerToolbarActions = actions ; } ) ; this . store . select ( getCurrentFolder ) . pipe ( takeUntil ( this . onDestroy$ ) ) . subscribe ( ( node ) => { this . canUpload = node && this . content . canUploadContent ( node ) ; } ) ; } ngOnChanges ( changes ) { if ( changes . nodeResult && changes . nodeResult . currentValue ) { this . nodeResult = changes . nodeResult . currentValue ; } } ngOnDestroy ( ) { this . subscriptions . forEach ( ( subscription ) => subscription . unsubscribe ( ) ) ; this . subscriptions = [ ] ; this . onDestroy$ . next ( true ) ; this . onDestroy$ . complete ( ) ; this . store . dispatch ( new SetSelectedNodesAction ( [ ] ) ) ; } showPreview ( node , extras ? ) { if ( node && node . entry ) { let id ; if ( node . entry . nodeType === 'app:filelink' ) { id = node . entry . properties [ 'cm:destination' ] ; } else { id = ( node as any ) . entry . nodeId || ( node as any ) . entry . guid || node . entry . id ; } this . store . dispatch ( new ViewNodeAction ( id , extras ) ) ; } } getParentNodeId ( ) { return this . node ? this . node . id : null ; } imageResolver ( row ) { if ( isLocked ( row . node ) ) { return 'assets/images/baseline-lock-24px.svg' ; } if ( isLibrary ( row . node ) ) { return 'assets/images/baseline-library_books-24px.svg' ; } return null ; } reload ( selectedNode ? ) { if ( this . isOutletPreviewUrl ( ) ) { return ; } this . store . dispatch ( new ReloadDocumentListAction ( ) ) ; if ( selectedNode ) { this . store . dispatch ( new SetSelectedNodesAction ( [ selectedNode ] ) ) ; } } trackByActionId ( _ , action ) { return action . id ; } trackById ( _ , obj ) { return obj . id ; } trackByColumnId ( _ , obj ) { return obj . id ; } private isOutletPreviewUrl ( ) { return location . href . includes ( 'viewer:view' ) ; } onSortingChanged ( event ) { this . filterSorting = event . detail . key + '-' + event . detail . direction ; } onAllFilterCleared ( ) { if ( ! this . isOutletPreviewUrl ( ) ) { this . documentList . node = null ; this . store . dispatch ( new ReloadDocumentListAction ( ) ) ; } } }