Skip to content
Snippets Groups Projects
Unverified Commit 23908b5f authored by Sébastien Gaya's avatar Sébastien Gaya
Browse files

static views + associations

parent 432e41f5
No related branches found
No related tags found
No related merge requests found
......@@ -66,8 +66,8 @@ module Communication::Website::WithAbouts
@people ||= begin
people = authors
if about_school?
people += about.university_people_through_teachers
people += about.university_people_through_administrators
people += about.university_people_through_involvements
people += about.university_people_through_roles
elsif about_journal?
people += about.people
end
......@@ -79,10 +79,10 @@ module Communication::Website::WithAbouts
@people_with_facets ||= begin
people = authors + authors.compact.map(&:author)
if about_school?
people += about.university_people_through_teachers
people += about.university_people_through_teachers.map(&:teacher)
people += about.university_people_through_administrators
people += about.university_people_through_administrators.map(&:administrator)
people += about.university_people_through_involvements
people += about.university_people_through_involvements.map(&:teacher)
people += about.university_people_through_roles
people += about.university_people_through_roles.map(&:administrator)
elsif about_journal?
people += about.people
people += about.people.map(&:researcher)
......
......@@ -83,13 +83,18 @@ class Education::Program < ApplicationRecord
as: :target,
dependent: :destroy
has_many :involvements_through_roles,
class_name: 'University::Person::Involvement',
through: :university_roles,
source: :involvements
has_many :university_people_through_role_involvements,
through: :involvements_through_roles,
source: :person
has_many :university_person_involvements,
class_name: 'University::Person::Involvement',
as: :target,
dependent: :destroy
has_many :university_people_through_involvements,
through: :university_person_involvements,
source: :person
has_many :website_categories,
class_name: 'Communication::Website::Category',
dependent: :destroy
......@@ -134,10 +139,12 @@ class Education::Program < ApplicationRecord
def git_dependencies(website)
[self] +
active_storage_blobs +
university_people_through_teachers +
university_people_through_teachers.map(&:teacher) +
university_people_through_roles
# TODO: les administrative via roles
university_people_through_involvements +
university_people_through_involvements.map(&:active_storage_blobs) +
university_people_through_involvements.map(&:teacher) +
university_people_through_role_involvements +
university_people_through_role_involvements.map(&:active_storage_blobs) +
university_people_through_role_involvements.map(&:administrator)
end
def git_destroy_dependencies(website)
......
......@@ -33,10 +33,6 @@ class Education::School < ApplicationRecord
-> { distinct },
through: :administrators,
source: :person
has_many :university_roles, class_name: 'University::Role', as: :target, dependent: :destroy
has_many :university_people_through_roles,
through: :university_roles,
source: :person
has_and_belongs_to_many :programs,
class_name: 'Education::Program',
join_table: 'education_programs_schools',
......@@ -48,6 +44,12 @@ class Education::School < ApplicationRecord
through: :teachers,
source: :person
has_many :university_roles, class_name: 'University::Role', as: :target, dependent: :destroy
has_many :involvements_through_roles, through: :university_roles, source: :involvements
has_many :university_people_through_involvements,
through: :involvements_through_roles,
source: :person
validates :name, :address, :city, :zipcode, :country, presence: true
scope :ordered, -> { order(:name) }
......@@ -62,7 +64,7 @@ class Education::School < ApplicationRecord
def git_dependencies(website)
[self] +
university_people_through_administrators +
university_people_through_administrators.map(&:administrator)
university_people_through_involvements +
university_people_through_involvements.map(&:administrator)
end
end
......@@ -40,7 +40,7 @@ class Research::Journal < ApplicationRecord
end
def git_dependencies(website)
[self] + articles + volumes + people + people.map(&:researcher)
[self] + articles + volumes + people + people.map(&:active_storage_blobs).flatten + people.map(&:researcher)
end
def git_destroy_dependencies(website)
......
......@@ -66,6 +66,7 @@ class Research::Journal::Article < ApplicationRecord
active_storage_blobs +
other_articles_in_the_volume +
people +
people.map(&:active_storage_blobs).flatten +
people.map(&:researcher)
end
......
......@@ -51,7 +51,7 @@ class Research::Journal::Volume < ApplicationRecord
end
def git_dependencies(website)
[self] + articles + people + people.map(&:researcher) + active_storage_blobs
[self] + articles + people + people.map(&:active_storage_blobs).flatten + people.map(&:researcher) + active_storage_blobs
end
def git_destroy_dependencies(website)
......
......@@ -120,7 +120,7 @@ class University::Person < ApplicationRecord
dependencies = []
if for_website?(website)
dependencies << self
dependencies << best_picture.blob
dependencies.concat active_storage_blobs
end
dependencies << administrator if administrator.for_website?(website)
dependencies << author if author.for_website?(website)
......
......@@ -30,7 +30,7 @@ class University::Person::Involvement < ApplicationRecord
enum kind: { administrator: 10, researcher: 20, teacher: 30 }
belongs_to :university
belongs_to :person
belongs_to :person, class_name: 'University::Person'
belongs_to :target, polymorphic: true
after_commit :sync_with_git
......
......@@ -25,7 +25,8 @@ class University::Role < ApplicationRecord
belongs_to :university
belongs_to :target, polymorphic: true, optional: true
has_many :involvements, class_name: 'University::Person::Involvement', as: :target
has_many :involvements, class_name: 'University::Person::Involvement', as: :target, dependent: :destroy
has_many :people, through: :involvements
def to_s
"#{description}"
......
......@@ -11,21 +11,21 @@ image_alt: "<%= @program.featured_image_alt %>"
<% end %>
category: "<%= @website.categories.find_by(program_id: @program.id)&.path %>/"
teachers:
<% @program.teachers.includes(:person).ordered.each do |teacher| %>
- "<%= teacher.person.slug %>"
<% @program.university_person_involvements.includes(:person).ordered.each do |involvement| %>
- "<%= involvement.person.slug %>"
<% end %>
teachers_description:
<% @program.teachers.includes(:person).ordered.each do |teacher| %>
"<%= teacher.person.slug %>": >
<%= teacher.best_description %>
<% @program.university_person_involvements.includes(:person).ordered.each do |involvement| %>
"<%= involvement.person.slug %>": >
<%= involvement.description %>
<% end %>
roles:
<% @program.roles.ordered.each do |role| %>
<% @program.university_roles.ordered.each do |role| %>
- title: >
<%= role.to_s %>
persons:
<% role.people.includes(:person).ordered.each do |role_person| %>
- "<%= role_person.person.slug %>"
<% role.involvements.includes(:person).ordered.each do |involvement| %>
- "<%= involvement.person.slug %>"
<% end %>
<% end %>
continuing: <%= @program.continuing %>
......
......@@ -12,12 +12,12 @@ country: >
phone: >
<%= @school.phone %>
administrators:
<% @school.administrators.includes(:person).ordered.each do |administrator| %>
- "<%= administrator.person.slug %>"
<% @school.involvements_through_roles.includes(:person).ordered.each do |involvement| %>
- "<%= involvement.person.slug %>"
<% end %>
administrators_description:
<% @school.administrators.includes(:person).ordered.each do |administrator| %>
"<%= administrator.person.slug %>": >
<%= administrator.best_description %>
<% @school.involvements_through_roles.includes(:person).ordered.each do |involvement| %>
"<%= involvement.person.slug %>": >
<%= involvement.best_description %>
<% 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