Denys Vuika fe683015c5
extensions: wave 2 (#497)
* introduce "create folder" action

* track opened folder via store

* "create folder" action, support mulitple targets

* fix card view colors and toolbar layouts

* basic support for permissions

* simplify create menu and add permissions

* add toolbar separators for extension entries

* "edit folder" extension command

* minor code improvements
2018-07-08 07:56:50 +01:00

164 lines
5.5 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 { DocumentListComponent, ShareDataRow } from '@alfresco/adf-content-services';
import { DisplayMode, FileUploadErrorEvent } from '@alfresco/adf-core';
import { OnDestroy, OnInit, ViewChild } from '@angular/core';
import { Store } from '@ngrx/store';
import { MinimalNodeEntity, MinimalNodeEntryEntity } from 'alfresco-js-api';
import { takeUntil } from 'rxjs/operators';
import { Subject, Subscription } from 'rxjs/Rx';
import { SnackbarErrorAction, ViewNodeAction, SetSelectedNodesAction } from '../store/actions';
import { appSelection, sharedUrl } from '../store/selectors/app.selectors';
import { AppStore } from '../store/states/app.state';
import { SelectionState } from '../store/states/selection.state';
import { Observable } from 'rxjs/Rx';
import { ExtensionService } from '../extensions/extension.service';
import { ContentActionExtension } from '../extensions/content-action.extension';
export abstract class PageComponent implements OnInit, OnDestroy {
onDestroy$: Subject<boolean> = new Subject<boolean>();
@ViewChild(DocumentListComponent)
documentList: DocumentListComponent;
title = 'Page';
infoDrawerOpened = false;
node: MinimalNodeEntryEntity;
selection: SelectionState;
displayMode = DisplayMode.List;
sharedPreviewUrl$: Observable<string>;
actions: Array<ContentActionExtension> = [];
protected subscriptions: Subscription[] = [];
static isLockedNode(node) {
return node.isLocked || (node.properties && node.properties['cm:lockType'] === 'READ_ONLY_LOCK');
}
constructor(
protected store: Store<AppStore>,
protected extensions: ExtensionService) {}
ngOnInit() {
this.sharedPreviewUrl$ = this.store.select(sharedUrl);
this.store
.select(appSelection)
.pipe(takeUntil(this.onDestroy$))
.subscribe(selection => {
this.selection = selection;
if (selection.isEmpty) {
this.infoDrawerOpened = false;
}
this.actions = this.extensions.getSelectedContentActions(selection, this.node);
});
}
ngOnDestroy() {
this.subscriptions.forEach(subscription => subscription.unsubscribe());
this.subscriptions = [];
this.onDestroy$.next(true);
this.onDestroy$.complete();
}
showPreview(node: MinimalNodeEntity) {
if (node && node.entry) {
const { id, nodeId, name, isFile, isFolder } = node.entry;
const parentId = this.node ? this.node.id : null;
this.store.dispatch(new ViewNodeAction({
parentId,
id: nodeId || id,
name,
isFile,
isFolder
}));
}
}
getParentNodeId(): string {
return this.node ? this.node.id : null;
}
imageResolver(row: ShareDataRow): string | null {
const entry: MinimalNodeEntryEntity = row.node.entry;
if (PageComponent.isLockedNode(entry)) {
return 'assets/images/ic_lock_black_24dp_1x.png';
}
return null;
}
toggleSidebar(event) {
if (event) {
return;
}
this.infoDrawerOpened = !this.infoDrawerOpened;
}
reload(): void {
if (this.documentList) {
this.documentList.resetSelection();
this.store.dispatch(new SetSelectedNodesAction([]));
this.documentList.reload();
}
}
onFileUploadedError(error: FileUploadErrorEvent) {
let message = 'APP.MESSAGES.UPLOAD.ERROR.GENERIC';
if (error.error.status === 409) {
message = 'APP.MESSAGES.UPLOAD.ERROR.CONFLICT';
}
if (error.error.status === 500) {
message = 'APP.MESSAGES.UPLOAD.ERROR.500';
}
const action = new SnackbarErrorAction(message);
this.store.dispatch(action);
}
toggleGalleryView(): void {
this.displayMode = this.displayMode === DisplayMode.List ? DisplayMode.Gallery : DisplayMode.List;
this.documentList.display = this.displayMode;
}
// this is where each application decides how to treat an action and what to do
// the ACA maps actions to the NgRx actions as an example
runAction(actionId: string) {
const context = {
selection: this.selection
};
this.extensions.runActionById(actionId, context);
}
}