mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
#1113 - Fix for show values on completed form
This commit is contained in:
committed by
Mario Romano
parent
98f3cc25f8
commit
424511d1f6
@@ -5,7 +5,7 @@
|
|||||||
class="mdl-checkbox__input"
|
class="mdl-checkbox__input"
|
||||||
[checked]="field.value"
|
[checked]="field.value"
|
||||||
[(ngModel)]="field.value"
|
[(ngModel)]="field.value"
|
||||||
(ngModelChange)="checkVisibility(field)"
|
(ngModelChange)="onChange()"
|
||||||
[disabled]="field.readOnly">
|
[disabled]="field.readOnly">
|
||||||
<span class="mdl-checkbox__label">{{field.name}}</span>
|
<span class="mdl-checkbox__label">{{field.name}}</span>
|
||||||
</label>
|
</label>
|
||||||
|
@@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
import { WidgetComponent } from './../widget.component';
|
import { WidgetComponent } from './../widget.component';
|
||||||
|
import { WidgetVisibilityService } from '../../../services/widget-visibility.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
moduleId: module.id,
|
moduleId: module.id,
|
||||||
@@ -25,4 +26,12 @@ import { WidgetComponent } from './../widget.component';
|
|||||||
})
|
})
|
||||||
export class CheckboxWidget extends WidgetComponent {
|
export class CheckboxWidget extends WidgetComponent {
|
||||||
|
|
||||||
|
constructor(private visibilityService: WidgetVisibilityService) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
onChange() {
|
||||||
|
this.visibilityService.refreshVisibility(this.field.form);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -168,7 +168,7 @@ describe('FormFieldModel', () => {
|
|||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
field.value = 'Option 2';
|
field.value = 'opt2';
|
||||||
expect(form.values['dropdown-2']).toEqual(field.options[1]);
|
expect(form.values['dropdown-2']).toEqual(field.options[1]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -270,7 +270,7 @@ export class FormFieldModel extends FormWidgetModel {
|
|||||||
if (this.value === 'empty' || this.value === '') {
|
if (this.value === 'empty' || this.value === '') {
|
||||||
this.form.values[this.id] = {};
|
this.form.values[this.id] = {};
|
||||||
} else {
|
} else {
|
||||||
let entry: FormFieldOption[] = this.options.filter(opt => opt.name === this.value);
|
let entry: FormFieldOption[] = this.options.filter(opt => opt.id === this.value);
|
||||||
if (entry.length > 0) {
|
if (entry.length > 0) {
|
||||||
this.form.values[this.id] = entry[0];
|
this.form.values[this.id] = entry[0];
|
||||||
}
|
}
|
||||||
|
@@ -24,6 +24,7 @@ export * from './form-widget.model';
|
|||||||
export * from './form-field.model';
|
export * from './form-field.model';
|
||||||
export * from './form.model';
|
export * from './form.model';
|
||||||
export * from './container.model';
|
export * from './container.model';
|
||||||
|
export * from './container-column.model';
|
||||||
export * from './tab.model';
|
export * from './tab.model';
|
||||||
export * from './form-outcome.model';
|
export * from './form-outcome.model';
|
||||||
export * from './form-outcome-event.model';
|
export * from './form-outcome-event.model';
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<div [ngSwitch]="fieldType" class="display-value-widget">
|
<div [ngSwitch]="fieldType" class="display-value-widget">
|
||||||
<div *ngSwitchCase="'boolean'">
|
<div *ngSwitchCase="'boolean'">
|
||||||
<label class="mdl-checkbox mdl-js-checkbox" [attr.for]="field.id">
|
<label class="mdl-checkbox mdl-js-checkbox" [attr.for]="field.id" *ngIf="field?.isVisible">
|
||||||
<input type="checkbox"
|
<input type="checkbox"
|
||||||
[attr.id]="field.id"
|
[attr.id]="field.id"
|
||||||
[checked]="field.value"
|
[checked]="field.value"
|
||||||
@@ -11,26 +11,30 @@
|
|||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div *ngSwitchCase="'text'"
|
<div *ngSwitchCase="'text'"
|
||||||
class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label text-widget">
|
class="mdl-textfield mdl-js-textfield text-widget">
|
||||||
<input class="mdl-textfield__input"
|
<label *ngIf="field?.isVisible" [attr.for]="field.id">{{field.name}}</label>
|
||||||
|
<input
|
||||||
|
*ngIf="field?.isVisible"
|
||||||
|
class="mdl-textfield__input"
|
||||||
type="text"
|
type="text"
|
||||||
[attr.id]="field.id"
|
[attr.id]="field.id"
|
||||||
[value]="value"
|
[value]="value"
|
||||||
disabled>
|
disabled>
|
||||||
<label class="mdl-textfield__label" [attr.for]="field.id">{{field.name}}</label>
|
|
||||||
</div>
|
</div>
|
||||||
<div *ngSwitchCase="'multi-line-text'"
|
<div *ngSwitchCase="'multi-line-text'"
|
||||||
class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label multiline-text-widget">
|
class="mdl-textfield mdl-js-textfield multiline-text-widget">
|
||||||
<textarea class="mdl-textfield__input"
|
<textarea class="mdl-textfield__input"
|
||||||
type="text"
|
type="text"
|
||||||
rows= "3"
|
rows="3"
|
||||||
[value]="value"
|
[value]="value"
|
||||||
[attr.id]="field.id"
|
[attr.id]="field.id"
|
||||||
disabled>
|
disabled
|
||||||
|
*ngIf="field?.isVisible">
|
||||||
</textarea>
|
</textarea>
|
||||||
<label class="mdl-textfield__label" [attr.for]="field.id">{{field.name}}</label>
|
<label *ngIf="field?.isVisible" class="mdl-textfield__label" [attr.for]="field.id">{{field.name}}</label>
|
||||||
</div>
|
</div>
|
||||||
<div *ngSwitchCase="'hyperlink'" class="hyperlink-widget">
|
<div *ngSwitchCase="'hyperlink'" class="hyperlink-widget">
|
||||||
|
<div *ngIf="field?.isVisible">
|
||||||
<div>
|
<div>
|
||||||
<span>{{field.name}}</span>
|
<span>{{field.name}}</span>
|
||||||
</div>
|
</div>
|
||||||
@@ -38,9 +42,10 @@
|
|||||||
<a [href]="linkUrl" target="_blank" rel="nofollow">{{linkText}}</a>
|
<a [href]="linkUrl" target="_blank" rel="nofollow">{{linkText}}</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
<div *ngSwitchCase="'dynamic-table'">
|
<div *ngSwitchCase="'dynamic-table'">
|
||||||
<div class="display-value-widget__dynamic-table">
|
<div class="display-value-widget__dynamic-table" *ngIf="field?.isVisible">
|
||||||
<div class="is-disabled">{{field.name}}</div>
|
<div>{{field.name}}</div>
|
||||||
<table class="mdl-data-table mdl-js-data-table">
|
<table class="mdl-data-table mdl-js-data-table">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -62,7 +67,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div *ngSwitchCase="'upload'">
|
<div *ngSwitchCase="'upload'">
|
||||||
<div class="upload-widget">
|
<div class="upload-widget" *ngIf="field?.isVisible">
|
||||||
<label class="upload-widget__label" [attr.for]="field.id">{{field.name}}</label>
|
<label class="upload-widget__label" [attr.for]="field.id">{{field.name}}</label>
|
||||||
<div>
|
<div>
|
||||||
<i *ngIf="hasFile" class="material-icons upload-widget__icon">attachment</i>
|
<i *ngIf="hasFile" class="material-icons upload-widget__icon">attachment</i>
|
||||||
@@ -71,14 +76,15 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div *ngSwitchDefault
|
<div *ngSwitchDefault
|
||||||
class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label text-widget">
|
class="mdl-textfield mdl-js-textfield text-widget is-disabled is-dirty is-upgraded">
|
||||||
<input class="mdl-textfield__input"
|
<label *ngIf="field?.isVisible" [attr.for]="field.id">{{field.name}}</label>
|
||||||
|
<input
|
||||||
|
*ngIf="field?.isVisible"
|
||||||
|
class="mdl-textfield__input"
|
||||||
type="text"
|
type="text"
|
||||||
[attr.id]="field.id"
|
[attr.id]="field.id"
|
||||||
[value]="value"
|
[value]="value"
|
||||||
(ngModelChange)="checkVisibility(field)"
|
|
||||||
disabled>
|
disabled>
|
||||||
<label class="mdl-textfield__label" [attr.for]="field.id">{{field.name}}</label>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@@ -25,15 +25,18 @@ import { FormFieldModel } from './../core/form-field.model';
|
|||||||
import { FormFieldTypes } from '../core/form-field-types';
|
import { FormFieldTypes } from '../core/form-field-types';
|
||||||
import { FormModel } from '../core/form.model';
|
import { FormModel } from '../core/form.model';
|
||||||
import { DynamicTableColumn, DynamicTableRow } from './../dynamic-table/dynamic-table.widget.model';
|
import { DynamicTableColumn, DynamicTableRow } from './../dynamic-table/dynamic-table.widget.model';
|
||||||
|
import { WidgetVisibilityService } from '../../../services/widget-visibility.service';
|
||||||
|
|
||||||
describe('DisplayValueWidget', () => {
|
describe('DisplayValueWidget', () => {
|
||||||
|
|
||||||
let widget: DisplayValueWidget;
|
let widget: DisplayValueWidget;
|
||||||
let formService: FormService;
|
let formService: FormService;
|
||||||
|
let visibilityService: WidgetVisibilityService;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
formService = new FormService(null, null);
|
formService = new FormService(null, null);
|
||||||
widget = new DisplayValueWidget(formService);
|
visibilityService = new WidgetVisibilityService(null, null, null);
|
||||||
|
widget = new DisplayValueWidget(formService, visibilityService);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should require field to setup default value', () => {
|
it('should require field to setup default value', () => {
|
||||||
@@ -686,7 +689,8 @@ describe('DisplayValueWidget', () => {
|
|||||||
declarations: [DisplayValueWidget],
|
declarations: [DisplayValueWidget],
|
||||||
providers: [
|
providers: [
|
||||||
EcmModelService,
|
EcmModelService,
|
||||||
FormService
|
FormService,
|
||||||
|
WidgetVisibilityService
|
||||||
]
|
]
|
||||||
}).compileComponents().then(() => {
|
}).compileComponents().then(() => {
|
||||||
fixture = TestBed.createComponent(DisplayValueWidget);
|
fixture = TestBed.createComponent(DisplayValueWidget);
|
||||||
|
@@ -15,12 +15,13 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit, AfterViewChecked } from '@angular/core';
|
||||||
import { WidgetComponent } from './../widget.component';
|
import { WidgetComponent } from './../widget.component';
|
||||||
import { FormFieldTypes } from '../core/form-field-types';
|
import { FormFieldTypes } from '../core/form-field-types';
|
||||||
import { FormService } from '../../../services/form.service';
|
import { FormService } from '../../../services/form.service';
|
||||||
import { FormFieldOption } from './../core/form-field-option';
|
import { FormFieldOption } from './../core/form-field-option';
|
||||||
import { DynamicTableColumn, DynamicTableRow } from './../dynamic-table/dynamic-table.widget.model';
|
import { DynamicTableColumn, DynamicTableRow } from './../dynamic-table/dynamic-table.widget.model';
|
||||||
|
import { WidgetVisibilityService } from '../../../services/widget-visibility.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
moduleId: module.id,
|
moduleId: module.id,
|
||||||
@@ -28,7 +29,7 @@ import { DynamicTableColumn, DynamicTableRow } from './../dynamic-table/dynamic-
|
|||||||
templateUrl: './display-value.widget.html',
|
templateUrl: './display-value.widget.html',
|
||||||
styleUrls: ['./display-value.widget.css']
|
styleUrls: ['./display-value.widget.css']
|
||||||
})
|
})
|
||||||
export class DisplayValueWidget extends WidgetComponent implements OnInit {
|
export class DisplayValueWidget extends WidgetComponent implements OnInit, AfterViewChecked {
|
||||||
|
|
||||||
value: any;
|
value: any;
|
||||||
fieldType: string;
|
fieldType: string;
|
||||||
@@ -45,14 +46,14 @@ export class DisplayValueWidget extends WidgetComponent implements OnInit {
|
|||||||
// upload/attach
|
// upload/attach
|
||||||
hasFile: boolean = false;
|
hasFile: boolean = false;
|
||||||
|
|
||||||
constructor(private formService: FormService) {
|
constructor(private formService: FormService,
|
||||||
|
private visibilityService: WidgetVisibilityService) {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
if (this.field) {
|
if (this.field) {
|
||||||
this.value = this.field.value;
|
this.value = this.field.value;
|
||||||
|
|
||||||
if (this.field.params) {
|
if (this.field.params) {
|
||||||
let originalField = this.field.params['field'];
|
let originalField = this.field.params['field'];
|
||||||
if (originalField && originalField.type) {
|
if (originalField && originalField.type) {
|
||||||
@@ -123,7 +124,7 @@ export class DisplayValueWidget extends WidgetComponent implements OnInit {
|
|||||||
this.visibleColumns = this.columns.filter(col => col.visible);
|
this.visibleColumns = this.columns.filter(col => col.visible);
|
||||||
}
|
}
|
||||||
if (json.value) {
|
if (json.value) {
|
||||||
this.rows = json.value.map(obj => <DynamicTableRow> {selected: false, value: obj});
|
this.rows = json.value.map(obj => <DynamicTableRow> { selected: false, value: obj });
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -135,6 +136,10 @@ export class DisplayValueWidget extends WidgetComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ngAfterViewChecked() {
|
||||||
|
this.visibilityService.refreshVisibility(this.field.form);
|
||||||
|
}
|
||||||
|
|
||||||
loadRadioButtonValue() {
|
loadRadioButtonValue() {
|
||||||
let options = this.field.options || [];
|
let options = this.field.options || [];
|
||||||
let toSelect = options.find(item => item.id === this.field.value);
|
let toSelect = options.find(item => item.id === this.field.value);
|
||||||
@@ -146,10 +151,10 @@ export class DisplayValueWidget extends WidgetComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
loadRestFieldValue() {
|
loadRestFieldValue() {
|
||||||
if (this.field.form.processDefinitionId) {
|
if (this.field.form.taskId) {
|
||||||
this.getValuesByProcessDefinitionId();
|
|
||||||
} else {
|
|
||||||
this.getValuesByTaskId();
|
this.getValuesByTaskId();
|
||||||
|
} else {
|
||||||
|
this.getValuesByProcessDefinitionId();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,11 +168,13 @@ export class DisplayValueWidget extends WidgetComponent implements OnInit {
|
|||||||
(result: FormFieldOption[]) => {
|
(result: FormFieldOption[]) => {
|
||||||
let options = result || [];
|
let options = result || [];
|
||||||
let toSelect = options.find(item => item.id === this.field.value);
|
let toSelect = options.find(item => item.id === this.field.value);
|
||||||
|
this.field.options = options;
|
||||||
if (toSelect) {
|
if (toSelect) {
|
||||||
this.value = toSelect.name;
|
this.value = toSelect.name;
|
||||||
} else {
|
} else {
|
||||||
this.value = this.field.value;
|
this.value = this.field.value;
|
||||||
}
|
}
|
||||||
|
this.visibilityService.refreshEntityVisibility(this.field);
|
||||||
},
|
},
|
||||||
error => {
|
error => {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
@@ -183,11 +190,13 @@ export class DisplayValueWidget extends WidgetComponent implements OnInit {
|
|||||||
(result: FormFieldOption[]) => {
|
(result: FormFieldOption[]) => {
|
||||||
let options = result || [];
|
let options = result || [];
|
||||||
let toSelect = options.find(item => item.id === this.field.value);
|
let toSelect = options.find(item => item.id === this.field.value);
|
||||||
|
this.field.options = options;
|
||||||
if (toSelect) {
|
if (toSelect) {
|
||||||
this.value = toSelect.name;
|
this.value = toSelect.name;
|
||||||
} else {
|
} else {
|
||||||
this.value = this.field.value;
|
this.value = this.field.value;
|
||||||
}
|
}
|
||||||
|
this.visibilityService.refreshEntityVisibility(this.field);
|
||||||
},
|
},
|
||||||
error => {
|
error => {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
|
@@ -84,7 +84,7 @@ export class DropdownWidget extends WidgetComponent implements OnInit {
|
|||||||
|
|
||||||
getOptionValue(option: FormFieldOption): string {
|
getOptionValue(option: FormFieldOption): string {
|
||||||
let optionValue: string = '';
|
let optionValue: string = '';
|
||||||
if (option.id === 'empty') {
|
if (option.id === 'empty' || option.name !== this.field.value) {
|
||||||
optionValue = option.id;
|
optionValue = option.id;
|
||||||
} else {
|
} else {
|
||||||
optionValue = option.name;
|
optionValue = option.name;
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
<div class="dynamic-table-widget"
|
<div class="dynamic-table-widget"
|
||||||
[class.dynamic-table-widget__invalid]="!isValid()">
|
[class.dynamic-table-widget__invalid]="!isValid()" *ngIf="field?.isVisible">
|
||||||
<div class="dynamic-table-widget__label">{{content.name}}</div>
|
<div class="dynamic-table-widget__label">{{content.name}}</div>
|
||||||
|
|
||||||
<div *ngIf="!editMode">
|
<div *ngIf="!editMode">
|
||||||
|
@@ -18,15 +18,18 @@
|
|||||||
import { DynamicTableWidget } from './dynamic-table.widget';
|
import { DynamicTableWidget } from './dynamic-table.widget';
|
||||||
import { DynamicTableModel, DynamicTableRow, DynamicTableColumn } from './dynamic-table.widget.model';
|
import { DynamicTableModel, DynamicTableRow, DynamicTableColumn } from './dynamic-table.widget.model';
|
||||||
import { FormModel, FormFieldTypes } from './../core/index';
|
import { FormModel, FormFieldTypes } from './../core/index';
|
||||||
|
import { WidgetVisibilityService } from '../../../services/widget-visibility.service';
|
||||||
|
|
||||||
describe('DynamicTableWidget', () => {
|
describe('DynamicTableWidget', () => {
|
||||||
|
|
||||||
let widget: DynamicTableWidget;
|
let widget: DynamicTableWidget;
|
||||||
let table: DynamicTableModel;
|
let table: DynamicTableModel;
|
||||||
|
let visibilityService: WidgetVisibilityService;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
table = new DynamicTableModel(null);
|
table = new DynamicTableModel(null);
|
||||||
widget = new DynamicTableWidget(null);
|
visibilityService = new WidgetVisibilityService(null, null, null);
|
||||||
|
widget = new DynamicTableWidget(null, visibilityService);
|
||||||
widget.content = table;
|
widget.content = table;
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -92,8 +95,8 @@ describe('DynamicTableWidget', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should move selection down', () => {
|
it('should move selection down', () => {
|
||||||
let row1 = <DynamicTableRow> { };
|
let row1 = <DynamicTableRow> {};
|
||||||
let row2 = <DynamicTableRow> { };
|
let row2 = <DynamicTableRow> {};
|
||||||
widget.content.rows.push(...[row1, row2]);
|
widget.content.rows.push(...[row1, row2]);
|
||||||
widget.content.selectedRow = row1;
|
widget.content.selectedRow = row1;
|
||||||
|
|
||||||
@@ -248,5 +251,124 @@ describe('DynamicTableWidget', () => {
|
|||||||
let actual = widget.getCellValue(row, column);
|
let actual = widget.getCellValue(row, column);
|
||||||
expect(actual).toBe('GBP 100');
|
expect(actual).toBe('GBP 100');
|
||||||
});
|
});
|
||||||
|
/*
|
||||||
|
describe('when template is ready', () => {
|
||||||
|
let dynamicTableWidget: DynamicTableWidget;
|
||||||
|
let fixture: ComponentFixture<DynamicTableWidget>;
|
||||||
|
let element: HTMLElement;
|
||||||
|
let componentHandler;
|
||||||
|
let stubFormService;
|
||||||
|
|
||||||
|
beforeEach(async(() => {
|
||||||
|
componentHandler = jasmine.createSpyObj('componentHandler', ['upgradeAllRegistered', 'upgradeElement']);
|
||||||
|
window['componentHandler'] = componentHandler;
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
imports: [CoreModule],
|
||||||
|
declarations: [DynamicTableWidget],
|
||||||
|
providers: [EcmModelService]
|
||||||
|
}).compileComponents().then(() => {
|
||||||
|
fixture = TestBed.createComponent(DropdownEditorComponent);
|
||||||
|
dropDownEditorComponent = fixture.componentInstance;
|
||||||
|
element = fixture.nativeElement;
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
fixture.destroy();
|
||||||
|
TestBed.resetTestingModule();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('and dropdown is populated via taskId', () => {
|
||||||
|
|
||||||
|
beforeEach(async(() => {
|
||||||
|
stubFormService = fixture.debugElement.injector.get(FormService);
|
||||||
|
spyOn(stubFormService, 'getRestFieldValuesColumn').and.returnValue(Observable.of(fakeOptionList));
|
||||||
|
row = <DynamicTableRow> { value: { dropdown: 'one' } };
|
||||||
|
column = <DynamicTableColumn> {
|
||||||
|
id: 'column-id',
|
||||||
|
optionType: 'rest',
|
||||||
|
options: [
|
||||||
|
<DynamicTableColumnOption> { id: '1', name: 'one' },
|
||||||
|
<DynamicTableColumnOption> { id: '2', name: 'two' }
|
||||||
|
]
|
||||||
|
};
|
||||||
|
form = new FormModel({ taskId: '<task-id>' });
|
||||||
|
dynamicTable = new DynamicTableModel(form, null);
|
||||||
|
dynamicTable.field = new FormFieldModel(form, { id: '<field-id>' });
|
||||||
|
dynamicTable.rows.push(row);
|
||||||
|
dynamicTable.columns.push(column);
|
||||||
|
dropDownEditorComponent.table = dynamicTable;
|
||||||
|
dropDownEditorComponent.column = column;
|
||||||
|
dropDownEditorComponent.row = row;
|
||||||
|
dropDownEditorComponent.table.field = new FormFieldModel(form, {
|
||||||
|
id: 'dropdown-id',
|
||||||
|
name: 'date-name',
|
||||||
|
type: 'dropdown',
|
||||||
|
readOnly: 'false',
|
||||||
|
restUrl: 'fake-rest-url'
|
||||||
|
});
|
||||||
|
dropDownEditorComponent.table.field.isVisible = true;
|
||||||
|
fixture.detectChanges();
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should show visible dropdown widget', async(() => {
|
||||||
|
expect(element.querySelector('#column-id')).toBeDefined();
|
||||||
|
expect(element.querySelector('#column-id')).not.toBeNull();
|
||||||
|
expect(element.querySelector('#opt_1')).not.toBeNull();
|
||||||
|
expect(element.querySelector('#opt_2')).not.toBeNull();
|
||||||
|
expect(element.querySelector('#opt_3')).not.toBeNull();
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('and dropdown is populated via processDefinitionId', () => {
|
||||||
|
|
||||||
|
beforeEach(async(() => {
|
||||||
|
stubFormService = fixture.debugElement.injector.get(FormService);
|
||||||
|
spyOn(stubFormService, 'getRestFieldValuesColumnByProcessId').and.returnValue(Observable.of(fakeOptionList));
|
||||||
|
row = <DynamicTableRow> { value: { dropdown: 'one' } };
|
||||||
|
column = <DynamicTableColumn> {
|
||||||
|
id: 'column-id',
|
||||||
|
optionType: 'rest',
|
||||||
|
options: [
|
||||||
|
<DynamicTableColumnOption> { id: '1', name: 'one' },
|
||||||
|
<DynamicTableColumnOption> { id: '2', name: 'two' }
|
||||||
|
]
|
||||||
|
};
|
||||||
|
form = new FormModel({ processDefinitionId: '<proc-id>' });
|
||||||
|
dynamicTable = new DynamicTableModel(form, null);
|
||||||
|
dynamicTable.field = new FormFieldModel(form, { id: '<field-id>' });
|
||||||
|
dynamicTable.rows.push(row);
|
||||||
|
dynamicTable.columns.push(column);
|
||||||
|
dropDownEditorComponent.table = dynamicTable;
|
||||||
|
dropDownEditorComponent.column = column;
|
||||||
|
dropDownEditorComponent.row = row;
|
||||||
|
dropDownEditorComponent.table.field = new FormFieldModel(form, {
|
||||||
|
id: 'dropdown-id',
|
||||||
|
name: 'date-name',
|
||||||
|
type: 'dropdown',
|
||||||
|
readOnly: 'false',
|
||||||
|
restUrl: 'fake-rest-url'
|
||||||
|
});
|
||||||
|
dropDownEditorComponent.table.field.isVisible = true;
|
||||||
|
fixture.detectChanges();
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should show visible dropdown widget', async(() => {
|
||||||
|
expect(element.querySelector('#column-id')).toBeDefined();
|
||||||
|
expect(element.querySelector('#column-id')).not.toBeNull();
|
||||||
|
expect(element.querySelector('#opt_1')).not.toBeNull();
|
||||||
|
expect(element.querySelector('#opt_2')).not.toBeNull();
|
||||||
|
expect(element.querySelector('#opt_3')).not.toBeNull();
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should show visible dropdown widget', async(() => {
|
||||||
|
expect(element.querySelector('#column-id')).toBeDefined();
|
||||||
|
expect(element.querySelector('#column-id')).not.toBeNull();
|
||||||
|
expect(element.querySelector('#opt_1')).not.toBeNull();
|
||||||
|
expect(element.querySelector('#opt_2')).not.toBeNull();
|
||||||
|
expect(element.querySelector('#opt_3')).not.toBeNull();
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
});*/
|
||||||
});
|
});
|
||||||
|
@@ -18,6 +18,7 @@
|
|||||||
import { Component, ElementRef, OnInit } from '@angular/core';
|
import { Component, ElementRef, OnInit } from '@angular/core';
|
||||||
import { WidgetComponent } from './../widget.component';
|
import { WidgetComponent } from './../widget.component';
|
||||||
import { DynamicTableModel, DynamicTableRow, DynamicTableColumn } from './dynamic-table.widget.model';
|
import { DynamicTableModel, DynamicTableRow, DynamicTableColumn } from './dynamic-table.widget.model';
|
||||||
|
import { WidgetVisibilityService } from '../../../services/widget-visibility.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
moduleId: module.id,
|
moduleId: module.id,
|
||||||
@@ -34,13 +35,15 @@ export class DynamicTableWidget extends WidgetComponent implements OnInit {
|
|||||||
editMode: boolean = false;
|
editMode: boolean = false;
|
||||||
editRow: DynamicTableRow = null;
|
editRow: DynamicTableRow = null;
|
||||||
|
|
||||||
constructor(private elementRef: ElementRef) {
|
constructor(private elementRef: ElementRef,
|
||||||
|
private visibilityService: WidgetVisibilityService) {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
if (this.field) {
|
if (this.field) {
|
||||||
this.content = new DynamicTableModel(this.field.form, this.field.json);
|
this.content = new DynamicTableModel(this.field.form, this.field.json);
|
||||||
|
this.visibilityService.refreshVisibility(this.field.form);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -57,7 +57,6 @@ export class TypeaheadWidget extends WidgetComponent implements OnInit {
|
|||||||
(result: FormFieldOption[]) => {
|
(result: FormFieldOption[]) => {
|
||||||
let options = result || [];
|
let options = result || [];
|
||||||
this.field.options = options;
|
this.field.options = options;
|
||||||
this.field.updateForm();
|
|
||||||
|
|
||||||
let fieldValue = this.field.value;
|
let fieldValue = this.field.value;
|
||||||
if (fieldValue) {
|
if (fieldValue) {
|
||||||
@@ -66,6 +65,8 @@ export class TypeaheadWidget extends WidgetComponent implements OnInit {
|
|||||||
this.value = toSelect.name;
|
this.value = toSelect.name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this.field.updateForm();
|
||||||
|
this.visibilityService.refreshEntityVisibility(this.field);
|
||||||
},
|
},
|
||||||
this.handleError
|
this.handleError
|
||||||
);
|
);
|
||||||
@@ -81,7 +82,6 @@ export class TypeaheadWidget extends WidgetComponent implements OnInit {
|
|||||||
(result: FormFieldOption[]) => {
|
(result: FormFieldOption[]) => {
|
||||||
let options = result || [];
|
let options = result || [];
|
||||||
this.field.options = options;
|
this.field.options = options;
|
||||||
this.field.updateForm();
|
|
||||||
|
|
||||||
let fieldValue = this.field.value;
|
let fieldValue = this.field.value;
|
||||||
if (fieldValue) {
|
if (fieldValue) {
|
||||||
@@ -90,6 +90,8 @@ export class TypeaheadWidget extends WidgetComponent implements OnInit {
|
|||||||
this.value = toSelect.name;
|
this.value = toSelect.name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this.field.updateForm();
|
||||||
|
this.visibilityService.refreshEntityVisibility(this.field);
|
||||||
},
|
},
|
||||||
this.handleError
|
this.handleError
|
||||||
);
|
);
|
||||||
|
@@ -28,6 +28,7 @@ import { AlfrescoSettingsService, AlfrescoAuthenticationService, AlfrescoApiServ
|
|||||||
import { TaskProcessVariableModel } from '../models/task-process-variable.model';
|
import { TaskProcessVariableModel } from '../models/task-process-variable.model';
|
||||||
import { WidgetVisibilityModel } from '../models/widget-visibility.model';
|
import { WidgetVisibilityModel } from '../models/widget-visibility.model';
|
||||||
import { FormModel, FormFieldModel, TabModel, ContainerModel, FormFieldTypes } from '../components/widgets/core/index';
|
import { FormModel, FormFieldModel, TabModel, ContainerModel, FormFieldTypes } from '../components/widgets/core/index';
|
||||||
|
import { FormService } from './form.service';
|
||||||
|
|
||||||
declare let jasmine: any;
|
declare let jasmine: any;
|
||||||
|
|
||||||
@@ -43,7 +44,8 @@ describe('WidgetVisibilityService', () => {
|
|||||||
AlfrescoSettingsService,
|
AlfrescoSettingsService,
|
||||||
AlfrescoAuthenticationService,
|
AlfrescoAuthenticationService,
|
||||||
AlfrescoApiService,
|
AlfrescoApiService,
|
||||||
WidgetVisibilityService
|
WidgetVisibilityService,
|
||||||
|
FormService
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
service = TestBed.get(WidgetVisibilityService);
|
service = TestBed.get(WidgetVisibilityService);
|
||||||
@@ -537,7 +539,7 @@ describe('WidgetVisibilityService', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should determine visibility for dropdown on label condition', () => {
|
it('should determine visibility for dropdown on label condition', () => {
|
||||||
let dropdownValue = service.getDropDownName(formTest.values, 'dropdown_LABEL');
|
let dropdownValue = service.getFieldValue(formTest.values, 'dropdown_LABEL');
|
||||||
|
|
||||||
expect(dropdownValue).not.toBeNull();
|
expect(dropdownValue).not.toBeNull();
|
||||||
expect(dropdownValue).toBeDefined();
|
expect(dropdownValue).toBeDefined();
|
||||||
@@ -545,7 +547,7 @@ describe('WidgetVisibilityService', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should be able to get the value for a dropdown filtered with Label', () => {
|
it('should be able to get the value for a dropdown filtered with Label', () => {
|
||||||
let dropdownValue = service.getValue(formTest.values, 'dropdown_LABEL');
|
let dropdownValue = service.getFieldValue(formTest.values, 'dropdown_LABEL');
|
||||||
|
|
||||||
expect(dropdownValue).not.toBeNull();
|
expect(dropdownValue).not.toBeNull();
|
||||||
expect(dropdownValue).toBeDefined();
|
expect(dropdownValue).toBeDefined();
|
||||||
@@ -553,7 +555,7 @@ describe('WidgetVisibilityService', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should be able to get the value for a standard field', () => {
|
it('should be able to get the value for a standard field', () => {
|
||||||
let dropdownValue = service.getValue(formTest.values, 'test_2');
|
let dropdownValue = service.getFieldValue(formTest.values, 'test_2');
|
||||||
|
|
||||||
expect(dropdownValue).not.toBeNull();
|
expect(dropdownValue).not.toBeNull();
|
||||||
expect(dropdownValue).toBeDefined();
|
expect(dropdownValue).toBeDefined();
|
||||||
|
@@ -19,7 +19,13 @@ import { Injectable } from '@angular/core';
|
|||||||
import { Response, Http, Headers, RequestOptions } from '@angular/http';
|
import { Response, Http, Headers, RequestOptions } from '@angular/http';
|
||||||
import { Observable } from 'rxjs/Rx';
|
import { Observable } from 'rxjs/Rx';
|
||||||
import { AlfrescoSettingsService, AlfrescoAuthenticationService } from 'ng2-alfresco-core';
|
import { AlfrescoSettingsService, AlfrescoAuthenticationService } from 'ng2-alfresco-core';
|
||||||
import { FormModel, FormFieldModel, TabModel } from '../components/widgets/core/index';
|
import {
|
||||||
|
FormModel,
|
||||||
|
FormFieldModel,
|
||||||
|
TabModel,
|
||||||
|
ContainerModel,
|
||||||
|
ContainerColumnModel
|
||||||
|
} from '../components/widgets/core/index';
|
||||||
import { WidgetVisibilityModel } from '../models/widget-visibility.model';
|
import { WidgetVisibilityModel } from '../models/widget-visibility.model';
|
||||||
import { TaskProcessVariableModel } from '../models/task-process-variable.model';
|
import { TaskProcessVariableModel } from '../models/task-process-variable.model';
|
||||||
|
|
||||||
@@ -96,45 +102,70 @@ export class WidgetVisibilityService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getFormValue(form: FormModel, field: string) {
|
getFormValue(form: FormModel, field: string) {
|
||||||
let value = this.getValue(form.values, field);
|
let value = this.getFieldValue(form.values, field);
|
||||||
value = value && value.id ? value.id : value;
|
|
||||||
return value ? value : this.searchForm(form, field);
|
return value ? value : this.searchForm(form, field);
|
||||||
}
|
}
|
||||||
|
|
||||||
getValue(values: any, fieldName: string) {
|
|
||||||
return this.getFieldValue(values, fieldName) ||
|
|
||||||
this.getDropDownName(values, fieldName);
|
|
||||||
}
|
|
||||||
|
|
||||||
getFieldValue(valueList: any, fieldName: string) {
|
getFieldValue(valueList: any, fieldName: string) {
|
||||||
return valueList[fieldName];
|
let dropDownFilterByName, valueFound = '';
|
||||||
}
|
|
||||||
|
|
||||||
getDropDownName(valueList: any, fieldName: string) {
|
|
||||||
let dropDownFilterByName;
|
|
||||||
if (fieldName && fieldName.indexOf('_LABEL') > 0) {
|
if (fieldName && fieldName.indexOf('_LABEL') > 0) {
|
||||||
dropDownFilterByName = fieldName.substring(0, fieldName.length - 6);
|
dropDownFilterByName = fieldName.substring(0, fieldName.length - 6);
|
||||||
|
if (valueList[dropDownFilterByName]) {
|
||||||
|
valueFound = valueList[dropDownFilterByName].name;
|
||||||
}
|
}
|
||||||
return ( dropDownFilterByName && valueList[dropDownFilterByName] ) ?
|
} else if (valueList[fieldName] && valueList[fieldName].id) {
|
||||||
valueList[dropDownFilterByName].name : dropDownFilterByName;
|
valueFound = valueList[fieldName].id;
|
||||||
|
} else {
|
||||||
|
valueFound = valueList[fieldName];
|
||||||
|
}
|
||||||
|
return valueFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
searchForm(form: FormModel, name: string) {
|
searchForm(form: FormModel, name: string) {
|
||||||
let fieldValue = '';
|
let fieldValue = '';
|
||||||
form.json.fields.forEach(columns => {
|
form.fields.forEach((containerModel: ContainerModel) => {
|
||||||
for (let i in columns.fields) {
|
containerModel.field.columns.forEach((containerColumnModel: ContainerColumnModel) => {
|
||||||
if (columns.fields.hasOwnProperty(i)) {
|
let fieldFound = containerColumnModel.fields.find(field => this.findFieldByValue(field, name));
|
||||||
let field = columns.fields[i].find(field => field.id === name);
|
if (fieldFound) {
|
||||||
if (field) {
|
if (name.indexOf('_LABEL') > 0) {
|
||||||
fieldValue = field.value;
|
if (fieldFound.value && fieldFound.value.name) {
|
||||||
|
fieldValue = fieldFound.value.name;
|
||||||
|
} else if (fieldFound.options) {
|
||||||
|
let option = fieldFound.options.find(option => option.id === fieldFound.value);
|
||||||
|
if (option) {
|
||||||
|
fieldValue = option.name;
|
||||||
|
} else {
|
||||||
|
fieldValue = fieldFound.value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (fieldFound.value && fieldFound.value && fieldFound.value.id) {
|
||||||
|
fieldValue = fieldFound.value.id;
|
||||||
|
} else {
|
||||||
|
fieldValue = fieldFound.value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
});
|
||||||
|
});
|
||||||
return fieldValue;
|
return fieldValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
findFieldByValue(field: FormFieldModel, fieldToFind: string) {
|
||||||
|
let isFound = false;
|
||||||
|
switch (field.fieldType) {
|
||||||
|
case 'RestFieldRepresentation' :
|
||||||
|
if (fieldToFind.indexOf('_LABEL') > 0) {
|
||||||
|
isFound = (fieldToFind.substring(0, fieldToFind.length - 6) === field.name);
|
||||||
|
} else {
|
||||||
|
isFound = (field.name === fieldToFind);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
isFound = (field.name === fieldToFind);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return isFound;
|
||||||
|
}
|
||||||
|
|
||||||
getVariableValue(form: FormModel, name: string, processVarList: TaskProcessVariableModel[]) {
|
getVariableValue(form: FormModel, name: string, processVarList: TaskProcessVariableModel[]) {
|
||||||
return this.getFormVariableValue(form, name) ||
|
return this.getFormVariableValue(form, name) ||
|
||||||
this.getProcessVariableValue(name, processVarList);
|
this.getProcessVariableValue(name, processVarList);
|
||||||
@@ -221,5 +252,4 @@ export class WidgetVisibilityService {
|
|||||||
console.error(error);
|
console.error(error);
|
||||||
return Observable.throw(error.json().error || 'Server error');
|
return Observable.throw(error.json().error || 'Server error');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user