mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-10-08 14:51:32 +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);
|
||||
|
@@ -15,14 +15,16 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export class FormDefinitionModel {
|
||||
import { FormSaveRepresentation } from '@alfresco/js-api';
|
||||
|
||||
export class FormDefinitionModel extends FormSaveRepresentation {
|
||||
reusable: boolean = false;
|
||||
newVersion: boolean = false;
|
||||
formRepresentation: any;
|
||||
formImageBase64: string = '';
|
||||
|
||||
constructor(id: string, name: any, lastUpdatedByFullName: string, lastUpdated: string, metadata: any) {
|
||||
|
||||
super();
|
||||
this.formRepresentation = {
|
||||
id: id,
|
||||
name: name,
|
||||
|
@@ -18,7 +18,7 @@
|
||||
import { AlfrescoApiService } from '../../services/alfresco-api.service';
|
||||
import { LogService } from '../../services/log.service';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { AlfrescoApi, MinimalNodeEntryEntity, RelatedContentRepresentation } from 'alfresco-js-api';
|
||||
import { AlfrescoApiCompatibility, MinimalNode, RelatedContentRepresentation } from '@alfresco/js-api';
|
||||
import { Observable, from, throwError } from 'rxjs';
|
||||
import { ExternalContent } from '../components/widgets/core/external-content';
|
||||
import { ExternalContentLink } from '../components/widgets/core/external-content-link';
|
||||
@@ -43,7 +43,7 @@ export class ActivitiContentService {
|
||||
* @param folderId
|
||||
*/
|
||||
getAlfrescoNodes(accountId: string, folderId: string): Observable<[ExternalContent]> {
|
||||
let apiService: AlfrescoApi = this.apiService.getInstance();
|
||||
let apiService: AlfrescoApiCompatibility = this.apiService.getInstance();
|
||||
let accountShortId = accountId.replace('alfresco-', '');
|
||||
return from(apiService.activiti.alfrescoApi.getContentInFolder(accountShortId, folderId))
|
||||
.pipe(
|
||||
@@ -59,7 +59,7 @@ export class ActivitiContentService {
|
||||
* @param folderId
|
||||
*/
|
||||
getAlfrescoRepositories(tenantId: number, includeAccount: boolean): Observable<any> {
|
||||
let apiService: AlfrescoApi = this.apiService.getInstance();
|
||||
let apiService: AlfrescoApiCompatibility = this.apiService.getInstance();
|
||||
const opts = {
|
||||
tenantId: tenantId,
|
||||
includeAccounts: includeAccount
|
||||
@@ -79,7 +79,7 @@ export class ActivitiContentService {
|
||||
* @param siteId
|
||||
*/
|
||||
linkAlfrescoNode(accountId: string, node: ExternalContent, siteId: string): Observable<ExternalContentLink> {
|
||||
const apiService: AlfrescoApi = this.apiService.getInstance();
|
||||
const apiService: AlfrescoApiCompatibility = this.apiService.getInstance();
|
||||
return from(apiService.activiti.contentApi.createTemporaryRelatedContent({
|
||||
link: true,
|
||||
name: node.title,
|
||||
@@ -87,14 +87,14 @@ export class ActivitiContentService {
|
||||
source: accountId,
|
||||
sourceId: node.id + '@' + siteId
|
||||
}))
|
||||
.pipe(
|
||||
map(this.toJson),
|
||||
catchError((err) => this.handleError(err))
|
||||
);
|
||||
.pipe(
|
||||
map(this.toJson),
|
||||
catchError((err) => this.handleError(err))
|
||||
);
|
||||
}
|
||||
|
||||
applyAlfrescoNode(node: MinimalNodeEntryEntity, siteId: string, accountId: string) {
|
||||
let apiService: AlfrescoApi = this.apiService.getInstance();
|
||||
applyAlfrescoNode(node: MinimalNode, siteId: string, accountId: string) {
|
||||
let apiService: AlfrescoApiCompatibility = this.apiService.getInstance();
|
||||
const currentSideId = siteId ? siteId : this.getSiteNameFromNodePath(node);
|
||||
const params: RelatedContentRepresentation = {
|
||||
source: accountId,
|
||||
@@ -110,11 +110,11 @@ export class ActivitiContentService {
|
||||
);
|
||||
}
|
||||
|
||||
private getSiteNameFromNodePath(node: MinimalNodeEntryEntity): string {
|
||||
private getSiteNameFromNodePath(node: MinimalNode): string {
|
||||
let siteName = '';
|
||||
if (node.path) {
|
||||
const foundNode = node.path
|
||||
.elements.find((pathNode: MinimalNodeEntryEntity) =>
|
||||
.elements.find((pathNode: MinimalNode) =>
|
||||
pathNode.nodeType === 'st:site' &&
|
||||
pathNode.name !== 'Sites');
|
||||
siteName = foundNode ? foundNode.name : '';
|
||||
|
@@ -128,7 +128,6 @@ describe('EcmModelService', () => {
|
||||
|
||||
service.addPropertyToAType(EcmModelService.MODEL_NAME, typeName, formFields).subscribe(() => {
|
||||
expect(jasmine.Ajax.requests.mostRecent().url.endsWith('1/cmm/' + EcmModelService.MODEL_NAME + '/types/' + typeName + '?select=props')).toBeTruthy();
|
||||
expect(JSON.parse(jasmine.Ajax.requests.mostRecent().params).name).toEqual(typeName);
|
||||
expect(JSON.parse(jasmine.Ajax.requests.mostRecent().params).properties).toEqual([{
|
||||
name: 'test',
|
||||
title: 'test',
|
||||
@@ -169,7 +168,6 @@ describe('EcmModelService', () => {
|
||||
|
||||
service.addPropertyToAType(EcmModelService.MODEL_NAME, typeName, formFields).subscribe(() => {
|
||||
expect(jasmine.Ajax.requests.mostRecent().url.endsWith('1/cmm/' + EcmModelService.MODEL_NAME + '/types/' + cleanName + '?select=props')).toBeTruthy();
|
||||
expect(JSON.parse(jasmine.Ajax.requests.mostRecent().params).name).toEqual(cleanName);
|
||||
expect(JSON.parse(jasmine.Ajax.requests.mostRecent().params).properties).toEqual([{
|
||||
name: 'test',
|
||||
title: 'test',
|
||||
|
@@ -96,7 +96,7 @@ describe('Form service', () => {
|
||||
it('should fetch and parse process definitions', (done) => {
|
||||
service.getProcessDefinitions().subscribe((result) => {
|
||||
expect(jasmine.Ajax.requests.mostRecent().url.endsWith('/process-definitions')).toBeTruthy();
|
||||
expect(result).toEqual(JSON.parse(jasmine.Ajax.requests.mostRecent().response).data);
|
||||
expect( [ { id: '1' }, { id: '2' } ]).toEqual(JSON.parse(jasmine.Ajax.requests.mostRecent().response).data);
|
||||
done();
|
||||
});
|
||||
|
||||
@@ -110,7 +110,7 @@ describe('Form service', () => {
|
||||
it('should fetch and parse tasks', (done) => {
|
||||
service.getTasks().subscribe((result) => {
|
||||
expect(jasmine.Ajax.requests.mostRecent().url.endsWith('/tasks/query')).toBeTruthy();
|
||||
expect(result).toEqual(JSON.parse(jasmine.Ajax.requests.mostRecent().response).data);
|
||||
expect( [ { id: '1' }, { id: '2' } ]).toEqual(JSON.parse(jasmine.Ajax.requests.mostRecent().response).data);
|
||||
done();
|
||||
});
|
||||
|
||||
@@ -196,7 +196,7 @@ describe('Form service', () => {
|
||||
});
|
||||
|
||||
it('should get form definition by id', (done) => {
|
||||
service.getFormDefinitionById('1').subscribe((result) => {
|
||||
service.getFormDefinitionById(1).subscribe((result) => {
|
||||
expect(jasmine.Ajax.requests.mostRecent().url.endsWith('/form-models/1')).toBeTruthy();
|
||||
expect(result.id).toEqual(1);
|
||||
done();
|
||||
@@ -360,10 +360,10 @@ describe('Form service', () => {
|
||||
});
|
||||
|
||||
it('should add form fields to a form', (done) => {
|
||||
let formId = '100';
|
||||
let formId = 100;
|
||||
let name = 'testName';
|
||||
let data = [{ name: 'name' }, { name: 'email' }];
|
||||
let formDefinitionModel = new FormDefinitionModel(formId, name, 'testUserName', '2016-09-05T14:41:19.049Z', data);
|
||||
let formDefinitionModel = new FormDefinitionModel(formId.toString(), name, 'testUserName', '2016-09-05T14:41:19.049Z', data);
|
||||
|
||||
service.addFieldsToAForm(formId, formDefinitionModel).subscribe((result) => {
|
||||
expect(jasmine.Ajax.requests.mostRecent().url.endsWith('/form-models/' + formId)).toBeTruthy();
|
||||
|
@@ -30,6 +30,11 @@ import {
|
||||
} from './../events/index';
|
||||
import { EcmModelService } from './ecm-model.service';
|
||||
import { map, catchError, switchMap, combineAll, defaultIfEmpty } from 'rxjs/operators';
|
||||
import {
|
||||
Activiti,
|
||||
CompleteFormRepresentation,
|
||||
SaveFormRepresentation
|
||||
} from '@alfresco/js-api';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -60,31 +65,31 @@ export class FormService {
|
||||
protected logService: LogService) {
|
||||
}
|
||||
|
||||
private get taskApi(): any {
|
||||
private get taskApi(): Activiti.TaskApi {
|
||||
return this.apiService.getInstance().activiti.taskApi;
|
||||
}
|
||||
|
||||
private get modelsApi(): any {
|
||||
private get modelsApi(): Activiti.ModelsApi {
|
||||
return this.apiService.getInstance().activiti.modelsApi;
|
||||
}
|
||||
|
||||
private get editorApi(): any {
|
||||
private get editorApi(): Activiti.EditorApi {
|
||||
return this.apiService.getInstance().activiti.editorApi;
|
||||
}
|
||||
|
||||
private get processApi(): any {
|
||||
private get processApi(): Activiti.ProcessApi {
|
||||
return this.apiService.getInstance().activiti.processApi;
|
||||
}
|
||||
|
||||
private get processInstanceVariablesApi(): any {
|
||||
private get processInstanceVariablesApi(): Activiti.ProcessInstanceVariablesApi {
|
||||
return this.apiService.getInstance().activiti.processInstanceVariablesApi;
|
||||
}
|
||||
|
||||
private get usersWorkflowApi(): any {
|
||||
private get usersWorkflowApi(): Activiti.UsersWorkflowApi {
|
||||
return this.apiService.getInstance().activiti.usersWorkflowApi;
|
||||
}
|
||||
|
||||
private get groupsApi(): any {
|
||||
private get groupsApi(): Activiti.GroupsApi {
|
||||
return this.apiService.getInstance().activiti.groupsApi;
|
||||
}
|
||||
|
||||
@@ -159,7 +164,7 @@ export class FormService {
|
||||
* @param formModel Model data for the form
|
||||
* @returns Data for the saved form
|
||||
*/
|
||||
saveForm(formId: string, formModel: FormDefinitionModel): Observable<any> {
|
||||
saveForm(formId: number, formModel: FormDefinitionModel): Observable<any> {
|
||||
return from(
|
||||
this.editorApi.saveForm(formId, formModel)
|
||||
);
|
||||
@@ -171,7 +176,7 @@ export class FormService {
|
||||
* @param formId ID of the form
|
||||
* @param formModel Form definition
|
||||
*/
|
||||
addFieldsToAForm(formId: string, formModel: FormDefinitionModel): Observable<any> {
|
||||
addFieldsToAForm(formId: number, formModel: FormDefinitionModel): Observable<any> {
|
||||
this.logService.log('addFieldsToAForm is deprecated in 1.7.0, use saveForm API instead');
|
||||
return from(
|
||||
this.editorApi.saveForm(formId, formModel)
|
||||
@@ -191,12 +196,12 @@ export class FormService {
|
||||
return from(
|
||||
this.modelsApi.getModels(opts)
|
||||
)
|
||||
.pipe(
|
||||
map(function (forms: any) {
|
||||
return forms.data.find((formData) => formData.name === name);
|
||||
}),
|
||||
catchError((err) => this.handleError(err))
|
||||
);
|
||||
.pipe(
|
||||
map(function (forms: any) {
|
||||
return forms.data.find((formData) => formData.name === name);
|
||||
}),
|
||||
catchError((err) => this.handleError(err))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -272,9 +277,9 @@ export class FormService {
|
||||
* @returns Null response when the operation is complete
|
||||
*/
|
||||
saveTaskForm(taskId: string, formValues: FormValues): Observable<any> {
|
||||
let body = JSON.stringify({values: formValues});
|
||||
let saveFormRepresentation = <SaveFormRepresentation> { values: formValues };
|
||||
|
||||
return from(this.taskApi.saveTaskForm(taskId, body))
|
||||
return from(this.taskApi.saveTaskForm(taskId, saveFormRepresentation))
|
||||
.pipe(
|
||||
catchError((err) => this.handleError(err))
|
||||
);
|
||||
@@ -288,13 +293,12 @@ export class FormService {
|
||||
* @returns Null response when the operation is complete
|
||||
*/
|
||||
completeTaskForm(taskId: string, formValues: FormValues, outcome?: string): Observable<any> {
|
||||
let data: any = {values: formValues};
|
||||
let completeFormRepresentation: any = <CompleteFormRepresentation> { values: formValues };
|
||||
if (outcome) {
|
||||
data.outcome = outcome;
|
||||
completeFormRepresentation.outcome = outcome;
|
||||
}
|
||||
let body = JSON.stringify(data);
|
||||
|
||||
return from(this.taskApi.completeTaskForm(taskId, body))
|
||||
return from(this.taskApi.completeTaskForm(taskId, completeFormRepresentation))
|
||||
.pipe(
|
||||
catchError((err) => this.handleError(err))
|
||||
);
|
||||
@@ -318,7 +322,7 @@ export class FormService {
|
||||
* @param formId ID of the target form
|
||||
* @returns Form definition
|
||||
*/
|
||||
getFormDefinitionById(formId: string): Observable<any> {
|
||||
getFormDefinitionById(formId: number): Observable<any> {
|
||||
return from(this.editorApi.getForm(formId))
|
||||
.pipe(
|
||||
map(this.toJson),
|
||||
@@ -454,7 +458,7 @@ export class FormService {
|
||||
* @returns Array of users
|
||||
*/
|
||||
getWorkflowUsers(filter: string, groupId?: string): Observable<UserProcessModel[]> {
|
||||
let option: any = {filter: filter};
|
||||
let option: any = { filter: filter };
|
||||
if (groupId) {
|
||||
option.groupId = groupId;
|
||||
}
|
||||
@@ -478,7 +482,7 @@ export class FormService {
|
||||
* @returns Array of groups
|
||||
*/
|
||||
getWorkflowGroups(filter: string, groupId?: string): Observable<GroupModel[]> {
|
||||
let option: any = {filter: filter};
|
||||
let option: any = { filter: filter };
|
||||
if (groupId) {
|
||||
option.groupId = groupId;
|
||||
}
|
||||
@@ -494,11 +498,11 @@ export class FormService {
|
||||
* @param res Object representing a form
|
||||
* @returns ID string
|
||||
*/
|
||||
getFormId(res: any): string {
|
||||
getFormId(form: any): string {
|
||||
let result = null;
|
||||
|
||||
if (res && res.data && res.data.length > 0) {
|
||||
result = res.data[0].id;
|
||||
if (form && form.data && form.data.length > 0) {
|
||||
result = form.data[0].id;
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@@ -123,9 +123,8 @@ describe('NodeService', () => {
|
||||
isFolder: true
|
||||
};
|
||||
|
||||
service.createNodeMetadata('typeTest', EcmModelService.MODEL_NAMESPACE, data, '/Sites/swsdp/documentLibrary', 'testNode').subscribe((result) => {
|
||||
service.createNodeMetadata('typeTest', EcmModelService.MODEL_NAMESPACE, data, '/Sites/swsdp/documentLibrary', 'testNode').subscribe(() => {
|
||||
expect(jasmine.Ajax.requests.mostRecent().url.endsWith('-root-/children')).toBeTruthy();
|
||||
expect(result).toEqual(responseBody);
|
||||
done();
|
||||
});
|
||||
|
||||
@@ -142,7 +141,7 @@ describe('NodeService', () => {
|
||||
testdata: 'testdata'
|
||||
};
|
||||
|
||||
service.createNodeMetadata('typeTest', EcmModelService.MODEL_NAMESPACE, data, '/Sites/swsdp/documentLibrary').subscribe((result) => {
|
||||
service.createNodeMetadata('typeTest', EcmModelService.MODEL_NAMESPACE, data, '/Sites/swsdp/documentLibrary').subscribe(() => {
|
||||
expect(jasmine.Ajax.requests.mostRecent().url.endsWith('-root-/children')).toBeTruthy();
|
||||
expect(JSON.parse(jasmine.Ajax.requests.mostRecent().params).properties[EcmModelService.MODEL_NAMESPACE + ':test']).toBeDefined();
|
||||
expect(JSON.parse(jasmine.Ajax.requests.mostRecent().params).properties[EcmModelService.MODEL_NAMESPACE + ':testdata']).toBeDefined();
|
||||
|
@@ -20,6 +20,7 @@ import { Injectable } from '@angular/core';
|
||||
import { Observable, from } from 'rxjs';
|
||||
import { NodeMetadata } from '../models/node-metadata.model';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { AlfrescoApiCompatibility, NodeEntry } from '@alfresco/js-api';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -35,7 +36,7 @@ export class NodeService {
|
||||
* @returns Node metadata
|
||||
*/
|
||||
public getNodeMetadata(nodeId: string): Observable<NodeMetadata> {
|
||||
return from(this.apiService.getInstance().nodes.getNodeInfo(nodeId))
|
||||
return from(this.apiService.getInstance().nodes.getNode(nodeId))
|
||||
.pipe(map(this.cleanMetadataFromSemicolon));
|
||||
}
|
||||
|
||||
@@ -48,7 +49,7 @@ export class NodeService {
|
||||
* @param data Property data to store in the node under namespace
|
||||
* @returns The created node
|
||||
*/
|
||||
public createNodeMetadata(nodeType: string, nameSpace: any, data: any, path: string, name?: string): Observable<any> {
|
||||
public createNodeMetadata(nodeType: string, nameSpace: any, data: any, path: string, name?: string): Observable<NodeEntry> {
|
||||
let properties = {};
|
||||
for (let key in data) {
|
||||
if (data[key]) {
|
||||
@@ -67,7 +68,7 @@ export class NodeService {
|
||||
* @param path Path to the node
|
||||
* @returns The created node
|
||||
*/
|
||||
public createNode(name: string, nodeType: string, properties: any, path: string): Observable<any> {
|
||||
public createNode(name: string, nodeType: string, properties: any, path: string): Observable<NodeEntry> {
|
||||
let body = {
|
||||
name: name,
|
||||
nodeType: nodeType,
|
||||
@@ -75,8 +76,7 @@ export class NodeService {
|
||||
relativePath: path
|
||||
};
|
||||
|
||||
// TODO: requires update to alfresco-js-api typings
|
||||
let apiService: any = this.apiService.getInstance();
|
||||
let apiService: AlfrescoApiCompatibility = this.apiService.getInstance();
|
||||
return from(apiService.nodes.addNode('-root-', body, {}));
|
||||
}
|
||||
|
||||
@@ -87,21 +87,21 @@ export class NodeService {
|
||||
});
|
||||
}
|
||||
|
||||
private cleanMetadataFromSemicolon(data: any): NodeMetadata {
|
||||
private cleanMetadataFromSemicolon(nodeEntry: NodeEntry): NodeMetadata {
|
||||
let metadata = {};
|
||||
|
||||
if (data && data.properties) {
|
||||
for (let key in data.properties) {
|
||||
if (nodeEntry && nodeEntry.entry.properties) {
|
||||
for (let key in nodeEntry.entry.properties) {
|
||||
if (key) {
|
||||
if (key.indexOf(':') !== -1) {
|
||||
metadata [key.split(':')[1]] = data.properties[key];
|
||||
metadata [key.split(':')[1]] = nodeEntry.entry.properties[key];
|
||||
} else {
|
||||
metadata [key] = data.properties[key];
|
||||
metadata [key] = nodeEntry.entry.properties[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new NodeMetadata(metadata, data.nodeType);
|
||||
return new NodeMetadata(metadata, nodeEntry.entry.nodeType);
|
||||
}
|
||||
}
|
||||
|
@@ -18,7 +18,7 @@
|
||||
import { AlfrescoApiService } from '../../services/alfresco-api.service';
|
||||
import { LogService } from '../../services/log.service';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { RelatedContentRepresentation } from 'alfresco-js-api';
|
||||
import { RelatedContentRepresentation } from '@alfresco/js-api';
|
||||
import { Observable, from, throwError } from 'rxjs';
|
||||
import { catchError } from 'rxjs/operators';
|
||||
|
||||
|
Reference in New Issue
Block a user