feat: add minifier and update esp32 HTML

This commit is contained in:
alban 2024-02-28 22:10:06 +01:00
parent 8162aa3c8e
commit 0ca4f0a9c6
4 changed files with 30 additions and 13 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
.vscode
.idea
venv
*.html

File diff suppressed because one or more lines are too long

View File

@ -9,12 +9,14 @@
<h1>Scheduler</h1>
<script>
class Schedule {
constructor(scheduleArray) {
if (scheduleArray && scheduleArray.length === 24) {
this.schedule = scheduleArray.slice(); // Copy the array to prevent direct mutation
// Copy the array to prevent direct mutation
this.schedule = scheduleArray.slice();
} else {
// Initialize with all hours turned off if no valid array is provided
this.schedule = new Array(24).fill(0x000);
@ -53,9 +55,11 @@ class Schedule {
serializeForDisplay() {
// Converts the schedule array into a display format with the appropriate class for coloring
return this.schedule.map(hour => {
if (hour === 0xFFF) { // All segments on
// All segments on
if (hour === 0xFFF) {
return { displayValue: ' ', class: 'on' };
} else if (hour === 0x00) { // All segments off
// All segments off
} else if (hour === 0x00) {
return { displayValue: ' ', class: 'off' };
} else {
return { displayValue: ' ', class: 'partial' };
@ -112,7 +116,7 @@ class Schedule {
var app = angular.module('plugSchedulerApp', []);
app.value('api_host', window.location.host);
app.factory("data", function(){
var sharedData = { api_host: window.location.host}
var sharedData = { api_host: window.location.host};
return {
getSharedData: function () {
return sharedData;
@ -124,7 +128,7 @@ app.controller('ApiHostController', ['$scope', 'api_host', 'data', function( $sc
var ctrl = this;
$scope.data = data.getSharedData();
window.ctrl = $scope
}])
}]);
app.controller('PlugScheduleController', ['$scope', '$http', 'data', function( $scope, $http, data) {
var ctrl = this;
@ -132,7 +136,8 @@ app.controller('PlugScheduleController', ['$scope', '$http', 'data', function( $
$scope.data = data.getSharedData();
ctrl.$onInit = function() {
ctrl.scheduleObj = new Schedule(); // Initialize with a default schedule
// Initialize with a default schedule
ctrl.scheduleObj = new Schedule();
ctrl.getSchedule();
};
@ -142,7 +147,7 @@ app.controller('PlugScheduleController', ['$scope', '$http', 'data', function( $
}
// Fetch the schedule from the server for a given plug ID
var url = `http://${$scope.data.api_host}/api/schedule/${ctrl.plugId}`
var url = `http://${$scope.data.api_host}/api/schedule/${ctrl.plugId}`;
$http.get(url, { responseType: 'arraybuffer' }).then(function(response) {
ctrl.scheduleObj.loadFromArrayBuffer(response.data);
ctrl.displaySchedule = ctrl.scheduleObj.serializeForDisplay();
@ -166,7 +171,7 @@ app.controller('PlugScheduleController', ['$scope', '$http', 'data', function( $
// Send the updated schedule to the server
ctrl.updateSchedule = function() {
var url = `http://${$scope.data.api_host}/api/schedule/${ctrl.plugId}`
var url = `http://${$scope.data.api_host}/api/schedule/${ctrl.plugId}`;
var serializedSchedule = ctrl.scheduleObj.serializeToArrayBuffer();
$http.post(url, serializedSchedule, {
@ -199,7 +204,7 @@ app.controller('PlugScheduleController', ['$scope', '$http', 'data', function( $
};
ctrl.invertAll = function(hourIndex) {
ctrl.editMatrix[hourIndex].forEach(segment => {
var inverted = Math.abs( segment.value - 1)
var inverted = Math.abs( segment.value - 1);
segment.value = inverted;
});
};

11
html/minify.sh Executable file
View File

@ -0,0 +1,11 @@
#!/usr/bin/env bash
APP_PATH=$(cd $(dirname $0) && pwd)
TMP_FILE=$(mktemp)
FINAL_FILE=minify.html
cp "$APP_PATH/index.html" "$TMP_FILE"
sed -ri "s/^\s+//" "$TMP_FILE"
sed -ri "s=^//.*$==" "$TMP_FILE"
sed -ri 's="=\\"=g' "$TMP_FILE"
tr -d '\n' < "$TMP_FILE" > "$FINAL_FILE"
cat "$FINAL_FILE"