mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
reduce complexity of the code
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Alfresco Angular 2 Activiti Analytics - Demo</title>
|
||||
<title>Alfresco Angular 2 Activiti Process - Demo</title>
|
||||
<base href="./">
|
||||
|
||||
<!-- Moment js -->
|
||||
|
@@ -15,11 +15,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { UserProcessInstanceFilterRepresentationModel } from '../models/filter.model';
|
||||
import { FilterRepresentationModel } from 'ng2-activiti-tasklist';
|
||||
|
||||
export var fakeFilters = {
|
||||
size: 0, total: 0, start: 0,
|
||||
data: [new UserProcessInstanceFilterRepresentationModel({
|
||||
data: [new FilterRepresentationModel({
|
||||
'name': 'Running',
|
||||
'appId': '22',
|
||||
'recent': true,
|
||||
@@ -30,14 +30,14 @@ export var fakeFilters = {
|
||||
|
||||
export var fakeEmptyFilters = {
|
||||
size: 0, total: 0, start: 0,
|
||||
data: [ ]
|
||||
data: []
|
||||
};
|
||||
|
||||
export var fakeApi = {
|
||||
activiti: {
|
||||
userFiltersApi: {
|
||||
getUserProcessInstanceFilters: (filterOpts) => Promise.resolve({}),
|
||||
createUserProcessInstanceFilter: (filter: UserProcessInstanceFilterRepresentationModel) => Promise.resolve(filter)
|
||||
createUserProcessInstanceFilter: (filter: FilterRepresentationModel) => Promise.resolve(filter)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@@ -18,7 +18,7 @@
|
||||
import { Component, Input, OnInit, ViewChild, OnChanges, SimpleChanges } from '@angular/core';
|
||||
import { AlfrescoTranslationService } from 'ng2-alfresco-core';
|
||||
import { ActivitiProcessService } from './../services/activiti-process.service';
|
||||
import { Comment } from '../models/comment.model';
|
||||
import { Comment } from 'ng2-activiti-tasklist';
|
||||
import { Observer } from 'rxjs/Observer';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
|
||||
|
@@ -18,7 +18,7 @@
|
||||
import { Component, Output, EventEmitter, OnInit, Input, OnChanges, SimpleChanges } from '@angular/core';
|
||||
import { AlfrescoTranslationService } from 'ng2-alfresco-core';
|
||||
import { ActivitiProcessService } from './../services/activiti-process.service';
|
||||
import { FilterRepresentationModel } from '../models/filter.model';
|
||||
import { FilterRepresentationModel } from 'ng2-activiti-tasklist';
|
||||
import { Observable, Observer } from 'rxjs/Rx';
|
||||
|
||||
declare let componentHandler: any;
|
||||
|
@@ -18,7 +18,7 @@
|
||||
import { Component, Input, OnInit, ViewChild, Output, EventEmitter } from '@angular/core';
|
||||
import { AlfrescoTranslationService } from 'ng2-alfresco-core';
|
||||
import { ActivitiProcessService } from './../services/activiti-process.service';
|
||||
import { TaskDetailsModel } from '../models/task-details.model';
|
||||
import { TaskDetailsModel } from 'ng2-activiti-tasklist';
|
||||
import { Observable, Observer } from 'rxjs/Rx';
|
||||
import { DatePipe } from '@angular/common';
|
||||
|
||||
|
@@ -18,9 +18,8 @@
|
||||
import { Component, OnInit, Input, Output, EventEmitter, OnChanges, SimpleChanges } from '@angular/core';
|
||||
import { AlfrescoTranslationService } from 'ng2-alfresco-core';
|
||||
import { ObjectDataTableAdapter, DataRowEvent, DataTableAdapter, ObjectDataRow } from 'ng2-alfresco-datatable';
|
||||
import { TaskQueryRequestRepresentationModel } from 'ng2-activiti-tasklist';
|
||||
import { TaskQueryRequestRepresentationModel, FilterRepresentationModel } from 'ng2-activiti-tasklist';
|
||||
import { ActivitiProcessService } from '../services/activiti-process.service';
|
||||
import { UserProcessInstanceFilterRepresentationModel } from '../models/filter.model';
|
||||
|
||||
@Component({
|
||||
moduleId: module.id,
|
||||
@@ -37,7 +36,7 @@ import { UserProcessInstanceFilterRepresentationModel } from '../models/filter.m
|
||||
export class ActivitiProcessInstanceListComponent implements OnInit, OnChanges {
|
||||
|
||||
@Input()
|
||||
filter: UserProcessInstanceFilterRepresentationModel;
|
||||
filter: FilterRepresentationModel;
|
||||
|
||||
@Input()
|
||||
data: DataTableAdapter;
|
||||
@@ -193,7 +192,7 @@ export class ActivitiProcessInstanceListComponent implements OnInit, OnChanges {
|
||||
return tasks;
|
||||
}
|
||||
|
||||
private convertProcessInstanceToTaskQuery(processFilter: UserProcessInstanceFilterRepresentationModel) {
|
||||
private convertProcessInstanceToTaskQuery(processFilter: FilterRepresentationModel) {
|
||||
let requestNode = {
|
||||
appDefinitionId: processFilter.appId,
|
||||
processDefinitionKey: processFilter.filter.processDefinitionKey,
|
||||
|
@@ -1,38 +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.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* Comment submitted against a process
|
||||
*
|
||||
* @returns {Comment} .
|
||||
*/
|
||||
import { User } from './user.model';
|
||||
|
||||
export class Comment {
|
||||
id: number;
|
||||
message: string;
|
||||
created: string;
|
||||
createdBy: User;
|
||||
|
||||
constructor(id: number, message: string, created: string, createdBy: User) {
|
||||
this.id = id;
|
||||
this.message = message;
|
||||
this.created = created;
|
||||
this.createdBy = createdBy;
|
||||
}
|
||||
}
|
@@ -1,79 +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.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* This object represent the filter.
|
||||
*
|
||||
*
|
||||
* @returns {FilterRepresentationModel} .
|
||||
*/
|
||||
export class FilterRepresentationModel {
|
||||
id: number;
|
||||
appId: string;
|
||||
name: string;
|
||||
recent: boolean;
|
||||
icon: string;
|
||||
filter: FilterParamRepresentationModel;
|
||||
index: number;
|
||||
|
||||
constructor(obj?: any) {
|
||||
this.appId = obj && obj.appId || null;
|
||||
this.name = obj && obj.name || null;
|
||||
this.recent = obj && obj.recent || false;
|
||||
this.icon = obj && obj.icon || null;
|
||||
this.filter = new FilterParamRepresentationModel(obj.filter);
|
||||
this.index = obj && obj.index;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* This object represent the parameters of a filter.
|
||||
*
|
||||
*
|
||||
* @returns {FilterParamRepresentationModel} .
|
||||
*/
|
||||
export class FilterParamRepresentationModel {
|
||||
processDefinitionId: string;
|
||||
processDefinitionKey: string;
|
||||
name: string;
|
||||
state: string;
|
||||
sort: string;
|
||||
|
||||
constructor(obj?: any) {
|
||||
this.processDefinitionId = obj && obj.processDefinitionId || null;
|
||||
this.processDefinitionKey = obj && obj.processDefinitionKey || null;
|
||||
this.name = obj && obj.name || null;
|
||||
this.state = obj && obj.state || null;
|
||||
this.sort = obj && obj.sort || null;
|
||||
}
|
||||
}
|
||||
|
||||
export class UserProcessInstanceFilterRepresentationModel extends FilterRepresentationModel {
|
||||
public filter: ProcessInstanceFilterRepresentation;
|
||||
constructor(obj?: any) {
|
||||
super(obj);
|
||||
this.filter = new ProcessInstanceFilterRepresentation(obj.filter);
|
||||
}
|
||||
}
|
||||
|
||||
export class ProcessInstanceFilterRepresentation extends FilterParamRepresentationModel {
|
||||
constructor(obj?: any) {
|
||||
super(obj);
|
||||
}
|
||||
}
|
@@ -1,92 +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.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* This object represent the details of a task.
|
||||
*
|
||||
*
|
||||
* @returns {TaskDetailsModel} .
|
||||
*/
|
||||
import { User } from './user.model';
|
||||
|
||||
export class TaskDetailsModel {
|
||||
id: string;
|
||||
name: string;
|
||||
assignee: User;
|
||||
priority: number;
|
||||
adhocTaskCanBeReassigned: number;
|
||||
category: string;
|
||||
created: string;
|
||||
description: string;
|
||||
dueDate: string;
|
||||
duration: string;
|
||||
endDate: string;
|
||||
executionId: string;
|
||||
formKey: string;
|
||||
initiatorCanCompleteTask: boolean = false;
|
||||
managerOfCandidateGroup: boolean = false;
|
||||
memberOfCandidateGroup: boolean = false;
|
||||
memberOfCandidateUsers: boolean = false;
|
||||
involvedPeople: User [];
|
||||
parentTaskId: string;
|
||||
parentTaskName: string;
|
||||
processDefinitionCategory: string;
|
||||
processDefinitionDeploymentId: string;
|
||||
processDefinitionDescription: string;
|
||||
processDefinitionId: string;
|
||||
processDefinitionKey: string;
|
||||
processDefinitionName: string;
|
||||
processDefinitionVersion: number = 0;
|
||||
processInstanceId: string;
|
||||
processInstanceName: string;
|
||||
processInstanceStartUserId: string;
|
||||
taskDefinitionKey: string;
|
||||
|
||||
constructor(obj: any) {
|
||||
this.id = obj.id;
|
||||
this.name = obj.name;
|
||||
this.priority = obj.priority;
|
||||
this.assignee = new User(obj.assignee.id, obj.assignee.email, obj.assignee.firstName, obj.assignee.lastName);
|
||||
this.adhocTaskCanBeReassigned = obj.adhocTaskCanBeReassigned;
|
||||
this.created = obj.created;
|
||||
this.description = obj.description;
|
||||
this.dueDate = obj.dueDate;
|
||||
this.duration = obj.duration;
|
||||
this.endDate = obj.endDate;
|
||||
this.executionId = obj.executionId;
|
||||
this.formKey = obj.formKey;
|
||||
this.initiatorCanCompleteTask = obj.initiatorCanCompleteTask;
|
||||
this.managerOfCandidateGroup = obj.managerOfCandidateGroup;
|
||||
this.memberOfCandidateGroup = obj.memberOfCandidateGroup;
|
||||
this.memberOfCandidateUsers = obj.memberOfCandidateUsers;
|
||||
this.involvedPeople = obj.involvedPeople;
|
||||
this.parentTaskId = obj.parentTaskId;
|
||||
this.parentTaskName = obj.parentTaskName;
|
||||
this.processDefinitionCategory = obj.processDefinitionCategory;
|
||||
this.processDefinitionDeploymentId = obj.processDefinitionDeploymentId;
|
||||
this.processDefinitionDescription = obj.processDefinitionDescription;
|
||||
this.processDefinitionId = obj.processDefinitionId;
|
||||
this.processDefinitionKey = obj.processDefinitionKey;
|
||||
this.processDefinitionName = obj.processDefinitionName;
|
||||
this.processDefinitionVersion = obj.processDefinitionVersion;
|
||||
this.processInstanceId = obj.processInstanceId;
|
||||
this.processInstanceName = obj.processInstanceName;
|
||||
this.processInstanceStartUserId = obj.processInstanceStartUserId;
|
||||
this.taskDefinitionKey = obj.taskDefinitionKey;
|
||||
}
|
||||
}
|
@@ -1,38 +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.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* This object represent the user.
|
||||
*
|
||||
*
|
||||
* @returns {User} .
|
||||
*/
|
||||
|
||||
export class User {
|
||||
id: number;
|
||||
email: string;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
|
||||
constructor(id: number, email: string, firstName: string, lastName: string) {
|
||||
this.id = id;
|
||||
this.email = email;
|
||||
this.firstName = firstName;
|
||||
this.lastName = lastName;
|
||||
}
|
||||
}
|
@@ -17,10 +17,7 @@
|
||||
|
||||
import { AlfrescoAuthenticationService } from 'ng2-alfresco-core';
|
||||
import { ProcessInstance } from '../models/process-instance';
|
||||
import { TaskQueryRequestRepresentationModel } from 'ng2-activiti-tasklist';
|
||||
import { UserProcessInstanceFilterRepresentationModel } from '../models/filter.model';
|
||||
import { User } from '../models/user.model';
|
||||
import { Comment } from '../models/comment.model';
|
||||
import { User, Comment, FilterRepresentationModel, TaskQueryRequestRepresentationModel } from 'ng2-activiti-tasklist';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import 'rxjs/add/operator/map';
|
||||
@@ -62,9 +59,9 @@ export class ActivitiProcessService {
|
||||
} : {};
|
||||
return Observable.fromPromise(this.callApiGetUserProcessInstanceFilters(filterOpts))
|
||||
.map((response: any) => {
|
||||
let filters: UserProcessInstanceFilterRepresentationModel[] = [];
|
||||
response.data.forEach((filter: UserProcessInstanceFilterRepresentationModel) => {
|
||||
let filterModel = new UserProcessInstanceFilterRepresentationModel(filter);
|
||||
let filters: FilterRepresentationModel[] = [];
|
||||
response.data.forEach((filter: FilterRepresentationModel) => {
|
||||
let filterModel = new FilterRepresentationModel(filter);
|
||||
filters.push(filterModel);
|
||||
});
|
||||
if (response && response.data && response.data.length === 0) {
|
||||
@@ -78,10 +75,10 @@ export class ActivitiProcessService {
|
||||
/**
|
||||
* Create and return the default filters
|
||||
* @param appId
|
||||
* @returns {UserProcessInstanceFilterRepresentationModel[]}
|
||||
* @returns {FilterRepresentationModel[]}
|
||||
*/
|
||||
private createDefaultFilters(appId: string): UserProcessInstanceFilterRepresentationModel[] {
|
||||
let filters: UserProcessInstanceFilterRepresentationModel[] = [];
|
||||
private createDefaultFilters(appId: string): FilterRepresentationModel[] {
|
||||
let filters: FilterRepresentationModel[] = [];
|
||||
|
||||
let involvedTasksFilter = this.getRunningFilterInstance(appId);
|
||||
this.addFilter(involvedTasksFilter);
|
||||
@@ -101,10 +98,10 @@ export class ActivitiProcessService {
|
||||
/**
|
||||
* Return a static Running filter instance
|
||||
* @param appId
|
||||
* @returns {UserProcessInstanceFilterRepresentationModel}
|
||||
* @returns {FilterRepresentationModel}
|
||||
*/
|
||||
private getRunningFilterInstance(appId: string): UserProcessInstanceFilterRepresentationModel {
|
||||
return new UserProcessInstanceFilterRepresentationModel({
|
||||
private getRunningFilterInstance(appId: string): FilterRepresentationModel {
|
||||
return new FilterRepresentationModel({
|
||||
'name': 'Running',
|
||||
'appId': appId,
|
||||
'recent': true,
|
||||
@@ -116,10 +113,10 @@ export class ActivitiProcessService {
|
||||
/**
|
||||
* Return a static Completed filter instance
|
||||
* @param appId
|
||||
* @returns {UserProcessInstanceFilterRepresentationModel}
|
||||
* @returns {FilterRepresentationModel}
|
||||
*/
|
||||
private getCompletedFilterInstance(appId: string): UserProcessInstanceFilterRepresentationModel {
|
||||
return new UserProcessInstanceFilterRepresentationModel({
|
||||
private getCompletedFilterInstance(appId: string): FilterRepresentationModel {
|
||||
return new FilterRepresentationModel({
|
||||
'name': 'Completed',
|
||||
'appId': appId,
|
||||
'recent': false,
|
||||
@@ -131,10 +128,10 @@ export class ActivitiProcessService {
|
||||
/**
|
||||
* Return a static All filter instance
|
||||
* @param appId
|
||||
* @returns {UserProcessInstanceFilterRepresentationModel}
|
||||
* @returns {FilterRepresentationModel}
|
||||
*/
|
||||
private getAllFilterInstance(appId: string): UserProcessInstanceFilterRepresentationModel {
|
||||
return new UserProcessInstanceFilterRepresentationModel({
|
||||
private getAllFilterInstance(appId: string): FilterRepresentationModel {
|
||||
return new FilterRepresentationModel({
|
||||
'name': 'All',
|
||||
'appId': appId,
|
||||
'recent': true,
|
||||
@@ -145,13 +142,13 @@ export class ActivitiProcessService {
|
||||
|
||||
/**
|
||||
* Add a filter
|
||||
* @param filter - UserProcessInstanceFilterRepresentationModel
|
||||
* @returns {UserProcessInstanceFilterRepresentationModel}
|
||||
* @param filter - FilterRepresentationModel
|
||||
* @returns {FilterRepresentationModel}
|
||||
*/
|
||||
addFilter(filter: UserProcessInstanceFilterRepresentationModel): Observable<UserProcessInstanceFilterRepresentationModel> {
|
||||
addFilter(filter: FilterRepresentationModel): Observable<FilterRepresentationModel> {
|
||||
return Observable.fromPromise(this.callApiAddFilter(filter))
|
||||
.map(res => res)
|
||||
.map((response: UserProcessInstanceFilterRepresentationModel) => {
|
||||
.map((response: FilterRepresentationModel) => {
|
||||
return response;
|
||||
}).catch(this.handleError);
|
||||
}
|
||||
@@ -188,8 +185,12 @@ export class ActivitiProcessService {
|
||||
.map((response: any) => {
|
||||
let comments: Comment[] = [];
|
||||
response.data.forEach((comment) => {
|
||||
let user = new User(
|
||||
comment.createdBy.id, comment.createdBy.email, comment.createdBy.firstName, comment.createdBy.lastName);
|
||||
let user = new User({
|
||||
id: comment.createdBy.id,
|
||||
email: comment.createdBy.email,
|
||||
firstName: comment.createdBy.firstName,
|
||||
lastName: comment.createdBy.lastName
|
||||
});
|
||||
comments.push(new Comment(comment.id, comment.message, comment.created, user));
|
||||
});
|
||||
return comments;
|
||||
@@ -252,7 +253,7 @@ export class ActivitiProcessService {
|
||||
return this.authService.getAlfrescoApi().activiti.userFiltersApi.getUserProcessInstanceFilters(filterOpts);
|
||||
}
|
||||
|
||||
private callApiAddFilter(filter: UserProcessInstanceFilterRepresentationModel) {
|
||||
private callApiAddFilter(filter: FilterRepresentationModel) {
|
||||
return this.authService.getAlfrescoApi().activiti.userFiltersApi.createUserProcessInstanceFilter(filter);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user