mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[AE-11486] remove unused comment services and improve doc (#8092)
* remove unused comment services and improve doc * fix after review * fix unit test * fix stories
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
/*!
|
||||
* @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>;
|
||||
}
|
@@ -0,0 +1,69 @@
|
||||
/*!
|
||||
* @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 { 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';
|
||||
|
||||
@Injectable()
|
||||
export class CommentProcessServiceMock implements CommentProcessServiceInterface {
|
||||
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[]> {
|
||||
const user = new UserProcessModel(fakeUser1);
|
||||
|
||||
this.comments.push(new CommentModel({
|
||||
id: 46,
|
||||
message: 'Hello from Process Model',
|
||||
created: new Date('2022-08-02T03:37:30.010+0000'),
|
||||
createdBy: user
|
||||
}));
|
||||
|
||||
return of(this.comments);
|
||||
}
|
||||
|
||||
addProcessInstanceComment(_processInstanceId: string, _message: string): Observable<CommentModel> {
|
||||
return from(this.comments).pipe(
|
||||
map((response) => new CommentModel({
|
||||
id: response.id,
|
||||
message: response.message,
|
||||
created: response.created,
|
||||
createdBy: response.createdBy
|
||||
}))
|
||||
);
|
||||
}
|
||||
}
|
@@ -0,0 +1,40 @@
|
||||
/*!
|
||||
* @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 { EcmUserModel } from '@alfresco/adf-core';
|
||||
|
||||
export const fakeUser1 = { id: 1, email: 'fake-email@dom.com', firstName: 'firstName', lastName: 'lastName' };
|
||||
|
||||
export const testUser: EcmUserModel = {
|
||||
id: '44',
|
||||
email: 'test.user@hyland.com',
|
||||
firstName: 'Test',
|
||||
lastName: 'User',
|
||||
company: {
|
||||
organization: '',
|
||||
address1: '',
|
||||
address2: '',
|
||||
address3: '',
|
||||
postcode: '',
|
||||
telephone: '',
|
||||
fax: '',
|
||||
email: ''
|
||||
},
|
||||
enabled: true,
|
||||
isAdmin: undefined,
|
||||
avatarId: '044'
|
||||
};
|
@@ -19,7 +19,8 @@ import { SimpleChange } from '@angular/core';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { of, throwError } from 'rxjs';
|
||||
|
||||
import { CommentProcessService, setupTestBed } from '@alfresco/adf-core';
|
||||
import { setupTestBed } from '@alfresco/adf-core';
|
||||
import { CommentProcessService } from './services/comment-process.service';
|
||||
|
||||
import { ProcessCommentsComponent } from './process-comments.component';
|
||||
import { ProcessTestingModule } from '../testing/process.testing.module';
|
||||
|
@@ -15,7 +15,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { CommentModel, CommentProcessService } from '@alfresco/adf-core';
|
||||
import { CommentModel } from '@alfresco/adf-core';
|
||||
import { CommentProcessService } from './services/comment-process.service';
|
||||
import { Component, EventEmitter, Input, OnChanges, Output, SimpleChanges, OnDestroy, ViewEncapsulation } from '@angular/core';
|
||||
import { Observable, Observer, Subject } from 'rxjs';
|
||||
import { share, takeUntil } from 'rxjs/operators';
|
||||
|
@@ -17,4 +17,6 @@
|
||||
|
||||
export * from './process-comments.component';
|
||||
|
||||
export * from './services/comment-process.service';
|
||||
|
||||
export * from './process-comments.module';
|
||||
|
@@ -0,0 +1,138 @@
|
||||
/*!
|
||||
* @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 { Injectable } from '@angular/core';
|
||||
import { Observable, from, throwError } from 'rxjs';
|
||||
import { CommentModel, UserProcessModel, AlfrescoApiService, LogService } 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 {
|
||||
|
||||
_commentsApi: ActivitiCommentsApi;
|
||||
get commentsApi(): ActivitiCommentsApi {
|
||||
this._commentsApi = this._commentsApi ?? new ActivitiCommentsApi(this.apiService.getInstance());
|
||||
return this._commentsApi;
|
||||
}
|
||||
|
||||
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))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all comments that have been added to a process instance.
|
||||
*
|
||||
* @param processInstanceId ID of the target process instance
|
||||
* @returns Details for each comment
|
||||
*/
|
||||
getProcessInstanceComments(processInstanceId: string): Observable<CommentModel[]> {
|
||||
return from(this.commentsApi.getProcessInstanceComments(processInstanceId))
|
||||
.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))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a comment to a process instance.
|
||||
*
|
||||
* @param processInstanceId ID of the target process instance
|
||||
* @param message Text for the comment
|
||||
* @returns Details of the comment added
|
||||
*/
|
||||
addProcessInstanceComment(processInstanceId: string, message: string): Observable<CommentModel> {
|
||||
return from(
|
||||
this.commentsApi.addProcessInstanceComment({ message }, processInstanceId)
|
||||
).pipe(
|
||||
map((response) => new CommentModel({
|
||||
id: response.id,
|
||||
message: response.message,
|
||||
created: response.created,
|
||||
createdBy: response.createdBy
|
||||
})),
|
||||
catchError((err: any) => this.handleError(err))
|
||||
);
|
||||
}
|
||||
|
||||
private handleError(error: any) {
|
||||
this.logService.error(error);
|
||||
return throwError(error || 'Server error');
|
||||
}
|
||||
|
||||
}
|
@@ -20,7 +20,8 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { of } from 'rxjs';
|
||||
|
||||
import { setupTestBed, CommentProcessService } from '@alfresco/adf-core';
|
||||
import { setupTestBed } from '@alfresco/adf-core';
|
||||
import { CommentProcessService } from '../../process-comments/services/comment-process.service';
|
||||
import { TaskListModule } from '../../task-list/task-list.module';
|
||||
|
||||
import { exampleProcess, exampleProcessNoName, mockRunningProcess, processEnded } from './../../mock';
|
||||
|
@@ -25,11 +25,12 @@ import {
|
||||
FormOutcomeModel,
|
||||
setupTestBed,
|
||||
BpmUserService,
|
||||
CommentProcessService, LogService,
|
||||
LogService,
|
||||
UserProcessModel,
|
||||
PeopleProcessService,
|
||||
CommentModel
|
||||
} from '@alfresco/adf-core';
|
||||
import { CommentProcessService } from '../../process-comments/services/comment-process.service';
|
||||
import { TaskDetailsModel } from '../models/task-details.model';
|
||||
import {
|
||||
noDataMock,
|
||||
|
Reference in New Issue
Block a user