Added fix for #1044

This commit is contained in:
Vito Albano 2016-11-11 00:53:34 +00:00
parent 8195c00c74
commit 38b61a4f64
6 changed files with 163 additions and 45 deletions

View File

@ -34,7 +34,7 @@ export class FormModel {
readonly name: string; readonly name: string;
readonly taskId: string; readonly taskId: string;
readonly taskName: string = FormModel.UNSET_TASK_NAME; readonly taskName: string = FormModel.UNSET_TASK_NAME;
readonly processDefinitionId: string;
private _isValid: boolean = true; private _isValid: boolean = true;
get isValid(): boolean { get isValid(): boolean {
@ -72,6 +72,7 @@ export class FormModel {
this.name = json.name; this.name = json.name;
this.taskId = json.taskId; this.taskId = json.taskId;
this.taskName = json.taskName || json.name || FormModel.UNSET_TASK_NAME; this.taskName = json.taskName || json.name || FormModel.UNSET_TASK_NAME;
this.processDefinitionId = json.processDefinitionId;
let tabCache: FormWidgetModelCache<TabModel> = {}; let tabCache: FormWidgetModelCache<TabModel> = {};

View File

@ -34,25 +34,52 @@ export class DropdownWidget extends WidgetComponent implements OnInit {
ngOnInit() { ngOnInit() {
if (this.field && this.field.restUrl) { if (this.field && this.field.restUrl) {
this.formService if (this.field.form.processDefinitionId) {
.getRestFieldValues( this.getValuesByProcessDefinitionId();
this.field.form.taskId, } else {
this.field.id this.getValuesByTaskId();
) }
.subscribe(
(result: FormFieldOption[]) => {
let options = [];
if (this.field.emptyOption) {
options.push(this.field.emptyOption);
}
this.field.options = options.concat((result || []));
this.field.updateForm();
},
this.handleError
);
} }
} }
getValuesByTaskId() {
this.formService
.getRestFieldValues(
this.field.form.taskId,
this.field.id
)
.subscribe(
(result: FormFieldOption[]) => {
let options = [];
if (this.field.emptyOption) {
options.push(this.field.emptyOption);
}
this.field.options = options.concat((result || []));
this.field.updateForm();
},
this.handleError
);
}
getValuesByProcessDefinitionId() {
this.formService
.getRestFieldValuesByProcessId(
this.field.form.processDefinitionId,
this.field.id
)
.subscribe(
(result: FormFieldOption[]) => {
let options = [];
if (this.field.emptyOption) {
options.push(this.field.emptyOption);
}
this.field.options = options.concat((result || []));
this.field.updateForm();
},
this.handleError
);
}
handleError(error: any) { handleError(error: any) {
console.error(error); console.error(error);
} }

View File

@ -39,20 +39,11 @@ export class DropdownEditorComponent extends CellEditorComponent implements OnIn
let field = this.table.field; let field = this.table.field;
if (field) { if (field) {
if (this.column.optionType === 'rest') { if (this.column.optionType === 'rest') {
this.formService if (this.table.form.processDefinitionId) {
.getRestFieldValuesColumn( this.getValuesByProcessDefinitionId(field);
field.form.taskId, } else {
field.id, this.getValuesByTaskId(field);
this.column.id }
)
.subscribe(
(result: DynamicTableColumnOption[]) => {
this.column.options = result || [];
this.options = this.column.options;
this.value = this.table.getCellValue(this.row, this.column);
},
err => this.handleError(err)
);
} else { } else {
this.options = this.column.options || []; this.options = this.column.options || [];
this.value = this.table.getCellValue(this.row, this.column); this.value = this.table.getCellValue(this.row, this.column);
@ -60,6 +51,40 @@ export class DropdownEditorComponent extends CellEditorComponent implements OnIn
} }
} }
getValuesByTaskId(field) {
this.formService
.getRestFieldValuesColumn(
field.form.taskId,
field.id,
this.column.id
)
.subscribe(
(result: DynamicTableColumnOption[]) => {
this.column.options = result || [];
this.options = this.column.options;
this.value = this.table.getCellValue(this.row, this.column);
},
err => this.handleError(err)
);
}
getValuesByProcessDefinitionId(field) {
this.formService
.getRestFieldValuesColumnByProcessId(
field.form.processDefinitionId,
field.id,
this.column.id
)
.subscribe(
(result: DynamicTableColumnOption[]) => {
this.column.options = result || [];
this.options = this.column.options;
this.value = this.table.getCellValue(this.row, this.column);
},
err => this.handleError(err)
);
}
onValueChanged(row: DynamicTableRow, column: DynamicTableColumn, event: any) { onValueChanged(row: DynamicTableRow, column: DynamicTableColumn, event: any) {
let value: any = (<HTMLInputElement>event.target).value; let value: any = (<HTMLInputElement>event.target).value;
value = column.options.find(opt => opt.name === value); value = column.options.find(opt => opt.name === value);

View File

@ -34,21 +34,44 @@ export class RadioButtonsWidget extends WidgetComponent implements OnInit {
ngOnInit() { ngOnInit() {
if (this.field && this.field.restUrl) { if (this.field && this.field.restUrl) {
this.formService if (this.field.form.processDefinitionId) {
.getRestFieldValues( this.getOptionsByProcessDefinitionId();
this.field.form.taskId, } else {
this.field.id this.getOptionsByTaskId();
) }
.subscribe(
(result: FormFieldOption[]) => {
this.field.options = result || [];
this.field.updateForm();
},
this.handleError
);
} }
} }
getOptionsByTaskId() {
this.formService
.getRestFieldValues(
this.field.form.taskId,
this.field.id
)
.subscribe(
(result: FormFieldOption[]) => {
this.field.options = result || [];
this.field.updateForm();
},
this.handleError
);
}
getOptionsByProcessDefinitionId() {
this.formService
.getRestFieldValuesByProcessId(
this.field.form.processDefinitionId,
this.field.id
)
.subscribe(
(result: FormFieldOption[]) => {
this.field.options = result || [];
this.field.updateForm();
},
this.handleError
);
}
onOptionClick(optionSelected: any) { onOptionClick(optionSelected: any) {
this.field.value = optionSelected; this.field.value = optionSelected;
this.checkVisibility(this.field); this.checkVisibility(this.field);

View File

@ -38,6 +38,14 @@ export class TypeaheadWidget extends WidgetComponent implements OnInit {
} }
ngOnInit() { ngOnInit() {
if (this.field.form.processDefinitionId) {
this.getValuesByProcessDefinitionId();
} else {
this.getValuesByTaskId();
}
}
getValuesByTaskId() {
this.formService this.formService
.getRestFieldValues( .getRestFieldValues(
this.field.form.taskId, this.field.form.taskId,
@ -61,6 +69,30 @@ export class TypeaheadWidget extends WidgetComponent implements OnInit {
); );
} }
getValuesByProcessDefinitionId() {
this.formService
.getRestFieldValuesByProcessId(
this.field.form.processDefinitionId,
this.field.id
)
.subscribe(
(result: FormFieldOption[]) => {
let options = result || [];
this.field.options = options;
this.field.updateForm();
let fieldValue = this.field.value;
if (fieldValue) {
let toSelect = options.find(item => item.id === fieldValue);
if (toSelect) {
this.value = toSelect.name;
}
}
},
this.handleError
);
}
getOptions(): FormFieldOption[] { getOptions(): FormFieldOption[] {
let val = this.value.toLocaleLowerCase(); let val = this.value.toLocaleLowerCase();
return this.field.options.filter(item => { return this.field.options.filter(item => {

View File

@ -143,7 +143,7 @@ export class FormService {
* @returns {Observable<any>} * @returns {Observable<any>}
*/ */
saveTaskForm(taskId: string, formValues: FormValues): Observable<any> { saveTaskForm(taskId: string, formValues: FormValues): Observable<any> {
let body = JSON.stringify({values: formValues}); let body = JSON.stringify({ values: formValues });
return Observable.fromPromise(this.apiService.getInstance().activiti.taskApi.saveTaskForm(taskId, body)) return Observable.fromPromise(this.apiService.getInstance().activiti.taskApi.saveTaskForm(taskId, body))
.catch(this.handleError); .catch(this.handleError);
@ -157,7 +157,7 @@ export class FormService {
* @returns {Observable<any>} * @returns {Observable<any>}
*/ */
completeTaskForm(taskId: string, formValues: FormValues, outcome?: string): Observable<any> { completeTaskForm(taskId: string, formValues: FormValues, outcome?: string): Observable<any> {
let data: any = {values: formValues}; let data: any = { values: formValues };
if (outcome) { if (outcome) {
data.outcome = outcome; data.outcome = outcome;
} }
@ -223,6 +223,16 @@ export class FormService {
return Observable.fromPromise(alfrescoApi.activiti.taskApi.getRestFieldValues(taskId, field)); return Observable.fromPromise(alfrescoApi.activiti.taskApi.getRestFieldValues(taskId, field));
} }
getRestFieldValuesByProcessId(processDefinitionId: string, field: string): Observable<any> {
let alfrescoApi = this.apiService.getInstance();
return Observable.fromPromise(alfrescoApi.activiti.processApi.getRestFieldValues(processDefinitionId, field));
}
getRestFieldValuesColumnByProcessId(processDefinitionId: string, field: string, column?: string): Observable<any> {
let alfrescoApi = this.apiService.getInstance();
return Observable.fromPromise(alfrescoApi.activiti.processApi.getRestTableFieldValues(processDefinitionId, field, column));
}
getRestFieldValuesColumn(taskId: string, field: string, column?: string): Observable<any> { getRestFieldValuesColumn(taskId: string, field: string, column?: string): Observable<any> {
let alfrescoApi = this.apiService.getInstance(); let alfrescoApi = this.apiService.getInstance();
return Observable.fromPromise(alfrescoApi.activiti.taskApi.getRestFieldValuesColumn(taskId, field, column)); return Observable.fromPromise(alfrescoApi.activiti.taskApi.getRestFieldValuesColumn(taskId, field, column));