mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
[ADF-491] Task Attachment List Component (#1877)
* Create a new component Task Attachment List Improve the datatable to get the rows to show * The component name should follow the guide style Move the Content calls in a different service file Show the attach file inside the viewer * Change method name * Datatable should get the path and show the icon * Improve attachment component * Improve datatable documentation * Remove console.log
This commit is contained in:
committed by
Eugenio Romano
parent
608b3639ea
commit
a90423aa21
@@ -23,6 +23,7 @@ import { ActivitiContent } from './src/components/activiti-content.component';
|
||||
import { FormFieldComponent } from './src/components/form-field/form-field.component';
|
||||
import { ActivitiStartForm } from './src/components/activiti-start-form.component';
|
||||
import { FormService } from './src/services/form.service';
|
||||
import { ActivitiContentService } from './src/services/activiti-content-service';
|
||||
import { EcmModelService } from './src/services/ecm-model.service';
|
||||
import { NodeService } from './src/services/node.service';
|
||||
import { WidgetVisibilityService } from './src/services/widget-visibility.service';
|
||||
@@ -35,6 +36,7 @@ export * from './src/components/activiti-form.component';
|
||||
export * from './src/components/activiti-content.component';
|
||||
export * from './src/components/activiti-start-form.component';
|
||||
export * from './src/services/form.service';
|
||||
export * from './src/services/activiti-content-service';
|
||||
export * from './src/components/widgets/index';
|
||||
export * from './src/services/ecm-model.service';
|
||||
export * from './src/services/node.service';
|
||||
@@ -51,6 +53,7 @@ export const ACTIVITI_FORM_DIRECTIVES: any[] = [
|
||||
|
||||
export const ACTIVITI_FORM_PROVIDERS: any[] = [
|
||||
FormService,
|
||||
ActivitiContentService,
|
||||
EcmModelService,
|
||||
NodeService,
|
||||
WidgetVisibilityService,
|
||||
|
@@ -0,0 +1,126 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2016 Alfresco Software, Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs/Rx';
|
||||
import { AlfrescoApiService, LogService } from 'ng2-alfresco-core';
|
||||
|
||||
@Injectable()
|
||||
export class ActivitiContentService {
|
||||
|
||||
static UNKNOWN_ERROR_MESSAGE: string = 'Unknown error';
|
||||
static GENERIC_ERROR_MESSAGE: string = 'Server error';
|
||||
static DEFAULT_MIME_TYPE_ICON: string = 'ft_ic_miscellaneous.svg';
|
||||
|
||||
mimeTypeIcons: any = {
|
||||
'image/png': 'ft_ic_raster_image.svg',
|
||||
'image/jpeg': 'ft_ic_raster_image.svg',
|
||||
'image/gif': 'ft_ic_raster_image.svg',
|
||||
'application/pdf': 'ft_ic_pdf.svg',
|
||||
'application/vnd.ms-excel': 'ft_ic_ms_excel.svg',
|
||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': 'ft_ic_ms_excel.svg',
|
||||
'application/vnd.openxmlformats-officedocument.spreadsheetml.template': 'ft_ic_ms_excel.svg',
|
||||
'application/msword': 'ft_ic_ms_word.svg',
|
||||
'application/vnd.openxmlformats-officedocument.wordprocessingml.document': 'ft_ic_ms_word.svg',
|
||||
'application/vnd.openxmlformats-officedocument.wordprocessingml.template': 'ft_ic_ms_word.svg',
|
||||
'application/vnd.ms-powerpoint': 'ft_ic_ms_powerpoint.svg',
|
||||
'application/vnd.openxmlformats-officedocument.presentationml.presentation': 'ft_ic_ms_powerpoint.svg',
|
||||
'application/vnd.openxmlformats-officedocument.presentationml.template': 'ft_ic_ms_powerpoint.svg',
|
||||
'application/vnd.openxmlformats-officedocument.presentationml.slideshow': 'ft_ic_ms_powerpoint.svg',
|
||||
'video/mp4': 'ft_ic_video.svg',
|
||||
'text/plain': 'ft_ic_document.svg',
|
||||
'application/x-javascript': 'ft_ic_document.svg',
|
||||
'application/json': 'ft_ic_document.svg',
|
||||
'image/svg+xml': 'ft_ic_vector_image.svg',
|
||||
'text/html': 'ft_ic_website.svg',
|
||||
'application/x-compressed': 'ft_ic_archive.svg',
|
||||
'application/x-zip-compressed': 'ft_ic_archive.svg',
|
||||
'application/zip': 'ft_ic_archive.svg',
|
||||
'application/vnd.apple.keynote': 'ft_ic_presentation.svg',
|
||||
'application/vnd.apple.pages': 'ft_ic_document.svg',
|
||||
'application/vnd.apple.numbers': 'ft_ic_spreadsheet.svg'
|
||||
};
|
||||
|
||||
constructor(private apiService: AlfrescoApiService,
|
||||
private logService: LogService) {
|
||||
}
|
||||
|
||||
getFileRawContent(contentId: number): Observable<any> {
|
||||
let alfrescoApi = this.apiService.getInstance();
|
||||
return Observable.fromPromise(alfrescoApi.activiti.contentApi.getRawContent(contentId))
|
||||
.catch(err => this.handleError(err));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all the related content of the task
|
||||
* @param taskId
|
||||
* @returns {any}
|
||||
*/
|
||||
getTaskRelatedContent(taskId: string): Observable<any> {
|
||||
return Observable.fromPromise(this.apiService.getInstance().activiti.contentApi.getRelatedContentForTask(taskId))
|
||||
.catch(err => this.handleError(err));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all the related content of the process
|
||||
* @param processId
|
||||
* @returns {any}
|
||||
*/
|
||||
getProcessRelatedContent(processId: string): Observable<any> {
|
||||
return Observable.fromPromise(this.apiService.getInstance().activiti.contentApi.getRelatedContentForProcessInstance(processId))
|
||||
.catch(err => this.handleError(err));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a content by Id
|
||||
* @param contentId
|
||||
* @returns {any}
|
||||
*/
|
||||
deleteRelatedContent(contentId: string): Observable<any> {
|
||||
return Observable.fromPromise(this.apiService.getInstance().activiti.contentApi.deleteContent(contentId))
|
||||
.catch(err => this.handleError(err));
|
||||
}
|
||||
|
||||
toJson(res: any) {
|
||||
if (res) {
|
||||
return res || {};
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
toJsonArray(res: any) {
|
||||
if (res) {
|
||||
return res.data || [];
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
handleError(error: any): Observable<any> {
|
||||
let errMsg = ActivitiContentService.UNKNOWN_ERROR_MESSAGE;
|
||||
if (error) {
|
||||
errMsg = (error.message) ? error.message :
|
||||
error.status ? `${error.status} - ${error.statusText}` : ActivitiContentService.GENERIC_ERROR_MESSAGE;
|
||||
}
|
||||
this.logService.error(errMsg);
|
||||
return Observable.throw(errMsg);
|
||||
}
|
||||
|
||||
getMimeTypeIcon(mimeType: string): string {
|
||||
let icon = this.mimeTypeIcons[mimeType];
|
||||
return icon || ActivitiContentService.DEFAULT_MIME_TYPE_ICON;
|
||||
}
|
||||
}
|
@@ -0,0 +1,99 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2016 Alfresco Software, Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { CoreModule } from 'ng2-alfresco-core';
|
||||
import { ActivitiContentService } from './activiti-content-service';
|
||||
|
||||
declare let jasmine: any;
|
||||
|
||||
describe('ActivitiContentService', () => {
|
||||
|
||||
let service: ActivitiContentService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
CoreModule.forRoot()
|
||||
],
|
||||
providers: [
|
||||
ActivitiContentService
|
||||
]
|
||||
});
|
||||
service = TestBed.get(ActivitiContentService);
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
jasmine.Ajax.install();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jasmine.Ajax.uninstall();
|
||||
});
|
||||
|
||||
it('Should fetch the attachements', (done) => {
|
||||
service.getTaskRelatedContent('1234').subscribe((res) => {
|
||||
expect(res.data).toBeDefined();
|
||||
expect(res.data.length).toBe(2);
|
||||
expect(res.data[0].name).toBe('fake.zip');
|
||||
expect(res.data[0].mimeType).toBe('application/zip');
|
||||
expect(res.data[0].relatedContent).toBeTruthy();
|
||||
expect(res.data[1].name).toBe('fake.jpg');
|
||||
expect(res.data[1].mimeType).toBe('image/jpeg');
|
||||
expect(res.data[1].relatedContent).toBeTruthy();
|
||||
done();
|
||||
});
|
||||
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
'status': 200,
|
||||
contentType: 'application/json',
|
||||
responseText: JSON.stringify({
|
||||
size: 2,
|
||||
total: 2,
|
||||
start: 0,
|
||||
data: [
|
||||
{
|
||||
id: 8,
|
||||
name: 'fake.zip',
|
||||
created: 1494595697381,
|
||||
createdBy: {id: 2, firstName: 'user', lastName: 'user', email: 'user@user.com'},
|
||||
relatedContent: true,
|
||||
contentAvailable: true,
|
||||
link: false,
|
||||
mimeType: 'application/zip',
|
||||
simpleType: 'content',
|
||||
previewStatus: 'unsupported',
|
||||
thumbnailStatus: 'unsupported'
|
||||
},
|
||||
{
|
||||
id: 9,
|
||||
name: 'fake.jpg',
|
||||
created: 1494595655381,
|
||||
createdBy: {id: 2, firstName: 'user', lastName: 'user', email: 'user@user.com'},
|
||||
relatedContent: true,
|
||||
contentAvailable: true,
|
||||
link: false,
|
||||
mimeType: 'image/jpeg',
|
||||
simpleType: 'image',
|
||||
previewStatus: 'unsupported',
|
||||
thumbnailStatus: 'unsupported'
|
||||
}
|
||||
]
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user