Skip to content
Snippets Groups Projects
Commit 34c9723a authored by ArtOfCode-'s avatar ArtOfCode-
Browse files

Start on category required/topic tags

parent 8e8d4c49
No related branches found
No related tags found
No related merge requests found
$(() => {
$('.js-category-tag-set-select').on('change', ev => {
const $tgt = $(ev.target);
const tagSetId = $tgt.val();
const formGroups = $('.js-category-tags-group');
if (tagSetId) {
formGroups.each((i, el) => {
const $el = $(el);
const $caption = $el.find('.js-tags-group-caption');
$caption.find('[data-state="absent"]').hide();
$caption.find('[data-state="present"]').show();
$el.find('.js-tag-select').attr('data-tag-set', tagSetId);
});
}
else {
formGroups.each((i, el) => {
const $el = $(el);
const $caption = $el.find('.js-tags-group-caption');
$caption.find('[data-state="absent"]').show();
$caption.find('[data-state="present"]').hide();
$el.find('.js-tag-select').attr('data-tag-set', null);
});
}
});
});
\ No newline at end of file
$(() => {
$('.js-tag-select').select2({
tags: true,
$('.js-tag-select').each((i, el) => {
const $tgt = $(el);
$tgt.select2({
tags: $tgt.attr('data-create') !== 'false',
ajax: {
url: '/tags',
data: function (params) {
......@@ -12,3 +14,4 @@ $(() => {
}
});
});
});
\ No newline at end of file
......@@ -75,7 +75,7 @@ class CategoriesController < ApplicationController
def category_params
params.require(:category).permit(:name, :short_wiki, :tag_set_id, :is_homepage, :min_trust_level, :button_text,
:color_code, :min_view_trust_level, :license_id, :sequence, display_post_types: [],
post_type_ids: [])
post_type_ids: [], required_tag_ids: [], topic_tag_ids: [])
end
def verify_view_access
......
......
......@@ -2,6 +2,8 @@ class Category < ApplicationRecord
include CommunityRelated
has_and_belongs_to_many :post_types
has_and_belongs_to_many :required_tags, class_name: 'Tag', join_table: 'categories_required_tags'
has_and_belongs_to_many :topic_tags, class_name: 'Tag', join_table: 'categories_topic_tags'
has_many :posts
belongs_to :tag_set
belongs_to :license
......
......
......@@ -31,7 +31,7 @@
<%= f.label :tag_set_id, 'Tag set', class: 'form-element' %>
<span class="form-caption">Which tag set may posts in this category draw from?</span>
<%= f.select :tag_set_id, options_for_select(TagSet.all.map { |ts| [ts.name, ts.id] }, selected: @category.tag_set_id),
{ include_blank: true }, class: 'form-element' %>
{ include_blank: true }, class: 'form-element js-category-tag-set-select' %>
</div>
<div class="form-group">
......@@ -90,5 +90,37 @@
<%= f.number_field :sequence, class: 'form-element' %>
</div>
<div class="form-group js-category-tags-group">
<%= f.label :required_tag_ids, 'Required tags', class: 'form-element' %>
<span class="form-caption js-tags-group-caption">
<span data-state="present" style="<%= @category.tag_set.nil? ? 'display: none' : '' %>">
Required tags for this category - every post will be required to have one of these tags.
</span>
<span data-state="absent" style="<%= @category.tag_set.nil? ? '' : 'display: none' %>">
Select a tag set first.
</span>
</span>
<%= f.select :required_tag_ids, options_for_select(@category.required_tags.map { |t| [t.name, t.id] },
selected: @category.required_tags.pluck(:name)),
{ include_blank: true }, multiple: true, class: 'form-element js-tag-select',
data: { tag_set: @category.tag_set&.id, create: 'false' } %>
</div>
<div class="form-group js-category-tags-group">
<%= f.label :required_tag_ids, 'Topic tags', class: 'form-element' %>
<span class="form-caption js-tags-group-caption">
<span data-state="present" style="<%= @category.tag_set.nil? ? 'display: none' : '' %>">
Tags that will be highlighted as the most important tag on a question.
</span>
<span data-state="absent" style="<%= @category.tag_set.nil? ? '' : 'display: none' %>">
Select a tag set first.
</span>
</span>
<%= f.select :topic_tag_ids, options_for_select(@category.topic_tags.map { |t| [t.name, t.id] },
selected: @category.topic_tags.pluck(:name)),
{ include_blank: true }, multiple: true, class: 'form-element js-tag-select',
data: { tag_set: @category.tag_set&.id, create: 'false' } %>
</div>
<%= f.submit 'Save', class: 'button is-filled' %>
<% end %>
class AddCategoryTagJoinTables < ActiveRecord::Migration[5.2]
def change
create_table :categories_required_tags, id: false, primary_key: [:category_id, :tag_id] do |t|
t.bigint :category_id
t.bigint :tag_id
end
create_table :categories_topic_tags, id: false, primary_key: [:category_id, :tag_id] do |t|
t.bigint :category_id
t.bigint :tag_id
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment