[ADF-794] Add people assignment component (#1977)

* Add people component

* exported people service

* added people-list component to show the involved user list

* changed people-search component layout

* changed people-list usage in people component

* changed people-list data table from custom template to data adapter

* changes people-search component related to people-list

* changes in activiti-people related to people-list and people-search component

* changed data adapter to direct data column setting to data-table

* removed ngChanges and added User and UserEvent models

* added User and UserEvent model in emitter and other emitter handler

* added user event model

* changed activiti-people component with latest UX changes

* addedand changed translate keys to the components

* added hasUser method to check the condition in html

* fixed tslint issue and test case issue in activiti-people component

* added test case for actviti-people-list component

* test case added for activiti-people-search component

* changed activiti-people test cases according to latest UX changes

* added description for activiti-people component

* changed test case to fix component.upgradeElement issue

* changes requested by Vito Albano #1

* splitted getDisplayUser into getDisplayUser and getInitialUsername
This commit is contained in:
Infad Kachancheri 2017-06-21 14:02:48 +05:30 committed by Eugenio Romano
parent 5aa5ac9e57
commit 58340384fc
4 changed files with 206 additions and 0 deletions

View File

@ -0,0 +1,7 @@
<alfresco-datatable
[rows]="users"
[actions]="hasActions()"
(rowClick)="selectUser($event)"
(showRowActionsMenu)="onShowRowActionsMenu($event)"
(executeRowAction)="onExecuteRowAction($event)">
</alfresco-datatable>

View File

@ -0,0 +1,100 @@
/*!
* @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 { ComponentFixture, TestBed, async } from '@angular/core/testing';
import { Observable } from 'rxjs/Observable';
import { CoreModule, AlfrescoTranslationService } from 'ng2-alfresco-core';
import { ActivitiPeopleList } from './activiti-people-list.component';
import { User, UserEventModel } from '../models/index';
import { DataTableModule, ObjectDataRow, DataRowEvent, DataRowActionEvent } from 'ng2-alfresco-datatable';
declare let jasmine: any;
const fakeUser: User = new User({
id: '1',
firstName: 'fake-name',
lastName: 'fake-last',
email: 'fake@mail.com'
});
describe('ActivitiPeopleList', () => {
let activitiPeopleListComponent: ActivitiPeopleList;
let fixture: ComponentFixture<ActivitiPeopleList>;
let element: HTMLElement;
let componentHandler;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
CoreModule.forRoot(),
DataTableModule
],
declarations: [
ActivitiPeopleList
]
}).compileComponents().then(() => {
let translateService = TestBed.get(AlfrescoTranslationService);
spyOn(translateService, 'addTranslationFolder').and.stub();
spyOn(translateService.translate, 'get').and.callFake((key) => { return Observable.of(key); });
fixture = TestBed.createComponent(ActivitiPeopleList);
activitiPeopleListComponent = fixture.componentInstance;
element = fixture.nativeElement;
componentHandler = jasmine.createSpyObj('componentHandler', [
'upgradeAllRegistered'
]);
window['componentHandler'] = componentHandler;
fixture.detectChanges();
});
}));
it('should emit row click event', (done) => {
let row = new ObjectDataRow(fakeUser);
let rowEvent = new DataRowEvent(row, null);
activitiPeopleListComponent.clickRow.subscribe(selectedUser => {
expect(selectedUser.id).toEqual('1');
expect(selectedUser.email).toEqual('fake@mail.com');
expect(activitiPeopleListComponent.user.id).toEqual('1');
expect(activitiPeopleListComponent.user.email).toEqual('fake@mail.com');
done();
});
activitiPeopleListComponent.selectUser(rowEvent);
});
it('should emit row action event', (done) => {
let row = new ObjectDataRow(fakeUser);
let removeObj = {
name: 'remove',
title: 'Remove'
};
let rowActionEvent = new DataRowActionEvent(row, removeObj);
activitiPeopleListComponent.clickAction.subscribe((selectedAction: UserEventModel) => {
expect(selectedAction.type).toEqual('remove');
expect(selectedAction.value.id).toEqual('1');
expect(selectedAction.value.email).toEqual('fake@mail.com');
done();
});
activitiPeopleListComponent.onExecuteRowAction(rowActionEvent);
});
});

View File

@ -0,0 +1,99 @@
/*!
* @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 { Component, Input, Output, EventEmitter, ViewChild, ContentChild } from '@angular/core';
import { User, UserEventModel } from '../models/index';
import { DataColumnListComponent } from 'ng2-alfresco-core';
import { DataTableComponent } from 'ng2-alfresco-datatable';
declare let componentHandler: any;
@Component({
selector: 'activiti-people-list',
templateUrl: './activiti-people-list.component.html',
styleUrls: ['./activiti-people-list.component.css']
})
export class ActivitiPeopleList {
@ContentChild(DataColumnListComponent) columnList: DataColumnListComponent;
@ViewChild(DataTableComponent)
peopleDataTable: DataTableComponent;
@Input()
users: User[];
@Input()
actions: boolean = false;
@Output()
clickRow: EventEmitter<User> = new EventEmitter<User>();
@Output()
clickAction: EventEmitter<UserEventModel> = new EventEmitter<UserEventModel>();
user: User;
constructor() {
}
ngAfterContentInit() {
this.peopleDataTable.columnList = this.columnList;
}
ngAfterViewInit() {
this.setupMaterialComponents(componentHandler);
}
setupMaterialComponents(handler?: any): boolean {
// workaround for MDL issues with dynamic components
let isUpgraded: boolean = false;
if (handler) {
handler.upgradeAllRegistered();
isUpgraded = true;
}
return isUpgraded;
}
selectUser(event: any) {
this.user = event.value.obj;
this.clickRow.emit(this.user);
}
hasActions(): boolean {
return this.actions;
}
onShowRowActionsMenu(event: any) {
let removeAction = {
title: 'Remove',
name: 'remove'
};
event.value.actions = [
removeAction
];
}
onExecuteRowAction(event: any) {
let args = event.value;
let action = args.action;
this.clickAction.emit(new UserEventModel({type: action.name, value: args.row.obj}));
}
}