From 54035b0a8cc6f7783ef748d16d1d733ff8733dc2 Mon Sep 17 00:00:00 2001 From: Arnaud Levy <contact@arnaudlevy.com> Date: Fri, 20 May 2022 18:53:49 +0200 Subject: [PATCH] refactor --- app/helpers/admin/application_helper.rb | 9 ++++++++ .../websites/menus/items/_form.html.erb | 22 ++++++------------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/app/helpers/admin/application_helper.rb b/app/helpers/admin/application_helper.rb index aba81c4f1..edad92b43 100644 --- a/app/helpers/admin/application_helper.rb +++ b/app/helpers/admin/application_helper.rb @@ -91,6 +91,15 @@ module Admin::ApplicationHelper '' end + def collection(list) + list.ordered.map do |e| + { + label: e.to_s, + id: e.id + } + end + end + def collection_tree(list, except = nil) collection = [] list.root.ordered.each do |object| diff --git a/app/views/admin/communication/websites/menus/items/_form.html.erb b/app/views/admin/communication/websites/menus/items/_form.html.erb index 14b8c2991..ec0a2a457 100644 --- a/app/views/admin/communication/websites/menus/items/_form.html.erb +++ b/app/views/admin/communication/websites/menus/items/_form.html.erb @@ -21,27 +21,19 @@ <% if item.has_about? if item.kind_page? - about_collection = collection_tree(@website.pages) + about_collection = collection_tree @website.pages elsif item.kind_diploma? - about_collection = @website.education_diplomas - .ordered - .map { |e| { label: e.to_s, id: e.id } } + about_collection = collection @website.education_diplomas elsif item.kind_program? - about_collection = collection_tree(@website.education_programs) + about_collection = collection_tree @website.education_programs elsif item.kind_news_category? - about_collection = collection_tree(@website.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 } } + about_collection = collection @website.posts elsif item.kind_research_volume? - about_collection = @website.research_volumes - .ordered - .map { |e| { label: e.to_s, id: e.id } } + about_collection = collection @website.research_volumes elsif item.kind_research_article? - about_collection = @website.research_articles - .ordered - .map { |e| { label: e.to_s, id: e.id } } + about_collection = collection @website.research_articles end else about_collection = [] -- GitLab