[ADF-2588] make comment component compatible with content (#3128)

This commit is contained in:
Mario Romano
2018-03-30 11:13:38 +01:00
committed by Eugenio Romano
parent f985dd11d5
commit 653a510a5c
46 changed files with 1186 additions and 462 deletions

View File

@@ -1,31 +0,0 @@
<mat-list class="adf-comment-list">
<mat-list-item *ngFor="let comment of comments"
(click)="selectComment(comment)"
class="adf-comment-list-item"
[class.is-selected]="comment.isSelected"
id="adf-comment-{{comment?.id}}">
<div id="comment-user-icon" class="adf-comment-img-container">
<div
*ngIf="!comment.createdBy.pictureId"
class="adf-comment-user-icon">
{{getUserShortName(comment.createdBy)}}</div>
<div>
<img *ngIf="comment.createdBy.pictureId"
class="adf-people-img"
[src]="peopleProcessService.getUserImage(comment.createdBy)"
/>
</div>
</div>
<div class="adf-comment-contents">
<div matLine id="comment-user" class="adf-comment-user-name">
{{comment.createdBy?.firstName}} {{comment.createdBy?.lastName}}
</div>
<div matLine id="comment-message" class="adf-comment-message">
{{comment.message}}
</div>
<div matLine id="comment-time" class="adf-comment-message-time">
{{transformDate(comment.created)}}
</div>
</div>
</mat-list-item>
</mat-list>

View File

@@ -1,94 +0,0 @@
@mixin adf-task-list-comment-list-theme($theme) {
$primary: map-get($theme, primary);
$primaryColor: mat-color($primary, 100);
$rippleColor: mat-color($primary, 300);
.is-selected {
background: mat-color($primary, 100);
}
.adf {
&-comment-img-container {
float: left;
width: 40px;
height: 100%;
display: flex;
align-self: flex-start;
padding-top: 18px;
}
&-comment-list-item {
white-space: initial;
display: table-row-group;
padding-top: 12px;
overflow: hidden;
height: 100% !important;
transition: background 0.8s;
background-position: center;
&:hover {
background: $primaryColor radial-gradient(circle, transparent 1%, $primaryColor 1%) center/15000%;
}
&:active {
background-color: $rippleColor;
background-size: 100%;
transition: background 0s;
}
}
&-comment-user-icon {
padding: 10px 5px;
width: 30px;
background-color: mat-color($primary);
border-radius: 50%;
font-size: 16px;
text-align: center;
height: 20px;
background-size: cover;
}
&-comment-user-name {
float: left;
width: calc(100% - 10%);
padding: 2px 10px;
font-weight: 600;
font-size: 14px;
}
&-comment-message {
float: left;
width: calc(100% - 10px);
padding: 2px 10px;
font-style: italic;
white-space: initial !important;
font-size: 14px;
letter-spacing: -0.2px;
line-height: 1.43;
opacity: 0.54;
}
&-comment-message-time {
float: left;
width: calc(100% - 10%);
padding: 2px 10px;
font-size: 12px !important;
opacity: 0.54;
}
&-comment-contents {
width: calc(100% - 10px);
padding-top: 12px;
padding-bottom: 12px;
padding-left: 5px;
}
&-people-img {
border-radius: 90%;
width: 40px;
height: 40px;
vertical-align: middle;
}
}
}

View File

@@ -1,193 +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 { DatePipe } from '@angular/common';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { CommentProcessModel, UserProcessModel } from '@alfresco/adf-core';
import { CommentListComponent } from './comment-list.component';
import { By } from '@angular/platform-browser';
const testUser: UserProcessModel = new UserProcessModel({
id: '1',
firstName: 'Test',
lastName: 'User',
email: 'tu@domain.com'
});
const testDate = new Date();
const testComment: CommentProcessModel = new CommentProcessModel({
id: 1,
message: 'Test Comment',
created: testDate.toDateString(),
createdBy: testUser
});
const secondtestComment: CommentProcessModel = new CommentProcessModel({
id: 2,
message: '2nd Test Comment',
created: new Date().toDateString(),
createdBy: testUser
});
describe('CommentListComponent', () => {
let commentList: CommentListComponent;
let fixture: ComponentFixture<CommentListComponent>;
let element: HTMLElement;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
CommentListComponent
],
providers: [
DatePipe
]
}).compileComponents().then(() => {
fixture = TestBed.createComponent(CommentListComponent);
commentList = fixture.componentInstance;
element = fixture.nativeElement;
fixture.detectChanges();
});
}));
it('should emit row click event', async(() => {
commentList.comments = [testComment];
commentList.clickRow.subscribe(selectedComment => {
expect(selectedComment.id).toEqual(1);
expect(selectedComment.message).toEqual('Test Comment');
expect(selectedComment.createdBy).toEqual(testUser);
expect(selectedComment.created).toEqual(testDate.toDateString());
expect(selectedComment.isSelected).toBeTruthy();
});
fixture.detectChanges();
fixture.whenStable().then(() => {
let comment = fixture.debugElement.query(By.css('#adf-comment-1'));
comment.triggerEventHandler('click', null);
});
}));
it('should deselect the previous selected comment when a new one is clicked', async(() => {
testComment.isSelected = true;
commentList.selectedComment = testComment;
commentList.comments = [testComment, secondtestComment];
commentList.clickRow.subscribe(selectedComment => {
fixture.detectChanges();
let commentSelectedList = fixture.nativeElement.querySelectorAll('.is-selected');
expect(commentSelectedList.length).toBe(1);
expect(commentSelectedList[0].textContent).toContain('2nd Test Comment');
});
fixture.detectChanges();
fixture.whenStable().then(() => {
let comment = fixture.debugElement.query(By.css('#adf-comment-2'));
comment.triggerEventHandler('click', null);
});
}));
it('should not show comment list if no input is given', async(() => {
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(fixture.nativeElement.querySelector('adf-datatable')).toBeNull();
});
}));
it('should show comment message when input is given', async(() => {
commentList.comments = [testComment];
fixture.detectChanges();
fixture.whenStable().then(() => {
let elements = fixture.nativeElement.querySelectorAll('#comment-message');
expect(elements.length).toBe(1);
expect(elements[0].innerText).toBe(testComment.message);
expect(fixture.nativeElement.querySelector('#comment-message:empty')).toBeNull();
});
}));
it('should show comment user when input is given', async(() => {
commentList.comments = [testComment];
fixture.detectChanges();
fixture.whenStable().then(() => {
let elements = fixture.nativeElement.querySelectorAll('#comment-user');
expect(elements.length).toBe(1);
expect(elements[0].innerText).toBe(testComment.createdBy.firstName + ' ' + testComment.createdBy.lastName);
expect(fixture.nativeElement.querySelector('#comment-user:empty')).toBeNull();
});
}));
it('should show comment date time when input is given', async(() => {
commentList.comments = [testComment];
fixture.detectChanges();
fixture.whenStable().then(() => {
let elements = fixture.nativeElement.querySelectorAll('#comment-time');
expect(elements.length).toBe(1);
expect(elements[0].innerText).toBe(commentList.transformDate(testDate.toDateString()));
expect(fixture.nativeElement.querySelector('#comment-time:empty')).toBeNull();
});
}));
it('comment date time should start with Today when comment date is today', async(() => {
commentList.comments = [testComment];
fixture.detectChanges();
fixture.whenStable().then(() => {
element = fixture.nativeElement.querySelector('#comment-time');
expect(element.innerText).toContain('Today');
});
}));
it('comment date time should start with Yesterday when comment date is yesterday', async(() => {
testComment.created = new Date((Date.now() - 24 * 3600 * 1000));
commentList.comments = [testComment];
fixture.detectChanges();
fixture.whenStable().then(() => {
element = fixture.nativeElement.querySelector('#comment-time');
expect(element.innerText).toContain('Yesterday');
});
}));
it('comment date time should not start with Today/Yesterday when comment date is before yesterday', async(() => {
testComment.created = new Date((Date.now() - 24 * 3600 * 1000 * 2));
commentList.comments = [testComment];
fixture.detectChanges();
fixture.whenStable().then(() => {
element = fixture.nativeElement.querySelector('#comment-time');
expect(element.innerText).not.toContain('Today');
expect(element.innerText).not.toContain('Yesterday');
});
}));
it('should show user icon when input is given', async(() => {
commentList.comments = [testComment];
fixture.detectChanges();
fixture.whenStable().then(() => {
let elements = fixture.nativeElement.querySelectorAll('#comment-user-icon');
expect(elements.length).toBe(1);
expect(elements[0].innerText).toContain(commentList.getUserShortName(testComment.createdBy));
expect(fixture.nativeElement.querySelector('#comment-user-icon:empty')).toBeNull();
});
}));
});

