[AAE-12179] Remove process-services and content-services dependencies… (#8161)

* [AAE-12179] Remove process-services and content-services dependencies from core comment-list component

* [AAE-12179] Remove comment-list injection token

* [AAE-12179] remove token injection in task module and node module
This commit is contained in:
Diogo Bastos
2023-01-31 15:21:01 +00:00
committed by GitHub
parent 11c3a02acc
commit 0ab39e28fd
28 changed files with 304 additions and 262 deletions

View File

@@ -1,26 +0,0 @@
/*!
* @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 { Observable } from 'rxjs';
import { CommentModel } from '@alfresco/adf-core';
export interface CommentProcessServiceInterface {
addTaskComment(taskId: string, message: string): Observable<CommentModel>;
getTaskComments(taskId: string): Observable<CommentModel[]>;
getProcessInstanceComments(processInstanceId: string): Observable<CommentModel[]>;
addProcessInstanceComment(processInstanceId: string, message: string): Observable<CommentModel>;
}

View File

@@ -18,32 +18,14 @@
import { Injectable } from '@angular/core';
import { Observable, from, of } from 'rxjs';
import { map } from 'rxjs/operators';
import { CommentModel, UserProcessModel } from '@alfresco/adf-core';
import { CommentProcessServiceInterface } from '../interfaces/comment-process.service.interface';
import { testUser, fakeUser1 } from '../mock/comment-process.mock';
import { CommentModel, UserProcessModel, CommentsService } from '@alfresco/adf-core';
import { fakeUser1 } from '../mock/comment-process.mock';
@Injectable()
export class CommentProcessServiceMock implements CommentProcessServiceInterface {
export class CommentProcessServiceMock implements Partial<CommentsService> {
private comments: CommentModel [] = [];
addTaskComment(taskId: string, message: string): Observable<CommentModel> {
const comment = new CommentModel({
id: taskId,
message: message,
created: new Date(),
createdBy: testUser,
isSelected: false
});
this.comments.push(comment);
return of(comment);
}
getTaskComments(_taskId: string): Observable<CommentModel[]> {
return of(this.comments);
}
getProcessInstanceComments(_processInstanceId: string): Observable<CommentModel[]> {
get(_id: string): Observable<CommentModel[]> {
const user = new UserProcessModel(fakeUser1);
this.comments.push(new CommentModel({
@@ -56,7 +38,7 @@ export class CommentProcessServiceMock implements CommentProcessServiceInterface
return of(this.comments);
}
addProcessInstanceComment(_processInstanceId: string, _message: string): Observable<CommentModel> {
add(_id: string, _message: string): Observable<CommentModel> {
return from(this.comments).pipe(
map((response) => new CommentModel({
id: response.id,

View File

@@ -47,7 +47,7 @@ describe('ProcessCommentsComponent', () => {
component = fixture.componentInstance;
commentProcessService = TestBed.inject(CommentProcessService);
getCommentsSpy = spyOn(commentProcessService, 'getProcessInstanceComments').and.returnValue(of(mockProcessInstanceComments));
getCommentsSpy = spyOn(commentProcessService, 'get').and.returnValue(of(mockProcessInstanceComments));
});
it('should load comments when processInstanceId specified', () => {

View File

@@ -76,7 +76,7 @@ export class ProcessCommentsComponent implements OnChanges, OnDestroy {
add(): void {
if (this.message && this.message.trim() && !this.beingAdded) {
this.beingAdded = true;
this.commentProcessService.addProcessInstanceComment(this.processInstanceId, this.message)
this.commentProcessService.add(this.processInstanceId, this.message)
.subscribe(
(res: CommentModel) => {
this.comments.unshift(res);
@@ -107,7 +107,7 @@ export class ProcessCommentsComponent implements OnChanges, OnDestroy {
private getProcessInstanceComments(processInstanceId: string): void {
this.resetComments();
if (processInstanceId) {
this.commentProcessService.getProcessInstanceComments(processInstanceId).subscribe(
this.commentProcessService.get(processInstanceId).subscribe(
(res: CommentModel[]) => {
res = res.sort((comment1: CommentModel, comment2: CommentModel) => {
const date1 = new Date(comment1.created);

View File

@@ -19,9 +19,10 @@ import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { MaterialModule } from '../material.module';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { CoreModule } from '@alfresco/adf-core';
import { ADF_COMMENTS_SERVICE, CoreModule } from '@alfresco/adf-core';
import { ProcessCommentsComponent } from './process-comments.component';
import { CommentProcessService } from './services/comment-process.service';
@NgModule({
imports: [
@@ -36,6 +37,12 @@ import { ProcessCommentsComponent } from './process-comments.component';
],
exports: [
ProcessCommentsComponent
],
providers: [
{
provide: ADF_COMMENTS_SERVICE,
useClass: CommentProcessService
}
]
})
export class ProcessCommentsModule {

View File

@@ -17,15 +17,14 @@
import { Injectable } from '@angular/core';
import { Observable, from, throwError } from 'rxjs';
import { CommentModel, UserProcessModel, AlfrescoApiService, LogService } from '@alfresco/adf-core';
import { CommentModel, UserProcessModel, AlfrescoApiService, LogService, CommentsService, PeopleProcessService } from '@alfresco/adf-core';
import { map, catchError } from 'rxjs/operators';
import { ActivitiCommentsApi } from '@alfresco/js-api';
import { CommentProcessServiceInterface } from '../interfaces/comment-process.service.interface';
@Injectable({
providedIn: 'root'
})
export class CommentProcessService implements CommentProcessServiceInterface {
export class CommentProcessService implements CommentsService {
private _commentsApi: ActivitiCommentsApi;
get commentsApi(): ActivitiCommentsApi {
@@ -34,53 +33,9 @@ export class CommentProcessService implements CommentProcessServiceInterface {
}
constructor(private apiService: AlfrescoApiService,
private logService: LogService) {
}
/**
* Adds a comment to a task.
*
* @param taskId ID of the target task
* @param message Text for the comment
* @returns Details about the comment
*/
addTaskComment(taskId: string, message: string): Observable<CommentModel> {
return from(this.commentsApi.addTaskComment({ message }, taskId))
.pipe(
map((response) => new CommentModel({
id: response.id,
message: response.message,
created: response.created,
createdBy: response.createdBy
})),
catchError((err: any) => this.handleError(err))
);
}
/**
* Gets all comments that have been added to a task.
*
* @param taskId ID of the target task
* @returns Details for each comment
*/
getTaskComments(taskId: string): Observable<CommentModel[]> {
return from(this.commentsApi.getTaskComments(taskId))
.pipe(
map((response) => {
const comments: CommentModel[] = [];
response.data.forEach((comment) => {
const user = new UserProcessModel(comment.createdBy);
comments.push(new CommentModel({
id: comment.id,
message: comment.message,
created: comment.created,
createdBy: user
}));
});
return comments;
}),
catchError((err: any) => this.handleError(err))
);
private logService: LogService,
private peopleProcessService: PeopleProcessService
) {
}
/**
@@ -89,8 +44,8 @@ export class CommentProcessService implements CommentProcessServiceInterface {
* @param processInstanceId ID of the target process instance
* @returns Details for each comment
*/
getProcessInstanceComments(processInstanceId: string): Observable<CommentModel[]> {
return from(this.commentsApi.getProcessInstanceComments(processInstanceId))
get(id: string): Observable<CommentModel[]> {
return from(this.commentsApi.getProcessInstanceComments(id))
.pipe(
map((response) => {
const comments: CommentModel[] = [];
@@ -116,9 +71,9 @@ export class CommentProcessService implements CommentProcessServiceInterface {
* @param message Text for the comment
* @returns Details of the comment added
*/
addProcessInstanceComment(processInstanceId: string, message: string): Observable<CommentModel> {
add(id: string, message: string): Observable<CommentModel> {
return from(
this.commentsApi.addProcessInstanceComment({ message }, processInstanceId)
this.commentsApi.addProcessInstanceComment({ message }, id)
).pipe(
map((response) => new CommentModel({
id: response.id,
@@ -135,4 +90,7 @@ export class CommentProcessService implements CommentProcessServiceInterface {
return throwError(error || 'Server error');
}
getUserImage(user: any): string {
return this.peopleProcessService.getUserImage(user);
}
}

View File

@@ -57,7 +57,7 @@ describe('ProcessInstanceDetailsComponent', () => {
const commentService = fixture.debugElement.injector.get(CommentProcessService);
getProcessSpy = spyOn(service, 'getProcess').and.returnValue(of(exampleProcess));
spyOn(commentService, 'getProcessInstanceComments').and.returnValue(of(mockProcessInstanceComments));
spyOn(commentService, 'get').and.returnValue(of(mockProcessInstanceComments));
});
afterEach(() => {

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
import { AlfrescoApiService, CommentModel, CommentsService, UserProcessModel } from '@alfresco/adf-core';
import { AlfrescoApiService, CommentModel, CommentsService, PeopleProcessService, UserProcessModel } from '@alfresco/adf-core';
import { ActivitiCommentsApi, CommentRepresentation } from '@alfresco/js-api';
import { Injectable } from '@angular/core';
import { from, Observable, throwError } from 'rxjs';
@@ -33,7 +33,8 @@ export class TaskCommentsService implements CommentsService {
}
constructor(
private apiService: AlfrescoApiService
private apiService: AlfrescoApiService,
private peopleProcessService: PeopleProcessService
) {}
/**
@@ -104,4 +105,8 @@ export class TaskCommentsService implements CommentsService {
private handleError(error: any) {
return throwError(error || 'Server error');
}
getUserImage(user: UserProcessModel): string {
return this.peopleProcessService.getUserImage(user);
}
}

View File

@@ -30,7 +30,6 @@ import {
PeopleProcessService,
CommentModel
} from '@alfresco/adf-core';
import { CommentProcessService } from '../../process-comments/services/comment-process.service';
import { TaskDetailsModel } from '../models/task-details.model';
import {
noDataMock,
@@ -45,6 +44,7 @@ import { ProcessTestingModule } from '../../testing/process.testing.module';
import { TranslateModule } from '@ngx-translate/core';
import { TaskService } from '../../form/services/task.service';
import { TaskFormService } from '../../form/services/task-form.service';
import { TaskCommentsService } from '../../task-comments/services/task-comments.service';
const fakeUser = new UserProcessModel({
id: 'fake-id',
@@ -71,7 +71,7 @@ describe('TaskDetailsComponent', () => {
let getTasksSpy: jasmine.Spy;
let assignTaskSpy: jasmine.Spy;
let logService: LogService;
let commentProcessService: CommentProcessService;
let taskCommentsService: TaskCommentsService;
let peopleProcessService: PeopleProcessService;
let bpmUserService: BpmUserService;
@@ -102,9 +102,9 @@ describe('TaskDetailsComponent', () => {
getTasksSpy = spyOn(taskListService, 'getTasks').and.returnValue(of(tasksMock));
assignTaskSpy = spyOn(taskListService, 'assignTask').and.returnValue(of(fakeTaskAssignResponse));
commentProcessService = TestBed.inject(CommentProcessService);
taskCommentsService = TestBed.inject(TaskCommentsService);
spyOn(commentProcessService, 'getTaskComments').and.returnValue(of([
spyOn(taskCommentsService, 'get').and.returnValue(of([
new CommentModel({ message: 'Test1', created: Date.now(), createdBy: { firstName: 'Admin', lastName: 'User' } }),
new CommentModel({ message: 'Test2', created: Date.now(), createdBy: { firstName: 'Admin', lastName: 'User' } }),
new CommentModel({ message: 'Test3', created: Date.now(), createdBy: { firstName: 'Admin', lastName: 'User' } })