import {Injectable, ReflectiveInjector, Injector} from '@angular/core'; import {Headers, Http, Response} from '@angular/http'; import 'rxjs/Rx'; import {FieldBase} from '../../app/form/fields/field-base'; import {JsonObjest} from '../../app/entities/JsonObject.class'; import {FieldVisibility} from '../../app/services/fieldVisibility.service'; import {dataModelBuilder} from '../../app/services/dataModelBuilder.service'; import { DatasetProfile } from '../entities/datasetprofile'; import {DataModel} from '../entities/DataModel' import './../../assets/xml2json.min.js'; declare var X2JS: any; @Injectable() export class ServerService { xml2jsonOBJ: any; //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/6c845c42-dc09-42ed-9959-cceb3b616364'; /* //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'; //fetchURL: string = 'http://dl010.madgik.di.uoa.gr:8080/dmp-backend/rest/DMP/6c845c42-dc09-42ed-9959-cceb3b616364'; */ data: any; constructor(private http: Http) { this.xml2jsonOBJ = new X2JS(); } getData() { if(this.data != null) return this.data; //use the already loaded one return this.http.get(this.fetchURL) .map( (response: Response) => { const data = response.json(); //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 this.data = data; //cache it for subsequent calls return data; } ); } 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; } ); } }