View File

@@ -1,82 +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 { CommentProcessModel, PeopleProcessService, UserProcessModel } from '@alfresco/adf-core';
import { DatePipe } from '@angular/common';
import { Component, EventEmitter, Input, Output, ViewEncapsulation } from '@angular/core';
@Component({
selector: 'adf-comment-list',
templateUrl: './comment-list.component.html',
styleUrls: ['./comment-list.component.scss'],
encapsulation: ViewEncapsulation.None
})
export class CommentListComponent {
/** The comments data used to populate the list. */
@Input()
comments: CommentProcessModel[];
/** Emitted when the user clicks on one of the comment rows. */
@Output()
clickRow: EventEmitter<CommentProcessModel> = new EventEmitter<CommentProcessModel>();
selectedComment: CommentProcessModel;
constructor(private datePipe: DatePipe, public peopleProcessService: PeopleProcessService) {
}
selectComment(comment: CommentProcessModel): void {
if (this.selectedComment) {
this.selectedComment.isSelected = false;
}
comment.isSelected = true;
this.selectedComment = comment;
this.clickRow.emit(this.selectedComment);
}
getUserShortName(user: UserProcessModel): string {
let shortName = '';
if (user) {
if (user.firstName) {
shortName = user.firstName[0].toUpperCase();
}
if (user.lastName) {
shortName += user.lastName[0].toUpperCase();
}
}
return shortName;
}
transformDate(aDate: string): string {
let formattedDate: string;
let givenDate = Number.parseInt(this.datePipe.transform(aDate, 'yMMdd'));
let today = Number.parseInt(this.datePipe.transform(Date.now(), 'yMMdd'));
if (givenDate === today) {
formattedDate = 'Today, ' + this.datePipe.transform(aDate, 'hh:mm a');
} else {
let yesterday = Number.parseInt(this.datePipe.transform(Date.now() - 24 * 3600 * 1000, 'yMMdd'));
if (givenDate === yesterday) {
formattedDate = 'Yesterday, ' + this.datePipe.transform(aDate, 'hh:mm a');
} else {
formattedDate = this.datePipe.transform(aDate, 'MMM dd y, hh:mm a');
}
}
return formattedDate;
}
}

