mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
#9 'Delete' action support for document nodes
This commit is contained in:
@@ -73,6 +73,12 @@
|
|||||||
title="{{'DOCUMENT_LIST.ACTIONS.DOCUMENT.CUSTOM' | translate}}"
|
title="{{'DOCUMENT_LIST.ACTIONS.DOCUMENT.CUSTOM' | translate}}"
|
||||||
(execute)="myCustomAction1($event)">
|
(execute)="myCustomAction1($event)">
|
||||||
</content-action>
|
</content-action>
|
||||||
|
<content-action
|
||||||
|
target="document"
|
||||||
|
type="menu"
|
||||||
|
title="{{'DOCUMENT_LIST.ACTIONS.DOCUMENT.DELETE' | translate}}"
|
||||||
|
handler="delete">
|
||||||
|
</content-action>
|
||||||
</content-actions>
|
</content-actions>
|
||||||
</alfresco-document-list>
|
</alfresco-document-list>
|
||||||
</alfresco-upload-drag-area>
|
</alfresco-upload-drag-area>
|
||||||
|
@@ -14,6 +14,7 @@
|
|||||||
},
|
},
|
||||||
"DOCUMENT": {
|
"DOCUMENT": {
|
||||||
"DOWNLOAD": "Download",
|
"DOWNLOAD": "Download",
|
||||||
|
"DELETE": "Delete",
|
||||||
"SYSTEM_2": "System document action 2",
|
"SYSTEM_2": "System document action 2",
|
||||||
"CUSTOM": "Custom action"
|
"CUSTOM": "Custom action"
|
||||||
}
|
}
|
||||||
|
@@ -194,6 +194,7 @@ All document actions with `type="menu"` are rendered as a dropdown menu as on th
|
|||||||
The following action handlers are provided out-of-box:
|
The following action handlers are provided out-of-box:
|
||||||
|
|
||||||
- Download
|
- Download
|
||||||
|
- Delete
|
||||||
|
|
||||||
All system handler names are case-insensitive, `handler="download"` and `handler="DOWNLOAD"`
|
All system handler names are case-insensitive, `handler="download"` and `handler="DOWNLOAD"`
|
||||||
will trigger the same `download` action.
|
will trigger the same `download` action.
|
||||||
|
@@ -106,6 +106,12 @@ import {
|
|||||||
title="{{'DOCUMENT_LIST.ACTIONS.DOCUMENT.CUSTOM' | translate}}"
|
title="{{'DOCUMENT_LIST.ACTIONS.DOCUMENT.CUSTOM' | translate}}"
|
||||||
(execute)="myCustomAction1($event)">
|
(execute)="myCustomAction1($event)">
|
||||||
</content-action>
|
</content-action>
|
||||||
|
<content-action
|
||||||
|
target="document"
|
||||||
|
type="menu"
|
||||||
|
title="{{'DOCUMENT_LIST.ACTIONS.DOCUMENT.DELETE' | translate}}"
|
||||||
|
handler="delete">
|
||||||
|
</content-action>
|
||||||
</content-actions>
|
</content-actions>
|
||||||
</alfresco-document-list>
|
</alfresco-document-list>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -14,16 +14,14 @@ System.config({
|
|||||||
format: 'register',
|
format: 'register',
|
||||||
map: Object.keys(window.__karma__.files).filter(onlyAppFiles).reduce(createPathRecords, {})
|
map: Object.keys(window.__karma__.files).filter(onlyAppFiles).reduce(createPathRecords, {})
|
||||||
},
|
},
|
||||||
'ng2-alfresco-core/dist': {
|
'ng2-alfresco-core/dist': { defaultExtension: 'js' },
|
||||||
defaultExtension: 'js'
|
'rxjs': { defaultExtension: 'js' },
|
||||||
},
|
'ng2-translate': { defaultExtension: 'js' }
|
||||||
'rxjs': {
|
|
||||||
defaultExtension: 'js'
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
map: {
|
map: {
|
||||||
'ng2-alfresco-core/dist': '/base/node_modules/ng2-alfresco-core/dist',
|
'ng2-alfresco-core/dist': '/base/node_modules/ng2-alfresco-core/dist',
|
||||||
'rxjs': '/base/node_modules/rxjs'
|
'rxjs': '/base/node_modules/rxjs',
|
||||||
|
'ng2-translate': '/base/node_modules/ng2-translate/bundles'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -17,6 +17,7 @@ module.exports = function (config) {
|
|||||||
{pattern: 'node_modules/angular2/bundles/http.dev.js', included: true, watched: true},
|
{pattern: 'node_modules/angular2/bundles/http.dev.js', included: true, watched: true},
|
||||||
{pattern: 'node_modules/alfresco-core-rest-api/bundle.js', included: true, watched: false},
|
{pattern: 'node_modules/alfresco-core-rest-api/bundle.js', included: true, watched: false},
|
||||||
{pattern: 'node_modules/ng2-alfresco-core/dist/**/*.js', included: false, served: true, watched: false},
|
{pattern: 'node_modules/ng2-alfresco-core/dist/**/*.js', included: false, served: true, watched: false},
|
||||||
|
{pattern: 'node_modules/ng2-translate/bundles/ng2-translate.js', included: true, watched: false},
|
||||||
|
|
||||||
{pattern: 'karma-test-shim.js', included: true, watched: true},
|
{pattern: 'karma-test-shim.js', included: true, watched: true},
|
||||||
|
|
||||||
|
@@ -56,10 +56,9 @@
|
|||||||
"reflect-metadata": "0.1.2",
|
"reflect-metadata": "0.1.2",
|
||||||
"rxjs": "5.0.0-beta.2",
|
"rxjs": "5.0.0-beta.2",
|
||||||
"systemjs": "0.19.26",
|
"systemjs": "0.19.26",
|
||||||
"zone.js": "^0.6.12"
|
"zone.js": "^0.6.12",
|
||||||
},
|
"alfresco-core-rest-api": "^0.1.0",
|
||||||
"peerDependencies": {
|
"ng2-translate": "^1.11.3"
|
||||||
"angular2": "2.0.0-beta.15"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"copyfiles": "^0.2.1",
|
"copyfiles": "^0.2.1",
|
||||||
|
@@ -15,7 +15,6 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {Http} from 'angular2/http';
|
|
||||||
import {Observable} from 'rxjs/Observable';
|
import {Observable} from 'rxjs/Observable';
|
||||||
import {AlfrescoService} from '../../src/services/alfresco.service';
|
import {AlfrescoService} from '../../src/services/alfresco.service';
|
||||||
import {AlfrescoSettingsService} from 'ng2-alfresco-core/dist/ng2-alfresco-core';
|
import {AlfrescoSettingsService} from 'ng2-alfresco-core/dist/ng2-alfresco-core';
|
||||||
@@ -25,10 +24,9 @@ export class AlfrescoServiceMock extends AlfrescoService {
|
|||||||
_folderToReturn: any = {};
|
_folderToReturn: any = {};
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
http: Http = null,
|
|
||||||
settings: AlfrescoSettingsService = null
|
settings: AlfrescoSettingsService = null
|
||||||
) {
|
) {
|
||||||
super(http, settings);
|
super(settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
getFolder(folder: string) {
|
getFolder(folder: string) {
|
||||||
|
@@ -247,7 +247,7 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit
|
|||||||
*/
|
*/
|
||||||
executeContentAction(node: MinimalNodeEntity, action: ContentActionModel) {
|
executeContentAction(node: MinimalNodeEntity, action: ContentActionModel) {
|
||||||
if (action) {
|
if (action) {
|
||||||
action.handler(node);
|
action.handler(node, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -34,5 +34,5 @@ export class ContentActionModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface ContentActionHandler {
|
export interface ContentActionHandler {
|
||||||
(obj: any): any;
|
(obj: any, target?: any): any;
|
||||||
}
|
}
|
||||||
|
@@ -16,7 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { Injectable } from 'angular2/core';
|
import { Injectable } from 'angular2/core';
|
||||||
import { Http, Response } from 'angular2/http';
|
import { Response } from 'angular2/http';
|
||||||
import { Observable } from 'rxjs/Rx';
|
import { Observable } from 'rxjs/Rx';
|
||||||
import { NodePaging, MinimalNodeEntity } from './../models/document-library.model';
|
import { NodePaging, MinimalNodeEntity } from './../models/document-library.model';
|
||||||
import { AlfrescoSettingsService } from 'ng2-alfresco-core/dist/ng2-alfresco-core';
|
import { AlfrescoSettingsService } from 'ng2-alfresco-core/dist/ng2-alfresco-core';
|
||||||
@@ -32,7 +32,6 @@ export class AlfrescoService {
|
|||||||
private _baseUrlPath: string = '/alfresco/api/-default-/public/alfresco/versions/1';
|
private _baseUrlPath: string = '/alfresco/api/-default-/public/alfresco/versions/1';
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private http: Http,
|
|
||||||
private settings: AlfrescoSettingsService) {
|
private settings: AlfrescoSettingsService) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,6 +70,13 @@ export class AlfrescoService {
|
|||||||
return apiInstance.getNodeChildren(nodeId, opts);
|
return apiInstance.getNodeChildren(nodeId, opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
deleteNode(nodeId: string) {
|
||||||
|
let client = this.getAlfrescoClient();
|
||||||
|
let nodesApi = new AlfrescoApi.NodesApi(client);
|
||||||
|
let opts = {};
|
||||||
|
return Observable.fromPromise(nodesApi.deleteNode(nodeId, opts));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the folder node with the content.
|
* Gets the folder node with the content.
|
||||||
* @param folder Path to folder.
|
* @param folder Path to folder.
|
||||||
|
@@ -42,24 +42,31 @@ export class DocumentActionsService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
canExecuteAction(obj: any): boolean {
|
||||||
|
return this._alfrescoService && obj && !obj.isFolder;
|
||||||
|
}
|
||||||
|
|
||||||
private setupActionHandlers() {
|
private setupActionHandlers() {
|
||||||
this.handlers['download'] = this.download.bind(this);
|
this.handlers['download'] = this.download.bind(this);
|
||||||
|
this.handlers['delete'] = this.deleteNode.bind(this);
|
||||||
|
|
||||||
// todo: just for dev/demo purposes, to be replaced with real actions
|
// TODO: for demo purposes only, will be removed during future revisions
|
||||||
this.handlers['system1'] = this.handleStandardAction1.bind(this);
|
this.handlers['system1'] = this.handleStandardAction1.bind(this);
|
||||||
this.handlers['system2'] = this.handleStandardAction2.bind(this);
|
this.handlers['system2'] = this.handleStandardAction2.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: for demo purposes only, will be removed during future revisions
|
||||||
private handleStandardAction1(obj: any) {
|
private handleStandardAction1(obj: any) {
|
||||||
window.alert('standard document action 1');
|
window.alert('standard document action 1');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: for demo purposes only, will be removed during future revisions
|
||||||
private handleStandardAction2(obj: any) {
|
private handleStandardAction2(obj: any) {
|
||||||
window.alert('standard document action 2');
|
window.alert('standard document action 2');
|
||||||
}
|
}
|
||||||
|
|
||||||
private download(obj: any) {
|
private download(obj: any) {
|
||||||
if (this._alfrescoService && obj && !obj.isFolder) {
|
if (this.canExecuteAction(obj)) {
|
||||||
let link = document.createElement('a');
|
let link = document.createElement('a');
|
||||||
document.body.appendChild(link);
|
document.body.appendChild(link);
|
||||||
link.setAttribute('download', 'download');
|
link.setAttribute('download', 'download');
|
||||||
@@ -68,4 +75,14 @@ export class DocumentActionsService {
|
|||||||
document.body.removeChild(link);
|
document.body.removeChild(link);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private deleteNode(obj: any, target?: any) {
|
||||||
|
if (this.canExecuteAction(obj) && obj.entry && obj.entry.id) {
|
||||||
|
this._alfrescoService.deleteNode(obj.entry.id).subscribe(() => {
|
||||||
|
if (target && typeof target.reload === 'function') {
|
||||||
|
target.reload();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user