mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-4499] Form definition selector should only display standAlone co… (#4880)
* [ADF-4499] Form definition selector should only display standAlone compatible forms * Improve service method * fix typo
This commit is contained in:
committed by
Eugenio Romano
parent
24714b8a87
commit
069e4297ea
@@ -6,7 +6,7 @@ Status: Active
|
|||||||
|
|
||||||
# [Form Definition Selector Cloud](../../../lib/process-services-cloud/src/lib/form/components/form-definition-selector-cloud.component.ts "Defined in form-definition-selector-cloud.component.ts")
|
# [Form Definition Selector Cloud](../../../lib/process-services-cloud/src/lib/form/components/form-definition-selector-cloud.component.ts "Defined in form-definition-selector-cloud.component.ts")
|
||||||
|
|
||||||
Allows one form to be selected.
|
Allows one form to be selected from a dropdown list. For forms to be displayed in this component they will need to be compatible with standAlone tasks.
|
||||||
|
|
||||||
## Basic Usage
|
## Basic Usage
|
||||||
|
|
||||||
|
@@ -42,7 +42,7 @@ describe('FormDefinitionCloudComponent', () => {
|
|||||||
fixture = TestBed.createComponent(FormDefinitionSelectorCloudComponent);
|
fixture = TestBed.createComponent(FormDefinitionSelectorCloudComponent);
|
||||||
element = fixture.nativeElement;
|
element = fixture.nativeElement;
|
||||||
service = TestBed.get(FormDefinitionSelectorCloudService);
|
service = TestBed.get(FormDefinitionSelectorCloudService);
|
||||||
getFormsSpy = spyOn(service, 'getForms').and.returnValue(of([{ id: 'fake-form', name: 'fakeForm' }]));
|
getFormsSpy = spyOn(service, 'getStandAloneTaskForms').and.returnValue(of([{ id: 'fake-form', name: 'fakeForm' }]));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should load the forms by default', () => {
|
it('should load the forms by default', () => {
|
||||||
|
@@ -43,7 +43,7 @@ export class FormDefinitionSelectorCloudComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.forms$ = this.formDefinitionCloudService.getForms(this.appName);
|
this.forms$ = this.formDefinitionCloudService.getStandAloneTaskForms(this.appName);
|
||||||
}
|
}
|
||||||
|
|
||||||
onSelect(event: MatSelectChange) {
|
onSelect(event: MatSelectChange) {
|
||||||
|
@@ -21,6 +21,7 @@ export class FormDefinitionSelectorCloudModel {
|
|||||||
name: string;
|
name: string;
|
||||||
description: string;
|
description: string;
|
||||||
version: string;
|
version: string;
|
||||||
|
standAlone: string;
|
||||||
|
|
||||||
constructor(obj?: any) {
|
constructor(obj?: any) {
|
||||||
if (obj) {
|
if (obj) {
|
||||||
@@ -28,6 +29,7 @@ export class FormDefinitionSelectorCloudModel {
|
|||||||
this.name = obj.name || null;
|
this.name = obj.name || null;
|
||||||
this.description = obj.description || null;
|
this.description = obj.description || null;
|
||||||
this.version = obj.version || null;
|
this.version = obj.version || null;
|
||||||
|
this.standAlone = obj.standAlone || null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,101 @@
|
|||||||
|
/*!
|
||||||
|
* @license
|
||||||
|
* Copyright 2019 Alfresco Software, Ltd.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { TestBed } from '@angular/core/testing';
|
||||||
|
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
||||||
|
import { AlfrescoApiService, CoreModule, setupTestBed, AppConfigService } from '@alfresco/adf-core';
|
||||||
|
import { FormDefinitionSelectorCloudService } from './form-definition-selector-cloud.service';
|
||||||
|
|
||||||
|
declare let jasmine: any;
|
||||||
|
|
||||||
|
const responseBody = [
|
||||||
|
{
|
||||||
|
formRepresentation: {
|
||||||
|
id: 'form-de8895be-d0d7-4434-beef-559b15305d72',
|
||||||
|
name: 'Form 1',
|
||||||
|
description: '',
|
||||||
|
version: 0,
|
||||||
|
standAlone: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
formRepresentation: {
|
||||||
|
id: 'form-de8895be-d0d7-4434-beef-fgr34ttgrtgd',
|
||||||
|
name: 'Form 2',
|
||||||
|
description: '',
|
||||||
|
version: 0,
|
||||||
|
standAlone: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
formRepresentation: {
|
||||||
|
id: 'form-de8895be-d0d7-4434-beef-53453453452',
|
||||||
|
name: 'Form 3',
|
||||||
|
description: '',
|
||||||
|
version: 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
const oauth2Auth = jasmine.createSpyObj('oauth2Auth', ['callCustomApi']);
|
||||||
|
|
||||||
|
describe('Form Definition Selector Cloud Service', () => {
|
||||||
|
|
||||||
|
let service: FormDefinitionSelectorCloudService;
|
||||||
|
let apiService: AlfrescoApiService;
|
||||||
|
const appName = 'app-name';
|
||||||
|
|
||||||
|
setupTestBed({
|
||||||
|
imports: [
|
||||||
|
NoopAnimationsModule,
|
||||||
|
CoreModule.forRoot()
|
||||||
|
],
|
||||||
|
providers: [
|
||||||
|
FormDefinitionSelectorCloudService,
|
||||||
|
AlfrescoApiService,
|
||||||
|
AppConfigService
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
service = TestBed.get(FormDefinitionSelectorCloudService);
|
||||||
|
apiService = TestBed.get(AlfrescoApiService);
|
||||||
|
spyOn(apiService, 'getInstance').and.returnValue({ oauth2Auth: oauth2Auth });
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should fetch all the forms when getForms is called', (done) => {
|
||||||
|
oauth2Auth.callCustomApi.and.returnValue(Promise.resolve(responseBody));
|
||||||
|
|
||||||
|
service.getForms(appName).subscribe((result) => {
|
||||||
|
expect(result).toBeDefined();
|
||||||
|
expect(result.length).toBe(3);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should fetch only standAlone enabled forms when getStandAloneTaskForms is called', (done) => {
|
||||||
|
oauth2Auth.callCustomApi.and.returnValue(Promise.resolve(responseBody));
|
||||||
|
|
||||||
|
service.getStandAloneTaskForms(appName).subscribe((result) => {
|
||||||
|
expect(result).toBeDefined();
|
||||||
|
expect(result.length).toBe(2);
|
||||||
|
expect(result[0].name).toBe('Form 1');
|
||||||
|
expect(result[1].name).toBe('Form 3');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
@@ -65,6 +65,21 @@ export class FormDefinitionSelectorCloudService extends BaseCloudService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all forms of an app.
|
||||||
|
* @param appName Name of the application
|
||||||
|
* @returns Details of the forms
|
||||||
|
*/
|
||||||
|
getStandAloneTaskForms(appName: string): Observable<FormDefinitionSelectorCloudModel[]> {
|
||||||
|
return from(this.getForms(appName)).pipe(
|
||||||
|
map((data: any) => {
|
||||||
|
return data.filter((formData: any) => formData.standAlone || formData.standAlone === undefined);
|
||||||
|
}),
|
||||||
|
catchError((err) => this.handleError(err))
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private buildGetFormsUrl(appName: string): any {
|
private buildGetFormsUrl(appName: string): any {
|
||||||
return `${this.getBasePath(appName)}/form/v1/forms`;
|
return `${this.getBasePath(appName)}/form/v1/forms`;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user