mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[AAE-10768] Make the comments reusable (#7983)
* [AAE-10768] Refactor core comments * [AAE-10768] Add models export in core comments refactor * [AAE-10768] Add comments implementation inside process-services package * [AAE-10768] Add task comments module to process module * [AAE-10768] Add node comments module to content services * [AAE-10768] Add id check to getComments and addComments in adf-core comments component * [AAE-10768] Remove unused service files in process-comments module * [AAE-10768] Remove unused service files in process-comments module * [AAE-10768] Add testing logic to spec files * [AAE-10768] Add comments components readme * [AAE-10768] Add a mock service to inject into the comment stories file * [AAE-10768] Add mock data for comments stories * [AAE-10768] Add mock service to inject into comments stories * [AAE-10768] Rename mock service and mock data * [AAE-10768] change taskId with id into the comments test because taskId is never used * [AAE-10768] Resolve pr suggestions * [AAE-10768] Resolve task-comments pr suggestions * [AAE-10768] Resolve comments pr suggestions * [AAE-10768] Fix merge error in comments.component.html * [AAE-10768] Add missing markdown files * [AAE-10768] Remove events from md files * [AAE-10768] Update upgrade50-60.md with renamed input property Co-authored-by: Amedeo Lepore <amedeo.lepore@hyland.com>
This commit is contained in:
@@ -31,6 +31,7 @@ import { PeopleModule } from './people/people.module';
|
||||
import { FormModule } from './form/form.module';
|
||||
import { ProcessFormRenderingService } from './form/process-form-rendering.service';
|
||||
import { ProcessServicesPipeModule } from './pipes/process-services-pipe.module';
|
||||
import { TaskCommentsModule } from './task-comments/task-comments.module';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
@@ -42,6 +43,7 @@ import { ProcessServicesPipeModule } from './pipes/process-services-pipe.module'
|
||||
MaterialModule,
|
||||
ProcessListModule,
|
||||
TaskListModule,
|
||||
TaskCommentsModule,
|
||||
AppsListModule,
|
||||
AttachmentModule,
|
||||
PeopleModule,
|
||||
@@ -65,6 +67,7 @@ import { ProcessServicesPipeModule } from './pipes/process-services-pipe.module'
|
||||
ReactiveFormsModule,
|
||||
ProcessListModule,
|
||||
TaskListModule,
|
||||
TaskCommentsModule,
|
||||
AppsListModule,
|
||||
AttachmentModule,
|
||||
PeopleModule,
|
||||
|
18
lib/process-services/src/lib/task-comments/index.ts
Normal file
18
lib/process-services/src/lib/task-comments/index.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2019 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.
|
||||
*/
|
||||
|
||||
export * from './public-api';
|
@@ -0,0 +1,32 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2019 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.
|
||||
*/
|
||||
|
||||
export const fakeUser1 = { id: 1, email: 'fake-email@dom.com', firstName: 'firstName', lastName: 'lastName' };
|
||||
|
||||
export const fakeUser2 = { id: 1001, email: 'some-one@somegroup.com', firstName: 'some', lastName: 'one' };
|
||||
|
||||
export const fakeTasksComment = {
|
||||
size: 2, total: 2, start: 0,
|
||||
data: [
|
||||
{
|
||||
id: 1, message: 'fake-message-1', created: '', createdBy: fakeUser1
|
||||
},
|
||||
{
|
||||
id: 2, message: 'fake-message-2', created: '', createdBy: fakeUser1
|
||||
}
|
||||
]
|
||||
};
|
22
lib/process-services/src/lib/task-comments/public-api.ts
Normal file
22
lib/process-services/src/lib/task-comments/public-api.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2019 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.
|
||||
*/
|
||||
|
||||
export * from './task-comments.component';
|
||||
|
||||
export * from './services/task-comments.service';
|
||||
|
||||
export * from './task-comments.module';
|
@@ -0,0 +1,94 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2019 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 { TestBed } from '@angular/core/testing';
|
||||
import { CommentModel, setupTestBed, CoreTestingModule } from '@alfresco/adf-core';
|
||||
import { fakeTasksComment, fakeUser1 } from '../mocks/task-comments.mock';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { TaskCommentsService } from './task-comments.service';
|
||||
|
||||
declare let jasmine: any;
|
||||
|
||||
describe('TaskCommentsService', () => {
|
||||
|
||||
let service: TaskCommentsService;
|
||||
|
||||
setupTestBed({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
]
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
service = TestBed.inject(TaskCommentsService);
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
jasmine.Ajax.install();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jasmine.Ajax.uninstall();
|
||||
});
|
||||
|
||||
describe('Task comments', () => {
|
||||
|
||||
it('should add a comment task ', (done) => {
|
||||
service.add('999', 'fake-comment-message').subscribe(
|
||||
(res: CommentModel) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res.id).not.toEqual(null);
|
||||
expect(res.message).toEqual('fake-comment-message');
|
||||
expect(res.created).not.toEqual(null);
|
||||
expect(res.createdBy.email).toEqual('fake-email@dom.com');
|
||||
expect(res.createdBy.firstName).toEqual('firstName');
|
||||
expect(res.createdBy.lastName).toEqual('lastName');
|
||||
done();
|
||||
}
|
||||
);
|
||||
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
responseText: JSON.stringify({
|
||||
id: '111', message: 'fake-comment-message',
|
||||
createdBy: fakeUser1,
|
||||
created: '2016-07-15T11:19:17.440+0000'
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
it('should return the tasks comments ', (done) => {
|
||||
service.get('999').subscribe(
|
||||
(res: CommentModel[]) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res.length).toEqual(2);
|
||||
expect(res[0].message).toEqual('fake-message-1');
|
||||
expect(res[1].message).toEqual('fake-message-2');
|
||||
done();
|
||||
}
|
||||
);
|
||||
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
responseText: JSON.stringify(fakeTasksComment)
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
@@ -0,0 +1,107 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2019 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 { AlfrescoApiService, CommentModel, CommentsService, UserProcessModel } from '@alfresco/adf-core';
|
||||
import { ActivitiCommentsApi, CommentRepresentation } from '@alfresco/js-api';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { from, Observable, throwError } from 'rxjs';
|
||||
import { catchError, map } from 'rxjs/operators';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class TaskCommentsService implements CommentsService {
|
||||
|
||||
private _commentsApi: ActivitiCommentsApi;
|
||||
get commentsApi(): ActivitiCommentsApi {
|
||||
this._commentsApi = this._commentsApi ?? new ActivitiCommentsApi(this.apiService.getInstance());
|
||||
return this._commentsApi;
|
||||
}
|
||||
|
||||
constructor(
|
||||
private apiService: AlfrescoApiService
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Gets all comments that have been added to a task.
|
||||
*
|
||||
* @param id ID of the target task
|
||||
* @returns Details for each comment
|
||||
*/
|
||||
get(id: string): Observable<CommentModel[]> {
|
||||
return from(this.commentsApi.getTaskComments(id))
|
||||
.pipe(
|
||||
map((response) => {
|
||||
const comments: CommentModel[] = [];
|
||||
|
||||
response.data.forEach((comment: CommentRepresentation) => {
|
||||
this.addToComments(comments, comment);
|
||||
});
|
||||
|
||||
return comments;
|
||||
}),
|
||||
catchError(
|
||||
(err: any) => this.handleError(err)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a comment to a task.
|
||||
*
|
||||
* @param id ID of the target task
|
||||
* @param message Text for the comment
|
||||
* @returns Details about the comment
|
||||
*/
|
||||
add(id: string, message: string): Observable<CommentModel> {
|
||||
return from(this.commentsApi.addTaskComment({ message }, id))
|
||||
.pipe(
|
||||
map(
|
||||
(response: CommentRepresentation) => this.newCommentModel(response)
|
||||
),
|
||||
catchError(
|
||||
(err: any) => this.handleError(err)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private addToComments(comments: CommentModel[], comment: CommentRepresentation): void {
|
||||
const user = new UserProcessModel(comment.createdBy);
|
||||
|
||||
const newComment: CommentRepresentation = {
|
||||
id: comment.id,
|
||||
message: comment.message,
|
||||
created: comment.created,
|
||||
createdBy: user
|
||||
};
|
||||
|
||||
comments.push(this.newCommentModel(newComment));
|
||||
}
|
||||
|
||||
private newCommentModel(representation: CommentRepresentation): CommentModel {
|
||||
return new CommentModel({
|
||||
id: representation.id,
|
||||
message: representation.message,
|
||||
created: representation.created,
|
||||
createdBy: representation.createdBy
|
||||
});
|
||||
}
|
||||
|
||||
private handleError(error: any) {
|
||||
return throwError(error || 'Server error');
|
||||
}
|
||||
}
|
@@ -0,0 +1,5 @@
|
||||
<adf-comments
|
||||
[readOnly]="readOnly"
|
||||
[id]="taskId"
|
||||
>
|
||||
</adf-comments>
|
@@ -0,0 +1,31 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2019 Alfresco Software, Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Component, Input, ViewEncapsulation } from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: 'adf-task-comments',
|
||||
templateUrl: './task-comments.component.html',
|
||||
encapsulation: ViewEncapsulation.None
|
||||
})
|
||||
export class TaskCommentsComponent {
|
||||
@Input()
|
||||
taskId: string;
|
||||
|
||||
@Input()
|
||||
readOnly: boolean;
|
||||
}
|
@@ -0,0 +1,38 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2019 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 { NgModule } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { TaskCommentsComponent } from './task-comments.component';
|
||||
import { TaskCommentsService } from './services/task-comments.service';
|
||||
import { ADF_COMMENTS_SERVICE, CoreModule } from '@alfresco/adf-core';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
CommonModule,
|
||||
CoreModule
|
||||
],
|
||||
declarations: [TaskCommentsComponent],
|
||||
exports: [TaskCommentsComponent],
|
||||
providers: [
|
||||
{
|
||||
provide: ADF_COMMENTS_SERVICE,
|
||||
useClass: TaskCommentsService
|
||||
}
|
||||
]
|
||||
})
|
||||
export class TaskCommentsModule {}
|
@@ -82,10 +82,12 @@
|
||||
<adf-info-drawer-tab label="ADF_TASK_LIST.DETAILS.LABELS.INFO_DRAWER_TAB_ACTIVITY_TITLE">
|
||||
<mat-card *ngIf="showComments">
|
||||
<mat-card-content>
|
||||
<adf-comments #activitiComments
|
||||
[readOnly]="isReadOnlyComment()"
|
||||
[taskId]="taskDetails.id">
|
||||
</adf-comments>
|
||||
<adf-task-comments
|
||||
#activitiComments
|
||||
[readOnly]="isReadOnlyComment()"
|
||||
[taskId]="taskDetails.id"
|
||||
>
|
||||
</adf-task-comments>
|
||||
</mat-card-content>
|
||||
</mat-card>
|
||||
</adf-info-drawer-tab>
|
||||
|
@@ -40,6 +40,7 @@ import { AttachFormComponent } from './components/attach-form.component';
|
||||
import { FormModule } from '../form/form.module';
|
||||
import { ClaimTaskDirective } from './components/task-form/claim-task.directive';
|
||||
import { UnclaimTaskDirective } from './components/task-form/unclaim-task.directive';
|
||||
import { TaskCommentsModule } from '../task-comments/task-comments.module';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
@@ -52,7 +53,8 @@ import { UnclaimTaskDirective } from './components/task-form/unclaim-task.direct
|
||||
CoreModule,
|
||||
PeopleModule,
|
||||
ProcessCommentsModule,
|
||||
ContentWidgetModule
|
||||
ContentWidgetModule,
|
||||
TaskCommentsModule
|
||||
],
|
||||
declarations: [
|
||||
NoTaskDetailsTemplateDirective,
|
||||
|
@@ -23,6 +23,7 @@ export * from './lib/process-comments/index';
|
||||
export * from './lib/people/index';
|
||||
export * from './lib/content-widget/index';
|
||||
export * from './lib/form/index';
|
||||
export * from './lib/task-comments/index';
|
||||
export * from './lib/pipes/process-name.pipe';
|
||||
export * from './lib/pipes/process-services-pipe.module';
|
||||
|
||||
|
Reference in New Issue
Block a user