From d612cc8ffa05b7e530af11f319bf5a63fce5de57 Mon Sep 17 00:00:00 2001 From: mauriziovitale84 Date: Wed, 27 Jul 2016 09:44:09 +0100 Subject: [PATCH] Improve the activiti task details --- .../ng2-activiti-tasklist/i18n/en.json | 23 ++++ .../ng2-activiti-tasklist/i18n/it.json | 11 ++ .../activiti-checklist.component.css | 11 ++ .../activiti-checklist.component.html | 19 ++++ .../activiti-checklist.component.ts | 81 ++++++++++++++ .../activiti-comments.component.css | 11 ++ .../activiti-comments.component.html | 35 ++++++ .../components/activiti-comments.component.ts | 104 ++++++++++++++++++ .../components/activiti-people.component.css | 11 ++ .../components/activiti-people.component.html | 19 ++++ .../components/activiti-people.component.ts | 55 +++++++++ .../activiti-task-details.component.html | 15 ++- .../activiti-task-details.component.ts | 22 ++-- .../activiti-task-header.component.css | 7 ++ .../activiti-task-header.component.html | 18 +++ .../activiti-task-header.component.ts | 82 ++++++++++++++ .../src/models/comment.model.ts | 39 +++++++ .../src/models/task-details.model.ts | 16 +-- .../src/models/user.model.ts | 38 +++++++ .../src/services/activiti-tasklist.service.ts | 83 ++++++++++++++ 20 files changed, 673 insertions(+), 27 deletions(-) create mode 100644 ng2-components/ng2-activiti-tasklist/src/components/activiti-checklist.component.css create mode 100644 ng2-components/ng2-activiti-tasklist/src/components/activiti-checklist.component.html create mode 100644 ng2-components/ng2-activiti-tasklist/src/components/activiti-checklist.component.ts create mode 100644 ng2-components/ng2-activiti-tasklist/src/components/activiti-comments.component.css create mode 100644 ng2-components/ng2-activiti-tasklist/src/components/activiti-comments.component.html create mode 100644 ng2-components/ng2-activiti-tasklist/src/components/activiti-comments.component.ts create mode 100644 ng2-components/ng2-activiti-tasklist/src/components/activiti-people.component.css create mode 100644 ng2-components/ng2-activiti-tasklist/src/components/activiti-people.component.html create mode 100644 ng2-components/ng2-activiti-tasklist/src/components/activiti-people.component.ts create mode 100644 ng2-components/ng2-activiti-tasklist/src/components/activiti-task-header.component.css create mode 100644 ng2-components/ng2-activiti-tasklist/src/components/activiti-task-header.component.html create mode 100644 ng2-components/ng2-activiti-tasklist/src/components/activiti-task-header.component.ts create mode 100644 ng2-components/ng2-activiti-tasklist/src/models/comment.model.ts create mode 100644 ng2-components/ng2-activiti-tasklist/src/models/user.model.ts diff --git a/ng2-components/ng2-activiti-tasklist/i18n/en.json b/ng2-components/ng2-activiti-tasklist/i18n/en.json index 1333cd2e5d..d83089f9f6 100644 --- a/ng2-components/ng2-activiti-tasklist/i18n/en.json +++ b/ng2-components/ng2-activiti-tasklist/i18n/en.json @@ -5,8 +5,31 @@ } }, "TASK_DETAILS": { + "LABELS": { + "ASSIGNEE": "Assignee", + "DUE": "Due", + "FORM": "Form", + "PEOPLE": "People", + "COMMENTS": "Comments", + "CHECKLIST": "Checklist" + }, "MESSAGES": { "NONE": "No task details found." + }, + "FORM": { + "NONE": "No form." + }, + "DUE": { + "NONE": "No due date." + }, + "PEOPLE": { + "NONE": "No people involved." + }, + "COMMENTS": { + "NONE": "No comments." + }, + "CHECKLIST": { + "NONE": "No checklist." } }, "TASK_FILTERS": { diff --git a/ng2-components/ng2-activiti-tasklist/i18n/it.json b/ng2-components/ng2-activiti-tasklist/i18n/it.json index d7fd51d6d0..62021c250d 100644 --- a/ng2-components/ng2-activiti-tasklist/i18n/it.json +++ b/ng2-components/ng2-activiti-tasklist/i18n/it.json @@ -5,8 +5,19 @@ } }, "TASK_DETAILS": { + "LABELS": { + "ASSIGNEE": "Assegnatario", + "DUE": "Scadenza", + "FORM": "Form" + }, "MESSAGES": { "NONE": "Nessun dettaglio task trovato." + }, + "FORM": { + "NONE": "Nessuna form." + }, + "DUE": { + "NONE": "Nessuna data di scadenza." } }, "TASK_FILTERS": { diff --git a/ng2-components/ng2-activiti-tasklist/src/components/activiti-checklist.component.css b/ng2-components/ng2-activiti-tasklist/src/components/activiti-checklist.component.css new file mode 100644 index 0000000000..6979275ee7 --- /dev/null +++ b/ng2-components/ng2-activiti-tasklist/src/components/activiti-checklist.component.css @@ -0,0 +1,11 @@ +:host { + width: 100%; +} + +.activiti-label { + color: rgb(255,152,0); +} + +.material-icons:hover { + color: rgb(255, 152, 0); +} diff --git a/ng2-components/ng2-activiti-tasklist/src/components/activiti-checklist.component.html b/ng2-components/ng2-activiti-tasklist/src/components/activiti-checklist.component.html new file mode 100644 index 0000000000..d85bfdbc00 --- /dev/null +++ b/ng2-components/ng2-activiti-tasklist/src/components/activiti-checklist.component.html @@ -0,0 +1,19 @@ +{{ 'TASK_DETAILS.LABELS.CHECKLIST' | translate }} +
add
+
+ Add a checklist +
+ +
+ {{ 'TASK_DETAILS.CHECKLIST.NONE' | translate }} +
\ No newline at end of file diff --git a/ng2-components/ng2-activiti-tasklist/src/components/activiti-checklist.component.ts b/ng2-components/ng2-activiti-tasklist/src/components/activiti-checklist.component.ts new file mode 100644 index 0000000000..57f66571fc --- /dev/null +++ b/ng2-components/ng2-activiti-tasklist/src/components/activiti-checklist.component.ts @@ -0,0 +1,81 @@ +/*! + * @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, Input, OnInit, OnChanges } from '@angular/core'; +import { AlfrescoTranslationService, AlfrescoAuthenticationService, AlfrescoPipeTranslate } from 'ng2-alfresco-core'; +import { ActivitiTaskListService } from './../services/activiti-tasklist.service'; +import { TaskDetailsModel } from '../models/task-details.model'; + +declare let componentHandler: any; +declare let __moduleName: string; + +@Component({ + selector: 'activiti-checklist', + moduleId: __moduleName, + templateUrl: './activiti-checklist.component.html', + styleUrls: ['./activiti-checklist.component.css'], + providers: [ActivitiTaskListService], + pipes: [ AlfrescoPipeTranslate ] + +}) +export class ActivitiChecklist implements OnInit, OnChanges { + + @Input() + taskId: string; + + checklist: TaskDetailsModel [] = []; + + /** + * Constructor + * @param auth + * @param translate + */ + constructor(private auth: AlfrescoAuthenticationService, + private translate: AlfrescoTranslationService, + private activitiTaskList: ActivitiTaskListService) { + + if (translate) { + translate.addTranslationFolder('node_modules/ng2-activiti-tasklist'); + } + } + + ngOnInit() { + if (this.taskId) { + this.load(this.taskId); + } + } + + ngOnChanges(change) { + this.load(this.taskId); + } + + public add() { + alert('Add CheckList'); + } + + public load(taskId: string) { + if (this.taskId) { + this.activitiTaskList.getTaskChecklist(this.taskId).subscribe( + (res: TaskDetailsModel[]) => { + this.checklist = res; + } + ); + } else { + this.checklist = []; + } + } +} diff --git a/ng2-components/ng2-activiti-tasklist/src/components/activiti-comments.component.css b/ng2-components/ng2-activiti-tasklist/src/components/activiti-comments.component.css new file mode 100644 index 0000000000..6979275ee7 --- /dev/null +++ b/ng2-components/ng2-activiti-tasklist/src/components/activiti-comments.component.css @@ -0,0 +1,11 @@ +:host { + width: 100%; +} + +.activiti-label { + color: rgb(255,152,0); +} + +.material-icons:hover { + color: rgb(255, 152, 0); +} diff --git a/ng2-components/ng2-activiti-tasklist/src/components/activiti-comments.component.html b/ng2-components/ng2-activiti-tasklist/src/components/activiti-comments.component.html new file mode 100644 index 0000000000..bb12d2fde4 --- /dev/null +++ b/ng2-components/ng2-activiti-tasklist/src/components/activiti-comments.component.html @@ -0,0 +1,35 @@ +{{ 'TASK_DETAILS.LABELS.COMMENTS' |translate }} +
add
+
+ Add a comment +
+ + +
+ {{ 'TASK_DETAILS.COMMENTS.NONE' | translate }} +
+ + + +

