mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-26 17:24:56 +00:00
sequential loading order (#1659)
This commit is contained in:
parent
3375a63680
commit
14c7f0409b
@ -425,7 +425,7 @@ describe('ActivitiForm', () => {
|
||||
expect(formComponent.onOutcomeClicked(outcome)).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should fetch and parse form by task id', () => {
|
||||
it('should fetch and parse form by task id', (done) => {
|
||||
spyOn(formService, 'getTask').and.returnValue(Observable.of({}));
|
||||
spyOn(formService, 'getTaskForm').and.callFake((taskId) => {
|
||||
return Observable.create(observer => {
|
||||
@ -435,19 +435,18 @@ describe('ActivitiForm', () => {
|
||||
});
|
||||
|
||||
const taskId = '456';
|
||||
let loaded = false;
|
||||
formComponent.formLoaded.subscribe(() => loaded = true);
|
||||
formComponent.formLoaded.subscribe(() => {
|
||||
expect(formService.getTaskForm).toHaveBeenCalledWith(taskId);
|
||||
expect(formComponent.form).toBeDefined();
|
||||
expect(formComponent.form.taskId).toBe(taskId);
|
||||
done();
|
||||
});
|
||||
|
||||
expect(formComponent.form).toBeUndefined();
|
||||
formComponent.getFormByTaskId(taskId);
|
||||
|
||||
expect(loaded).toBeTruthy();
|
||||
expect(formService.getTaskForm).toHaveBeenCalledWith(taskId);
|
||||
expect(formComponent.form).toBeDefined();
|
||||
expect(formComponent.form.taskId).toBe(taskId);
|
||||
});
|
||||
|
||||
it('should handle error when getting form by task id', () => {
|
||||
it('should handle error when getting form by task id', (done) => {
|
||||
const error = 'Some error';
|
||||
|
||||
spyOn(formService, 'getTask').and.returnValue(Observable.of({}));
|
||||
@ -456,11 +455,13 @@ describe('ActivitiForm', () => {
|
||||
return Observable.throw(error);
|
||||
});
|
||||
|
||||
formComponent.getFormByTaskId('123');
|
||||
expect(formComponent.handleError).toHaveBeenCalledWith(error);
|
||||
formComponent.getFormByTaskId('123').then(_ => {
|
||||
expect(formComponent.handleError).toHaveBeenCalledWith(error);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should apply readonly state when getting form by task id', () => {
|
||||
it('should apply readonly state when getting form by task id', (done) => {
|
||||
spyOn(formService, 'getTask').and.returnValue(Observable.of({}));
|
||||
spyOn(formService, 'getTaskForm').and.callFake((taskId) => {
|
||||
return Observable.create(observer => {
|
||||
@ -470,10 +471,11 @@ describe('ActivitiForm', () => {
|
||||
});
|
||||
|
||||
formComponent.readOnly = true;
|
||||
formComponent.getFormByTaskId('123');
|
||||
|
||||
expect(formComponent.form).toBeDefined();
|
||||
expect(formComponent.form.readOnly).toBe(true);
|
||||
formComponent.getFormByTaskId('123').then(_ => {
|
||||
expect(formComponent.form).toBeDefined();
|
||||
expect(formComponent.form.readOnly).toBe(true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should fetch and parse form definition by id', () => {
|
||||
|
@ -305,16 +305,24 @@ export class ActivitiForm implements OnInit, AfterViewChecked, OnChanges {
|
||||
}
|
||||
}
|
||||
|
||||
loadFormPorcessVariable(taskId) {
|
||||
this.formService.getTask(taskId).subscribe(
|
||||
task => {
|
||||
if (this.isAProcessTask(task)) {
|
||||
this.visibilityService.getTaskProcessVariable(taskId).subscribe();
|
||||
loadFormProcessVariables(taskId: string): Promise<boolean> {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.formService.getTask(taskId).subscribe(
|
||||
task => {
|
||||
if (this.isAProcessTask(task)) {
|
||||
this.visibilityService.getTaskProcessVariable(taskId).subscribe(_ => {
|
||||
resolve(true);
|
||||
});
|
||||
} else {
|
||||
resolve(true);
|
||||
}
|
||||
},
|
||||
error => {
|
||||
this.handleError(error);
|
||||
resolve(false);
|
||||
}
|
||||
},
|
||||
(error) => {
|
||||
this.handleError(error);
|
||||
});
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
isAProcessTask(taskRepresentation) {
|
||||
@ -330,20 +338,25 @@ export class ActivitiForm implements OnInit, AfterViewChecked, OnChanges {
|
||||
return false;
|
||||
}
|
||||
|
||||
getFormByTaskId(taskId: string) {
|
||||
this.loadFormPorcessVariable(this.taskId);
|
||||
let data = this.data;
|
||||
this.formService
|
||||
.getTaskForm(taskId)
|
||||
.subscribe(
|
||||
form => {
|
||||
this.form = new FormModel(form, data, this.readOnly, this.formService);
|
||||
this.onFormLoaded(this.form);
|
||||
},
|
||||
(error) => {
|
||||
this.handleError(error);
|
||||
}
|
||||
);
|
||||
getFormByTaskId(taskId: string): Promise<FormModel> {
|
||||
return new Promise<FormModel>((resolve, reject) => {
|
||||
this.loadFormProcessVariables(this.taskId).then(_ => {
|
||||
this.formService
|
||||
.getTaskForm(taskId)
|
||||
.subscribe(
|
||||
form => {
|
||||
this.form = new FormModel(form, this.data, this.readOnly, this.formService);
|
||||
this.onFormLoaded(this.form);
|
||||
resolve(this.form);
|
||||
},
|
||||
error => {
|
||||
this.handleError(error);
|
||||
// reject(error);
|
||||
resolve(null);
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
getFormDefinitionByFormId(formId: string) {
|
||||
|
@ -143,7 +143,7 @@ export class WidgetVisibilityService {
|
||||
if (field.value && field.value.name) {
|
||||
value = field.value.name;
|
||||
} else if (field.options) {
|
||||
let option = field.options.find(option => option.id === field.value);
|
||||
let option = field.options.find(opt => opt.id === field.value);
|
||||
if (option) {
|
||||
value = option.name;
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user