View File

@@ -1,15 +0,0 @@
<div class="adf-comments-container">
<div id="comment-header" class="adf-comments-header">
{{'ADF_TASK_LIST.DETAILS.COMMENTS.HEADER' | translate: { count: comments?.length} }}
</div>
<div class="adf-comments-input-container" *ngIf="!isReadOnly()">
<mat-form-field class="adf-full-width">
<input matInput id="comment-input" placeholder="{{'ADF_TASK_LIST.DETAILS.COMMENTS.ADD' | translate}}" [(ngModel)]="message" (keyup.enter)="add()" (keyup.esc)="clear()">
</mat-form-field>
</div>
<div *ngIf="comments.length > 0">
<adf-comment-list [comments]="comments">
</adf-comment-list>
</div>
</div>

View File

@@ -1,36 +0,0 @@
@mixin adf-task-list-comment-theme($theme) {
$foreground: map-get($theme, foreground);
$header-border: 1px solid mat-color($foreground, divider);
.adf-comments-container {
height: 100%;
width: 100%;
overflow: auto;
}
.adf-comments-header {
padding: 10px 20px;
font-size: 14px;
font-weight: 600;
border-bottom: $header-border;
}
.adf-comments-input-container {
padding: 0 15px;
width: calc(100% - 30px);
padding-top: 8px;
border-bottom: $header-border;
}
.adf-full-width {
width: 100%;
}
adf-comment-list {
float: left;
overflow: auto;
height: calc(100% - 101px);
width: 100%;
}
}

View File