New comment

+
+
+ + +
+
+
+ + +
+
\ No newline at end of file diff --git a/ng2-components/ng2-activiti-tasklist/src/components/activiti-comments.component.ts b/ng2-components/ng2-activiti-tasklist/src/components/activiti-comments.component.ts new file mode 100644 index 0000000000..55a93c9de2 --- /dev/null +++ b/ng2-components/ng2-activiti-tasklist/src/components/activiti-comments.component.ts @@ -0,0 +1,104 @@ +/*! + * @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, Input, OnInit, OnChanges, ViewChild } from '@angular/core'; +import { AlfrescoTranslationService, AlfrescoAuthenticationService, AlfrescoPipeTranslate } from 'ng2-alfresco-core'; +import { ActivitiTaskListService } from './../services/activiti-tasklist.service'; +import { Comment } from '../models/comment.model'; + +declare let componentHandler: any; +declare let __moduleName: string; + +@Component({ + selector: 'activiti-comments', + moduleId: __moduleName, + templateUrl: './activiti-comments.component.html', + styleUrls: ['./activiti-comments.component.css'], + providers: [ActivitiTaskListService], + pipes: [ AlfrescoPipeTranslate ] + +}) +export class ActivitiComments implements OnInit, OnChanges { + + @Input() + taskId: string; + + @ViewChild('dialog') + dialog: any; + + comments: Comment [] = []; + + /** + * Constructor + * @param auth + * @param translate + */ + constructor(private auth: AlfrescoAuthenticationService, + private translate: AlfrescoTranslationService, + private activitiTaskList: ActivitiTaskListService) { + + if (translate) { + translate.addTranslationFolder('node_modules/ng2-activiti-tasklist'); + } + } + + ngOnInit() { + if (this.taskId) { + this.load(this.taskId); + } + } + + ngOnChanges(change) { + this.load(this.taskId); + } + + public load(taskId: string) { + if (this.taskId) { + this.activitiTaskList.getTaskComments(this.taskId).subscribe( + (res: Comment[]) => { + this.comments = res; + } + ); + } else { + this.comments = []; + } + } + + public showDialog() { + if (this.dialog) { + this.dialog.nativeElement.showModal(); + } + } + + public add() { + alert('add comment'); + if (this.taskId) { + this.activitiTaskList.addTaskComment(this.taskId, 'test comment').subscribe( + (res: Comment[]) => { + this.comments = res; + } + ); + } + this.cancel(); + } + + public cancel() { + if (this.dialog) { + this.dialog.nativeElement.close(); + } + } +} diff --git a/ng2-components/ng2-activiti-tasklist/src/components/activiti-people.component.css b/ng2-components/ng2-activiti-tasklist/src/components/activiti-people.component.css new file mode 100644 index 0000000000..6979275ee7 --- /dev/null +++ b/ng2-components/ng2-activiti-tasklist/src/components/activiti-people.component.css @@ -0,0 +1,11 @@ +:host { + width: 100%; +} + +.activiti-label { + color: rgb(255,152,0); +} + +.material-icons:hover { + color: rgb(255, 152, 0); +} diff --git a/ng2-components/ng2-activiti-tasklist/src/components/activiti-people.component.html b/ng2-components/ng2-activiti-tasklist/src/components/activiti-people.component.html new file mode 100644 index 0000000000..f5fe224419 --- /dev/null +++ b/ng2-components/ng2-activiti-tasklist/src/components/activiti-people.component.html @@ -0,0 +1,19 @@ +{{ 'TASK_DETAILS.LABELS.PEOPLE' | translate }} +
add
+
+ Add a people +
+ +
+ {{ 'TASK_DETAILS.PEOPLE.NONE' | translate }} +
\ No newline at end of file diff --git a/ng2-components/ng2-activiti-tasklist/src/components/activiti-people.component.ts b/ng2-components/ng2-activiti-tasklist/src/components/activiti-people.component.ts new file mode 100644 index 0000000000..46bcc4a2c6 --- /dev/null +++ b/ng2-components/ng2-activiti-tasklist/src/components/activiti-people.component.ts @@ -0,0 +1,55 @@ +/*! + * @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, Input, OnInit } from '@angular/core'; +import { AlfrescoTranslationService, AlfrescoAuthenticationService, AlfrescoPipeTranslate } from 'ng2-alfresco-core'; +import { User } from '../models/user.model'; + +declare let componentHandler: any; +declare let __moduleName: string; + +@Component({ + selector: 'activiti-people', + moduleId: __moduleName, + templateUrl: './activiti-people.component.html', + styleUrls: ['./activiti-people.component.css'], + pipes: [ AlfrescoPipeTranslate ] + +}) +export class ActivitiPeople implements OnInit { + + @Input() + people: User [] = []; + + /** + * Constructor + * @param auth + * @param translate + */ + constructor(private auth: AlfrescoAuthenticationService, + private translate: AlfrescoTranslationService) { + + if (translate) { + translate.addTranslationFolder('node_modules/ng2-activiti-tasklist'); + } + } + + ngOnInit() { + + } + +} diff --git a/ng2-components/ng2-activiti-tasklist/src/components/activiti-task-details.component.html b/ng2-components/ng2-activiti-tasklist/src/components/activiti-task-details.component.html index 371288afe5..8963833316 100644 --- a/ng2-components/ng2-activiti-tasklist/src/components/activiti-task-details.component.html +++ b/ng2-components/ng2-activiti-tasklist/src/components/activiti-task-details.component.html @@ -3,12 +3,17 @@

