mirror of
https://github.com/discourse/discourse.git
synced 2025-06-04 23:36:11 +08:00
DEV: Tag group improvements (#8252)
* DEV: Add the actual "tag_groups/new" route Allows refreshing the "new" page without an error. * DEV: Prevent attempts to create group tags if tagging is disabled * DEV: Refactor the tag-groups controller Gets rid of `selectedItem`, `selected`, and `selectTagGroup` action. * DEV: Rename tag-groups-show to tag-groups-edit * DEV: Refactor tag-groups form * Extracted the tag-groups-form that's used by tag-groups-new and tag-groups-edit * The model is now a buffered property * Serialization relies more heavily on RestAdapter now * Data is sent as JSON * Payload is now namespaced ("tag_group") * Update app/assets/javascripts/discourse/controllers/tag-groups-new.js.es6 Co-Authored-By: Joffrey JAFFEUX <j.jaffeux@gmail.com> * Update app/assets/javascripts/discourse/components/tag-groups-form.js.es6 Co-Authored-By: Joffrey JAFFEUX <j.jaffeux@gmail.com> * Update app/assets/javascripts/discourse/controllers/tag-groups-edit.js.es6 Co-Authored-By: Joffrey JAFFEUX <j.jaffeux@gmail.com>
This commit is contained in:
@ -1,11 +1,10 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class TagGroupsController < ApplicationController
|
||||
|
||||
requires_login
|
||||
before_action :ensure_staff
|
||||
|
||||
skip_before_action :check_xhr, only: [:index, :show]
|
||||
skip_before_action :check_xhr, only: [:index, :show, :new]
|
||||
before_action :fetch_tag_group, only: [:show, :update, :destroy]
|
||||
|
||||
def index
|
||||
@ -31,6 +30,13 @@ class TagGroupsController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
def new
|
||||
tag_groups = TagGroup.order('name ASC').includes(:parent_tag).preload(:tags).all
|
||||
serializer = ActiveModel::ArraySerializer.new(tag_groups, each_serializer: TagGroupSerializer, root: 'tag_groups')
|
||||
store_preloaded "tagGroup", MultiJson.dump(serializer)
|
||||
render "default/empty"
|
||||
end
|
||||
|
||||
def create
|
||||
guardian.ensure_can_admin_tag_groups!
|
||||
@tag_group = TagGroup.new(tag_groups_params)
|
||||
@ -73,6 +79,9 @@ class TagGroupsController < ApplicationController
|
||||
end
|
||||
|
||||
def tag_groups_params
|
||||
tag_group = params.delete(:tag_group)
|
||||
params.merge!(tag_group.permit!) if tag_group
|
||||
|
||||
if permissions = params[:permissions]
|
||||
permissions.each do |k, v|
|
||||
permissions[k] = v.to_i
|
||||
@ -87,9 +96,11 @@ class TagGroupsController < ApplicationController
|
||||
parent_tag_name: [],
|
||||
permissions: permissions&.keys,
|
||||
)
|
||||
|
||||
result[:tag_names] ||= []
|
||||
result[:parent_tag_name] ||= []
|
||||
result[:one_per_topic] = (params[:one_per_topic] == "true")
|
||||
result[:one_per_topic] = params[:one_per_topic].in?([true, "true"])
|
||||
|
||||
result
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user