From f57731abf206bf3030a7a95a9019aa398c3dea2e Mon Sep 17 00:00:00 2001 From: Christian Hofmaier Date: Mon, 3 Dec 2018 19:03:24 +0100 Subject: [locationinfo] add new settings for panels (counter, updaterate) - setting: consider only clients in roomplaner, instead of ip range - add option to set update rate in summary panels - directly initialize when mode is "only calendar" - Set counter to "-" if room has ongoing event - fix some spelling / unused code --- .../locationinfo/templates/frontend-summary.html | 74 ++++++---------------- 1 file changed, 20 insertions(+), 54 deletions(-) (limited to 'modules-available/locationinfo/templates/frontend-summary.html') diff --git a/modules-available/locationinfo/templates/frontend-summary.html b/modules-available/locationinfo/templates/frontend-summary.html index 4105dd16..0053d1ff 100644 --- a/modules-available/locationinfo/templates/frontend-summary.html +++ b/modules-available/locationinfo/templates/frontend-summary.html @@ -116,6 +116,7 @@ var startdate; var roomidsString = ""; var config = {{{config}}}; + var lastPanelUpdate = 0; $(document).ready(function () { init(); @@ -139,6 +140,7 @@ SetUpDate(time); generateLayout(config.tree); update(); + setInterval(update, 10000); } function SetUpDate(d) { @@ -165,7 +167,7 @@ */ function generateObject(json, myParent, outermost) { var obj; - if (!json.children || json.children.length == 0) { + if (!json.children || json.children.length === 0) { obj = generateChild(myParent, json.locationid, json.locationname, outermost); } else { obj = generateParent(myParent, json.locationid, json.locationname, outermost); @@ -178,59 +180,24 @@ } /** - * Helper function to generate id string used in query functions - * @param list A string, wicht contains ids or not(for now) - * @param id An ID which should be added to the list + * Main Update loop, this loop runs every 10 seconds */ - function addIdToUpdateList(list, id) { - if (list == "") { - list += id; - } else { - list += ("," + id); - } - return list; - } - - - const ROOMUPDATE_MS = 2*60*1000; - const CALUPDATE_MS = 20*60*1000; - var timeout = null; - function update() { - var calendarUpdateIds = ""; - var rommUpdateIds = ""; - var count = 0; - var nextUpdate = 15000; - var property; - // TODO: Only query a few rooms is not possible with the new api stuff ... - for (property in rooms) { - if (rooms[property].lastCalendarUpdate === null || rooms[property].lastCalendarUpdate + CALUPDATE_MS < MyDate().getTime()) { - // TODO: NOT NECESSARY ANYMORE?! - calendarUpdateIds = addIdToUpdateList(calendarUpdateIds, rooms[property].id); - count++; - rooms[property].lastCalendarUpdate = MyDate().getTime(); - } - if (rooms[property].lastRoomUpdate === null || rooms[property].lastRoomUpdate + ROOMUPDATE_MS < MyDate().getTime()) { - // TODO: NOT NECESSARY ANYMORE?! - rommUpdateIds = addIdToUpdateList(rommUpdateIds, rooms[property].id); - count++; - rooms[property].lastRoomUpdate = MyDate().getTime(); - } - // TODO if (count > 7) break; - } - if (calendarUpdateIds !== "") { - queryCalendars(); - nextUpdate = 1000; - } - if (rommUpdateIds !== "") { + var date = MyDate(); + var now = date.getTime(); + if (lastPanelUpdate + (config.panelupdate * 1000) < now) { + // Set Roomupdate Interval has passed, update. queryRooms(); - nextUpdate = 1000; - } - if (nextUpdate !== 1000) { + queryCalendars(); + lastPanelUpdate = now; + for (var property in rooms) { + rooms[property].lastCalendarUpdate = now; + rooms[property].lastRoomUpdate = now; + } + } else { + // Set Roomupdate Interval has NOT passed, check if panel was changed since last call and reload if true. queryPanelChange(); } - clearTimeout(timeout); - setTimeout(update, nextUpdate); } function cleanDate(d) { @@ -283,7 +250,6 @@ cache: false, timeout: 30000, success: function (result) { - var l = result.length; if (result[0] == null) { console.log("Error: Backend reported null back for RoomUpdate, this might happend if the room isn't" + "configurated."); @@ -331,7 +297,7 @@ function updatePcStates(json) { var l = json.length; for (var i = 0; i < l; i++) { - updateRoomUsage(json[i].id, json[i].idle, json[i].occupied, json[i].offline, json[i].broken, json[i].standby) + updateRoomUsage(json[i].id, json[i].idle, json[i].occupied, json[i].offline, json[i].broken, json[i].standby); } } @@ -428,8 +394,8 @@ /** * computes state of a room, states are: - * closed, FreeNoEnd, Free, ClaendarEvent. - * @param Room Object + * closed, FreeNoEnd, Free, CalendarEvent. + * @param room Object */ function ComputeCurrentState(room) { if (room.lastRoomUpdate === null) { @@ -479,7 +445,7 @@ /** * checks if a room is open * @param room Room object - * @returns bool for open or not + * @returns boolean for open or not */ function IsOpenNow(room) { var now = new MyDate(); -- cgit v1.2.3-55-g7522 From 7d9cf0a24308b2204fd063cc2fd0ef0af7f59d50 Mon Sep 17 00:00:00 2001 From: Christian Hofmaier Date: Tue, 4 Dec 2018 17:15:39 +0100 Subject: [locationinfo] fix panel being closed all day long in summary --- modules-available/locationinfo/templates/frontend-summary.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules-available/locationinfo/templates/frontend-summary.html') diff --git a/modules-available/locationinfo/templates/frontend-summary.html b/modules-available/locationinfo/templates/frontend-summary.html index 0053d1ff..adb3ce39 100644 --- a/modules-available/locationinfo/templates/frontend-summary.html +++ b/modules-available/locationinfo/templates/frontend-summary.html @@ -466,7 +466,7 @@ var closeDate = new MyDate(); closeDate.setHours(tmp[i].HourClose); closeDate.setMinutes(tmp[i].MinutesClose); - if (openDate < now && closeDate > now) { + if (openDate <= now && closeDate > now) { return true; } } -- cgit v1.2.3-55-g7522 From dad607e72ee87f40e91dc3c5f342e8df10e3b088 Mon Sep 17 00:00:00 2001 From: Christian Hofmaier Date: Sat, 8 Dec 2018 15:59:50 +0100 Subject: [locationinfo] fix summary pannel always in german --- .../locationinfo/templates/frontend-summary.html | 46 ++++++++++++++++++++-- 1 file changed, 42 insertions(+), 4 deletions(-) (limited to 'modules-available/locationinfo/templates/frontend-summary.html') diff --git a/modules-available/locationinfo/templates/frontend-summary.html b/modules-available/locationinfo/templates/frontend-summary.html index adb3ce39..a3fa77b0 100644 --- a/modules-available/locationinfo/templates/frontend-summary.html +++ b/modules-available/locationinfo/templates/frontend-summary.html @@ -1,5 +1,5 @@ - + @@ -108,6 +108,10 @@ border-radius: 1px; } + #i18n { + display: none; + } +
+ +
+ {{lang_room}} + {{lang_closed}} + {{lang_free}} + {{lang_shortSun}} + {{lang_shortMon}} + {{lang_shortTue}} + {{lang_shortWed}} + {{lang_shortThu}} + {{lang_shortFri}} + {{lang_shortSat}} + {{lang_longSun}} + {{lang_longMon}} + {{lang_longTue}} + {{lang_longWed}} + {{lang_longThu}} + {{lang_longFri}} + {{lang_longSat}} + {{lang_to}} +
-- cgit v1.2.3-55-g7522 From ebea4443c841d41f2ceac41d11626840842e3228 Mon Sep 17 00:00:00 2001 From: Christian Hofmaier Date: Tue, 11 Dec 2018 16:06:01 +0100 Subject: [locationinfo] fix summary panel showing "closed" when room without opening times --- .../locationinfo/templates/frontend-summary.html | 112 ++++++++------------- 1 file changed, 44 insertions(+), 68 deletions(-) (limited to 'modules-available/locationinfo/templates/frontend-summary.html') diff --git a/modules-available/locationinfo/templates/frontend-summary.html b/modules-available/locationinfo/templates/frontend-summary.html index a3fa77b0..ecb41467 100644 --- a/modules-available/locationinfo/templates/frontend-summary.html +++ b/modules-available/locationinfo/templates/frontend-summary.html @@ -279,7 +279,7 @@ var state = room.getState(); if (state.state == "CalendarEvent") { - updateCourseText(room.id, state.titel); + updateCourseText(room.id, state.title); updateCoursTimer(room.id, GetTimeDiferenceAsString(state.end, MyDate())); } else if (state.state == "Free") { updateCourseText(room.id, t("free")); @@ -287,8 +287,7 @@ } else if (state.state == "FreeNoEnd") { updateCourseText(room.id, t("free")); updateCoursTimer(room.id, ""); - } - else if (state.state == "closed") { + } else if (state.state == "closed") { updateCourseText(room.id, t("closed")); updateCoursTimer(room.id, ""); } @@ -402,105 +401,82 @@ * @param room Object */ function ComputeCurrentState(room) { - if (room.lastRoomUpdate === null) { - room.state = {state: 'unknown'}; + if (!IsOpen(MyDate(), room)) { + room.state = {state: "closed", end: GetNextOpening(room), title: "", next: ""}; return; } - if (!IsOpenNow(room)) { - room.state = {state: "closed", end: GetNextOpening(room), titel: "", next: ""}; - return; - } - var closing = GetNextClosing(room); + console.log("Timetable", room.id, room.timetable); + var closing = GetNextClosing(room); var event = getNextEvent(room.timetable); + + console.log("Event", room.id, event); + // no event and no closing - if (closing == null && event == null) { - room.state = {state: "FreeNoEnd", end: "", titel: "", next: ""}; + if (!closing && !event) { + room.state = {state: "FreeNoEnd", end: "", title: "", next: "", free: true}; return; } // no event so closing is next - if (event == null) { - room.state = {state: "Free", end: closing, titel: "", next: "closing"}; + if (!event) { + room.state = {state: "Free", end: closing, title: "", next: "closing", free: true}; return; } // event is at the moment - if ((closing == null || event.start.getTime() < closing.getTime()) && event.start.getTime() < new MyDate()) { - room.state = {state: "CalendarEvent", end: event.end, titel: event.title, next: ""}; + if ((!closing || event.start.getTime() < closing.getTime()) && event.start.getTime() < MyDate()) { + room.state = { + state: "CalendarEvent", + end: event.end, + title: event.title, + next: "" + }; + console.log("CalendarEvent", room.id, room.state); return; } // no closing so event is next - if (closing == null) { - room.state = {state: "Free", end: event.start, titel: "", next: "event"}; + if (!closing) { + room.state = {state: "Free", end: event.start, title: "", next: "event", free: true}; return; } // event sooner then closing if (event.start.getTime() < closing) { - room.state = {state: "Free", end: event.start, titel: "", next: "event"}; - } else if (event.start.getTime() > closing) { - room.state = {state: "Free", end: closing, titel: "", next: "closing"}; - } - } - - /** - * checks if a room is open - * @param room Room object - * @returns boolean for open or not - */ - function IsOpenNow(room) { - var now = new MyDate(); - if (room.openingTimes == null) { - - // changes from falls needs testing - return true; + room.state = {state: "Free", end: event.start, title: "", next: "event", free: true}; + } else { + room.state = {state: "Free", end: closing, title: "", next: "closing", free: true}; } - var tmp = room.openingTimes[now.getDay()]; - if (tmp == null) { - return false; - } - for (var i = 0; i < tmp.length; i++) { - var openDate = new MyDate(); - openDate.setHours(tmp[i].HourOpen); - openDate.setMinutes(tmp[i].MinutesOpen); - var closeDate = new MyDate(); - closeDate.setHours(tmp[i].HourClose); - closeDate.setMinutes(tmp[i].MinutesClose); - if (openDate <= now && closeDate > now) { - return true; - } - } - return false; } /** * returns next event from a given json of events - * @param json Json which contains the calendar data. - * @returns event next Carlendar Event + * @param calEvents Json which contains the calendar data. + * @returns event next Calendar Event */ - function getNextEvent(json) { - if (json == null) { - return; - } - var event; - var now = new MyDate(); - for (var i = 0; i < json.length; i++) { + function getNextEvent(calEvents) { + if (!calEvents) return null; + if (calEvents.constructor !== Array) { + console.log('getNextEvent called with something not array: ' + typeof(calEvents)); + return null; + } + var event = null; + var now = MyDate(); + for (var i = 0; i < calEvents.length; i++) { //event is now active - if (json[i].start.getTime() < now.getTime() && json[i].end.getTime() > now.getTime()) { - return json[i]; + if (calEvents[i].start.getTime() < now.getTime() && calEvents[i].end.getTime() > now.getTime()) { + return calEvents[i]; } //first element to consider - if (event == null) { - if (json[i].start.getTime() > now.getTime()) { - event = json[i]; + if (!event) { + if (calEvents[i].start.getTime() > now.getTime()) { + event = calEvents[i]; } - } - if (json[i].start.getTime() > now.getTime() && event.start.getTime() > json[i].start.getTime()) { - event = json[i]; + } else if (calEvents[i].start.getTime() > now.getTime() && event.start.getTime() > calEvents[i].start.getTime()) { + event = calEvents[i]; } } return event; -- cgit v1.2.3-55-g7522