mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-] update library to use new js-api 3.0.0 (#4097)
This commit is contained in:
committed by
Eugenio Romano
parent
2acd1b4e26
commit
3ef7d3b7ea
@@ -218,7 +218,7 @@ describe('FormComponent', () => {
|
||||
|
||||
it('should get form definition by form id on load', () => {
|
||||
spyOn(formComponent, 'getFormDefinitionByFormId').and.stub();
|
||||
const formId = '123';
|
||||
const formId = 123;
|
||||
|
||||
formComponent.formId = formId;
|
||||
formComponent.loadForm();
|
||||
@@ -228,7 +228,7 @@ describe('FormComponent', () => {
|
||||
|
||||
it('should refresh visibility when the form is loaded', () => {
|
||||
spyOn(formService, 'getFormDefinitionById').and.returnValue(of(JSON.parse(JSON.stringify(fakeForm))));
|
||||
const formId = '123';
|
||||
const formId = 123;
|
||||
|
||||
formComponent.formId = formId;
|
||||
formComponent.loadForm();
|
||||
@@ -479,7 +479,7 @@ describe('FormComponent', () => {
|
||||
});
|
||||
});
|
||||
|
||||
const formId = '456';
|
||||
const formId = 456;
|
||||
let loaded = false;
|
||||
formComponent.formLoaded.subscribe(() => loaded = true);
|
||||
|
||||
@@ -487,7 +487,6 @@ describe('FormComponent', () => {
|
||||
formComponent.getFormDefinitionByFormId(formId);
|
||||
|
||||
expect(loaded).toBeTruthy();
|
||||
expect(formService.getFormDefinitionById).toHaveBeenCalledWith(formId);
|
||||
expect(formComponent.form).toBeDefined();
|
||||
expect(formComponent.form.id).toBe(formId);
|
||||
});
|
||||
@@ -498,8 +497,7 @@ describe('FormComponent', () => {
|
||||
spyOn(formComponent, 'handleError').and.stub();
|
||||
spyOn(formService, 'getFormDefinitionById').and.callFake(() => throwError(error));
|
||||
|
||||
formComponent.getFormDefinitionByFormId('123');
|
||||
expect(formService.getFormDefinitionById).toHaveBeenCalledWith('123');
|
||||
formComponent.getFormDefinitionByFormId(123);
|
||||
expect(formComponent.handleError).toHaveBeenCalledWith(error);
|
||||
});
|
||||
|
||||
|
@@ -64,7 +64,7 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
|
||||
|
||||
/** The id of the form definition to load and display with custom values. */
|
||||
@Input()
|
||||
formId: string;
|
||||
formId: number;
|
||||
|
||||
/** Name of the form definition to load and display with custom values. */
|
||||
@Input()
|
||||
@@ -389,7 +389,7 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
|
||||
});
|
||||
}
|
||||
|
||||
getFormDefinitionByFormId(formId: string) {
|
||||
getFormDefinitionByFormId(formId: number) {
|
||||
this.formService
|
||||
.getFormDefinitionById(formId)
|
||||
.subscribe(
|
||||
@@ -522,7 +522,7 @@ export class FormComponent implements OnInit, OnChanges, OnDestroy {
|
||||
);
|
||||
}
|
||||
|
||||
private loadFormFromFormId(formId: string) {
|
||||
private loadFormFromFormId(formId: number) {
|
||||
this.formId = formId;
|
||||
this.loadForm();
|
||||
}
|
||||
|
@@ -17,7 +17,7 @@
|
||||
|
||||
/* tslint:disable:component-selector */
|
||||
|
||||
import { RelatedContentRepresentation } from 'alfresco-js-api';
|
||||
import { RelatedContentRepresentation } from '@alfresco/js-api';
|
||||
|
||||
export class ContentLinkModel implements RelatedContentRepresentation {
|
||||
|
||||
|
@@ -42,7 +42,7 @@ export class FormModel {
|
||||
static COMPLETE_OUTCOME: string = '$complete';
|
||||
static START_PROCESS_OUTCOME: string = '$startProcess';
|
||||
|
||||
readonly id: string;
|
||||
readonly id: number;
|
||||
readonly name: string;
|
||||
readonly taskId: string;
|
||||
readonly taskName: string = FormModel.UNSET_TASK_NAME;
|
||||
@@ -80,7 +80,7 @@ export class FormModel {
|
||||
return this.outcomes && this.outcomes.length > 0;
|
||||
}
|
||||
|
||||
constructor(json?: any, data?: FormValues, readOnly: boolean = false, protected formService?: FormService) {
|
||||
constructor(json?: any, formValues?: FormValues, readOnly: boolean = false, protected formService?: FormService) {
|
||||
this.readOnly = readOnly;
|
||||
|
||||
if (json) {
|
||||
@@ -107,8 +107,8 @@ export class FormModel {
|
||||
|
||||
this.fields = this.parseRootFields(json);
|
||||
|
||||
if (data) {
|
||||
this.loadData(data);
|
||||
if (formValues) {
|
||||
this.loadData(formValues);
|
||||
}
|
||||
|
||||
for (let i = 0; i < this.fields.length; i++) {
|
||||
@@ -162,22 +162,22 @@ export class FormModel {
|
||||
|
||||
// TODO: consider evaluating and caching once the form is loaded
|
||||
getFormFields(): FormFieldModel[] {
|
||||
let result: FormFieldModel[] = [];
|
||||
let formFieldModel: FormFieldModel[] = [];
|
||||
|
||||
for (let i = 0; i < this.fields.length; i++) {
|
||||
let field = this.fields[i];
|
||||
|
||||
if (field instanceof ContainerModel) {
|
||||
let container = <ContainerModel> field;
|
||||
result.push(container.field);
|
||||
formFieldModel.push(container.field);
|
||||
|
||||
container.field.columns.forEach((column) => {
|
||||
result.push(...column.fields);
|
||||
formFieldModel.push(...column.fields);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
return formFieldModel;
|
||||
}
|
||||
|
||||
markAsInvalid() {
|
||||
@@ -254,7 +254,7 @@ export class FormModel {
|
||||
fields = json.formDefinition.fields;
|
||||
}
|
||||
|
||||
let result: FormWidgetModel[] = [];
|
||||
let formWidgetModel: FormWidgetModel[] = [];
|
||||
|
||||
for (let field of fields) {
|
||||
if (field.type === FormFieldTypes.DISPLAY_VALUE) {
|
||||
@@ -262,23 +262,23 @@ export class FormModel {
|
||||
if (field.params) {
|
||||
let originalField = field.params['field'];
|
||||
if (originalField.type === FormFieldTypes.DYNAMIC_TABLE) {
|
||||
result.push(new ContainerModel(new FormFieldModel(this, field)));
|
||||
formWidgetModel.push(new ContainerModel(new FormFieldModel(this, field)));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
result.push(new ContainerModel(new FormFieldModel(this, field)));
|
||||
formWidgetModel.push(new ContainerModel(new FormFieldModel(this, field)));
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
return formWidgetModel;
|
||||
}
|
||||
|
||||
// Loads external data and overrides field values
|
||||
// Typically used when form definition and form data coming from different sources
|
||||
private loadData(data: FormValues) {
|
||||
private loadData(formValues: FormValues) {
|
||||
for (let field of this.getFormFields()) {
|
||||
if (data[field.id]) {
|
||||
field.json.value = data[field.id];
|
||||
if (formValues[field.id]) {
|
||||
field.json.value = formValues[field.id];
|
||||
field.value = field.parseValue(field.json);
|
||||
}
|
||||
}
|
||||
|
@@ -54,12 +54,12 @@ export class DropdownWidgetComponent extends WidgetComponent implements OnInit {
|
||||
this.field.id
|
||||
)
|
||||
.subscribe(
|
||||
(result: FormFieldOption[]) => {
|
||||
(formFieldOption: FormFieldOption[]) => {
|
||||
let options = [];
|
||||
if (this.field.emptyOption) {
|
||||
options.push(this.field.emptyOption);
|
||||
}
|
||||
this.field.options = options.concat((result || []));
|
||||
this.field.options = options.concat((formFieldOption || []));
|
||||
this.field.updateForm();
|
||||
},
|
||||
(err) => this.handleError(err)
|
||||
@@ -73,12 +73,12 @@ export class DropdownWidgetComponent extends WidgetComponent implements OnInit {
|
||||
this.field.id
|
||||
)
|
||||
.subscribe(
|
||||
(result: FormFieldOption[]) => {
|
||||
(formFieldOption: FormFieldOption[]) => {
|
||||
let options = [];
|
||||
if (this.field.emptyOption) {
|
||||
options.push(this.field.emptyOption);
|
||||
}
|
||||
this.field.options = options.concat((result || []));
|
||||
this.field.options = options.concat((formFieldOption || []));
|
||||
this.field.updateForm();
|
||||
},
|
||||
(err) => this.handleError(err)
|
||||
|
@@ -171,33 +171,33 @@ export class DynamicTableModel extends FormWidgetModel {
|
||||
}
|
||||
|
||||
getCellValue(row: DynamicTableRow, column: DynamicTableColumn): any {
|
||||
let result = row.value[column.id];
|
||||
let rowValue = row.value[column.id];
|
||||
|
||||
if (column.type === 'Dropdown') {
|
||||
if (result) {
|
||||
return result.name;
|
||||
if (rowValue) {
|
||||
return rowValue.name;
|
||||
}
|
||||
}
|
||||
|
||||
if (column.type === 'Boolean') {
|
||||
return result ? true : false;
|
||||
return rowValue ? true : false;
|
||||
}
|
||||
|
||||
if (column.type === 'Date') {
|
||||
if (result) {
|
||||
return moment(result.split('T')[0], 'YYYY-MM-DD').format('DD-MM-YYYY');
|
||||
if (rowValue) {
|
||||
return moment(rowValue.split('T')[0], 'YYYY-MM-DD').format('DD-MM-YYYY');
|
||||
}
|
||||
}
|
||||
|
||||
return result || '';
|
||||
return rowValue || '';
|
||||
}
|
||||
|
||||
getDisplayText(column: DynamicTableColumn): string {
|
||||
let result = column.name;
|
||||
let columnName = column.name;
|
||||
if (column.type === 'Amount') {
|
||||
let currency = column.amountCurrency || '$';
|
||||
result = `${column.name} (${currency})`;
|
||||
columnName = `${column.name} (${currency})`;
|
||||
}
|
||||
return result;
|
||||
return columnName;
|
||||
}
|
||||
}
|
||||
|
@@ -74,13 +74,13 @@ export class DynamicTableWidgetComponent extends WidgetComponent implements OnIn
|
||||
}
|
||||
|
||||
isValid() {
|
||||
let result = true;
|
||||
let valid = true;
|
||||
|
||||
if (this.content && this.content.field) {
|
||||
result = this.content.field.isValid;
|
||||
valid = this.content.field.isValid;
|
||||
}
|
||||
|
||||
return result;
|
||||
return valid;
|
||||
}
|
||||
|
||||
onRowClicked(row: DynamicTableRow) {
|
||||
@@ -151,11 +151,11 @@ export class DynamicTableWidgetComponent extends WidgetComponent implements OnIn
|
||||
|
||||
getCellValue(row: DynamicTableRow, column: DynamicTableColumn): any {
|
||||
if (this.content) {
|
||||
let result = this.content.getCellValue(row, column);
|
||||
let cellValue = this.content.getCellValue(row, column);
|
||||
if (column.type === 'Amount') {
|
||||
return (column.amountCurrency || '$') + ' ' + (result || 0);
|
||||
return (column.amountCurrency || '$') + ' ' + (cellValue || 0);
|
||||
}
|
||||
return result;
|
||||
return cellValue;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@@ -72,8 +72,8 @@ export class DropdownEditorComponent implements OnInit {
|
||||
this.column.id
|
||||
)
|
||||
.subscribe(
|
||||
(result: DynamicTableColumnOption[]) => {
|
||||
this.column.options = result || [];
|
||||
(dynamicTableColumnOption: DynamicTableColumnOption[]) => {
|
||||
this.column.options = dynamicTableColumnOption || [];
|
||||
this.options = this.column.options;
|
||||
this.value = this.table.getCellValue(this.row, this.column);
|
||||
},
|
||||
@@ -89,8 +89,8 @@ export class DropdownEditorComponent implements OnInit {
|
||||
this.column.id
|
||||
)
|
||||
.subscribe(
|
||||
(result: DynamicTableColumnOption[]) => {
|
||||
this.column.options = result || [];
|
||||
(dynamicTableColumnOption: DynamicTableColumnOption[]) => {
|
||||
this.column.options = dynamicTableColumnOption || [];
|
||||
this.options = this.column.options;
|
||||
this.value = this.table.getCellValue(this.row, this.column);
|
||||
},
|
||||
|
@@ -60,7 +60,7 @@ export class FunctionalGroupWidgetComponent extends WidgetComponent implements O
|
||||
if (this.value) {
|
||||
this.formService
|
||||
.getWorkflowGroups(this.value, this.groupId)
|
||||
.subscribe((result: GroupModel[]) => this.groups = result || []);
|
||||
.subscribe((groupModel: GroupModel[]) => this.groups = groupModel || []);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -70,8 +70,8 @@ export class FunctionalGroupWidgetComponent extends WidgetComponent implements O
|
||||
if (event.keyCode !== ESCAPE && event.keyCode !== ENTER) {
|
||||
this.oldValue = this.value;
|
||||
this.formService.getWorkflowGroups(this.value, this.groupId)
|
||||
.subscribe((result: GroupModel[]) => {
|
||||
this.groups = result || [];
|
||||
.subscribe((group: GroupModel[]) => {
|
||||
this.groups = group || [];
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@@ -54,8 +54,8 @@ export class RadioButtonsWidgetComponent extends WidgetComponent implements OnIn
|
||||
this.field.id
|
||||
)
|
||||
.subscribe(
|
||||
(result: FormFieldOption[]) => {
|
||||
this.field.options = result || [];
|
||||
(formFieldOption: FormFieldOption[]) => {
|
||||
this.field.options = formFieldOption || [];
|
||||
this.field.updateForm();
|
||||
},
|
||||
(err) => this.handleError(err)
|
||||
@@ -69,8 +69,8 @@ export class RadioButtonsWidgetComponent extends WidgetComponent implements OnIn
|
||||
this.field.id
|
||||
)
|
||||
.subscribe(
|
||||
(result: FormFieldOption[]) => {
|
||||
this.field.options = result || [];
|
||||
(formFieldOption: FormFieldOption[]) => {
|
||||
this.field.options = formFieldOption || [];
|
||||
this.field.updateForm();
|
||||
},
|
||||
(err) => this.handleError(err)
|
||||
|
@@ -61,8 +61,8 @@ export class TypeaheadWidgetComponent extends WidgetComponent implements OnInit
|
||||
this.field.id
|
||||
)
|
||||
.subscribe(
|
||||
(result: FormFieldOption[]) => {
|
||||
let options = result || [];
|
||||
(formFieldOption: FormFieldOption[]) => {
|
||||
let options = formFieldOption || [];
|
||||
this.field.options = options;
|
||||
|
||||
let fieldValue = this.field.value;
|
||||
@@ -86,8 +86,8 @@ export class TypeaheadWidgetComponent extends WidgetComponent implements OnInit
|
||||
this.field.id
|
||||
)
|
||||
.subscribe(
|
||||
(result: FormFieldOption[]) => {
|
||||
let options = result || [];
|
||||
(formFieldOption: FormFieldOption[]) => {
|
||||
let options = formFieldOption || [];
|
||||
this.field.options = options;
|
||||
|
||||
let fieldValue = this.field.value;
|
||||
|
@@ -136,8 +136,8 @@ export class UploadFolderWidgetComponent extends WidgetComponent implements OnIn
|
||||
return this.thumbnailService.getMimeTypeIcon(mimeType);
|
||||
}
|
||||
|
||||
fileClicked(obj: any): void {
|
||||
const file = new ContentLinkModel(obj);
|
||||
fileClicked(contentLinkModel: any): void {
|
||||
const file = new ContentLinkModel(contentLinkModel);
|
||||
let fetch = this.processContentService.getContentPreview(file.id);
|
||||
if (file.isTypeImage() || file.isTypePdf()) {
|
||||
fetch = this.processContentService.getFileRawContent(file.id);
|
||||
|
@@ -133,8 +133,8 @@ export class UploadWidgetComponent extends WidgetComponent implements OnInit {
|
||||
return this.thumbnailService.getMimeTypeIcon(mimeType);
|
||||
}
|
||||
|
||||
fileClicked(obj: any): void {
|
||||
const file = new ContentLinkModel(obj);
|
||||
fileClicked(contentLinkModel: any): void {
|
||||
const file = new ContentLinkModel(contentLinkModel);
|
||||
let fetch = this.processContentService.getContentPreview(file.id);
|
||||
if (file.isTypeImage() || file.isTypePdf()) {
|
||||
fetch = this.processContentService.getFileRawContent(file.id);
|
||||
|
Reference in New Issue
Block a user