@@ -1,231 +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 { SimpleChange } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { Observable } from 'rxjs/Observable';
import { FormModule } from '@alfresco/adf-core';
import { CommentProcessService } from '@alfresco/adf-core';
import { DatePipe } from '@angular/common';
import { MatInputModule } from '@angular/material';
import { PeopleProcessService } from '@alfresco/adf-core';
import { TaskListService } from '../task-list/services/tasklist.service';
import { CommentListComponent } from './comment-list.component';
import { CommentsComponent } from './comments.component';
describe('CommentsComponent', () => {
let component: CommentsComponent;
let fixture: ComponentFixture<CommentsComponent>;
let getCommentsSpy: jasmine.Spy;
let addCommentSpy: jasmine.Spy;
let commentProcessService: CommentProcessService;
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
FormModule,
MatInputModule
],
declarations: [
CommentsComponent,
CommentListComponent
],
providers: [
TaskListService,
DatePipe,
PeopleProcessService,
CommentProcessService
]
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(CommentsComponent);
component = fixture.componentInstance;
commentProcessService = fixture.debugElement.injector.get(CommentProcessService);
getCommentsSpy = spyOn(commentProcessService, 'getTaskComments').and.returnValue(Observable.of([
{ message: 'Test1', created: Date.now(), createdBy: {firstName: 'Admin', lastName: 'User'} },
{ message: 'Test2', created: Date.now(), createdBy: {firstName: 'Admin', lastName: 'User'} },
{ message: 'Test3', created: Date.now(), createdBy: {firstName: 'Admin', lastName: 'User'} }
]));
addCommentSpy = spyOn(commentProcessService, 'addTaskComment').and.returnValue(Observable.of({id: 123, message: 'Test Comment', createdBy: {id: '999'}}));
});
it('should load comments when taskId specified', () => {
let change = new SimpleChange(null, '123', true);
component.ngOnChanges({ 'taskId': change });
expect(getCommentsSpy).toHaveBeenCalled();
});
it('should emit an error when an error occurs loading comments', () => {
let emitSpy = spyOn(component.error, 'emit');
getCommentsSpy.and.returnValue(Observable.throw({}));
let change = new SimpleChange(null, '123', true);
component.ngOnChanges({ 'taskId': change });
expect(emitSpy).toHaveBeenCalled();
});
it('should not load comments when no taskId is specified', () => {
fixture.detectChanges();
expect(getCommentsSpy).not.toHaveBeenCalled();
});
it('should display comments when the task has comments', async(() => {
let change = new SimpleChange(null, '123', true);
component.ngOnChanges({ 'taskId': change });
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(fixture.nativeElement.querySelectorAll('#comment-message').length).toBe(3);
expect(fixture.nativeElement.querySelector('#comment-message:empty')).toBeNull();
});
}));
it('should display comments count when the task has comments', async(() => {
let change = new SimpleChange(null, '123', true);
component.ngOnChanges({ 'taskId': change });
fixture.whenStable().then(() => {
fixture.detectChanges();
let element = fixture.nativeElement.querySelector('#comment-header');
expect(element.innerText).toBe('ADF_TASK_LIST.DETAILS.COMMENTS.HEADER');
});
}));
it('should not display comments when the task has no comments', async(() => {
component.taskId = '123';
getCommentsSpy.and.returnValue(Observable.of([]));
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(fixture.nativeElement.querySelector('#comment-container')).toBeNull();
});
}));
it('should display comments input by default', async(() => {
let change = new SimpleChange(null, '123', true);
component.ngOnChanges({ 'taskId': change });
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(fixture.nativeElement.querySelector('#comment-input')).not.toBeNull();
});
}));
it('should not display comments input when the task is readonly', async(() => {
component.readOnly = true;
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(fixture.nativeElement.querySelector('#comment-input')).toBeNull();
});
}));
describe('change detection', () => {
let change = new SimpleChange('123', '456', true);
let nullChange = new SimpleChange('123', null, true);
beforeEach(async(() => {
component.taskId = '123';
fixture.detectChanges();
fixture.whenStable().then(() => {
getCommentsSpy.calls.reset();
});
}));
it('should fetch new comments when taskId changed', () => {
component.ngOnChanges({ 'taskId': change });
expect(getCommentsSpy).toHaveBeenCalledWith('456');
});
it('should not fetch new comments when empty changeset made', () => {
component.ngOnChanges({});
expect(getCommentsSpy).not.toHaveBeenCalled();
});
it('should not fetch new comments when taskId changed to null', () => {
component.ngOnChanges({ 'taskId': nullChange });
expect(getCommentsSpy).not.toHaveBeenCalled();
});
});
describe('Add comment', () => {
beforeEach(async(() => {
component.taskId = '123';
fixture.detectChanges();
fixture.whenStable();
}));
it('should call service to add a comment when enter key is pressed', async(() => {
let event = new KeyboardEvent('keyup', {'key': 'Enter'});
let element = fixture.nativeElement.querySelector('#comment-input');
component.message = 'Test Comment';
element.dispatchEvent(event);
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(addCommentSpy).toHaveBeenCalled();
let elements = fixture.nativeElement.querySelectorAll('#comment-message');
expect(elements.length).toBe(1);
expect(elements[0].innerText).toBe('Test Comment');
});
}));
it('should not call service to add a comment when comment is empty', async(() => {
let event = new KeyboardEvent('keyup', {'key': 'Enter'});
let element = fixture.nativeElement.querySelector('#comment-input');
component.message = '';
element.dispatchEvent(event);
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(addCommentSpy).not.toHaveBeenCalled();
});
}));
it('should clear comment when escape key is pressed', async(() => {
let event = new KeyboardEvent('keyup', {'key': 'Escape'});
let element = fixture.nativeElement.querySelector('#comment-input');
component.message = 'Test comment';
element.dispatchEvent(event);
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
element = fixture.nativeElement.querySelector('#comment-input');
expect(element.value).toBe('');
});
}));
it('should emit an error when an error occurs adding the comment', () => {
let emitSpy = spyOn(component.error, 'emit');
addCommentSpy.and.returnValue(Observable.throw({}));
component.message = 'Test comment';
component.add();
expect(emitSpy).toHaveBeenCalled();
});
});
});

