From 40a24f4247069b337e28af61a623457ee4f68edb Mon Sep 17 00:00:00 2001 From: Alex Ling Date: Wed, 30 Dec 2020 05:35:28 +0000 Subject: [PATCH] Add tags to the web UI --- public/js/title.js | 30 ++++++++++++++++++++++++++++++ src/views/components/tags.html.ecr | 15 +++++++++++++++ src/views/title.html.ecr | 2 ++ 3 files changed, 47 insertions(+) create mode 100644 src/views/components/tags.html.ecr diff --git a/public/js/title.js b/public/js/title.js index d46c173..6f53265 100644 --- a/public/js/title.js +++ b/public/js/title.js @@ -252,3 +252,33 @@ const bulkProgress = (action, el) => { deselectAll(); }); }; + +const tagsComponent = () => { + return { + tags: tags, + newTag: '', + inputShown: false, + add() { + this.tags.push(this.newTag); + this.newTag = ''; + }, + keydown(event) { + if (event.key === 'Enter') + this.add() + }, + rm(event) { + const tag = event.currentTarget.id.split('-')[0]; + const idx = this.tags.indexOf(tag); + if (idx < 0) return; + this.tags.splice(idx, 1); + }, + toggleInput(nextTick) { + this.inputShown = !this.inputShown; + if (this.inputShown) { + nextTick(() => { + $('#tag-input').get(0).focus(); + }); + } + } + }; +}; diff --git a/src/views/components/tags.html.ecr b/src/views/components/tags.html.ecr new file mode 100644 index 0000000..a443393 --- /dev/null +++ b/src/views/components/tags.html.ecr @@ -0,0 +1,15 @@ + +
+

+ Tags: + + +

+ +
diff --git a/src/views/title.html.ecr b/src/views/title.html.ecr index 53db6ab..ff14fee 100644 --- a/src/views/title.html.ecr +++ b/src/views/title.html.ecr @@ -33,6 +33,8 @@
  • <%= title.display_name %>
  • <%= title.content_label %> found

    +<% tags = title.tags %> +<%= render_component "tags" %>