From 77f9f9d9e975bd14083656f987b426e81908dd9e Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 3 Nov 2020 13:45:37 +0100 Subject: [locationinfo] Remove unused javascript Most javascript was needed for editing the opening times of locations. Some javascript was still used to fill the now disabled input forms for display only. This is now done server-side, and the input fields have been replaced by a simple table. --- modules-available/locationinfo/clientscript.js | 91 ----------- modules-available/locationinfo/config.json | 2 - modules-available/locationinfo/lang/de/module.json | 10 +- .../locationinfo/lang/de/template-tags.json | 10 -- modules-available/locationinfo/lang/en/module.json | 12 +- .../locationinfo/lang/en/template-tags.json | 10 -- modules-available/locationinfo/page.inc.php | 110 ++++++++------ .../templates/ajax-config-location.html | 168 ++------------------- .../templates/page-config-panel-default.html | 20 ++- .../templates/page-config-panel-summary.html | 8 +- .../locationinfo/templates/page-locations.html | 6 +- 11 files changed, 114 insertions(+), 333 deletions(-) delete mode 100644 modules-available/locationinfo/clientscript.js diff --git a/modules-available/locationinfo/clientscript.js b/modules-available/locationinfo/clientscript.js deleted file mode 100644 index f8309a8a..00000000 --- a/modules-available/locationinfo/clientscript.js +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Generic helpers. - */ - -/** - * Initialize timepicker on given element. - */ -function setTimepicker($e) { - $e.timepicker({ - minuteStep: 15, - appendWidgetTo: 'body', - showSeconds: false, - showMeridian: false, - defaultTime: false - }); -} - -function getTime(str) { - if (!str) return false; - str = str.split(':'); - if (str.length !== 2) return false; - var h = parseInt(str[0].replace(/^0/, '')); - var m = parseInt(str[1].replace(/^0/, '')); - if (h < 0 || h > 23) return false; - if (m < 0 || m > 59) return false; - return h * 60 + m; -} - -const allDays = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']; - -/* - * Opening times related... - */ - -var slxIdCounter = 0; - -/** - * Adds a new opening time to the table in expert mode. - */ -function newOpeningTime(vals) { - var $row = $('#expert-template').find('div.row').clone(); - if (vals['days'] && Array.isArray(vals['days'])) { - for (var i = 0; i < allDays.length; ++i) { - $row.find('.i-' + allDays[i]).prop('checked', vals['days'].indexOf(allDays[i]) !== -1); - } - } - $row.find('input').each(function() { - var $inp = $(this); - if ($inp.length === 0) return; - slxIdCounter++; - $inp.prop('id', 'id-inp-' + slxIdCounter); - $inp.siblings('label').prop('for', 'id-inp-' + slxIdCounter); - }); - $row.find('.i-openingtime').val(vals['openingtime']); - $row.find('.i-closingtime').val(vals['closingtime']); - $('#expert-table').append($row); - return $row; -} - -/** - * Convert fields from simple mode view to entries in expert mode. - * @returns {Array} - */ -function simpleToExpert() { - var retval = []; - if ($('#week-open').val() || $('#week-close').val()) { - retval.push({ - 'days': ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'], - 'openingtime': $('#week-open').val(), - 'closingtime': $('#week-close').val(), - 'tag': '#week' - }); - } - if ($('#saturday-open').val() || $('#saturday-close').val()) { - retval.push({ - 'days': ['Saturday'], - 'openingtime': $('#saturday-open').val(), - 'closingtime': $('#saturday-close').val(), - 'tag': '#saturday' - }); - } - if ($('#sunday-open').val() || $('#sunday-close').val()) { - retval.push({ - 'days': ['Sunday'], - 'openingtime': $('#sunday-open').val(), - 'closingtime': $('#sunday-close').val(), - 'tag': '#sunday' - }); - } - return retval; -} diff --git a/modules-available/locationinfo/config.json b/modules-available/locationinfo/config.json index 15298ea1..4fa2859e 100644 --- a/modules-available/locationinfo/config.json +++ b/modules-available/locationinfo/config.json @@ -1,8 +1,6 @@ { "category": "main.content", "dependencies": [ - "js_jqueryui", - "bootstrap_timepicker", "locations", "bootstrap_switch" ] diff --git a/modules-available/locationinfo/lang/de/module.json b/modules-available/locationinfo/lang/de/module.json index c344581c..a285351e 100644 --- a/modules-available/locationinfo/lang/de/module.json +++ b/modules-available/locationinfo/lang/de/module.json @@ -1,3 +1,11 @@ { - "module_name": "Infoscreen" + "friday": "Freitag", + "module_name": "Infoscreen", + "monday": "Montag", + "page_title": "Inforscreens und Rechercheterminals", + "saturday": "Samstag", + "sunday": "Sonntag", + "thursday": "Donnerstag", + "tuesday": "Dienstag", + "wednesday": "Mittwoch" } \ No newline at end of file diff --git a/modules-available/locationinfo/lang/de/template-tags.json b/modules-available/locationinfo/lang/de/template-tags.json index b376b905..457f071c 100644 --- a/modules-available/locationinfo/lang/de/template-tags.json +++ b/modules-available/locationinfo/lang/de/template-tags.json @@ -17,14 +17,12 @@ "lang_checkConnection": "Verbindung pr\u00fcfen", "lang_chromium": "Chromium", "lang_closed": "Geschlossen", - "lang_closingTime": "Schlie\u00dfungszeit", "lang_configOverride": "Konfiguration \u00fcberschreiben", "lang_countIp": "\u00fcber IP-Adressbereich", "lang_countRoomplan": "\u00fcber Raumplaner", "lang_createPanel": "Panel anlegen", "lang_credentials": "Anmeldung", "lang_currentDay": "Aktueller Tag", - "lang_day": "Tag", "lang_daysToShow": "Tage", "lang_daysToShowTooltip": "Legt die Anzahl an Tagen im Kalender fest, die angezeigt werden", "lang_defaultPanel": "Standard-Panel", @@ -76,7 +74,6 @@ "lang_mode3": "Raum", "lang_mode4": "Wechselnd", "lang_modeTooltip": "Die Anzeigemodi, welche das Frontend unterst\u00fctzt", - "lang_monTilFr": "Montag - Freitag", "lang_monday": "Montag", "lang_nameTooltip": "Legt den Namen des Servers fest", "lang_noLocationsWarning": "Bitte w\u00e4hlen Sie mindestens einen Ort aus, der vom Panel angezeigt werden soll.", @@ -119,19 +116,12 @@ "lang_serverTooltip": "Legt fest, von welchem Backend-Server die Kalenderdaten bezogen werden", "lang_serverType": "Typ", "lang_shortFri": "Fr", - "lang_shortFriday": "Fr", "lang_shortMon": "Mo", - "lang_shortMonday": "Mo", "lang_shortSat": "Sa", - "lang_shortSaturday": "Sa", "lang_shortSun": "So", - "lang_shortSunday": "So", "lang_shortThu": "Do", - "lang_shortThursday": "Do", "lang_shortTue": "Di", - "lang_shortTuesday": "Di", "lang_shortWed": "Mi", - "lang_shortWednesday": "Mi", "lang_showHostname": "Hostname anzeigen", "lang_showLog": "Log", "lang_slxbrowser": "SLX Browser", diff --git a/modules-available/locationinfo/lang/en/module.json b/modules-available/locationinfo/lang/en/module.json index 2fd14353..183b1877 100644 --- a/modules-available/locationinfo/lang/en/module.json +++ b/modules-available/locationinfo/lang/en/module.json @@ -1,3 +1,11 @@ { - "module_name": "Infoscreen" -} + "friday": "Friday", + "module_name": "Infoscreen", + "monday": "Monday", + "page_title": "Info screens and research terminals", + "saturday": "Saturday", + "sunday": "Sunday", + "thursday": "Thursday", + "tuesday": "Tuesday", + "wednesday": "Wednesday" +} \ No newline at end of file diff --git a/modules-available/locationinfo/lang/en/template-tags.json b/modules-available/locationinfo/lang/en/template-tags.json index 27315bea..95e1b23f 100644 --- a/modules-available/locationinfo/lang/en/template-tags.json +++ b/modules-available/locationinfo/lang/en/template-tags.json @@ -17,14 +17,12 @@ "lang_checkConnection": "Check connection", "lang_chromium": "Chromium", "lang_closed": "Closed", - "lang_closingTime": "Closing time", "lang_configOverride": "Configuration override", "lang_countIp": "by IP-Range", "lang_countRoomplan": "by Roomplanner", "lang_createPanel": "Create panel", "lang_credentials": "Login", "lang_currentDay": "Current Day", - "lang_day": "Day", "lang_daysToShow": "Days", "lang_daysToShowTooltip": "Defines the amount of days to show in the calendar", "lang_defaultPanel": "Default panel", @@ -76,7 +74,6 @@ "lang_mode3": "Room", "lang_mode4": "Switching", "lang_modeTooltip": "The display modes the frontend supports", - "lang_monTilFr": "Monday - Friday", "lang_monday": "Monday", "lang_nameTooltip": "Defines the name of the server", "lang_noLocationsWarning": "Please select at least one location this panel should display.", @@ -119,19 +116,12 @@ "lang_serverTooltip": "Defines from which server the room queries the calendar data", "lang_serverType": "Type", "lang_shortFri": "Fri", - "lang_shortFriday": "Fri", "lang_shortMon": "Mon", - "lang_shortMonday": "Mon", "lang_shortSat": "Sat", - "lang_shortSaturday": "Sat", "lang_shortSun": "Sun", - "lang_shortSunday": "Sun", "lang_shortThu": "Thu", - "lang_shortThursday": "Thu", "lang_shortTue": "Tue", - "lang_shortTuesday": "Tue", "lang_shortWed": "Wed", - "lang_shortWednesday": "Wed", "lang_showHostname": "Show hostname", "lang_showLog": "Log", "lang_slxbrowser": "SLX Browser", diff --git a/modules-available/locationinfo/page.inc.php b/modules-available/locationinfo/page.inc.php index bc918765..df5b3632 100644 --- a/modules-available/locationinfo/page.inc.php +++ b/modules-available/locationinfo/page.inc.php @@ -747,83 +747,101 @@ class Page_LocationInfo extends Page 'id' => $id, 'serverlist' => $serverList, 'serverlocationid' => $locConfig['serverlocationid'], + 'openingtimes' => $this->compressTimes($openingtimes), ); - $data['expertMode'] = !$this->isSimpleMode($openingtimes); - // !! isSimpleMode might have changed $openingtimes, so order is important here... - $data['schedule_data'] = json_encode($openingtimes); echo Render::parse('ajax-config-location', $data); } + private function fmtTime($time) + { + $t = explode(':', $time); + return sprintf('%02d:%02d', $t[0], $t[1]); + } + /** * Checks if simple mode or expert mode is active. * Tries to merge/compact the opening times schedule, and * will actually modify the passed array iff it can be - * transformed into easy opening times. + * transformed into simple opening times. * - * @param array $array of the saved openingtimes. - * @return bool True if simple mode, false if expert mode + * @return array new optimized openingtimes */ - private function isSimpleMode(&$array) + private function compressTimes(&$array) { if (empty($array)) - return true; + return []; // Decompose by day - $new = array(); + $DAYLIST = array_flip(['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']); + $new = []; foreach ($array as $row) { $s = $this->getTime($row['openingtime']); $e = $this->getTime($row['closingtime']); if ($s === false || $e === false || $e <= $s) continue; foreach ($row['days'] as $day) { + $day = $DAYLIST[$day] ?? -1; + if ($day === -1) + continue; $this->addDay($new, $day, $s, $e); } } - // Merge by timespan, but always keep saturday and sunday separate - $merged = array(); + // Merge by timespan + $merged = []; foreach ($new as $day => $ranges) { foreach ($ranges as $range) { - if ($day === 'Saturday' || $day === 'Sunday') { - $add = $day; - } else { - $add = ''; + $range = $range[0] . '#' . $range[1]; + if (!isset($merged[$range])) { + $merged[$range] = []; } - $key = '#' . $range[0] . '#' . $range[1] . '#' . $add; - if (!isset($merged[$key])) { - $merged[$key] = array(); - } - $merged[$key][$day] = true; + $merged[$range][$day] = true; } } - // Check if it passes as simple mode - if (count($merged) > 3) - return false; - foreach ($merged as $days) { - if (count($days) === 5) { - $res = array_keys($days); - $res = array_intersect($res, array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday")); - if (count($res) !== 5) - return false; - } elseif (count($days) === 1) { - if (!isset($days['Saturday']) && !isset($days['Sunday'])) { - return false; - } + // Finally transform to display struct + $new = []; + foreach ($merged as $span => $days) { + $out = explode('#', $span); + $new[] = [ + 'days' => $this->buildDaysString(array_keys($days)), + 'open' => sprintf('%02d:%02d', ($out[0] / 60), ($out[0] % 60)), + 'close' => sprintf('%02d:%02d', ($out[1] / 60), ($out[1] % 60)), + ]; + } + return $new; + } + + /** + * @param array $daysArray List of days, "Monday", "Tuesday" etc. Must not contain duplicates. + * @return string Human readable representation of list of days + */ + private function buildDaysString(array $daysArray) + { + /* Dictionary::translate('monday') Dictionary::translate('tuesday') Dictionary::translate('wednesday') + * Dictionary::translate('thursday') Dictionary::translate('friday') Dictionary::translate('saturday') + * Dictionary::translate('sunday') + */ + $DAYLIST = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday']; + $output = []; + $first = $last = -1; + sort($daysArray); + $daysArray[] = -1; // One trailing element to enforce a flush + foreach ($daysArray as $day) { + if ($first === -1) { + $first = $last = $day; + } elseif ($last + 1 === $day) { + // Chain + $last++; } else { - return false; + $string = Dictionary::translate($DAYLIST[$first], true); + if ($first !== $last) { + $string .= ($first + 1 === $last ? ",\xe2\x80\x89" : "\xe2\x80\x89-\xe2\x80\x89") + . Dictionary::translate($DAYLIST[$last], true); + } + $output[] = $string; + $first = $last = $day; } } - // Valid simple mode, finally transform back to what we know - $new = array(); - foreach ($merged as $span => $days) { - preg_match('/^#(\d+)#(\d+)#/', $span, $out); - $new[] = array( - 'days' => array_keys($days), - 'openingtime' => floor($out[1] / 60) . ':' . ($out[1] % 60), - 'closingtime' => floor($out[2] / 60) . ':' . ($out[2] % 60), - ); - } - $array = $new; - return true; + return implode(', ', $output); } private function addDay(&$array, $day, $s, $e) diff --git a/modules-available/locationinfo/templates/ajax-config-location.html b/modules-available/locationinfo/templates/ajax-config-location.html index 530207f6..a5e7e45e 100644 --- a/modules-available/locationinfo/templates/ajax-config-location.html +++ b/modules-available/locationinfo/templates/ajax-config-location.html @@ -1,89 +1,13 @@ -
-