View File

@@ -1,121 +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 { CommentProcessModel, CommentProcessService } from '@alfresco/adf-core';
import { Component, EventEmitter, Input, OnChanges, Output, SimpleChanges } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { Observer } from 'rxjs/Observer';
@Component({
selector: 'adf-comments',
templateUrl: './comments.component.html',
styleUrls: ['./comments.component.scss']
})
export class CommentsComponent implements OnChanges {
/** The numeric ID of the task. */
@Input()
taskId: string;
/** Are the comments read only? */
@Input()
readOnly: boolean = false;
/** Emitted when an error occurs while displaying/adding a comment. */
@Output()
error: EventEmitter<any> = new EventEmitter<any>();
comments: CommentProcessModel [] = [];
private commentObserver: Observer<CommentProcessModel>;
comment$: Observable<CommentProcessModel>;
message: string;
beingAdded: boolean = false;
constructor(private commentProcessService: CommentProcessService) {
this.comment$ = new Observable<CommentProcessModel>(observer => this.commentObserver = observer).share();
this.comment$.subscribe((comment: CommentProcessModel) => {
this.comments.push(comment);
});
}
ngOnChanges(changes: SimpleChanges) {
let taskId = changes['taskId'];
if (taskId) {
if (taskId.currentValue) {
this.getTaskComments(taskId.currentValue);
} else {
this.resetComments();
}
}
}
private getTaskComments(taskId: string): void {
this.resetComments();
if (taskId) {
this.commentProcessService.getTaskComments(taskId).subscribe(
(res: CommentProcessModel[]) => {
res = res.sort((comment1: CommentProcessModel, comment2: CommentProcessModel) => {
let date1 = new Date(comment1.created);
let date2 = new Date(comment2.created);
return date1 > date2 ? -1 : date1 < date2 ? 1 : 0;
});
res.forEach((comment) => {
this.commentObserver.next(comment);
});
},
(err) => {
this.error.emit(err);
}
);
}
}
private resetComments(): void {
this.comments = [];
}
add(): void {
if (this.message && this.message.trim() && !this.beingAdded) {
this.beingAdded = true;
this.commentProcessService.addTaskComment(this.taskId, this.message)
.subscribe(
(res: CommentProcessModel) => {
this.comments.unshift(res);
this.message = '';
this.beingAdded = false;
},
(err) => {
this.error.emit(err);
this.beingAdded = false;
}
);
}
}
clear(): void {
this.message = '';
}
isReadOnly(): boolean {
return this.readOnly;
}
}

View File

@@ -21,7 +21,12 @@ export * from './process-list/process-list.module';
export * from './task-list/task-list.module';
export * from './app-list/apps-list.module';
export * from './attachment/attachment.module';
export * from './comments/comments.module';
/** @deprecated in 2.3.0, part of the module moved in the core */
export { CommentsModule } from '@alfresco/adf-core';
export * from './process-comments/process-comments.module';
export * from './people/people.module';
export * from './content-widget/content-widget.module';
@@ -29,6 +34,12 @@ export * from './process-list';
export * from './task-list';
export * from './app-list';
export * from './attachment';
export * from './comments';
/** @deprecated in 2.3.0, component moved in the core */
export { CommentListComponent } from '@alfresco/adf-core';
/** @deprecated in 2.3.0, component moved in the core */
export { CommentsComponent } from '@alfresco/adf-core';
export * from './process-comments';
export * from './people';
export * from './content-widget';

View File

