diff --git a/app/controllers/admin/communication/website/menu/items_controller.rb b/app/controllers/admin/communication/website/menu/items_controller.rb index 35e393a59443812cd1e142da2ce18684929db45f..5779e978bf5d0e537f55348d34da5aec362e2be8 100644 --- a/app/controllers/admin/communication/website/menu/items_controller.rb +++ b/app/controllers/admin/communication/website/menu/items_controller.rb @@ -13,7 +13,7 @@ class Admin::Communication::Website::Menu::ItemsController < Admin::Communicatio skip_publication_callback: true ) end - @menu.force_publish! + @menu.sync_with_git end def show diff --git a/app/helpers/admin/application_helper.rb b/app/helpers/admin/application_helper.rb index c2d92946fe332882f35ca477a6a17445da9138d6..8eecec8163b92f288f2b0ad0d01f7f597964499b 100644 --- a/app/helpers/admin/application_helper.rb +++ b/app/helpers/admin/application_helper.rb @@ -72,12 +72,13 @@ module Admin::ApplicationHelper sanitize text end - def collection_tree(list, except) + def collection_tree(list, except = nil) collection = [] list.root.ordered.each do |object| collection.concat(object.self_and_children(0)) end - collection.reject { |o| o[:id] == except.id } + collection = collection.reject { |o| o[:id] == except.id } unless except.nil? + collection end private diff --git a/app/models/communication/website.rb b/app/models/communication/website.rb index b8aba04c715f284b7465ceae1b07c9b35911ce6d..1b9d8372dfdbcf191ea928636b476120088edda9 100644 --- a/app/models/communication/website.rb +++ b/app/models/communication/website.rb @@ -41,22 +41,6 @@ class Communication::Website < ApplicationRecord "#{name}" 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 - - def list_of_programs - all_programs = [] - programs.root.ordered.each do |program| - all_programs.concat(program.self_and_children(0)) - end - all_programs - end - def git_path_static "data/website.yml" end diff --git a/app/models/communication/website/category.rb b/app/models/communication/website/category.rb index 08c2fa1f6c753b4a2e94c5e505c69e314add133f..86ee5e1c60a6d5624ef3d3e2213479028a9b5c9d 100644 --- a/app/models/communication/website/category.rb +++ b/app/models/communication/website/category.rb @@ -70,11 +70,6 @@ class Communication::Website::Category < ApplicationRecord before_create :set_position - def list_of_other_categories - new_record? ? website.list_of_categories - : website.list_of_categories.reject! { |p| p[:id] == id } - end - def to_s "#{name}" end diff --git a/app/models/communication/website/menu.rb b/app/models/communication/website/menu.rb index e66a5a16d79361923214bb73de96cbea4018ccad..7396c580d3f64b3abead4188658c3a02ea54daed 100644 --- a/app/models/communication/website/menu.rb +++ b/app/models/communication/website/menu.rb @@ -40,8 +40,4 @@ class Communication::Website::Menu < ApplicationRecord def git_path_static "data/menus/#{identifier}.yml" end - - def to_static(github_file) - items.root.ordered.map(&:to_static_hash).to_yaml - end end diff --git a/app/models/communication/website/menu/item.rb b/app/models/communication/website/menu/item.rb index 781c15a658540329147b4330b21d794e3d7e37cd..6327f27ba9a12c91a1d17b2d13f47b6a508bcc2b 100644 --- a/app/models/communication/website/menu/item.rb +++ b/app/models/communication/website/menu/item.rb @@ -62,7 +62,7 @@ class Communication::Website::Menu::Item < ApplicationRecord validates :about, presence: true, if: :has_about? before_create :set_position - after_commit :force_publish_menu, unless: :skip_publication_callback + after_commit :sync_menu scope :ordered, -> { order(position: :asc) } @@ -115,8 +115,8 @@ class Communication::Website::Menu::Item < ApplicationRecord kind_page? || kind_program? || kind_news_category? || kind_news_article? end - def force_publish_menu - menu.force_publish! + def sync_menu + menu.sync_with_git end def siblings @@ -127,11 +127,7 @@ class Communication::Website::Menu::Item < ApplicationRecord def set_position last_element = menu.items.where(parent_id: parent_id).ordered.last - - unless last_element.nil? - self.position = last_element.position + 1 - else - self.position = 1 - end + self.position = last_element.nil? ? 1 + : last_element.position + 1 end end diff --git a/app/models/education/program.rb b/app/models/education/program.rb index 98884b2388291c88ecce1dbd44ef8c20f18c951e..2a1be194430945aa60da806a35be20d9e0cbe7b3 100644 --- a/app/models/education/program.rb +++ b/app/models/education/program.rb @@ -122,10 +122,6 @@ class Education::Program < ApplicationRecord end end - def list_of_other_programs - university.list_of_programs.reject! { |p| p[:id] == id } - end - def set_websites_categories websites.find_each(&:set_programs_categories!) end diff --git a/app/models/university/with_education.rb b/app/models/university/with_education.rb index 16be46c1b99ef01265cc1b5d8b7153a298bf5340..5acddc90f4055bb204487797d97d6994c82a189e 100644 --- a/app/models/university/with_education.rb +++ b/app/models/university/with_education.rb @@ -4,14 +4,5 @@ module University::WithEducation included do has_many :education_programs, class_name: 'Education::Program', dependent: :destroy has_many :education_schools, class_name: 'Education::School', dependent: :destroy - - def list_of_programs - all_programs = [] - education_programs.root.ordered.each do |program| - all_programs.concat(program.self_and_children(0)) - end - all_programs - end - end end diff --git a/app/views/admin/communication/website/menu/items/_form.html.erb b/app/views/admin/communication/website/menu/items/_form.html.erb index e69a398400fd64f60bc6d7ea1654e2d46042a344..44ccf48546d8c00069d35301ad181c62dc048a14 100644 --- a/app/views/admin/communication/website/menu/items/_form.html.erb +++ b/app/views/admin/communication/website/menu/items/_form.html.erb @@ -21,11 +21,11 @@ <% if item.has_about? if item.kind_page? - about_collection = @website.list_of_pages + about_collection = collection_tree(@website.pages) elsif item.kind_program? - about_collection = @website.list_of_programs + about_collection = collection_tree(@website.programs) elsif item.kind_news_category? - about_collection = @website.list_of_categories + about_collection = collection_tree(@website.categories) elsif item.kind_news_article? about_collection = @website.posts.ordered.map { |e| { label: e.to_s, id: e.id } } end diff --git a/app/views/admin/communication/website/menu/items/kind_switch.js.erb b/app/views/admin/communication/website/menu/items/kind_switch.js.erb index cb32d1252526a3b26625f5bbc0b8134883ed9fcd..e883ff32bdcc7dc7ea174b8527d257b46aec8161 100644 --- a/app/views/admin/communication/website/menu/items/kind_switch.js.erb +++ b/app/views/admin/communication/website/menu/items/kind_switch.js.erb @@ -14,16 +14,16 @@ function hideAbout() { hideAbout(); <% elsif @kind == 'page' %> <% - options = ['<option value="" label=" "></option>'] - @website.list_of_pages.each do |page| - options << "<option value=\"#{page[:id]}\">#{page[:label]}</option>" - end + options = ['<option value="" label=" "></option>'] + collection_tree(@website.pages).each do |page| + options << "<option value=\"#{page[:id]}\">#{page[:label]}</option>" + end %> displayAbout('Communication::Website::Page', "<%= j(raw(options.join(''))) %>"); <% elsif @kind == 'program' %> <% options = ['<option value="" label=" "></option>'] - @website.list_of_programs.each do |page| + collection_tree(@website.programs).each do |page| options << "<option value=\"#{page[:id]}\">#{page[:label]}</option>" end %> @@ -31,17 +31,17 @@ function hideAbout() { <% elsif @kind == 'news_category' %> <% options = ['<option value="" label=" "></option>'] - @website.list_of_categories.each do |category| + collection_tree(@website.categories).each do |category| options << "<option value=\"#{category[:id]}\">#{category[:label]}</option>" end %> displayAbout('Communication::Website::Category', "<%= j(raw(options.join(''))) %>"); <% elsif @kind == 'news_article' %> <% - options = ['<option value="" label=" "></option>'] - @website.posts.ordered.each do |post| - options << "<option value=\"#{post.id}\">#{post.to_s}</option>" - end + options = ['<option value="" label=" "></option>'] + @website.posts.ordered.each do |post| + options << "<option value=\"#{post.id}\">#{post.to_s}</option>" + end %> displayAbout('Communication::Website::Post', "<%= j(raw(options.join(''))) %>"); <% else %> diff --git a/app/views/admin/communication/website/menus/static.html.erb b/app/views/admin/communication/website/menus/static.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..035a94b4a3a9e6728b0935912c0ee4d6b17e15ff --- /dev/null +++ b/app/views/admin/communication/website/menus/static.html.erb @@ -0,0 +1,5 @@ +<%= raw @menu.items + .root + .ordered + .map(&:to_static_hash) + .to_yaml %> diff --git a/app/views/admin/communication/website/pages/_form.html.erb b/app/views/admin/communication/website/pages/_form.html.erb index 4cb44c14b3d4c36ef31dbaf1243e3246827fb8fe..b7b890ce605ac69d123db269a8cbd3cf9096b4ab 100644 --- a/app/views/admin/communication/website/pages/_form.html.erb +++ b/app/views/admin/communication/website/pages/_form.html.erb @@ -10,7 +10,7 @@ <%= f.input :description %> <%= f.input :text, as: :rich_text_area %> <%= f.association :related_category, - collection: @website.list_of_categories, + collection: collection_tree(@website.categories), label_method: ->(p) { sanitize p[:label] }, value_method: ->(p) { p[:id] } if @website.categories.any? %> </div> @@ -30,7 +30,7 @@ } %> <%= f.input :published %> <%= f.association :parent, - collection: collection_tree(page.website.pages, page), + collection: collection_tree(@website.pages, page), label_method: ->(p) { sanitize p[:label] }, value_method: ->(p) { p[:id] } %> <ul> diff --git a/app/views/admin/communication/website/posts/_form.html.erb b/app/views/admin/communication/website/posts/_form.html.erb index e2d1226bec399ccfc5364aec4e9402b77008dc28..f575dced17bd16b739a1c7de7e7d484b8f057b9a 100644 --- a/app/views/admin/communication/website/posts/_form.html.erb +++ b/app/views/admin/communication/website/posts/_form.html.erb @@ -30,7 +30,7 @@ <%= f.association :author, collection: current_university.administration_members.authors.ordered %> <%= f.association :categories, as: :check_boxes, - collection: @website.list_of_categories.map { |category| [ + collection: collection_tree(@website.categories).map { |category| [ sanitize(category[:label]), category[:id], { data: { parent: category[:parent_id] } } diff --git a/app/views/admin/education/programs/_form.html.erb b/app/views/admin/education/programs/_form.html.erb index 66de89881303e9f0a256637a77721d837a0bed8a..93e2959b57c101b291d1d591ba3592725c58d82a 100644 --- a/app/views/admin/education/programs/_form.html.erb +++ b/app/views/admin/education/programs/_form.html.erb @@ -22,7 +22,7 @@ as: :check_boxes, collection: current_university.education_schools.ordered %> <%= f.association :parent, - collection: program.persisted? ? program.list_of_other_programs : current_university.list_of_programs, + collection: collection_tree(current_university.programs, program), label_method: ->(p) { sanitize p[:label] }, value_method: ->(p) { p[:id] } %> </div> diff --git a/app/views/admin/education/schools/_form.html.erb b/app/views/admin/education/schools/_form.html.erb index 93a0809b8bc6d612c1de8fabd144090f766bd36b..87c4e36d4e27063bc1941bcf3ae0d6e4e779ddbc 100644 --- a/app/views/admin/education/schools/_form.html.erb +++ b/app/views/admin/education/schools/_form.html.erb @@ -29,7 +29,7 @@ <div class="card-body"> <%= f.association :programs, as: :check_boxes, - collection: current_university.list_of_programs, + collection: collection_tree(current_university.education_programs, label_method: ->(p) { sanitize p[:label] }, value_method: ->(p) { p[:id] } %> </div> diff --git a/app/views/admin/education/teachers/_form.html.erb b/app/views/admin/education/teachers/_form.html.erb index dd685aeacbfc35c698b164bcb65b84a1c814a1a9..82d37bc4227c744e5b65520c378546c7dcfafaf6 100644 --- a/app/views/admin/education/teachers/_form.html.erb +++ b/app/views/admin/education/teachers/_form.html.erb @@ -7,7 +7,7 @@ <%= f.association :education_programs, as: :check_boxes, legend_tag: false, - collection: current_university.list_of_programs, + collection: collection_tree(current_university.education_programs), label_method: ->(p) { sanitize p[:label] }, value_method: ->(p) { p[:id] } %> </div> diff --git a/app/views/admin/education/teachers/_list.html.erb b/app/views/admin/education/teachers/_list.html.erb index 5ef8fafad0c8c94009036f45f5153b5c10dfada0..9f59a100f69bc9beffd8e65b293ccfb1e582407a 100644 --- a/app/views/admin/education/teachers/_list.html.erb +++ b/app/views/admin/education/teachers/_list.html.erb @@ -9,7 +9,8 @@ <tbody> <% teachers.each do |teacher| %> <tr> - <td><%= link_to teacher, admin_education_teacher_path(teacher) %></td> + <td><%= link_to teacher.last_name, admin_education_teacher_path(teacher) %></td> + <td><%= link_to teacher.first_name, admin_education_teacher_path(teacher) %></td> <td class="text-end"> <div class="btn-group" role="group"> <%= link_to t('edit'),