From 90318bde754e282b5cce4577ab5ed99112c749a4 Mon Sep 17 00:00:00 2001 From: Luca Haid Date: Mon, 3 Jun 2024 07:51:44 +0200 Subject: [PATCH] Update --- .../RaspberryDisplayController.php | 42 +++++++++++++++++++ .../RaspberryDisplay/RaspberryDisplay.js | 35 ++++++++++++---- public/plugins/vue/tt-components/tt-table.js | 19 ++++++++- 3 files changed, 86 insertions(+), 10 deletions(-) diff --git a/application/RaspberryDisplay/RaspberryDisplayController.php b/application/RaspberryDisplay/RaspberryDisplayController.php index ea014e086..3b51fe184 100644 --- a/application/RaspberryDisplay/RaspberryDisplayController.php +++ b/application/RaspberryDisplay/RaspberryDisplayController.php @@ -31,9 +31,15 @@ class RaspberryDisplayController extends mfBaseController { case "reboot": $return = $this->restartRaspberryPi($this->request->displayID); break; + case "rebootAll": + $return = $this->restartAllRaspberryPis(); + break; case "getConfig": $return = $this->getConfig(); break; + case "displayPower": + $return = $this->displayPower(); + break; default: $return = false; break; @@ -95,6 +101,21 @@ class RaspberryDisplayController extends mfBaseController { return true; } + protected function restartAllRaspberryPis() { + $displays = RaspberryDisplayModel::getAll(); + $ipAddresses = []; + foreach ($displays as $display) { + if (in_array($display->ip_address, $ipAddresses)) { + continue; + } + $ipAddresses[] = $display->ip_address; + $ssh = new SSH2($display->ip_address, $this->port); + $ssh->login($this->username, $this->password); + $ssh->exec('sudo reboot now'); + } + return true; + } + protected function getConfig() { $hostname = $this->request->hostname; @@ -129,5 +150,26 @@ class RaspberryDisplayController extends mfBaseController { $this->layout()->setTemplate("VueViews/Vue"); } + private function displayPower(): bool + { + $state = $this->request->state; + $displays = RaspberryDisplayModel::getAll(); + $ipAddresses = []; + foreach ($displays as $display) { + if (in_array($display->ip_address, $ipAddresses)) { + continue; + } + $ipAddresses[] = $display->ip_address; + $ssh = new SSH2($display->ip_address, $this->port); + $ssh->login($this->username, $this->password); + if ($state === "on") { + $ssh->exec('sudo bash /root/on.sh'); + } else { + $ssh->exec('sudo bash /root/off.sh'); + } + } + return true; + } + } \ No newline at end of file diff --git a/public/js/pages/RaspberryDisplay/RaspberryDisplay.js b/public/js/pages/RaspberryDisplay/RaspberryDisplay.js index 189d54c0f..a8522fded 100644 --- a/public/js/pages/RaspberryDisplay/RaspberryDisplay.js +++ b/public/js/pages/RaspberryDisplay/RaspberryDisplay.js @@ -6,14 +6,20 @@ Vue.filter('cleanupURL', function (value) { Vue.component('RaspberryDisplay', { //language=Vue template: ` -
- -
-

8322 Studenzen NOC Displays

+
+

8322 Studenzen NOC Displays

+ +
+ + + + +
+
-
`, @@ -89,9 +94,21 @@ Vue.component('RaspberryDisplay', { }, methods: { async rebootRaspberry(displayID) { this.loading = true; - await axios.get(`${window['TT_CONFIG']["BASE_URL"]}/api?do=reboot`, { + if (displayID === 'all') { + await axios.get(`${window['TT_CONFIG']["BASE_URL"]}/api?do=rebootAll`); + } else { + await axios.get(`${window['TT_CONFIG']["BASE_URL"]}/api?do=reboot`, { + params: { + displayID: displayID + } + }) + } + this.loading = false; + }, async displayPower(state) { + this.loading = true; + await axios.get(`${window['TT_CONFIG']["BASE_URL"]}/api?do=displayPower`, { params: { - displayID: displayID + state: state } }); this.loading = false; @@ -113,7 +130,9 @@ Vue.component('RaspberryDisplay', { }); }, disableDisplayURLEditMode(displayID, displayURL) { this.displaysURLEditMode = null; - this.submitChanges(displayID, 'display_url', displayURL); + if (this.displays.find(d => d.id === displayID).display_url !== displayURL) { + this.submitChanges(displayID, 'display_url', displayURL); + } }, async submitChanges(displayID, field, value) { this.loading = true; await axios.get(`${window['TT_CONFIG']["BASE_URL"]}/api?do=change`, { diff --git a/public/plugins/vue/tt-components/tt-table.js b/public/plugins/vue/tt-components/tt-table.js index 4c48bb99e..106efd5e0 100644 --- a/public/plugins/vue/tt-components/tt-table.js +++ b/public/plugins/vue/tt-components/tt-table.js @@ -144,7 +144,7 @@ Vue.component('tt-table', { (column.filter === 'dateRange' ? 'min-width: 260px;' : '') + (originalColumnWidths[column.key] ? 'width: ' + originalColumnWidths[column.key] + 'px;' : '')" > -
{{ column.text }} @@ -774,4 +774,19 @@ Vue.component('tt-table', { beforeDestroy() { window.removeEventListener('resize', this.debounce(this.handleResponsiveColumns, 100)); } -}) \ No newline at end of file +}) + +Vue.config.errorHandler = function(err, vm, info) { + // still log errors to the console + console.error(info, err, vm); + + if (typeof vm.config.key === 'string') { + // check if document.querySelector table.tt-table exists aswell if it has atleast 3 elements + const table = document.querySelector('table.tt-table'); + if (!table || !table.querySelectorAll('tr').length > 2) { + // localStorage.removeItem(`tt-table-${vm.config.key}`); + // window.location.reload(); + } + } +} +