From 8c2afc7d151346e73e3838f729911ee333d94f28 Mon Sep 17 00:00:00 2001 From: Arnaud Levy <contact@arnaudlevy.com> Date: Fri, 24 Dec 2021 11:42:49 +0100 Subject: [PATCH] almost done, though member export broken --- app/models/administration/member.rb | 42 ++++++++++--------- .../communication/website/github_file.rb | 9 ---- app/models/communication/website/menu/item.rb | 17 ++++---- app/models/user.rb | 6 +-- .../administration/members/_list.html.erb | 6 ++- .../administration/members/static.html.erb | 10 +++++ app/views/admin/application/_top.html.erb | 2 +- .../website/authors/_list.html.erb | 6 ++- .../website/authors/static.html.erb | 13 ++---- .../admin/education/teachers/_list.html.erb | 3 +- ...tic_collection.yml.erb => static.html.erb} | 11 ++--- .../admin/research/researchers/index.html.erb | 4 +- ...tic_collection.yml.erb => static.html.erb} | 9 ++-- 13 files changed, 72 insertions(+), 66 deletions(-) create mode 100644 app/views/admin/administration/members/static.html.erb rename app/views/admin/education/teachers/{static_collection.yml.erb => static.html.erb} (69%) rename app/views/admin/research/researchers/{static_collection.yml.erb => static.html.erb} (51%) diff --git a/app/models/administration/member.rb b/app/models/administration/member.rb index 7d399e5ef..bf3afeffa 100644 --- a/app/models/administration/member.rb +++ b/app/models/administration/member.rb @@ -77,7 +77,7 @@ class Administration::Member < ApplicationRecord scope :researchers, -> { where(is_researcher: true) } def to_s - "#{last_name} #{first_name}" + "#{first_name} #{last_name}" end def websites @@ -93,6 +93,7 @@ class Administration::Member < ApplicationRecord manifest.concat(author_github_manifest_items) if is_author? manifest.concat(researcher_github_manifest_items) if is_researcher? manifest.concat(teacher_github_manifest_items) if is_teacher? + manifest.concat(administrator_github_manifest_items) if is_administrative? manifest end @@ -100,22 +101,12 @@ class Administration::Member < ApplicationRecord [ { identifier: "author", - generated_path: -> (github_file) { "#{github_file.website.authors_github_directory}/#{slug}.yml" }, + generated_path: -> (github_file) { "content/authors/#{slug}/_index.html" }, data: -> (github_file) { ApplicationController.render( template: "admin/communication/website/authors/static", layout: false, assigns: { author: self, github_file: github_file } ) } - }, - { - identifier: "author_collection_item", - generated_path: -> (github_file) { "_data/authors/#{slug}.yml" }, - data: -> (github_file) { ApplicationController.render( - template: "admin/communication/website/authors/static_collection", - formats: [:yml], - layout: false, - assigns: { author: self, github_file: github_file } - ) } } ] end @@ -123,11 +114,10 @@ class Administration::Member < ApplicationRecord def researcher_github_manifest_items [ { - identifier: "researcher_collection_item", - generated_path: -> (github_file) { "_data/researchers/#{slug}.yml" }, + identifier: "researcher", + generated_path: -> (github_file) { "content/researchers/#{slug}/_index.html" }, data: -> (github_file) { ApplicationController.render( - template: "admin/research/researchers/static_collection", - formats: [:yml], + template: "admin/research/researchers/static", layout: false, assigns: { researcher: self, github_file: github_file } ) } @@ -138,11 +128,10 @@ class Administration::Member < ApplicationRecord def teacher_github_manifest_items [ { - identifier: "teacher_collection_item", - generated_path: -> (github_file) { "_data/teachers/#{slug}.yml" }, + identifier: "teacher", + generated_path: -> (github_file) { "content/teachers/#{slug}/_index.html" }, data: -> (github_file) { ApplicationController.render( - template: "admin/education/teachers/static_collection", - formats: [:yml], + template: "admin/education/teachers/static", layout: false, assigns: { teacher: self, github_file: github_file } ) } @@ -150,4 +139,17 @@ class Administration::Member < ApplicationRecord ] end + def administrator_github_manifest_items + [ + { + identifier: "administrator", + generated_path: -> (github_file) { "content/administrators/#{slug}/_index.html" }, + data: -> (github_file) { ApplicationController.render( + template: "admin/administration/members/static", + layout: false, + assigns: { member: self, github_file: github_file } + ) } + } + ] + end end diff --git a/app/models/communication/website/github_file.rb b/app/models/communication/website/github_file.rb index e173927ee..95a09b42e 100644 --- a/app/models/communication/website/github_file.rb +++ b/app/models/communication/website/github_file.rb @@ -46,15 +46,6 @@ class Communication::Website::GithubFile < ApplicationRecord add_media_to_batch(github) end - def github_frontmatter - @github_frontmatter ||= begin - github_content = github.read_file_at(github_path) - FrontMatterParser::Parser.new(:md).call(github_content) - rescue - FrontMatterParser::Parser.new(:md).call('') - end - end - protected def add_media_to_batch(github) diff --git a/app/models/communication/website/menu/item.rb b/app/models/communication/website/menu/item.rb index 0f4f2b62d..538a99285 100644 --- a/app/models/communication/website/menu/item.rb +++ b/app/models/communication/website/menu/item.rb @@ -58,22 +58,25 @@ class Communication::Website::Menu::Item < ApplicationRecord end def static_target + target = case self.kind when 'url' - url + target = url when 'programs' - "/#{website.programs_github_directory}" + target = "/#{website.programs_github_directory}" when 'program' - "/#{website.programs_github_directory}#{about.path}" + target = "/#{website.programs_github_directory}#{about.path}" when 'news' - "/#{website.posts_github_directory}" + target = "/#{website.posts_github_directory}" when 'staff' - "/#{website.staff_github_directory}" + target = "/#{website.staff_github_directory}" when 'blank' - nil + target = nil else - about&.path + target = about&.path end + target.end_with? "/" ? target + : "#{target}/" end def list_of_other_items diff --git a/app/models/user.rb b/app/models/user.rb index 43d21694c..912755e7b 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -64,12 +64,8 @@ class User < ApplicationRecord scope :ordered, -> { order(:last_name, :first_name) } - def human_name - "#{first_name} #{last_name}" - end - def to_s - "#{last_name} #{first_name}" + "#{first_name} #{last_name}" end end diff --git a/app/views/admin/administration/members/_list.html.erb b/app/views/admin/administration/members/_list.html.erb index 7a1dcab14..5d04d354d 100644 --- a/app/views/admin/administration/members/_list.html.erb +++ b/app/views/admin/administration/members/_list.html.erb @@ -1,14 +1,16 @@ <table class="<%= table_classes %>"> <thead> <tr> - <th><%= Administration::Member.human_attribute_name('name') %></th> + <th><%= Administration::Member.human_attribute_name('last_name') %></th> + <th><%= Administration::Member.human_attribute_name('first_name') %></th> <th></th> </tr> </thead> <tbody> <% members.each do |member| %> <tr> - <td><%= link_to member, admin_administration_member_path(member) %></td> + <td><%= link_to member.last_name, admin_administration_member_path(member) %></td> + <td><%= link_to member.first_name, admin_administration_member_path(member) %></td> <td class="text-end"> <div class="btn-group" role="group"> <%= link_to t('edit'), diff --git a/app/views/admin/administration/members/static.html.erb b/app/views/admin/administration/members/static.html.erb new file mode 100644 index 000000000..3c16ebf87 --- /dev/null +++ b/app/views/admin/administration/members/static.html.erb @@ -0,0 +1,10 @@ +--- +title: > + <%= @member.to_s %> +slug: "<%= @member.slug %>" +first_name: "<%= @member.first_name %>" +last_name: "<%= @member.last_name %>" +phone: "<%= @member.phone %>" +email: "<%= @member.email %>" +--- +<%= prepare_for_github @member.biography, @member.university %> diff --git a/app/views/admin/application/_top.html.erb b/app/views/admin/application/_top.html.erb index 15a97ce26..3de9fcc23 100644 --- a/app/views/admin/application/_top.html.erb +++ b/app/views/admin/application/_top.html.erb @@ -7,7 +7,7 @@ <ul class="navbar-nav navbar-align"> <li class="nav-item dropdown"> <a class="nav-link dropdown-toggle d-none d-sm-inline-block js-user-dropdown-toggle" href="#" data-bs-toggle="dropdown"> - <span class="text-dark"><%= current_user.human_name %></span> + <span class="text-dark"><%= current_user.to_s %></span> </a> <div class="dropdown-menu dropdown-menu-end"> <%= link_to t('menu.profile'), edit_user_registration_path, class: 'dropdown-item' %> diff --git a/app/views/admin/communication/website/authors/_list.html.erb b/app/views/admin/communication/website/authors/_list.html.erb index fede64fd3..9eb1c1bdd 100644 --- a/app/views/admin/communication/website/authors/_list.html.erb +++ b/app/views/admin/communication/website/authors/_list.html.erb @@ -1,14 +1,16 @@ <table class="<%= table_classes %>"> <thead> <tr> - <th><%= Administration::Member.human_attribute_name('name') %></th> + <th><%= Administration::Member.human_attribute_name('last_name') %></th> + <th><%= Administration::Member.human_attribute_name('first_name') %></th> <th><%= t('communication.number_of_posts') %></th> </tr> </thead> <tbody> <% authors.each do |author| %> <tr> - <td><%= link_to author, admin_communication_website_author_path(website_id: @website.id, id: author.id) %></td> + <td><%= link_to author.last_name, admin_communication_website_author_path(website_id: @website.id, id: author.id) %></td> + <td><%= link_to author.first_name, admin_communication_website_author_path(website_id: @website.id, id: author.id) %></td> <td><%= author.communication_website_posts.count %></td> </tr> <% end %> diff --git a/app/views/admin/communication/website/authors/static.html.erb b/app/views/admin/communication/website/authors/static.html.erb index e563627b9..b52f8eadc 100644 --- a/app/views/admin/communication/website/authors/static.html.erb +++ b/app/views/admin/communication/website/authors/static.html.erb @@ -1,17 +1,10 @@ --- -title: "<%= @author.to_s %>" +title: > + <%= @author.to_s %> slug: "<%= @author.slug %>" -identifier: "<%= @author.id %>" -permalink: "/<%= @github_file.website.authors_github_directory %>/<%= @author.slug %>" first_name: "<%= @author.first_name %>" last_name: "<%= @author.last_name %>" phone: "<%= @author.phone %>" email: "<%= @author.email %>" -biography: > - <%= prepare_for_github @author.biography, @author.university %> -pagination: - enabled: true - tag: <%= @author.id %> - permalink: /:num/ --- -<%= @github_file.github_frontmatter.content.html_safe %> +<%= prepare_for_github @author.biography, @author.university %> diff --git a/app/views/admin/education/teachers/_list.html.erb b/app/views/admin/education/teachers/_list.html.erb index ec41239ac..5ef8fafad 100644 --- a/app/views/admin/education/teachers/_list.html.erb +++ b/app/views/admin/education/teachers/_list.html.erb @@ -1,7 +1,8 @@ <table class="<%= table_classes %>"> <thead> <tr> - <th><%= Administration::Member.human_attribute_name('name') %></th> + <th><%= Administration::Member.human_attribute_name('last_name') %></th> + <th><%= Administration::Member.human_attribute_name('first_name') %></th> <th></th> </tr> </thead> diff --git a/app/views/admin/education/teachers/static_collection.yml.erb b/app/views/admin/education/teachers/static.html.erb similarity index 69% rename from app/views/admin/education/teachers/static_collection.yml.erb rename to app/views/admin/education/teachers/static.html.erb index 954df1c55..8da73a8a3 100644 --- a/app/views/admin/education/teachers/static_collection.yml.erb +++ b/app/views/admin/education/teachers/static.html.erb @@ -1,15 +1,16 @@ -title: "<%= @teacher.to_s %>" -identifier: "<%= @teacher.id %>" +--- +title: > + <%= @teacher.to_s %> +slug: "<%= @teacher.slug %>" first_name: "<%= @teacher.first_name %>" last_name: "<%= @teacher.last_name %>" phone: "<%= @teacher.phone %>" email: "<%= @teacher.email %>" -slug: "<%= @teacher.slug %>" <% if @teacher.education_programs.any? %> programs: <% @teacher.education_programs.each do |program| %> - "<%= program.id %>" <% end %> <% end %> -biography: > - <%= prepare_for_github @teacher.biography, @teacher.university %> +--- +<%= prepare_for_github @teacher.biography, @teacher.university %> diff --git a/app/views/admin/research/researchers/index.html.erb b/app/views/admin/research/researchers/index.html.erb index eb0e7bb1d..9f11f2a30 100644 --- a/app/views/admin/research/researchers/index.html.erb +++ b/app/views/admin/research/researchers/index.html.erb @@ -4,6 +4,7 @@ <thead> <tr> <th><%= Administration::Member.human_attribute_name('name') %></th> + <th><%= Administration::Member.human_attribute_name('first_name') %></th> <th><%= t('research.number_of_articles') %></th> </tr> </thead> @@ -11,7 +12,8 @@ <tbody> <% @researchers.each do |researcher| %> <tr> - <td><%= link_to researcher, admin_research_researcher_path(researcher) %></td> + <td><%= link_to researcher.last_name, admin_research_researcher_path(researcher) %></td> + <td><%= link_to researcher.first_name, admin_research_researcher_path(researcher) %></td> <td><%= researcher.research_journal_articles.count %></td> </tr> <% end %> diff --git a/app/views/admin/research/researchers/static_collection.yml.erb b/app/views/admin/research/researchers/static.html.erb similarity index 51% rename from app/views/admin/research/researchers/static_collection.yml.erb rename to app/views/admin/research/researchers/static.html.erb index 3a539eebb..ba6513d72 100644 --- a/app/views/admin/research/researchers/static_collection.yml.erb +++ b/app/views/admin/research/researchers/static.html.erb @@ -1,7 +1,10 @@ -title: "<%= @researcher.to_s %>" +--- +title: > + <%= @researcher.to_s %> +slug: "<%= @researcher.slug %>" first_name: "<%= @researcher.first_name %>" last_name: "<%= @researcher.last_name %>" phone: "<%= @researcher.phone %>" email: "<%= @researcher.email %>" -biography: > - <%= prepare_for_github @researcher.biography, @researcher.university %> +--- +<%= prepare_for_github @researcher.biography, @researcher.university %> -- GitLab