mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
[ADF-1041] Node picker, first iteration (#2122)
* First try * Dialog basic functionality * Search input * Hammering it together * Fist working proto for copy * Fix the tests and tslint errors for a happier world * Add more tests (and test shells for the future) * copyNode and moveNode methods * Copy and move actions for content type * Extract common parts in favor of using them in folder content type also * Small fixes * Copy and Move actions for folders as well * Style fixes, ui behaviours and tests needed to be written * Move duplicated search service from documentlist to core * Use search service from core within the search component * Fix dialog width * Update docs * Tests for node selector * Change seletionMade event's name to select
This commit is contained in:
committed by
Eugenio Romano
parent
952da3ab99
commit
4fd8bfb875
@@ -16,12 +16,15 @@
|
||||
*/
|
||||
|
||||
import { Injectable } from '@angular/core';
|
||||
import { AlfrescoContentService } from 'ng2-alfresco-core';
|
||||
import { MinimalNodeEntity } from 'alfresco-js-api';
|
||||
import { AlfrescoContentService, AlfrescoTranslationService, NotificationService } from 'ng2-alfresco-core';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import { Subject } from 'rxjs/Rx';
|
||||
import { ContentNodeSelectorComponent } from '../components/content-node-selector/content-node-selector.component';
|
||||
import { ContentActionHandler } from '../models/content-action.model';
|
||||
import { PermissionModel } from '../models/permissions.model';
|
||||
import { DocumentListService } from './document-list.service';
|
||||
import { NodeActionsService } from './node-actions.service';
|
||||
|
||||
@Injectable()
|
||||
export class DocumentActionsService {
|
||||
@@ -30,9 +33,15 @@ export class DocumentActionsService {
|
||||
|
||||
private handlers: { [id: string]: ContentActionHandler; } = {};
|
||||
|
||||
constructor(private documentListService?: DocumentListService,
|
||||
constructor(private translateService: AlfrescoTranslationService,
|
||||
private notificationService: NotificationService,
|
||||
private nodeActionsService: NodeActionsService,
|
||||
private documentListService?: DocumentListService,
|
||||
private contentService?: AlfrescoContentService) {
|
||||
this.setupActionHandlers();
|
||||
if (translateService) {
|
||||
translateService.addTranslationFolder('ng2-alfresco-documentlist', 'assets/ng2-alfresco-documentlist');
|
||||
}
|
||||
}
|
||||
|
||||
getHandler(key: string): ContentActionHandler {
|
||||
@@ -58,35 +67,9 @@ export class DocumentActionsService {
|
||||
|
||||
private setupActionHandlers() {
|
||||
this.handlers['download'] = this.download.bind(this);
|
||||
this.handlers['copy'] = this.copyNode.bind(this);
|
||||
this.handlers['move'] = this.moveNode.bind(this);
|
||||
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
|
||||
/**
|
||||
* @deprecated in 1.7.0
|
||||
*
|
||||
* @private
|
||||
* @memberof DocumentActionsService
|
||||
*/
|
||||
private handleStandardAction1(/*obj: any*/) {
|
||||
console.log('handleStandardAction1 is deprecated in 1.7.0 and will be removed in future versions');
|
||||
window.alert('standard document action 1');
|
||||
}
|
||||
|
||||
// TODO: for demo purposes only, will be removed during future revisions
|
||||
/**
|
||||
* @deprecated in 1.7.0
|
||||
*
|
||||
* @private
|
||||
* @memberof DocumentActionsService
|
||||
*/
|
||||
private handleStandardAction2(/*obj: any*/) {
|
||||
console.log('handleStandardAction2 is deprecated in 1.7.0 and will be removed in future versions');
|
||||
window.alert('standard document action 2');
|
||||
}
|
||||
|
||||
private download(obj: any): Observable<boolean> {
|
||||
@@ -102,6 +85,43 @@ export class DocumentActionsService {
|
||||
return Observable.of(false);
|
||||
}
|
||||
|
||||
private copyNode(obj: MinimalNodeEntity, target?: any, permission?: string) {
|
||||
const actionObservable = this.nodeActionsService.copyContent(obj.entry, permission);
|
||||
this.prepareHandlers(actionObservable, 'content', 'copy', target, permission);
|
||||
return actionObservable;
|
||||
}
|
||||
|
||||
private moveNode(obj: MinimalNodeEntity, target?: any, permission?: string) {
|
||||
const actionObservable = this.nodeActionsService.moveContent(obj.entry, permission);
|
||||
this.prepareHandlers(actionObservable, 'content', 'move', target, permission);
|
||||
return actionObservable;
|
||||
}
|
||||
|
||||
private prepareHandlers(actionObservable, type: string, action: string, target?: any, permission?: string): void {
|
||||
actionObservable.subscribe(
|
||||
(fileOperationMessage) => {
|
||||
this.notificationService.openSnackMessage(fileOperationMessage, 3000);
|
||||
if (target && typeof target.reload === 'function') {
|
||||
target.reload();
|
||||
}
|
||||
},
|
||||
(errorStatusCode) => {
|
||||
switch (errorStatusCode) {
|
||||
case 403:
|
||||
this.permissionEvent.next(new PermissionModel({type, action, permission}));
|
||||
break;
|
||||
case 409:
|
||||
let conflictError: any = this.translateService.get('OPERATION.ERROR.CONFLICT');
|
||||
this.notificationService.openSnackMessage(conflictError.value, 3000);
|
||||
break;
|
||||
default:
|
||||
let unknownError: any = this.translateService.get('OPERATION.ERROR.UNKNOWN');
|
||||
this.notificationService.openSnackMessage(unknownError.value, 3000);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private deleteNode(obj: any, target?: any, permission?: string): Observable<any> {
|
||||
let handlerObservable;
|
||||
|
||||
|
Reference in New Issue
Block a user