{{taskDetails.name}}

+
-
Assignee: {{taskDetails.assignee.lastName}}
-
Due: {{taskDetails.dueDate}}
-
Due: No due date
-
Form: {{taskForm?.name}}
+
+ +
+
+ +
+
+ +
-
\ No newline at end of file diff --git a/ng2-components/ng2-activiti-tasklist/src/components/activiti-task-details.component.ts b/ng2-components/ng2-activiti-tasklist/src/components/activiti-task-details.component.ts index a82f962ae5..7acaf89fb4 100644 --- a/ng2-components/ng2-activiti-tasklist/src/components/activiti-task-details.component.ts +++ b/ng2-components/ng2-activiti-tasklist/src/components/activiti-task-details.component.ts @@ -18,7 +18,12 @@ import { Component, Input, OnInit, OnChanges } from '@angular/core'; import { AlfrescoTranslationService, AlfrescoAuthenticationService, AlfrescoPipeTranslate } from 'ng2-alfresco-core'; import { ActivitiTaskListService } from './../services/activiti-tasklist.service'; +import { ActivitiTaskHeader } from './activiti-task-header.component'; +import { ActivitiComments } from './activiti-comments.component'; +import { ActivitiChecklist } from './activiti-checklist.component'; +import { ActivitiPeople } from './activiti-people.component'; import { TaskDetailsModel } from '../models/task-details.model'; +import { User } from '../models/user.model'; import { ActivitiForm, FormModel, FormService } from 'ng2-activiti-form'; @@ -30,8 +35,8 @@ declare let __moduleName: string; moduleId: __moduleName, templateUrl: './activiti-task-details.component.html', styleUrls: ['./activiti-task-details.component.css'], - providers: [ActivitiTaskListService, FormService], - directives: [ActivitiForm], + providers: [ ActivitiTaskListService, FormService ], + directives: [ ActivitiTaskHeader, ActivitiPeople, ActivitiComments, ActivitiChecklist, ActivitiForm ], pipes: [ AlfrescoPipeTranslate ] }) @@ -44,6 +49,8 @@ export class ActivitiTaskDetails implements OnInit, OnChanges { taskForm: FormModel; + taskPeople: User[] = []; + /** * Constructor * @param auth @@ -76,16 +83,15 @@ export class ActivitiTaskDetails implements OnInit, OnChanges { loadDetails(id: string) { this.taskForm = null; + this.taskPeople = []; if (id) { this.activitiTaskList.getTaskDetails(id).subscribe( (res: TaskDetailsModel) => { this.taskDetails = res; - if (this.taskDetails && this.taskDetails.formKey) { - this.activitiForm.getTaskForm(this.taskDetails.id).subscribe( - (response) => { - this.taskForm = response; - } - ); + if (this.taskDetails && this.taskDetails.involvedPeople) { + this.taskDetails.involvedPeople.forEach((user) => { + this.taskPeople.push(new User(user.id, user.email, user.firstName, user.lastName)); + }); } console.log(this.taskDetails); } diff --git a/ng2-components/ng2-activiti-tasklist/src/components/activiti-task-header.component.css b/ng2-components/ng2-activiti-tasklist/src/components/activiti-task-header.component.css new file mode 100644 index 0000000000..61bded3cfd --- /dev/null +++ b/ng2-components/ng2-activiti-tasklist/src/components/activiti-task-header.component.css @@ -0,0 +1,7 @@ +:host { + width: 100%; +} + +.activiti-label { + color: rgb(255,152,0); +} \ No newline at end of file diff --git a/ng2-components/ng2-activiti-tasklist/src/components/activiti-task-header.component.html b/ng2-components/ng2-activiti-tasklist/src/components/activiti-task-header.component.html new file mode 100644 index 0000000000..c098c1d8c3 --- /dev/null +++ b/ng2-components/ng2-activiti-tasklist/src/components/activiti-task-header.component.html @@ -0,0 +1,18 @@ +
+
+
+ {{ 'TASK_DETAILS.LABELS.ASSIGNEE' | translate }}: + {{taskDetails.assignee.lastName }} +
+
+ + {{ 'TASK_DETAILS.LABELS.DUE' | translate }}: + {{taskDetails?.dueDate ? taskDetails.dueDate : ('TASK_DETAILS.DUE.NONE' |translate) }} + +
+
+ {{ 'TASK_DETAILS.LABELS.FORM' | translate }}: + {{taskForm?.name ? taskForm.name : ('TASK_DETAILS.FORM.NONE' | translate) }} +
+
+
\ No newline at end of file diff --git a/ng2-components/ng2-activiti-tasklist/src/components/activiti-task-header.component.ts b/ng2-components/ng2-activiti-tasklist/src/components/activiti-task-header.component.ts new file mode 100644 index 0000000000..a1f4d777ee --- /dev/null +++ b/ng2-components/ng2-activiti-tasklist/src/components/activiti-task-header.component.ts @@ -0,0 +1,82 @@ +/*! + * @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, Input, OnInit, OnChanges } from '@angular/core'; +import { AlfrescoTranslationService, AlfrescoAuthenticationService, AlfrescoPipeTranslate } from 'ng2-alfresco-core'; +import { TaskDetailsModel } from '../models/task-details.model'; +import { FormModel, FormService } from 'ng2-activiti-form'; + +declare let componentHandler: any; +declare let __moduleName: string; + +@Component({ + selector: 'activiti-task-header', + moduleId: __moduleName, + templateUrl: './activiti-task-header.component.html', + styleUrls: ['./activiti-task-header.component.css'], + providers: [ FormService ], + pipes: [ AlfrescoPipeTranslate ] + +}) +export class ActivitiTaskHeader implements OnInit, OnChanges { + + @Input() + taskDetails: TaskDetailsModel; + + taskForm: FormModel; + + /** + * Constructor + * @param auth + * @param translate + */ + constructor(private auth: AlfrescoAuthenticationService, + private activitiForm: FormService, + private translate: AlfrescoTranslationService) { + + if (translate) { + translate.addTranslationFolder('node_modules/ng2-activiti-tasklist'); + } + } + + ngOnInit() { + if (this.taskDetails && this.taskDetails.formKey) { + this.load(this.taskDetails.id); + } + } + + ngOnChanges(change) { + if (this.taskDetails && this.taskDetails.formKey) { + this.load(this.taskDetails.id); + } else { + this.taskForm = null; + } + } + + public load(taskId: string) { + if (taskId) { + this.activitiForm.getTaskForm(taskId).subscribe( + (response) => { + this.taskForm = response; + }, + (err) => { + console.error(err); + } + ); + } + } +} diff --git a/ng2-components/ng2-activiti-tasklist/src/models/comment.model.ts b/ng2-components/ng2-activiti-tasklist/src/models/comment.model.ts new file mode 100644 index 0000000000..ba7ab40c86 --- /dev/null +++ b/ng2-components/ng2-activiti-tasklist/src/models/comment.model.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. + */ + +/** + * + * This object represent the comment of a task. + * + * + * @returns {Comment} . + */ +import { User } from './user.model'; + +export class Comment { + id: number; + message: string; + created: string; + createdBy: User; + + constructor(id: number, message: string, created: string, createdBy: User) { + this.id = id; + this.message = message; + this.created = created; + this.createdBy = createdBy; + } +} diff --git a/ng2-components/ng2-activiti-tasklist/src/models/task-details.model.ts b/ng2-components/ng2-activiti-tasklist/src/models/task-details.model.ts index b9915ab089..5ab0361aaa 100644 --- a/ng2-components/ng2-activiti-tasklist/src/models/task-details.model.ts +++ b/ng2-components/ng2-activiti-tasklist/src/models/task-details.model.ts @@ -22,6 +22,8 @@ * * @returns {TaskDetailsModel} . */ +import { User } from './user.model'; + export class TaskDetailsModel { id: string; name: string; @@ -89,17 +91,3 @@ export class TaskDetailsModel { this.taskDefinitionKey = obj.taskDefinitionKey; } } - -export class User { - id: number; - email: string; - firstName: string; - lastName: string; - - constructor(id: number, email: string, firstName: string, lastName: string) { - this.id = id; - this.email = email; - this.firstName = firstName; - this.lastName = lastName; - } -} diff --git a/ng2-components/ng2-activiti-tasklist/src/models/user.model.ts b/ng2-components/ng2-activiti-tasklist/src/models/user.model.ts new file mode 100644 index 0000000000..6d21ad4e0b --- /dev/null +++ b/ng2-components/ng2-activiti-tasklist/src/models/user.model.ts @@ -0,0 +1,38 @@ +/*! + * @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. + */ + +/** + * + * This object represent the user. + * + * + * @returns {User} . + */ + +export class User { + id: number; + email: string; + firstName: string; + lastName: string; + + constructor(id: number, email: string, firstName: string, lastName: string) { + this.id = id; + this.email = email; + this.firstName = firstName; + this.lastName = lastName; + } +} diff --git a/ng2-components/ng2-activiti-tasklist/src/services/activiti-tasklist.service.ts b/ng2-components/ng2-activiti-tasklist/src/services/activiti-tasklist.service.ts index 5a5a2343f9..eb9ba7ea3d 100644 --- a/ng2-components/ng2-activiti-tasklist/src/services/activiti-tasklist.service.ts +++ b/ng2-components/ng2-activiti-tasklist/src/services/activiti-tasklist.service.ts @@ -20,6 +20,9 @@ import { AlfrescoSettingsService } from 'ng2-alfresco-core'; import { Http, Headers, RequestOptions, Response } from '@angular/http'; import { Observable } from 'rxjs/Rx'; import { FilterModel } from '../models/filter.model'; +import { Comment } from '../models/comment.model'; +import { User } from '../models/user.model'; + import { TaskDetailsModel } from '../models/task-details.model'; @Injectable() @@ -69,6 +72,49 @@ export class ActivitiTaskListService { .catch(this.handleError); } + getTaskComments(id: string): Observable { + return Observable.fromPromise(this.callApiTaskComments(id)) + .map(res => res.json()) + .map((response: any) => { + let comments: Comment[] = []; + response.data.forEach((comment) => { + let user = new User( + comment.createdBy.id, comment.createdBy.email, comment.createdBy.firstName, comment.createdBy.lastName); + comments.push(new Comment(comment.id, comment.message, comment.created, user)); + }); + return comments; + }) + .catch(this.handleError); + } + + addTaskComment(id: string, message: string): Observable { + return Observable.fromPromise(this.callApiAddTaskComment(id, message)) + .map(res => res.json()) + .map((response: any) => { + let comments: Comment[] = []; + response.data.forEach((comment) => { + let user = new User( + comment.createdBy.id, comment.createdBy.email, comment.createdBy.firstName, comment.createdBy.lastName); + comments.push(new Comment(comment.id, comment.message, comment.created, user)); + }); + return comments; + }) + .catch(this.handleError); + } + + getTaskChecklist(id: string): Observable { + return Observable.fromPromise(this.callApiTaskChecklist(id)) + .map(res => res.json()) + .map((response: any) => { + let checklists: TaskDetailsModel[] = []; + response.data.forEach((checklist) => { + checklists.push(new TaskDetailsModel(checklist)); + }); + return checklists; + }) + .catch(this.handleError); + } + completeTask(id: string): Observable { return Observable.fromPromise(this.callApiCompleteTask(id)) .catch(this.handleError); @@ -114,6 +160,43 @@ export class ActivitiTaskListService { .get(url, options).toPromise(); } + private callApiTaskComments(id: string) { + let url = `${this.basePath}/api/enterprise/tasks/${id}/comments`; + let headers = new Headers({ + 'Content-Type': 'application/json', + 'Cache-Control': 'no-cache' + }); + let options = new RequestOptions({headers: headers}); + + return this.http + .get(url, options).toPromise(); + } + + private callApiAddTaskComment(id: string, message: string) { + let url = `${this.basePath}/api/enterprise/tasks/${id}/comments`; + let headers = new Headers({ + 'Content-Type': 'application/json', + 'Cache-Control': 'no-cache' + }); + let body = JSON.stringify({message: message}); + let options = new RequestOptions({headers: headers}); + + return this.http + .post(url, body, options).toPromise(); + } + + private callApiTaskChecklist(id: string) { + let url = `${this.basePath}/api/enterprise/tasks/${id}/checklist`; + let headers = new Headers({ + 'Content-Type': 'application/json', + 'Cache-Control': 'no-cache' + }); + let options = new RequestOptions({headers: headers}); + + return this.http + .get(url, options).toPromise(); + } + private callApiCompleteTask(id: string) { let url = this.alfrescoSettingsService.getBPMApiBaseUrl() + `/api/enterprise/tasks/${id}/action/complete`; // let url = `http://localhost:9999/activiti-app/app/rest/tasks/${id}/action/complete`;