mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-2055] Ability to pre-populate form with a file and values (#2834)
* fix translations form * fix style webpack script * fix tslint error problem in viewer * fix naming problems in attach file widget * add start process form values data initialization option * fix translation problems * missing return type * start process name configuration * add CS cross PS configuration * start process from file example * fix minor issues * add documentation and move the dialog in a separate component * easy test select app * alfrescoRepositoryName right property * file conversion test * fix issue after CR * Remove forgotten semicolon.
This commit is contained in:
@@ -15,8 +15,23 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Component, EventEmitter, Input, OnChanges, Output, SimpleChanges, ViewChild, ViewEncapsulation } from '@angular/core';
|
||||
import { StartFormComponent, FormRenderingService } from '@alfresco/adf-core';
|
||||
import {
|
||||
Component,
|
||||
EventEmitter,
|
||||
Input,
|
||||
OnChanges,
|
||||
Output,
|
||||
SimpleChanges,
|
||||
ViewChild,
|
||||
ViewEncapsulation
|
||||
} from '@angular/core';
|
||||
import {
|
||||
ActivitiContentService,
|
||||
AppConfigService,
|
||||
StartFormComponent,
|
||||
FormRenderingService,
|
||||
FormValues
|
||||
} from '@alfresco/adf-core';
|
||||
import { ProcessInstanceVariable } from '../models/process-instance-variable.model';
|
||||
import { ProcessDefinitionRepresentation } from './../models/process-definition.model';
|
||||
import { ProcessInstance } from './../models/process-instance.model';
|
||||
@@ -37,6 +52,12 @@ export class StartProcessInstanceComponent implements OnChanges {
|
||||
@Input()
|
||||
variables: ProcessInstanceVariable[];
|
||||
|
||||
@Input()
|
||||
values: FormValues;
|
||||
|
||||
@Input()
|
||||
name: string;
|
||||
|
||||
@Output()
|
||||
start: EventEmitter<ProcessInstance> = new EventEmitter<ProcessInstance>();
|
||||
|
||||
@@ -51,19 +72,23 @@ export class StartProcessInstanceComponent implements OnChanges {
|
||||
|
||||
processDefinitions: ProcessDefinitionRepresentation[] = [];
|
||||
|
||||
name: string;
|
||||
|
||||
currentProcessDef: ProcessDefinitionRepresentation = new ProcessDefinitionRepresentation();
|
||||
|
||||
errorMessageId: string = '';
|
||||
|
||||
constructor(private activitiProcess: ProcessService,
|
||||
private formRenderingService: FormRenderingService) {
|
||||
private formRenderingService: FormRenderingService,
|
||||
private activitiContentService: ActivitiContentService,
|
||||
private appConfig: AppConfigService) {
|
||||
this.formRenderingService.setComponentTypeResolver('upload', () => AttachFileWidgetComponent, true);
|
||||
this.formRenderingService.setComponentTypeResolver('select-folder', () => AttachFolderWidgetComponent, true);
|
||||
}
|
||||
|
||||
ngOnChanges(changes: SimpleChanges) {
|
||||
if (changes['values'] && changes['values'].currentValue) {
|
||||
this.moveNodeFromCStoPS();
|
||||
}
|
||||
|
||||
let appIdChange = changes['appId'];
|
||||
let appId = appIdChange ? appIdChange.currentValue : null;
|
||||
this.load(appId);
|
||||
@@ -82,6 +107,30 @@ export class StartProcessInstanceComponent implements OnChanges {
|
||||
);
|
||||
}
|
||||
|
||||
getAlfrescoRepositoryName(): string {
|
||||
let alfrescoRepositoryName = this.appConfig.get<string>('alfrescoRepositoryName');
|
||||
if (!alfrescoRepositoryName) {
|
||||
alfrescoRepositoryName = 'alfresco-1';
|
||||
}
|
||||
return alfrescoRepositoryName + 'Alfresco';
|
||||
}
|
||||
|
||||
moveNodeFromCStoPS() {
|
||||
let accountIdentifier = this.getAlfrescoRepositoryName();
|
||||
|
||||
for (let key in this.values) {
|
||||
if (this.values.hasOwnProperty(key)) {
|
||||
let currentValue = this.values[key];
|
||||
|
||||
if (currentValue.isFile) {
|
||||
this.activitiContentService.applyAlfrescoNode(currentValue, null, accountIdentifier).subscribe((res) => {
|
||||
this.values[key] = [res];
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public startProcess(outcome?: string) {
|
||||
if (this.currentProcessDef.id && this.name) {
|
||||
this.resetErrorMessage();
|
||||
@@ -121,7 +170,7 @@ export class StartProcessInstanceComponent implements OnChanges {
|
||||
this.cancel.emit();
|
||||
}
|
||||
|
||||
hasStartForm() {
|
||||
hasStartForm(): boolean {
|
||||
return this.currentProcessDef && this.currentProcessDef.hasStartForm;
|
||||
}
|
||||
|
||||
@@ -129,7 +178,7 @@ export class StartProcessInstanceComponent implements OnChanges {
|
||||
return this.processDefinitions ? (this.processDefinitions.length > 0 || this.errorMessageId) : this.errorMessageId;
|
||||
}
|
||||
|
||||
isStartFormMissingOrValid() {
|
||||
isStartFormMissingOrValid(): boolean {
|
||||
if (this.startForm) {
|
||||
return this.startForm.form && this.startForm.form.isValid;
|
||||
} else {
|
||||
@@ -137,7 +186,7 @@ export class StartProcessInstanceComponent implements OnChanges {
|
||||
}
|
||||
}
|
||||
|
||||
validateForm() {
|
||||
validateForm(): boolean {
|
||||
return this.currentProcessDef.id && this.name && this.isStartFormMissingOrValid();
|
||||
}
|
||||
|
||||
@@ -149,7 +198,7 @@ export class StartProcessInstanceComponent implements OnChanges {
|
||||
this.errorMessageId = '';
|
||||
}
|
||||
|
||||
hasErrorMessage() {
|
||||
hasErrorMessage(): boolean {
|
||||
return this.processDefinitions.length === 0 && !this.errorMessageId;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user