Re-implement existing website template (from PHP). Add all assets.
This commit is contained in:
parent
a87a334bc7
commit
ddf6c5b8ce
60 changed files with 2514 additions and 87 deletions
12
Website/wwwroot/js/controllers/gallery.js
Normal file
12
Website/wwwroot/js/controllers/gallery.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
angular.module("robware").controller('gallery', ["$scope", function($scope) {
|
||||
$scope.images=[];
|
||||
$scope.imageToShow=0;
|
||||
|
||||
$scope.showNextImage=function(){
|
||||
$scope.imageToShow=Math.min($scope.imageToShow+1, $scope.images.length-1);
|
||||
};
|
||||
|
||||
$scope.showPreviousImage=function(){
|
||||
$scope.imageToShow=Math.max($scope.imageToShow-1, 0);
|
||||
};
|
||||
}]);
|
77
Website/wwwroot/js/controllers/galleryManage.js
Normal file
77
Website/wwwroot/js/controllers/galleryManage.js
Normal file
|
@ -0,0 +1,77 @@
|
|||
angular.module("robware").controller('galleryManage', ["$scope", "$http", function($scope, $http) {
|
||||
$scope.albums=[];
|
||||
var albumActions={};
|
||||
|
||||
var moveIndex="Move selected to album";
|
||||
$scope.contextMenuActions={
|
||||
"Delete selected":deleteSelected
|
||||
};
|
||||
|
||||
function getSelectedImageIds(){
|
||||
var images=[];
|
||||
angular.forEach($scope.selectedAlbum.Images, function(image){
|
||||
if (image.selected)
|
||||
images.push(image.ImageId);
|
||||
});
|
||||
return images;
|
||||
}
|
||||
|
||||
function updateAlbums(data){
|
||||
var selectedId=$scope.selectedAlbum.AlbumId;
|
||||
$scope.albums=data;
|
||||
angular.forEach($scope.albums, function(album){
|
||||
if (album.AlbumId===selectedId)
|
||||
$scope.selectedAlbum=album;
|
||||
});
|
||||
}
|
||||
|
||||
function deleteSelected(){
|
||||
var images=getSelectedImageIds();
|
||||
if (images.length===0 || !confirm("Are you sure you want to delete?"))
|
||||
return;
|
||||
|
||||
var data={
|
||||
selectedImages:images
|
||||
};
|
||||
|
||||
$http.post("/gallery/deleteimages",data).then(function(response){
|
||||
updateAlbums(response.data);
|
||||
});
|
||||
};
|
||||
|
||||
function moveImages(newAlbum){
|
||||
var images=getSelectedImageIds();
|
||||
if (images.length===0)
|
||||
return;
|
||||
|
||||
var data={
|
||||
selectedImages:images,
|
||||
targetAlbumId:newAlbum.AlbumId
|
||||
};
|
||||
$http.post("/gallery/move",data).then(function(response){
|
||||
updateAlbums(response.data);
|
||||
});
|
||||
}
|
||||
|
||||
$scope.$watch("albums", function(){
|
||||
if ($scope.selectedAlbum===undefined)
|
||||
$scope.selectedAlbum=$scope.albums[0];
|
||||
|
||||
albumActions={};
|
||||
angular.forEach($scope.albums, function(album){
|
||||
albumActions[album.AlbumTitle]=function(){
|
||||
moveImages(album);
|
||||
};
|
||||
});
|
||||
$scope.contextMenuActions[moveIndex]=albumActions;
|
||||
});
|
||||
|
||||
$scope.selectImage=function(image){
|
||||
image.selected=!image.selected;
|
||||
};
|
||||
|
||||
$scope.editAlbum=function(album){
|
||||
Navigate("/gallery/editablum/"+album.AlbumId);
|
||||
};
|
||||
}]);
|
||||
|
101
Website/wwwroot/js/controllers/galleryUpload.js
Normal file
101
Website/wwwroot/js/controllers/galleryUpload.js
Normal file
|
@ -0,0 +1,101 @@
|
|||
angular.module("robware").controller('galleryUpload', ["$scope", "$http", function($scope, $http) {
|
||||
$scope.images = [];
|
||||
$scope.contextMenuActions = {
|
||||
Remove: remove,
|
||||
Clear: clear
|
||||
};
|
||||
|
||||
function remove(containerScope) {
|
||||
if (!containerScope.image)
|
||||
return;
|
||||
|
||||
var index = $scope.images.indexOf(containerScope.image);
|
||||
if (index !== -1)
|
||||
$scope.images.splice(index, 1);
|
||||
}
|
||||
|
||||
function clear() {
|
||||
if (confirm("Are you sure you want to clear the uploads?"))
|
||||
$scope.images = [];
|
||||
}
|
||||
|
||||
function removeImages(toRemove) {
|
||||
// I need this roundabout way to work with Angular's view engine
|
||||
var imageReferences = [];
|
||||
angular.forEach(toRemove, function(index) {
|
||||
imageReferences.push($scope.images[index]);
|
||||
});
|
||||
angular.forEach(imageReferences, function(ref) {
|
||||
$scope.images.splice($scope.images.indexOf(ref), 1);
|
||||
});
|
||||
}
|
||||
|
||||
$scope.getTotalImageSize = function() {
|
||||
var totalSize = 0;
|
||||
angular.forEach($scope.images, function(image) {
|
||||
totalSize += image.file.size;
|
||||
});
|
||||
return totalSize;
|
||||
}
|
||||
|
||||
$scope.safeUploadSize = function() {
|
||||
return $scope.maxUploadSize * 0.95;
|
||||
}
|
||||
|
||||
$scope.fileDrop = function(files) {
|
||||
angular.forEach(files, function(file) {
|
||||
var imageObject = {
|
||||
file: file,
|
||||
title: file.name.replace(/\.[^/.]+$/, ""),
|
||||
description: "",
|
||||
preview: ""
|
||||
};
|
||||
|
||||
var reader = new FileReader();
|
||||
reader.onload = function(e) {
|
||||
imageObject.preview = e.target.result;
|
||||
$scope.$apply();
|
||||
};
|
||||
reader.readAsDataURL(file);
|
||||
|
||||
$scope.images.push(imageObject);
|
||||
});
|
||||
};
|
||||
|
||||
$scope.upload = function() {
|
||||
var data = new FormData();
|
||||
var errors = [];
|
||||
angular.forEach($scope.images, function(image) {
|
||||
if (!image.title)
|
||||
errors.push("The image " + image.file.name + " doesn't have a title");
|
||||
data.append("files[]", image.file);
|
||||
data.append("title[]", image.title);
|
||||
data.append("description[]", image.description);
|
||||
});
|
||||
|
||||
var totalSize = 0;
|
||||
data.getAll("files[]").forEach(function(entry){
|
||||
totalSize += entry.size;
|
||||
});
|
||||
if (totalSize>$scope.safeUploadSize())
|
||||
errors.push("Max upload size exceeded");
|
||||
|
||||
if (errors.length>0){
|
||||
$scope.showErrors(errors);
|
||||
return;
|
||||
}
|
||||
|
||||
$http({
|
||||
method: 'POST',
|
||||
url: '/gallery/uploadimages',
|
||||
data: data,
|
||||
showSpinner: true,
|
||||
headers: {'Content-Type': undefined},
|
||||
transformRequest: angular.identity
|
||||
}).then(function(response) {
|
||||
$scope.showErrors(response.data.errors);
|
||||
removeImages(response.data.uploaded);
|
||||
});
|
||||
};
|
||||
}]);
|
||||
|
107
Website/wwwroot/js/controllers/main.js
Normal file
107
Website/wwwroot/js/controllers/main.js
Normal file
|
@ -0,0 +1,107 @@
|
|||
/* global app, angular */
|
||||
|
||||
angular.module("robware", ['ngAnimate'], ["$httpProvider", function($httpProvider) {
|
||||
/*
|
||||
* Stolen from: http://stackoverflow.com/questions/19254029/angularjs-http-post-does-not-send-data
|
||||
* Reason: send payload as form data instead of JSON, bind to controller action parameters
|
||||
*/
|
||||
// Use x-www-form-urlencoded Content-Type
|
||||
$httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';
|
||||
/**
|
||||
* The workhorse; converts an object to x-www-form-urlencoded serialization.
|
||||
* @param {Object} obj
|
||||
* @return {String}
|
||||
*/
|
||||
var param = function(obj) {
|
||||
var query = '', name, value, fullSubName, subName, subValue, innerObj, i;
|
||||
for (name in obj) {
|
||||
value = obj[name];
|
||||
if (value instanceof Array) {
|
||||
for (i = 0; i < value.length; ++i) {
|
||||
subValue = value[i];
|
||||
fullSubName = name + '[' + i + ']';
|
||||
innerObj = {};
|
||||
innerObj[fullSubName] = subValue;
|
||||
query += param(innerObj) + '&';
|
||||
}
|
||||
}
|
||||
else if (value instanceof Object) {
|
||||
for (subName in value) {
|
||||
subValue = value[subName];
|
||||
fullSubName = name + '[' + subName + ']';
|
||||
innerObj = {};
|
||||
innerObj[fullSubName] = subValue;
|
||||
query += param(innerObj) + '&';
|
||||
}
|
||||
}
|
||||
else if (value !== undefined && value !== null)
|
||||
query += encodeURIComponent(name) + '=' + encodeURIComponent(value) + '&';
|
||||
}
|
||||
|
||||
return query.length ? query.substr(0, query.length - 1) : query;
|
||||
};
|
||||
// Override $http service's default transformRequest
|
||||
$httpProvider.defaults.transformRequest = [
|
||||
function(data) {
|
||||
return angular.isObject(data) && String(data) !== '[object File]' ? param(data) : data;
|
||||
}
|
||||
];
|
||||
|
||||
$httpProvider.interceptors.push([
|
||||
'$rootScope',
|
||||
'$q',
|
||||
function($rootScope, $q) {
|
||||
return {
|
||||
request: function(config) {
|
||||
if (config.showSpinner)
|
||||
$rootScope.showSpinner();
|
||||
return config;
|
||||
},
|
||||
requestError: function(rejection) {
|
||||
$rootScope.hideSpinner();
|
||||
return $q.reject(rejection);
|
||||
},
|
||||
response: function(response) {
|
||||
$rootScope.hideSpinner();
|
||||
return response;
|
||||
},
|
||||
responseError: function(rejection) {
|
||||
$rootScope.hideSpinner();
|
||||
return $q.reject(rejection);
|
||||
}
|
||||
};
|
||||
}
|
||||
]);
|
||||
}]);
|
||||
|
||||
angular.module("robware").controller("main", ['$scope', '$rootScope', function ($scope, $rootScope) {
|
||||
console.log(123);
|
||||
var largeWindowBoundary = 1023;
|
||||
|
||||
$scope.menuVisible = false;//window.innerWidth > largeWindowBoundary;
|
||||
|
||||
$scope.shouldShowMenu = function() {
|
||||
return $scope.menuVisible || window.innerWidth > largeWindowBoundary;
|
||||
};
|
||||
|
||||
$scope.spinnerVisible = false;
|
||||
|
||||
$rootScope.showSpinner = function() {
|
||||
$scope.spinnerVisible = true;
|
||||
};
|
||||
|
||||
$rootScope.hideSpinner = function() {
|
||||
$scope.spinnerVisible = false;
|
||||
};
|
||||
|
||||
$(window).on("resize.doResize", function() {
|
||||
$scope.$apply(function() {
|
||||
//$scope.menuVisible = false;
|
||||
});
|
||||
});
|
||||
|
||||
$scope.errors=[];
|
||||
$scope.showErrors=function(errors){
|
||||
$scope.errors=errors;
|
||||
}
|
||||
}]);
|
65
Website/wwwroot/js/controllers/status.js
Normal file
65
Website/wwwroot/js/controllers/status.js
Normal file
|
@ -0,0 +1,65 @@
|
|||
angular.module("robware").controller('status', ["$scope", "statusService", "$interval", function($scope, statusService, $interval) {
|
||||
$scope.chartData=[];
|
||||
var chartDataId=0;
|
||||
|
||||
function reloadUptime() {
|
||||
statusService.getUptime().then(function(data) {
|
||||
$scope.uptime = data;
|
||||
$scope.haveUptime = true;
|
||||
});
|
||||
}
|
||||
$scope.haveUptime = false;
|
||||
$scope.uptime = {};
|
||||
reloadUptime();
|
||||
$interval(reloadUptime, 60000);
|
||||
|
||||
function reloadSystemInfo() {
|
||||
statusService.getSystemInfo().then(function(data) {
|
||||
if ($scope.chartData.length>=50)
|
||||
$scope.chartData.shift();
|
||||
$scope.chartData=$scope.chartData.concat([{id: chartDataId, CPU: data.load[0]*100, Mem: data.memUsage, Temp: data.cpuTemp}]);
|
||||
chartDataId++;
|
||||
$scope.load = data.load;
|
||||
$scope.cpuTemp = data.cpuTemp;
|
||||
$scope.memory = {
|
||||
free: data.memFree,
|
||||
used: data.memUsage,
|
||||
total: data.memTotal
|
||||
};
|
||||
$scope.haveSystemInfo = true;
|
||||
});
|
||||
}
|
||||
$scope.haveSystemInfo = false;
|
||||
$scope.load = {};
|
||||
$scope.loadHistory = [];
|
||||
$scope.cpuTemp = 0;
|
||||
$scope.systemInfoRefreshInterval = 5;
|
||||
var systemRefresh = $interval(reloadSystemInfo, $scope.systemInfoRefreshInterval * 1000);
|
||||
reloadSystemInfo();
|
||||
$scope.changeSystemInfoRefreshInterval = function(amount) {
|
||||
$scope.systemInfoRefreshInterval += amount;
|
||||
if ($scope.systemInfoRefreshInterval < 1)
|
||||
return;
|
||||
$interval.cancel(systemRefresh);
|
||||
systemRefresh = $interval(reloadSystemInfo, $scope.systemInfoRefreshInterval * 1000);
|
||||
};
|
||||
|
||||
function reloadProcesses() {
|
||||
statusService.getProcesses().then(function(data) {
|
||||
$scope.processes = data;
|
||||
$scope.haveProcesses = true;
|
||||
});
|
||||
}
|
||||
$scope.haveProcesses = false;
|
||||
$scope.processses = {};
|
||||
$scope.processRefreshInterval = 10;
|
||||
var processRefesh = $interval(reloadProcesses, $scope.processRefreshInterval * 1000);
|
||||
reloadProcesses();
|
||||
$scope.changeProcesRefreshInterval = function(amount) {
|
||||
$scope.processRefreshInterval += amount;
|
||||
if ($scope.processRefreshInterval < 1)
|
||||
return;
|
||||
$interval.cancel(processRefesh);
|
||||
processRefesh = $interval(reloadProcesses, $scope.processRefreshInterval * 1000);
|
||||
};
|
||||
}]);
|
56
Website/wwwroot/js/controllers/temperature.js
Normal file
56
Website/wwwroot/js/controllers/temperature.js
Normal file
|
@ -0,0 +1,56 @@
|
|||
angular.module("robware").controller('temperature', ["$scope", "temperatureService", "$interval", function($scope, temperatureService, $interval) {
|
||||
$scope.readings = [];
|
||||
$scope.temperatureData = {};
|
||||
|
||||
$scope.$watch("readings", function() {
|
||||
for (var i = 0; i < $scope.readings.length; i++) {
|
||||
$scope.readings[i].Timestamp = new Date($scope.readings[i].Timestamp * 1000);
|
||||
}
|
||||
});
|
||||
|
||||
function getData() {
|
||||
temperatureService.getReadings().then(function(data) {
|
||||
$scope.readings = data;
|
||||
});
|
||||
}
|
||||
$interval(getData, 60000);
|
||||
|
||||
function updateCurrentTemperature() {
|
||||
temperatureService.getCurrentTemperatureData().then(function(data) {
|
||||
$scope.temperatureData = data;
|
||||
});
|
||||
}
|
||||
$interval(updateCurrentTemperature, 5000);
|
||||
|
||||
var graphAdjustment = 10;
|
||||
|
||||
$scope.getGraphPercentage = function() {
|
||||
var graphTarget = ($scope.temperatureData.target * 1.2) - graphAdjustment;
|
||||
var graphTemperature = $scope.temperatureData.temperature - graphAdjustment;
|
||||
return Math.min((graphTemperature / graphTarget) * 100, 100);
|
||||
};
|
||||
|
||||
function getPercentage() {
|
||||
return (($scope.temperatureData.target - graphAdjustment) / (($scope.temperatureData.temperature * 1.5) - graphAdjustment)) * 100;
|
||||
}
|
||||
|
||||
$scope.getRed = function() {
|
||||
var percentage = getPercentage();
|
||||
return 255 * (1 - (Math.min(50, percentage) / 50));
|
||||
};
|
||||
|
||||
$scope.getBlue = function() {
|
||||
var percentage = Math.max(getPercentage() - 50, 0);
|
||||
return 255 * (Math.min(50, percentage) / 50);
|
||||
};
|
||||
|
||||
$scope.getGreen = function() {
|
||||
var percentage = getPercentage();
|
||||
percentage = Math.min(percentage, 75);
|
||||
percentage = Math.max(percentage, 25);
|
||||
percentage = Math.abs(50 - percentage);
|
||||
percentage /= 25;
|
||||
return 255 * (1 - Math.max(percentage, 0));
|
||||
};
|
||||
}]);
|
||||
|
48
Website/wwwroot/js/controllers/weight.js
Normal file
48
Website/wwwroot/js/controllers/weight.js
Normal file
|
@ -0,0 +1,48 @@
|
|||
angular.module("robware").controller("weight", ["$scope", "weightService", function($scope, weightService) {
|
||||
$scope.submitting = false;
|
||||
$scope.weight = null;
|
||||
$scope.fat = null;
|
||||
|
||||
$scope.readings = [];
|
||||
$scope.headings = {weight: "Weight (KG)", fat: "Fat %", bmi: "BMI"};
|
||||
|
||||
function refreshReadings() {
|
||||
weightService.getReadings().then(function(data) {
|
||||
$scope.readings = data;
|
||||
});
|
||||
}
|
||||
|
||||
$scope.$watch("readings", function() {
|
||||
for (var i = 0; i < $scope.readings.length; i++) {
|
||||
$scope.readings[i].date = new Date($scope.readings[i].date);
|
||||
}
|
||||
});
|
||||
|
||||
$scope.addReading = function() {
|
||||
if (!$scope.weight || !$scope.fat)
|
||||
return;
|
||||
|
||||
$scope.submitting = true;
|
||||
weightService.addWeight($scope.weight, $scope.fat).then(function(data) {
|
||||
refreshReadings();
|
||||
$scope.submitting = false;
|
||||
$scope.weight = null;
|
||||
$scope.fat = null;
|
||||
});
|
||||
};
|
||||
|
||||
$scope.deleteReading = function(id) {
|
||||
weightService.deleteWeight(id).then(function() {
|
||||
refreshReadings();
|
||||
});
|
||||
};
|
||||
|
||||
Object.defineProperty($scope, "tenLatestReadings", {
|
||||
get: function() {
|
||||
var temp = $scope.readings.slice(-10);
|
||||
temp.reverse();
|
||||
return temp;
|
||||
}
|
||||
});
|
||||
}]);
|
||||
|
58
Website/wwwroot/js/directives/contextMenu.js
Normal file
58
Website/wwwroot/js/directives/contextMenu.js
Normal file
|
@ -0,0 +1,58 @@
|
|||
angular.module("robware").directive('contextMenu', function() {
|
||||
return {
|
||||
restrict: 'E',
|
||||
templateUrl: '/scripts/directives/templates/contextMenu.html',
|
||||
scope: {
|
||||
actions: '=',
|
||||
isChild: '=?'
|
||||
},
|
||||
link: function(scope, element) {
|
||||
scope.isFunction = angular.isFunction;
|
||||
scope.show=false;
|
||||
scope.selectedElement=null;
|
||||
scope.subMenuShowKey="";
|
||||
|
||||
scope.changeSubMenuShowKey=function(name){
|
||||
scope.subMenuShowKey=name;
|
||||
};
|
||||
|
||||
function show(x, y, target){
|
||||
scope.changeSubMenuShowKey("");
|
||||
scope.menuX=x+"px";
|
||||
scope.menuY=y+"px";
|
||||
scope.selectedElement=target;
|
||||
scope.show=true;
|
||||
};
|
||||
|
||||
function hide(){
|
||||
scope.show=false;
|
||||
}
|
||||
|
||||
scope.performAction=function(func){
|
||||
if (!angular.isFunction(func))
|
||||
return;
|
||||
func($(scope.selectedElement).scope());
|
||||
hide();
|
||||
};
|
||||
|
||||
$(document).on("click", function(e){
|
||||
hide();
|
||||
scope.$apply();
|
||||
});
|
||||
|
||||
var parent=element.parent()[0];
|
||||
|
||||
if (scope.isChild){
|
||||
show(parent.clientWidth,parent.clientTop);
|
||||
}else
|
||||
$(parent).css("position","relative");
|
||||
element.parent().on("contextmenu", function(e){
|
||||
var offset=$(element).offset();
|
||||
show(e.pageX-offset.left, e.pageY-offset.top, e.target);
|
||||
scope.$apply();
|
||||
e.preventDefault();
|
||||
});
|
||||
}
|
||||
};
|
||||
});
|
||||
|
38
Website/wwwroot/js/directives/dragDrop.js
Normal file
38
Website/wwwroot/js/directives/dragDrop.js
Normal file
|
@ -0,0 +1,38 @@
|
|||
angular.module("robware").directive('dragDrop', function() {
|
||||
return {
|
||||
restrict: 'A',
|
||||
scope: {
|
||||
dragDrop:'='
|
||||
},
|
||||
link: function(scope, element) {
|
||||
function handleEvent(e){
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
}
|
||||
|
||||
element.on('dragover', function(e) {
|
||||
handleEvent(e);
|
||||
});
|
||||
element.on('dragenter', function(e) {
|
||||
handleEvent(e);
|
||||
$(element).addClass("dragOver");
|
||||
});
|
||||
element.on('dragleave', function(e) {
|
||||
handleEvent(e);
|
||||
$(element).removeClass("dragOver");
|
||||
});
|
||||
element.on('drop', function(e){
|
||||
handleEvent(e);
|
||||
$(element).removeClass("dragOver");
|
||||
|
||||
if (e.originalEvent.dataTransfer){
|
||||
if (e.originalEvent.dataTransfer.files.length > 0) {
|
||||
scope.dragDrop(e.originalEvent.dataTransfer.files);
|
||||
scope.$apply();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
});
|
||||
|
14
Website/wwwroot/js/directives/equalHeightWidth.js
Normal file
14
Website/wwwroot/js/directives/equalHeightWidth.js
Normal file
|
@ -0,0 +1,14 @@
|
|||
angular.module("robware").directive("equalWidth", function() {
|
||||
return {
|
||||
restrict: 'A',
|
||||
link: function(scope, element) {
|
||||
scope.getHeight = function() {
|
||||
return $(element).height();
|
||||
};
|
||||
scope.$watch(scope.getHeight, function(height) {
|
||||
$(element).width(height);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
122
Website/wwwroot/js/directives/googleChart.js
Normal file
122
Website/wwwroot/js/directives/googleChart.js
Normal file
|
@ -0,0 +1,122 @@
|
|||
/* global google, angular */
|
||||
|
||||
angular.module("robware").directive('googleChart', function() {
|
||||
return {
|
||||
restrict: 'E',
|
||||
templateUrl: '/scripts/directives/templates/googleChart.html',
|
||||
scope: {
|
||||
data: '=',
|
||||
headings: '=?',
|
||||
ignore: '=?',
|
||||
height: '='
|
||||
},
|
||||
link: function(scope, element, attributes) {
|
||||
var chartLoaded = false;
|
||||
|
||||
if (!scope.headings)
|
||||
scope.headings = [];
|
||||
|
||||
if (!scope.ignore)
|
||||
scope.ignore = [];
|
||||
|
||||
var chartData, chart;
|
||||
var chartOptions = {
|
||||
title: attributes.title,
|
||||
height: scope.height || 400,
|
||||
curveType: attributes.curveType,
|
||||
legend: {
|
||||
position: attributes.legendPosition || 'right'
|
||||
},
|
||||
vAxis: {
|
||||
title: attributes.vAxisTitle
|
||||
},
|
||||
backgroundColor: attributes.background || 'transparent'
|
||||
};
|
||||
|
||||
function formatToolTip(input, args) {
|
||||
return input.replace(/{(.+?)(:.*?)?}/g, function(match, index, format) {
|
||||
if (format)
|
||||
format = format.slice(1);
|
||||
if (args[index]===undefined)
|
||||
return match;
|
||||
if (isNumber(args[index]))
|
||||
return args[index].toString(format, true);
|
||||
return args[index].toString(format);
|
||||
});
|
||||
}
|
||||
|
||||
function shouldIgnore(value){
|
||||
return scope.ignore.indexOf(value)>-1;
|
||||
}
|
||||
|
||||
function setupChart() {
|
||||
if (!chartLoaded)
|
||||
return;
|
||||
|
||||
var firstRow = scope.data[0];
|
||||
var fields = {};
|
||||
for (var propertyName in firstRow) {
|
||||
if (shouldIgnore(propertyName))
|
||||
continue;
|
||||
|
||||
var datum = firstRow[propertyName];
|
||||
var type = typeof (datum);
|
||||
if (type === "object")
|
||||
type = datum.constructor.name;
|
||||
fields[propertyName] = {
|
||||
title: scope.headings[propertyName] || propertyName,
|
||||
type: type.toLowerCase()
|
||||
};
|
||||
}
|
||||
|
||||
chartData = new google.visualization.DataTable();
|
||||
angular.forEach(fields, function(value) {
|
||||
chartData.addColumn(value.type, value.title);
|
||||
if (attributes['toolTip' + value.title.upperCaseFirst()])
|
||||
chartData.addColumn({type: 'string', role: 'tooltip'});
|
||||
});
|
||||
|
||||
angular.forEach(scope.data, function(value) {
|
||||
var row = [];
|
||||
angular.forEach(value, function(value2, index) {
|
||||
if (shouldIgnore(index))
|
||||
return;
|
||||
|
||||
row.push(value2);
|
||||
var attrIndex = 'toolTip' + index.upperCaseFirst();
|
||||
if (attributes[attrIndex])
|
||||
row.push(formatToolTip(attributes[attrIndex], value));
|
||||
});
|
||||
chartData.addRow(row);
|
||||
});
|
||||
|
||||
chart = new google.visualization.LineChart(element[0]);
|
||||
drawChart();
|
||||
}
|
||||
|
||||
function drawChart() {
|
||||
chart.draw(chartData, chartOptions);
|
||||
}
|
||||
|
||||
$.getScript("https://www.google.com/jsapi", function() {
|
||||
//google.load('visualization', '1.1', {packages: ['line'], callback:function(){
|
||||
google.load('visualization', '1', {
|
||||
packages: ['corechart'],
|
||||
callback: function() {
|
||||
chartLoaded = true;
|
||||
setupChart();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
scope.$watch("data", function(v) {
|
||||
setupChart();
|
||||
});
|
||||
|
||||
angular.element(window).bind('resize', function() {
|
||||
drawChart();
|
||||
});
|
||||
}
|
||||
};
|
||||
});
|
||||
|
11
Website/wwwroot/js/directives/scopeInit.js
Normal file
11
Website/wwwroot/js/directives/scopeInit.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
angular.module("robware").directive("scopeInit", function(){
|
||||
return {
|
||||
restrict : 'E',
|
||||
link:function(scope, element, attributes){
|
||||
var content=element[0].innerHTML.trim();
|
||||
scope[attributes.value]=JSON.parse(content);
|
||||
element.remove();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
6
Website/wwwroot/js/directives/templates/contextMenu.html
Normal file
6
Website/wwwroot/js/directives/templates/contextMenu.html
Normal file
|
@ -0,0 +1,6 @@
|
|||
<div class="contextMenu" ng-if="show" ng-style="{left:menuX,top:menuY}">
|
||||
<div ng-repeat="(name, func) in actions track by name" class="menuItem" ng-click="performAction(func)" ng-mouseover="changeSubMenuShowKey(name)">
|
||||
{{name}}<span class="arrow" ng-if="!isFunction(func)"> ›</span>
|
||||
<context-menu ng-if="!isFunction(func)" actions="func" is-child="true" ng-show="subMenuShowKey==name"></context-menu>
|
||||
</div>
|
||||
</div>
|
1
Website/wwwroot/js/directives/templates/googleChart.html
Normal file
1
Website/wwwroot/js/directives/templates/googleChart.html
Normal file
|
@ -0,0 +1 @@
|
|||
<div class="mapsContainer">Loading chart...</div>
|
145
Website/wwwroot/js/javascript.js
Normal file
145
Website/wwwroot/js/javascript.js
Normal file
|
@ -0,0 +1,145 @@
|
|||
function Navigate(url) {
|
||||
window.location = url;
|
||||
}
|
||||
|
||||
function CreateCookie(name, value, days) {
|
||||
var expires;
|
||||
if (days) {
|
||||
var date = new Date();
|
||||
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
|
||||
expires = "; expires=" + date.toGMTString();
|
||||
}
|
||||
else {
|
||||
expires = "";
|
||||
}
|
||||
document.cookie = name + "=" + value + expires + "; path=/";
|
||||
}
|
||||
|
||||
function round(value, decimals) {
|
||||
return Number(Math.round(value + 'e' + decimals) + 'e-' + decimals);
|
||||
}
|
||||
|
||||
function isNumber(value){
|
||||
return isFinite(String(value));
|
||||
}
|
||||
|
||||
String.prototype.upperCaseFirst = function() {
|
||||
var lower = this.toLowerCase();
|
||||
return lower.charAt(0).toUpperCase() + lower.slice(1);
|
||||
};
|
||||
|
||||
function twoDigitZeroPad(input){
|
||||
input=input.toString();
|
||||
return [!input[1] && '0' || "", input].join('');
|
||||
}
|
||||
|
||||
Date.prototype.oldToString = Date.prototype.toString;
|
||||
Date.prototype.toString = function(format) {
|
||||
if (!format)
|
||||
return this.oldToString();
|
||||
var me=this;
|
||||
return format.replace(/./g, function(match) {
|
||||
switch(match){
|
||||
case 'd': return twoDigitZeroPad(me.getDate());
|
||||
case 'm': return twoDigitZeroPad(me.getMonth()+1);
|
||||
case 'y': return me.getFullYear();
|
||||
case "H": return twoDigitZeroPad(me.getHours());
|
||||
case "i": return twoDigitZeroPad(me.getMinutes());
|
||||
case "s": return twoDigitZeroPad(me.getSeconds());
|
||||
default: return match;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Number.prototype.oldToString=Number.prototype.toString;
|
||||
Number.prototype.toString=function(input, shouldRound){
|
||||
if (!shouldRound)
|
||||
return this.oldToString(input);
|
||||
|
||||
return round(this, input);
|
||||
};
|
||||
|
||||
$(function() {
|
||||
var panels = $("nav > dl > .sub-pages");
|
||||
var goIndicators = $("nav > dl > dt .go");
|
||||
var expandIndicators = $("nav > dl > dt .expand");
|
||||
panels.hide();
|
||||
expandIndicators.show();
|
||||
|
||||
$("nav > dl > dt").click(function(e) {
|
||||
var next = $(this).next();
|
||||
if (!next.hasClass("sub-pages")) {
|
||||
Navigate($(this).children("a").attr("href"));
|
||||
return;
|
||||
}
|
||||
panels.slideUp();
|
||||
goIndicators.hide();
|
||||
expandIndicators.show();
|
||||
if (next.is(":visible")) {
|
||||
return;
|
||||
}
|
||||
next.slideDown();
|
||||
$(this).children(".go").show();
|
||||
$(this).children(".expand").hide();
|
||||
});
|
||||
|
||||
$("nav dd").click(function(e) {
|
||||
Navigate($(this).children("a").attr("href"));
|
||||
});
|
||||
|
||||
$("nav a").click(function(e) {
|
||||
$(this).parent().click();
|
||||
return false;
|
||||
});
|
||||
|
||||
$("#body").css("padding-bottom", window.innerHeight - $("#buttons-right").offset().top);
|
||||
|
||||
$("form[ajaxForm]").submit(function(e) {
|
||||
e.preventDefault();
|
||||
form = $(this);
|
||||
$.ajax({
|
||||
url: form.attr("action"),
|
||||
method: form.attr("method"),
|
||||
data: form.serialize(),
|
||||
success: function(data) {
|
||||
var successFunction = form.attr("onsuccess");
|
||||
if (successFunction !== undefined && window[successFunction] !== undefined)
|
||||
window[successFunction](data);
|
||||
},
|
||||
error: function() {
|
||||
var errorFunction = form.attr("onerror");
|
||||
if (errorFunction !== undefined && window[errorFunction] !== undefined)
|
||||
window[errorFunction]();
|
||||
},
|
||||
});
|
||||
var postFunction = form.attr("onpost");
|
||||
if (postFunction !== undefined && window[postFunction] !== undefined)
|
||||
window[postFunction]();
|
||||
});
|
||||
|
||||
$("td").each(function() {
|
||||
var elem = $(this);
|
||||
if (/^[+-]?\d+(\.\d+)?$/.test(elem.text())) {
|
||||
elem.addClass("number");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$(document).delegate('.allowTabInput', 'keydown', function(e) {
|
||||
var keyCode = e.keyCode || e.which;
|
||||
console.log(e);
|
||||
if (keyCode == 9) {
|
||||
e.preventDefault();
|
||||
var start = $(this).get(0).selectionStart;
|
||||
var end = $(this).get(0).selectionEnd;
|
||||
|
||||
// set textarea value to: text before caret + tab + text after caret
|
||||
$(this).val($(this).val().substring(0, start)
|
||||
+ "\t"
|
||||
+ $(this).val().substring(end));
|
||||
|
||||
// put caret at right position again
|
||||
$(this).get(0).selectionStart =
|
||||
$(this).get(0).selectionEnd = start + 1;
|
||||
}
|
||||
});
|
60
Website/wwwroot/js/services/statusService.js
Normal file
60
Website/wwwroot/js/services/statusService.js
Normal file
|
@ -0,0 +1,60 @@
|
|||
angular.module("robware").service('statusService', ["$http", function($http) {
|
||||
function parseProcessData(data) {
|
||||
var headers = data.shift();
|
||||
var cpuIndex = -1;
|
||||
var ignoreColNames = ["user", "pid", "vsz", "rss", "tty", "stat"];
|
||||
var ignoreCols = [];
|
||||
|
||||
var processHeaders = []
|
||||
for (var col in headers) {
|
||||
if (headers[col].toLowerCase() === "%cpu")
|
||||
cpuIndex = col;
|
||||
|
||||
if (ignoreColNames.indexOf(headers[col].toLowerCase()) > -1)
|
||||
ignoreCols.push(col);
|
||||
else
|
||||
processHeaders.push(headers[col]);
|
||||
}
|
||||
|
||||
data.sort(function (a, b) {
|
||||
cpuA = parseFloat(a[cpuIndex]);
|
||||
cpuB = parseFloat(b[cpuIndex]);
|
||||
if (cpuA > cpuB)
|
||||
return -1;
|
||||
if (cpuA < cpuB)
|
||||
return 1
|
||||
return 0;
|
||||
});
|
||||
|
||||
var processData = [];
|
||||
for (var row in data) {
|
||||
var obj = {};
|
||||
for (var col in data[row]) {
|
||||
if (ignoreCols.indexOf(col) === -1)
|
||||
obj[headers[col]] = data[row][col];
|
||||
}
|
||||
processData.push(obj);
|
||||
}
|
||||
|
||||
return [processHeaders, processData];
|
||||
}
|
||||
|
||||
this.getProcesses = function() {
|
||||
return $http.get('/status/getprocesses').then(function(response) {
|
||||
parsedData = parseProcessData(response.data);
|
||||
return {headers: parsedData[0], data: parsedData[1]};
|
||||
});
|
||||
};
|
||||
|
||||
this.getSystemInfo=function(){
|
||||
return $http.get('/status/getsysteminfo').then(function(response){
|
||||
return response.data;
|
||||
});
|
||||
};
|
||||
|
||||
this.getUptime=function(){
|
||||
return $http.get('/status/getuptime').then(function(response){
|
||||
return response.data;
|
||||
})
|
||||
};
|
||||
}]);
|
13
Website/wwwroot/js/services/temperatureService.js
Normal file
13
Website/wwwroot/js/services/temperatureService.js
Normal file
|
@ -0,0 +1,13 @@
|
|||
angular.module("robware").service('temperatureService', ["$http", function($http) {
|
||||
this.getReadings = function() {
|
||||
return $http.get('/temperature/getreadings', {dontShowSpinner:true}).then(function(response) {
|
||||
return response.data;
|
||||
});
|
||||
};
|
||||
|
||||
this.getCurrentTemperatureData = function() {
|
||||
return $http.get("/temperature/GetTemperatureData", {dontShowSpinner:true}).then(function(response) {
|
||||
return response.data;
|
||||
});
|
||||
}
|
||||
}]);
|
31
Website/wwwroot/js/services/weightService.js
Normal file
31
Website/wwwroot/js/services/weightService.js
Normal file
|
@ -0,0 +1,31 @@
|
|||
angular.module("robware").service('weightService', ["$http", function($http) {
|
||||
this.addWeight=function(weight, fat){
|
||||
return $http({
|
||||
method:'post',
|
||||
url:'/weight/add',
|
||||
data:{weight:weight, fat:fat},
|
||||
showSpinner:true
|
||||
}).then(function(response){
|
||||
return response.data;
|
||||
});
|
||||
};
|
||||
this.deleteWeight=function(id){
|
||||
return $http({
|
||||
method:'post',
|
||||
url:'/weight/delete',
|
||||
data:{id:id},
|
||||
showSpinner:true
|
||||
}).then(function(response){
|
||||
return response.data;
|
||||
});
|
||||
};
|
||||
this.getReadings=function(){
|
||||
return $http({
|
||||
method:'post',
|
||||
url:'/weight/getreadings',
|
||||
showSpinner:true
|
||||
}).then(function(response){
|
||||
return response.data;
|
||||
});
|
||||
};
|
||||
}]);
|
|
@ -1,4 +0,0 @@
|
|||
// Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification
|
||||
// for details on configuring this project to bundle and minify static web assets.
|
||||
|
||||
// Write your JavaScript code.
|
Loading…
Add table
Add a link
Reference in a new issue