From a49c1aaa93d6a63a107cfa1bd4afbc6ada1455cd Mon Sep 17 00:00:00 2001 From: Arnaud Levy <contact@arnaudlevy.com> Date: Tue, 4 Jan 2022 12:48:34 +0100 Subject: [PATCH] person --- .../administration/members_controller.rb | 6 +- app/models/administration/member.rb | 151 ++++++++---------- app/models/communication/website/category.rb | 2 +- app/models/communication/website/page.rb | 2 +- app/models/communication/website/post.rb | 4 + app/models/concerns/with_git.rb | 5 +- .../members/administrator.html.erb | 7 + .../administration/members/author.html.erb | 7 + .../members/researcher.html.erb | 7 + .../administration/members/static.html.erb | 13 ++ .../administration/members/teacher.html.erb | 7 + .../website/authors/static.html.erb | 10 -- .../admin/education/teachers/static.html.erb | 16 -- .../research/researchers/static.html.erb | 10 -- 14 files changed, 122 insertions(+), 125 deletions(-) create mode 100644 app/views/admin/administration/members/administrator.html.erb create mode 100644 app/views/admin/administration/members/author.html.erb create mode 100644 app/views/admin/administration/members/researcher.html.erb create mode 100644 app/views/admin/administration/members/teacher.html.erb delete mode 100644 app/views/admin/communication/website/authors/static.html.erb delete mode 100644 app/views/admin/education/teachers/static.html.erb delete mode 100644 app/views/admin/research/researchers/static.html.erb diff --git a/app/controllers/admin/administration/members_controller.rb b/app/controllers/admin/administration/members_controller.rb index d17fe8e7f..70cb82433 100644 --- a/app/controllers/admin/administration/members_controller.rb +++ b/app/controllers/admin/administration/members_controller.rb @@ -22,7 +22,7 @@ class Admin::Administration::MembersController < Admin::Administration::Applicat end def create - if @member.save + if @member.save_and_sync redirect_to admin_administration_member_path(@member), notice: t('admin.successfully_created_html', model: @member.to_s) else breadcrumb @@ -31,7 +31,7 @@ class Admin::Administration::MembersController < Admin::Administration::Applicat end def update - if @member.update(member_params) + if @member.update_and_sync(member_params) redirect_to admin_administration_member_path(@member), notice: t('admin.successfully_updated_html', model: @member.to_s) else breadcrumb @@ -41,7 +41,7 @@ class Admin::Administration::MembersController < Admin::Administration::Applicat end def destroy - @member.destroy + @member.destroy_and_sync redirect_to admin_administration_members_url, notice: t('admin.successfully_destroyed_html', model: @member.to_s) end diff --git a/app/models/administration/member.rb b/app/models/administration/member.rb index 7ffa80d32..cf4201377 100644 --- a/app/models/administration/member.rb +++ b/app/models/administration/member.rb @@ -36,11 +36,6 @@ class Administration::Member < ApplicationRecord belongs_to :university belongs_to :user, optional: true - has_many :communication_website_posts, - class_name: 'Communication::Website::Post', - foreign_key: :author_id, - dependent: :nullify - has_and_belongs_to_many :research_journal_articles, class_name: 'Research::Journal::Article', join_table: :research_journal_articles_researchers, @@ -52,29 +47,42 @@ class Administration::Member < ApplicationRecord foreign_key: :education_teacher_id, association_foreign_key: :education_program_id - has_many :communication_websites, - -> { distinct }, - through: :communication_website_posts, - source: :website - has_many :research_websites, - -> { distinct }, - through: :research_journal_articles, - source: :websites - has_many :education_websites, - -> { distinct }, - through: :education_programs, - source: :websites - - validates_presence_of :first_name, :last_name - validates_uniqueness_of :email, scope: :university_id, allow_blank: true, if: :will_save_change_to_email? - validates_format_of :email, with: Devise::email_regexp, allow_blank: true, if: :will_save_change_to_email? - - - scope :ordered, -> { order(:last_name, :first_name) } + has_many :communication_website_posts, + class_name: 'Communication::Website::Post', + foreign_key: :author_id, + dependent: :nullify + + has_many :communication_websites, + -> { distinct }, + through: :communication_website_posts, + source: :website + + has_many :research_websites, + -> { distinct }, + through: :research_journal_articles, + source: :websites + + has_many :education_websites, + -> { distinct }, + through: :education_programs, + source: :websites + + validates_presence_of :first_name, :last_name + validates_uniqueness_of :email, + scope: :university_id, + allow_blank: true, + if: :will_save_change_to_email? + validates_format_of :email, + with: Devise::email_regexp, + allow_blank: true, + if: :will_save_change_to_email? + + + scope :ordered, -> { order(:last_name, :first_name) } scope :administratives, -> { where(is_administrative: true) } - scope :authors, -> { where(is_author: true) } - scope :teachers, -> { where(is_teacher: true) } - scope :researchers, -> { where(is_researcher: true) } + scope :authors, -> { where(is_author: true) } + scope :teachers, -> { where(is_teacher: true) } + scope :researchers, -> { where(is_researcher: true) } def to_s "#{first_name} #{last_name}" @@ -88,68 +96,47 @@ class Administration::Member < ApplicationRecord ].flatten.uniq) end - def github_manifest - manifest = [] - 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 + def identifiers + [:static, :author, :researcher, :teacher, :administrator] + end + + def git_path_static + "content/persons/#{slug}.html" + end + + def git_path_author + "content/authors/#{slug}/_index.html" + end + + def git_path_researcher + "content/researchers/#{slug}/_index.html" + end + + def git_path_teacher + "content/teachers/#{slug}/_index.html" + end + + def git_path_administrator + "content/administrators/#{slug}/_index.html" + end + + def git_dependencies_static + [] end - def author_github_manifest_items - [ - { - identifier: "author", - 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 } - ) } - } - ] + def git_dependencies_author + [] end - def researcher_github_manifest_items - [ - { - identifier: "researcher", - generated_path: -> (github_file) { "content/researchers/#{slug}/_index.html" }, - data: -> (github_file) { ApplicationController.render( - template: "admin/research/researchers/static", - layout: false, - assigns: { researcher: self, github_file: github_file } - ) } - } - ] + def git_dependencies_researcher + [] end - def teacher_github_manifest_items - [ - { - identifier: "teacher", - generated_path: -> (github_file) { "content/teachers/#{slug}/_index.html" }, - data: -> (github_file) { ApplicationController.render( - template: "admin/education/teachers/static", - layout: false, - assigns: { teacher: self, github_file: github_file } - ) } - } - ] + def git_dependencies_teacher + [] 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 } - ) } - } - ] + def git_dependencies_administrator + [] end end diff --git a/app/models/communication/website/category.rb b/app/models/communication/website/category.rb index 8f294a62a..56c83147c 100644 --- a/app/models/communication/website/category.rb +++ b/app/models/communication/website/category.rb @@ -83,7 +83,7 @@ class Communication::Website::Category < ApplicationRecord "content/categories/#{path}/_index.html".gsub(/\/+/, '/') end - def git_dependencies(identifier) + def git_dependencies_static posts end diff --git a/app/models/communication/website/page.rb b/app/models/communication/website/page.rb index 076601f13..6d328380c 100644 --- a/app/models/communication/website/page.rb +++ b/app/models/communication/website/page.rb @@ -75,7 +75,7 @@ class Communication::Website::Page < ApplicationRecord "content/pages/#{path}/_index.html".gsub(/\/+/, '/') end - def git_dependencies(identifier) + def git_dependencies_static descendents + siblings end diff --git a/app/models/communication/website/post.rb b/app/models/communication/website/post.rb index 290c08f4e..616d3a21d 100644 --- a/app/models/communication/website/post.rb +++ b/app/models/communication/website/post.rb @@ -71,6 +71,10 @@ class Communication::Website::Post < ApplicationRecord "content/posts/#{published_at.year}/#{published_at.strftime "%Y-%m-%d"}-#{slug}.html" end + def git_dependencies_static + [author] + categories + end + def to_s "#{title}" end diff --git a/app/models/concerns/with_git.rb b/app/models/concerns/with_git.rb index dcd0af344..37f41564d 100644 --- a/app/models/concerns/with_git.rb +++ b/app/models/concerns/with_git.rb @@ -45,7 +45,8 @@ module WithGit websites.each do |website| identifiers.each do |identifier| Communication::Website::GitFile.sync website, self, identifier - git_dependencies(identifier).each do |object| + dependencies = send "git_dependencies_#{identifier}" + dependencies.each do |object| Communication::Website::GitFile.sync website, object, identifier end end @@ -61,7 +62,7 @@ module WithGit [:static] end - def git_dependencies(identifier) + def git_dependencies_static [] end end diff --git a/app/views/admin/administration/members/administrator.html.erb b/app/views/admin/administration/members/administrator.html.erb new file mode 100644 index 000000000..4e281854b --- /dev/null +++ b/app/views/admin/administration/members/administrator.html.erb @@ -0,0 +1,7 @@ +--- +title: > + Responsabilités de <%= @member.to_s %> +person: > + <%= @member.to_s %> +slug: "<%= @member.slug %>" +--- diff --git a/app/views/admin/administration/members/author.html.erb b/app/views/admin/administration/members/author.html.erb new file mode 100644 index 000000000..3dccaf0e0 --- /dev/null +++ b/app/views/admin/administration/members/author.html.erb @@ -0,0 +1,7 @@ +--- +title: > + Actualités de <%= @member.to_s %> +person: > + <%= @member.to_s %> +slug: "<%= @member.slug %>" +--- diff --git a/app/views/admin/administration/members/researcher.html.erb b/app/views/admin/administration/members/researcher.html.erb new file mode 100644 index 000000000..823ad92ba --- /dev/null +++ b/app/views/admin/administration/members/researcher.html.erb @@ -0,0 +1,7 @@ +--- +title: > + Publications de <%= @member.to_s %> +person: > + <%= @member.to_s %> +slug: "<%= @member.slug %>" +--- diff --git a/app/views/admin/administration/members/static.html.erb b/app/views/admin/administration/members/static.html.erb index 3c16ebf87..792802493 100644 --- a/app/views/admin/administration/members/static.html.erb +++ b/app/views/admin/administration/members/static.html.erb @@ -6,5 +6,18 @@ first_name: "<%= @member.first_name %>" last_name: "<%= @member.last_name %>" phone: "<%= @member.phone %>" email: "<%= @member.email %>" +roles: +<% if @member.is_author %> + - author +<% end %> +<% if @member.is_teacher %> + - teacher +<% end %> +<% if @member.is_researcher %> + - researcher +<% end %> +<% if @member.is_administrative %> + - administrator +<% end %> --- <%= prepare_for_github @member.biography, @member.university %> diff --git a/app/views/admin/administration/members/teacher.html.erb b/app/views/admin/administration/members/teacher.html.erb new file mode 100644 index 000000000..6a76fea4a --- /dev/null +++ b/app/views/admin/administration/members/teacher.html.erb @@ -0,0 +1,7 @@ +--- +title: > + Enseignements de <%= @member.to_s %> +person: > + <%= @member.to_s %> +slug: "<%= @member.slug %>" +--- diff --git a/app/views/admin/communication/website/authors/static.html.erb b/app/views/admin/communication/website/authors/static.html.erb deleted file mode 100644 index b52f8eadc..000000000 --- a/app/views/admin/communication/website/authors/static.html.erb +++ /dev/null @@ -1,10 +0,0 @@ ---- -title: > - <%= @author.to_s %> -slug: "<%= @author.slug %>" -first_name: "<%= @author.first_name %>" -last_name: "<%= @author.last_name %>" -phone: "<%= @author.phone %>" -email: "<%= @author.email %>" ---- -<%= prepare_for_github @author.biography, @author.university %> diff --git a/app/views/admin/education/teachers/static.html.erb b/app/views/admin/education/teachers/static.html.erb deleted file mode 100644 index 8da73a8a3..000000000 --- a/app/views/admin/education/teachers/static.html.erb +++ /dev/null @@ -1,16 +0,0 @@ ---- -title: > - <%= @teacher.to_s %> -slug: "<%= @teacher.slug %>" -first_name: "<%= @teacher.first_name %>" -last_name: "<%= @teacher.last_name %>" -phone: "<%= @teacher.phone %>" -email: "<%= @teacher.email %>" -<% if @teacher.education_programs.any? %> -programs: - <% @teacher.education_programs.each do |program| %> - - "<%= program.id %>" - <% end %> -<% end %> ---- -<%= prepare_for_github @teacher.biography, @teacher.university %> diff --git a/app/views/admin/research/researchers/static.html.erb b/app/views/admin/research/researchers/static.html.erb deleted file mode 100644 index ba6513d72..000000000 --- a/app/views/admin/research/researchers/static.html.erb +++ /dev/null @@ -1,10 +0,0 @@ ---- -title: > - <%= @researcher.to_s %> -slug: "<%= @researcher.slug %>" -first_name: "<%= @researcher.first_name %>" -last_name: "<%= @researcher.last_name %>" -phone: "<%= @researcher.phone %>" -email: "<%= @researcher.email %>" ---- -<%= prepare_for_github @researcher.biography, @researcher.university %> -- GitLab