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
@@ -22,6 +22,7 @@ import { DocumentListService } from '../document-list/services/document-list.ser
|
||||
import { ContentNodeDialogService } from './content-node-dialog.service';
|
||||
import { MatDialog } from '@angular/material';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import { Subject } from 'rxjs/Subject';
|
||||
|
||||
const fakeNode: MinimalNodeEntryEntity = <MinimalNodeEntryEntity> {
|
||||
id: 'fake',
|
||||
@@ -56,6 +57,7 @@ describe('ContentNodeDialogService', () => {
|
||||
let sitesService: SitesService;
|
||||
let materialDialog: MatDialog;
|
||||
let spyOnDialogOpen: jasmine.Spy;
|
||||
let afterOpenObservable: Subject<any>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
@@ -66,6 +68,7 @@ describe('ContentNodeDialogService', () => {
|
||||
MatDialog
|
||||
]
|
||||
}).compileComponents();
|
||||
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -75,12 +78,29 @@ describe('ContentNodeDialogService', () => {
|
||||
service = TestBed.get(ContentNodeDialogService);
|
||||
documentListService = TestBed.get(DocumentListService);
|
||||
materialDialog = TestBed.get(MatDialog);
|
||||
sitesService = TestBed.get(SitesService);
|
||||
spyOnDialogOpen = spyOn(materialDialog, 'open').and.stub();
|
||||
spyOn(materialDialog, 'closeAll').and.stub();
|
||||
sitesService = TestBed.get(SitesService);
|
||||
afterOpenObservable = new Subject<any>();
|
||||
spyOnDialogOpen = spyOn(materialDialog, 'open').and.returnValue({
|
||||
afterOpen: () => afterOpenObservable,
|
||||
afterClosed: () => Observable.of({}),
|
||||
componentInstance: {
|
||||
error: new Subject<any>()
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
it('should not open the lock node dialog if have no permission', () => {
|
||||
const testNode: MinimalNodeEntryEntity = <MinimalNodeEntryEntity> {
|
||||
id: 'fake',
|
||||
isFile: false
|
||||
};
|
||||
|
||||
service.openLockNodeDialog(testNode).subscribe(() => {}, (error) => {
|
||||
expect(error).toBe('OPERATION.FAIL.NODE.NO_PERMISSION');
|
||||
});
|
||||
});
|
||||
|
||||
it('should be able to create the service', () => {
|
||||
expect(service).not.toBeNull();
|
||||
});
|
||||
@@ -123,6 +143,7 @@ describe('ContentNodeDialogService', () => {
|
||||
}));
|
||||
|
||||
it('should be able to close the material dialog', () => {
|
||||
spyOn(materialDialog, 'closeAll');
|
||||
service.close();
|
||||
expect(materialDialog.closeAll).toHaveBeenCalled();
|
||||
});
|
||||
|
@@ -16,20 +16,24 @@
|
||||
*/
|
||||
|
||||
import { MatDialog } from '@angular/material';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { EventEmitter, Injectable, Output } from '@angular/core';
|
||||
import { ContentService } from '@alfresco/adf-core';
|
||||
import { Subject } from 'rxjs/Subject';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import { ShareDataRow } from '../document-list/data/share-data-row.model';
|
||||
import { MinimalNodeEntryEntity, SitePaging } from 'alfresco-js-api';
|
||||
import { DataColumn, SitesService, TranslationService } from '@alfresco/adf-core';
|
||||
import { DataColumn, SitesService, TranslationService, PermissionsEnum } from '@alfresco/adf-core';
|
||||
import { DocumentListService } from '../document-list/services/document-list.service';
|
||||
import { ContentNodeSelectorComponent } from './content-node-selector.component';
|
||||
import { ContentNodeSelectorComponentData } from './content-node-selector.component-data.interface';
|
||||
import { NodeLockDialogComponent } from '../dialogs/node-lock.dialog';
|
||||
|
||||
@Injectable()
|
||||
export class ContentNodeDialogService {
|
||||
|
||||
@Output()
|
||||
error: EventEmitter<any> = new EventEmitter<any>();
|
||||
|
||||
constructor(private dialog: MatDialog,
|
||||
private contentService: ContentService,
|
||||
private documentListService: DocumentListService,
|
||||
@@ -45,6 +49,32 @@ export class ContentNodeDialogService {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens a lock node dialog
|
||||
*
|
||||
* @param contentEntry Node to lock
|
||||
*/
|
||||
public openLockNodeDialog(contentEntry: MinimalNodeEntryEntity): Subject<string> {
|
||||
const observable: Subject<string> = new Subject<string>();
|
||||
|
||||
if (this.contentService.hasPermission(contentEntry, PermissionsEnum.LOCK)) {
|
||||
this.dialog.open(NodeLockDialogComponent, {
|
||||
data: {
|
||||
node: contentEntry,
|
||||
onError: (error) => {
|
||||
this.error.emit(error);
|
||||
observable.error(error);
|
||||
}
|
||||
},
|
||||
width: '400px'
|
||||
});
|
||||
} else {
|
||||
observable.error('OPERATION.FAIL.NODE.NO_PERMISSION');
|
||||
}
|
||||
|
||||
return observable;
|
||||
}
|
||||
|
||||
/** Opens a file browser at a chosen site location. */
|
||||
openFileBrowseDialogBySite(): Observable<MinimalNodeEntryEntity[]> {
|
||||
return this.siteService.getSites().switchMap((response: SitePaging) => {
|
||||
|
Reference in New Issue
Block a user