Merge pull request #816 from Alfresco/dev-denys-814

Fixes for Activiti Form (validation and rendering)
This commit is contained in:
Mario Romano 2016-09-27 15:43:58 +02:00 committed by GitHub
commit d2f30d24d5
11 changed files with 114 additions and 21 deletions

View File

@ -65,7 +65,7 @@ export class RequiredFieldValidator implements FormFieldValidator {
return field.value && field.value.length > 0; return field.value && field.value.length > 0;
} }
if (!field.value) { if (field.value === null || field.value === undefined || field.value === '') {
return false; return false;
} }
} }

View File

@ -29,7 +29,7 @@ describe('FunctionalGroupWidget', () => {
beforeEach(() => { beforeEach(() => {
formService = new FormService(null, null); formService = new FormService(null, null);
widget = new FunctionalGroupWidget(formService); widget = new FunctionalGroupWidget(formService, null);
widget.field = new FormFieldModel(new FormModel()); widget.field = new FormFieldModel(new FormModel());
}); });

View File

@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
import { Component, OnInit } from '@angular/core'; import { Component, OnInit, ElementRef } from '@angular/core';
import { WidgetComponent } from './../widget.component'; import { WidgetComponent } from './../widget.component';
import { FormService } from '../../../services/form.service'; import { FormService } from '../../../services/form.service';
import { GroupModel } from './../core/group.model'; import { GroupModel } from './../core/group.model';
@ -36,7 +36,8 @@ export class FunctionalGroupWidget extends WidgetComponent implements OnInit {
minTermLength: number = 1; minTermLength: number = 1;
groupId: string; groupId: string;
constructor(private formService: FormService) { constructor(private formService: FormService,
private elementRef: ElementRef) {
super(); super();
} }
@ -108,4 +109,19 @@ export class FunctionalGroupWidget extends WidgetComponent implements OnInit {
event.preventDefault(); event.preventDefault();
} }
} }
setupMaterialComponents(handler: any): boolean {
// workaround for MDL issues with dynamic components
if (handler) {
handler.upgradeAllRegistered();
if (this.elementRef && this.value) {
let container = this.elementRef.nativeElement.querySelector('.mdl-textfield');
if (container) {
container.MaterialTextfield.change(this.value);
}
}
return true;
}
return false;
}
} }

View File

@ -15,11 +15,10 @@
* limitations under the License. * limitations under the License.
*/ */
import { Component } from '@angular/core'; import { Component, ElementRef } from '@angular/core';
import { WidgetComponent } from './../widget.component'; import { WidgetComponent } from './../widget.component';
declare let __moduleName: string; declare let __moduleName: string;
declare var componentHandler;
@Component({ @Component({
moduleId: __moduleName, moduleId: __moduleName,
@ -29,4 +28,25 @@ declare var componentHandler;
}) })
export class MultilineTextWidget extends WidgetComponent { export class MultilineTextWidget extends WidgetComponent {
constructor(private elementRef: ElementRef) {
super();
}
setupMaterialComponents(handler: any): boolean {
// workaround for MDL issues with dynamic components
if (handler) {
handler.upgradeAllRegistered();
if (this.elementRef && this.hasValue()) {
let el = this.elementRef.nativeElement;
let container = el.querySelector('.mdl-textfield');
if (container) {
container.MaterialTextfield.change(this.field.value);
}
}
return true;
}
return false;
}
} }

View File

@ -15,11 +15,10 @@
* limitations under the License. * limitations under the License.
*/ */
import { Component } from '@angular/core'; import { Component, ElementRef } from '@angular/core';
import { WidgetComponent } from './../widget.component'; import { WidgetComponent } from './../widget.component';
declare let __moduleName: string; declare let __moduleName: string;
declare var componentHandler;
@Component({ @Component({
moduleId: __moduleName, moduleId: __moduleName,
@ -29,4 +28,22 @@ declare var componentHandler;
}) })
export class NumberWidget extends WidgetComponent { export class NumberWidget extends WidgetComponent {
constructor(private elementRef: ElementRef) {
super();
}
setupMaterialComponents(handler: any): boolean {
// workaround for MDL issues with dynamic components
if (handler) {
handler.upgradeAllRegistered();
if (this.elementRef && this.hasValue()) {
let container = this.elementRef.nativeElement.querySelector('.mdl-textfield');
if (container) {
container.MaterialTextfield.change(this.field.value.toString());
}
}
return true;
}
return false;
}
} }

View File

