From 1e5bf85b8783c90f2fd288830542c4179f2cab9a Mon Sep 17 00:00:00 2001 From: Patrick McDonagh Date: Wed, 27 Apr 2016 22:11:33 -0500 Subject: [PATCH] Can see tags and values now --- .../api/controllers/Tag_valController.js | 10 +- tagserverApp/assets/js/controller.js | 216 +++++------------- tagserverApp/assets/templates/tags.html | 8 +- tagserverApp/config/routes.js | 4 +- 4 files changed, 77 insertions(+), 161 deletions(-) diff --git a/tagserverApp/api/controllers/Tag_valController.js b/tagserverApp/api/controllers/Tag_valController.js index 860767c..4b119c4 100644 --- a/tagserverApp/api/controllers/Tag_valController.js +++ b/tagserverApp/api/controllers/Tag_valController.js @@ -6,6 +6,12 @@ */ module.exports = { - + latest: function(req, res){ + var query = "SELECT v1.id as id, v1.createdAt as dtime, t.id as t_id, t.name as name, t.tag as tag, v1.val as val, t.units as units, t.description as description, t.minExpected as minExpected, t.maxExpected as maxExpected FROM tag_vals v1 LEFT JOIN tags t ON t.id = v1.tagID WHERE v1.id = (SELECT v2.id FROM tag_vals v2 WHERE v2.tagID = v1.tagID ORDER BY v2.id DESC LIMIT 1)"; + console.log(query); + Tag_val.query(query, function(err, results){ + if (err) return res.serverError(err); + return res.ok(results); + }); + } }; - diff --git a/tagserverApp/assets/js/controller.js b/tagserverApp/assets/js/controller.js index 582a68b..ac2f4a2 100644 --- a/tagserverApp/assets/js/controller.js +++ b/tagserverApp/assets/js/controller.js @@ -103,92 +103,41 @@ tsCtrlrs.factory('Alerts', function($log) { tsCtrlrs.factory('tags',function($q, $http, $log){ var getTag = function(id) { var deferred = $q.defer(); - $http.get('/json/tag/' + id).success(function(data) { - if(data.status == "OK"){ - deferred.resolve({ - tag:data.tags[0], - status: data.status - }); - } else { - deferred.resolve({ - status:data.status, - message: data.message - }); - } + $http.get('/tag/' + id).success(function(data) { + deferred.resolve({ + tag:data + }); }); return deferred.promise; }; var getTagList = function() { var deferred = $q.defer(); - $http.get('/json/tag/').success(function(data) { - if(data.status == "OK"){ - deferred.resolve({ - tags:data.tags, - status: data.status - }); - } else { - deferred.resolve({ - status:data.status, - message: data.message - }); - } - }); - return deferred.promise; - }; - - var getTagHistory = function(id){ - var deferred = $q.defer(); - $http.get('/json/series/'+ id + "/24").success(function(data) { - if(data.status == "OK"){ - deferred.resolve({ - vals:data.vals, - status: data.status - }); - } else { - deferred.resolve({ - status:data.status, - message: data.message - }); - } + $http.get('/tag/').success(function(data) { + deferred.resolve({ + tags:data + }); }); return deferred.promise; }; var getTagHistoryBetween = function(id, start, end){ var deferred = $q.defer(); - var url = '/json/valBetween/'+ id + "/" + date_to_dString(start) + "/" + date_to_dString(end); - $log.info("getting value for: " + url); - $http.get(url).success(function(data) { - if(data.status == "OK"){ - deferred.resolve({ - vals:data.vals, - status: data.status - }); - } else { - deferred.resolve({ - status:data.status, - message: data.message - }); - } + var w = {'where':{'tagID': id, 'createdAt': {">=":0, "<=":end}}}; + $http.get("/tag_val", {params:w}).success(function(data) { + deferred.resolve({ + vals:data + }); }); return deferred.promise; }; var getCurrentValues = function(){ var deferred = $q.defer(); - $http.get('/json/all').success(function(data) { - if(data.status == "OK"){ - deferred.resolve({ - vals:data.vals, - status: data.status - }); - } else { - deferred.resolve({ - status:data.status, - message: data.message - }); - } + $http.get('/tag_val/latest').success(function(data) { + deferred.resolve({ + vals:data + }); }); return deferred.promise; }; @@ -265,7 +214,6 @@ tsCtrlrs.factory('tags',function($q, $http, $log){ return { getTag: getTag, getTagList: getTagList, - getTagHistory: getTagHistory, getTagHistoryBetween: getTagHistoryBetween, getCurrentValues: getCurrentValues, createTag: createTag, @@ -365,12 +313,7 @@ tsCtrlrs.controller('dashboardCtrl', function($scope, $route, $http, $routeParam var getCurrentValues = tags.getCurrentValues(); getCurrentValues.then(function(data) { $scope.loading = false; - if (data.status == "OK"){ - $scope.vals = data.vals; - $scope.error = false; - } else { - $scope.error = data.message; - } + $scope.vals = data.vals; }); }; $scope.loadDashboard(); @@ -384,12 +327,7 @@ tsCtrlrs.controller('tagsCtrl', function($scope, $route, $http, $routeParams, Pa var getTagList = tags.getTagList(); getTagList.then(function(data) { $scope.loading = false; - if (data.status == "OK"){ - $scope.tags = data.tags; - $scope.error = false; - } else { - $scope.error = data.message; - } + $scope.tags = data.tags; }); }; $scope.loadTagList(); @@ -403,13 +341,9 @@ tsCtrlrs.controller('tagsCtrl', function($scope, $route, $http, $routeParams, Pa $scope.openDeleteTag = function(id){ var getTag = tags.getTag(id); getTag.then(function(data){ - if (data.status == "OK"){ - $scope.error = false; - $scope.dTag = data.tag; - $log.info("Thinking about deleting tag with parameters: "+ JSON.stringify($scope.dTag)); - } else { - $scope.error = data.message; - } + $scope.error = false; + $scope.dTag = data.tag; + $log.info("Thinking about deleting tag with parameters: "+ JSON.stringify($scope.dTag)); }); }; @@ -417,25 +351,17 @@ tsCtrlrs.controller('tagsCtrl', function($scope, $route, $http, $routeParams, Pa var deleteTag = tags.deleteTag(id); deleteTag.then(function(data){ $log.info("deleting tag "+ id + " status: " + data.status); - if (data.status == "OK"){ - $scope.error = false; - $scope.loadTagList(); - } else { - $scope.error = data.message; - } + $scope.error = false; + $scope.loadTagList(); }); }; $scope.openClearTagData = function(id){ var getTag = tags.getTag(id); getTag.then(function(data){ - if (data.status == "OK"){ - $scope.error = false; - $scope.dTagValues = data.tag; - $log.info("Thinking about deleting tag data with parameters: "+ JSON.stringify($scope.dTagValues)); - } else { - $scope.error = data.message; - } + $scope.error = false; + $scope.dTagValues = data.tag; + $log.info("Thinking about deleting tag data with parameters: "+ JSON.stringify($scope.dTagValues)); }); }; @@ -443,25 +369,17 @@ tsCtrlrs.controller('tagsCtrl', function($scope, $route, $http, $routeParams, Pa var clearSingleTagData = tags.clearSingleTagData(id); clearSingleTagData.then(function(data){ $log.info("deleting tag "+ id + " status: " + data.status); - if (data.status == "OK"){ - $scope.error = false; - $scope.loadTagList(); - } else { - $scope.error = data.message; - } + $scope.error = false; + $scope.loadTagList(); }); }; $scope.openEditTag = function(id){ var getTag = tags.getTag(id); getTag.then(function(data){ - if (data.status == "OK"){ - $scope.error = false; - $scope.editTag = data.tag; - $log.info("Started editing tag with parameters: "+ JSON.stringify($scope.editTag)); - } else { - $scope.error = data.message; - } + $scope.error = false; + $scope.editTag = data.tag; + $log.info("Started editing tag with parameters: "+ JSON.stringify($scope.editTag)); }); }; @@ -495,46 +413,38 @@ tsCtrlrs.controller('tagValsCtrl', function($scope, $route, $http, $routeParams, $scope.loading = true; var getTag = tags.getTag($routeParams.tagID); getTag.then(function(tagData){ - if (tagData.status == "OK"){ - $scope.tag = tagData.tag; - Page.setTitle('Tag Series: '+ tagData.tag.tagName); - var getTagHistoryBetween = tags.getTagHistoryBetween($routeParams.tagID, sDTime, eDTime); - getTagHistoryBetween.then(function(data) { - $scope.loading = false; - if (data.status == "OK"){ - $scope.data = data; - $scope.data.vals = $scope.data.vals.map(function(x){ - return {id: x.id, tagID: x.tagID, val: x.val, dtime: new Date(x.dtime)}; - }); - $scope.error = false; + $scope.tag = tagData.tag; + Page.setTitle('Tag Series: '+ tagData.tag.tagName); + var getTagHistoryBetween = tags.getTagHistoryBetween($routeParams.tagID, sDTime, eDTime); + getTagHistoryBetween.then(function(data) { + $log.info(data); + $scope.loading = false; + $scope.data = data; + $scope.data.vals = $scope.data.vals.map(function(x){ + return {id: x.id, tagID: x.tagID, val: x.val, dtime: new Date(x.createdAt)}; + }); + $scope.error = false; - $scope.options = { - series: [ - { - axis: "y", - dataset: "vals", - key: "val", - label: "Tag Value", - color: "#1f77b4", - type: ['line'], - id: 'tagChart' - } - ], - axes: { - x: { - key: "dtime", - type: "date" - } - } - }; - } else { - $scope.error = data.message; - } - }); - } else { - $scope.loading = false; - $scope.error = data.message; - } + $scope.options = { + series: [ + { + axis: "y", + dataset: "vals", + key: "val", + label: "Tag Value", + color: "#1f77b4", + type: ['line'], + id: 'tagChart' + } + ], + axes: { + x: { + key: "dtime", + type: "date" + } + } + }; + }); }); }; $scope.loadTagVals($scope.startDatetime, $scope.endDatetime); diff --git a/tagserverApp/assets/templates/tags.html b/tagserverApp/assets/templates/tags.html index 296c221..9342dbe 100644 --- a/tagserverApp/assets/templates/tags.html +++ b/tagserverApp/assets/templates/tags.html @@ -93,10 +93,10 @@
- + + +
diff --git a/tagserverApp/config/routes.js b/tagserverApp/config/routes.js index 5d769d3..e008776 100644 --- a/tagserverApp/config/routes.js +++ b/tagserverApp/config/routes.js @@ -34,7 +34,7 @@ module.exports.routes = { '/': { view: 'homepage' - } +}, /*************************************************************************** * * @@ -45,5 +45,5 @@ module.exports.routes = { * for configuration options and examples. * * * ***************************************************************************/ - + "/tag_val/latest": "Tag_valController.latest" };