mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-26 17:24:56 +00:00
* add codelyzer in core and datatable * add codelyzer in the main build * order imports * fix import in test * fix import test * import reorder form * tasklist and processlist import reorder
104 lines
3.6 KiB
TypeScript
104 lines
3.6 KiB
TypeScript
/*!
|
|
* @license
|
|
* Copyright 2016 Alfresco Software, Ltd.
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
import { Injectable } from '@angular/core';
|
|
import { Observable, Subject } from 'rxjs/Rx';
|
|
import { ContentActionHandler } from '../models/content-action.model';
|
|
import { PermissionModel } from '../models/permissions.model';
|
|
import { DocumentListService } from './document-list.service';
|
|
|
|
@Injectable()
|
|
export class FolderActionsService {
|
|
|
|
permissionEvent: Subject<PermissionModel> = new Subject<PermissionModel>();
|
|
|
|
private handlers: { [id: string]: ContentActionHandler; } = {};
|
|
|
|
constructor(private documentListService?: DocumentListService) {
|
|
this.setupActionHandlers();
|
|
}
|
|
|
|
getHandler(key: string): ContentActionHandler {
|
|
if (key) {
|
|
let lkey = key.toLowerCase();
|
|
return this.handlers[lkey] || null;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
setHandler(key: string, handler: ContentActionHandler): boolean {
|
|
if (key) {
|
|
let lkey = key.toLowerCase();
|
|
this.handlers[lkey] = handler;
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
canExecuteAction(obj: any): boolean {
|
|
return this.documentListService && obj && obj.entry.isFolder === true;
|
|
}
|
|
|
|
private setupActionHandlers() {
|
|
this.handlers['delete'] = this.deleteNode.bind(this);
|
|
|
|
// TODO: for demo purposes only, will be removed during future revisions
|
|
this.handlers['system1'] = this.handleStandardAction1.bind(this);
|
|
this.handlers['system2'] = this.handleStandardAction2.bind(this);
|
|
}
|
|
|
|
// TODO: for demo purposes only, will be removed during future revisions
|
|
private handleStandardAction1(document: any) {
|
|
window.alert('standard folder action 1');
|
|
}
|
|
|
|
// TODO: for demo purposes only, will be removed during future revisions
|
|
private handleStandardAction2(document: any) {
|
|
window.alert('standard folder action 2');
|
|
}
|
|
|
|
private deleteNode(obj: any, target?: any, permission?: string): Observable<any> {
|
|
let handlerObservale: Observable<any>;
|
|
|
|
if (this.canExecuteAction(obj)) {
|
|
if (this.hasPermission(obj.entry, permission)) {
|
|
handlerObservale = this.documentListService.deleteNode(obj.entry.id);
|
|
handlerObservale.subscribe(() => {
|
|
if (target && typeof target.reload === 'function') {
|
|
target.reload();
|
|
}
|
|
});
|
|
return handlerObservale;
|
|
} else {
|
|
this.permissionEvent.next(new PermissionModel({type: 'folder', action: 'delete', permission: permission}));
|
|
return Observable.throw(new Error('No permission to delete'));
|
|
}
|
|
}
|
|
}
|
|
|
|
private hasPermission(node: any, permissionToCheck: string): boolean {
|
|
if (this.hasPermissions(node)) {
|
|
return node.allowableOperations.find(permision => permision === permissionToCheck) ? true : false;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
private hasPermissions(node: any): boolean {
|
|
return node && node.allowableOperations ? true : false;
|
|
}
|
|
}
|