Skip to content

Commit

Permalink
Merge branch 'develop' into 0valt/1459/draft-discard
Browse files Browse the repository at this point in the history
  • Loading branch information
Oaphi authored Dec 6, 2024
2 parents e265b8c + 6b22ff8 commit 9f34700
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 13 deletions.
2 changes: 1 addition & 1 deletion app/assets/javascripts/posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ $(() => {
draftTimeout = setTimeout(() => {
const { draft, field } = parseDraft(ev.target);
saveDraft(draft, field);
}, 3000);
}, 1000);
});

postFields.on('paste', async (evt) => {
Expand Down
11 changes: 6 additions & 5 deletions app/assets/javascripts/tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 {
Expand All @@ -68,6 +68,7 @@ $(() => {
};
},
},
placeholder: '',
templateResult: template,
allowClear: true
});
Expand All @@ -90,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;
Expand Down Expand Up @@ -120,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');
Expand All @@ -136,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');
Expand Down
8 changes: 6 additions & 2 deletions app/controllers/posts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?)

RequestContext.redis.del(key_name)

if valid_tags.present?
RequestContext.redis.sadd(key_name, valid_tags)
end
else
RequestContext.redis.set(key_name, params[key])
Expand Down
6 changes: 3 additions & 3 deletions app/views/categories/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>
</div>

Expand All @@ -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 %>
</div>

Expand All @@ -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 %>
</div>
</details>
Expand Down
2 changes: 1 addition & 1 deletion app/views/posts/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 } %>
Expand Down
8 changes: 7 additions & 1 deletion app/views/tour/question2.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,13 @@

<div class="form-group">
<label class="form-element" for="post_tags_cache">Tags (at least one):</label>
<input name="post[tags_cache][]" type="hidden" value="" /><select multiple="multiple" class="form-element js-tag-select" data-tag-set="<%= @tagset_id %>" name="post[tags_cache][]" id="post_tags_cache"><option value=""></option></select>
<input name="post[tags_cache][]" type="hidden" value="" />
<select multiple="multiple"
class="form-element js-tag-select"
data-tag-set="<%= @tagset_id %>"
name="post[tags_cache][]"
id="post_tags_cache">
</select>
</div>

</div>
Expand Down

0 comments on commit 9f34700

Please sign in to comment.