@ -29,7 +29,7 @@ describe('PeopleWidget', () => {
beforeEach(() => { beforeEach(() => {
formService = new FormService(null, null); formService = new FormService(null, null);
widget = new PeopleWidget(formService); widget = new PeopleWidget(formService, null);
widget.field = new FormFieldModel(new FormModel()); widget.field = new FormFieldModel(new FormModel());
}); });

View File

@ -15,7 +15,7 @@
* limitations under the License. * limitations under the License.
*/ */
import { Component, OnInit } from '@angular/core'; import { Component, OnInit, ElementRef } from '@angular/core';
import { WidgetComponent } from './../widget.component'; import { WidgetComponent } from './../widget.component';
import { FormService } from '../../../services/form.service'; import { FormService } from '../../../services/form.service';
import { GroupModel } from '../core/group.model'; import { GroupModel } from '../core/group.model';
@ -37,7 +37,8 @@ export class PeopleWidget extends WidgetComponent implements OnInit {
users: GroupUserModel[] = []; users: GroupUserModel[] = [];
groupId: string; groupId: string;
constructor(private formService: FormService) { constructor(private formService: FormService,
private elementRef: ElementRef) {
super(); super();
} }
@ -121,4 +122,19 @@ export class PeopleWidget extends WidgetComponent implements OnInit {
event.preventDefault(); event.preventDefault();
} }
} }
setupMaterialComponents(handler: any): boolean {
// workaround for MDL issues with dynamic components
if (handler) {
handler.upgradeAllRegistered();
if (this.elementRef && this.value) {
let container = this.elementRef.nativeElement.querySelector('.mdl-textfield');
if (container) {
container.MaterialTextfield.change(this.value);
}
}
return true;
}
return false;
}
} }

View File

@ -15,11 +15,10 @@
* limitations under the License. * limitations under the License.
*/ */
import { Component } from '@angular/core'; import { Component, ElementRef } from '@angular/core';
import { WidgetComponent } from './../widget.component'; import { WidgetComponent } from './../widget.component';
declare let __moduleName: string; declare let __moduleName: string;
declare var componentHandler;
@Component({ @Component({
moduleId: __moduleName, moduleId: __moduleName,
@ -29,4 +28,25 @@ declare var componentHandler;
}) })
export class TextWidget extends WidgetComponent { export class TextWidget extends WidgetComponent {
constructor(private elementRef: ElementRef) {
super();
}
setupMaterialComponents(componentHandler: any): boolean {
// workaround for MDL issues with dynamic components
if (componentHandler) {
componentHandler.upgradeAllRegistered();
if (this.elementRef && this.hasValue()) {
let el = this.elementRef.nativeElement;
let container = el.querySelector('.mdl-textfield');
if (container) {
container.MaterialTextfield.change(this.field.value);
}
}
return true;
}
return false;
}
} }

View File

@ -39,9 +39,7 @@ describe('WidgetComponent', () => {
it('should setup MDL content only if component handler available', () => { it('should setup MDL content only if component handler available', () => {
let component = new WidgetComponent(); let component = new WidgetComponent();
expect(component.setupMaterialComponents()).toBeTruthy(); expect(component.setupMaterialComponents(componentHandler)).toBeTruthy();
window['componentHandler'] = null;
expect(component.setupMaterialComponents()).toBeFalsy(); expect(component.setupMaterialComponents()).toBeFalsy();
}); });

View File

@ -43,15 +43,21 @@ export class WidgetComponent implements AfterViewInit {
return null; return null;
} }
hasValue(): boolean {
return this.field &&
this.field.value !== null &&
this.field.value !== undefined;
}
ngAfterViewInit() { ngAfterViewInit() {
this.setupMaterialComponents(); this.setupMaterialComponents(componentHandler);
this.fieldChanged.emit(this.field); this.fieldChanged.emit(this.field);
} }
setupMaterialComponents(): boolean { setupMaterialComponents(handler?: any): boolean {
// workaround for MDL issues with dynamic components // workaround for MDL issues with dynamic components
if (componentHandler) { if (handler) {
componentHandler.upgradeAllRegistered(); handler.upgradeAllRegistered();
return true; return true;
} }
return false; return false;

View File

@ -188,7 +188,7 @@ describe('ShareDataTableAdapter', () => {
}); });
it('should log error when having date conversion issues', () => { it('should log error when having date conversion issues', () => {
let dateValue = '[wrong-date]'; let dateValue = <Date> {};
let file = new FileNode(); let file = new FileNode();
file.entry.createdAt = <any> dateValue; file.entry.createdAt = <any> dateValue;