{{lang_openingTime}}

- - {{^expertMode}} -
- -
- - - - - - - - - - - - - - - - - - - - - - -
{{lang_day}}{{lang_openingTime}}{{lang_closingTime}}
{{lang_monTilFr}} -
- - - - -
-
-
- - - - -
-
{{lang_saturday}} -
- - - - -
-
-
- - - - -
-
{{lang_sunday}} -
- - - - -
-
-
- - - - -
-
-
- {{/expertMode}} - -
-
-
-
-
{{lang_openingTime}}
-
{{lang_closingTime}}
-
-
-
-
+

{{lang_openingTime}}

+ + {{#openingtimes}} + + + + + {{/openingtimes}} +
{{days}}{{open}} - {{close}}
@@ -93,7 +17,6 @@

-

{{lang_remoteSchedule}}

@@ -134,76 +57,3 @@ {{lang_roomIdTooltip}}
- - - - diff --git a/modules-available/locationinfo/templates/page-config-panel-default.html b/modules-available/locationinfo/templates/page-config-panel-default.html index 1ffef408..447a8834 100644 --- a/modules-available/locationinfo/templates/page-config-panel-default.html +++ b/modules-available/locationinfo/templates/page-config-panel-default.html @@ -60,7 +60,10 @@
- +
+ + +
{{lang_ecoTooltip}} @@ -74,7 +77,10 @@
- +
+ + +
{{lang_prettytimeTooltip}} @@ -198,7 +204,10 @@
- +
+ + +
{{lang_autoscaleTooltip}} @@ -253,7 +262,10 @@
- +
+ + +
{{lang_hostnameTooltip}} diff --git a/modules-available/locationinfo/templates/page-config-panel-summary.html b/modules-available/locationinfo/templates/page-config-panel-summary.html index b909f873..a7a34217 100644 --- a/modules-available/locationinfo/templates/page-config-panel-summary.html +++ b/modules-available/locationinfo/templates/page-config-panel-summary.html @@ -56,7 +56,10 @@
- +
+ + +
{{lang_ecoTooltip}} @@ -191,9 +194,6 @@ document.addEventListener("DOMContentLoaded", function () { $(this).siblings().find('.range-display').text($(this).val()); }); // Set state of input controls that aren't statically initialized server side - $('.modify-inputs input[type="checkbox"]') - .bootstrapSwitch({size: 'small'}); - var lids = $locInput.val().split(','); $selLocs.empty(); for (var i = 0; i < lids.length; ++i) { diff --git a/modules-available/locationinfo/templates/page-locations.html b/modules-available/locationinfo/templates/page-locations.html index 553df648..fa2e3a2d 100644 --- a/modules-available/locationinfo/templates/page-locations.html +++ b/modules-available/locationinfo/templates/page-locations.html @@ -65,8 +65,7 @@
- + -- cgit v1.2.3-55-g7522