mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ACA-3348] Add default process name pipe (#5745)
* [ACA-3348] Add default process name pipe * [ACA-3348] Add documentation * [ACA-3348] Change transform function to recieve a process def parameter, Update documentation * Change parameter type to fix build * Fix lint errors * Move unit test to the correct describe * Fix lint errors * Move from one core pipe to different for APS1 and Cloud * Add Pipe to process cloud providers * Update documentation * Revert demo-shell default process name * Fix pipe version in documentation * e2e - select process definition and then type name * Fix process services e2e * Align process filters e2e * Align start-task-form cloud e2e * Use processInstance model instead of processDefinition as a parameter for transform function
This commit is contained in:
79
lib/process-services/src/lib/pipes/process-name.pipe.spec.ts
Normal file
79
lib/process-services/src/lib/pipes/process-name.pipe.spec.ts
Normal file
@@ -0,0 +1,79 @@
|
||||
/*!
|
||||
* @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 { async, TestBed } from '@angular/core/testing';
|
||||
import { ProcessNamePipe } from './process-name.pipe';
|
||||
import { setupTestBed } from 'core';
|
||||
import { CoreTestingModule } from 'core/testing/core.testing.module';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import moment from 'moment-es6';
|
||||
import { LocalizedDatePipe } from '@alfresco/adf-core';
|
||||
import { ProcessInstance } from '../process-list';
|
||||
|
||||
describe('ProcessNamePipe', () => {
|
||||
|
||||
let processNamePipe: ProcessNamePipe;
|
||||
const defaultName = 'default-name';
|
||||
const datetimeIdentifier = '%{datetime}';
|
||||
const processDefinitionIdentifier = '%{processDefinition}';
|
||||
const mockCurrentDate = 'Wed Oct 23 2019';
|
||||
const mockLocalizedCurrentDate = 'Oct 23, 2019, 12:00:00 AM';
|
||||
const nameWithProcessDefinitionIdentifier = `${defaultName} - ${processDefinitionIdentifier}`;
|
||||
const nameWithDatetimeIdentifier = `${defaultName} - ${datetimeIdentifier}`;
|
||||
const nameWithAllIdentifiers = `${defaultName} ${processDefinitionIdentifier} - ${datetimeIdentifier}`;
|
||||
const fakeProcessInstanceDetails = new ProcessInstance({ processDefinitionName: 'fake-process-def-name'});
|
||||
|
||||
setupTestBed({
|
||||
imports: [
|
||||
TranslateModule.forRoot(),
|
||||
CoreTestingModule
|
||||
]
|
||||
});
|
||||
|
||||
beforeEach(async(() => {
|
||||
const localizedDatePipe = TestBed.get(LocalizedDatePipe);
|
||||
processNamePipe = new ProcessNamePipe(localizedDatePipe);
|
||||
}));
|
||||
|
||||
it('should not modify the name when there is no identifier', () => {
|
||||
const transformResult = processNamePipe.transform(defaultName);
|
||||
expect(transformResult).toEqual(defaultName);
|
||||
});
|
||||
|
||||
it('should add the selected process definition name to the process name', () => {
|
||||
const transformResult = processNamePipe.transform(nameWithProcessDefinitionIdentifier, fakeProcessInstanceDetails);
|
||||
expect(transformResult).toEqual(`${defaultName} - ${fakeProcessInstanceDetails.processDefinitionName}`);
|
||||
});
|
||||
|
||||
it('should add the current datetime to the process name', () => {
|
||||
spyOn(moment, 'now').and.returnValue(mockCurrentDate);
|
||||
const transformResult = processNamePipe.transform(nameWithDatetimeIdentifier);
|
||||
expect(transformResult).toEqual(`${defaultName} - ${mockLocalizedCurrentDate}`);
|
||||
});
|
||||
|
||||
it('should add the current datetime and the selected process definition name when both identifiers are present', () => {
|
||||
spyOn(moment, 'now').and.returnValue(mockCurrentDate);
|
||||
const transformResult = processNamePipe.transform(nameWithAllIdentifiers, fakeProcessInstanceDetails);
|
||||
expect(transformResult).toEqual(`${defaultName} ${fakeProcessInstanceDetails.processDefinitionName} - ${mockLocalizedCurrentDate}`);
|
||||
});
|
||||
|
||||
it('should not modify the process name when processDefinition identifier is present but no process definition is selected', () => {
|
||||
const transformResult = processNamePipe.transform(nameWithProcessDefinitionIdentifier);
|
||||
expect(transformResult).toEqual(`${defaultName} - `);
|
||||
});
|
||||
|
||||
});
|
50
lib/process-services/src/lib/pipes/process-name.pipe.ts
Normal file
50
lib/process-services/src/lib/pipes/process-name.pipe.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
/*!
|
||||
* @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 { Pipe, PipeTransform } from '@angular/core';
|
||||
import moment from 'moment-es6';
|
||||
import { LocalizedDatePipe } from '@alfresco/adf-core';
|
||||
import { ProcessInstance } from '../process-list';
|
||||
|
||||
@Pipe({ name: 'processName' })
|
||||
export class ProcessNamePipe implements PipeTransform {
|
||||
static DATE_TIME_IDENTIFIER_REG_EXP = new RegExp('%{datetime}', 'i');
|
||||
static PROCESS_DEFINITION_IDENTIFIER_REG_EXP = new RegExp('%{processdefinition}', 'i');
|
||||
|
||||
constructor(private localizedDatePipe: LocalizedDatePipe) {
|
||||
}
|
||||
|
||||
transform(processNameFormat: string, processInstance?: ProcessInstance): string {
|
||||
let processName = processNameFormat;
|
||||
if (processName.match(ProcessNamePipe.DATE_TIME_IDENTIFIER_REG_EXP)) {
|
||||
const presentDateTime = moment.now();
|
||||
processName = processName.replace(
|
||||
ProcessNamePipe.DATE_TIME_IDENTIFIER_REG_EXP,
|
||||
this.localizedDatePipe.transform(presentDateTime, 'medium')
|
||||
);
|
||||
}
|
||||
|
||||
if (processName.match(ProcessNamePipe.PROCESS_DEFINITION_IDENTIFIER_REG_EXP)) {
|
||||
const selectedProcessDefinitionName = processInstance ? processInstance.processDefinitionName : '';
|
||||
processName = processName.replace(
|
||||
ProcessNamePipe.PROCESS_DEFINITION_IDENTIFIER_REG_EXP,
|
||||
selectedProcessDefinitionName
|
||||
);
|
||||
}
|
||||
return processName;
|
||||
}
|
||||
}
|
@@ -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 { NgModule } from '@angular/core';
|
||||
|
||||
import { ProcessNamePipe } from './process-name.pipe';
|
||||
|
||||
@NgModule({
|
||||
declarations: [
|
||||
ProcessNamePipe
|
||||
],
|
||||
exports: [
|
||||
ProcessNamePipe
|
||||
]
|
||||
})
|
||||
export class ProcessServicesPipeModule {
|
||||
}
|
@@ -207,6 +207,12 @@ describe('StartFormComponent', () => {
|
||||
expect(cancelSpy).toHaveBeenCalled();
|
||||
});
|
||||
}));
|
||||
|
||||
it('should return true if startFrom defined', async () => {
|
||||
component.name = 'my:process1';
|
||||
await fixture.whenStable();
|
||||
expect(component.hasStartForm()).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('CS content connection', () => {
|
||||
@@ -438,7 +444,7 @@ describe('StartFormComponent', () => {
|
||||
});
|
||||
|
||||
it('should call service to start process if required fields provided', async(() => {
|
||||
component.selectedProcessDef = testProcessDef;
|
||||
component.processDefinitionSelectionChanged(testProcessDef);
|
||||
component.startProcess();
|
||||
fixture.whenStable().then(() => {
|
||||
expect(startProcessSpy).toHaveBeenCalled();
|
||||
@@ -454,7 +460,7 @@ describe('StartFormComponent', () => {
|
||||
}));
|
||||
|
||||
it('should call service to start process with the correct parameters', async(() => {
|
||||
component.selectedProcessDef = testProcessDef;
|
||||
component.processDefinitionSelectionChanged(testProcessDef);
|
||||
component.startProcess();
|
||||
fixture.whenStable().then(() => {
|
||||
expect(startProcessSpy).toHaveBeenCalledWith('my:process1', 'My new process', undefined, undefined, undefined);
|
||||
@@ -471,7 +477,7 @@ describe('StartFormComponent', () => {
|
||||
inputProcessVariable.push(variable);
|
||||
|
||||
component.variables = inputProcessVariable;
|
||||
component.selectedProcessDef = testProcessDef;
|
||||
component.processDefinitionSelectionChanged(testProcessDef);
|
||||
component.startProcess();
|
||||
fixture.whenStable().then(() => {
|
||||
expect(startProcessSpy).toHaveBeenCalledWith('my:process1', 'My new process', undefined, undefined, inputProcessVariable);
|
||||
@@ -480,7 +486,7 @@ describe('StartFormComponent', () => {
|
||||
|
||||
it('should output start event when process started successfully', async(() => {
|
||||
const emitSpy = spyOn(component.start, 'emit');
|
||||
component.selectedProcessDef = testProcessDef;
|
||||
component.processDefinitionSelectionChanged(testProcessDef);
|
||||
component.startProcess();
|
||||
fixture.whenStable().then(() => {
|
||||
expect(emitSpy).toHaveBeenCalledWith(newProcess);
|
||||
@@ -493,7 +499,7 @@ describe('StartFormComponent', () => {
|
||||
done();
|
||||
});
|
||||
|
||||
component.selectedProcessDef = testProcessDef;
|
||||
component.processDefinitionSelectionChanged(testProcessDef);
|
||||
component.name = 'my:Process';
|
||||
component.startProcess();
|
||||
fixture.detectChanges();
|
||||
@@ -535,7 +541,7 @@ describe('StartFormComponent', () => {
|
||||
|
||||
it('should able to start the process when the required fields are filled up', (done) => {
|
||||
component.name = 'my:process1';
|
||||
component.selectedProcessDef = testProcessDef;
|
||||
component.processDefinitionSelectionChanged(testProcessDef);
|
||||
|
||||
const disposableStart = component.start.subscribe(() => {
|
||||
disposableStart.unsubscribe();
|
||||
@@ -544,16 +550,6 @@ describe('StartFormComponent', () => {
|
||||
|
||||
component.startProcess();
|
||||
});
|
||||
|
||||
it('should return true if startFrom defined', async(() => {
|
||||
component.selectedProcessDef = testProcessDef;
|
||||
component.name = 'my:process1';
|
||||
component.selectedProcessDef.hasStartForm = true;
|
||||
component.hasStartForm();
|
||||
fixture.whenStable().then(() => {
|
||||
expect(component.hasStartForm()).toBe(true);
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
describe('Select applications', () => {
|
||||
|
@@ -37,6 +37,7 @@ import { MatAutocompleteTrigger } from '@angular/material';
|
||||
import { StartFormComponent } from '../../form';
|
||||
import { MinimalNode, RelatedContentRepresentation } from '@alfresco/js-api';
|
||||
import { AppDefinitionRepresentationModel } from '../../task-list';
|
||||
import { ProcessNamePipe } from '../../pipes/process-name.pipe';
|
||||
|
||||
@Component({
|
||||
selector: 'adf-start-process',
|
||||
@@ -130,19 +131,16 @@ export class StartProcessInstanceComponent implements OnChanges, OnInit, OnDestr
|
||||
constructor(private activitiProcess: ProcessService,
|
||||
private activitiContentService: ActivitiContentService,
|
||||
private appsProcessService: AppsProcessService,
|
||||
private appConfig: AppConfigService) {
|
||||
private appConfig: AppConfigService,
|
||||
private processNamePipe: ProcessNamePipe) {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.processNameInput = new FormControl(this.name, [Validators.required, Validators.maxLength(this.maxProcessNameLength), Validators.pattern('^[^\\s]+(\\s+[^\\s]+)*$')]);
|
||||
this.processNameInput = new FormControl('', [Validators.required, Validators.maxLength(this.maxProcessNameLength), Validators.pattern('^[^\\s]+(\\s+[^\\s]+)*$')]);
|
||||
this.processDefinitionInput = new FormControl();
|
||||
|
||||
this.load();
|
||||
|
||||
this.processNameInput.valueChanges
|
||||
.pipe(takeUntil(this.onDestroy$))
|
||||
.subscribe(name => this.name = name);
|
||||
|
||||
this.filteredProcessesDefinitions$ = this.processDefinitionInput.valueChanges
|
||||
.pipe(
|
||||
map((value) => this._filter(value)),
|
||||
@@ -244,9 +242,8 @@ export class StartProcessInstanceComponent implements OnChanges, OnInit, OnDestr
|
||||
).subscribe(
|
||||
(filteredProcessDefinitions) => {
|
||||
this.processDefinitions = filteredProcessDefinitions.processDefinitionRepresentations;
|
||||
this.selectedProcessDef = filteredProcessDefinitions.currentProcessDef;
|
||||
this.processDefinitionSelectionChanged(filteredProcessDefinitions.currentProcessDef);
|
||||
this.processDefinitionInput.setValue(this.selectedProcessDef ? this.selectedProcessDef.name : '');
|
||||
this.processDefinitionSelection.emit(this.selectedProcessDef);
|
||||
this.isProcessDefinitionsLoading = false;
|
||||
},
|
||||
(error) => {
|
||||
@@ -262,9 +259,8 @@ export class StartProcessInstanceComponent implements OnChanges, OnInit, OnDestr
|
||||
});
|
||||
|
||||
if (filteredProcessDef) {
|
||||
this.selectedProcessDef = filteredProcessDef;
|
||||
this.processDefinitionSelectionChanged(filteredProcessDef);
|
||||
this.processDefinitionInput.setValue(this.selectedProcessDef ? this.selectedProcessDef.name : '');
|
||||
this.processDefinitionSelection.emit(this.selectedProcessDef);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -373,9 +369,9 @@ export class StartProcessInstanceComponent implements OnChanges, OnInit, OnDestr
|
||||
}
|
||||
|
||||
startProcess(outcome?: string) {
|
||||
if (this.selectedProcessDef && this.selectedProcessDef.id && this.name) {
|
||||
if (this.selectedProcessDef && this.selectedProcessDef.id && this.nameController.value) {
|
||||
const formValues = this.startForm ? this.startForm.form.values : undefined;
|
||||
this.activitiProcess.startProcess(this.selectedProcessDef.id, this.name, outcome, formValues, this.variables).subscribe(
|
||||
this.activitiProcess.startProcess(this.selectedProcessDef.id, this.nameController.value, outcome, formValues, this.variables).subscribe(
|
||||
(res) => {
|
||||
this.name = '';
|
||||
this.start.emit(res);
|
||||
@@ -470,9 +466,18 @@ export class StartProcessInstanceComponent implements OnChanges, OnInit, OnDestr
|
||||
}
|
||||
}
|
||||
|
||||
processDefinitionSelectionChanged(processDefinition) {
|
||||
this.selectedProcessDef = processDefinition;
|
||||
this.processDefinitionSelection.emit(this.selectedProcessDef);
|
||||
processDefinitionSelectionChanged(processDefinition: ProcessDefinitionRepresentation) {
|
||||
if (processDefinition) {
|
||||
const processInstanceDetails = new ProcessInstance({ processDefinitionName: processDefinition.name });
|
||||
const processName = this.processNamePipe.transform(this.name, processInstanceDetails);
|
||||
this.processNameInput.setValue(processName);
|
||||
this.processNameInput.markAsDirty();
|
||||
this.processNameInput.markAsTouched();
|
||||
this.selectedProcessDef = processDefinition;
|
||||
this.processDefinitionSelection.emit(this.selectedProcessDef);
|
||||
} else {
|
||||
this.nameController.reset();
|
||||
}
|
||||
}
|
||||
|
||||
isLoading(): boolean {
|
||||
|
@@ -25,7 +25,6 @@ import { ProcessCommentsModule } from '../process-comments/process-comments.modu
|
||||
import { TaskListModule } from '../task-list/task-list.module';
|
||||
import { PeopleModule } from '../people/people.module';
|
||||
import { ContentWidgetModule } from '../content-widget/content-widget.module';
|
||||
|
||||
import { ProcessAuditDirective } from './components/process-audit.directive';
|
||||
import { ProcessFiltersComponent } from './components/process-filters.component';
|
||||
import { ProcessInstanceDetailsComponent } from './components/process-instance-details.component';
|
||||
@@ -34,6 +33,7 @@ import { ProcessInstanceTasksComponent } from './components/process-instance-tas
|
||||
import { ProcessInstanceListComponent } from './components/process-list.component';
|
||||
import { StartProcessInstanceComponent } from './components/start-process.component';
|
||||
import { FormModule } from '../form/form.module';
|
||||
import { ProcessNamePipe } from '../pipes/process-name.pipe';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
@@ -66,6 +66,9 @@ import { FormModule } from '../form/form.module';
|
||||
ProcessInstanceHeaderComponent,
|
||||
ProcessInstanceTasksComponent,
|
||||
StartProcessInstanceComponent
|
||||
],
|
||||
providers: [
|
||||
ProcessNamePipe
|
||||
]
|
||||
})
|
||||
export class ProcessListModule {
|
||||
|
@@ -30,6 +30,7 @@ import { AttachmentModule } from './attachment/attachment.module';
|
||||
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';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
@@ -44,7 +45,8 @@ import { ProcessFormRenderingService } from './form/process-form-rendering.servi
|
||||
AppsListModule,
|
||||
AttachmentModule,
|
||||
PeopleModule,
|
||||
FormModule
|
||||
FormModule,
|
||||
ProcessServicesPipeModule
|
||||
],
|
||||
providers: [
|
||||
{
|
||||
@@ -66,7 +68,8 @@ import { ProcessFormRenderingService } from './form/process-form-rendering.servi
|
||||
AppsListModule,
|
||||
AttachmentModule,
|
||||
PeopleModule,
|
||||
FormModule
|
||||
FormModule,
|
||||
ProcessServicesPipeModule
|
||||
]
|
||||
})
|
||||
export class ProcessModule {
|
||||
|
Reference in New Issue
Block a user