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