general improvements & fixes
This commit is contained in:
parent
ea2e3340fe
commit
7a11d3bb58
|
@ -33,7 +33,6 @@ export class DynamicFormComponent implements OnInit {
|
|||
this.form = this.qcs.toFormGroup(new Array(), new Array());
|
||||
}
|
||||
|
||||
|
||||
getSubForm(subformName) {
|
||||
return this.form.controls[subformName];
|
||||
}
|
||||
|
|
|
@ -33,7 +33,8 @@
|
|||
<div>{{field.description}}</div>
|
||||
|
||||
<input *ngSwitchCase="'textbox'" class="form-control" [formControlName]="field.key" [id]="field.key" [type]="field.type"
|
||||
[(ngModel)]="field.value" [required]="field.required" [pattern] = "field.regex" (blur) = "toggleVisibility($event, field)">
|
||||
[(ngModel)]="field.value" [required]="field.required" [pattern] = "field.regex" (ngModelChange) = "toggleVisibility($event, field)"> <!--input or change event
|
||||
on change event the listener is triggered on blur -->
|
||||
|
||||
<select *ngSwitchCase="'dropdown'" class="form-control" [id]="field.key" [formControlName]="field.key" [(ngModel)]="field.value" [required]="field.required">
|
||||
<option *ngFor="let opt of field.options" [value]="opt.key">{{opt.value}}</option>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { DataModel } from '../../entities/DataModel';
|
||||
import { Component, Input, OnInit } from '@angular/core';
|
||||
import { FormGroup, ValidatorFn, AbstractControl, Validators } from '@angular/forms';
|
||||
import { ActivatedRoute} from '@angular/router';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
|
||||
import { FieldBase } from './field-base';
|
||||
import { GroupBase } from '../../form/dynamic-form-group/group-base';
|
||||
|
@ -21,7 +21,11 @@ export class DynamicFormFieldComponent {
|
|||
|
||||
private fragment: string;
|
||||
|
||||
constructor (private route: ActivatedRoute){}
|
||||
constructor(private route: ActivatedRoute) { }
|
||||
|
||||
ngOnChanges(changeRecord) {
|
||||
}
|
||||
|
||||
|
||||
get isValid() {
|
||||
return this.form.controls[this.field.key].valid;
|
||||
|
@ -65,73 +69,72 @@ export class DynamicFormFieldComponent {
|
|||
return true;
|
||||
}
|
||||
FieldValueRuleMethod(field, rule) { //fieldValue rule -- checks the value of target and apply rules, at the same time when the field becomes visible
|
||||
if (rule._ruleStyle == "range") { //calling the AddvalidationRules we apply the validation rules for the new field
|
||||
var targetField = this.dataModel.getFieldByKey(rule._target);
|
||||
if (parseInt(rule._from) < parseInt(field.value) && parseInt(field.value)< parseInt(rule._to)) {
|
||||
var targetField = this.dataModel.getFieldByKey(rule._target); //calling the AddvalidationRules we apply the validation rules for the new field
|
||||
if (rule._ruleStyle == "range") {
|
||||
if (parseInt(rule._from) < parseInt(field.value) && parseInt(field.value) < parseInt(rule._to)) {
|
||||
console.log("visible" + field.value)
|
||||
targetField.visible = true;
|
||||
this.AddvalidationRules(rule._target);
|
||||
}else{
|
||||
targetField.visible = false;
|
||||
this.form.controls[rule._target].clearValidators(); // when a field is hidden must clear the validators and the errors
|
||||
this.form.controls[rule._target].updateValueAndValidity();
|
||||
} else {
|
||||
this.hideField(targetField, rule);
|
||||
}
|
||||
|
||||
}
|
||||
if (rule._ruleStyle == "boolean") { //boolean Decision field
|
||||
let ruleValue = rule.value.__text;
|
||||
if (field.value.value.toString() == ruleValue) {
|
||||
this.dataModel.getFieldByKey(rule._target).visible = true;
|
||||
targetField.visible = true;
|
||||
this.AddvalidationRules(rule._target);
|
||||
} else {
|
||||
this.dataModel.getFieldByKey(rule._target).visible = false;
|
||||
this.form.controls[rule._target].clearValidators(); // when a field is hidden must clear the validators and the errors
|
||||
this.form.controls[rule._target].updateValueAndValidity();
|
||||
this.hideField(targetField, rule);
|
||||
}
|
||||
}
|
||||
if (rule._ruleStyle == "checked") { //checkbox field
|
||||
if (field.value == true) {
|
||||
this.dataModel.getFieldByKey(rule._target).visible = true;
|
||||
targetField.visible = true;
|
||||
this.AddvalidationRules(rule._target);
|
||||
} else {
|
||||
this.dataModel.getFieldByKey(rule._target).visible = false;
|
||||
this.form.controls[rule._target].clearValidators();
|
||||
this.form.controls[rule._target].updateValueAndValidity();
|
||||
this.hideField(targetField, rule);
|
||||
}
|
||||
}
|
||||
if (rule._ruleStyle == "existence") {
|
||||
if (field.visible == "true" || field.visible == true) {
|
||||
this.dataModel.getFieldByKey(rule._target).visible = true;
|
||||
targetField.visible = true;
|
||||
this.AddvalidationRules(rule._target);
|
||||
} else {
|
||||
this.dataModel.getFieldByKey(rule._target).visible = false;
|
||||
this.form.controls[rule._target].clearValidators();
|
||||
this.form.controls[rule._target].updateValueAndValidity();
|
||||
this.hideField(targetField, rule);
|
||||
}
|
||||
}
|
||||
if (rule._ruleStyle == "regex") {
|
||||
if (new RegExp(rule.__cdata).test(field.value)) {
|
||||
this.dataModel.getFieldByKey(rule._target).visible = true;
|
||||
targetField.visible = true;
|
||||
this.AddvalidationRules(rule._target);
|
||||
} else {
|
||||
this.dataModel.getFieldByKey(rule._target).visible = false;
|
||||
this.form.controls[rule._target].clearValidators();
|
||||
this.hideField(targetField, rule);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
hideField(targetField, rule) {
|
||||
targetField.visible = false;
|
||||
targetField.value = ' ';
|
||||
if (this.form.controls[rule._target].hasError("pattern"))
|
||||
this.form.controls[rule._target].reset(); //the regex error message didn't remove without field reset
|
||||
this.form.controls[rule._target].clearValidators(); // when a field is hidden must clear the validators and the errors
|
||||
this.form.controls[rule._target].updateValueAndValidity();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
toggleVisibility(e, field, ckb) { //ckb the checkbox only send this parameter, it's essential to change the field value
|
||||
if (ckb)
|
||||
field.value = ckb.checked;
|
||||
if(field.rules.length != undefined && field.rules.length > 1)
|
||||
if (field.rules.length != undefined && field.rules.length > 1)
|
||||
field.rules.forEach(rule => {
|
||||
if (rule._type == "fieldValue") {
|
||||
this.FieldValueRuleMethod(field, rule);
|
||||
}
|
||||
});
|
||||
else if(field.rules._type == "fieldValue"){
|
||||
this.FieldValueRuleMethod(field,field.rules);
|
||||
else if (field.rules._type == "fieldValue") {
|
||||
this.FieldValueRuleMethod(field, field.rules);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -139,15 +142,15 @@ export class DynamicFormFieldComponent {
|
|||
if (this.dataModel.getFieldByKey(field).attributes.validation != undefined) {
|
||||
let arrayVal = new Array();
|
||||
this.dataModel.getFieldByKey(field).attributes.validation.forEach(rule => {
|
||||
if (rule.ruleStyle.toString() == RuleStyle[RuleStyle.existence]){
|
||||
if (rule.ruleStyle.toString() == RuleStyle[RuleStyle.existence]) {
|
||||
this.dataModel.getFieldByKey(field).required = true;
|
||||
arrayVal.push(Validators.required);
|
||||
}
|
||||
if (rule.ruleStyle.toString() == RuleStyle[RuleStyle.regex]){
|
||||
if (rule.ruleStyle.toString() == RuleStyle[RuleStyle.regex]) {
|
||||
this.dataModel.getFieldByKey(field).regex = rule.regex;
|
||||
arrayVal.push(Validators.pattern(rule.regex));
|
||||
}
|
||||
if (rule.ruleStyle.toString() == RuleStyle[RuleStyle.customValidation]){
|
||||
if (rule.ruleStyle.toString() == RuleStyle[RuleStyle.customValidation]) {
|
||||
arrayVal.push(this.forbiddenNameValidator(/nothing/i));
|
||||
}
|
||||
|
||||
|
@ -165,4 +168,6 @@ export class DynamicFormFieldComponent {
|
|||
return forbidden ? { 'forbiddenName': { value: control.value } } : null;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -9,6 +9,7 @@ import { Router, ActivatedRoute } from '@angular/router';
|
|||
})
|
||||
export class LoginComponent implements OnInit{
|
||||
returnUrl: string;
|
||||
public static token : string;
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
|
@ -26,15 +27,17 @@ export class LoginComponent implements OnInit{
|
|||
}
|
||||
private myClientId: string = '524432312250-vhgidft856v8qftsc81kls4c74v87d8o.apps.googleusercontent.com';
|
||||
|
||||
onGoogleSignInSuccess(event: GoogleSignInSuccess) { debugger;
|
||||
onGoogleSignInSuccess(event: GoogleSignInSuccess) {
|
||||
let googleUser: gapi.auth2.GoogleUser = event.googleUser;
|
||||
let id: string = googleUser.getId();
|
||||
let profile: gapi.auth2.BasicProfile = googleUser.getBasicProfile();
|
||||
console.log('ID: ' +
|
||||
profile
|
||||
.getId()); // Do not send to your backend! Use an ID token instead.
|
||||
LoginComponent.token = googleUser.getAuthResponse().id_token;
|
||||
console.log('ID: ' + profile.getId()); // Do not send to your backend! Use an ID token instead.
|
||||
console.log('Name: ' + profile.getName());
|
||||
console.log('token: ' + LoginComponent.token);
|
||||
localStorage.setItem('currentUser', JSON.stringify(googleUser));
|
||||
var currentUser = JSON.parse(localStorage.getItem('currentUser'));
|
||||
console.log('current user local storage:' +currentUser)
|
||||
//this.router.navigateByUrl('dynamic-form');
|
||||
this.ngZone.run(() => this.router.navigateByUrl('projects'));
|
||||
//this.router.navigate(['/projects']);
|
||||
|
|
|
@ -26,7 +26,6 @@ export class ProjectDetailComponent implements OnInit {
|
|||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
debugger;
|
||||
// this.hero$ = this.route.paramMap
|
||||
// .switchMap((params: ParamMap) =>
|
||||
// this.service.getHero(params.get('id')));
|
||||
|
|
|
@ -34,7 +34,7 @@ export class ProjectsComponent implements OnInit{
|
|||
|
||||
}
|
||||
|
||||
ngOnInit() {debugger;
|
||||
ngOnInit() {
|
||||
this.projects = this.serverService.getDummyProjects()
|
||||
}
|
||||
|
||||
|
|
|
@ -262,7 +262,7 @@ export class dataModelBuilder {
|
|||
if (attr.validation.rule._ruleStyle == "customValidation"){
|
||||
rule.method= attr.validation.rule._method;
|
||||
functions.forEach(fnc => {
|
||||
if(fnc._id == rule.method) debugger;
|
||||
if(fnc._id == rule.method)
|
||||
rule.methodJs = fnc.__cdata;
|
||||
});
|
||||
|
||||
|
@ -272,7 +272,6 @@ export class dataModelBuilder {
|
|||
}
|
||||
}
|
||||
|
||||
console.log(newAttribute);
|
||||
attribute.push(newAttribute);
|
||||
fields.find(x => x.key == newAttribute.id).attributes.sources = newAttribute.sources;
|
||||
fields.find(x => x.key == newAttribute.id).attributes.validation = newAttribute.validation;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import {Injectable, ReflectiveInjector, Injector} from '@angular/core';
|
||||
import {Headers, Http, Response} from '@angular/http';
|
||||
import { HttpClient , HttpHeaders, HttpParams} from '@angular/common/http';
|
||||
import 'rxjs/Rx';
|
||||
import {FieldBase} from '../../app/form/fields/field-base';
|
||||
import {JsonObjest} from '../../app/entities/JsonObject.class';
|
||||
|
@ -7,7 +8,7 @@ import {dataModelBuilder} from '../../app/services/dataModelBuilder.service';
|
|||
import { DatasetProfile } from '../entities/datasetprofile';
|
||||
import {DataModel} from '../entities/DataModel';
|
||||
import {Project} from '../entities/model/project';
|
||||
|
||||
import {LoginComponent} from '../../app/login/login-page';
|
||||
|
||||
import './../../assets/xml2json.min.js';
|
||||
|
||||
|
@ -20,7 +21,8 @@ export class ServerService {
|
|||
//fetchURL: string = 'http://dl010.madgik.di.uoa.gr:8080/dmp-backend/rest/DMP/a868dbbb-ee37-4ce6-81c8-27048e0599a9';
|
||||
//fetchURL: string = 'http://dl010.madgik.di.uoa.gr:8080/dmp-backend/rest/DMP/a71a6a92-5c23-40d7-ab87-e30bc860f5a4';//include rules!
|
||||
//fetchURL: string = 'http://dl010.madgik.di.uoa.gr:8080/dmp-backend/rest/DMP/d597c26e-3d8b-416a-bc07-1734d68c79c9';//include sections! + 3groupfields
|
||||
fetchURL: string = 'http://dl010.madgik.di.uoa.gr:8080/dmp-backend/rest/DMP/9a4a4a57-4d01-465e-9887-254534f31600';
|
||||
//fetchURL: string = 'http://dl010.madgik.di.uoa.gr:8080/dmp-backend/rest/dmps/9a4a4a57-4d01-465e-9887-254534f31600'; με το security
|
||||
fetchURL: string = 'http://dl010.madgik.di.uoa.gr:8080/dmp-backend-no-sec/rest/dmps/9a4a4a57-4d01-465e-9887-254534f31600';
|
||||
//fetchURL: string = 'http://dl010.madgik.di.uoa.gr:8080/dmp-backend/rest/DMP/6c845c42-dc09-42ed-9959-cceb3b616364';
|
||||
|
||||
/*
|
||||
|
@ -31,7 +33,7 @@ export class ServerService {
|
|||
|
||||
data: any;
|
||||
|
||||
constructor(private http: Http) {
|
||||
constructor(private http: Http) { //private http: Http
|
||||
this.xml2jsonOBJ = new X2JS();
|
||||
}
|
||||
|
||||
|
@ -41,6 +43,8 @@ export class ServerService {
|
|||
if(this.data != null)
|
||||
return this.data; //use the already loaded one
|
||||
|
||||
//let headers = new HttpHeaders();
|
||||
let headers = new HttpHeaders().set("google-token", LoginComponent.token);
|
||||
|
||||
return this.http.get(this.fetchURL)
|
||||
.map(
|
||||
|
@ -61,34 +65,6 @@ export class ServerService {
|
|||
|
||||
}
|
||||
|
||||
|
||||
|
||||
getFields() {
|
||||
|
||||
|
||||
//return this.http.get('http://dl010.madgik.di.uoa.gr:8080/dmp-backend/rest/DMP/6c845c42-dc09-42ed-9959-cceb3b616364')
|
||||
return this.http.get('http://dl010.madgik.di.uoa.gr:8080/dmp-backend/rest/DMP/a868dbbb-ee37-4ce6-81c8-27048e0599a9')
|
||||
.map(
|
||||
(response: Response) => {
|
||||
const data = response.json();
|
||||
let obj: JsonObjest = new JsonObjest();
|
||||
|
||||
//let test = new FieldBase(data);
|
||||
|
||||
//replace the xmls {model,view,rule} definitions with json -- https://github.com/abdmob/x2js library
|
||||
data.dataset.profile.definition = this.xml2jsonOBJ.xml_str2json(data.dataset.profile.definition);
|
||||
data.dataset.profile.ruleset.definition = this.xml2jsonOBJ.xml_str2json(data.dataset.profile.ruleset.definition);
|
||||
data.dataset.profile.viewstyle.definition = this.xml2jsonOBJ.xml_str2json(data.dataset.profile.viewstyle.definition);
|
||||
//can be converted back to xml (which shouldn't be needed) with this.xml2jsonOBJ.json2xml_str
|
||||
obj.fields = data.dataset.profile.viewstyle.definition.root.fields.field;
|
||||
|
||||
console.log("obj.fields");
|
||||
console.log(obj.fields);
|
||||
|
||||
return obj.fields; //return data;
|
||||
}
|
||||
);
|
||||
}
|
||||
getDummyProjects(){
|
||||
let projects :Project[] =[];
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
</head>
|
||||
<body>
|
||||
<script>
|
||||
function signOut() {debugger;
|
||||
function signOut() {
|
||||
var auth2 = gapi.auth2.getAuthInstance();
|
||||
auth2.signOut().then(function () {
|
||||
console.log('User signed out.');
|
||||
|
|
Loading…
Reference in New Issue