diff --git a/www/app.js b/www/app.js index eca5d4b..1e0f359 100644 --- a/www/app.js +++ b/www/app.js @@ -63,14 +63,16 @@ var angular = function(req, res) { res.render('angularIndex'); }; -app.get('/json/get/id/:tagName', fns.getTagID); // Gets the id for a tag name -app.get('/json/get/tagName/:tagID', fns.getTagName); // Gets the tagName for an ID -app.get('/json/add/:tagName/:units', fns.addTag); // Adds a tag to the scan list -app.get('/json/remove/:tag', fns.removeTag); // Removes a tag from the scan list -app.get('/json/val/:tag', fns.latestTagValue); // Gets the latest value of a single tag -app.get('/json/series/:tag/:hours', fns.seriesTagValues); // Gets all the values of a tag for the last X hours -app.get('/json/tags', fns.allTags); // Lists all tags in the scan list -app.get('/json/all', fns.allValues); // Gets the latest values of all tags in the scan list +app.get('/json/get/id/:tagName', fns.getTagID); // Gets the id for a tag name +app.get('/json/get/tagName/:tagID', fns.getTagName); // Gets the tagName for an ID +app.get('/json/tag/add/:tagName/:units', fns.createTag); // Adds a tag to the scan list +app.get('/json/tag/update/:id/:tagName/:units', fns.updateTag); // Updates tag data +app.get('/json/tag/delete/:tag', fns.deleteTag); // Removes a tag from the scan list +app.get('/json/tag/:id', fns.getTag); // Lists all tags in the scan list +app.get('/json/tag', fns.getAllTags); // Lists all tags in the scan list +app.get('/json/val/:tag', fns.latestTagValue); // Gets the latest value of a single tag +app.get('/json/series/:tag/:hours', fns.seriesTagValues); // Gets all the values of a tag for the last X hours +app.get('/json/all', fns.allValues); // Gets the latest values of all tags in the scan list app.get('*', angular); diff --git a/www/functions_SQLite.js b/www/functions_SQLite.js index d094d96..17bedc9 100644 --- a/www/functions_SQLite.js +++ b/www/functions_SQLite.js @@ -1,5 +1,5 @@ -// var dbFile = "/usr/db/data.db" -var dbFile = '/Users/patrickjmcd/data.db'; +var dbFile = "/usr/db/data.db" +// var dbFile = '/Users/patrickjmcd/data.db'; // app.get('/json/add/:tag', fns.addTag); // Adds a tag to the scan list // app.get('/json/remove/:tag', fns.removeTag); // Removes a tag from the scan list // app.get('/json/val/:tag', fns.latestTagValue); // Gets the latest value of a single tag @@ -70,7 +70,7 @@ exports.getTagName = function(req, res){ }) }; -exports.addTag = function(req, res){ +exports.createTag = function(req, res){ var sqlite3 = require('sqlite3').verbose(); var db = new sqlite3.Database(dbFile); @@ -90,13 +90,13 @@ exports.addTag = function(req, res){ }); }; -exports.removeTag = function(req, res){ +exports.deleteTag = function(req, res){ var sqlite3 = require('sqlite3').verbose(); var db = new sqlite3.Database(dbFile); db.serialize(function(){ var query = "UPDATE tags SET deleted = 1 WHERE id = ?"; - var preqQuery = db.prepare(query); + var prepQuery = db.prepare(query); prepQuery.run(req.params.tag, function(err) { prepQuery.finalize(); db.close(); @@ -110,6 +110,26 @@ exports.removeTag = function(req, res){ }); }; +exports.updateTag = function(req, res){ + var sqlite3 = require('sqlite3').verbose(); + var db = new sqlite3.Database(dbFile); + + db.serialize(function(){ + var query = "UPDATE tags set tagName = ?, units = ? WHERE id = ?"; + var prepQuery = db.prepare(query); + prepQuery.run(req.params.tagName, req.params.units, req.params.id, function(err) { + prepQuery.finalize(); + db.close(); + if (err) { + res.json({status:"error", message:err}); + console.log(err); + } else { + res.json({status:"OK"}); + } + }); + }); +}; + exports.latestTagValue = function(req, res){ var sqlite3 = require('sqlite3').verbose(); var db = new sqlite3.Database(dbFile); @@ -150,7 +170,7 @@ exports.seriesTagValues = function(req, res){ }); }; -exports.allTags = function(req, res){ +exports.getAllTags = function(req, res){ var sqlite3 = require('sqlite3').verbose(); var db = new sqlite3.Database(dbFile); @@ -170,6 +190,26 @@ exports.allTags = function(req, res){ }); }; +exports.getTag = function(req, res){ + var sqlite3 = require('sqlite3').verbose(); + var db = new sqlite3.Database(dbFile); + + db.serialize(function(){ + var query = "SELECT * FROM tags WHERE id = ?"; + var prepQuery = db.prepare(query); + prepQuery.all(req.params.id, function(err, rows) { + prepQuery.finalize(); + db.close(); + if (err) { + res.json({status:"error", message:err}); + console.log(err); + } else { + res.json({status:"OK", tags:rows}); + } + }); + }); +}; + exports.allValues = function(req, res){ res.json({status: "error", message: "not implemented"}); }; diff --git a/www/public/js/controller.js b/www/public/js/controller.js index 7b872f7..57db805 100644 --- a/www/public/js/controller.js +++ b/www/public/js/controller.js @@ -40,7 +40,7 @@ tsCtrlrs.factory('Alerts', function($log) { tsCtrlrs.factory('tags',function($q, $http, $log){ var getTagList = function() { var deferred = $q.defer(); - $http.get('http://localhost:3000/json/tags/').success(function(data) { + $http.get('/json/tag/').success(function(data) { if(data.status == "OK"){ deferred.resolve({ tags:data.tags, @@ -55,8 +55,28 @@ tsCtrlrs.factory('tags',function($q, $http, $log){ }); 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 + }); + } + }); + return deferred.promise; + }; + return { - getTagList: getTagList + getTagList: getTagList, + getTagHistory: getTagHistory }; }); @@ -74,6 +94,7 @@ tsCtrlrs.controller('tagsCtrl', function($scope, $route, $http, $routeParams, Pa $scope.loading = true; var getTagList = tags.getTagList(); getTagList.then(function(data) { + $scope.loading = false; if (data.status == "OK"){ $scope.tags = data.tags; $scope.error = false; @@ -83,3 +104,17 @@ tsCtrlrs.controller('tagsCtrl', function($scope, $route, $http, $routeParams, Pa } }); }); +tsCtrlrs.controller('tagValsCtrl', function($scope, $route, $http, $routeParams, Page, Alerts, $log, tags) { + $scope.loading = true; + var getTagHistory = tags.getTagHistory($routeParams.tagID); + getTagHistory.then(function(data) { + $scope.loading = false; + if (data.status == "OK"){ + $scope.vals = data.vals; + $scope.error = false; + } else { + $scope.tags = []; + $scope.error = data.message; + } + }); +}); diff --git a/www/public/js/router.js b/www/public/js/router.js index bb46e8d..84419c1 100644 --- a/www/public/js/router.js +++ b/www/public/js/router.js @@ -8,6 +8,9 @@ tagserver.config([ }).when('/tags', { templateUrl: '../../public/partials/tags.html', controller: 'tagsCtrl' + }).when('/tag/:tagID', { + templateUrl: '../../public/partials/tagVals.html', + controller: 'tagsValsCtrl' }); } ]); diff --git a/www/public/partials/tagVals.html b/www/public/partials/tagVals.html new file mode 100644 index 0000000..37f4708 --- /dev/null +++ b/www/public/partials/tagVals.html @@ -0,0 +1,10 @@ +
+
{{message}}
+
+ +
+
{{vals}}
+ +
\ No newline at end of file diff --git a/www/views/angularIndex.html b/www/views/angularIndex.html index f38eda8..11622b0 100644 --- a/www/views/angularIndex.html +++ b/www/views/angularIndex.html @@ -1,7 +1,7 @@ - POConsole: {{ Page.title() }} + TagServer: {{ Page.title() }}