Denys Vuika 9dcdacce40 [ACA-1552] extensibility support for document lists (#714)
* dynamic column component

* dynamic columns for files

* support conditional rendering

* libraries preset

* shared files preset

* recent files preset

* favorites preset

* trashcan preset

* load presets from the extension config

* code fixes
2018-10-14 10:21:58 +03:00

107 lines
2.9 KiB
TypeScript

/*!
* @license
* Alfresco Example Content Application
*
* Copyright (C) 2005 - 2018 Alfresco Software Limited
*
* This file is part of the Alfresco Example Content Application.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
import {
Component,
Input,
OnInit,
OnDestroy,
ViewChild,
ViewContainerRef,
ComponentRef,
ComponentFactoryResolver,
OnChanges,
SimpleChanges,
ViewEncapsulation,
ChangeDetectionStrategy
} from '@angular/core';
import { ExtensionService } from '@alfresco/adf-extensions';
@Component({
selector: 'app-dynamic-column',
template: `<ng-container #content></ng-container>`,
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
host: { class: 'app-dynamic-column' },
styles: [
`
.app-dynamic-column {
display: flex;
align-items: center;
}
`
]
})
export class DynamicColumnComponent implements OnInit, OnChanges, OnDestroy {
@ViewChild('content', { read: ViewContainerRef })
content: ViewContainerRef;
@Input()
id: string;
@Input()
context: any;
private componentRef: ComponentRef<any>;
constructor(
private extensions: ExtensionService,
private componentFactoryResolver: ComponentFactoryResolver
) {}
ngOnInit() {
const componentType = this.extensions.getComponentById(this.id);
if (componentType) {
const factory = this.componentFactoryResolver.resolveComponentFactory(
componentType
);
if (factory) {
this.content.clear();
this.componentRef = this.content.createComponent(factory, 0);
this.updateInstance();
}
}
}
ngOnChanges(changes: SimpleChanges) {
if (changes.node) {
this.updateInstance();
}
}
ngOnDestroy() {
if (this.componentRef) {
this.componentRef.destroy();
this.componentRef = null;
}
}
private updateInstance() {
if (this.componentRef && this.componentRef.instance) {
this.componentRef.instance.context = this.context;
}
}
}