From 5ca3cffdd990996fdc772207af525df634cd0b94 Mon Sep 17 00:00:00 2001 From: Ruben van de Ven Date: Fri, 14 Jun 2019 20:47:59 +0200 Subject: [PATCH] Save light status (not properly restored yet) and clearer status in timeline when running in a loop --- hugvey/central_command.py | 1 + hugvey/story.py | 5 ++++- www/js/hugvey_timeline.js | 5 +++-- www/timeline.html | 4 ++++ 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/hugvey/central_command.py b/hugvey/central_command.py index 07004e1..7c2b749 100644 --- a/hugvey/central_command.py +++ b/hugvey/central_command.py @@ -123,6 +123,7 @@ class CentralCommand(object): status['light_on'] = bool(hv.lightStatus) status['language'] = hv.language_code status['light_id'] = hv.lightId + status['available'] = hv.isAvailable() status['msg'] = hv.story.currentMessage.id if hv.story and hv.story.currentMessage else None # status['finished'] = hv.story.isFinished() status['history'] = {} if isSelected is False or not hv.story else hv.story.getLogSummary() diff --git a/hugvey/story.py b/hugvey/story.py index 4d9fba8..b74b082 100644 --- a/hugvey/story.py +++ b/hugvey/story.py @@ -1782,6 +1782,7 @@ class Story(object): fn = self.getStateFilename(self.hugvey.lightId) tmpfn = fn + '.tmp' self.stateSave = time.time() + self.lightStateSave = self.hugvey.lightStatus with open(tmpfn, 'wb') as fp: pickle.dump(self, fp) # write atomic to disk: flush, close, rename @@ -1805,9 +1806,11 @@ class Story(object): story = pickle.load(fp) story.hugvey = hugvey_state + #: :type story: Story story.logger = mainLogger.getChild(f"{story.hugvey.id}").getChild("story") + # TODO: this is not really working because it is overridden by the set-status later. + story.hugvey.setLightStatus(story.lightStateSave) return story - # TODO: take running state etc. @classmethod def clearSavedState(cls, hv_id): diff --git a/www/js/hugvey_timeline.js b/www/js/hugvey_timeline.js index 786303d..1020b88 100644 --- a/www/js/hugvey_timeline.js +++ b/www/js/hugvey_timeline.js @@ -95,8 +95,9 @@ checkbox.addEventListener('change', (event) => { if(msg['action'] == 'status') { for(let hv of msg['hugveys']){ console.log(hv['language'], hv['status']); - let evenOdd = parseInt(hv['id'])%2 ? 'odd': 'even' - this.dataGroups.update({id: parseInt(hv['id']), content: 'Hugvey #'+hv['id'], className: `status-${hv['status']} lang-${hv['language']} ${evenOdd}`}) + let evenOdd = parseInt(hv['id'])%2 ? 'odd': 'even'; + let availableClass = hv['available'] ? 'is-available' : 'is-not-available' + this.dataGroups.update({id: parseInt(hv['id']), content: 'Hugvey #'+hv['id'], className: `status-${hv['status']} ${availableClass} lang-${hv['language']} ${evenOdd}`}) } } diff --git a/www/timeline.html b/www/timeline.html index 94af64a..a228cbb 100644 --- a/www/timeline.html +++ b/www/timeline.html @@ -98,6 +98,10 @@ font-size: 20pt; .status-available{ background-color: #660; } +.status-running.is-available{ + /* When running in a loop, Hugvey is listening while available */ + background-color: #246f6f !important; +} .status-running.lang-en-GB{ background-color: #02547e;