From 426b09b7e1e3913cb9cdadf639f11c04fecbe3d3 Mon Sep 17 00:00:00 2001 From: Leigh Morresi <275001+dgtlmoon@users.noreply.github.com> Date: Thu, 11 Feb 2021 10:36:54 +0100 Subject: [PATCH] Make records in the overview that have a difference that have not been viewed in the [diff] tab bold --- backend/backend.py | 4 ++++ backend/static/css/styles.css | 6 ++++++ backend/store.py | 29 ++++++++++++++++++++++++++- backend/templates/watch-overview.html | 4 +++- 4 files changed, 41 insertions(+), 2 deletions(-) diff --git a/backend/backend.py b/backend/backend.py index d76c1618..0a007d71 100644 --- a/backend/backend.py +++ b/backend/backend.py @@ -90,6 +90,8 @@ def main_page(): # Sort by last_changed and add the uuid which is usually the key.. sorted_watches = [] for uuid, watch in datastore.data['watching'].items(): + + if limit_tag != None: # Support for comma separated list of tags. for tag_in_watch in watch['tag'].split(','): @@ -249,6 +251,8 @@ def diff_history_page(uuid): dates.sort(reverse=True) dates = [str(i) for i in dates] + # Save the current newest history as the most recently viewed + datastore.set_last_viewed(uuid, dates[0]) newest_file = watch['history'][dates[0]] with open(newest_file, 'r') as f: diff --git a/backend/static/css/styles.css b/backend/static/css/styles.css index c61e36c9..6b7450fd 100644 --- a/backend/static/css/styles.css +++ b/backend/static/css/styles.css @@ -48,7 +48,13 @@ section.content { /* table related */ .watch-table { width: 100%; + } + +.watch-table tr.unviewed { + font-weight: bold; +} + .watch-tag-list { color: #e70069; white-space: nowrap; diff --git a/backend/store.py b/backend/store.py index 0ac09419..f68d60e8 100644 --- a/backend/store.py +++ b/backend/store.py @@ -41,6 +41,8 @@ class ChangeDetectionStore: 'tag': None, 'last_checked': 0, 'last_changed': 0, + 'last_viewed': 0, # history key value of the last viewed via the [diff] link + 'newest_history_key': "", 'title': None, 'previous_md5': "", 'uuid': str(uuid_builder.uuid4()), @@ -77,7 +79,8 @@ class ChangeDetectionStore: _blank = deepcopy(self.generic_definition) _blank.update(watch) self.__data['watching'].update({uuid: _blank}) - print("Watching:", uuid, _blank['url']) + self.__data['watching'][uuid]['newest_history_key'] = self.get_newest_history_key(uuid) + print("Watching:", uuid, self.__data['watching'][uuid]['url']) # First time ran, doesnt exist. except (FileNotFoundError, json.decoder.JSONDecodeError): @@ -87,6 +90,28 @@ class ChangeDetectionStore: self.add_watch(url='https://www.gov.uk/coronavirus', tag='Covid') self.add_watch(url='https://changedetection.io', tag='Tech news') + # Returns the newest key, but if theres only 1 record, then it's counted as not being new, so return 0. + def get_newest_history_key(self, uuid): + if len(self.__data['watching'][uuid]['history']) == 1: + return 0 + + dates = list(self.__data['watching'][uuid]['history'].keys()) + # Convert to int, sort and back to str again + dates = [int(i) for i in dates] + dates.sort(reverse=True) + if len(dates): + # always keyed as str + return str(dates[0]) + + return 0 + + + + + def set_last_viewed(self, uuid, timestamp): + self.data['watching'][uuid].update({'last_viewed': str(timestamp)}) + self.needs_write = True + def update_watch(self, uuid, update_obj): with self.lock: @@ -99,11 +124,13 @@ class ChangeDetectionStore: del(update_obj[dict_key]) self.__data['watching'][uuid].update(update_obj) + self.__data['watching'][uuid]['newest_history_key'] = self.get_newest_history_key(uuid) self.needs_write = True @property def data(self): + return self.__data def get_all_tags(self): diff --git a/backend/templates/watch-overview.html b/backend/templates/watch-overview.html index 7777bd36..573a05b4 100644 --- a/backend/templates/watch-overview.html +++ b/backend/templates/watch-overview.html @@ -41,7 +41,9 @@ {% for watch in watches %}