Commit 0354c7697acecd05c4ad17198f51b20a170f8266
Committed by
Michel Felipe
1 parent
118eeb9d
Exists in
master
and in
6 other branches
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 | 1 | <div class="task-accept task-confirmation"> |
| 2 | 2 | <div class="accept-title confirmation-title">{{"tasks.actions.accept.confirmation.title" | translate}}</div> |
| 3 | 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 | 5 | </div> |
| 6 | 6 | <div class="actions"> |
| 7 | 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 | 1 | <div class="task-reject task-confirmation"> |
| 2 | 2 | <div class="reject-title confirmation-title">{{"tasks.actions.reject.confirmation.title" | translate}}</div> |
| 3 | 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 | 5 | </div> |
| 6 | 6 | <div class="actions"> |
| 7 | 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 | 10 | export class TaskAcceptComponent { |
| 11 | 11 | |
| 12 | 12 | @Input() task: noosfero.Task; |
| 13 | + @Input() confirmationTask: noosfero.Task; | |
| 13 | 14 | |
| 14 | 15 | ngOnInit() { |
| 15 | 16 | let componentName = this.task.type.replace(/::/, '').replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(); |
| 16 | 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 | 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 | 2 | import { NotificationService } from "../../shared/services/notification.service"; |
| 3 | 3 | import { TaskService } from "../../../lib/ng-noosfero-api/http/task.service"; |
| 4 | 4 | import { TaskAcceptComponent } from "./task-accept.component"; |
| 5 | +import { Arrays } from "../../../lib/util/arrays"; | |
| 5 | 6 | |
| 6 | 7 | @Component({ |
| 7 | 8 | selector: "task-list", |
| ... | ... | @@ -15,8 +16,8 @@ export class TaskListComponent { |
| 15 | 16 | |
| 16 | 17 | private taskTemplates = ["AddFriend", "AddMember", "CreateCommunity", "SuggestArticle", "AbuseComplaint"]; |
| 17 | 18 | |
| 18 | - rejectionExplanation: string; | |
| 19 | 19 | currentTask: noosfero.Task; |
| 20 | + confirmationTask: noosfero.Task; | |
| 20 | 21 | private modalInstance: any = null; |
| 21 | 22 | |
| 22 | 23 | constructor(private notificationService: NotificationService, private $scope: ng.IScope, private $uibModal: any, private taskService: TaskService) { } |
| ... | ... | @@ -32,6 +33,7 @@ export class TaskListComponent { |
| 32 | 33 | |
| 33 | 34 | accept(task: noosfero.Task) { |
| 34 | 35 | this.currentTask = task; |
| 36 | + this.confirmationTask = <any>{ id: task.id }; | |
| 35 | 37 | if (task.accept_details) { |
| 36 | 38 | this.modalInstance = this.$uibModal.open({ |
| 37 | 39 | templateUrl: "app/task/task-list/accept.html", |
| ... | ... | @@ -47,6 +49,7 @@ export class TaskListComponent { |
| 47 | 49 | |
| 48 | 50 | reject(task: noosfero.Task) { |
| 49 | 51 | this.currentTask = task; |
| 52 | + this.confirmationTask = <any>{ id: task.id }; | |
| 50 | 53 | if (task.reject_details) { |
| 51 | 54 | this.modalInstance = this.$uibModal.open({ |
| 52 | 55 | templateUrl: "app/task/task-list/reject.html", |
| ... | ... | @@ -61,8 +64,8 @@ export class TaskListComponent { |
| 61 | 64 | } |
| 62 | 65 | |
| 63 | 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 | 69 | this.notificationService.success({ title: "tasks.actions.accept.title", message: "tasks.actions.accept.message" }); |
| 67 | 70 | }).finally(() => { |
| 68 | 71 | this.cancel(); |
| ... | ... | @@ -70,8 +73,8 @@ export class TaskListComponent { |
| 70 | 73 | } |
| 71 | 74 | |
| 72 | 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 | 78 | this.notificationService.success({ title: "tasks.actions.reject.title", message: "tasks.actions.reject.message" }); |
| 76 | 79 | }).finally(() => { |
| 77 | 80 | this.cancel(); |
| ... | ... | @@ -83,19 +86,12 @@ export class TaskListComponent { |
| 83 | 86 | this.modalInstance.close(); |
| 84 | 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 | 93 | private getTemplateName(task: noosfero.Task) { |
| 92 | 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 | 2 | <label>Select Roles:</label> |
| 3 | 3 | <div class="form-group roles"> |
| 4 | 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 | 6 | </div> |
| 7 | 7 | </div> |
| 8 | 8 | </div> | ... | ... |
src/app/task/types/add-member/add-member-task-accept-component.spec.ts
0 → 100644
| ... | ... | @@ -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 | 9 | export class AddMemberTaskAcceptComponent { |
| 10 | 10 | |
| 11 | 11 | @Input() task: noosfero.Task; |
| 12 | + @Input() confirmationTask: noosfero.Task; | |
| 12 | 13 | roles: noosfero.Role[]; |
| 13 | 14 | |
| 14 | 15 | constructor(private roleService: RoleService) { } |
| 15 | 16 | |
| 16 | 17 | ngOnInit() { |
| 17 | 18 | if (!this.task.target) return; |
| 19 | + (<any>this.confirmationTask)['roles'] = []; | |
| 18 | 20 | this.roleService.getByProfile(this.task.target.id).then((result: noosfero.RestResult<noosfero.Role[]>) => { |
| 19 | 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 | 36 | |
| 37 | 37 | private closeTask(task: noosfero.Task, action: string) { |
| 38 | 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 | 41 | let deferred = this.$q.defer<noosfero.RestResult<noosfero.Task>>(); |
| 41 | 42 | put.then(this.getHandleSuccessFunction<noosfero.RestResult<noosfero.Task>>(deferred)); |
| 42 | 43 | put.catch(this.getHandleErrorFunction<noosfero.RestResult<noosfero.Task>>(deferred)); | ... | ... |