-
-
-
-
+
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'));
+ }
+
}