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();
|
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, 'getTask').and.returnValue(Observable.of({}));
|
||||||
spyOn(formService, 'getTaskForm').and.callFake((taskId) => {
|
spyOn(formService, 'getTaskForm').and.callFake((taskId) => {
|
||||||
return Observable.create(observer => {
|
return Observable.create(observer => {
|
||||||
@ -435,19 +435,18 @@ describe('ActivitiForm', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const taskId = '456';
|
const taskId = '456';
|
||||||
let loaded = false;
|
formComponent.formLoaded.subscribe(() => {
|
||||||
formComponent.formLoaded.subscribe(() => loaded = true);
|
expect(formService.getTaskForm).toHaveBeenCalledWith(taskId);
|
||||||
|
expect(formComponent.form).toBeDefined();
|
||||||
|
expect(formComponent.form.taskId).toBe(taskId);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
expect(formComponent.form).toBeUndefined();
|
expect(formComponent.form).toBeUndefined();
|
||||||
formComponent.getFormByTaskId(taskId);
|
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';
|
const error = 'Some error';
|
||||||
|
|
||||||
spyOn(formService, 'getTask').and.returnValue(Observable.of({}));
|
spyOn(formService, 'getTask').and.returnValue(Observable.of({}));
|
||||||
@ -456,11 +455,13 @@ describe('ActivitiForm', () => {
|
|||||||
return Observable.throw(error);
|
return Observable.throw(error);
|
||||||
});
|
});
|
||||||
|
|
||||||
formComponent.getFormByTaskId('123');
|
formComponent.getFormByTaskId('123').then(_ => {
|
||||||
expect(formComponent.handleError).toHaveBeenCalledWith(error);
|
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, 'getTask').and.returnValue(Observable.of({}));
|
||||||
spyOn(formService, 'getTaskForm').and.callFake((taskId) => {
|
spyOn(formService, 'getTaskForm').and.callFake((taskId) => {
|
||||||
return Observable.create(observer => {
|
return Observable.create(observer => {
|
||||||
@ -470,10 +471,11 @@ describe('ActivitiForm', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
formComponent.readOnly = true;
|
formComponent.readOnly = true;
|
||||||
formComponent.getFormByTaskId('123');
|
formComponent.getFormByTaskId('123').then(_ => {
|
||||||
|
expect(formComponent.form).toBeDefined();
|
||||||
expect(formComponent.form).toBeDefined();
|
expect(formComponent.form.readOnly).toBe(true);
|
||||||
expect(formComponent.form.readOnly).toBe(true);
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fetch and parse form definition by id', () => {
|
it('should fetch and parse form definition by id', () => {
|
||||||
|
@ -305,16 +305,24 @@ export class ActivitiForm implements OnInit, AfterViewChecked, OnChanges {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
loadFormPorcessVariable(taskId) {
|
loadFormProcessVariables(taskId: string): Promise<boolean> {
|
||||||
this.formService.getTask(taskId).subscribe(
|
return new Promise((resolve, reject) => {
|
||||||
task => {
|
this.formService.getTask(taskId).subscribe(
|
||||||
if (this.isAProcessTask(task)) {
|
task => {
|
||||||
this.visibilityService.getTaskProcessVariable(taskId).subscribe();
|
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) {
|
isAProcessTask(taskRepresentation) {
|
||||||
@ -330,20 +338,25 @@ export class ActivitiForm implements OnInit, AfterViewChecked, OnChanges {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
getFormByTaskId(taskId: string) {
|
getFormByTaskId(taskId: string): Promise<FormModel> {
|
||||||
this.loadFormPorcessVariable(this.taskId);
|
return new Promise<FormModel>((resolve, reject) => {
|
||||||
let data = this.data;
|
this.loadFormProcessVariables(this.taskId).then(_ => {
|
||||||
this.formService
|
this.formService
|
||||||
.getTaskForm(taskId)
|
.getTaskForm(taskId)
|
||||||
.subscribe(
|
.subscribe(
|
||||||
form => {
|
form => {
|
||||||
this.form = new FormModel(form, data, this.readOnly, this.formService);
|
this.form = new FormModel(form, this.data, this.readOnly, this.formService);
|
||||||
this.onFormLoaded(this.form);
|
this.onFormLoaded(this.form);
|
||||||
},
|
resolve(this.form);
|
||||||
(error) => {
|
},
|
||||||
this.handleError(error);
|
error => {
|
||||||
}
|
this.handleError(error);
|
||||||
);
|
// reject(error);
|
||||||
|
resolve(null);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
getFormDefinitionByFormId(formId: string) {
|
getFormDefinitionByFormId(formId: string) {
|
||||||
|
@ -143,7 +143,7 @@ export class WidgetVisibilityService {
|
|||||||
if (field.value && field.value.name) {
|
if (field.value && field.value.name) {
|
||||||
value = field.value.name;
|
value = field.value.name;
|
||||||
} else if (field.options) {
|
} 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) {
|
if (option) {
|
||||||
value = option.name;
|
value = option.name;
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user