@@ -21,7 +21,6 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { MatInputModule } from '@angular/material';
import { Observable } from 'rxjs/Observable';
import { CommentListComponent, CommentsComponent } from '../index';
import { CommentProcessService, PeopleProcessService } from '@alfresco/adf-core';
import { ProcessService } from '../process-list/services/process.service';
@@ -40,9 +39,7 @@ describe('ActivitiProcessInstanceComments', () => {
MatInputModule
],
declarations: [
ProcessCommentsComponent,
CommentsComponent,
CommentListComponent
ProcessCommentsComponent
],
providers: [
ProcessService,

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
import { CommentProcessModel, CommentProcessService } from '@alfresco/adf-core';
import { CommentModel, CommentProcessService } from '@alfresco/adf-core';
import { Component, EventEmitter, Input, OnChanges, Output, SimpleChanges } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { Observer } from 'rxjs/Observer';
@@ -39,18 +39,18 @@ export class ProcessCommentsComponent implements OnChanges {
@Output()
error: EventEmitter<any> = new EventEmitter<any>();
comments: CommentProcessModel [] = [];
comments: CommentModel [] = [];
private commentObserver: Observer<CommentProcessModel>;
comment$: Observable<CommentProcessModel>;
private commentObserver: Observer<CommentModel>;
comment$: Observable<CommentModel>;
message: string;
beingAdded: boolean = false;
constructor(private commentProcessService: CommentProcessService) {
this.comment$ = new Observable<CommentProcessModel>(observer => this.commentObserver = observer).share();
this.comment$.subscribe((comment: CommentProcessModel) => {
this.comment$ = new Observable<CommentModel>(observer => this.commentObserver = observer).share();
this.comment$.subscribe((comment: CommentModel) => {
this.comments.push(comment);
});
}
@@ -70,8 +70,8 @@ export class ProcessCommentsComponent implements OnChanges {
this.resetComments();
if (processInstanceId) {
this.commentProcessService.getProcessInstanceComments(processInstanceId).subscribe(
(res: CommentProcessModel[]) => {
res = res.sort((comment1: CommentProcessModel, comment2: CommentProcessModel) => {
(res: CommentModel[]) => {
res = res.sort((comment1: CommentModel, comment2: CommentModel) => {
let date1 = new Date(comment1.created);
let date2 = new Date(comment2.created);
return date1 > date2 ? -1 : date1 < date2 ? 1 : 0;
@@ -96,7 +96,7 @@ export class ProcessCommentsComponent implements OnChanges {
this.beingAdded = true;
this.commentProcessService.addProcessInstanceComment(this.processInstanceId, this.message)
.subscribe(
(res: CommentProcessModel) => {
(res: CommentModel) => {
this.comments.unshift(res);
this.message = '';
this.beingAdded = false;

View File

@@ -20,11 +20,9 @@ import { NgModule } from '@angular/core';
import { TranslateModule } from '@ngx-translate/core';
import { MaterialModule } from '../material.module';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { DataColumnModule, DataTableModule } from '@alfresco/adf-core';
import { DataColumnModule, DataTableModule, CommentsModule } from '@alfresco/adf-core';
import { ProcessCommentsComponent } from './process-comments.component';
import { CommentListComponent } from './comment-list.component';
import { CommentsComponent } from './comments.component';
@NgModule({
imports: [
@@ -34,17 +32,15 @@ import { CommentsComponent } from './comments.component';
ReactiveFormsModule,
MaterialModule,
CommonModule,
TranslateModule
TranslateModule,
CommentsModule
],
declarations: [
ProcessCommentsComponent,
CommentListComponent,
CommentsComponent
ProcessCommentsComponent
],
exports: [
ProcessCommentsComponent,
CommentListComponent,
CommentsComponent
ProcessCommentsComponent
]
})
export class CommentsModule {}
export class ProcessCommentsModule {
}

View File

@@ -16,5 +16,3 @@
*/
export * from './process-comments.component';
export * from './comment-list.component';
export * from './comments.component';

View File

@@ -20,13 +20,12 @@ import { NgModule } from '@angular/core';
import { FlexLayoutModule } from '@angular/flex-layout';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { TranslateModule } from '@ngx-translate/core';
import { FormModule } from '@alfresco/adf-core';
import { FormModule, CommentsModule } from '@alfresco/adf-core';
import { MaterialModule } from '../material.module';
import { ProcessCommentsModule } from '../process-comments/process-comments.module';
import { CardViewModule, DataColumnModule, DataTableModule, DirectiveModule, PipeModule } from '@alfresco/adf-core';
import { TaskListModule } from '../task-list/task-list.module';
import { PeopleModule } from '../people/people.module';
import { CommentsModule } from '../comments/comments.module';
import { ContentWidgetModule } from '../content-widget/content-widget.module';
import { ProcessAuditDirective } from './components/process-audit.directive';
@@ -57,7 +56,8 @@ import { ProcessFilterService } from './services/process-filter.service';
DirectiveModule,
PeopleModule,
CommentsModule,
ContentWidgetModule
ContentWidgetModule,
ProcessCommentsModule
],
declarations: [
ProcessInstanceListComponent,
@@ -82,4 +82,5 @@ import { ProcessFilterService } from './services/process-filter.service';
StartProcessInstanceComponent
]
})
export class ProcessListModule {}
export class ProcessListModule {
}

View File

@@ -18,14 +18,14 @@
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { CoreModule, TRANSLATION_PROVIDER } from '@alfresco/adf-core';
import { CoreModule, TRANSLATION_PROVIDER, CommentsModule } from '@alfresco/adf-core';
import { MaterialModule } from './material.module';
import { ProcessListModule } from './process-list/process-list.module';
import { TaskListModule } from './task-list/task-list.module';
import { AppsListModule } from './app-list/apps-list.module';
import { CommentsModule } from './comments/comments.module';
import { ProcessCommentsModule } from './process-comments/process-comments.module';
import { AttachmentModule } from './attachment/attachment.module';
import { PeopleModule } from './people/people.module';
@@ -34,6 +34,7 @@ import { PeopleModule } from './people/people.module';
CoreModule,
CommonModule,
CommentsModule,
ProcessCommentsModule,
FormsModule,
ReactiveFormsModule,
MaterialModule,
@@ -56,6 +57,7 @@ import { PeopleModule } from './people/people.module';
exports: [
CommonModule,
CommentsModule,
ProcessCommentsModule,
FormsModule,
ReactiveFormsModule,
ProcessListModule,

View File

@@ -1,9 +1,7 @@
@import '../process-list/components/process-filters.component';
@import '../attachment/process-attachment-list.component';
@import '../attachment/task-attachment-list.component';
@import '../comments/comment-list.component';
@import '../comments/comments.component';
@import '../comments/process-comments.component';
@import '../process-comments/process-comments.component';
@import '../people/people.module';
@import '../task-list/components/start-task.component';
@import '../task-list/components/task-filters.component';
@@ -13,8 +11,6 @@
@mixin adf-process-services-theme($theme) {
@include adf-process-filters-theme($theme);
@include adf-task-list-comment-list-theme($theme);
@include adf-task-list-comment-theme($theme);
@include adf-process-comment-theme($theme);
@include adf-task-list-start-task-theme($theme);
@include adf-people-module-theme($theme);

View File

@@ -30,6 +30,7 @@ import { noDataMock, taskDetailsMock, taskFormMock, tasksMock, taskDetailsWithOu
import { TaskListService } from './../services/tasklist.service';
import { PeopleSearchComponent } from '../../people';
import { TaskDetailsComponent } from './task-details.component';
import { DatePipe } from '@angular/common';
declare let jasmine: any;
@@ -68,7 +69,8 @@ describe('TaskDetailsComponent', () => {
TaskListService,
PeopleProcessService,
CommentProcessService,
AuthenticationService
AuthenticationService,
DatePipe
],
schemas: [NO_ERRORS_SCHEMA]
}).compileComponents();
@@ -83,7 +85,6 @@ describe('TaskDetailsComponent', () => {
component = fixture.componentInstance;
service = fixture.debugElement.injector.get(TaskListService);
formService = fixture.debugElement.injector.get(FormService);
commentProcessService = TestBed.get(CommentProcessService);
getTaskDetailsSpy = spyOn(service, 'getTaskDetails').and.returnValue(Observable.of(taskDetailsMock));
spyOn(formService, 'getTaskForm').and.returnValue(Observable.of(taskFormMock));
@@ -93,9 +94,14 @@ describe('TaskDetailsComponent', () => {
getTasksSpy = spyOn(service, 'getTasks').and.returnValue(Observable.of(tasksMock));
assignTaskSpy = spyOn(service, 'assignTask').and.returnValue(Observable.of(fakeUser));
completeTaskSpy = spyOn(service, 'completeTask').and.returnValue(Observable.of({}));
spyOn(commentProcessService, 'getTaskComments').and.returnValue(Observable.of(noDataMock));
spyOn(service, 'getTaskChecklist').and.returnValue(Observable.of(noDataMock));
commentProcessService = fixture.debugElement.injector.get(CommentProcessService);
spyOn(commentProcessService, 'getTaskComments').and.returnValue(Observable.of([
{message: 'Test1', created: Date.now(), createdBy: {firstName: 'Admin', lastName: 'User'}},
{message: 'Test2', created: Date.now(), createdBy: {firstName: 'Admin', lastName: 'User'}},
{message: 'Test3', created: Date.now(), createdBy: {firstName: 'Admin', lastName: 'User'}}
]));
});
it('should load task details when taskId specified', () => {
@@ -336,7 +342,7 @@ describe('TaskDetailsComponent', () => {
component.taskDetails.endDate = new Date('2017-10-03T17:03:57.311+0000');
fixture.detectChanges();
expect((component.activiticomments as any).nativeElement.readOnly).toBe(true);
expect((component.activiticomments as any).readOnly).toBe(true);
});
it('should comments be readonly if the task is complete and user are NOT involved', () => {
@@ -348,7 +354,7 @@ describe('TaskDetailsComponent', () => {
component.taskDetails.endDate = new Date('2017-10-03T17:03:57.311+0000');
fixture.detectChanges();
expect((component.activiticomments as any).nativeElement.readOnly).toBe(true);
expect((component.activiticomments as any).readOnly).toBe(true);
});
it('should comments NOT be readonly if the task is NOT complete and user are NOT involved', () => {
@@ -360,7 +366,7 @@ describe('TaskDetailsComponent', () => {
component.taskDetails.endDate = null;
fixture.detectChanges();
expect((component.activiticomments as any).nativeElement.readOnly).toBe(false);
expect((component.activiticomments as any).readOnly).toBe(false);
});
it('should comments NOT be readonly if the task is complete and user are involved', () => {
@@ -372,7 +378,7 @@ describe('TaskDetailsComponent', () => {
component.taskDetails.endDate = new Date('2017-10-03T17:03:57.311+0000');
fixture.detectChanges();
expect((component.activiticomments as any).nativeElement.readOnly).toBe(false);
expect((component.activiticomments as any).readOnly).toBe(false);
});
it('should comments be present if showComments is true', () => {

View File

@@ -22,7 +22,8 @@ import {
ClickNotification,
LogService,
UpdateNotification,
FormRenderingService
FormRenderingService,
CommentsComponent
} from '@alfresco/adf-core';
import {
Component,
@@ -42,7 +43,6 @@ import { ContentLinkModel, FormFieldValidator, FormModel, FormOutcomeEvent } fro
import { TaskQueryRequestRepresentationModel } from '../models/filter.model';
import { TaskDetailsModel } from '../models/task-details.model';
import { TaskListService } from './../services/tasklist.service';
import { CommentsComponent } from '../../comments';
import { AttachFileWidgetComponent, AttachFolderWidgetComponent } from '../../content-widget';
@Component({

View File

@@ -19,14 +19,13 @@ import { CommonModule, DatePipe } from '@angular/common';
import { NgModule } from '@angular/core';
import { FlexLayoutModule } from '@angular/flex-layout';
import { TranslateModule } from '@ngx-translate/core';
import { FormModule } from '@alfresco/adf-core';
import { CardViewModule, DataColumnModule, DataTableModule, DirectiveModule, InfoDrawerModule } from '@alfresco/adf-core';
import { FormModule, CommentsModule } from '@alfresco/adf-core';
import { ProcessCommentsModule } from '../process-comments/process-comments.module';
import { CardViewModule, DataColumnModule, DataTableModule, DirectiveModule, InfoDrawerModule } from '@alfresco/adf-core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { MaterialModule } from '../material.module';
import { PeopleModule } from '../people/people.module';
import { CommentsModule } from '../comments/comments.module';
import { ContentWidgetModule } from '../content-widget/content-widget.module';
import { TaskUploadService } from './services/task-upload.service';
import { ProcessUploadService } from './services/process-upload.service';
@@ -59,6 +58,7 @@ import { TaskStandaloneComponent } from './components/task-standalone.component'
ReactiveFormsModule,
PeopleModule,
CommentsModule,
ProcessCommentsModule,
ContentWidgetModule
],
declarations: [
@@ -91,4 +91,5 @@ import { TaskStandaloneComponent } from './components/task-standalone.component'
TaskStandaloneComponent
]
})
export class TaskListModule {}
export class TaskListModule {
}