mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-2540] Lock node feature (#3138)
* add adf-node-lock directive * add lock-node service + button in context menu * unit tests * docs * unit tests fix * Remove unnecessary imports * PR changes * Remove fit from tests * Update specific node from list on lock/ulock
This commit is contained in:
committed by
Denys Vuika
parent
7b7e39d989
commit
7d1b4bf14a
@@ -60,8 +60,8 @@ describe('ContentAction', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
contentService = TestBed.get(ContentService);
|
||||
nodeActionsService = new NodeActionsService(null, null);
|
||||
documentActions = new DocumentActionsService(nodeActionsService);
|
||||
nodeActionsService = new NodeActionsService(null, null, null);
|
||||
documentActions = new DocumentActionsService(nodeActionsService, null);
|
||||
folderActions = new FolderActionsService(nodeActionsService, null, contentService);
|
||||
|
||||
documentList = (TestBed.createComponent(DocumentListComponent).componentInstance as DocumentListComponent);
|
||||
|
@@ -25,7 +25,8 @@ import {
|
||||
ObjectDataColumn,
|
||||
PaginatedComponent,
|
||||
PaginationQueryParams,
|
||||
PermissionsEnum
|
||||
PermissionsEnum,
|
||||
ContentService
|
||||
} from '@alfresco/adf-core';
|
||||
import {
|
||||
AlfrescoApiService,
|
||||
@@ -255,7 +256,8 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
|
||||
private elementRef: ElementRef,
|
||||
private apiService: AlfrescoApiService,
|
||||
private appConfig: AppConfigService,
|
||||
private preferences: UserPreferencesService) {
|
||||
private preferences: UserPreferencesService,
|
||||
private contentService?: ContentService) {
|
||||
this.maxItems = this.preferences.paginationSize;
|
||||
|
||||
this.pagination = new BehaviorSubject<Pagination>(<Pagination> {
|
||||
@@ -433,7 +435,7 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
|
||||
}
|
||||
|
||||
checkPermission(node: any, action: ContentActionModel): ContentActionModel {
|
||||
if (action.permission && action.permission !== PermissionsEnum.COPY) {
|
||||
if (action.permission && !~[PermissionsEnum.COPY, PermissionsEnum.LOCK].indexOf(action.permission)) {
|
||||
if (this.hasPermissions(node)) {
|
||||
let permissions = node.entry.allowableOperations;
|
||||
let findPermission = permissions.find(permission => permission === action.permission);
|
||||
@@ -442,6 +444,11 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (action.permission === PermissionsEnum.LOCK) {
|
||||
action.disabled = !this.contentService.hasPermission(node.entry, PermissionsEnum.LOCK);
|
||||
}
|
||||
|
||||
return action;
|
||||
}
|
||||
|
||||
|
@@ -39,13 +39,17 @@ describe('DocumentActionsService', () => {
|
||||
let alfrescoApiService = new AlfrescoApiServiceMock(new AppConfigService(null), new StorageService());
|
||||
documentListService = new DocumentListService(null, contentService, alfrescoApiService, null, null);
|
||||
|
||||
service = new DocumentActionsService(null, documentListService, contentService);
|
||||
service = new DocumentActionsService(null, null, documentListService, contentService);
|
||||
});
|
||||
|
||||
it('should register default download action', () => {
|
||||
expect(service.getHandler('download')).not.toBeNull();
|
||||
});
|
||||
|
||||
it('should register lock action', () => {
|
||||
expect(service.getHandler('lock')).toBeDefined();
|
||||
});
|
||||
|
||||
it('should register custom action handler', () => {
|
||||
let handler: ContentActionHandler = function (obj: any) {};
|
||||
service.setHandler('<key>', handler);
|
||||
@@ -71,7 +75,7 @@ describe('DocumentActionsService', () => {
|
||||
let file = new FileNode();
|
||||
expect(service.canExecuteAction(file)).toBeTruthy();
|
||||
|
||||
service = new DocumentActionsService(nodeActionsService);
|
||||
service = new DocumentActionsService(nodeActionsService, null);
|
||||
expect(service.canExecuteAction(file)).toBeFalsy();
|
||||
});
|
||||
|
||||
|
@@ -24,6 +24,7 @@ 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';
|
||||
import { ContentNodeDialogService } from '../../content-node-selector/content-node-dialog.service';
|
||||
import 'rxjs/add/observable/throw';
|
||||
|
||||
@Injectable()
|
||||
@@ -36,6 +37,7 @@ export class DocumentActionsService {
|
||||
private handlers: { [id: string]: ContentActionHandler; } = {};
|
||||
|
||||
constructor(private nodeActionsService: NodeActionsService,
|
||||
private contentNodeDialogService: ContentNodeDialogService,
|
||||
private documentListService?: DocumentListService,
|
||||
private contentService?: ContentService) {
|
||||
this.setupActionHandlers();
|
||||
@@ -83,6 +85,11 @@ export class DocumentActionsService {
|
||||
this.handlers['move'] = this.moveNode.bind(this);
|
||||
this.handlers['delete'] = this.deleteNode.bind(this);
|
||||
this.handlers['download'] = this.downloadNode.bind(this);
|
||||
this.handlers['lock'] = this.lockNode.bind(this);
|
||||
}
|
||||
|
||||
private lockNode(node: MinimalNodeEntity, target?: any, permission?: string) {
|
||||
return this.contentNodeDialogService.openLockNodeDialog(node.entry);
|
||||
}
|
||||
|
||||
private downloadNode(obj: MinimalNodeEntity, target?: any, permission?: string) {
|
||||
|
@@ -22,9 +22,12 @@ import { DocumentListService } from './document-list.service';
|
||||
import { NodeActionsService } from './node-actions.service';
|
||||
import { ContentNodeDialogService } from '../../content-node-selector/content-node-dialog.service';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import { MatDialogRef } from '@angular/material';
|
||||
import { NodeLockDialogComponent } from '../../dialogs/node-lock.dialog';
|
||||
import { BrowserDynamicTestingModule } from '@angular/platform-browser-dynamic/testing';
|
||||
|
||||
const fakeNode: MinimalNodeEntryEntity = <MinimalNodeEntryEntity> {
|
||||
id: 'fake'
|
||||
id: 'fake'
|
||||
};
|
||||
|
||||
describe('NodeActionsService', () => {
|
||||
@@ -32,15 +35,28 @@ describe('NodeActionsService', () => {
|
||||
let service: NodeActionsService;
|
||||
let documentListService: DocumentListService;
|
||||
let contentDialogService: ContentNodeDialogService;
|
||||
const dialogRef = {
|
||||
open: jasmine.createSpy('open')
|
||||
};
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [
|
||||
NodeLockDialogComponent
|
||||
],
|
||||
imports: [],
|
||||
providers: [
|
||||
NodeActionsService,
|
||||
DocumentListService,
|
||||
ContentNodeDialogService
|
||||
ContentNodeDialogService,
|
||||
{ provide: MatDialogRef, useValue: dialogRef }
|
||||
]
|
||||
});
|
||||
|
||||
TestBed.overrideModule(BrowserDynamicTestingModule, {
|
||||
set: { entryComponents: [ NodeLockDialogComponent ] }
|
||||
}).compileComponents();
|
||||
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
|
@@ -15,10 +15,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Injectable, Output, EventEmitter } from '@angular/core';
|
||||
import { MinimalNodeEntryEntity, MinimalNodeEntity } from 'alfresco-js-api';
|
||||
import { Subject } from 'rxjs/Subject';
|
||||
import { AlfrescoApiService } from '@alfresco/adf-core';
|
||||
import { AlfrescoApiService, ContentService } from '@alfresco/adf-core';
|
||||
import { MatDialog } from '@angular/material';
|
||||
|
||||
import { DocumentListService } from './document-list.service';
|
||||
@@ -28,7 +28,12 @@ import { NodeDownloadDirective } from '../../directives/node-download.directive'
|
||||
@Injectable()
|
||||
export class NodeActionsService {
|
||||
|
||||
@Output()
|
||||
error: EventEmitter<any> = new EventEmitter<any>();
|
||||
|
||||
constructor(private contentDialogService: ContentNodeDialogService,
|
||||
public dialogRef: MatDialog,
|
||||
public content: ContentService,
|
||||
private documentListService?: DocumentListService,
|
||||
private apiService?: AlfrescoApiService,
|
||||
private dialog?: MatDialog) {}
|
||||
|
Reference in New Issue
Block a user