From 018cd8fa734f62098c139ea2488abfa36bb1914c Mon Sep 17 00:00:00 2001 From: Vito Albano Date: Mon, 31 Oct 2016 17:12:48 +0000 Subject: [PATCH] Changed activiti people to manage the new search user window --- .../components/activiti-people.component.css | 4 ++ .../components/activiti-people.component.html | 22 ++++---- .../activiti-people.component.spec.ts | 50 +++++++++++++++++ .../components/activiti-people.component.ts | 55 ++++++++++++------- 4 files changed, 101 insertions(+), 30 deletions(-) create mode 100644 ng2-components/ng2-activiti-tasklist/src/components/activiti-people.component.spec.ts 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 index 7e9e64291f..0578c7e3c3 100644 --- a/ng2-components/ng2-activiti-tasklist/src/components/activiti-people.component.css +++ b/ng2-components/ng2-activiti-tasklist/src/components/activiti-people.component.css @@ -9,3 +9,7 @@ .material-icons:hover { color: rgb(255, 152, 0); } + +.involve-user-padding { + padding: 20px 24px 2px; +} 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 index 5430f9b172..c2c359dec4 100644 --- a/ng2-components/ng2-activiti-tasklist/src/components/activiti-people.component.html +++ b/ng2-components/ng2-activiti-tasklist/src/components/activiti-people.component.html @@ -1,16 +1,19 @@ {{ 'TASK_DETAILS.LABELS.PEOPLE' | translate }}
add
-
+
Add a person
@@ -19,15 +22,14 @@
-

New User

-
-
- - -
+

Involve User

+
+ +
-
diff --git a/ng2-components/ng2-activiti-tasklist/src/components/activiti-people.component.spec.ts b/ng2-components/ng2-activiti-tasklist/src/components/activiti-people.component.spec.ts new file mode 100644 index 0000000000..f8047fbef2 --- /dev/null +++ b/ng2-components/ng2-activiti-tasklist/src/components/activiti-people.component.spec.ts @@ -0,0 +1,50 @@ +/*! + * @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 { + AlfrescoAuthenticationService, + AlfrescoSettingsService, + AlfrescoApiService + } from 'ng2-alfresco-core';*/ +import { AlfrescoTranslationService } from 'ng2-alfresco-core'; +import { ActivitiPeopleService } from '../services/activiti-people.service'; +import { ActivitiPeople } from './activiti-people.component'; +import { ComponentFixture, TestBed, async } from '@angular/core/testing'; + +describe('Activiti People Component', () => { + + let activitiPeopleComponent: ActivitiPeople; + let fixture: ComponentFixture; + let element: HTMLElement; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ActivitiPeople], + providers: [AlfrescoTranslationService, ActivitiPeopleService] + }).compileComponents().then(() => { + fixture = TestBed.createComponent(ActivitiPeople); + activitiPeopleComponent = fixture.componentInstance; + element = fixture.nativeElement; + }); + })); + + it('should not show any image if the user is not logged in', () => { + expect(element.querySelector('#userinfo_container')).toBeDefined(); + expect(element.querySelector('#logged-user-img')).toBeNull(); + }); +}); 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 index a055de8824..5795275b45 100644 --- a/ng2-components/ng2-activiti-tasklist/src/components/activiti-people.component.ts +++ b/ng2-components/ng2-activiti-tasklist/src/components/activiti-people.component.ts @@ -15,10 +15,11 @@ * limitations under the License. */ -import { Component, Input, OnInit, ViewChild } from '@angular/core'; -import { AlfrescoTranslationService, AlfrescoAuthenticationService } from 'ng2-alfresco-core'; +import { Component, Input, ViewChild } from '@angular/core'; +import { AlfrescoTranslationService } from 'ng2-alfresco-core'; import { User } from '../models/user.model'; import { Observer, Observable } from 'rxjs/Rx'; +import { ActivitiPeopleService } from '../services/activiti-people.service'; @Component({ selector: 'activiti-people', @@ -26,35 +27,32 @@ import { Observer, Observable } from 'rxjs/Rx'; templateUrl: './activiti-people.component.html', styleUrls: ['./activiti-people.component.css'] }) -export class ActivitiPeople implements OnInit { +export class ActivitiPeople { @Input() people: User [] = []; + @Input() + taskId: string = ''; + @ViewChild('dialog') dialog: any; - private peopleObserver: Observer; + private peopleObserver: Observer; people$: Observable; /** * Constructor - * @param auth * @param translate + * @param people service */ - constructor(private auth: AlfrescoAuthenticationService, - private translate: AlfrescoTranslationService) { + constructor(private translate: AlfrescoTranslationService, + private peopleService: ActivitiPeopleService) { if (translate) { translate.addTranslationFolder('node_modules/ng2-activiti-tasklist/src'); } - this.people$ = new Observable(observer => this.peopleObserver = observer).share(); - } - - ngOnInit() { - this.people$.subscribe((user: User) => { - this.people.push(user); - }); + this.people$ = new Observable(observer => this.peopleObserver = observer).share(); } public showDialog() { @@ -66,16 +64,33 @@ export class ActivitiPeople implements OnInit { } } - public add() { - alert('add people'); - - this.cancel(); - } - public cancel() { if (this.dialog) { this.dialog.nativeElement.close(); } } + searchUser(searchedWord: string) { + this.peopleService.getWorkflowUsers(this.taskId, searchedWord) + .subscribe((users) => { + this.peopleObserver.next(users); + }, error => console.log('Could not load users')); + } + + involveUser(user: User) { + this.peopleService.involveUserWithTask(this.taskId, user.id.toString()) + .subscribe(() => { + this.people.push(user); + }, error => console.error('Impossible to involve user with task')); + } + + removeInvolvedUser(user: User) { + this.peopleService.removeInvolvedUser(this.taskId, user.id.toString()) + .subscribe(() => { + this.people = this.people.filter((involvedUser) => { + return involvedUser.id !== user.id; + }); + }, error => console.error('Impossible to remove involved user from task')); + } + }