fix user model process service and image loading (#2431)

This commit is contained in:
Eugenio Romano
2017-10-05 22:35:14 +01:00
committed by GitHub
parent f9302869d1
commit ad13bcafd6
41 changed files with 188 additions and 314 deletions

View File

@@ -1,39 +0,0 @@
/*!
* @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 { GroupUserModel } from './group-user.model';
describe('GroupUserModel', () => {
it('should init with json', () => {
let json = {
company: '<company>',
email: '<email>',
firstName: '<firstName>',
id: '<id>',
lastName: '<lastName>'
};
let model = new GroupUserModel(json);
expect(model.company).toBe(json.company);
expect(model.email).toBe(json.email);
expect(model.firstName).toBe(json.firstName);
expect(model.id).toBe(json.id);
expect(model.lastName).toBe(json.lastName);
});
});

View File

@@ -23,10 +23,9 @@
<div class="adf-people-widget-pic">
{{getInitialUserName(user.firstName, user.lastName)}}
</div>
<div *ngIf="user.userImage" class="adf-people-widget-image-row">
<div *ngIf="user.pictureId" class="adf-people-widget-image-row">
<img id="adf-people-widget-pic-{{i}}" class="adf-people-widget-image"
[src]="user.userImage"
(error)="onErrorImageLoad(user)"/>
[src]="peopleProcessService.getUserImage(user)"/>
</div>
<span class="adf-people-label-name">{{getDisplayName(user)}}</span>
</div>

View File

@@ -16,14 +16,13 @@
*/
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { CoreModule } from 'ng2-alfresco-core';
import { CoreModule, LightUserRepresentation } from 'ng2-alfresco-core';
import { Observable } from 'rxjs/Rx';
import { ActivitiAlfrescoContentService } from '../../../services/activiti-alfresco.service';
import { FormService } from '../../../services/form.service';
import { MaterialModule } from '../../material.module';
import { FormFieldModel } from '../core/form-field.model';
import { FormModel } from '../core/form.model';
import { GroupUserModel } from '../core/group-user.model';
import { ErrorWidgetComponent } from '../error/error.component';
import { EcmModelService } from './../../../services/ecm-model.service';
import { PeopleWidgetComponent } from './people.widget';
@@ -68,7 +67,7 @@ describe('PeopleWidgetComponent', () => {
});
it('should return full name for a given model', () => {
let model = new GroupUserModel({
let model = new LightUserRepresentation({
firstName: 'John',
lastName: 'Doe'
});
@@ -76,17 +75,17 @@ describe('PeopleWidgetComponent', () => {
});
it('should skip first name for display name', () => {
let model = new GroupUserModel({firstName: null, lastName: 'Doe'});
let model = new LightUserRepresentation({firstName: null, lastName: 'Doe'});
expect(widget.getDisplayName(model)).toBe('Doe');
});
it('should skip last name for display name', () => {
let model = new GroupUserModel({firstName: 'John', lastName: null});
let model = new LightUserRepresentation({firstName: 'John', lastName: null});
expect(widget.getDisplayName(model)).toBe('John');
});
it('should init value from the field', () => {
widget.field.value = new GroupUserModel({
widget.field.value = new LightUserRepresentation({
firstName: 'John',
lastName: 'Doe'
});
@@ -109,7 +108,7 @@ describe('PeopleWidgetComponent', () => {
});
it('should update values on item click', () => {
let item = new GroupUserModel({firstName: 'John', lastName: 'Doe'});
let item = new LightUserRepresentation({firstName: 'John', lastName: 'Doe'});
widget.onItemClick(item, null);
expect(widget.field.value).toBe(item);
@@ -213,8 +212,8 @@ describe('PeopleWidgetComponent', () => {
it('should flush value and update field', () => {
widget.users = [
new GroupUserModel({firstName: 'Tony', lastName: 'Stark'}),
new GroupUserModel({firstName: 'John', lastName: 'Doe'})
new LightUserRepresentation({firstName: 'Tony', lastName: 'Stark'}),
new LightUserRepresentation({firstName: 'John', lastName: 'Doe'})
];
widget.value = 'John Doe';
widget.flushValue();
@@ -225,8 +224,8 @@ describe('PeopleWidgetComponent', () => {
it('should be case insensitive when flushing field', () => {
widget.users = [
new GroupUserModel({firstName: 'Tony', lastName: 'Stark'}),
new GroupUserModel({firstName: 'John', lastName: 'Doe'})
new LightUserRepresentation({firstName: 'Tony', lastName: 'Stark'}),
new LightUserRepresentation({firstName: 'John', lastName: 'Doe'})
];
widget.value = 'TONY sTaRk';
widget.flushValue();

View File

@@ -20,8 +20,8 @@
import { ENTER, ESCAPE } from '@angular/cdk/keycodes';
import { Component, OnInit, ViewChild, ViewEncapsulation } from '@angular/core';
import { MdAutocompleteTrigger } from '@angular/material';
import { LightUserRepresentation, PeopleProcessService } from 'ng2-alfresco-core';
import { FormService } from '../../../services/form.service';
import { GroupUserModel } from '../core/group-user.model';
import { GroupModel } from '../core/group.model';
import { baseHost , WidgetComponent } from './../widget.component';
@@ -40,16 +40,16 @@ export class PeopleWidgetComponent extends WidgetComponent implements OnInit {
minTermLength: number = 1;
value: string;
oldValue: string;
users: GroupUserModel[] = [];
users: LightUserRepresentation[] = [];
groupId: string;
constructor(public formService: FormService) {
constructor(public formService: FormService, public peopleProcessService: PeopleProcessService) {
super(formService);
}
ngOnInit() {
if (this.field) {
let user: GroupUserModel = this.field.value;
let user: LightUserRepresentation = this.field.value;
if (user) {
this.value = this.getDisplayName(user);
}
@@ -75,17 +75,11 @@ export class PeopleWidgetComponent extends WidgetComponent implements OnInit {
searchUsers() {
this.formService.getWorkflowUsers(this.value, this.groupId)
.subscribe((result: GroupUserModel[]) => {
.subscribe((result: LightUserRepresentation[]) => {
this.users = result || [];
});
}
onErrorImageLoad(user) {
if (user.userImage) {
user.userImage = null;
}
}
flushValue() {
let option = this.users.find(item => {
let fullName = this.getDisplayName(item).toLocaleLowerCase();
@@ -103,7 +97,7 @@ export class PeopleWidgetComponent extends WidgetComponent implements OnInit {
this.field.updateForm();
}
getDisplayName(model: GroupUserModel) {
getDisplayName(model: LightUserRepresentation) {
if (model) {
let displayName = `${model.firstName || ''} ${model.lastName || ''}`;
return displayName.trim();
@@ -112,7 +106,7 @@ export class PeopleWidgetComponent extends WidgetComponent implements OnInit {
return '';
}
onItemClick(item: GroupUserModel, event: Event) {
onItemClick(item: LightUserRepresentation, event: Event) {
if (item) {
this.field.value = item;
this.value = this.getDisplayName(item);
@@ -122,7 +116,7 @@ export class PeopleWidgetComponent extends WidgetComponent implements OnInit {
}
}
onItemSelect(item: GroupUserModel) {
onItemSelect(item: LightUserRepresentation) {
if (item) {
this.field.value = item;
this.value = this.getDisplayName(item);

View File

@@ -16,11 +16,10 @@
*/
import { Injectable } from '@angular/core';
import { AlfrescoApiService, LogService } from 'ng2-alfresco-core';
import { AlfrescoApiService, LightUserRepresentation, LogService } from 'ng2-alfresco-core';
import { Observable, Subject } from 'rxjs/Rx';
import { FormDefinitionModel } from '../models/form-definition.model';
import { ContentLinkModel } from './../components/widgets/core/content-link.model';
import { GroupUserModel } from './../components/widgets/core/group-user.model';
import { GroupModel } from './../components/widgets/core/group.model';
import { FormModel, FormOutcomeEvent, FormOutcomeModel, FormValues } from './../components/widgets/core/index';
import {
@@ -376,13 +375,13 @@ export class FormService {
return this.apiService.getInstance().activiti.userApi.getUserProfilePictureUrl(userId);
}
getWorkflowUsers(filter: string, groupId?: string): Observable<GroupUserModel[]> {
getWorkflowUsers(filter: string, groupId?: string): Observable<LightUserRepresentation[]> {
let option: any = {filter: filter};
if (groupId) {
option.groupId = groupId;
}
return Observable.fromPromise(this.usersWorkflowApi.getUsers(option))
.switchMap((response: any) => <GroupUserModel[]> response.data || [])
.switchMap((response: any) => <LightUserRepresentation[]> response.data || [])
.map((user: any) => {
user.userImage = this.getUserProfileImageApi(user.id);
return Observable.of(user);

View File

@@ -15,14 +15,10 @@
* limitations under the License.
*/
import {
AppDefinitionRepresentationModel,
Comment,
TaskDetailsModel,
User
} from 'ng2-activiti-tasklist';
import { AppDefinitionRepresentationModel, Comment, TaskDetailsModel } from 'ng2-activiti-tasklist';
import { FilterProcessRepresentationModel } from '../models/filter-process.model';
import { ProcessDefinitionRepresentation } from '../models/process-definition.model';
import { LightUserRepresentation } from 'ng2-alfresco-core';
export let fakeFilters = {
size: 1, total: 1, start: 0,
@@ -80,7 +76,7 @@ export let fakeTaskList = {
})]
};
export let fakeComment = new Comment(1, 'Test', '2016-11-10T03:37:30.010+0000', new User({
export let fakeComment = new Comment(1, 'Test', '2016-11-10T03:37:30.010+0000', new LightUserRepresentation({
id: 13,
firstName: 'Wilbur',
lastName: 'Adams',

View File

@@ -23,10 +23,9 @@ import { Observable } from 'rxjs/Rx';
import {
CommentListComponent,
CommentsComponent,
PeopleService,
TaskListService
} from 'ng2-activiti-tasklist';
import { AlfrescoTranslationService, CoreModule } from 'ng2-alfresco-core';
import { AlfrescoTranslationService, CoreModule, PeopleProcessService } from 'ng2-alfresco-core';
import { DataTableModule } from 'ng2-alfresco-datatable';
import { TranslationMock } from './../assets/translation.service.mock';
@@ -57,7 +56,7 @@ describe('ActivitiProcessInstanceComments', () => {
{ provide: AlfrescoTranslationService, useClass: TranslationMock },
{ provide: TaskListService, useClass: ProcessService },
DatePipe,
PeopleService
PeopleProcessService
]
}).compileComponents();
}));

View File

@@ -20,9 +20,8 @@ import { RestVariable } from 'alfresco-js-api';
import {
Comment,
TaskDetailsModel,
TaskListService,
User } from 'ng2-activiti-tasklist';
import { AlfrescoApiService, LogService } from 'ng2-alfresco-core';
TaskListService } from 'ng2-activiti-tasklist';
import { AlfrescoApiService, LightUserRepresentation, LogService } from 'ng2-alfresco-core';
import { Observable } from 'rxjs/Observable';
import { FilterProcessRepresentationModel } from '../models/filter-process.model';
import { ProcessDefinitionRepresentation } from '../models/process-definition.model';
@@ -234,7 +233,7 @@ export class ProcessService extends TaskListService {
.map((response: any) => {
let comments: Comment[] = [];
response.data.forEach((comment) => {
let user = new User({
let user = new LightUserRepresentation({
id: comment.createdBy.id,
email: comment.createdBy.email,
firstName: comment.createdBy.firstName,

View File

@@ -23,7 +23,6 @@ import { ActivitiFormModule } from 'ng2-activiti-form';
import { CoreModule, TRANSLATION_PROVIDER } from 'ng2-alfresco-core';
import { DataTableModule } from 'ng2-alfresco-datatable';
import { MaterialModule } from './src/components/material.module';
import { PeopleService } from './src/services/people.service';
import { ProcessUploadService } from './src/services/process-upload.service';
import { TaskListService } from './src/services/tasklist.service';
@@ -62,7 +61,6 @@ export {PeopleListComponent } from './src/components/people-list.component';
export {CommentListComponent } from './src/components/comment-list.component';
export { TaskListService } from './src/services/tasklist.service';
export { PeopleService } from './src/services/people.service';
export { ProcessUploadService } from './src/services/process-upload.service';
// Old Deprecated export
@@ -79,7 +77,6 @@ import {TaskDetailsComponent as ActivitiTaskDetails } from './src/components/tas
import {TaskFiltersComponent as ActivitiFilters } from './src/components/task-filters.component';
import {TaskHeaderComponent as ActivitiTaskHeader } from './src/components/task-header.component';
import {TaskListComponent as ActivitiTaskList } from './src/components/tasklist.component';
import {PeopleService as ActivitiPeopleService } from './src/services/people.service';
import {TaskListService as ActivitiTaskListService } from './src/services/tasklist.service';
export {AppsListComponent as ActivitiApps} from './src/components/apps-list.component';
export {ChecklistComponent as ActivitiChecklist} from './src/components/checklist.component';
@@ -94,13 +91,11 @@ export {TaskDetailsComponent as ActivitiTaskDetails } from './src/components/tas
export {TaskFiltersComponent as ActivitiFilters } from './src/components/task-filters.component';
export {TaskHeaderComponent as ActivitiTaskHeader} from './src/components/task-header.component';
export {TaskListComponent as ActivitiTaskList } from './src/components/tasklist.component';
export {PeopleService as ActivitiPeopleService } from './src/services/people.service';
export {TaskListService as ActivitiTaskListService } from './src/services/tasklist.service';
export * from './src/models/comment.model';
export * from './src/models/filter.model';
export * from './src/models/icon.model';
export * from './src/models/user.model';
export * from './src/models/task-details.model';
export * from './src/models/task-details.event';
export * from './src/models/user-event.model';
@@ -144,12 +139,10 @@ export const ACTIVITI_TASKLIST_DIRECTIVES: any[] = [
export const ACTIVITI_TASKLIST_PROVIDERS: any[] = [
TaskListService,
PeopleService,
ProcessUploadService,
// Old Deprecated export
ActivitiTaskListService,
ActivitiPeopleService
ActivitiTaskListService
];
@NgModule({

View File

@@ -8,12 +8,11 @@
<div id="comment-user-icon"
class="adf-comment-img-container">
<div
*ngIf="!entry.row.obj.createdBy.userImage" class="adf-comment-user-icon">
*ngIf="!entry.row.obj.createdBy.pictureId" class="adf-comment-user-icon">
{{getUserShortName(entry.row.obj.createdBy)}}</div>
<div>
<img *ngIf="entry.row.obj.createdBy.userImage" class="adf-people-img"
[src]="entry.row.obj.createdBy.userImage"
(error)="onErrorImageLoad(entry.row.obj.createdBy)"/>
<img *ngIf="entry.row.obj.createdBy.pictureId" class="adf-people-img"
[src]="peopleProcessService.getUserImage(entry.row.obj.createdBy)"/>
</div>
</div>
</ng-template>

View File

@@ -18,16 +18,16 @@
import { DatePipe } from '@angular/common';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { AppConfigService, CoreModule, TranslationService } from 'ng2-alfresco-core';
import { LightUserRepresentation } from 'ng2-alfresco-core';
import { DataRowEvent, DataTableModule, ObjectDataRow } from 'ng2-alfresco-datatable';
import { AppConfigServiceMock } from '../assets/app-config.service.mock';
import { TranslationMock } from '../assets/translation.service.mock';
import { Comment } from '../models/comment.model';
import { User } from '../models/user.model';
import { CommentListComponent } from './comment-list.component';
declare let jasmine: any;
const testUser: User = new User({
const testUser: LightUserRepresentation = new LightUserRepresentation({
id: '1',
firstName: 'Test',
lastName: 'User',
@@ -54,8 +54,8 @@ describe('CommentListComponent', () => {
],
providers: [
DatePipe,
{ provide: AppConfigService, useClass: AppConfigServiceMock },
{ provide: TranslationService, useClass: TranslationMock }
{provide: AppConfigService, useClass: AppConfigServiceMock},
{provide: TranslationService, useClass: TranslationMock}
]
}).compileComponents().then(() => {

View File

@@ -17,8 +17,8 @@
import { DatePipe } from '@angular/common';
import { Component, EventEmitter, Input, Output } from '@angular/core';
import { LightUserRepresentation, PeopleProcessService } from 'ng2-alfresco-core';
import { Comment } from '../models/comment.model';
import { User } from '../models/user.model';
@Component({
selector: 'adf-comment-list',
@@ -36,7 +36,7 @@ export class CommentListComponent {
selectedComment: Comment;
constructor(private datePipe: DatePipe) {
constructor(private datePipe: DatePipe, public peopleProcessService: PeopleProcessService) {
}
selectComment(event: any): void {
@@ -44,7 +44,7 @@ export class CommentListComponent {
this.clickRow.emit(this.selectedComment);
}
getUserShortName(user: User): string {
getUserShortName(user: LightUserRepresentation): string {
let shortName = '';
if (user) {
if (user.firstName) {
@@ -78,10 +78,4 @@ export class CommentListComponent {
return this.comments && this.comments.length && true;
}
onErrorImageLoad(user: User) {
if (user.userImage) {
user.userImage = null;
}
}
}

View File

@@ -26,8 +26,8 @@ import { TranslationMock } from '../assets/translation.service.mock';
import { DatePipe } from '@angular/common';
import { MdInputModule } from '@angular/material';
import { PeopleProcessService } from 'ng2-alfresco-core';
import { DataTableModule } from 'ng2-alfresco-datatable';
import { PeopleService } from '../services/people.service';
import { TaskListService } from './../services/tasklist.service';
import { CommentListComponent } from './comment-list.component';
import { CommentsComponent } from './comments.component';
@@ -56,7 +56,7 @@ describe('CommentsComponent', () => {
providers: [
TaskListService,
DatePipe,
PeopleService,
PeopleProcessService,
{ provide: TranslationService, useClass: TranslationMock },
{ provide: AppConfigService, useClass: AppConfigServiceMock }
]

View File

@@ -19,7 +19,6 @@ import { Component, EventEmitter, Input, OnChanges, Output, SimpleChanges } from
import { Observable, Observer } from 'rxjs/Rx';
import { Comment } from '../models/comment.model';
import { PeopleService } from '../services/people.service';
import { TaskListService } from '../services/tasklist.service';
@Component({
@@ -52,7 +51,7 @@ export class CommentsComponent implements OnChanges {
* @param translate Translation service
* @param activitiTaskList Task service
*/
constructor(private activitiTaskList: TaskListService, private peopleService: PeopleService) {
constructor(private activitiTaskList: TaskListService) {
this.comment$ = new Observable<Comment>(observer => this.commentObserver = observer).share();
this.comment$.subscribe((comment: Comment) => {
this.comments.push(comment);
@@ -81,7 +80,6 @@ export class CommentsComponent implements OnChanges {
return date1 > date2 ? -1 : date1 < date2 ? 1 : 0;
});
res.forEach((comment) => {
comment.createdBy.userImage = this.peopleService.getUserImage(comment.createdBy);
this.commentObserver.next(comment);
});
},
@@ -102,7 +100,6 @@ export class CommentsComponent implements OnChanges {
this.activitiTaskList.addComment(this.taskId, this.message)
.subscribe(
(res: Comment) => {
res.createdBy.userImage = this.peopleService.getUserImage(res.createdBy);
this.comments.unshift(res);
this.message = '';
this.beingAdded = false;

View File

@@ -17,16 +17,16 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { AppConfigService, CoreModule, TranslationService } from 'ng2-alfresco-core';
import { LightUserRepresentation } from 'ng2-alfresco-core';
import { DataRowActionEvent, DataRowEvent, DataTableModule, ObjectDataRow } from 'ng2-alfresco-datatable';
import { AppConfigServiceMock } from '../assets/app-config.service.mock';
import { TranslationMock } from '../assets/translation.service.mock';
import { UserEventModel } from '../models/user-event.model';
import { User } from '../models/user.model';
import { PeopleListComponent } from './people-list.component';
declare let jasmine: any;
const fakeUser: User = new User({
const fakeUser: LightUserRepresentation = new LightUserRepresentation({
id: '1',
firstName: 'fake-name',
lastName: 'fake-last',

View File

@@ -17,9 +17,9 @@
import { AfterContentInit, AfterViewInit, Component, ContentChild, EventEmitter, Input, Output, ViewChild } from '@angular/core';
import { DataColumnListComponent } from 'ng2-alfresco-core';
import { LightUserRepresentation } from 'ng2-alfresco-core';
import { DataTableComponent } from 'ng2-alfresco-datatable';
import { UserEventModel } from '../models/user-event.model';
import { User } from '../models/user.model';
declare let componentHandler: any;
@@ -37,18 +37,18 @@ export class PeopleListComponent implements AfterViewInit, AfterContentInit {
peopleDataTable: DataTableComponent;
@Input()
users: User[];
users: LightUserRepresentation[];
@Input()
actions: boolean = false;
@Output()
clickRow: EventEmitter<User> = new EventEmitter<User>();
clickRow: EventEmitter<LightUserRepresentation> = new EventEmitter<LightUserRepresentation>();
@Output()
clickAction: EventEmitter<UserEventModel> = new EventEmitter<UserEventModel>();
user: User;
user: LightUserRepresentation;
ngAfterContentInit() {
this.peopleDataTable.columnList = this.columnList;

View File

@@ -11,12 +11,11 @@
<data-columns>
<data-column key="firstName">
<ng-template let-entry="$implicit">
<div *ngIf="!entry.row.obj.userImage" class="people-pic">
<div *ngIf="!entry.row.obj.pictureId" class="people-pic">
{{getInitialUserName(entry.row.obj.firstName, entry.row.obj.lastName)}}</div>
<div>
<img *ngIf="entry.row.obj.userImage" class="people-img"
[src]="entry.row.obj.userImage"
(error)="onErrorImageLoad(entry.row.obj)"/>
<img *ngIf="entry.row.obj.pictureId" class="people-img"
[src]="peopleProcessService.getUserImage(entry.row.obj)"/>
</div>
</ng-template>
</data-column>

View File

@@ -18,24 +18,24 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { MdButtonModule, MdInputModule } from '@angular/material';
import { AppConfigService, CoreModule, TranslationService } from 'ng2-alfresco-core';
import { LightUserRepresentation } from 'ng2-alfresco-core';
import { DataTableModule } from 'ng2-alfresco-datatable';
import { Observable } from 'rxjs/Observable';
import { AppConfigServiceMock } from '../assets/app-config.service.mock';
import { TranslationMock } from '../assets/translation.service.mock';
import { User } from '../models/user.model';
import { PeopleListComponent } from './people-list.component';
import { PeopleSearchComponent } from './people-search.component';
declare let jasmine: any;
const fakeUser: User = new User({
const fakeUser: LightUserRepresentation = new LightUserRepresentation({
id: '1',
firstName: 'fake-name',
lastName: 'fake-last',
email: 'fake@mail.com'
});
const fakeSecondUser: User = new User({
const fakeSecondUser: LightUserRepresentation = new LightUserRepresentation({
id: '2',
firstName: 'fake-involve-name',
lastName: 'fake-involve-last',

View File

@@ -17,8 +17,9 @@
import { Component, Directive, EventEmitter, Input, OnInit, Output, ViewEncapsulation } from '@angular/core';
import { FormControl } from '@angular/forms';
import { LightUserRepresentation } from 'ng2-alfresco-core';
import { PeopleProcessService } from 'ng2-alfresco-core';
import { Observable } from 'rxjs/Observable';
import { User } from '../models/user.model';
@Component({
selector: 'adf-people-search, activiti-people-search',
@@ -33,24 +34,24 @@ import { User } from '../models/user.model';
export class PeopleSearchComponent implements OnInit {
@Input()
results: Observable<User[]>;
results: Observable<LightUserRepresentation[]>;
@Output()
searchPeople: EventEmitter<any> = new EventEmitter();
@Output()
success: EventEmitter<User> = new EventEmitter<User>();
success: EventEmitter<LightUserRepresentation> = new EventEmitter<LightUserRepresentation>();
@Output()
closeSearch = new EventEmitter();
searchUser: FormControl = new FormControl();
users: User[] = [];
users: LightUserRepresentation[] = [];
selectedUser: User;
selectedUser: LightUserRepresentation;
constructor() {
constructor(peopleProcessService: PeopleProcessService) {
this.searchUser
.valueChanges
.debounceTime(200)
@@ -69,7 +70,7 @@ export class PeopleSearchComponent implements OnInit {
});
}
onRowClick(user: User) {
onRowClick(user: LightUserRepresentation) {
this.selectedUser = user;
}
@@ -108,12 +109,6 @@ export class PeopleSearchComponent implements OnInit {
hasUsers() {
return (this.users && this.users.length > 0);
}
onErrorImageLoad(user: User) {
if (user.userImage) {
user.userImage = null;
}
}
}
@Directive({ selector: 'people-search-title' }) export class PeopleSearchTitleDirective { }

View File

@@ -29,12 +29,11 @@
<data-columns>
<data-column key="firstName">
<ng-template let-entry="$implicit">
<div *ngIf="!entry.row.obj.userImage" class="people-pic">
<div *ngIf="!entry.row.obj.pictureId" class="people-pic">
{{getInitialUserName(entry.row.obj.firstName, entry.row.obj.lastName)}}</div>
<div>
<img *ngIf="entry.row.obj.userImage" class="people-img"
[src]="entry.row.obj.userImage"
(error)="onErrorImageLoad(entry.row.obj)"/>
<img *ngIf="entry.row.obj.pictureId" class="people-img"
[src]="peopleProcessService.getUserImage(entry.row.obj)"/>
</div>
</ng-template>
</data-column>

View File

@@ -19,25 +19,25 @@ import { NO_ERRORS_SCHEMA } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { MdButtonModule, MdInputModule } from '@angular/material';
import { AppConfigService, CoreModule, LogService, TranslationService } from 'ng2-alfresco-core';
import { LightUserRepresentation } from 'ng2-alfresco-core';
import { PeopleProcessService } from 'ng2-alfresco-core';
import { DataTableModule } from 'ng2-alfresco-datatable';
import { AppConfigServiceMock } from '../assets/app-config.service.mock';
import { TranslationMock } from '../assets/translation.service.mock';
import { User } from '../models/user.model';
import { PeopleService } from '../services/people.service';
import { PeopleListComponent } from './people-list.component';
import { PeopleSearchComponent } from './people-search.component';
import { PeopleComponent } from './people.component';
declare let jasmine: any;
const fakeUser: User = new User({
const fakeUser: LightUserRepresentation = new LightUserRepresentation({
id: 'fake-id',
firstName: 'fake-name',
lastName: 'fake-last',
email: 'fake@mail.com'
});
const fakeSecondUser: User = new User({
const fakeSecondUser: LightUserRepresentation = new LightUserRepresentation({
id: 'fake-involve-id',
firstName: 'fake-involve-name',
lastName: 'fake-involve-last',
@@ -67,7 +67,7 @@ describe('PeopleComponent', () => {
PeopleComponent
],
providers: [
PeopleService,
PeopleProcessService,
{ provide: TranslationService, useClass: TranslationMock },
{ provide: AppConfigService, useClass: AppConfigServiceMock }
],

View File

@@ -17,13 +17,11 @@
import { AfterViewInit, Component, Input, OnInit, ViewChild } from '@angular/core';
import { LogService } from 'ng2-alfresco-core';
import { LightUserRepresentation, PeopleProcessService } from 'ng2-alfresco-core';
import { Observable, Observer } from 'rxjs/Rx';
import { UserEventModel } from '../models/user-event.model';
import { User } from '../models/user.model';
import { PeopleSearchComponent } from './people-search.component';
import { PeopleService } from '../services/people.service';
declare let componentHandler: any;
declare var require: any;
@@ -38,7 +36,7 @@ export class PeopleComponent implements OnInit, AfterViewInit {
iconImageUrl: string = require('../assets/images/user.jpg');
@Input()
people: User[] = [];
people: LightUserRepresentation[] = [];
@Input()
taskId: string = '';
@@ -51,25 +49,14 @@ export class PeopleComponent implements OnInit, AfterViewInit {
showAssignment: boolean = false;
private peopleSearchObserver: Observer<User[]>;
peopleSearch$: Observable<User[]>;
private peopleSearchObserver: Observer<LightUserRepresentation[]>;
peopleSearch$: Observable<LightUserRepresentation[]>;
/**
* Constructor
* @param translate
* @param people service
*/
constructor(private peopleService: PeopleService,
private logService: LogService) {
this.peopleSearch$ = new Observable<User[]>(observer => this.peopleSearchObserver = observer).share();
constructor(private logService: LogService, public peopleProcessService: PeopleProcessService) {
this.peopleSearch$ = new Observable<LightUserRepresentation[]>(observer => this.peopleSearchObserver = observer).share();
}
ngOnInit() {
if (this.people && this.people.length > 0) {
this.people.forEach((person) => {
person.userImage = this.peopleService.getUserImage(person);
});
}
}
ngAfterViewInit() {
@@ -99,21 +86,21 @@ export class PeopleComponent implements OnInit, AfterViewInit {
}
searchUser(searchedWord: string) {
this.peopleService.getWorkflowUsersWithImages(this.taskId, searchedWord)
this.peopleProcessService.getWorkflowUsers(this.taskId, searchedWord)
.subscribe((users) => {
this.peopleSearchObserver.next(users);
}, error => this.logService.error(error));
}
involveUser(user: User) {
this.peopleService.involveUserWithTask(this.taskId, user.id.toString())
involveUser(user: LightUserRepresentation) {
this.peopleProcessService.involveUserWithTask(this.taskId, user.id.toString())
.subscribe(() => {
this.people = [...this.people, user];
}, error => this.logService.error('Impossible to involve user with task'));
}
removeInvolvedUser(user: User) {
this.peopleService.removeInvolvedUser(this.taskId, user.id.toString())
removeInvolvedUser(user: LightUserRepresentation) {
this.peopleProcessService.removeInvolvedUser(this.taskId, user.id.toString())
.subscribe(() => {
this.people = this.people.filter((involvedUser) => {
return involvedUser.id !== user.id;
@@ -154,10 +141,4 @@ export class PeopleComponent implements OnInit, AfterViewInit {
onCloseSearch() {
this.showAssignment = false;
}
onErrorImageLoad(user: User) {
if (user.userImage) {
user.userImage = null;
}
}
}

View File

@@ -17,12 +17,11 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { MdButtonModule, MdDatepickerModule, MdGridListModule, MdIconModule, MdInputModule, MdNativeDateModule, MdSelectModule } from '@angular/material';
import { AppConfigService, CoreModule, TranslationService } from 'ng2-alfresco-core';
import { AppConfigService, CoreModule, PeopleProcessService, TranslationService } from 'ng2-alfresco-core';
import { Observable } from 'rxjs/Rx';
import { AppConfigServiceMock } from '../assets/app-config.service.mock';
import { TranslationMock } from '../assets/translation.service.mock';
import { StartTaskModel } from '../models/start-task.model';
import { PeopleService } from '../services/people.service';
import { TaskListService } from '../services/tasklist.service';
import { startTaskMock } from './../assets/start-task.mock';
import { StartTaskComponent } from './start-task.component';
@@ -32,7 +31,7 @@ describe('StartTaskComponent', () => {
let component: StartTaskComponent;
let fixture: ComponentFixture<StartTaskComponent>;
let service: TaskListService;
let peopleService: PeopleService;
let peopleService: PeopleProcessService;
let element: HTMLElement;
let getFormlistSpy: jasmine.Spy;
let getWorkflowUsersSpy: jasmine.Spy;
@@ -67,7 +66,7 @@ describe('StartTaskComponent', () => {
],
providers: [
TaskListService,
PeopleService,
PeopleProcessService,
{ provide: AppConfigService, useClass: AppConfigServiceMock },
{ provide: TranslationService, useClass: TranslationMock }
]
@@ -78,7 +77,7 @@ describe('StartTaskComponent', () => {
element = fixture.nativeElement;
service = fixture.debugElement.injector.get(TaskListService);
peopleService = fixture.debugElement.injector.get(PeopleService);
peopleService = fixture.debugElement.injector.get(PeopleProcessService);
getFormlistSpy = spyOn(service, 'getFormList').and.returnValue(Observable.of(fakeForms));
getWorkflowUsersSpy = spyOn(peopleService, 'getWorkflowUsers').and.returnValue(Observable.of([
{

View File

@@ -18,14 +18,12 @@
import { Component, EventEmitter, Input, OnInit, Output, ViewEncapsulation } from '@angular/core';
import { DateAdapter, MD_DATE_FORMATS } from '@angular/material';
import * as moment from 'moment';
import { MOMENT_DATE_FORMATS, MomentDateAdapter } from 'ng2-alfresco-core';
import { LogService } from 'ng2-alfresco-core';
import { LightUserRepresentation, LogService, MOMENT_DATE_FORMATS,
MomentDateAdapter, PeopleProcessService } from 'ng2-alfresco-core';
import { Observable } from 'rxjs/Rx';
import { Form } from '../models/form.model';
import { StartTaskModel } from '../models/start-task.model';
import { TaskDetailsModel } from '../models/task-details.model';
import { User } from '../models/user.model';
import { PeopleService } from '../services/people.service';
import { TaskListService } from './../services/tasklist.service';
@Component({
@@ -53,7 +51,7 @@ export class StartTaskComponent implements OnInit {
@Output()
error: EventEmitter<any> = new EventEmitter<any>();
people: User[] = [];
people: LightUserRepresentation[] = [];
startTaskmodel: StartTaskModel = new StartTaskModel();
@@ -74,7 +72,7 @@ export class StartTaskComponent implements OnInit {
* @param taskService
*/
constructor(private taskService: TaskListService,
private peopleService: PeopleService,
private peopleService: PeopleProcessService,
private logService: LogService) {
}
@@ -143,7 +141,7 @@ export class StartTaskComponent implements OnInit {
});
}
public isUserNameEmpty(user: any): boolean {
public isUserNameEmpty(user: LightUserRepresentation): boolean {
return !user || (this.isEmpty(user.firstName) && this.isEmpty(user.lastName));
}

View File

@@ -24,19 +24,19 @@ import { Observable } from 'rxjs/Rx';
import { ActivitiFormModule, FormModel, FormOutcomeEvent, FormOutcomeModel, FormService } from 'ng2-activiti-form';
import { AppConfigService, CoreModule, LogService, TranslationService } from 'ng2-alfresco-core';
import { LightUserRepresentation } from 'ng2-alfresco-core';
import { PeopleProcessService } from 'ng2-alfresco-core';
import { AppConfigServiceMock } from '../assets/app-config.service.mock';
import { TranslationMock } from '../assets/translation.service.mock';
import { TaskDetailsModel } from '../models/task-details.model';
import { User } from '../models/user.model';
import { noDataMock, taskDetailsMock, taskFormMock, tasksMock } from './../assets/task-details.mock';
import { PeopleService } from './../services/people.service';
import { TaskListService } from './../services/tasklist.service';
import { PeopleSearchComponent } from './people-search.component';
import { TaskDetailsComponent } from './task-details.component';
declare let jasmine: any;
const fakeUser: User = new User({
const fakeUser: LightUserRepresentation = new LightUserRepresentation({
id: 'fake-id',
firstName: 'fake-name',
lastName: 'fake-last',
@@ -72,7 +72,7 @@ describe('TaskDetailsComponent', () => {
],
providers: [
TaskListService,
PeopleService,
PeopleProcessService,
{ provide: TranslationService, useClass: TranslationMock },
{ provide: AppConfigService, useClass: AppConfigServiceMock }
],

View File

@@ -28,11 +28,11 @@ import { Component,
import { MdDialog, MdDialogRef } from '@angular/material';
import { ContentLinkModel, FormFieldValidator, FormModel, FormOutcomeEvent } from 'ng2-activiti-form';
import { AlfrescoAuthenticationService, CardViewUpdateService, ClickNotification, LogService, UpdateNotification } from 'ng2-alfresco-core';
import { LightUserRepresentation } from 'ng2-alfresco-core';
import { PeopleProcessService } from 'ng2-alfresco-core';
import { Observable, Observer } from 'rxjs/Rx';
import { TaskQueryRequestRepresentationModel } from '../models/filter.model';
import { TaskDetailsModel } from '../models/task-details.model';
import { User } from '../models/user.model';
import { PeopleService } from './../services/people.service';
import { TaskListService } from './../services/tasklist.service';
declare var require: any;
@@ -131,24 +131,24 @@ export class TaskDetailsComponent implements OnInit, OnChanges {
taskDetails: TaskDetailsModel;
taskFormName: string = null;
taskPeople: User[] = [];
taskPeople: LightUserRepresentation[] = [];
noTaskDetailsTemplateComponent: TemplateRef<any>;
showAssignee: boolean = false;
private peopleSearchObserver: Observer<User[]>;
private peopleSearchObserver: Observer<LightUserRepresentation[]>;
public errorDialogRef: MdDialogRef<TemplateRef<any>>;
peopleSearch$: Observable<User[]>;
peopleSearch$: Observable<LightUserRepresentation[]>;
constructor(private activitiTaskList: TaskListService,
private authService: AlfrescoAuthenticationService,
private peopleService: PeopleService,
private peopleProcessService: PeopleProcessService,
private logService: LogService,
private cardViewUpdateService: CardViewUpdateService,
private dialog: MdDialog) {
this.peopleSearch$ = new Observable<User[]>(observer => this.peopleSearchObserver = observer).share();
this.peopleSearch$ = new Observable<LightUserRepresentation[]>(observer => this.peopleSearchObserver = observer).share();
}
ngOnInit() {
@@ -234,7 +234,7 @@ export class TaskDetailsComponent implements OnInit, OnChanges {
this.readOnlyForm = this.readOnlyForm ? this.readOnlyForm : !!(endDate && !isNaN(endDate.getTime()));
if (this.taskDetails && this.taskDetails.involvedPeople) {
this.taskDetails.involvedPeople.forEach((user) => {
this.taskPeople.push(new User(user));
this.taskPeople.push(new LightUserRepresentation(user));
});
}
});
@@ -336,7 +336,7 @@ export class TaskDetailsComponent implements OnInit, OnChanges {
}
searchUser(searchedWord: string) {
this.peopleService.getWorkflowUsers(null, searchedWord)
this.peopleProcessService.getWorkflowUsers(null, searchedWord)
.subscribe((users) => {
users = users.filter((user) => user.id !== this.taskDetails.assignee.id);
this.peopleSearchObserver.next(users);
@@ -347,7 +347,7 @@ export class TaskDetailsComponent implements OnInit, OnChanges {
this.showAssignee = false;
}
assignTaskToUser(selectedUser: User) {
assignTaskToUser(selectedUser: LightUserRepresentation) {
this.activitiTaskList.assignTask(this.taskDetails.id, selectedUser).subscribe(
(res: any) => {
this.logService.info('Task Assigned to ' + selectedUser.email);

View File

@@ -23,6 +23,7 @@ import { Observable } from 'rxjs/Rx';
import { AppConfigServiceMock } from '../assets/app-config.service.mock';
import { TranslationMock } from '../assets/translation.service.mock';
import { LightUserRepresentation } from '../../../ng2-alfresco-core/src/models/user-process.model';
import { TaskDetailsModel } from '../models/task-details.model';
import { taskDetailsMock } from './../assets/task-details.mock';
import { TaskListService } from './../services/tasklist.service';
@@ -138,7 +139,7 @@ describe('TaskHeaderComponent', () => {
describe('Unclaim', () => {
const batman = { id : 1, email: 'bruce.wayne@gotham.com', firstName: 'Bruce', lastName: 'Wayne', userImage: 'batman.jpg' };
const batman = new LightUserRepresentation({ id : 1, email: 'bruce.wayne@gotham.com', firstName: 'Bruce', lastName: 'Wayne', userImage: 'batman.jpg' });
let taskListService;
beforeEach(() => {

View File

@@ -22,15 +22,15 @@
*
* @returns {Comment} .
*/
import { User } from './user.model';
import { LightUserRepresentation } from 'ng2-alfresco-core';
export class Comment {
id: number;
message: string;
created: string;
createdBy: User;
createdBy: LightUserRepresentation;
constructor(id: number, message: string, created: string, createdBy: User) {
constructor(id: number, message: string, created: string, createdBy: LightUserRepresentation) {
this.id = id;
this.message = message;
this.created = created;

View File

@@ -22,13 +22,13 @@
*
* @returns {StartTaskModel} .
*/
import { User } from './user.model';
import { LightUserRepresentation } from 'ng2-alfresco-core';
export class StartTaskModel {
name: string;
description: string;
assignee: User;
assignee: LightUserRepresentation;
dueDate: any;
formKey: any;
category: string;
@@ -36,7 +36,7 @@ export class StartTaskModel {
constructor(obj?: any) {
this.name = obj && obj.name || null;
this.description = obj && obj.description || null;
this.assignee = obj && obj.assignee ? new User(obj.assignee) : null;
this.assignee = obj && obj.assignee ? new LightUserRepresentation(obj.assignee) : null;
this.dueDate = obj && obj.dueDate || null;
this.formKey = obj && obj.formKey || null;
this.category = obj && obj.category || null;

View File

@@ -22,12 +22,12 @@
*
* @returns {TaskDetailsModel} .
*/
import { User } from './user.model';
import { LightUserRepresentation } from 'ng2-alfresco-core';
export class TaskDetailsModel {
id: string;
name: string;
assignee: User;
assignee: LightUserRepresentation;
priority: number;
adhocTaskCanBeReassigned: number;
category: string;
@@ -42,7 +42,7 @@ export class TaskDetailsModel {
managerOfCandidateGroup: boolean;
memberOfCandidateGroup: boolean;
memberOfCandidateUsers: boolean;
involvedPeople: User [];
involvedPeople: LightUserRepresentation [];
parentTaskId: string;
parentTaskName: string;
processDefinitionCategory: string;
@@ -62,7 +62,7 @@ export class TaskDetailsModel {
this.id = obj.id || null;
this.name = obj.name || null;
this.priority = obj.priority;
this.assignee = obj.assignee ? new User(obj.assignee) : null;
this.assignee = obj.assignee ? new LightUserRepresentation(obj.assignee) : null;
this.adhocTaskCanBeReassigned = obj.adhocTaskCanBeReassigned;
this.category = obj.category || null;
this.created = obj.created || null;

View File

@@ -17,6 +17,7 @@
import { async, TestBed } from '@angular/core/testing';
import { AppConfigService, CoreModule, TranslationService } from 'ng2-alfresco-core';
import { LightUserRepresentation } from 'ng2-alfresco-core';
import { Observable } from 'rxjs/Rx';
import { AppConfigServiceMock } from '../assets/app-config.service.mock';
import {
@@ -43,7 +44,6 @@ import { TranslationMock } from '../assets/translation.service.mock';
import { Comment } from '../models/comment.model';
import { FilterRepresentationModel, TaskQueryRequestRepresentationModel } from '../models/filter.model';
import { TaskDetailsModel } from '../models/task-details.model';
import { User } from '../models/user.model';
import { TaskListService } from './tasklist.service';
declare let jasmine: any;
@@ -679,7 +679,7 @@ describe('Activiti TaskList Service', () => {
expect(res.category).toEqual('3');
expect(res.created).not.toEqual('');
expect(res.adhocTaskCanBeReassigned).toBe(true);
expect(res.assignee).toEqual(new User(fakeUser2));
expect(res.assignee).toEqual(new LightUserRepresentation(fakeUser2));
expect(res.involvedPeople).toEqual([fakeUser1]);
done();
}
@@ -712,7 +712,7 @@ describe('Activiti TaskList Service', () => {
expect(res.category).toEqual('3');
expect(res.created).not.toEqual('');
expect(res.adhocTaskCanBeReassigned).toBe(true);
expect(res.assignee).toEqual(new User(fakeUser2));
expect(res.assignee).toEqual(new LightUserRepresentation(fakeUser2));
expect(res.involvedPeople).toEqual([fakeUser1]);
done();
}

View File

@@ -17,6 +17,7 @@
import { Injectable } from '@angular/core';
import { AlfrescoApiService, LogService } from 'ng2-alfresco-core';
import { LightUserRepresentation } from 'ng2-alfresco-core';
import { Observable, Subject } from 'rxjs/Rx';
import { Comment } from '../models/comment.model';
import {
@@ -26,7 +27,6 @@ import {
import { Form } from '../models/form.model';
import { TaskDetailsModel } from '../models/task-details.model';
import { TaskListModel } from '../models/task-list.model';
import { User } from '../models/user.model';
@Injectable()
export class TaskListService {
@@ -231,7 +231,7 @@ export class TaskListService {
.map((response: any) => {
let comments: Comment[] = [];
response.data.forEach((comment) => {
let user = new User(comment.createdBy);
let user = new LightUserRepresentation(comment.createdBy);
comments.push(new Comment(comment.id, comment.message, comment.created, user));
});
return comments;

View File

@@ -61,7 +61,8 @@ import { DiscoveryApiService } from './src/services/discovery-api.service';
import { FavoritesApiService } from './src/services/favorites-api.service';
import { HighlightTransformService } from './src/services/highlight-transform.service';
import { NodesApiService } from './src/services/nodes-api.service';
import { PeopleApiService } from './src/services/people-api.service';
import { PeopleContentService } from './src/services/people-content.service';
import { PeopleProcessService } from './src/services/people-process.service';
import { SearchApiService } from './src/services/search-api.service';
import { SearchService } from './src/services/search.service';
import { SharedLinksApiService } from './src/services/shared-links-api.service';
@@ -103,7 +104,8 @@ export { HighlightTransformService, HightlightTransformResult } from './src/serv
export { DeletedNodesApiService } from './src/services/deleted-nodes-api.service';
export { FavoritesApiService } from './src/services/favorites-api.service';
export { NodesApiService } from './src/services/nodes-api.service';
export { PeopleApiService } from './src/services/people-api.service';
export { PeopleContentService } from './src/services/people-content.service';
export { PeopleProcessService } from './src/services/people-process.service';
export { SearchApiService } from './src/services/search-api.service';
export { SharedLinksApiService } from './src/services/shared-links-api.service';
export { SitesApiService } from './src/services/sites-api.service';
@@ -156,6 +158,7 @@ export * from './src/models/file.model';
export * from './src/models/permissions.enum';
export * from './src/models/site.model';
export * from './src/models/product-version.model';
export * from './src/models/user-process.model';
// Old deprecated import
import { AuthenticationService as AlfrescoAuthenticationService } from './src/services/authentication.service';
@@ -190,13 +193,14 @@ export function providers() {
DeletedNodesApiService,
FavoritesApiService,
NodesApiService,
PeopleApiService,
PeopleContentService,
SearchApiService,
SharedLinksApiService,
SitesApiService,
DiscoveryApiService,
HighlightTransformService,
MomentDateAdapter
MomentDateAdapter,
PeopleProcessService
];
}

View File

@@ -15,25 +15,16 @@
* limitations under the License.
*/
/* tslint:disable:component-selector */
import { Injectable } from '@angular/core';
export class GroupUserModel {
@Injectable()
export class AppConfigServiceMock {
company: string;
email: string;
firstName: string;
id: string;
lastName: string;
userImage: string;
constructor() { }
/** @override */
get(key: string) { }
load(resource: string, values?: {}) { }
constructor(json?: any) {
if (json) {
this.company = json.company;
this.email = json.email;
this.firstName = json.firstName;
this.id = json.id;
this.lastName = json.lastName;
this.userImage = json.userImage;
}
}
}

View File

@@ -16,19 +16,15 @@
*/
/**
*
* This object represent the user.
*
*
* @returns {User} .
* This object represent the process service user.*
*/
export class User {
export class LightUserRepresentation {
id: number;
email: string;
firstName: string;
lastName: string;
userImage: string = null;
pictureId: number = null;
constructor(obj?: any) {
if (obj) {
@@ -36,6 +32,8 @@ export class User {
this.email = obj.email || null;
this.firstName = obj.firstName || null;
this.lastName = obj.lastName || null;
this.pictureId = obj.pictureId || null;
}
}
}

View File

@@ -17,8 +17,7 @@
import { async, inject, TestBed } from '@angular/core/testing';
import { Router } from '@angular/router';
import { AlfrescoApiService } from 'ng2-alfresco-core';
import { AlfrescoApiService } from './alfresco-api.service';
import { AuthGuardEcm } from './auth-guard-ecm.service';
class RouterProvider {

View File

@@ -17,9 +17,9 @@
import { async, inject, TestBed } from '@angular/core/testing';
import { AlfrescoApiService } from './alfresco-api.service';
import { PeopleApiService } from './people-api.service';
import { PeopleContentService } from './people-content.service';
class PeopleApiServiceTest {
class PeopleContentServiceTest {
service: any = null;
setup: any = {
rejectGetPerson: false
@@ -38,11 +38,11 @@ class PeopleApiServiceTest {
TestBed.configureTestingModule({
providers: [
alfrescoApiServiceProvider,
PeopleApiService
PeopleContentService
]
});
inject([ PeopleApiService ], (service) => {
inject([ PeopleContentService ], (service) => {
this.service = service;
})();
}
@@ -81,7 +81,7 @@ class PeopleApiServiceTest {
describe('PeopleAPI', () => {
describe('Get persons', () => {
it('calls method by an id', async(() => {
const test = new PeopleApiServiceTest();
const test = new PeopleContentServiceTest();
test.service.getPerson('person-1').subscribe(() => {
expect(test.peopleApiGetPersonArguments[0])
@@ -90,7 +90,7 @@ describe('PeopleAPI', () => {
}));
it('calls method with "-me-"', async(() => {
const test = new PeopleApiServiceTest();
const test = new PeopleContentServiceTest();
test.service.getCurrentPerson().subscribe(() => {
expect(test.peopleApiGetPersonArguments[0])
@@ -99,7 +99,7 @@ describe('PeopleAPI', () => {
}));
it('handles the error when it fails', async(() => {
const test = new PeopleApiServiceTest({
const test = new PeopleContentServiceTest({
rejectGetPerson: true
});

View File

@@ -20,7 +20,7 @@ import { Observable } from 'rxjs/Rx';
import { AlfrescoApiService } from './alfresco-api.service';
@Injectable()
export class PeopleApiService {
export class PeopleContentService {
constructor(private apiService: AlfrescoApiService) {}

View File

@@ -16,44 +16,47 @@
*/
import { TestBed } from '@angular/core/testing';
import { AppConfigService, CoreModule } from 'ng2-alfresco-core';
import { AppConfigServiceMock } from '../assets/app-config.service.mock';
import { User } from '../models/user.model';
import { PeopleService } from './people.service';
import { LightUserRepresentation } from '../models/user-process.model';
import { AlfrescoApiService } from './alfresco-api.service';
import { AppConfigService } from './app-config.service';
import { LogService } from './log.service';
import { PeopleProcessService } from './people-process.service';
import { StorageService } from './storage.service';
declare let jasmine: any;
const firstInvolvedUser: User = new User({
const firstInvolvedUser: LightUserRepresentation = new LightUserRepresentation({
id: '1',
email: 'fake-user1@fake.com',
firstName: 'fakeName1',
lastName: 'fakeLast1'
});
const secondInvolvedUser: User = new User({
const secondInvolvedUser: LightUserRepresentation = new LightUserRepresentation({
id: '2',
email: 'fake-user2@fake.com',
firstName: 'fakeName2',
lastName: 'fakeLast2'
});
const fakeInvolveUserList: User[] = [firstInvolvedUser, secondInvolvedUser];
const fakeInvolveUserList: LightUserRepresentation[] = [firstInvolvedUser, secondInvolvedUser];
describe('PeopleService', () => {
describe('PeopleProcessService', () => {
let service: PeopleService;
let service: PeopleProcessService;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
CoreModule
],
providers: [
PeopleService,
PeopleProcessService,
AlfrescoApiService,
StorageService,
LogService,
{ provide: AppConfigService, useClass: AppConfigServiceMock }
]
});
service = TestBed.get(PeopleService);
service = TestBed.get(PeopleProcessService);
});
describe('when user is logged in', () => {
@@ -68,7 +71,7 @@ describe('PeopleService', () => {
it('should be able to retrieve people to involve in the task', (done) => {
service.getWorkflowUsers('fake-task-id', 'fake-filter').subscribe(
(users: User[]) => {
(users: LightUserRepresentation[]) => {
expect(users).toBeDefined();
expect(users.length).toBe(2);
expect(users[0].id).toEqual('1');
@@ -85,12 +88,12 @@ describe('PeopleService', () => {
});
it('should be able to get people images for people retrieved', (done) => {
service.getWorkflowUsersWithImages('fake-task-id', 'fake-filter').subscribe(
(users: User[]) => {
service.getWorkflowUsers('fake-task-id', 'fake-filter').subscribe(
(users: LightUserRepresentation[]) => {
expect(users).toBeDefined();
expect(users.length).toBe(2);
expect(users[0].userImage).toContain('/users/' + users[0].id + '/picture');
expect(users[1].userImage).toContain('/users/' + users[1].id + '/picture');
expect(service.getUserImage(users[0])).toContain('/users/' + users[0].id + '/picture');
expect(service.getUserImage(users[1])).toContain('/users/' + users[1].id + '/picture');
done();
});
jasmine.Ajax.requests.mostRecent().respondWith({
@@ -100,16 +103,6 @@ describe('PeopleService', () => {
});
});
it('should be able to return user with image url', (done) => {
service.addImageToUser(firstInvolvedUser).subscribe(
(user: User) => {
expect(user).toBeDefined();
expect(user.userImage).toContain('/users/' + user.id + '/picture');
expect(user.id).toBe('1');
done();
});
});
it('should return user image url', () => {
let url = service.getUserImage(firstInvolvedUser);
@@ -118,7 +111,7 @@ describe('PeopleService', () => {
it('should return empty list when there are no users to involve', (done) => {
service.getWorkflowUsers('fake-task-id', 'fake-filter').subscribe(
(users: User[]) => {
(users: LightUserRepresentation[]) => {
expect(users).toBeDefined();
expect(users.length).toBe(0);
done();

View File

@@ -17,49 +17,36 @@
import { Injectable } from '@angular/core';
import { Response } from '@angular/http';
import { AlfrescoApiService, LogService } from 'ng2-alfresco-core';
import { Observable } from 'rxjs/Rx';
import { User } from '../models/user.model';
import { LightUserRepresentation } from '../models/user-process.model';
import { AlfrescoApiService } from './alfresco-api.service';
import { LogService } from './log.service';
@Injectable()
export class PeopleService {
export class PeopleProcessService {
constructor(private alfrescoJsApi: AlfrescoApiService,
private logService: LogService) {
}
getWorkflowUsers(taskId?: string, searchWord?: string): Observable<User[]> {
getWorkflowUsers(taskId?: string, searchWord?: string): Observable<LightUserRepresentation[]> {
let option = { excludeTaskId: taskId, filter: searchWord };
return Observable.fromPromise(this.getWorkflowUserApi(option))
.map((response: any) => <User[]> response.data || [])
.map((response: any) => <LightUserRepresentation[]> response.data || [])
.catch(err => this.handleError(err));
}
getWorkflowUsersWithImages(taskId?: string, searchWord?: string): Observable<User[]> {
let option = { excludeTaskId: taskId, filter: searchWord };
return Observable.fromPromise(this.getWorkflowUserApi(option))
.switchMap((response: any) => <User[]> response.data || [])
.map((user: User) => this.addImageToUser(user))
.combineAll()
.catch(err => this.handleError(err));
}
getUserImage(user: User): string {
getUserImage(user: LightUserRepresentation): string {
return this.getUserProfileImageApi(user.id + '');
}
addImageToUser(user: User): Observable<User> {
user.userImage = this.getUserImage(user);
return Observable.of(user);
}
involveUserWithTask(taskId: string, idToInvolve: string): Observable<User[]> {
involveUserWithTask(taskId: string, idToInvolve: string): Observable<LightUserRepresentation[]> {
let node = {userId: idToInvolve};
return Observable.fromPromise(this.involveUserToTaskApi(taskId, node))
.catch(err => this.handleError(err));
}
removeInvolvedUser(taskId: string, idToRemove: string): Observable<User[]> {
removeInvolvedUser(taskId: string, idToRemove: string): Observable<LightUserRepresentation[]> {
let node = {userId: idToRemove};
return Observable.fromPromise(this.removeInvolvedUserFromTaskApi(taskId, node))
.catch(err => this.handleError(err));