diff --git a/app/controllers/admin/communication/websites_controller.rb b/app/controllers/admin/communication/websites_controller.rb index 1c4878bb3d7fddc4bfaf449040455ed8b0e0b831..cb854367f5029eb5f87a4dde8d8fef3dbe443934 100644 --- a/app/controllers/admin/communication/websites_controller.rb +++ b/app/controllers/admin/communication/websites_controller.rb @@ -2,7 +2,7 @@ class Admin::Communication::WebsitesController < Admin::Communication::Applicati load_and_authorize_resource class: Communication::Website def index - @websites = current_university.communication_websites + @websites = current_university.communication_websites.ordered breadcrumb add_breadcrumb Communication::Website.model_name.human(count: 2), admin_communication_websites_path end diff --git a/app/models/communication/website.rb b/app/models/communication/website.rb index 6cc21d8164e3717e7e4cdd86a400d10c199faf4d..91c21dd2cda91c29b63e377caed6c256df6d0402 100644 --- a/app/models/communication/website.rb +++ b/app/models/communication/website.rb @@ -59,6 +59,8 @@ class Communication::Website < ApplicationRecord after_save :publish_about_object, if: :saved_change_to_about_id? after_save_commit :set_programs_categories!, if: -> (website) { website.about_type == 'Education::School' } + scope :ordered, -> { order(:name) } + def self.about_types [nil, Education::School.name, Research::Journal.name] end @@ -89,6 +91,14 @@ class Communication::Website < ApplicationRecord all_pages end + def list_of_categories + all_categories = [] + categories.root.ordered.each do |category| + all_categories.concat(category.self_and_children(0)) + end + all_categories + end + protected def create_home diff --git a/app/models/communication/website/category.rb b/app/models/communication/website/category.rb index e1767b780059bcb7d3582eb8becf8cde7a81d05e..f94f9b5df8e18cf13bd720728a3aecb252ad8ac4 100644 --- a/app/models/communication/website/category.rb +++ b/app/models/communication/website/category.rb @@ -69,12 +69,7 @@ class Communication::Website::Category < ApplicationRecord before_create :set_position def list_of_other_categories - categories = [] - website.categories.where.not(id: id).root.ordered.each do |category| - categories.concat(category.self_and_children(0)) - end - categories.reject! { |p| p[:id] == id } - categories + website.list_of_categories.reject! { |p| p[:id] == id } end def to_s diff --git a/app/views/admin/communication/website/pages/_form.html.erb b/app/views/admin/communication/website/pages/_form.html.erb index 3d49f894d1269512a3d6b729bdd0c8bbcf8124fe..7c7f0ed26e5208c675f6164d7faadb0a700e5ee9 100644 --- a/app/views/admin/communication/website/pages/_form.html.erb +++ b/app/views/admin/communication/website/pages/_form.html.erb @@ -9,6 +9,10 @@ <%= f.input :title %> <%= f.input :description %> <%= f.input :text, as: :rich_text_area %> + <%= f.association :related_category, + collection: @website.list_of_categories, + label_method: ->(p) { sanitize p[:label] }, + value_method: ->(p) { p[:id] } if @website.categories.any? %> </div> </div> </div> @@ -25,8 +29,10 @@ data: { source: '#communication_website_page_title' } } %> <%= f.input :published %> - <%= f.association :parent, collection: page.persisted? ? page.list_of_other_pages : @website.list_of_pages, label_method: ->(p) { sanitize p[:label] }, value_method: ->(p) { p[:id] } %> - <%= f.association :related_category, collection: page.website.categories.ordered %> + <%= f.association :parent, + collection: page.persisted? ? page.list_of_other_pages : page.website.list_of_pages, + label_method: ->(p) { sanitize p[:label] }, + value_method: ->(p) { p[:id] } %> <ul> </ul> </div> diff --git a/app/views/admin/communication/website/posts/_form.html.erb b/app/views/admin/communication/website/posts/_form.html.erb index 2b885ef90ce6829f06d42dcafecac01bfae952fb..a430c84fc448583e69ce1a12e54ae80be886f60e 100644 --- a/app/views/admin/communication/website/posts/_form.html.erb +++ b/app/views/admin/communication/website/posts/_form.html.erb @@ -27,7 +27,11 @@ <%= f.input :published %> <%= f.input :published_at, html5: true %> <%= f.association :author, collection: @website.authors.ordered if @website.authors.any? %> - <%= f.association :categories, as: :check_boxes if @website.categories.any? %> + <%= f.association :categories, + as: :check_boxes, + collection: @website.list_of_categories, + label_method: ->(p) { sanitize p[:label] }, + value_method: ->(p) { p[:id] } if @website.categories.any? %> </div> </div> <div class="card flex-fill w-100"> diff --git a/app/views/admin/communication/websites/show.html.erb b/app/views/admin/communication/websites/show.html.erb index 512a5a42acbf4163c394007681ba90991aac3242..70c6eca9fc183f8e8f14d30d78a90f336116a69f 100644 --- a/app/views/admin/communication/websites/show.html.erb +++ b/app/views/admin/communication/websites/show.html.erb @@ -21,15 +21,15 @@ </div> </div> <div class="row"> - <div class="col-md-4"> - <%= render 'admin/communication/websites/show/categories' %> - </div> <div class="col-md-4"> <%= render 'admin/communication/websites/show/authors' %> </div> <div class="col-md-4"> <%= render 'admin/communication/websites/show/menus' %> </div> + <div class="col-md-4"> + <%= render 'admin/communication/websites/show/categories' %> + </div> </div> <% content_for :action_bar_left do %>