From: Michael Prager Date: Tue, 29 Mar 2011 00:38:19 +0000 (+0200) Subject: reload calendar data every 6 hours only, updating display without actually reloading... X-Git-Url: https://code.delx.au/comingnext/commitdiff_plain/f74aa516d56123c086ced32163a486cc0854214a reload calendar data every 6 hours only, updating display without actually reloading anything. --- diff --git a/comingNext/index.html b/comingNext/index.html index 2dd85d7..b0f844c 100644 --- a/comingNext/index.html +++ b/comingNext/index.html @@ -99,8 +99,11 @@ var calendarList = []; var calendarColors = []; var updateTimer = null; var screenRotationTimer = null; -var lastUpdateTime = now; +var lastUpdateTime = now; // last time we updated the display +var lastReloadTime = null; // last time we fetched calendar data +var reloadInterval = 6 * 60 * 60 * 1000; // = 6 hours; time interval for reloading calendar data var errorOccured = false; +var entryLists = null; // stores all fetched calendar entries until data is refreshed // vars for daylight saving time var summertime = false; // true, if current date is in summer, false if in winter @@ -365,6 +368,7 @@ function cancelNotification() function callback(transId, eventCode, result) { log("callback(): panelNum: %d transId: %d eventCode: %d result.ErrorCode: %d", panelNum, transId, eventCode, result.ErrorCode); + lastReloadTime = null; // force calendar data reload on next update updateData(); } @@ -531,65 +535,72 @@ function updateData() updateCalendarColors(); cancelNotification(); requestNotification(); + lastReloadTime = null; // force calendar data reload on this update } - - try { - // meetings have time - // note: anniveraries have a start time of 12:00am. So since we want to include them, we have to query the whole day and check if events have passed later - now = new Date(); - summertime = isSummertime(now); // cache summer time info for today - var meetingList = []; - for(var i=0; i < calendarList.length; i++) { - // ignore excluded calendars - if (config['excludedCalendars'].Value.indexOf(calendarList[i]) != -1) - continue; - var meetingListFiltering = { - Type:'CalendarEntry', - Filter:{ - CalendarName: calendarList[i], - StartRange: (new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 0)), - EndRange: (new Date(now.getFullYear(), now.getMonth() + config['monthRange'].Value, now.getDate(), 0, 0, 0)) - } - } - var meetingResult = calendarService.IDataSource.GetList(meetingListFiltering); - if (meetingResult.ErrorCode != 0) - throw("Error fetching calendar data: " + meetingResult.ErrorCode + ': ' + meetingResult.ErrorMessage); - var list = meetingResult.ReturnValue; - meetingList = meetingList.concat(listToArray(list, calendarList[i])); - } - console.info("updateData(): meetingList.sort()"); - meetingList.sort(sortCalendarEntries); - // todos don't, they start on 00:00 hrs., but should be visible anyway - // this will generate a list of passed todos. We have to check if they have been marked as "done" yet - if (config['includeTodos'].Value) { - var todayTodoList = []; + now = new Date(); + + // only reload calendar data every 6 hours, visual updates occure more often + if (!lastReloadTime || now.getTime() - lastReloadTime.getTime() > reloadInterval) { + log('updateData(): reloading calendar data'); + try { + // meetings have time + // note: anniveraries have a start time of 12:00am. So since we want to include them, we have to query the whole day and check if events have passed later + summertime = isSummertime(now); // cache summer time info for today + var meetingList = []; for(var i=0; i < calendarList.length; i++) { // ignore excluded calendars if (config['excludedCalendars'].Value.indexOf(calendarList[i]) != -1) continue; - var todayTodoListFiltering = { + var meetingListFiltering = { Type:'CalendarEntry', Filter:{ CalendarName: calendarList[i], - Type: 'ToDo', - StartRange: (new Date(now.getFullYear() - 1, now.getMonth(), now.getDate(), 0, 0, 0)), - EndRange: (new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 1)) + StartRange: (new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 0)), + EndRange: (new Date(now.getFullYear(), now.getMonth() + config['monthRange'].Value, now.getDate(), 0, 0, 0)) + } + } + var meetingResult = calendarService.IDataSource.GetList(meetingListFiltering); + if (meetingResult.ErrorCode != 0) + throw("Error fetching calendar data: " + meetingResult.ErrorCode + ': ' + meetingResult.ErrorMessage); + var list = meetingResult.ReturnValue; + meetingList = meetingList.concat(listToArray(list, calendarList[i])); + } + log("updateData(): meetingList.sort()"); + meetingList.sort(sortCalendarEntries); + + // todos don't, they start on 00:00 hrs., but should be visible anyway + // this will generate a list of passed todos. We have to check if they have been marked as "done" yet + if (config['includeTodos'].Value) { + var todayTodoList = []; + for(var i=0; i < calendarList.length; i++) { + // ignore excluded calendars + if (config['excludedCalendars'].Value.indexOf(calendarList[i]) != -1) + continue; + var todayTodoListFiltering = { + Type:'CalendarEntry', + Filter:{ + CalendarName: calendarList[i], + Type: 'ToDo', + StartRange: (new Date(now.getFullYear() - 1, now.getMonth(), now.getDate(), 0, 0, 0)), + EndRange: (new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 1)) + } } + var todayTodoResult = calendarService.IDataSource.GetList(todayTodoListFiltering); + var list = todayTodoResult.ReturnValue; + todayTodoList = todayTodoList.concat(listToArray(list, calendarList[i])); } - var todayTodoResult = calendarService.IDataSource.GetList(todayTodoListFiltering); - var list = todayTodoResult.ReturnValue; - todayTodoList = todayTodoList.concat(listToArray(list, calendarList[i])); + log("updateData(): todayTodoList.sort()"); + todayTodoList.sort(sortCalendarEntries); + entryLists = [todayTodoList, meetingList]; + } else { + entryLists = [meetingList]; } - console.info("updateData(): todayTodoList.sort()"); - todayTodoList.sort(sortCalendarEntries); - var entryLists = [todayTodoList, meetingList]; - } else { - var entryLists = [meetingList]; + lastReloadTime = new Date(); + } catch(e) { + error('loading Calendar items list:' + e + ', line ' + e.line); + return; } - } catch(e) { - error('loading Calendar items list:' + e + ', line ' + e.line); - return; } try { @@ -622,16 +633,18 @@ function updateData() else max = 30; // we can display a lot more events in fullscreen mode - var listinfo = ""; - for (var i=0; i < entryLists.length; i++) { - listinfo = listinfo + " " + entryLists[i].length; - var entrieslist = ""; - for (var j=0; j < entryLists[i].length; j++) { - entrieslist += entryLists[i][j].Summary + ", "; + if (config['enableLogging'].Value) { + var listinfo = ""; + for (var i=0; i < entryLists.length; i++) { + listinfo = listinfo + " " + entryLists[i].length; + var entrieslist = ""; + for (var j=0; j < entryLists[i].length; j++) { + entrieslist += entryLists[i][j].Summary + ", "; + } + log("updateData(): entrieslist: " + entrieslist); } - console.info("updateData(): entrieslist: " + entrieslist); + log("updateData(): inner loop, " + entryLists.length + " lists, [" + listinfo + "] entries"); } - console.info("updateData(): inner loop, " + entryLists.length + " lists, [" + listinfo + "] entries"); // the first outer loop iteration is for passed ToDos, the second loop is for all upcomming events (may also include ToDos) for (var i=0; counter < max && i < entryLists.length; i++) { @@ -1176,6 +1189,7 @@ function saveSettings() error("saveSettings: " + e + ', line ' + e.line); } + lastReloadTime = null; // force calendar data reload on next update clearUpdateTimer(); setUpdateTimer(); }