diff --git a/app/controllers/admin/university/alumni/cohorts_controller.rb b/app/controllers/admin/university/alumni/cohorts_controller.rb index c3a285dd9d947bbeb4ff7ea89679576adae7ffac..9af2f787c76bba2e2b6f1f4f29107a3aafba547e 100644 --- a/app/controllers/admin/university/alumni/cohorts_controller.rb +++ b/app/controllers/admin/university/alumni/cohorts_controller.rb @@ -30,7 +30,7 @@ class Admin::University::Alumni::CohortsController < Admin::University::Applicat def cohorts_params params.require(:university_person) - .permit(cohorts_attributes: [:id, :program_id, :year, :_destroy]) + .permit(cohorts_attributes: [:id, :school_id, :program_id, :year, :_destroy]) .merge(university_id: current_university.id) .tap { |permitted_params| permitted_params[:cohorts_attributes].transform_values! do |hash| diff --git a/app/models/education/cohort.rb b/app/models/education/cohort.rb index fff2ec382e6c82e454bc387c07b2b21a8c207ed6..c086cf0d3a93432e4d178efbb8c686f8013f9474 100644 --- a/app/models/education/cohort.rb +++ b/app/models/education/cohort.rb @@ -8,23 +8,30 @@ # updated_at :datetime not null # academic_year_id :uuid not null, indexed # program_id :uuid not null, indexed +# school_id :uuid not null, indexed # university_id :uuid not null, indexed # # Indexes # # index_education_cohorts_on_academic_year_id (academic_year_id) # index_education_cohorts_on_program_id (program_id) +# index_education_cohorts_on_school_id (school_id) # index_education_cohorts_on_university_id (university_id) # # Foreign Keys # # fk_rails_0f4a4f43d9 (university_id => universities.id) # fk_rails_72528c3d76 (program_id => education_programs.id) +# fk_rails_8545767e2d (school_id => education_schools.id) # fk_rails_c2d725cabd (academic_year_id => education_academic_years.id) # class Education::Cohort < ApplicationRecord include WithUniversity + belongs_to :school, + class_name: 'Education::School' + alias_attribute :education_school, :school + belongs_to :program, class_name: 'Education::Program' alias_attribute :education_program, :program @@ -38,7 +45,7 @@ class Education::Cohort < ApplicationRecord foreign_key: 'education_cohort_id', association_foreign_key: 'university_person_id' - validates_associated :academic_year, :program + validates_associated :school, :academic_year, :program validates :year, presence: true scope :ordered, -> { @@ -46,7 +53,7 @@ class Education::Cohort < ApplicationRecord } def to_s - "#{program} #{academic_year} #{name}" + "#{school} #{program} #{academic_year}" end def year diff --git a/app/models/university/person/with_education.rb b/app/models/university/person/with_education.rb index 15a7e3682261b48ebe8882a95c1fee4b95f6f43f..55e94ad13a133322ff6755e65acdcefe770377a7 100644 --- a/app/models/university/person/with_education.rb +++ b/app/models/university/person/with_education.rb @@ -67,7 +67,7 @@ module University::Person::WithEducation cohorts_ids = [] self.cohorts.map do |object| academic_year = Education::AcademicYear.where(university_id: university_id, year: object.year).first_or_create - cohort = Education::Cohort.where(university_id: university_id, program_id: object.program_id, academic_year_id: academic_year.id).first_or_initialize + cohort = Education::Cohort.where(university_id: university_id, school_id: object.school_id, program_id: object.program_id, academic_year_id: academic_year.id).first_or_initialize return unless cohort.valid? cohort.save if cohort.new_record? unless cohorts_ids.include?(cohort.reload.id) || object._destroy diff --git a/app/views/admin/education/cohorts/_list.html.erb b/app/views/admin/education/cohorts/_list.html.erb index 5d5ed64b255db9496160606195b7dba5220d033f..9f593bd74d8dd545f7fbe6a484bcb84cce7dbab5 100644 --- a/app/views/admin/education/cohorts/_list.html.erb +++ b/app/views/admin/education/cohorts/_list.html.erb @@ -2,6 +2,7 @@ <thead> <tr> <th><%= Education::Cohort.human_attribute_name('year') %></th> + <th><%= Education::Cohort.human_attribute_name('school') %></th> <th><%= Education::Cohort.human_attribute_name('program') %></th> <th><%= Education::Cohort.human_attribute_name('alumni') %></th> </tr> @@ -15,7 +16,8 @@ <%= cohort.name %> <% end %> </td> - <td><%= link_to cohort.program, [:admin, cohort.program] %></td> + <td><%= link_to_if can?(:read, cohort.school), cohort.school, [:admin, cohort.school] %></td> + <td><%= link_to_if can?(:read, cohort.program), cohort.program, [:admin, cohort.program] %></td> <td><%= cohort.people.count %></td> </tr> <% end %> diff --git a/app/views/admin/education/cohorts/show.html.erb b/app/views/admin/education/cohorts/show.html.erb index 9453d4e8edeedb495d7c5e4ec94dbf61e048bfe2..e6597d907d6a6c5a9949f2ee2baffbb584556fa6 100644 --- a/app/views/admin/education/cohorts/show.html.erb +++ b/app/views/admin/education/cohorts/show.html.erb @@ -4,6 +4,8 @@ <div class="col-md-8"> <div class="card flex-fill w-100"> <div class="card-body"> + <h3 class="h5"><%= Education::Cohort.human_attribute_name('school') %></h3> + <p><%= link_to_if can?(:read, @cohort.school), @cohort.school, [:admin, @cohort.school] %></p> <h3 class="h5"><%= Education::Cohort.human_attribute_name('program') %></h3> <p><%= link_to_if can?(:read, @cohort.program), @cohort.program, [:admin, @cohort.program] %></p> <h3 class="h5"><%= Education::Cohort.human_attribute_name('year') %></h3> diff --git a/app/views/admin/education/programs/show/_cohorts.html.erb b/app/views/admin/education/programs/show/_cohorts.html.erb index 4e37a2cbba97b81a70d39d89814f39ce23c08f47..e954c2e8acf955de2e24648ea4b3a4c62442ac02 100644 --- a/app/views/admin/education/programs/show/_cohorts.html.erb +++ b/app/views/admin/education/programs/show/_cohorts.html.erb @@ -11,6 +11,7 @@ <thead> <tr> <th><%= Education::Cohort.human_attribute_name('year') %></th> + <th><%= Education::Cohort.human_attribute_name('school') %></th> <th><%= Education::Cohort.human_attribute_name('alumni') %></th> </tr> </thead> @@ -23,6 +24,7 @@ <%= cohort.name %> <% end %> </td> + <td><%= link_to_if can?(:read, cohort.school), cohort.school, [:admin, cohort.school] %></td> <td><%= cohort.people.count %></td> </tr> <% end %> diff --git a/app/views/admin/university/alumni/cohorts/_cohort_fields.html.erb b/app/views/admin/university/alumni/cohorts/_cohort_fields.html.erb index 5ebeac2151780506b8e7b588365f59dc9a76e48a..b66b73ca7f2bc0df238ae63e3524b2554432b9ce 100644 --- a/app/views/admin/university/alumni/cohorts/_cohort_fields.html.erb +++ b/app/views/admin/university/alumni/cohorts/_cohort_fields.html.erb @@ -3,7 +3,15 @@ <div class="card mb-3"> <div class="card-body"> <div class="row"> - <div class="col-md-5"> + <div class="col-md-3"> + <%= f.association :school, + collection: current_university.education_schools.ordered, + label: false, + include_blank: t('simple_form.include_blanks.defaults.school'), + required: true, + wrapper: false %> + </div> + <div class="col-md-4"> <%= f.association :program, collection: collection_tree(current_university.education_programs), label_method: ->(p) { sanitize p[:label] }, @@ -13,7 +21,7 @@ required: true, wrapper: false %> </div> - <div class="col-md-6"> + <div class="col-md-2"> <%= f.input :year, as: :select, collection: ((Time.now.year + 5).downto(1950)), diff --git a/app/views/admin/university/alumni/show.html.erb b/app/views/admin/university/alumni/show.html.erb index b87024b416852b349dbbce8d8bbdf415d164f5b8..7bce04550bcad56a8d1ab0c8eb0708d022636e2c 100644 --- a/app/views/admin/university/alumni/show.html.erb +++ b/app/views/admin/university/alumni/show.html.erb @@ -7,13 +7,7 @@ <div class="card-header"> <h2 class="card-title mb-0 h5"><%= Education::Cohort.model_name.human(count: @alumnus.cohorts.count) %></h2> </div> - <div class="card-body"> - <ul class="list-unstyled"> - <% @alumnus.cohorts.ordered.each do |cohort| %> - <li><%= link_to cohort, [:admin, cohort] %></li> - <% end %> - </ul> - </div> + <%= render 'admin/education/cohorts/list', cohorts: @alumnus.cohorts.ordered %> </div> <% end %> @@ -49,9 +43,9 @@ <% content_for :action_bar_right do %> <%= edit_link @alumnus %> - <%= link_to t('university.manage_cohorts'), + <%= link_to t('university.manage_cohorts'), cohorts_admin_university_alumnus_path(@alumnus), class: button_classes if can?(:update, @alumnus) %> - <%= link_to t('university.manage_experiences'), experiences_admin_university_alumnus_path(@alumnus), + <%= link_to t('university.manage_experiences'), experiences_admin_university_alumnus_path(@alumnus), class: button_classes if can?(:update, @alumnus) %> <% end %> diff --git a/config/locales/education/en.yml b/config/locales/education/en.yml index c3fc9d2a5792ba56a227c80061069981b0fe660d..a9652bec1cf93d67633164f94cc06affa1719fa7 100644 --- a/config/locales/education/en.yml +++ b/config/locales/education/en.yml @@ -25,6 +25,7 @@ en: education/cohort: alumni: Alumni program: Program + school: School year: Year education/diploma: name: Name diff --git a/config/locales/education/fr.yml b/config/locales/education/fr.yml index 88f83eede8b6d70ae8f20931704d600070513cde..777c44f832947337e62a99dfdd0d404d2e3bcae2 100644 --- a/config/locales/education/fr.yml +++ b/config/locales/education/fr.yml @@ -25,6 +25,7 @@ fr: education/cohort: alumni: Alumni program: Formation + school: École year: Année education/diploma: name: Nom diff --git a/config/locales/university/en.yml b/config/locales/university/en.yml index cd6cb5d0f7e218a0081d425a6e5816b1ef2e97a5..9b34762256ee15907293ffc3f0630aedeb3e1409 100644 --- a/config/locales/university/en.yml +++ b/config/locales/university/en.yml @@ -70,6 +70,7 @@ en: zipcode: Zipcode university/person/experience: description: Description + edit: Edit experience organization: Organization from_year: Start year to_year: End year @@ -150,6 +151,7 @@ en: include_blanks: defaults: organization: Select organization + school: Select school year: Select year enums: university: @@ -174,6 +176,7 @@ en: manage_cohorts: Manage cohorts manage_experiences: Manage experiences organisation: + employees: Employees import_hint_html: "Possible values for <i>kind</i> are: company, non_profit, government.<br><i>Siren</i>, <i>nic</i>, <i>zipcode</i> and <i>phone</i> fields must have a text format, not numbers.<br><i>Country</i> field must contain the ISO 3166 code of the country, so 2 upcase characters (<a href=\"https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes\" target=\_blank\">list</a>)." person: administrator_roles: Administrator roles diff --git a/config/locales/university/fr.yml b/config/locales/university/fr.yml index aba7fa598ca9e2b7853e790afaeefe66baeff17d..ddb61535fa78a7521877e915f734ab14fcb78bd3 100644 --- a/config/locales/university/fr.yml +++ b/config/locales/university/fr.yml @@ -151,6 +151,7 @@ fr: include_blanks: defaults: organization: Sélectionnez une organisation + school: Sélectionnez une école year: Sélectionnez une année enums: university: diff --git a/db/migrate/20221003144016_add_school_to_cohorts.rb b/db/migrate/20221003144016_add_school_to_cohorts.rb new file mode 100644 index 0000000000000000000000000000000000000000..251b13f692be20895d4e49b6051809e2ef528ea4 --- /dev/null +++ b/db/migrate/20221003144016_add_school_to_cohorts.rb @@ -0,0 +1,10 @@ +class AddSchoolToCohorts < ActiveRecord::Migration[6.1] + def change + add_reference :education_cohorts, :school, foreign_key: {to_table: :education_schools}, type: :uuid + Education::Cohort.all.each do |cohort| + cohort.school_id = cohort.program.schools.first.id + cohort.save + end + change_column_null :education_cohorts, :school_id, false + end +end diff --git a/db/schema.rb b/db/schema.rb index c2271a7ad029e0bda19a3cc7614427a177a16561..cfbd6e2f3b2335161585516f87a33893c2e2dec8 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2022_09_01_160808) do +ActiveRecord::Schema.define(version: 2022_10_03_144016) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" @@ -410,8 +410,10 @@ ActiveRecord::Schema.define(version: 2022_09_01_160808) do t.string "name" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false + t.uuid "school_id", null: false t.index ["academic_year_id"], name: "index_education_cohorts_on_academic_year_id" t.index ["program_id"], name: "index_education_cohorts_on_program_id" + t.index ["school_id"], name: "index_education_cohorts_on_school_id" t.index ["university_id"], name: "index_education_cohorts_on_university_id" end @@ -848,6 +850,7 @@ ActiveRecord::Schema.define(version: 2022_09_01_160808) do add_foreign_key "education_academic_years", "universities" add_foreign_key "education_cohorts", "education_academic_years", column: "academic_year_id" add_foreign_key "education_cohorts", "education_programs", column: "program_id" + add_foreign_key "education_cohorts", "education_schools", column: "school_id" add_foreign_key "education_cohorts", "universities" add_foreign_key "education_diplomas", "universities" add_foreign_key "education_programs", "education_programs", column: "parent_id" diff --git a/test/fixtures/education/cohorts.yml b/test/fixtures/education/cohorts.yml index c8f91dc321cdf74db15034a038b712ec022aa4a2..13f18884fe9b537fc623019cb72330c3e498b7cf 100644 --- a/test/fixtures/education/cohorts.yml +++ b/test/fixtures/education/cohorts.yml @@ -8,18 +8,21 @@ # updated_at :datetime not null # academic_year_id :uuid not null, indexed # program_id :uuid not null, indexed +# school_id :uuid not null, indexed # university_id :uuid not null, indexed # # Indexes # # index_education_cohorts_on_academic_year_id (academic_year_id) # index_education_cohorts_on_program_id (program_id) +# index_education_cohorts_on_school_id (school_id) # index_education_cohorts_on_university_id (university_id) # # Foreign Keys # # fk_rails_0f4a4f43d9 (university_id => universities.id) # fk_rails_72528c3d76 (program_id => education_programs.id) +# fk_rails_8545767e2d (school_id => education_schools.id) # fk_rails_c2d725cabd (academic_year_id => education_academic_years.id) # diff --git a/test/models/education/cohort_test.rb b/test/models/education/cohort_test.rb index 2bb945a4269462f09d294da1e8c6b96f50241a05..deb8e05ebeff51613a1a5555726cbf28bf9778d9 100644 --- a/test/models/education/cohort_test.rb +++ b/test/models/education/cohort_test.rb @@ -8,18 +8,21 @@ # updated_at :datetime not null # academic_year_id :uuid not null, indexed # program_id :uuid not null, indexed +# school_id :uuid not null, indexed # university_id :uuid not null, indexed # # Indexes # # index_education_cohorts_on_academic_year_id (academic_year_id) # index_education_cohorts_on_program_id (program_id) +# index_education_cohorts_on_school_id (school_id) # index_education_cohorts_on_university_id (university_id) # # Foreign Keys # # fk_rails_0f4a4f43d9 (university_id => universities.id) # fk_rails_72528c3d76 (program_id => education_programs.id) +# fk_rails_8545767e2d (school_id => education_schools.id) # fk_rails_c2d725cabd (academic_year_id => education_academic_years.id) # require "test_helper"