Commit 00341879e57ec4143b7bf3a4e90be5b0206599eb
1 parent
0af91d99
Accept parameters when accept/reject tasks
Showing
8 changed files
with
72 additions
and
19 deletions
Show diff stats
src/app/task/task-list/accept.html
1 | <div class="task-accept task-confirmation"> | 1 | <div class="task-accept task-confirmation"> |
2 | <div class="accept-title confirmation-title">{{"tasks.actions.accept.confirmation.title" | translate}}</div> | 2 | <div class="accept-title confirmation-title">{{"tasks.actions.accept.confirmation.title" | translate}}</div> |
3 | <div class="accept-fields confirmation-details"> | 3 | <div class="accept-fields confirmation-details"> |
4 | - <task-accept ng-if="ctrl.currentTask.accept_details" [task]="ctrl.currentTask"></task-accept> | 4 | + <task-accept ng-if="ctrl.currentTask.accept_details" [task]="ctrl.currentTask" [confirmation-task]="ctrl.confirmationTask"></task-accept> |
5 | </div> | 5 | </div> |
6 | <div class="actions"> | 6 | <div class="actions"> |
7 | <button type="submit" class="btn btn-default" ng-click="ctrl.callAccept()">{{"tasks.actions.confirmation.yes" | translate}}</button> | 7 | <button type="submit" class="btn btn-default" ng-click="ctrl.callAccept()">{{"tasks.actions.confirmation.yes" | translate}}</button> |
src/app/task/task-list/reject.html
1 | <div class="task-reject task-confirmation"> | 1 | <div class="task-reject task-confirmation"> |
2 | <div class="reject-title confirmation-title">{{"tasks.actions.reject.confirmation.title" | translate}}</div> | 2 | <div class="reject-title confirmation-title">{{"tasks.actions.reject.confirmation.title" | translate}}</div> |
3 | <div class="reject-fields confirmation-details"> | 3 | <div class="reject-fields confirmation-details"> |
4 | - <input ng-model="ctrl.rejectionExplanation" id="rejectionExplanationInput" type="text" placeholder="{{'tasks.actions.reject.explanation.label' | translate}}" class="rejection-explanation form-control"> | 4 | + <input ng-model="ctrl.confirmationTask.reject_explanation" id="rejectionExplanationInput" type="text" placeholder="{{'tasks.actions.reject.explanation.label' | translate}}" class="rejection-explanation form-control"> |
5 | </div> | 5 | </div> |
6 | <div class="actions"> | 6 | <div class="actions"> |
7 | <button type="submit" class="btn btn-default" ng-click="ctrl.callReject()">{{"tasks.actions.confirmation.yes" | translate}}</button> | 7 | <button type="submit" class="btn btn-default" ng-click="ctrl.callReject()">{{"tasks.actions.confirmation.yes" | translate}}</button> |
src/app/task/task-list/task-accept.component.ts
@@ -10,11 +10,12 @@ import { AddMemberTaskAcceptComponent } from "../types/add-member/add-member-tas | @@ -10,11 +10,12 @@ import { AddMemberTaskAcceptComponent } from "../types/add-member/add-member-tas | ||
10 | export class TaskAcceptComponent { | 10 | export class TaskAcceptComponent { |
11 | 11 | ||
12 | @Input() task: noosfero.Task; | 12 | @Input() task: noosfero.Task; |
13 | + @Input() confirmationTask: noosfero.Task; | ||
13 | 14 | ||
14 | ngOnInit() { | 15 | ngOnInit() { |
15 | let componentName = this.task.type.replace(/::/, '').replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(); | 16 | let componentName = this.task.type.replace(/::/, '').replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(); |
16 | componentName += "-task-accept"; | 17 | componentName += "-task-accept"; |
17 | - this.$element.replaceWith(this.$compile(`<${componentName} [task]="ctrl.task"></${componentName}>`)(this.$scope)); | 18 | + this.$element.replaceWith(this.$compile(`<${componentName} [task]="ctrl.task" [confirmation-task]="ctrl.confirmationTask"></${componentName}>`)(this.$scope)); |
18 | } | 19 | } |
19 | 20 | ||
20 | constructor(private $element: any, private $scope: ng.IScope, private $injector: ng.auto.IInjectorService, private $compile: ng.ICompileService) { } | 21 | constructor(private $element: any, private $scope: ng.IScope, private $injector: ng.auto.IInjectorService, private $compile: ng.ICompileService) { } |
src/app/task/task-list/task-list.component.ts
@@ -2,6 +2,7 @@ import { Component, Input, Inject } from "ng-forward"; | @@ -2,6 +2,7 @@ import { Component, Input, Inject } from "ng-forward"; | ||
2 | import { NotificationService } from "../../shared/services/notification.service"; | 2 | import { NotificationService } from "../../shared/services/notification.service"; |
3 | import { TaskService } from "../../../lib/ng-noosfero-api/http/task.service"; | 3 | import { TaskService } from "../../../lib/ng-noosfero-api/http/task.service"; |
4 | import { TaskAcceptComponent } from "./task-accept.component"; | 4 | import { TaskAcceptComponent } from "./task-accept.component"; |
5 | +import { Arrays } from "../../../lib/util/arrays"; | ||
5 | 6 | ||
6 | @Component({ | 7 | @Component({ |
7 | selector: "task-list", | 8 | selector: "task-list", |
@@ -15,8 +16,8 @@ export class TaskListComponent { | @@ -15,8 +16,8 @@ export class TaskListComponent { | ||
15 | 16 | ||
16 | private taskTemplates = ["AddFriend", "AddMember", "CreateCommunity", "SuggestArticle", "AbuseComplaint"]; | 17 | private taskTemplates = ["AddFriend", "AddMember", "CreateCommunity", "SuggestArticle", "AbuseComplaint"]; |
17 | 18 | ||
18 | - rejectionExplanation: string; | ||
19 | currentTask: noosfero.Task; | 19 | currentTask: noosfero.Task; |
20 | + confirmationTask: noosfero.Task; | ||
20 | private modalInstance: any = null; | 21 | private modalInstance: any = null; |
21 | 22 | ||
22 | constructor(private notificationService: NotificationService, private $scope: ng.IScope, private $uibModal: any, private taskService: TaskService) { } | 23 | constructor(private notificationService: NotificationService, private $scope: ng.IScope, private $uibModal: any, private taskService: TaskService) { } |
@@ -32,6 +33,7 @@ export class TaskListComponent { | @@ -32,6 +33,7 @@ export class TaskListComponent { | ||
32 | 33 | ||
33 | accept(task: noosfero.Task) { | 34 | accept(task: noosfero.Task) { |
34 | this.currentTask = task; | 35 | this.currentTask = task; |
36 | + this.confirmationTask = <any>{ id: task.id }; | ||
35 | if (task.accept_details) { | 37 | if (task.accept_details) { |
36 | this.modalInstance = this.$uibModal.open({ | 38 | this.modalInstance = this.$uibModal.open({ |
37 | templateUrl: "app/task/task-list/accept.html", | 39 | templateUrl: "app/task/task-list/accept.html", |
@@ -47,6 +49,7 @@ export class TaskListComponent { | @@ -47,6 +49,7 @@ export class TaskListComponent { | ||
47 | 49 | ||
48 | reject(task: noosfero.Task) { | 50 | reject(task: noosfero.Task) { |
49 | this.currentTask = task; | 51 | this.currentTask = task; |
52 | + this.confirmationTask = <any>{ id: task.id }; | ||
50 | if (task.reject_details) { | 53 | if (task.reject_details) { |
51 | this.modalInstance = this.$uibModal.open({ | 54 | this.modalInstance = this.$uibModal.open({ |
52 | templateUrl: "app/task/task-list/reject.html", | 55 | templateUrl: "app/task/task-list/reject.html", |
@@ -61,8 +64,8 @@ export class TaskListComponent { | @@ -61,8 +64,8 @@ export class TaskListComponent { | ||
61 | } | 64 | } |
62 | 65 | ||
63 | callAccept() { | 66 | callAccept() { |
64 | - this.taskService.finishTask(this.currentTask).then(() => { | ||
65 | - this.removeTask(this.currentTask); | 67 | + this.taskService.finishTask(this.confirmationTask).then(() => { |
68 | + Arrays.remove(this.tasks, this.currentTask); | ||
66 | this.notificationService.success({ title: "tasks.actions.accept.title", message: "tasks.actions.accept.message" }); | 69 | this.notificationService.success({ title: "tasks.actions.accept.title", message: "tasks.actions.accept.message" }); |
67 | }).finally(() => { | 70 | }).finally(() => { |
68 | this.cancel(); | 71 | this.cancel(); |
@@ -70,8 +73,8 @@ export class TaskListComponent { | @@ -70,8 +73,8 @@ export class TaskListComponent { | ||
70 | } | 73 | } |
71 | 74 | ||
72 | callReject() { | 75 | callReject() { |
73 | - this.taskService.cancelTask(this.currentTask).then(() => { | ||
74 | - this.removeTask(this.currentTask); | 76 | + this.taskService.cancelTask(this.confirmationTask).then(() => { |
77 | + Arrays.remove(this.tasks, this.currentTask); | ||
75 | this.notificationService.success({ title: "tasks.actions.reject.title", message: "tasks.actions.reject.message" }); | 78 | this.notificationService.success({ title: "tasks.actions.reject.title", message: "tasks.actions.reject.message" }); |
76 | }).finally(() => { | 79 | }).finally(() => { |
77 | this.cancel(); | 80 | this.cancel(); |
@@ -83,19 +86,12 @@ export class TaskListComponent { | @@ -83,19 +86,12 @@ export class TaskListComponent { | ||
83 | this.modalInstance.close(); | 86 | this.modalInstance.close(); |
84 | this.modalInstance = null; | 87 | this.modalInstance = null; |
85 | } | 88 | } |
86 | - if (this.currentTask) { | ||
87 | - this.currentTask = null; | ||
88 | - } | 89 | + this.currentTask = null; |
90 | + this.confirmationTask = null; | ||
89 | } | 91 | } |
90 | 92 | ||
91 | private getTemplateName(task: noosfero.Task) { | 93 | private getTemplateName(task: noosfero.Task) { |
92 | return task.type.replace(/::/, '').replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(); | 94 | return task.type.replace(/::/, '').replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(); |
93 | } | 95 | } |
94 | 96 | ||
95 | - private removeTask(task: noosfero.Task) { | ||
96 | - let index = this.tasks.map((t: noosfero.Task) => { return t.id; }).indexOf(task.id); | ||
97 | - if (index > -1) { | ||
98 | - this.tasks.splice(index, 1); | ||
99 | - } | ||
100 | - } | ||
101 | } | 97 | } |
src/app/task/types/add-member/add-member-accept.html
@@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
2 | <label>Select Roles:</label> | 2 | <label>Select Roles:</label> |
3 | <div class="form-group roles"> | 3 | <div class="form-group roles"> |
4 | <div class="checkbox" ng-repeat="role in ctrl.roles"> | 4 | <div class="checkbox" ng-repeat="role in ctrl.roles"> |
5 | - <input type="checkbox"> {{role.name}} | 5 | + <input type="checkbox" ng-click="ctrl.toggleSelection(role)"> {{role.name}} |
6 | </div> | 6 | </div> |
7 | </div> | 7 | </div> |
8 | </div> | 8 | </div> |
src/app/task/types/add-member/add-member-task-accept-component.spec.ts
0 → 100644
@@ -0,0 +1,44 @@ | @@ -0,0 +1,44 @@ | ||
1 | +import { Provider, provide, Component } from 'ng-forward'; | ||
2 | +import * as helpers from "../../../../spec/helpers"; | ||
3 | +import { ComponentTestHelper, createClass } from '../../../../spec/component-test-helper'; | ||
4 | +import { AddMemberTaskAcceptComponent } from './add-member-task-accept.component'; | ||
5 | + | ||
6 | +const htmlTemplate: string = '<add-member-task-accept [task]="ctrl.task" [confirmation-task]="ctrl.confirmationTask"></add-member-task-accept>'; | ||
7 | + | ||
8 | +describe("Components", () => { | ||
9 | + describe("Add Member Task Accept Component", () => { | ||
10 | + | ||
11 | + let helper: ComponentTestHelper<AddMemberTaskAcceptComponent>; | ||
12 | + let roleService = jasmine.createSpyObj("roleService", ["getByProfile"]); | ||
13 | + let roles = [{ id: 1 }, { id: 2 }]; | ||
14 | + let task = <any>{ target: { id: 5 } }; | ||
15 | + roleService.getByProfile = jasmine.createSpy("getByProfile").and.returnValue(Promise.resolve({ headers: () => { }, data: roles })); | ||
16 | + | ||
17 | + beforeEach(angular.mock.module("templates")); | ||
18 | + | ||
19 | + beforeEach((done) => { | ||
20 | + let cls = createClass({ | ||
21 | + template: htmlTemplate, | ||
22 | + directives: [AddMemberTaskAcceptComponent], | ||
23 | + providers: [ | ||
24 | + helpers.createProviderToValue("RoleService", roleService) | ||
25 | + ].concat(helpers.provideFilters("translateFilter")), | ||
26 | + properties: { task: task, confirmationTask: task } | ||
27 | + }); | ||
28 | + helper = new ComponentTestHelper<AddMemberTaskAcceptComponent>(cls, done); | ||
29 | + }); | ||
30 | + | ||
31 | + it("insert role id in roles list when toggle selection", () => { | ||
32 | + let role = { id: 1 }; | ||
33 | + helper.component.toggleSelection(<any>role); | ||
34 | + expect((<any>helper.component.confirmationTask)['roles']).toEqual([role.id]); | ||
35 | + }); | ||
36 | + | ||
37 | + it("remove role id from roles list when toggle selection", () => { | ||
38 | + let role = { id: 1 }; | ||
39 | + (<any>helper.component.confirmationTask)['roles'] = [role.id]; | ||
40 | + helper.component.toggleSelection(<any>role); | ||
41 | + expect((<any>helper.component.confirmationTask)['roles']).toEqual([]); | ||
42 | + }); | ||
43 | + }); | ||
44 | +}); |
src/app/task/types/add-member/add-member-task-accept.component.ts
@@ -9,14 +9,25 @@ import { RoleService } from "../../../../lib/ng-noosfero-api/http/role.service"; | @@ -9,14 +9,25 @@ import { RoleService } from "../../../../lib/ng-noosfero-api/http/role.service"; | ||
9 | export class AddMemberTaskAcceptComponent { | 9 | export class AddMemberTaskAcceptComponent { |
10 | 10 | ||
11 | @Input() task: noosfero.Task; | 11 | @Input() task: noosfero.Task; |
12 | + @Input() confirmationTask: noosfero.Task; | ||
12 | roles: noosfero.Role[]; | 13 | roles: noosfero.Role[]; |
13 | 14 | ||
14 | constructor(private roleService: RoleService) { } | 15 | constructor(private roleService: RoleService) { } |
15 | 16 | ||
16 | ngOnInit() { | 17 | ngOnInit() { |
17 | if (!this.task.target) return; | 18 | if (!this.task.target) return; |
19 | + (<any>this.confirmationTask)['roles'] = []; | ||
18 | this.roleService.getByProfile(this.task.target.id).then((result: noosfero.RestResult<noosfero.Role[]>) => { | 20 | this.roleService.getByProfile(this.task.target.id).then((result: noosfero.RestResult<noosfero.Role[]>) => { |
19 | this.roles = result.data; | 21 | this.roles = result.data; |
20 | }); | 22 | }); |
21 | } | 23 | } |
24 | + | ||
25 | + toggleSelection(role: noosfero.Role) { | ||
26 | + let index = (<any>this.confirmationTask)['roles'].indexOf(role.id); | ||
27 | + if (index >= 0) { | ||
28 | + (<any>this.confirmationTask)['roles'].splice(index, 1); | ||
29 | + } else { | ||
30 | + (<any>this.confirmationTask)['roles'].push(role.id); | ||
31 | + } | ||
32 | + } | ||
22 | } | 33 | } |
src/lib/ng-noosfero-api/http/task.service.ts
@@ -36,7 +36,8 @@ export class TaskService extends RestangularService<noosfero.Task> { | @@ -36,7 +36,8 @@ export class TaskService extends RestangularService<noosfero.Task> { | ||
36 | 36 | ||
37 | private closeTask(task: noosfero.Task, action: string) { | 37 | private closeTask(task: noosfero.Task, action: string) { |
38 | let element = this.getElement(task.id); | 38 | let element = this.getElement(task.id); |
39 | - let put = element.customPUT(null, action); | 39 | + delete task.id; |
40 | + let put = element.customPUT({ task: task }, action); | ||
40 | let deferred = this.$q.defer<noosfero.RestResult<noosfero.Task>>(); | 41 | let deferred = this.$q.defer<noosfero.RestResult<noosfero.Task>>(); |
41 | put.then(this.getHandleSuccessFunction<noosfero.RestResult<noosfero.Task>>(deferred)); | 42 | put.then(this.getHandleSuccessFunction<noosfero.RestResult<noosfero.Task>>(deferred)); |
42 | put.catch(this.getHandleErrorFunction<noosfero.RestResult<noosfero.Task>>(deferred)); | 43 | put.catch(this.getHandleErrorFunction<noosfero.RestResult<noosfero.Task>>(deferred)); |