From 08031dadfa9c5bc6ff19927d834be6760053ef20 Mon Sep 17 00:00:00 2001 From: Arnaud Levy <contact@arnaudlevy.com> Date: Tue, 21 Sep 2021 21:04:10 +0200 Subject: [PATCH] better --- .../admin/application_controller.rb | 6 ++++ .../website/application_controller.rb | 3 +- .../journal/application_controller.rb | 3 +- app/models/communication/website/page.rb | 1 + app/views/admin/application/_nav.html.erb | 2 +- .../website/pages/_list.html.erb | 21 ++++++++++++ .../website/pages/index.html.erb | 22 +----------- .../communication/websites/show.html.erb | 10 ++---- app/views/admin/dashboard/index.html.erb | 34 +++++++++++++++++++ 9 files changed, 68 insertions(+), 34 deletions(-) create mode 100644 app/views/admin/communication/website/pages/_list.html.erb diff --git a/app/controllers/admin/application_controller.rb b/app/controllers/admin/application_controller.rb index 0e72a394e..5ed9a73d7 100644 --- a/app/controllers/admin/application_controller.rb +++ b/app/controllers/admin/application_controller.rb @@ -9,6 +9,12 @@ class Admin::ApplicationController < ApplicationController add_breadcrumb t('dashboard'), :admin_root_path end + def short_breadcrumb + @menu_collapsed = true + add_breadcrumb t('dashboard'), :admin_root_path + add_breadcrumb '...' + end + def breadcrumb_for(object, **options) return unless object object.persisted? ? add_breadcrumb(object, [:admin, object, options]) diff --git a/app/controllers/admin/communication/website/application_controller.rb b/app/controllers/admin/communication/website/application_controller.rb index ebf2579c9..351e872c3 100644 --- a/app/controllers/admin/communication/website/application_controller.rb +++ b/app/controllers/admin/communication/website/application_controller.rb @@ -4,8 +4,7 @@ class Admin::Communication::Website::ApplicationController < Admin::Communicatio protected def breadcrumb - add_breadcrumb t('dashboard'), :admin_root_path - add_breadcrumb '...' + short_breadcrumb breadcrumb_for @website, website_id: nil end diff --git a/app/controllers/admin/research/journal/application_controller.rb b/app/controllers/admin/research/journal/application_controller.rb index 43064c7e6..a4365619e 100644 --- a/app/controllers/admin/research/journal/application_controller.rb +++ b/app/controllers/admin/research/journal/application_controller.rb @@ -4,8 +4,7 @@ class Admin::Research::Journal::ApplicationController < Admin::Research::Applica protected def breadcrumb - add_breadcrumb t('dashboard'), :admin_root_path - add_breadcrumb '...' + short_breadcrumb breadcrumb_for @journal, journal_id: nil end diff --git a/app/models/communication/website/page.rb b/app/models/communication/website/page.rb index 114d2e4d3..fe2dbca5b 100644 --- a/app/models/communication/website/page.rb +++ b/app/models/communication/website/page.rb @@ -43,6 +43,7 @@ class Communication::Website::Page < ApplicationRecord after_save :publish_to_github scope :ordered, -> { order(:path) } + scope :recent, -> { order(updated_at: :desc).limit(10) } def content @content ||= github.read_file_at "_pages/#{id}.html" diff --git a/app/views/admin/application/_nav.html.erb b/app/views/admin/application/_nav.html.erb index 00d41bb7c..d29518d0e 100644 --- a/app/views/admin/application/_nav.html.erb +++ b/app/views/admin/application/_nav.html.erb @@ -1,4 +1,4 @@ -<nav id="sidebar" class="sidebar"> +<nav id="sidebar" class="sidebar<%= ' collapsed' if @menu_collapsed %>"> <div class="sidebar-content js-simplebar"> <%= link_to admin_root_path, class: 'sidebar-brand' do %> <%= image_tag 'osuny-white.svg', class: 'img-fluid' %> diff --git a/app/views/admin/communication/website/pages/_list.html.erb b/app/views/admin/communication/website/pages/_list.html.erb new file mode 100644 index 000000000..f32da088e --- /dev/null +++ b/app/views/admin/communication/website/pages/_list.html.erb @@ -0,0 +1,21 @@ +<table class="table"> + <thead> + <tr> + <th><%= Communication::Website::Page.human_attribute_name('title') %></th> + <th><%= Communication::Website::Page.human_attribute_name('path') %></th> + <th></th> + </tr> + </thead> + <tbody> + <% pages.each do |page| %> + <tr> + <td><%= link_to page, admin_communication_website_page_path(page.id) %></td> + <td><%= page.path %></td> + <td class="text-end"> + <%= edit_link page %> + <%= destroy_link page %> + </td> + </tr> + <% end %> + </tbody> +</table> diff --git a/app/views/admin/communication/website/pages/index.html.erb b/app/views/admin/communication/website/pages/index.html.erb index 829bfcfff..157e08e9d 100644 --- a/app/views/admin/communication/website/pages/index.html.erb +++ b/app/views/admin/communication/website/pages/index.html.erb @@ -1,26 +1,6 @@ <% content_for :title, Communication::Website::Page.model_name.human(count: 2) %> -<table class="table"> - <thead> - <tr> - <th><%= Communication::Website::Page.human_attribute_name('title') %></th> - <th><%= Communication::Website::Page.human_attribute_name('path') %></th> - <th></th> - </tr> - </thead> - <tbody> - <% @pages.each do |page| %> - <tr> - <td><%= link_to page, admin_communication_website_page_path(page.id) %></td> - <td><%= page.path %></td> - <td class="text-end"> - <%= edit_link page %> - <%= destroy_link page %> - </td> - </tr> - <% end %> - </tbody> -</table> +<%= render 'admin/communication/website/pages/list', pages: @pages %> <% content_for :buttons do %> <%= create_link Communication::Website::Page %> diff --git a/app/views/admin/communication/websites/show.html.erb b/app/views/admin/communication/websites/show.html.erb index 31fbef1b3..098fff183 100644 --- a/app/views/admin/communication/websites/show.html.erb +++ b/app/views/admin/communication/websites/show.html.erb @@ -13,18 +13,12 @@ <%= link_to t('create'), new_admin_communication_website_page_path(website_id: @website), - class: button_classes %> + class: button_classes('me-3') %> <%= link_to 'Toutes les pages', admin_communication_website_pages_path(website_id: @website) %> -<div class="row"> - <% @website.pages.ordered.limit(5).each do |page| %> - <div class="col-md-3 mt-4"> - <%= link_to page, admin_communication_website_page_path(website_id: @website, id: page) %> - </div> - <% end %> -</div> +<%= render 'admin/communication/website/pages/list', pages: @website.pages.recent %> <% content_for :buttons do %> <%= edit_link @website %> diff --git a/app/views/admin/dashboard/index.html.erb b/app/views/admin/dashboard/index.html.erb index 8b1daf9ec..b57ad81a8 100644 --- a/app/views/admin/dashboard/index.html.erb +++ b/app/views/admin/dashboard/index.html.erb @@ -10,3 +10,37 @@ </div> </div> </div> + +<% if current_university.research_journals.any? %> + <h2 class="h4 my-4"><%= Research::Journal.model_name.human(count: 2) %></h2> + <div class="row"> + <% current_university.research_journals.each do |journal| %> + <div class="col-md-4"> + <div class="card"> + <div class="card-body"> + <span class="float-end"><i class="fas fa-newspaper fa-2x"></i></span> + <h4><%= journal %></h4> + <p><%= link_to 'Voir', [:admin, journal], class: 'stretched-link' %></p> + </div> + </div> + </div> + <% end %> + </div> +<% end %> + +<% if current_university.communication_websites.any? %> + <h2 class="h4 my-4"><%= Communication::Website.model_name.human(count: 2) %></h2> + <div class="row"> + <% current_university.communication_websites.each do |website| %> + <div class="col-md-4"> + <div class="card"> + <div class="card-body"> + <span class="float-end"><i class="fas fa-sitemap fa-2x"></i></span> + <h4><%= website %></h4> + <p><%= link_to 'Voir', [:admin, website], class: 'stretched-link' %></p> + </div> + </div> + </div> + <% end %> + </div> +<% end %> -- GitLab