mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
#340 Rename 'AlfrescoService' to 'DocumentListService'
This commit is contained in:
@@ -25,7 +25,7 @@ import { DocumentListBreadcrumb } from './src/components/document-list-breadcrum
|
|||||||
|
|
||||||
import { FolderActionsService } from './src/services/folder-actions.service';
|
import { FolderActionsService } from './src/services/folder-actions.service';
|
||||||
import { DocumentActionsService } from './src/services/document-actions.service';
|
import { DocumentActionsService } from './src/services/document-actions.service';
|
||||||
import { AlfrescoService } from './src/services/alfresco.service';
|
import { DocumentListService } from './src/services/document-list.service';
|
||||||
|
|
||||||
// components
|
// components
|
||||||
export * from './src/components/document-list';
|
export * from './src/components/document-list';
|
||||||
@@ -39,7 +39,7 @@ export * from './src/components/document-list-breadcrumb.component';
|
|||||||
// services
|
// services
|
||||||
export * from './src/services/folder-actions.service';
|
export * from './src/services/folder-actions.service';
|
||||||
export * from './src/services/document-actions.service';
|
export * from './src/services/document-actions.service';
|
||||||
export * from './src/services/alfresco.service';
|
export * from './src/services/document-list.service';
|
||||||
|
|
||||||
export const DOCUMENT_LIST_DIRECTIVES: [any] = [
|
export const DOCUMENT_LIST_DIRECTIVES: [any] = [
|
||||||
DocumentList,
|
DocumentList,
|
||||||
@@ -52,7 +52,7 @@ export const DOCUMENT_LIST_DIRECTIVES: [any] = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
export const DOCUMENT_LIST_PROVIDERS: [any] = [
|
export const DOCUMENT_LIST_PROVIDERS: [any] = [
|
||||||
AlfrescoService,
|
DocumentListService,
|
||||||
FolderActionsService,
|
FolderActionsService,
|
||||||
DocumentActionsService
|
DocumentActionsService
|
||||||
];
|
];
|
||||||
|
@@ -15,15 +15,15 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {Observable} from 'rxjs/Observable';
|
import { Observable } from 'rxjs/Observable';
|
||||||
import {AlfrescoService} from '../../src/services/alfresco.service';
|
import { DocumentListService } from './../services/document-list.service';
|
||||||
import {
|
import {
|
||||||
AlfrescoSettingsService,
|
AlfrescoSettingsService,
|
||||||
AlfrescoAuthenticationService,
|
AlfrescoAuthenticationService,
|
||||||
AlfrescoContentService
|
AlfrescoContentService
|
||||||
} from 'ng2-alfresco-core';
|
} from 'ng2-alfresco-core';
|
||||||
|
|
||||||
export class AlfrescoServiceMock extends AlfrescoService {
|
export class DocumentListServiceMock extends DocumentListService {
|
||||||
|
|
||||||
folderToReturn: any = {};
|
folderToReturn: any = {};
|
||||||
getFolderReject: boolean = false;
|
getFolderReject: boolean = false;
|
@@ -23,7 +23,7 @@ import {
|
|||||||
} from '@angular/core/testing';
|
} from '@angular/core/testing';
|
||||||
|
|
||||||
import { DocumentList } from './document-list';
|
import { DocumentList } from './document-list';
|
||||||
import { AlfrescoServiceMock } from '../assets/alfresco.service.mock';
|
import { DocumentListServiceMock } from '../assets/document-list.service.mock';
|
||||||
import { ContentActionModel } from './../models/content-action.model';
|
import { ContentActionModel } from './../models/content-action.model';
|
||||||
import { ContentActionList } from './content-action-list';
|
import { ContentActionList } from './content-action-list';
|
||||||
|
|
||||||
@@ -33,8 +33,8 @@ describe('ContentColumnList', () => {
|
|||||||
let actionList: ContentActionList;
|
let actionList: ContentActionList;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
let alfrescoServiceMock = new AlfrescoServiceMock();
|
let documentListService = new DocumentListServiceMock();
|
||||||
documentList = new DocumentList(alfrescoServiceMock, null);
|
documentList = new DocumentList(documentListService, null);
|
||||||
actionList = new ContentActionList(documentList);
|
actionList = new ContentActionList(documentList);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -40,7 +40,7 @@ import {
|
|||||||
ObjectDataColumn
|
ObjectDataColumn
|
||||||
} from 'ng2-alfresco-datatable';
|
} from 'ng2-alfresco-datatable';
|
||||||
|
|
||||||
import { AlfrescoService } from './../services/alfresco.service';
|
import { DocumentListService } from './../services/document-list.service';
|
||||||
import { MinimalNodeEntity } from './../models/document-library.model';
|
import { MinimalNodeEntity } from './../models/document-library.model';
|
||||||
import { ContentActionModel } from './../models/content-action.model';
|
import { ContentActionModel } from './../models/content-action.model';
|
||||||
import { ShareDataTableAdapter, ShareDataRow } from './../data/share-datatable-adapter';
|
import { ShareDataTableAdapter, ShareDataRow } from './../data/share-datatable-adapter';
|
||||||
@@ -53,7 +53,7 @@ declare let __moduleName: string;
|
|||||||
selector: 'alfresco-document-list',
|
selector: 'alfresco-document-list',
|
||||||
styleUrls: ['./document-list.css'],
|
styleUrls: ['./document-list.css'],
|
||||||
templateUrl: './document-list.html',
|
templateUrl: './document-list.html',
|
||||||
providers: [AlfrescoService],
|
providers: [DocumentListService],
|
||||||
directives: [CONTEXT_MENU_DIRECTIVES, ALFRESCO_DATATABLE_DIRECTIVES],
|
directives: [CONTEXT_MENU_DIRECTIVES, ALFRESCO_DATATABLE_DIRECTIVES],
|
||||||
host: {
|
host: {
|
||||||
'(contextmenu)': 'onShowContextMenu($event)'
|
'(contextmenu)': 'onShowContextMenu($event)'
|
||||||
@@ -125,7 +125,7 @@ export class DocumentList implements OnInit, AfterViewInit, AfterViewChecked, Af
|
|||||||
data: ShareDataTableAdapter;
|
data: ShareDataTableAdapter;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private alfrescoService: AlfrescoService,
|
private documentListService: DocumentListService,
|
||||||
private ngZone: NgZone) {
|
private ngZone: NgZone) {
|
||||||
|
|
||||||
this.setupData();
|
this.setupData();
|
||||||
@@ -329,7 +329,7 @@ export class DocumentList implements OnInit, AfterViewInit, AfterViewChecked, Af
|
|||||||
}
|
}
|
||||||
|
|
||||||
private setupData() {
|
private setupData() {
|
||||||
this.data = new ShareDataTableAdapter(this.alfrescoService, this.baseComponentPath, []);
|
this.data = new ShareDataTableAdapter(this.documentListService, this.baseComponentPath, []);
|
||||||
this.data.setSorting(new DataSorting('id', 'asc'));
|
this.data.setSorting(new DataSorting('id', 'asc'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -23,7 +23,7 @@ import {
|
|||||||
} from 'ng2-alfresco-datatable';
|
} from 'ng2-alfresco-datatable';
|
||||||
|
|
||||||
import { NodePaging, MinimalNodeEntity } from './../models/document-library.model';
|
import { NodePaging, MinimalNodeEntity } from './../models/document-library.model';
|
||||||
import { AlfrescoService as DataService } from './../services/alfresco.service';
|
import { DocumentListService } from './../services/document-list.service';
|
||||||
|
|
||||||
export class ShareDataTableAdapter implements DataTableAdapter {
|
export class ShareDataTableAdapter implements DataTableAdapter {
|
||||||
|
|
||||||
@@ -33,7 +33,7 @@ export class ShareDataTableAdapter implements DataTableAdapter {
|
|||||||
|
|
||||||
thumbnails: boolean = false;
|
thumbnails: boolean = false;
|
||||||
|
|
||||||
constructor(private dataService: DataService,
|
constructor(private documentListService: DocumentListService,
|
||||||
private basePath: string,
|
private basePath: string,
|
||||||
schema: DataColumn[]) {
|
schema: DataColumn[]) {
|
||||||
this.rows = [];
|
this.rows = [];
|
||||||
@@ -94,8 +94,8 @@ export class ShareDataTableAdapter implements DataTableAdapter {
|
|||||||
if (node.entry.isFile) {
|
if (node.entry.isFile) {
|
||||||
|
|
||||||
if (this.thumbnails) {
|
if (this.thumbnails) {
|
||||||
if (this.dataService) {
|
if (this.documentListService) {
|
||||||
return this.dataService.getDocumentThumbnailUrl(node);
|
return this.documentListService.getDocumentThumbnailUrl(node);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -103,7 +103,7 @@ export class ShareDataTableAdapter implements DataTableAdapter {
|
|||||||
if (node.entry.content && node.entry.content.mimeType) {
|
if (node.entry.content && node.entry.content.mimeType) {
|
||||||
let mimeType = node.entry.content.mimeType;
|
let mimeType = node.entry.content.mimeType;
|
||||||
if (mimeType) {
|
if (mimeType) {
|
||||||
let icon = this.dataService.getMimeTypeIcon(mimeType);
|
let icon = this.documentListService.getMimeTypeIcon(mimeType);
|
||||||
if (icon) {
|
if (icon) {
|
||||||
return `${this.basePath}/img/${icon}`;
|
return `${this.basePath}/img/${icon}`;
|
||||||
}
|
}
|
||||||
@@ -163,8 +163,8 @@ export class ShareDataTableAdapter implements DataTableAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
loadPath(path: string) {
|
loadPath(path: string) {
|
||||||
if (path && this.dataService) {
|
if (path && this.documentListService) {
|
||||||
this.dataService
|
this.documentListService
|
||||||
.getFolder(path)
|
.getFolder(path)
|
||||||
.subscribe(val => {
|
.subscribe(val => {
|
||||||
let page = <NodePaging>val;
|
let page = <NodePaging>val;
|
||||||
|
@@ -24,8 +24,8 @@ import {
|
|||||||
import { AlfrescoContentService } from 'ng2-alfresco-core';
|
import { AlfrescoContentService } from 'ng2-alfresco-core';
|
||||||
import { ContentActionHandler } from '../models/content-action.model';
|
import { ContentActionHandler } from '../models/content-action.model';
|
||||||
import { DocumentActionsService } from './document-actions.service';
|
import { DocumentActionsService } from './document-actions.service';
|
||||||
import { AlfrescoServiceMock } from '../assets/alfresco.service.mock';
|
import { DocumentListServiceMock } from '../assets/document-list.service.mock';
|
||||||
import { AlfrescoService } from './alfresco.service';
|
import { DocumentListService } from './document-list.service';
|
||||||
import {
|
import {
|
||||||
FileNode,
|
FileNode,
|
||||||
FolderNode
|
FolderNode
|
||||||
@@ -34,13 +34,13 @@ import {
|
|||||||
describe('DocumentActionsService', () => {
|
describe('DocumentActionsService', () => {
|
||||||
|
|
||||||
let service: DocumentActionsService;
|
let service: DocumentActionsService;
|
||||||
let alfrescoService: AlfrescoService;
|
let documentListService: DocumentListService;
|
||||||
let contentService: AlfrescoContentService;
|
let contentService: AlfrescoContentService;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
alfrescoService = new AlfrescoServiceMock();
|
documentListService = new DocumentListServiceMock();
|
||||||
contentService = new AlfrescoContentService(null, null);
|
contentService = new AlfrescoContentService(null, null);
|
||||||
service = new DocumentActionsService(alfrescoService, contentService);
|
service = new DocumentActionsService(documentListService, contentService);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should register default download action', () => {
|
it('should register default download action', () => {
|
||||||
@@ -147,7 +147,7 @@ describe('DocumentActionsService', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should require content service for download action', () => {
|
it('should require content service for download action', () => {
|
||||||
let actionService = new DocumentActionsService(alfrescoService, null);
|
let actionService = new DocumentActionsService(documentListService, null);
|
||||||
let file = new FileNode();
|
let file = new FileNode();
|
||||||
let result = actionService.getHandler('download')(file);
|
let result = actionService.getHandler('download')(file);
|
||||||
expect(result).toBeFalsy();
|
expect(result).toBeFalsy();
|
||||||
@@ -159,44 +159,44 @@ describe('DocumentActionsService', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should delete file node', () => {
|
it('should delete file node', () => {
|
||||||
spyOn(alfrescoService, 'deleteNode').and.callThrough();
|
spyOn(documentListService, 'deleteNode').and.callThrough();
|
||||||
|
|
||||||
let file = new FileNode();
|
let file = new FileNode();
|
||||||
service.getHandler('delete')(file);
|
service.getHandler('delete')(file);
|
||||||
|
|
||||||
expect(alfrescoService.deleteNode).toHaveBeenCalledWith(file.entry.id);
|
expect(documentListService.deleteNode).toHaveBeenCalledWith(file.entry.id);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should support deletion only file node', () => {
|
it('should support deletion only file node', () => {
|
||||||
spyOn(alfrescoService, 'deleteNode').and.callThrough();
|
spyOn(documentListService, 'deleteNode').and.callThrough();
|
||||||
|
|
||||||
let folder = new FolderNode();
|
let folder = new FolderNode();
|
||||||
service.getHandler('delete')(folder);
|
service.getHandler('delete')(folder);
|
||||||
expect(alfrescoService.deleteNode).not.toHaveBeenCalled();
|
expect(documentListService.deleteNode).not.toHaveBeenCalled();
|
||||||
|
|
||||||
let file = new FileNode();
|
let file = new FileNode();
|
||||||
service.getHandler('delete')(file);
|
service.getHandler('delete')(file);
|
||||||
expect(alfrescoService.deleteNode).toHaveBeenCalled();
|
expect(documentListService.deleteNode).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should require node id to delete', () => {
|
it('should require node id to delete', () => {
|
||||||
spyOn(alfrescoService, 'deleteNode').and.callThrough();
|
spyOn(documentListService, 'deleteNode').and.callThrough();
|
||||||
|
|
||||||
let file = new FileNode();
|
let file = new FileNode();
|
||||||
file.entry.id = null;
|
file.entry.id = null;
|
||||||
service.getHandler('delete')(file);
|
service.getHandler('delete')(file);
|
||||||
|
|
||||||
expect(alfrescoService.deleteNode).not.toHaveBeenCalled();
|
expect(documentListService.deleteNode).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should reload target upon node deletion', () => {
|
it('should reload target upon node deletion', () => {
|
||||||
spyOn(alfrescoService, 'deleteNode').and.callThrough();
|
spyOn(documentListService, 'deleteNode').and.callThrough();
|
||||||
|
|
||||||
let target = jasmine.createSpyObj('obj', ['reload']);
|
let target = jasmine.createSpyObj('obj', ['reload']);
|
||||||
let file = new FileNode();
|
let file = new FileNode();
|
||||||
service.getHandler('delete')(file, target);
|
service.getHandler('delete')(file, target);
|
||||||
|
|
||||||
expect(alfrescoService.deleteNode).toHaveBeenCalled();
|
expect(documentListService.deleteNode).toHaveBeenCalled();
|
||||||
expect(target.reload).toHaveBeenCalled();
|
expect(target.reload).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -15,9 +15,9 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {Injectable} from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import {ContentActionHandler} from '../models/content-action.model';
|
import { ContentActionHandler } from '../models/content-action.model';
|
||||||
import {AlfrescoService} from './alfresco.service';
|
import { DocumentListService } from './document-list.service';
|
||||||
import { AlfrescoContentService } from 'ng2-alfresco-core';
|
import { AlfrescoContentService } from 'ng2-alfresco-core';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
@@ -25,7 +25,7 @@ export class DocumentActionsService {
|
|||||||
private handlers: { [id: string]: ContentActionHandler; } = {};
|
private handlers: { [id: string]: ContentActionHandler; } = {};
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private alfrescoService?: AlfrescoService,
|
private documentListService?: DocumentListService,
|
||||||
private contentService?: AlfrescoContentService
|
private contentService?: AlfrescoContentService
|
||||||
) {
|
) {
|
||||||
this.setupActionHandlers();
|
this.setupActionHandlers();
|
||||||
@@ -49,7 +49,7 @@ export class DocumentActionsService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
canExecuteAction(obj: any): boolean {
|
canExecuteAction(obj: any): boolean {
|
||||||
return this.alfrescoService && obj && obj.entry.isFile === true;
|
return this.documentListService && obj && obj.entry.isFile === true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private setupActionHandlers() {
|
private setupActionHandlers() {
|
||||||
@@ -86,7 +86,7 @@ export class DocumentActionsService {
|
|||||||
|
|
||||||
private deleteNode(obj: any, target?: any) {
|
private deleteNode(obj: any, target?: any) {
|
||||||
if (this.canExecuteAction(obj) && obj.entry && obj.entry.id) {
|
if (this.canExecuteAction(obj) && obj.entry && obj.entry.id) {
|
||||||
this.alfrescoService.deleteNode(obj.entry.id).subscribe(() => {
|
this.documentListService.deleteNode(obj.entry.id).subscribe(() => {
|
||||||
if (target && typeof target.reload === 'function') {
|
if (target && typeof target.reload === 'function') {
|
||||||
target.reload();
|
target.reload();
|
||||||
}
|
}
|
||||||
|
@@ -27,12 +27,11 @@ import {
|
|||||||
AlfrescoContentService
|
AlfrescoContentService
|
||||||
} from 'ng2-alfresco-core';
|
} from 'ng2-alfresco-core';
|
||||||
import { FileNode } from '../assets/document-library.model.mock';
|
import { FileNode } from '../assets/document-library.model.mock';
|
||||||
import { AlfrescoService } from './alfresco.service';
|
import { DocumentListService } from './document-list.service';
|
||||||
|
|
||||||
// TODO: rename to DocumentListService
|
describe('DocumentListService', () => {
|
||||||
describe('AlfrescoService', () => {
|
|
||||||
|
|
||||||
let service: AlfrescoService;
|
let service: DocumentListService;
|
||||||
let settingsService: AlfrescoSettingsService;
|
let settingsService: AlfrescoSettingsService;
|
||||||
let authService: AlfrescoAuthenticationService;
|
let authService: AlfrescoAuthenticationService;
|
||||||
let contentService: AlfrescoContentService;
|
let contentService: AlfrescoContentService;
|
||||||
@@ -42,7 +41,7 @@ describe('AlfrescoService', () => {
|
|||||||
settingsService = new AlfrescoSettingsService();
|
settingsService = new AlfrescoSettingsService();
|
||||||
authService = new AlfrescoAuthenticationService(settingsService);
|
authService = new AlfrescoAuthenticationService(settingsService);
|
||||||
contentService = new AlfrescoContentService(settingsService, authService);
|
contentService = new AlfrescoContentService(settingsService, authService);
|
||||||
service = new AlfrescoService(settingsService, authService, contentService);
|
service = new DocumentListService(settingsService, authService, contentService);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should require node to get thumbnail url', () => {
|
it('should require node to get thumbnail url', () => {
|
||||||
@@ -50,7 +49,7 @@ describe('AlfrescoService', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should require content service to get thumbnail url', () => {
|
it('should require content service to get thumbnail url', () => {
|
||||||
service = new AlfrescoService(settingsService, authService, null);
|
service = new DocumentListService(settingsService, authService, null);
|
||||||
let file = new FileNode();
|
let file = new FileNode();
|
||||||
expect(service.getDocumentThumbnailUrl(file)).toBeNull();
|
expect(service.getDocumentThumbnailUrl(file)).toBeNull();
|
||||||
});
|
});
|
||||||
@@ -72,9 +71,9 @@ describe('AlfrescoService', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should resolve default icon for mime type', () => {
|
it('should resolve default icon for mime type', () => {
|
||||||
expect(service.getMimeTypeIcon(null)).toBe(AlfrescoService.DEFAULT_MIME_TYPE_ICON);
|
expect(service.getMimeTypeIcon(null)).toBe(DocumentListService.DEFAULT_MIME_TYPE_ICON);
|
||||||
expect(service.getMimeTypeIcon('')).toBe(AlfrescoService.DEFAULT_MIME_TYPE_ICON);
|
expect(service.getMimeTypeIcon('')).toBe(DocumentListService.DEFAULT_MIME_TYPE_ICON);
|
||||||
expect(service.getMimeTypeIcon('missing/type')).toBe(AlfrescoService.DEFAULT_MIME_TYPE_ICON);
|
expect(service.getMimeTypeIcon('missing/type')).toBe(DocumentListService.DEFAULT_MIME_TYPE_ICON);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
@@ -27,12 +27,8 @@ import {
|
|||||||
|
|
||||||
declare let AlfrescoApi: any;
|
declare let AlfrescoApi: any;
|
||||||
|
|
||||||
// TODO: consider renaming to something like 'DocumentListService'
|
|
||||||
/**
|
|
||||||
* Internal service used by Document List component.
|
|
||||||
*/
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AlfrescoService {
|
export class DocumentListService {
|
||||||
|
|
||||||
static DEFAULT_MIME_TYPE_ICON: string = 'ft_ic_miscellaneous.svg';
|
static DEFAULT_MIME_TYPE_ICON: string = 'ft_ic_miscellaneous.svg';
|
||||||
|
|
||||||
@@ -120,7 +116,7 @@ export class AlfrescoService {
|
|||||||
|
|
||||||
getMimeTypeIcon(mimeType: string): string {
|
getMimeTypeIcon(mimeType: string): string {
|
||||||
let icon = this.mimeTypeIcons[mimeType];
|
let icon = this.mimeTypeIcons[mimeType];
|
||||||
return icon || AlfrescoService.DEFAULT_MIME_TYPE_ICON;
|
return icon || DocumentListService.DEFAULT_MIME_TYPE_ICON;
|
||||||
}
|
}
|
||||||
|
|
||||||
private handleError(error: Response) {
|
private handleError(error: Response) {
|
@@ -27,17 +27,17 @@ import {
|
|||||||
FileNode,
|
FileNode,
|
||||||
FolderNode
|
FolderNode
|
||||||
} from '../assets/document-library.model.mock';
|
} from '../assets/document-library.model.mock';
|
||||||
import { AlfrescoService } from './alfresco.service';
|
import { DocumentListService } from './document-list.service';
|
||||||
import { AlfrescoServiceMock } from '../assets/alfresco.service.mock';
|
import { DocumentListServiceMock } from '../assets/document-list.service.mock';
|
||||||
|
|
||||||
describe('FolderActionsService', () => {
|
describe('FolderActionsService', () => {
|
||||||
|
|
||||||
let service: FolderActionsService;
|
let service: FolderActionsService;
|
||||||
let alfrescoService: AlfrescoService;
|
let documentListService: DocumentListService;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
alfrescoService = new AlfrescoServiceMock();
|
documentListService = new DocumentListServiceMock();
|
||||||
service = new FolderActionsService(alfrescoService);
|
service = new FolderActionsService(documentListService);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should register custom action handler', () => {
|
it('should register custom action handler', () => {
|
||||||
@@ -105,44 +105,44 @@ describe('FolderActionsService', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should delete folder node', () => {
|
it('should delete folder node', () => {
|
||||||
spyOn(alfrescoService, 'deleteNode').and.callThrough();
|
spyOn(documentListService, 'deleteNode').and.callThrough();
|
||||||
|
|
||||||
let folder = new FolderNode();
|
let folder = new FolderNode();
|
||||||
service.getHandler('delete')(folder);
|
service.getHandler('delete')(folder);
|
||||||
|
|
||||||
expect(alfrescoService.deleteNode).toHaveBeenCalledWith(folder.entry.id);
|
expect(documentListService.deleteNode).toHaveBeenCalledWith(folder.entry.id);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should support deletion only folder node', () => {
|
it('should support deletion only folder node', () => {
|
||||||
spyOn(alfrescoService, 'deleteNode').and.callThrough();
|
spyOn(documentListService, 'deleteNode').and.callThrough();
|
||||||
|
|
||||||
let file = new FileNode();
|
let file = new FileNode();
|
||||||
service.getHandler('delete')(file);
|
service.getHandler('delete')(file);
|
||||||
expect(alfrescoService.deleteNode).not.toHaveBeenCalled();
|
expect(documentListService.deleteNode).not.toHaveBeenCalled();
|
||||||
|
|
||||||
let folder = new FolderNode();
|
let folder = new FolderNode();
|
||||||
service.getHandler('delete')(folder);
|
service.getHandler('delete')(folder);
|
||||||
expect(alfrescoService.deleteNode).toHaveBeenCalled();
|
expect(documentListService.deleteNode).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should require node id to delete', () => {
|
it('should require node id to delete', () => {
|
||||||
spyOn(alfrescoService, 'deleteNode').and.callThrough();
|
spyOn(documentListService, 'deleteNode').and.callThrough();
|
||||||
|
|
||||||
let folder = new FolderNode();
|
let folder = new FolderNode();
|
||||||
folder.entry.id = null;
|
folder.entry.id = null;
|
||||||
service.getHandler('delete')(folder);
|
service.getHandler('delete')(folder);
|
||||||
|
|
||||||
expect(alfrescoService.deleteNode).not.toHaveBeenCalled();
|
expect(documentListService.deleteNode).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should reload target upon node deletion', () => {
|
it('should reload target upon node deletion', () => {
|
||||||
spyOn(alfrescoService, 'deleteNode').and.callThrough();
|
spyOn(documentListService, 'deleteNode').and.callThrough();
|
||||||
|
|
||||||
let target = jasmine.createSpyObj('obj', ['reload']);
|
let target = jasmine.createSpyObj('obj', ['reload']);
|
||||||
let folder = new FolderNode();
|
let folder = new FolderNode();
|
||||||
service.getHandler('delete')(folder, target);
|
service.getHandler('delete')(folder, target);
|
||||||
|
|
||||||
expect(alfrescoService.deleteNode).toHaveBeenCalled();
|
expect(documentListService.deleteNode).toHaveBeenCalled();
|
||||||
expect(target.reload).toHaveBeenCalled();
|
expect(target.reload).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -15,15 +15,15 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {Injectable} from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import {ContentActionHandler} from '../models/content-action.model';
|
import { ContentActionHandler } from '../models/content-action.model';
|
||||||
import {AlfrescoService} from './alfresco.service';
|
import { DocumentListService } from './document-list.service';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class FolderActionsService {
|
export class FolderActionsService {
|
||||||
private handlers: { [id: string]: ContentActionHandler; } = {};
|
private handlers: { [id: string]: ContentActionHandler; } = {};
|
||||||
|
|
||||||
constructor(private _alfrescoService?: AlfrescoService) {
|
constructor(private documentListService?: DocumentListService) {
|
||||||
this.setupActionHandlers();
|
this.setupActionHandlers();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,7 +45,7 @@ export class FolderActionsService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
canExecuteAction(obj: any): boolean {
|
canExecuteAction(obj: any): boolean {
|
||||||
return this._alfrescoService && obj && obj.entry.isFolder === true;
|
return this.documentListService && obj && obj.entry.isFolder === true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private setupActionHandlers() {
|
private setupActionHandlers() {
|
||||||
@@ -68,7 +68,7 @@ export class FolderActionsService {
|
|||||||
|
|
||||||
private deleteNode(obj: any, target?: any) {
|
private deleteNode(obj: any, target?: any) {
|
||||||
if (this.canExecuteAction(obj) && obj.entry && obj.entry.id) {
|
if (this.canExecuteAction(obj) && obj.entry && obj.entry.id) {
|
||||||
this._alfrescoService.deleteNode(obj.entry.id).subscribe(() => {
|
this.documentListService.deleteNode(obj.entry.id).subscribe(() => {
|
||||||
if (target && typeof target.reload === 'function') {
|
if (target && typeof target.reload === 'function') {
|
||||||
target.reload();
|
target.reload();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user