Skip to content
Snippets Groups Projects
Commit 703d1801 authored by pabois's avatar pabois
Browse files

wip menus

parent 1121da76
No related branches found
No related tags found
No related merge requests found
......@@ -62,7 +62,7 @@ class Communication::Website < ApplicationRecord
after_create :create_home
after_save :publish_about_object, if: :saved_change_to_about_id?
after_save_commit :set_programs_categories!, if: -> (website) { website.about_type == 'Education::School' }
after_save_commit :set_programs_categories!, if: -> (website) { website.about_school? }
scope :ordered, -> { order(:name) }
......@@ -74,12 +74,15 @@ class Communication::Website < ApplicationRecord
"#{name}"
end
def programs
about_school? ? about.programs : Education::Program.none
end
def import!
unless imported?
self.imported_website = Communication::Website::Imported::Website.where(website: self, university: university)
.first_or_create
imported_website = Communication::Website::Imported::Website.where(
website: self, university: university
).first_or_create unless imported?
end
imported_website.run!
imported_website
end
......@@ -104,6 +107,14 @@ class Communication::Website < ApplicationRecord
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
protected
def create_home
......@@ -113,4 +124,8 @@ class Communication::Website < ApplicationRecord
def github
@github ||= Github.with_website self
end
def about_school?
about_type == 'Education::School'
end
end
......@@ -81,7 +81,7 @@ class Communication::Website::Menu::Item < ApplicationRecord
end
def has_about?
kind_page? || kind_program? || kind_news_category? || kind_news_article
kind_page? || kind_program? || kind_news_category? || kind_news_article?
end
protected
......
......@@ -24,11 +24,14 @@
if item.kind_page?
about_collection = @website.list_of_pages
elsif item.kind_program?
about_collection = @website.list_of_programs
elsif item.kind_news_category?
about_collection = @website.list_of_categories
elsif item.kind_news_article?
about_collection = @website.posts.ordered.map { |e| { label: e.to_s, id: e.id } }
end
else
about_collection = nil
about_collection = []
end
%>
<%= f.input :about_type, as: :hidden, input_html: { class: 'js-about-type' } %>
......
......@@ -21,11 +21,29 @@ function hideAbout() {
%>
displayAbout('Communication::Website::Page', "<%= j(raw(options.join(''))) %>");
<% elsif @kind == 'program' %>
displayAbout();
<%
options = ['<option value="" label=" "></option>']
@website.list_of_programs.each do |page|
options << "<option value=\"#{page[:id]}\">#{page[:label]}</option>"
end
%>
displayAbout('Education::Program', "<%= j(raw(options.join(''))) %>");
<% elsif @kind == 'news_category' %>
displayAbout();
<%
options = ['<option value="" label=" "></option>']
@website.list_of_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' %>
displayAbout();
<%
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 %>
$('.js-url-field').addClass('d-none');
hideAbout();
......
......@@ -26,7 +26,7 @@
<% if @item.kind_url? %>
<h3 class="h5"><%= Communication::Website::Menu::Item.human_attribute_name('url') %></h3>
<p><%= link_to @item.url, @item.url, target: '_blank' unless @item.url.blank? %></p>
<% elsif @item.kind_page? %>
<% elsif @item.has_about? %>
<h3 class="h5"><%= Communication::Website::Menu::Item.human_attribute_name('about') %></h3>
<p><%= link_to_if can?(:read, @item.about), @item.about, [:admin, @item.about] %></p>
<% end %>
......
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