...
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
angular.module('GreenhouseUIApp').service('QueryService', function ($http){ return{ discoverGreenhouseEndpoint : discoverGreenhouseEndpoint, getGreenhouses : getGreenhouses, getLanesForGreenhouse : getLanesForGreenhouse, getZonesForLane : getZonesForLane } function discoverGreenhouseEndpoint(){ // Find the project handle by the name of the project var findProjectQuery = "<query><find><project><projName eq='Greenhouse'/></project></find></query>"; return $http.post(TQLEngineManagerURL, findProjectQuery).then(function(response) { var x2js = new X2JS(); var jsonObj = x2js.xml_str2json(response.data); // Find project end points - http and ws var findProjectEndpointsQuery = "<GetProjectEndPoints><ProjectSysId>"+jsonObj.Find.Result.Project.SysId+"</ProjectSysId></GetProjectEndPoints>"; return $http.post(TQLEngineManagerURL, findProjectEndpointsQuery).then(function(response) { var x2js = new X2JS(); var endpointsJson = x2js.xml_str2json(response.data); return endpointsJson; }); }); } }); }); } // Given endpoint URL, find the project end points for communication function getGreenhouses(endpointURL){ var query = "<Query><Find><Greenhouse><GreenhouseID ne=''/></Greenhouse></Find></Query>"; return $http.post(endpointURL, query).then(function(response) { var x2js = new X2JS(); var jsonObj = x2js.xml_str2json(response.data); return jsonObj; }); } // Given greenhouse ID, get the array of lanes function getLanesForGreenhouse(GreenhouseID){ var query = "<Query><Find><Lane><GreenhouseID eq="+ GreenhouseID +"/></Lane></Find></Query>"; return $http.post(url, query).then(function(response) { var x2js = new X2JS(); var jsonObj = x2js.xml_str2json(response.data); return jsonObj; }); } // Given the Lane ID, get the array of zones function getZonesForLane(LaneID){ var query = "<Query><Find><Zone><LaneID eq="+LaneID+" /></Zone></Find></Query>"; return $http.post(url, query).then(function(response) { var x2js = new X2JS(); var jsonObj = x2js.xml_str2json(response.data); return jsonObj; }); } }); |
...