From cf9cf089478d5713e83339e02d4164efaa30ed28 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 19 Dec 2017 12:35:22 +0100 Subject: [locationinfo] Fix infinite reload loop --- .../locationinfo/inc/infopanel.inc.php | 3 +- .../locationinfo/templates/frontend-summary.html | 32 ++++++++++++++++++++-- 2 files changed, 30 insertions(+), 5 deletions(-) (limited to 'modules-available/locationinfo') diff --git a/modules-available/locationinfo/inc/infopanel.inc.php b/modules-available/locationinfo/inc/infopanel.inc.php index 12b6aec7..edeb9ccf 100644 --- a/modules-available/locationinfo/inc/infopanel.inc.php +++ b/modules-available/locationinfo/inc/infopanel.inc.php @@ -12,7 +12,7 @@ class InfoPanel */ public static function getConfig($paneluuid, &$config) { - $panel = Database::queryFirst('SELECT panelname, panelconfig, paneltype, locationids, lastchange FROM locationinfo_panel WHERE paneluuid = :paneluuid', + $panel = Database::queryFirst('SELECT panelname, panelconfig, paneltype, locationids FROM locationinfo_panel WHERE paneluuid = :paneluuid', compact('paneluuid')); if ($panel === false) { @@ -68,7 +68,6 @@ class InfoPanel } self::appendOpeningTimes($config['locations'], $lids); - $config['ts'] = (int)$panel['lastchange']; $config['locations'] = array_values($config['locations']); $config['time'] = date('Y-n-j-G-') . (int)date('i') . '-' . (int)(date('s')); diff --git a/modules-available/locationinfo/templates/frontend-summary.html b/modules-available/locationinfo/templates/frontend-summary.html index ec5d8aab..4105dd16 100644 --- a/modules-available/locationinfo/templates/frontend-summary.html +++ b/modules-available/locationinfo/templates/frontend-summary.html @@ -226,8 +226,8 @@ queryRooms(); nextUpdate = 1000; } - for (property in rooms) { - upDateRoomState(rooms[property]); + if (nextUpdate !== 1000) { + queryPanelChange(); } clearTimeout(timeout); setTimeout(update, nextUpdate); @@ -267,7 +267,9 @@ } ComputeCurrentState(rooms[json[i].id]); } - update(); + for (property in rooms) { + upDateRoomState(rooms[property]); + } } /** @@ -765,6 +767,30 @@ }); } + /** + * Checks whether the panel has been edited and reloads + * the entire page if so. + */ + function queryPanelChange() { + $.ajax({ + url: "{{dirprefix}}api.php?do=locationinfo&get=timestamp&uuid={{uuid}}", + dataType: 'json', + cache: false, + timeout: 5000, + success: function (result) { + if (!result || !result.ts) { + console.log('Warning: get=timestamp didnt return json with ts field'); + return; + } + if (config.ts && config.ts !== result.ts) { + // Change + window.location.reload(true); + } + config.ts = result.ts; + } + }) + } + -- cgit v1.2.3-55-g7522