diff --git a/app/controllers/admin/education/cohorts_controller.rb b/app/controllers/admin/education/cohorts_controller.rb index c32d9edf9cb122816d2d85191765d2ca214ba597..ddee70517bf2f515e1959c14955403c1934d5304 100644 --- a/app/controllers/admin/education/cohorts_controller.rb +++ b/app/controllers/admin/education/cohorts_controller.rb @@ -49,11 +49,12 @@ class Admin::Education::CohortsController < Admin::Education::ApplicationControl def breadcrumb super - add_breadcrumb Education::cohort.model_name.human(count: 2), admin_education_cohorts_path + add_breadcrumb Education::Cohort.model_name.human(count: 2), admin_education_cohorts_path breadcrumb_for @cohort end def cohort_params - params.require(:education_cohort).permit(:university_id, :program_id, :academic_year_id, :name) + params.require(:education_cohort) + .permit(:program_id, :academic_year_id, :name) end end diff --git a/app/models/ability.rb b/app/models/ability.rb index abd6781296f7997015cd5c097574b4fec42e585d..0b32788eb8b717ec582fc62f2c602ebad63dbcb0 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -60,6 +60,7 @@ class Ability can [:read, :update], Communication::Website::IndexPage, university_id: @user.university_id, communication_website_id: managed_websites_ids can :manage, Communication::Website::Menu::Item, university_id: @user.university_id, website_id: managed_websites_ids can :create, Communication::Website::Menu::Item, university_id: @user.university_id + can :manage, University::Organization, university_id: @user.university_id end def admin @@ -86,6 +87,7 @@ class Ability can :manage, Research::Laboratory, university_id: @user.university_id can :manage, University::Role, university_id: @user.university_id can :manage, University::Person::Involvement, university_id: @user.university_id + can :manage, University::Organization, university_id: @user.university_id can :read, User, university_id: @user.university_id can :manage, User, university_id: @user.university_id, role: @user.managed_roles end diff --git a/app/models/education/cohort.rb b/app/models/education/cohort.rb index 862b7578816503c4866990acc3571278096418e9..1d1aceba419850f4b9c61d07382aa26a753eba3c 100644 --- a/app/models/education/cohort.rb +++ b/app/models/education/cohort.rb @@ -34,6 +34,6 @@ class Education::Cohort < ApplicationRecord scope :ordered, -> { includes(:academic_year).order('education_academic_years.year DESC') } def to_s - "#{program} #{academic_year}" + "#{program} #{academic_year} #{name}" end end diff --git a/app/models/education/program.rb b/app/models/education/program.rb index 360d5ba5f7ddf67fe2e8f92e2b5115037db5dd4e..fee59d836a20742259a5e8b5ff7d9c81e00abda3 100644 --- a/app/models/education/program.rb +++ b/app/models/education/program.rb @@ -104,7 +104,10 @@ class Education::Program < ApplicationRecord join_table: 'education_programs_schools', foreign_key: 'education_program_id', association_foreign_key: 'education_school_id' - has_many :websites, -> { distinct }, through: :schools + has_many :cohorts, + class_name: 'Education::Cohort' + has_many :websites, -> { distinct }, + through: :schools accepts_nested_attributes_for :university_person_involvements, reject_if: :all_blank, allow_destroy: true diff --git a/app/models/university/organization.rb b/app/models/university/organization.rb index 314d82894f13716262a01941f9061063dfa603f6..b53bb6e69e93b73cdd0cfdef3d38a0dcf7bd051b 100644 --- a/app/models/university/organization.rb +++ b/app/models/university/organization.rb @@ -15,6 +15,7 @@ # phone :string # sirene :string # slug :string +# text :text # url :string # zipcode :string # created_at :datetime not null @@ -35,6 +36,8 @@ class University::Organization < ApplicationRecord include WithUniversity include WithSlug + has_summernote :text + has_one_attached_deletable :logo scope :ordered, -> { order(:name) } diff --git a/app/models/university/person.rb b/app/models/university/person.rb index 73144b3d28b5e2fdf7dda8da80ad85a4c2e1157b..07366c7ae228abb4e6b942c4c9496bf29a2003e5 100644 --- a/app/models/university/person.rb +++ b/app/models/university/person.rb @@ -86,11 +86,6 @@ class University::Person < ApplicationRecord through: :education_programs, source: :websites - has_and_belongs_to_many :cohorts, - class_name: 'Education::Cohort', - foreign_key: 'university_person_id', - association_foreign_key: 'education_cohort_id' - accepts_nested_attributes_for :involvements validates_presence_of :first_name, :last_name diff --git a/app/models/university/person/with_education.rb b/app/models/university/person/with_education.rb index a72fbde6bb02579ffd06675d9597ee2b9b9fa596..049d08f97bfa94e462c09995152b1430e9f8b52c 100644 --- a/app/models/university/person/with_education.rb +++ b/app/models/university/person/with_education.rb @@ -13,7 +13,9 @@ module University::Person::WithEducation source_type: "Education::Program" has_and_belongs_to_many :cohorts, - class_name: 'Education::Cohort' + class_name: 'Education::Cohort', + foreign_key: 'university_person_id', + association_foreign_key: 'education_cohort_id' end def education_programs_as_administrator diff --git a/app/views/admin/education/cohorts/index.html.erb b/app/views/admin/education/cohorts/index.html.erb index 58267d3e37dd85cf37bd7658da0dcd0442435af2..98276c3997cd16e80a6466bba0fd5fc5bfd2c49b 100644 --- a/app/views/admin/education/cohorts/index.html.erb +++ b/app/views/admin/education/cohorts/index.html.erb @@ -1,33 +1,3 @@ -<p id="notice"><%= notice %></p> +<% content_for :title, Education::Cohort.model_name.human(count: 2) %> -<h1>Education Cohorts</h1> - -<table> - <thead> - <tr> - <th>University</th> - <th>Program</th> - <th>Academic year</th> - <th>Name</th> - <th colspan="3"></th> - </tr> - </thead> - - <tbody> - <% @education_cohorts.each do |education_cohort| %> - <tr> - <td><%= education_cohort.university_id %></td> - <td><%= education_cohort.program_id %></td> - <td><%= education_cohort.academic_year_id %></td> - <td><%= education_cohort.name %></td> - <td><%= link_to 'Show', education_cohort %></td> - <td><%= link_to 'Edit', edit_education_cohort_path(education_cohort) %></td> - <td><%= link_to 'Destroy', education_cohort, method: :delete, data: { confirm: 'Are you sure?' } %></td> - </tr> - <% end %> - </tbody> -</table> - -<br> - -<%= link_to 'New Education Cohort', new_education_cohort_path %> +<%= render 'admin/education/cohorts/list', cohorts: @cohorts %> diff --git a/app/views/admin/education/cohorts/show.html.erb b/app/views/admin/education/cohorts/show.html.erb index e28142b11e21ae5eecba90ff87c32320035a3ad6..1a73e37ce088fb3dfccc7a2628cca237a581a291 100644 --- a/app/views/admin/education/cohorts/show.html.erb +++ b/app/views/admin/education/cohorts/show.html.erb @@ -1,24 +1,15 @@ -<p id="notice"><%= notice %></p> - -<p> - <strong>University:</strong> - <%= @education_cohort.university_id %> -</p> +<% content_for :title, @cohort %> <p> <strong>Program:</strong> - <%= @education_cohort.program_id %> + <%= link_to @cohort.program, [:admin, @cohort.program] %> </p> <p> <strong>Academic year:</strong> - <%= @education_cohort.academic_year_id %> + <%= link_to @cohort.academic_year, [:admin, @cohort.academic_year] %> </p> -<p> - <strong>Name:</strong> - <%= @education_cohort.name %> -</p> +<h2><%= University::Person::Alumnus.model_name.human(count: 2) %></h2> -<%= link_to 'Edit', edit_education_cohort_path(@education_cohort) %> | -<%= link_to 'Back', education_cohorts_path %> +<%= render 'admin/university/person/alumni/list', alumni: @cohort.people.ordered %> diff --git a/app/views/admin/education/programs/show.html.erb b/app/views/admin/education/programs/show.html.erb index 0569878bdbc435c611c53a213053f18a91324de4..7569786203f489231ea18d11433ed3a3e3a12987 100644 --- a/app/views/admin/education/programs/show.html.erb +++ b/app/views/admin/education/programs/show.html.erb @@ -99,6 +99,8 @@ <%= render 'admin/education/programs/list', programs: @program.children %> </div> <% end %> + + <%= render 'admin/education/programs/show/cohorts' %> </div> </div> diff --git a/app/views/admin/university/person/alumni/show.html.erb b/app/views/admin/university/person/alumni/show.html.erb index a82ea88ffa2827c84ac4aa00f8540ab2809c0c45..920c3ee23b71c4b51dd450754de2843a7c5d2583 100644 --- a/app/views/admin/university/person/alumni/show.html.erb +++ b/app/views/admin/university/person/alumni/show.html.erb @@ -1 +1,6 @@ <% content_for :title, @alumnus %> + +<h2><%= Education::Cohort.model_name.human(count: @alumnus.cohorts.count) %></h2> +<% @alumnus.cohorts.each do |cohort| %> + <%= link_to cohort, [:admin, cohort] %> +<% end %> diff --git a/db/schema.rb b/db/schema.rb index 2c7e3d7f4e853abcd138975997b210543d83f6ba..599e7719930452b8c0aaf34b49a2a83fd50ae655 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_03_23_224105) do +ActiveRecord::Schema.define(version: 2022_03_24_081520) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" @@ -643,6 +643,7 @@ ActiveRecord::Schema.define(version: 2022_03_23_224105) do t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false t.string "slug" + t.text "text" t.index ["university_id"], name: "index_university_organizations_on_university_id" end diff --git a/test/fixtures/university/organizations.yml b/test/fixtures/university/organizations.yml index 331f9675a46e6b5782a69e300e86abda21bddad2..a6627badce8edfd4c126e36dd58d5e598f49a958 100644 --- a/test/fixtures/university/organizations.yml +++ b/test/fixtures/university/organizations.yml @@ -15,6 +15,7 @@ # phone :string # sirene :string # slug :string +# text :text # url :string # zipcode :string # created_at :datetime not null diff --git a/test/models/university/organization_test.rb b/test/models/university/organization_test.rb index b6888e0cc50aba83346e301297f1c3514147c187..12c7900224706b7468378ba91dedfb589d5f84e2 100644 --- a/test/models/university/organization_test.rb +++ b/test/models/university/organization_test.rb @@ -15,6 +15,7 @@ # phone :string # sirene :string # slug :string +# text :text # url :string # zipcode :string # created_at :datetime not null