From 50fef106a8b34c498353e04ce4784c5f2575e842 Mon Sep 17 00:00:00 2001 From: Maurizio Vitale Date: Tue, 11 Jul 2017 10:21:04 +0100 Subject: [PATCH] [ADF-1045] Process Attachments List - Improve the component (#2067) * Create two different ProcessUpload service on for task one for process because the API are different Move the attachment task list and process list in different component outside the activiti demo component * Move the create task/process attachment in the child component --- demo-shell-ng2/app/app.module.ts | 4 ++ .../activiti/activiti-demo.component.html | 49 ++------------- .../activiti/activiti-demo.component.ts | 62 ++----------------- ...ctiviti-process-attachments.component.html | 29 +++++++++ .../activiti-process-attachments.component.ts | 60 ++++++++++++++++++ .../activiti-task-attachments.component.html | 29 +++++++++ .../activiti-task-attachments.component.ts | 60 ++++++++++++++++++ demo-shell-ng2/app/components/index.ts | 2 + ng2-components/ng2-activiti-form/index.ts | 3 - .../ng2-activiti-processlist/index.ts | 5 +- .../adf-process-attachment-list.component.ts | 10 +++ .../src/services/process-upload.service.ts | 39 ++++++++++++ ng2-components/ng2-activiti-tasklist/index.ts | 5 +- .../src/services/process-upload.service.ts | 0 14 files changed, 252 insertions(+), 105 deletions(-) create mode 100644 demo-shell-ng2/app/components/activiti/activiti-process-attachments.component.html create mode 100644 demo-shell-ng2/app/components/activiti/activiti-process-attachments.component.ts create mode 100644 demo-shell-ng2/app/components/activiti/activiti-task-attachments.component.html create mode 100644 demo-shell-ng2/app/components/activiti/activiti-task-attachments.component.ts create mode 100644 ng2-components/ng2-activiti-processlist/src/services/process-upload.service.ts rename ng2-components/{ng2-activiti-form => ng2-activiti-tasklist}/src/services/process-upload.service.ts (100%) diff --git a/demo-shell-ng2/app/app.module.ts b/demo-shell-ng2/app/app.module.ts index 0b1b8f684f..68c4005301 100644 --- a/demo-shell-ng2/app/app.module.ts +++ b/demo-shell-ng2/app/app.module.ts @@ -53,6 +53,8 @@ import { SearchBarComponent, LoginDemoComponent, ActivitiDemoComponent, + ActivitiTaskAttachmentsComponent, + ActivitiProcessAttachmentsComponent, ActivitiShowDiagramComponent, ActivitiAppsView, FormViewer, @@ -106,6 +108,8 @@ if (process.env.ENV === 'production') { SearchBarComponent, LoginDemoComponent, ActivitiDemoComponent, + ActivitiTaskAttachmentsComponent, + ActivitiProcessAttachmentsComponent, ActivitiShowDiagramComponent, ActivitiAppsView, FormViewer, diff --git a/demo-shell-ng2/app/components/activiti/activiti-demo.component.html b/demo-shell-ng2/app/components/activiti/activiti-demo.component.html index 90374137c7..68dfc972a0 100644 --- a/demo-shell-ng2/app/components/activiti/activiti-demo.component.html +++ b/demo-shell-ng2/app/components/activiti/activiti-demo.component.html @@ -72,30 +72,9 @@ (taskDeleted)="onTaskDeleted($event)">
-
-
Attachments
-
-
- -
- - - - -
- - -
-
-
+ + @@ -158,25 +137,9 @@ (taskClick)="onProcessDetailsTaskClick($event)">
-
-
Attachments
-
- -
- - -
- - -
-
+ +
diff --git a/demo-shell-ng2/app/components/activiti/activiti-demo.component.ts b/demo-shell-ng2/app/components/activiti/activiti-demo.component.ts index 7a754fa5d6..fbc02355b2 100644 --- a/demo-shell-ng2/app/components/activiti/activiti-demo.component.ts +++ b/demo-shell-ng2/app/components/activiti/activiti-demo.component.ts @@ -22,8 +22,7 @@ import { ActivitiTaskList, ActivitiTaskDetails, FilterRepresentationModel, - TaskDetailsEvent, - TaskAttachmentListComponent + TaskDetailsEvent } from 'ng2-activiti-tasklist'; import { ActivitiProcessFilters, @@ -31,8 +30,7 @@ import { ActivitiProcessInstanceListComponent, ActivitiStartProcessInstance, FilterProcessRepresentationModel, - ProcessInstance, - ActivitiProcessAttachmentListComponent + ProcessInstance } from 'ng2-activiti-processlist'; import { AnalyticsReportListComponent } from 'ng2-activiti-analytics'; import { ActivatedRoute, Router } from '@angular/router'; @@ -42,8 +40,8 @@ import { ObjectDataRow, DataSorting } from 'ng2-alfresco-datatable'; -import { AlfrescoApiService, UploadService } from 'ng2-alfresco-core'; -import { FormService, FormRenderingService, FormEvent, FormFieldEvent, ProcessUploadService } from 'ng2-activiti-form'; +import { AlfrescoApiService } from 'ng2-alfresco-core'; +import { FormService, FormRenderingService, FormEvent, FormFieldEvent } from 'ng2-activiti-form'; import { /*CustomEditorComponent*/ CustomStencil01 } from './custom-editor/custom-editor.component'; declare var componentHandler; @@ -53,10 +51,7 @@ const currentProcessIdNew = '__NEW__'; @Component({ selector: 'activiti-demo', templateUrl: './activiti-demo.component.html', - styleUrls: ['./activiti-demo.component.css'], - providers: [ - { provide: UploadService, useClass: ProcessUploadService } - ] + styleUrls: ['./activiti-demo.component.css'] }) export class ActivitiDemoComponent implements AfterViewInit { @@ -66,9 +61,6 @@ export class ActivitiDemoComponent implements AfterViewInit { @ViewChild(ActivitiTaskList) taskList: ActivitiTaskList; - @ViewChild(TaskAttachmentListComponent) - taskAttachList: TaskAttachmentListComponent; - @ViewChild(ActivitiProcessFilters) activitiprocessfilter: ActivitiProcessFilters; @@ -81,9 +73,6 @@ export class ActivitiDemoComponent implements AfterViewInit { @ViewChild(ActivitiTaskDetails) activitidetails: ActivitiTaskDetails; - @ViewChild(ActivitiProcessAttachmentListComponent) - processAttachList: ActivitiProcessAttachmentListComponent; - @ViewChild(ActivitiStartProcessInstance) activitiStartProcess: ActivitiStartProcessInstance; @@ -115,8 +104,6 @@ export class ActivitiDemoComponent implements AfterViewInit { sub: Subscription; blobFile: any; flag: boolean = true; - createTaskAttach: boolean = false; - createProcessAttach: boolean = false; dataTasks: ObjectDataTableAdapter; dataProcesses: ObjectDataTableAdapter; @@ -125,7 +112,6 @@ export class ActivitiDemoComponent implements AfterViewInit { private route: ActivatedRoute, private router: Router, private apiService: AlfrescoApiService, - private uploadService: UploadService, private formRenderingService: FormRenderingService, private formService: FormService) { this.dataTasks = new ObjectDataTableAdapter(); @@ -175,8 +161,6 @@ export class ActivitiDemoComponent implements AfterViewInit { }); this.layoutType = ActivitiApps.LAYOUT_GRID; - this.uploadService.fileUploadComplete.subscribe(value => this.onFileUploadComplete(value.data)); - } ngOnDestroy() { @@ -281,16 +265,6 @@ export class ActivitiDemoComponent implements AfterViewInit { this.contentName = content.name; } - onFileUploadComplete(content: any) { - this.taskAttachList.add(content); - } - - onAttachmentClick(content: any): void { - this.fileShowed = true; - this.content = content.contentBlob; - this.contentName = content.name; - } - onTaskCreated(data: any): void { this.currentTaskId = data.parentTaskId; this.taskList.reload(); @@ -356,32 +330,6 @@ export class ActivitiDemoComponent implements AfterViewInit { console.log(event); } - onCreateTaskSuccess(): void { - this.taskAttachList.reload(); - this.toggleCreateTakAttach(); - } - - onContentCreated() { - this.processAttachList.reload(); - this.toggleCreateProcessAttach(); - } - - toggleCreateTakAttach(): void { - this.createTaskAttach = !this.createTaskAttach; - } - - isCreateTaskAttachVisible(): boolean { - return this.createTaskAttach; - } - - toggleCreateProcessAttach(): void { - this.createProcessAttach = !this.createProcessAttach; - } - - isCreateProcessAttachVisible(): boolean { - return this.createProcessAttach; - } - isTaskCompleted(): boolean { return this.activitidetails.isCompletedTask(); } diff --git a/demo-shell-ng2/app/components/activiti/activiti-process-attachments.component.html b/demo-shell-ng2/app/components/activiti/activiti-process-attachments.component.html new file mode 100644 index 0000000000..1b87721be8 --- /dev/null +++ b/demo-shell-ng2/app/components/activiti/activiti-process-attachments.component.html @@ -0,0 +1,29 @@ +
+
Attachments
+
+ + + + + + + + +
+
+ +
+ + +
diff --git a/demo-shell-ng2/app/components/activiti/activiti-process-attachments.component.ts b/demo-shell-ng2/app/components/activiti/activiti-process-attachments.component.ts new file mode 100644 index 0000000000..22884f45d0 --- /dev/null +++ b/demo-shell-ng2/app/components/activiti/activiti-process-attachments.component.ts @@ -0,0 +1,60 @@ +/*! + * @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 { Component, ViewChild, Input } from '@angular/core'; +import { ActivitiProcessAttachmentListComponent, ProcessUploadService } from 'ng2-activiti-processlist'; +import { UploadService } from 'ng2-alfresco-core'; + +@Component({ + selector: 'activiti-process-attachments', + templateUrl: './activiti-process-attachments.component.html', + providers: [ + { provide: UploadService, useClass: ProcessUploadService } + ] +}) + +export class ActivitiProcessAttachmentsComponent { + + @Input() + processId: string; + + @ViewChild(ActivitiProcessAttachmentListComponent) + processAttachList: ActivitiProcessAttachmentListComponent; + + fileShowed: boolean = false; + content: Blob; + contentName: string; + + constructor(private uploadService: UploadService) { + + } + + ngOnInit() { + this.uploadService.fileUploadComplete.subscribe(value => this.onFileUploadComplete(value.data)); + } + + onFileUploadComplete(content: any) { + this.processAttachList.add(content); + } + + onAttachmentClick(content: any): void { + this.fileShowed = true; + this.content = content.contentBlob; + this.contentName = content.name; + } + +} diff --git a/demo-shell-ng2/app/components/activiti/activiti-task-attachments.component.html b/demo-shell-ng2/app/components/activiti/activiti-task-attachments.component.html new file mode 100644 index 0000000000..72871b82b6 --- /dev/null +++ b/demo-shell-ng2/app/components/activiti/activiti-task-attachments.component.html @@ -0,0 +1,29 @@ +
+
Attachments
+
+ + + + + + + + +
+
+ +
+ + +
diff --git a/demo-shell-ng2/app/components/activiti/activiti-task-attachments.component.ts b/demo-shell-ng2/app/components/activiti/activiti-task-attachments.component.ts new file mode 100644 index 0000000000..9cbd8f4871 --- /dev/null +++ b/demo-shell-ng2/app/components/activiti/activiti-task-attachments.component.ts @@ -0,0 +1,60 @@ +/*! + * @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 { Component, ViewChild, Input } from '@angular/core'; +import { TaskAttachmentListComponent, ProcessUploadService } from 'ng2-activiti-tasklist'; +import { UploadService } from 'ng2-alfresco-core'; + +@Component({ + selector: 'activiti-task-attachments', + templateUrl: './activiti-task-attachments.component.html', + providers: [ + { provide: UploadService, useClass: ProcessUploadService } + ] +}) + +export class ActivitiTaskAttachmentsComponent { + + @Input() + taskId: string; + + @ViewChild(TaskAttachmentListComponent) + taskAttachList: TaskAttachmentListComponent; + + fileShowed: boolean = false; + content: Blob; + contentName: string; + + constructor(private uploadService: UploadService) { + + } + + ngOnInit() { + this.uploadService.fileUploadComplete.subscribe(value => this.onFileUploadComplete(value.data)); + } + + onFileUploadComplete(content: any) { + this.taskAttachList.add(content); + } + + onAttachmentClick(content: any): void { + this.fileShowed = true; + this.content = content.contentBlob; + this.contentName = content.name; + } + +} diff --git a/demo-shell-ng2/app/components/index.ts b/demo-shell-ng2/app/components/index.ts index 8b968f8e75..772ec16580 100644 --- a/demo-shell-ng2/app/components/index.ts +++ b/demo-shell-ng2/app/components/index.ts @@ -21,6 +21,8 @@ export { SearchComponent } from './search/search.component'; export { SearchBarComponent } from './search/search-bar.component'; export { LoginDemoComponent } from './login/login-demo.component'; export { ActivitiDemoComponent } from './activiti/activiti-demo.component'; +export { ActivitiTaskAttachmentsComponent } from './activiti/activiti-task-attachments.component'; +export { ActivitiProcessAttachmentsComponent } from './activiti/activiti-process-attachments.component'; export { ActivitiShowDiagramComponent } from './activiti/activiti-show-diagram.component'; export { FormViewer } from './activiti/form-viewer.component'; export { WebscriptComponent } from './webscript/webscript.component'; diff --git a/ng2-components/ng2-activiti-form/index.ts b/ng2-components/ng2-activiti-form/index.ts index 9070b79abb..a1bc9bef82 100644 --- a/ng2-components/ng2-activiti-form/index.ts +++ b/ng2-components/ng2-activiti-form/index.ts @@ -32,7 +32,6 @@ import { EcmModelService } from './src/services/ecm-model.service'; import { FormRenderingService } from './src/services/form-rendering.service'; import { FormService } from './src/services/form.service'; import { NodeService } from './src/services/node.service'; -import { ProcessUploadService } from './src/services/process-upload.service'; import { WidgetVisibilityService } from './src/services/widget-visibility.service'; export * from './src/components/activiti-form.component'; @@ -40,7 +39,6 @@ export * from './src/components/adf-form-list.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/process-upload.service'; export * from './src/services/activiti-content-service'; export * from './src/components/widgets/index'; export * from './src/services/ecm-model.service'; @@ -59,7 +57,6 @@ export const ACTIVITI_FORM_DIRECTIVES: any[] = [ export const ACTIVITI_FORM_PROVIDERS: any[] = [ FormService, - ProcessUploadService, ActivitiContentService, EcmModelService, NodeService, diff --git a/ng2-components/ng2-activiti-processlist/index.ts b/ng2-components/ng2-activiti-processlist/index.ts index 681dec5988..022ae38263 100644 --- a/ng2-components/ng2-activiti-processlist/index.ts +++ b/ng2-components/ng2-activiti-processlist/index.ts @@ -35,6 +35,7 @@ import { } from './src/components/index'; import { ActivitiProcessService } from './src/services/activiti-process.service'; +import { ProcessUploadService } from './src/services/process-upload.service'; // components export * from './src/components/activiti-processlist.component'; @@ -43,6 +44,7 @@ export * from './src/components/activiti-process-instance-details.component'; export * from './src/components/activiti-start-process.component'; export * from './src/components/adf-process-attachment-list.component'; export * from './src/components/adf-create-process-attachment.component'; +export * from './src/services/process-upload.service'; // models export * from './src/models/index'; @@ -64,7 +66,8 @@ export const ACTIVITI_PROCESSLIST_DIRECTIVES: [any] = [ ]; export const ACTIVITI_PROCESSLIST_PROVIDERS: [any] = [ - ActivitiProcessService + ActivitiProcessService, + ProcessUploadService ]; @NgModule({ diff --git a/ng2-components/ng2-activiti-processlist/src/components/adf-process-attachment-list.component.ts b/ng2-components/ng2-activiti-processlist/src/components/adf-process-attachment-list.component.ts index 7543803213..aa6167bb99 100644 --- a/ng2-components/ng2-activiti-processlist/src/components/adf-process-attachment-list.component.ts +++ b/ng2-components/ng2-activiti-processlist/src/components/adf-process-attachment-list.component.ts @@ -64,6 +64,16 @@ export class ActivitiProcessAttachmentListComponent implements OnChanges { this.loadAttachmentsByProcessInstanceId(this.processInstanceId); } + add(content: any): void { + this.attachments.push({ + id: content.id, + name: content.name, + created: content.created, + createdBy: content.createdBy.firstName + ' ' + content.createdBy.lastName, + icon: this.thumbnailService.getMimeTypeIcon(content.mimeType) + }); + } + private loadAttachmentsByProcessInstanceId(processInstanceId: string) { if (processInstanceId) { this.reset(); diff --git a/ng2-components/ng2-activiti-processlist/src/services/process-upload.service.ts b/ng2-components/ng2-activiti-processlist/src/services/process-upload.service.ts new file mode 100644 index 0000000000..49d270ce7b --- /dev/null +++ b/ng2-components/ng2-activiti-processlist/src/services/process-upload.service.ts @@ -0,0 +1,39 @@ +/*! + * @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 { AlfrescoApiService, AppConfigService, UploadService } from 'ng2-alfresco-core'; + +@Injectable() +export class ProcessUploadService extends UploadService { + + instanceApi: AlfrescoApiService; + + constructor(apiService: AlfrescoApiService, appConfigService: AppConfigService) { + super(apiService, appConfigService); + this.instanceApi = apiService; + } + + getUploadPromise(file: any) { + let opts = { + isRelatedContent: true + }; + let processId = file.options.parentId; + return this.instanceApi.getInstance().activiti.contentApi.createRelatedContentOnProcessInstance(processId, file.file, opts); + } + +} diff --git a/ng2-components/ng2-activiti-tasklist/index.ts b/ng2-components/ng2-activiti-tasklist/index.ts index 92591a486d..868bf30b46 100644 --- a/ng2-components/ng2-activiti-tasklist/index.ts +++ b/ng2-components/ng2-activiti-tasklist/index.ts @@ -23,6 +23,7 @@ import { CoreModule } from 'ng2-alfresco-core'; import { DataTableModule } from 'ng2-alfresco-datatable'; import { ActivitiPeopleService } from './src/services/activiti-people.service'; import { ActivitiTaskListService } from './src/services/activiti-tasklist.service'; +import { ProcessUploadService } from './src/services/process-upload.service'; import { ActivitiApps, @@ -45,6 +46,7 @@ import { export * from './src/components/index'; export * from './src/services/activiti-tasklist.service'; export * from './src/services/activiti-people.service'; +export * from './src/services/process-upload.service'; export * from './src/models/index'; export const ACTIVITI_TASKLIST_DIRECTIVES: any[] = [ @@ -67,7 +69,8 @@ export const ACTIVITI_TASKLIST_DIRECTIVES: any[] = [ export const ACTIVITI_TASKLIST_PROVIDERS: any[] = [ ActivitiTaskListService, - ActivitiPeopleService + ActivitiPeopleService, + ProcessUploadService ]; @NgModule({ diff --git a/ng2-components/ng2-activiti-form/src/services/process-upload.service.ts b/ng2-components/ng2-activiti-tasklist/src/services/process-upload.service.ts similarity index 100% rename from ng2-components/ng2-activiti-form/src/services/process-upload.service.ts rename to ng2-components/ng2-activiti-tasklist/src/services/process-upload.service.ts