Changed activiti people to manage the new search user window

This commit is contained in:
Vito Albano 2016-10-31 17:12:48 +00:00
parent e33c5d9859
commit 018cd8fa73
4 changed files with 101 additions and 30 deletions

View File

@ -9,3 +9,7 @@
.material-icons:hover { .material-icons:hover {
color: rgb(255, 152, 0); color: rgb(255, 152, 0);
} }
.involve-user-padding {
padding: 20px 24px 2px;
}

View File

@ -1,16 +1,19 @@
<span class="activiti-label mdl-badge" <span class="activiti-label mdl-badge"
[attr.data-badge]="people?.length">{{ 'TASK_DETAILS.LABELS.PEOPLE' | translate }}</span> [attr.data-badge]="people?.length">{{ 'TASK_DETAILS.LABELS.PEOPLE' | translate }}</span>
<div id="addPeople" (click)="showDialog()" class="icon material-icons">add</div> <div id="addPeople" (click)="showDialog()" class="icon material-icons">add</div>
<div class="mdl-tooltip" for="addPeople"> <div class="mdl-tooltip" data-mdl-for="addPeople">
Add a person Add a person
</div> </div>
<div class="menu-container" *ngIf="people?.length > 0"> <div class="menu-container" *ngIf="people?.length > 0">
<ul class='mdl-list'> <ul class='mdl-list'>
<li class="mdl-list__item" *ngFor="let user of people"> <li class="mdl-list__item" *ngFor="let user of people">
<span class="mdl-list__item-primary-content"> <span class="mdl-list__item-primary-content">
<i class="material-icons mdl-list__item-icon">face</i> <i class="material-icons mdl-list__item-icon">face</i>
{{user.firstName}} <span>{{user.firstName}} {{user.lastName}}</span>
</span> </span>
<a class="mdl-list__item-secondary-action">
<i id="remove" class="material-icons" (click)="removeInvolvedUser(user)">delete</i>
</a>
</li> </li>
</ul> </ul>
</div> </div>
@ -19,15 +22,14 @@
</div> </div>
<dialog class="mdl-dialog" #dialog> <dialog class="mdl-dialog" #dialog>
<h4 class="mdl-dialog__title">New User</h4> <h4 class="mdl-dialog__title">Involve User</h4>
<div class="mdl-dialog__content"> <div class="mdl-dialog__content involve-user-padding">
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label"> <activiti-people-search (onSearch)="searchUser($event)"
<input class="mdl-textfield__input" type="text" id="people" /> (onModalRowClicked)="involveUser($event)"
<label class="mdl-textfield__label" for="people">Name</label> [results]="people$">
</div> </activiti-people-search>
</div> </div>
<div class="mdl-dialog__actions"> <div class="mdl-dialog__actions">
<button type="button" (click)="add()" class="mdl-button">Add User</button>
<button type="button" (click)="cancel()" class="mdl-button close">Cancel</button> <button type="button" (click)="cancel()" class="mdl-button close">Cancel</button>
</div> </div>
</dialog> </dialog>

View File

@ -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<ActivitiPeople>;
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();
});
});

View File

@ -15,10 +15,11 @@
* limitations under the License. * limitations under the License.
*/ */
import { Component, Input, OnInit, ViewChild } from '@angular/core'; import { Component, Input, ViewChild } from '@angular/core';
import { AlfrescoTranslationService, AlfrescoAuthenticationService } from 'ng2-alfresco-core'; import { AlfrescoTranslationService } from 'ng2-alfresco-core';
import { User } from '../models/user.model'; import { User } from '../models/user.model';
import { Observer, Observable } from 'rxjs/Rx'; import { Observer, Observable } from 'rxjs/Rx';
import { ActivitiPeopleService } from '../services/activiti-people.service';
@Component({ @Component({
selector: 'activiti-people', selector: 'activiti-people',
@ -26,35 +27,32 @@ import { Observer, Observable } from 'rxjs/Rx';
templateUrl: './activiti-people.component.html', templateUrl: './activiti-people.component.html',
styleUrls: ['./activiti-people.component.css'] styleUrls: ['./activiti-people.component.css']
}) })
export class ActivitiPeople implements OnInit { export class ActivitiPeople {
@Input() @Input()
people: User [] = []; people: User [] = [];
@Input()
taskId: string = '';
@ViewChild('dialog') @ViewChild('dialog')
dialog: any; dialog: any;
private peopleObserver: Observer<User>; private peopleObserver: Observer<User[]>;
people$: Observable<User>; people$: Observable<User>;
/** /**
* Constructor * Constructor
* @param auth
* @param translate * @param translate
* @param people service
*/ */
constructor(private auth: AlfrescoAuthenticationService, constructor(private translate: AlfrescoTranslationService,
private translate: AlfrescoTranslationService) { private peopleService: ActivitiPeopleService) {
if (translate) { if (translate) {
translate.addTranslationFolder('node_modules/ng2-activiti-tasklist/src'); translate.addTranslationFolder('node_modules/ng2-activiti-tasklist/src');
} }
this.people$ = new Observable<User>(observer => this.peopleObserver = observer).share(); this.people$ = new Observable<User>(observer => this.peopleObserver = observer).share();
}
ngOnInit() {
this.people$.subscribe((user: User) => {
this.people.push(user);
});
} }
public showDialog() { public showDialog() {
@ -66,16 +64,33 @@ export class ActivitiPeople implements OnInit {
} }
} }
public add() {
alert('add people');
this.cancel();
}
public cancel() { public cancel() {
if (this.dialog) { if (this.dialog) {
this.dialog.nativeElement.close(); 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'));
}
} }