Re-implement existing website template (from PHP). Add all assets.

This commit is contained in:
Robert Marshall 2019-04-27 21:24:52 +01:00
parent a87a334bc7
commit ddf6c5b8ce
60 changed files with 2514 additions and 87 deletions

View 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);
};
}]);

View 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);
};
}]);

View 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);
});
};
}]);

View 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;
}
}]);

View 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);
};
}]);

View 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));
};
}]);

View 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;
}
});
}]);