feat: add minifier and update esp32 HTML
This commit is contained in:
parent
8162aa3c8e
commit
0ca4f0a9c6
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
|||||||
.vscode
|
.vscode
|
||||||
.idea
|
.idea
|
||||||
venv
|
venv
|
||||||
|
*.html
|
||||||
|
File diff suppressed because one or more lines are too long
@ -9,12 +9,14 @@
|
|||||||
<h1>Scheduler</h1>
|
<h1>Scheduler</h1>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
class Schedule {
|
class Schedule {
|
||||||
|
|
||||||
constructor(scheduleArray) {
|
constructor(scheduleArray) {
|
||||||
|
|
||||||
if (scheduleArray && scheduleArray.length === 24) {
|
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 {
|
} else {
|
||||||
// Initialize with all hours turned off if no valid array is provided
|
// Initialize with all hours turned off if no valid array is provided
|
||||||
this.schedule = new Array(24).fill(0x000);
|
this.schedule = new Array(24).fill(0x000);
|
||||||
@ -53,9 +55,11 @@ class Schedule {
|
|||||||
serializeForDisplay() {
|
serializeForDisplay() {
|
||||||
// Converts the schedule array into a display format with the appropriate class for coloring
|
// Converts the schedule array into a display format with the appropriate class for coloring
|
||||||
return this.schedule.map(hour => {
|
return this.schedule.map(hour => {
|
||||||
if (hour === 0xFFF) { // All segments on
|
// All segments on
|
||||||
|
if (hour === 0xFFF) {
|
||||||
return { displayValue: ' ', class: 'on' };
|
return { displayValue: ' ', class: 'on' };
|
||||||
} else if (hour === 0x00) { // All segments off
|
// All segments off
|
||||||
|
} else if (hour === 0x00) {
|
||||||
return { displayValue: ' ', class: 'off' };
|
return { displayValue: ' ', class: 'off' };
|
||||||
} else {
|
} else {
|
||||||
return { displayValue: ' ', class: 'partial' };
|
return { displayValue: ' ', class: 'partial' };
|
||||||
@ -112,7 +116,7 @@ class Schedule {
|
|||||||
var app = angular.module('plugSchedulerApp', []);
|
var app = angular.module('plugSchedulerApp', []);
|
||||||
app.value('api_host', window.location.host);
|
app.value('api_host', window.location.host);
|
||||||
app.factory("data", function(){
|
app.factory("data", function(){
|
||||||
var sharedData = { api_host: window.location.host}
|
var sharedData = { api_host: window.location.host};
|
||||||
return {
|
return {
|
||||||
getSharedData: function () {
|
getSharedData: function () {
|
||||||
return sharedData;
|
return sharedData;
|
||||||
@ -124,7 +128,7 @@ app.controller('ApiHostController', ['$scope', 'api_host', 'data', function( $sc
|
|||||||
var ctrl = this;
|
var ctrl = this;
|
||||||
$scope.data = data.getSharedData();
|
$scope.data = data.getSharedData();
|
||||||
window.ctrl = $scope
|
window.ctrl = $scope
|
||||||
}])
|
}]);
|
||||||
|
|
||||||
app.controller('PlugScheduleController', ['$scope', '$http', 'data', function( $scope, $http, data) {
|
app.controller('PlugScheduleController', ['$scope', '$http', 'data', function( $scope, $http, data) {
|
||||||
var ctrl = this;
|
var ctrl = this;
|
||||||
@ -132,7 +136,8 @@ app.controller('PlugScheduleController', ['$scope', '$http', 'data', function( $
|
|||||||
$scope.data = data.getSharedData();
|
$scope.data = data.getSharedData();
|
||||||
|
|
||||||
ctrl.$onInit = function() {
|
ctrl.$onInit = function() {
|
||||||
ctrl.scheduleObj = new Schedule(); // Initialize with a default schedule
|
// Initialize with a default schedule
|
||||||
|
ctrl.scheduleObj = new Schedule();
|
||||||
ctrl.getSchedule();
|
ctrl.getSchedule();
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -142,7 +147,7 @@ app.controller('PlugScheduleController', ['$scope', '$http', 'data', function( $
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Fetch the schedule from the server for a given plug ID
|
// 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) {
|
$http.get(url, { responseType: 'arraybuffer' }).then(function(response) {
|
||||||
ctrl.scheduleObj.loadFromArrayBuffer(response.data);
|
ctrl.scheduleObj.loadFromArrayBuffer(response.data);
|
||||||
ctrl.displaySchedule = ctrl.scheduleObj.serializeForDisplay();
|
ctrl.displaySchedule = ctrl.scheduleObj.serializeForDisplay();
|
||||||
@ -166,7 +171,7 @@ app.controller('PlugScheduleController', ['$scope', '$http', 'data', function( $
|
|||||||
|
|
||||||
// Send the updated schedule to the server
|
// Send the updated schedule to the server
|
||||||
ctrl.updateSchedule = function() {
|
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();
|
var serializedSchedule = ctrl.scheduleObj.serializeToArrayBuffer();
|
||||||
|
|
||||||
$http.post(url, serializedSchedule, {
|
$http.post(url, serializedSchedule, {
|
||||||
@ -199,7 +204,7 @@ app.controller('PlugScheduleController', ['$scope', '$http', 'data', function( $
|
|||||||
};
|
};
|
||||||
ctrl.invertAll = function(hourIndex) {
|
ctrl.invertAll = function(hourIndex) {
|
||||||
ctrl.editMatrix[hourIndex].forEach(segment => {
|
ctrl.editMatrix[hourIndex].forEach(segment => {
|
||||||
var inverted = Math.abs( segment.value - 1)
|
var inverted = Math.abs( segment.value - 1);
|
||||||
segment.value = inverted;
|
segment.value = inverted;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
11
html/minify.sh
Executable file
11
html/minify.sh
Executable 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"
|
Loading…
Reference in New Issue
Block a user