203 lines
4.9 KiB
JavaScript
203 lines
4.9 KiB
JavaScript
var tsCtrlrs = angular.module('tsCtrlrs', ['ngJustGage', 'n3-line-chart']);
|
|
|
|
tsCtrlrs.factory('Page', function($log) {
|
|
var title = 'default';
|
|
var page = 'default';
|
|
return {
|
|
title: function() {
|
|
return title;
|
|
},
|
|
setTitle: function(newTitle) {
|
|
title = newTitle;
|
|
},
|
|
page: function() {
|
|
return page;
|
|
},
|
|
setPage: function(newPage) {
|
|
page = newPage;
|
|
}
|
|
};
|
|
});
|
|
|
|
tsCtrlrs.factory('Alerts', function($log) {
|
|
var alerts = [];
|
|
return {
|
|
add: function(alt) {
|
|
alerts.push(alt);
|
|
},
|
|
remove: function(indx) {
|
|
alerts.splice(indx, 1);
|
|
},
|
|
clear: function() {
|
|
alerts = [];
|
|
},
|
|
get: function() {
|
|
return alerts;
|
|
}
|
|
};
|
|
});
|
|
|
|
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
|
|
});
|
|
}
|
|
});
|
|
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
|
|
});
|
|
}
|
|
});
|
|
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
|
|
});
|
|
}
|
|
});
|
|
return deferred.promise;
|
|
}
|
|
|
|
return {
|
|
getTag: getTag,
|
|
getTagList: getTagList,
|
|
getTagHistory: getTagHistory,
|
|
getCurrentValues: getCurrentValues
|
|
};
|
|
});
|
|
|
|
tsCtrlrs.controller('mainCtrl', function($scope, Page, Alerts) {
|
|
$scope.Page = Page;
|
|
$scope.Alerts = Alerts;
|
|
});
|
|
|
|
tsCtrlrs.controller('dashboardCtrl', function($scope, $route, $http, $routeParams, Page, Alerts, $log, tags) {
|
|
Page.setTitle('Dashboard');
|
|
Page.setPage('dashboard');
|
|
$scope.loading = true;
|
|
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;
|
|
}
|
|
});
|
|
});
|
|
|
|
tsCtrlrs.controller('tagsCtrl', function($scope, $route, $http, $routeParams, Page, Alerts, $log, tags) {
|
|
Page.setTitle('Tags');
|
|
Page.setPage('tags');
|
|
$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;
|
|
} else {
|
|
$scope.error = data.message;
|
|
}
|
|
});
|
|
});
|
|
|
|
tsCtrlrs.controller('tagValsCtrl', function($scope, $route, $http, $routeParams, Page, Alerts, $log, tags) {
|
|
Page.setTitle('Tag Series');
|
|
Page.setPage('tags');
|
|
$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 getTagHistory = tags.getTagHistory($routeParams.tagID);
|
|
getTagHistory.then(function(data) {
|
|
$scope.loading = false;
|
|
if (data.status == "OK"){
|
|
$scope.data = data;
|
|
$scope.error = false;
|
|
|
|
$scope.options = {
|
|
series: [
|
|
{
|
|
axis: "y",
|
|
dataset: "vals",
|
|
key: "val",
|
|
label: "Tag Value",
|
|
color: "#1f77b4",
|
|
type: ['line'],
|
|
id: 'tagChart'
|
|
}
|
|
],
|
|
axes: {
|
|
x: {
|
|
key: "id",
|
|
// type: "date"
|
|
}
|
|
}
|
|
};
|
|
} else {
|
|
$scope.error = data.message;
|
|
}
|
|
});
|
|
} else {
|
|
$scope.loading = false;
|
|
$scope.error = data.message;
|
|
}
|
|
});
|
|
});
|