From acdd75e1db4ddae65e9e14eb8ae4b5ae5001ed3d Mon Sep 17 00:00:00 2001 From: Oleg Valter Date: Tue, 3 Dec 2024 18:28:10 +0300 Subject: [PATCH 1/6] save_draft should validate the incoming tag array --- app/controllers/posts_controller.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 341db5187..35ef8368f 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -602,8 +602,12 @@ def save_draft key_name = [:body, :saved_at].include?(key) ? base_key : "#{base_key}.#{key}" if key == :tags - if params[key].present? - RequestContext.redis.sadd(key_name, params[key]) + valid_tags = params[key]&.select(&:present?) + + if valid_tags.present? + RequestContext.redis.sadd(key_name, valid_tags) + else + RequestContext.redis.del(key_name) end else RequestContext.redis.set(key_name, params[key]) From f6e2e271d4da215fe2f71d0c17e358f36b272481 Mon Sep 17 00:00:00 2001 From: Oleg Valter Date: Tue, 3 Dec 2024 18:30:57 +0300 Subject: [PATCH 2/6] without placeholder, tags select can't be cleared --- app/assets/javascripts/tags.js | 1 + 1 file changed, 1 insertion(+) diff --git a/app/assets/javascripts/tags.js b/app/assets/javascripts/tags.js index 33e4dd4be..4d63dddb7 100644 --- a/app/assets/javascripts/tags.js +++ b/app/assets/javascripts/tags.js @@ -68,6 +68,7 @@ $(() => { }; }, }, + placeholder: '', templateResult: template, allowClear: true }); From dd9b6fe34e8972d346d981f869cce64710e35740 Mon Sep 17 00:00:00 2001 From: Oleg Valter Date: Tue, 3 Dec 2024 18:37:12 +0300 Subject: [PATCH 3/6] always delete draft tags before reinserting them --- app/controllers/posts_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 35ef8368f..79e03f7b1 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -604,10 +604,10 @@ def save_draft if key == :tags valid_tags = params[key]&.select(&:present?) + RequestContext.redis.del(key_name) + if valid_tags.present? RequestContext.redis.sadd(key_name, valid_tags) - else - RequestContext.redis.del(key_name) end else RequestContext.redis.set(key_name, params[key]) From 9c7422fd7e2a81d8e97d7dae7813075f3b00ea09 Mon Sep 17 00:00:00 2001 From: Oleg Valter Date: Tue, 3 Dec 2024 18:42:10 +0300 Subject: [PATCH 4/6] reduced delay before saving a post draft to 1 second --- app/assets/javascripts/posts.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/posts.js b/app/assets/javascripts/posts.js index ca816dc4e..2b0210eed 100644 --- a/app/assets/javascripts/posts.js +++ b/app/assets/javascripts/posts.js @@ -206,7 +206,7 @@ $(() => { draftTimeout = setTimeout(() => { const { draft, field } = parseDraft(ev.target); saveDraft(draft, field); - }, 3000); + }, 1000); }); postFields.on('paste', async (evt) => { From 2a7d8ac927edff42ce63640d3418fef276d7fc63 Mon Sep 17 00:00:00 2001 From: Oleg Valter Date: Tue, 3 Dec 2024 18:57:43 +0300 Subject: [PATCH 5/6] minor cleanup of tags JS asset --- app/assets/javascripts/tags.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/tags.js b/app/assets/javascripts/tags.js index 4d63dddb7..460c215b5 100644 --- a/app/assets/javascripts/tags.js +++ b/app/assets/javascripts/tags.js @@ -23,7 +23,7 @@ $(() => { return $(tagSpan + descSpan); } - $('.js-tag-select').each((i, el) => { + $('.js-tag-select').each((_i, el) => { const $tgt = $(el); let $this; const useIds = $tgt.attr('data-use-ids') === 'true'; @@ -46,7 +46,7 @@ $(() => { }, headers: { 'Accept': 'application/json' }, delay: 100, - processResults: data => { + processResults: (data) => { // (for the tour) if (Number($this.data('tag-set')) === -1) { return { @@ -91,7 +91,7 @@ $(() => { return synonymsString; } - $('#add-tag-synonym').on('click', ev => { + $('#add-tag-synonym').on('click', (ev) => { const $wrapper = $('#tag-synonyms-wrapper'); const lastId = $wrapper.children('.tag-synonym').last().attr('data-id'); const newId = parseInt(lastId, 10) + 1; @@ -121,7 +121,7 @@ $(() => { synonym.hide(); } - $('.js-add-required-tag').on('click', ev => { + $('.js-add-required-tag').on('click', (ev) => { const $tgt = $(ev.target); const useIds = $tgt.attr('data-use-ids') === 'true'; const tagId = $tgt.attr('data-tag-id'); @@ -137,7 +137,7 @@ $(() => { } }); - $('.js-rename-tag').on('click', async ev => { + $('.js-rename-tag').on('click', async (ev) => { const $tgt = $(ev.target).is('a') ? $(ev.target) : $(ev.target).parents('a'); const categoryId = $tgt.attr('data-category'); const tagId = $tgt.attr('data-tag'); From 0b71ed442ef9db1ec9a1a06235b6296617434f65 Mon Sep 17 00:00:00 2001 From: Oleg Valter Date: Tue, 3 Dec 2024 19:08:35 +0300 Subject: [PATCH 6/6] include_blank shouldn't be used with multiple choice tag fields --- app/views/categories/_form.html.erb | 6 +++--- app/views/posts/_form.html.erb | 2 +- app/views/tour/question2.html.erb | 8 +++++++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/app/views/categories/_form.html.erb b/app/views/categories/_form.html.erb index 064e2444d..55e04b314 100644 --- a/app/views/categories/_form.html.erb +++ b/app/views/categories/_form.html.erb @@ -221,7 +221,7 @@ <% disabled = @category.tag_set.nil? %> <%= f.select :required_tag_ids, options_for_select(@category.required_tags.map { |t| [t.name, t.id] }, selected: @category.required_tag_ids), - { include_blank: true }, multiple: true, class: 'form-element js-tag-select js-required-tags', + {}, multiple: true, class: 'form-element js-tag-select js-required-tags', data: { tag_set: @category.tag_set&.id, create: 'false', use_ids: 'true' }, disabled: disabled %> @@ -239,7 +239,7 @@ <%= f.select :topic_tag_ids, options_for_select(@category.topic_tags.map { |t| [t.name, t.id] }, selected: @category.topic_tag_ids), - { include_blank: true }, multiple: true, class: 'form-element js-tag-select js-topic-tags', + {}, multiple: true, class: 'form-element js-tag-select js-topic-tags', data: { tag_set: @category.tag_set&.id, create: 'false', use_ids: 'true' }, disabled: disabled %> @@ -256,7 +256,7 @@ <%= f.select :moderator_tag_ids, options_for_select(@category.moderator_tags.map { |t| [t.name, t.id] }, selected: @category.moderator_tag_ids), - { include_blank: true }, multiple: true, class: 'form-element js-tag-select js-moderator-tags', + {}, multiple: true, class: 'form-element js-tag-select js-moderator-tags', data: { tag_set: @category.tag_set&.id, create: 'false', use_ids: 'true' }, disabled: disabled %> diff --git a/app/views/posts/_form.html.erb b/app/views/posts/_form.html.erb index 4c11343a1..6002284bd 100644 --- a/app/views/posts/_form.html.erb +++ b/app/views/posts/_form.html.erb @@ -129,7 +129,7 @@ <%= f.select :tags_cache, options_for_select( (tags || post.tags_cache).map { |t| [t, t] }, selected: tags || post.tags_cache), - { include_blank: true }, + {}, multiple: true, class: "form-element js-tag-select", data: { tag_set: category.tag_set_id } %> diff --git a/app/views/tour/question2.html.erb b/app/views/tour/question2.html.erb index f5d4cd6db..b2da72932 100644 --- a/app/views/tour/question2.html.erb +++ b/app/views/tour/question2.html.erb @@ -43,7 +43,13 @@
- + +