Skip to content
Snippets Groups Projects
Unverified Commit 041e09eb authored by Sébastien Gaya's avatar Sébastien Gaya
Browse files

Merge branch 'git' of github.com:noesya/osuny into git

parents 27a1ca31 1f48dd10
No related branches found
No related tags found
No related merge requests found
Showing
with 35 additions and 70 deletions
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......@@ -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
......@@ -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
......
......@@ -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
......@@ -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
......
......@@ -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 %>
......
<%= raw @menu.items
.root
.ordered
.map(&:to_static_hash)
.to_yaml %>
......@@ -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>
......
......@@ -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] } }
......
......@@ -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>
......
......@@ -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>
......
......@@ -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>
......
......@@ -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'),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment