1
0
mirror of https://github.com/mgerb/mywebsite synced 2026-01-11 18:32:50 +00:00

adding api functionality to sensor information page

This commit is contained in:
2016-05-18 04:03:42 -05:00
parent b6d5854250
commit b3da7be0b8
3 changed files with 95 additions and 20 deletions

View File

@@ -68,19 +68,93 @@ app.controller('IndexController', function($scope, $http) {
});
app.controller('SensorInfoController', function($scope, $route, $routeParams) {
app.controller('SensorsController', function($scope, $http) {
$http({
method: 'GET',
url: '/api/allsensors'
}).then(function successCallback(response) {
// this callback will be called asynchronously
// when the response is available
$scope.information = response.data;
for (i in $scope.information) {
var date = new Date($scope.information[i].updated);
var options = { month: 'numeric', day: 'numeric', year: 'numeric', hour: 'numeric', minute: 'numeric', hour12: true };
$scope.information[i].date = date.toLocaleString('en-US', options);
if ((Date.now() - date) < 120000) {
$scope.information[i].status = "Connected";
$scope.information[i].css = "colorGreen";
} else {
$scope.information[i].status = "Disconnected";
$scope.information[i].css = "colorRed";
}
}
}, function errorCallback(response) {
// called asynchronously if an error occurs
// or server returns response with an error status.
});
});
app.controller('SensorInfoController', function($scope, $http, $routeParams) {
$scope.location = $routeParams.location;
});
$http({
method: 'GET',
url: '/api/sensor/' + $scope.location
}).then(function successCallback(response) {
// this callback will be called asynchronously
// when the response is available
app.controller('SensorsController', function($scope) {
$scope.information = response.data;
$scope.message = 'This is Show orders screen';
var list = [];
for (i in $scope.information) {
var exists = false,
index = 0;
for (j in list) {
if ($scope.information[i].year == list[j].year) {
exists = true;
index = j;
break;
}
}
if (exists == true) {
if (list[index].months.indexOf($scope.information[i].month) < 0) {
list[index].months.push($scope.information[i].month);
}
} else {
//console.log("pusing" + $scope.information[i].year);
list.push({ year: $scope.information[i].year, months: [$scope.information[i].month] });
}
}
console.log(JSON.stringify(list));
}, function errorCallback(response) {
// called asynchronously if an error occurs
// or server returns response with an error status.
});
});
//handle each post page after individual posts are selected
app.controller('PostController', function($scope, $route, $routeParams) {