From e88a313149cb39e187baf74a2fc18cc7c5d86d81 Mon Sep 17 00:00:00 2001 From: Jannik Schönartz Date: Thu, 30 Nov 2017 12:59:49 +0100 Subject: [locationinfo] Reworked summary-panel to the new panel uuid stuff. --- modules-available/locationinfo/api.inc.php | 52 +----- .../locationinfo/inc/infopanel.inc.php | 3 + .../locationinfo/inc/locationinfo.inc.php | 76 ++++++-- .../locationinfo/lang/de/template-tags.json | 1 + modules-available/locationinfo/page.inc.php | 47 ++++- .../locationinfo/templates/frontend-summary.html | 43 +++-- .../templates/page-config-panel-summary.html | 208 +++++++++++++++++++++ 7 files changed, 342 insertions(+), 88 deletions(-) create mode 100644 modules-available/locationinfo/templates/page-config-panel-summary.html diff --git a/modules-available/locationinfo/api.inc.php b/modules-available/locationinfo/api.inc.php index e14fe9d7..33a0f3db 100644 --- a/modules-available/locationinfo/api.inc.php +++ b/modules-available/locationinfo/api.inc.php @@ -1,33 +1,5 @@ getLastChangeTs($uuid)); } elseif ($get === "machines") { - $locationIds = getLocationsOr404($uuid); + $locationIds = LocationInfo::getLocationsOr404($uuid); $output = array(); InfoPanel::appendMachineData($output, $locationIds, false); $output = array_values($output); @@ -57,13 +29,13 @@ function HandleParameters() die('Panel not found'); } } elseif ($get === "pcstates") { - $locationIds = getLocationsOr404($uuid); + $locationIds = LocationInfo::getLocationsOr404($uuid); $output = getPcStates($locationIds); } elseif ($get === "locationtree") { - $locationIds = getLocationsOr404($uuid); + $locationIds = LocationInfo::getLocationsOr404($uuid); $output = getLocationTree($locationIds); } elseif ($get === "calendar") { - $locationIds = getLocationsOr404($uuid); + $locationIds = LocationInfo::getLocationsOr404($uuid); $output = getCalendar($locationIds); } if ($output !== false) { @@ -75,22 +47,6 @@ function HandleParameters() } } -/** - * Return list of locationids associated with given panel. - * @param string $paneluuid panel - * @return int[] locationIds - */ -function getLocationsOr404($paneluuid) -{ - $panel = Database::queryFirst('SELECT locationids FROM locationinfo_panel WHERE paneluuid = :paneluuid', - compact('paneluuid')); - if ($panel !== false) { - return array_map('intval', explode(',', $panel['locationids'])); - } - http_response_code(404); - die('Panel not found'); -} - /** * Get last config modification timestamp for given panel. * This was planned to be smart and check the involved locations, diff --git a/modules-available/locationinfo/inc/infopanel.inc.php b/modules-available/locationinfo/inc/infopanel.inc.php index c612e518..dacf860f 100644 --- a/modules-available/locationinfo/inc/infopanel.inc.php +++ b/modules-available/locationinfo/inc/infopanel.inc.php @@ -20,6 +20,7 @@ class InfoPanel } if ($panel['paneltype'] === 'URL') { + // Shortcut for URL redirect $config = json_decode($panel['panelconfig'], true); return $panel['paneltype']; } @@ -31,6 +32,7 @@ class InfoPanel if (!empty($panel['panelconfig'])) { $json = json_decode($panel['panelconfig'], true); if (is_array($json)) { + // Put location-specific overrides in separate variable for later use if (isset($json['overrides']) && is_array($json['overrides'])) { $overrides = $json['overrides']; } @@ -48,6 +50,7 @@ class InfoPanel 'id' => $lid, 'name' => isset($locations[$lid]) ? $locations[$lid]['locationname'] : 'noname00.pas', ); + // Now apply any overrides from above if (isset($overrides[$lid]) && is_array($overrides[$lid])) { $config['locations'][$lid]['config'] = $overrides[$lid]; } diff --git a/modules-available/locationinfo/inc/locationinfo.inc.php b/modules-available/locationinfo/inc/locationinfo.inc.php index 933eaf4d..64070cd4 100644 --- a/modules-available/locationinfo/inc/locationinfo.inc.php +++ b/modules-available/locationinfo/inc/locationinfo.inc.php @@ -22,6 +22,32 @@ class LocationInfo return $pc['state']; } + /** + * Return list of locationids associated with given panel. + * @param string $paneluuid panel + * @param bool $recursive if true and paneltype == SUMMARY the result is recursive with all child room ids. + * @return int[] locationIds + */ + public static function getLocationsOr404($paneluuid, $recursive = true) + { + $panel = Database::queryFirst('SELECT paneltype, locationids FROM locationinfo_panel WHERE paneluuid = :paneluuid', + compact('paneluuid')); + if ($panel !== false) { + $idArray = array_map('intval', explode(',', $panel['locationids'])); + if ($panel['paneltype'] == "SUMMARY" && $recursive) { + $idList = Location::getRecursiveFlat($idArray); + $idArray = array(); + + foreach ($idList as $key => $value) { + $idArray[] = $key; + } + } + return $idArray; + } + http_response_code(404); + die('Panel not found'); + } + /** * Set current error message of given server. Pass null or false to clear. * @@ -47,27 +73,38 @@ class LocationInfo } /** - * Creates and returns a default config for room that didn't saved a config yet. + * Creates and returns a default config for room that didn't save a config yet. * * @return array Return a default config. */ public static function defaultPanelConfig($type) { - return array( - 'language' => 'en', - 'mode' => 1, - 'vertical' => false, - 'eco' => false, - 'prettytime' => true, - 'scaledaysauto' => true, - 'daystoshow' => 7, - 'rotation' => 0, - 'scale' => 50, - 'switchtime' => 20, - 'calupdate' => 30, - 'roomupdate' => 15, - 'configupdate' => 180, - ); + if ($type === 'DEFAULT') { + return array( + 'language' => 'en', + 'mode' => 1, + 'vertical' => false, + 'eco' => false, + 'prettytime' => true, + 'scaledaysauto' => true, + 'daystoshow' => 7, + 'rotation' => 0, + 'scale' => 50, + 'switchtime' => 20, + 'calupdate' => 30, + 'roomupdate' => 15, + 'configupdate' => 180, + ); + } + if ($type === 'SUMMARY') { + return array( + 'language' => 'en', + 'calupdate' => 30, + 'roomupdate' => 15, + 'configupdate' => 180, + ); + } + return array(); } /** @@ -81,6 +118,12 @@ class LocationInfo return $ret['panelname']; } + /** + * Hook called by runmode module where we should modify the client config according to our + * needs. Disable standby/logout timeouts, enable autologin, set URL. + * @param $machineUuid + * @param $panelUuid + */ public static function configHook($machineUuid, $panelUuid) { $row = Database::queryFirst('SELECT paneltype, panelconfig FROM locationinfo_panel WHERE paneluuid = :uuid', @@ -98,6 +141,7 @@ class LocationInfo ConfigHolder::add('SLX_ADDONS', '', 1000); ConfigHolder::add('SLX_LOGOUT_TIMEOUT', '', 1000); ConfigHolder::add('SLX_SCREEN_STANDBY_TIMEOUT', '', 1000); + ConfigHolder::add('SLX_SYSTEM_STANDBY_TIMEOUT', '', 1000); ConfigHolder::add('SLX_AUTOLOGIN', '1', 1000); } diff --git a/modules-available/locationinfo/lang/de/template-tags.json b/modules-available/locationinfo/lang/de/template-tags.json index 1574d9e8..265f3444 100644 --- a/modules-available/locationinfo/lang/de/template-tags.json +++ b/modules-available/locationinfo/lang/de/template-tags.json @@ -24,6 +24,7 @@ "lang_ecoMode": "E-Ink Modus", "lang_ecoTooltip": "Anstelle der Farb-basierten PC-Status Bilder, werden Symbol-basierte PC Bilder verwendet", "lang_editDefaultPanelHints": "Hier k\u00f6nnen Sie ein Panel (z.B. digitales T\u00fcrschild) in Aussehen und Funktionsweise definieren. Um im Kalender \u00d6ffnungszeiten anzeigen zu k\u00f6nnen, m\u00fcssen Sie im Tab \"Raum-\/Ortsbezogene Einstellungen\" f\u00fcr den ausgew\u00e4hlten Raum entsprechend \u00d6ffnungszeiten eintragen. Damit im Kalender Veranstaltungen und andere Termine angezeigt werden k\u00f6nnen, muss ein funktionierendes Backend konfiguriert und den ausgew\u00e4hlten R\u00e4umen zugewiesen worden sein.", + "lang_editSummaryPanelHints": "Hier k\u00f6nnen Sie ein Summary-Panel definieren. Das Panel zeigt eine Übersicht der in den R\u00e4umen enthalten PCs.", "lang_editPanel": "Panel bearbeiten", "lang_entryName": "Name", "lang_error": "Fehler", diff --git a/modules-available/locationinfo/page.inc.php b/modules-available/locationinfo/page.inc.php index 30c38362..847dc73a 100644 --- a/modules-available/locationinfo/page.inc.php +++ b/modules-available/locationinfo/page.inc.php @@ -254,11 +254,14 @@ class Page_LocationInfo extends Page $params = $this->preparePanelConfigDefault(); } elseif ($paneltype === 'URL') { $params = $this->preparePanelConfigUrl(); + } elseif ($paneltype === 'SUMMARY') { + $params = $this->preparePanelConfigSummary(); } else { Message::addError('invalid-panel-type', $paneltype); Util::redirect('?do=locationinfo'); } + if ($paneluuid === 'new') { $paneluuid = Util::randomUuid(); $query = "INSERT INTO `locationinfo_panel` (paneluuid, panelname, locationids, paneltype, panelconfig, lastchange) @@ -320,6 +323,16 @@ class Page_LocationInfo extends Page return array('config' => $conf, 'locationids' => []); } + private function preparePanelConfigSummary() + { + // Check locations + $locationids = self::getLocationIdsFromRequest(true); + if (count($locationids) > 4) { + $locationids = array_slice($locationids, 0, 4); + } + return array('locationids' => $locationids); + } + /** * Updates the server settings in the db. */ @@ -832,7 +845,7 @@ class Page_LocationInfo extends Page 'url' => $config['url'], 'ssl_checked' => $config['insecure-ssl'] ? 'checked' : '', )); - } else { // TODO + } else { Render::addTemplate('page-config-panel-summary', array( 'new' => $id === 'new', 'uuid' => $id, @@ -862,19 +875,37 @@ class Page_LocationInfo extends Page Util::redirect($config['url']); } - $data = array( - 'uuid' => $uuid, - 'config' => json_encode($config), - 'language' => $config['language'], - ); - + $data = array(); preg_match('#^(.*)/#', $_SERVER['PHP_SELF'], $script); preg_match('#^([^?]+)/#', $_SERVER['REQUEST_URI'], $request); if ($script[1] !== $request[1]) { $data['dirprefix'] = $script[1] . '/'; } - echo Render::parse('frontend-default', $data); + if ($type === 'DEFAULT') { + $data += array( + 'uuid' => $uuid, + 'config' => json_encode($config), + 'language' => $config['language'], + ); + + die(Render::parse('frontend-default', $data)); + } + + if ($type === 'SUMMARY') { + $locations = LocationInfo::getLocationsOr404($uuid, false); + $config['tree'] = Location::getRecursive($locations); + $data += array( + 'uuid' => $uuid, + 'config' => json_encode($config), + 'language' => $config['language'], + ); + + die(Render::parse('frontend-summary', $data)); + } + + http_response_code(500); + die('Unknown panel type ' . $type); } } diff --git a/modules-available/locationinfo/templates/frontend-summary.html b/modules-available/locationinfo/templates/frontend-summary.html index dd5fc25d..e117cbcb 100644 --- a/modules-available/locationinfo/templates/frontend-summary.html +++ b/modules-available/locationinfo/templates/frontend-summary.html @@ -2,7 +2,8 @@ - + +