From 8997e05128a99bf7e61cb09b0552befc9055e79e Mon Sep 17 00:00:00 2001 From: j Date: Fri, 29 Oct 2021 15:04:34 +0100 Subject: [PATCH] to E: or not to E: --- app/static/js/ascroll.js | 17 +++++++++++++++-- app/text/models.py | 8 +++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/app/static/js/ascroll.js b/app/static/js/ascroll.js index 845f12b..cf610ac 100755 --- a/app/static/js/ascroll.js +++ b/app/static/js/ascroll.js @@ -339,7 +339,18 @@ function loadAnnotations(config) { return !(config.user && annotation.user != config.user) }) loadClips(annotations).then(annotations => { - config.annotations = annotations + config.annotations = annotations.filter(annotation => { + if (config.only_e) { + if (annotation.value.slice(0, 2) == 'E:') { + annotation.value = annotation.value.slice(2).trim() + return true + } else { + return false + } + } else { + return annotation.value.slice(0, 2) != 'E:' + } + }) renderAnnotations(config) }) }) @@ -358,7 +369,9 @@ function loadAnnotations(config) { annotations.push(annotation) } } else { - annotations.push(annotation) + if (annotation.value.slice(0, 2) != 'E:') { + annotations.push(annotation) + } } }) }) diff --git a/app/text/models.py b/app/text/models.py index c633c36..51faf99 100644 --- a/app/text/models.py +++ b/app/text/models.py @@ -79,6 +79,12 @@ class Text(models.Model): user = self.data.get('user', None) if user: annotations = list(filter(lambda annot: annot['user'] == user, annotations)) + if self.data.get('only_e'): + annotations = [e for e in annotations if e['value'].startswith('E:')] + for e in annotations: + e['value'] = e['value'][2:].strip() + else: + annotations = [e for e in annotations if not e['value'].startswith('E:')] return self.get_clips(api, annotations) def get_edit_annotations(self, api): @@ -101,7 +107,7 @@ class Text(models.Model): if annotation['value'].startswith('E:'): annotation['value'] = annotation['value'][2:].strip() annotations.append(annotation) - else: + elif not annotation['value'].startswith('E:'): annotations.append(annotation) return self.get_clips(api, annotations)