diff --git a/app/assets/javascripts/admin/university/edit.js b/app/assets/javascripts/admin/university/edit.js index 9799b2a344ed7d58e4e802377eb1091bc79ba1fe..f28aff7782236f888f513731d91113adc074696e 100644 --- a/app/assets/javascripts/admin/university/edit.js +++ b/app/assets/javascripts/admin/university/edit.js @@ -3,17 +3,20 @@ window.osuny.university.edit = { 'use strict'; this.hasSsoInput = document.querySelector('input[type="checkbox"][name="university[has_sso]"]'); this.hasSsoInput.addEventListener('change', this.onHasSsoChange.bind(this)); - this.ssoFields = document.getElementById('sso-inputs'); + this.ssoFields = document.querySelectorAll('.sso-inputs'); this.onHasSsoChange(); }, onHasSsoChange: function () { 'use strict'; - var value = this.hasSsoInput.checked; - if (value) { - this.ssoFields.classList.remove('d-none'); - } else { - this.ssoFields.classList.add('d-none'); + var value = this.hasSsoInput.checked, + i; + for (i = 0; i < this.ssoFields.length; i += 1) { + if (value) { + this.ssoFields[i].classList.remove('d-none'); + } else { + this.ssoFields[i].classList.add('d-none'); + } } }, diff --git a/app/controllers/admin/university/people/alumni_controller.rb b/app/controllers/admin/university/people/alumni_controller.rb index 2fd91f16d7dfda0c6780f90fe583ca0cc5c7e2ce..0123d44b7918016c381292720043a467928263dc 100644 --- a/app/controllers/admin/university/people/alumni_controller.rb +++ b/app/controllers/admin/university/people/alumni_controller.rb @@ -14,23 +14,25 @@ class Admin::University::People::AlumniController < Admin::University::Applicati end def show + @cohorts = @alumnus.cohorts.ordered.page(params[:cohorts_page]) breadcrumb end - def edit + def edit_cohorts breadcrumb add_breadcrumb t('edit') end - def update - if @alumnus.update(alumnus_params) - redirect_to [:admin, @alumnus], - notice: t('admin.successfully_updated_html', model: @alumnus.to_s) - else - render :edit - breadcrumb - add_breadcrumb t('edit') - end + def update_cohorts + # TODO + # if @alumnus.update(alumnus_params) + # redirect_to [:admin, @alumnus], + # notice: t('admin.successfully_updated_html', model: @alumnus.to_s) + # else + # render :edit + # breadcrumb + # add_breadcrumb t('edit') + # end end protected @@ -39,10 +41,11 @@ class Admin::University::People::AlumniController < Admin::University::Applicati super add_breadcrumb University::Person::Alumnus.model_name.human(count: 2), admin_university_people_alumni_path - breadcrumb_for @alumnus + add_breadcrumb @alumnus, admin_university_person_alumnus_path(@alumnus) if @alumnus end def alumnus_params + # TODO: Permit nested attrs params.require(:university_person_alumnus) .permit() end diff --git a/app/models/university/person/with_education.rb b/app/models/university/person/with_education.rb index eef6b9c79f6c055ec84f1d081f3045ca9315e086..a42f499dbab3d54be47ae8b2894201cf5c90977a 100644 --- a/app/models/university/person/with_education.rb +++ b/app/models/university/person/with_education.rb @@ -25,6 +25,10 @@ module University::Person::WithEducation foreign_key: 'university_person_id', association_foreign_key: 'education_cohort_id' + accepts_nested_attributes_for :cohorts, + reject_if: :all_blank, + allow_destroy: true + # Dénormalisation des liens via cohorts, pour la recherche par facettes has_and_belongs_to_many :diploma_years, class_name: 'Education::AcademicYear', diff --git a/app/views/admin/application/_nav.html.erb b/app/views/admin/application/_nav.html.erb index 8843006cbca3dea2d01a640db1fa75913e5ff3d5..ae1ae913b18fbc8acb4c095ebf7d5ba134ac5f1b 100644 --- a/app/views/admin/application/_nav.html.erb +++ b/app/views/admin/application/_nav.html.erb @@ -5,7 +5,14 @@ <% end %> <%= render_navigation context: :admin %> + <footer class="small my-5"> + <hr> + <div class="sidebar-header"> + <p class="small"> + <%= t('admin.number_of_enqueued_tasks', tasks: Delayed::Job.all.length) %> + </p> + </div> <hr> <%= link_to 'API', api_root_path, class: 'sidebar-link' %> <% diff --git a/app/views/admin/communication/websites/pages/_form.html.erb b/app/views/admin/communication/websites/pages/_form.html.erb index fe48a44effb1f674351a236dc7fe8d965158848f..ebbb2feadcfb269e22a88760749e8823e832f353 100644 --- a/app/views/admin/communication/websites/pages/_form.html.erb +++ b/app/views/admin/communication/websites/pages/_form.html.erb @@ -17,7 +17,7 @@ input_html: { data: { 'summernote-config' => 'mini' } } %> - <%= f.input :text, as: :summernote %> + <%= f.input :text, as: :summernote if page.text&.to_plain_text.present? %> <%= f.association :related_category, collection: collection_tree(@website.categories), label_method: ->(p) { sanitize p[:label] }, diff --git a/app/views/admin/communication/websites/pages/show.html.erb b/app/views/admin/communication/websites/pages/show.html.erb index c9de26166a1876c6cc903232e370c3e59b8f7bbe..c8f5773399a9b98cad09e4fec5cc5c75e7cb8395 100644 --- a/app/views/admin/communication/websites/pages/show.html.erb +++ b/app/views/admin/communication/websites/pages/show.html.erb @@ -20,7 +20,7 @@ </div> <div class="card-body"> <%= render 'admin/application/property/text', object: @page, property: :description_short %> - <%= render 'admin/application/property/text', object: @page, property: :text %> + <%= render 'admin/application/property/text', object: @page, property: :text if @page.text&.to_plain_text.present? %> </div> </div> <%= render 'admin/communication/blocks/list', about: @page %> diff --git a/app/views/admin/communication/websites/pages/static.html.erb b/app/views/admin/communication/websites/pages/static.html.erb index d4cc6399d8ca35929319ac703da27812bc3185af..c3f1d35eea17b74b566300a0332448da22fe2097 100644 --- a/app/views/admin/communication/websites/pages/static.html.erb +++ b/app/views/admin/communication/websites/pages/static.html.erb @@ -21,6 +21,7 @@ description_short: > <%= prepare_text_for_static @about.description_short %> header_text: > <%= prepare_html_for_static @about.header_text, @website.university %> +legacy_text: > + <%= prepare_html_for_static @about.text, @about.university %> <%= render 'admin/communication/blocks/static', about: @about %> --- -<%= prepare_html_for_static @about.text, @about.university %> diff --git a/app/views/admin/education/teachers/edit.html.erb b/app/views/admin/education/teachers/edit.html.erb index 68677371f643c11014008508c5a21f9aeafde9c1..8d3adb0053f4422ebe9f73f46b3b6a4f46a1760b 100644 --- a/app/views/admin/education/teachers/edit.html.erb +++ b/app/views/admin/education/teachers/edit.html.erb @@ -4,27 +4,29 @@ <%= simple_form_for [:admin, @teacher], url: admin_education_teacher_path(@teacher) do |f| %> <%= f.error_notification %> - <%= f.error_notification message: f.object.errors[:base].to_sentence if f.object.errors[:base].present? %><div class="row"> + <%= f.error_notification message: f.object.errors[:base].to_sentence if f.object.errors[:base].present? %> - <div class="col-md-2"> - <%= link_to_add_association t('add'), f, :involvements, - class: button_classes, - data: { - 'association-insertion-method': 'append', - 'association-insertion-node': '#involvements', - } %> + <div class="row"> + + <div class="col-md-2"> + <%= link_to_add_association t('add'), f, :involvements, + class: button_classes, + data: { + 'association-insertion-method': 'append', + 'association-insertion-node': '#involvements', + } %> - </div> - <div class="col-md-10"> - <div id="involvements"> - <% sorted_teacher_involvements = @teacher.involvements.select(&:teacher?).sort_by { |involvement| involvement.created_at || Time.zone.now } %> - <%= f.simple_fields_for :involvements, sorted_teacher_involvements, include_id: false do |involvement_f| %> - <%= render 'admin/education/teachers/involvement_fields', f: involvement_f, include_id: true %> - <% end %> </div> + <div class="col-md-10"> + <div id="involvements"> + <% sorted_teacher_involvements = @teacher.involvements.select(&:teacher?).sort_by { |involvement| involvement.created_at || Time.zone.now } %> + <%= f.simple_fields_for :involvements, sorted_teacher_involvements, include_id: false do |involvement_f| %> + <%= render 'admin/education/teachers/involvement_fields', f: involvement_f, include_id: true %> + <% end %> + </div> + </div> </div> -</div> <% content_for :action_bar_right do %> <%= submit f %> <% end %> diff --git a/app/views/admin/university/people/alumni/_cohort_fields.html.erb b/app/views/admin/university/people/alumni/_cohort_fields.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..bf6e5f83490f73d5864f5f755f2ff14ad497483d --- /dev/null +++ b/app/views/admin/university/people/alumni/_cohort_fields.html.erb @@ -0,0 +1,32 @@ +<% include_id ||= false %> +<div class="nested-fields"> + <div class="card mb-3"> + <div class="card-body"> + <div class="row"> + <div class="col-md-5"> + <%= f.association :program, + collection: collection_tree(current_university.education_programs), + label_method: ->(p) { sanitize p[:label] }, + value_method: ->(p) { p[:id] }, + label: false, + include_blank: t('simple_form.include_blanks.defaults.program'), + required: true, + wrapper: false %> + </div> + <div class="col-md-6"> + <%#= f.input :description, + as: :string, + label: false, + placeholder: University::Person::Involvement.human_attribute_name('description'), + wrapper: false %> + </div> + <div class="col-md-1 text-end"> + <%= link_to_remove_association '<i class="fas fa-times"></i>'.html_safe, + f, + class: 'btn btn-sm btn-danger' %> + </div> + </div> + </div> + <%= f.hidden_field :id if include_id %> + </div> +</div> diff --git a/app/views/admin/university/people/alumni/_list.html.erb b/app/views/admin/university/people/alumni/_list.html.erb index fca4f7824a75544919aa69ffcda8f50f13325335..00f837195a83c7a68cbd084a275fdb91b6cc116f 100644 --- a/app/views/admin/university/people/alumni/_list.html.erb +++ b/app/views/admin/university/people/alumni/_list.html.erb @@ -3,7 +3,6 @@ <tr> <th><%= University::Person.human_attribute_name('last_name') %></th> <th><%= University::Person.human_attribute_name('first_name') %></th> - <th></th> </tr> </thead> <tbody> @@ -12,18 +11,6 @@ <tr> <td><%= link_to alumnus.last_name, path %></td> <td><%= link_to alumnus.first_name, path %></td> - <td class="text-end"> - <div class="btn-group" role="group"> - <%= link_to t('edit'), - edit_admin_university_person_path(alumnus), - class: button_classes if can?(:update, alumnus) %> - <%= link_to t('delete'), - path, - method: :delete, - data: { confirm: t('please_confirm') }, - class: button_classes_danger if can?(:destroy, alumnus) %> - </div> - </td> </tr> <% end %> </tbody> diff --git a/app/views/admin/university/people/alumni/edit_cohorts.html.erb b/app/views/admin/university/people/alumni/edit_cohorts.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..5cc53c3ef5f2efd63a0a5ade2d1527f03e620565 --- /dev/null +++ b/app/views/admin/university/people/alumni/edit_cohorts.html.erb @@ -0,0 +1,32 @@ +<% content_for :title, @alumnus %> + +<h2 class="h3"><%= Education::Program.model_name.human(count: 2) %></h2> + +<%= simple_form_for [:admin, @alumnus], url: edit_cohorts_admin_university_person_alumnus_path(@alumnus) do |f| %> + <%= f.error_notification %> + <%= f.error_notification message: f.object.errors[:base].to_sentence if f.object.errors[:base].present? %> + + <div class="row"> + + <div class="col-md-2"> + <%= link_to_add_association t('add'), f, :cohorts, + class: button_classes, + data: { + 'association-insertion-method': 'append', + 'association-insertion-node': '#cohorts', + } %> + + </div> + + <div class="col-md-10"> + <div id="cohorts"> + <%= f.simple_fields_for :cohorts, @alumnus.cohorts.ordered, include_id: false do |cohort_f| %> + <%= render 'admin/university/person/alumni/cohort_fields', f: cohort_f, include_id: true %> + <% end %> + </div> + </div> + </div> + <% content_for :action_bar_right do %> + <%= submit f %> + <% end %> +<% end %> diff --git a/app/views/admin/university/people/alumni/index.html.erb b/app/views/admin/university/people/alumni/index.html.erb index db95e616de7f1b2e19a5312efc1eca39b3bd1e2a..dc53377d88626440dd47ff45d7e1de84e81eb234 100644 --- a/app/views/admin/university/people/alumni/index.html.erb +++ b/app/views/admin/university/people/alumni/index.html.erb @@ -13,4 +13,5 @@ <% end %> <% content_for :action_bar_right do %> + <%= link_to t('university.manage_alumni'), admin_university_people_path, class: button_classes if can?(:read, University::Person) %> <% end %> diff --git a/app/views/admin/university/people/alumni/new.html.erb b/app/views/admin/university/people/alumni/new.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..5a24f1f3bd07bb3819ec45ee9503995f926c385b --- /dev/null +++ b/app/views/admin/university/people/alumni/new.html.erb @@ -0,0 +1,3 @@ +<% content_for :title, University::Person.model_name.human %> + +<%= render 'form', person: @person %> diff --git a/app/views/admin/university/people/alumni/show.html.erb b/app/views/admin/university/people/alumni/show.html.erb index 920c3ee23b71c4b51dd450754de2843a7c5d2583..7ee7ad53cacea6d9e59e955a00060cd783f08542 100644 --- a/app/views/admin/university/people/alumni/show.html.erb +++ b/app/views/admin/university/people/alumni/show.html.erb @@ -1,6 +1,20 @@ <% content_for :title, @alumnus %> +<%= render 'admin/university/people/main_infos', person: @alumnus %> + +<%= render 'admin/university/person/alumni/show/cohorts', cohorts: @cohorts, param_name: 'cohorts_page' %> + +<%# TODO: remove %> +<% if @alumnus.cohorts.any? %> <h2><%= Education::Cohort.model_name.human(count: @alumnus.cohorts.count) %></h2> <% @alumnus.cohorts.each do |cohort| %> <%= link_to cohort, [:admin, cohort] %> <% end %> +<% end %> +<%# end TODO %> + + +<% content_for :action_bar_right do %> + <%= edit_link @alumnus %> + <%= link_to t('university.manage_cohorts'), edit_cohorts_admin_university_person_alumnus_path(@alumnus), class: button_classes if can?(:update, @alumnus) %> +<% end %> diff --git a/app/views/admin/university/people/alumni/show/_cohorts.html.erb b/app/views/admin/university/people/alumni/show/_cohorts.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..a85f73d8abd631a2d1f123591a450c97508de44c --- /dev/null +++ b/app/views/admin/university/people/alumni/show/_cohorts.html.erb @@ -0,0 +1,48 @@ +<% param_name ||= :page %> + +<% if cohorts.total_count > 0 %> + <div class="card"> + <div class="card-header"> + <h2 class="card-title mb-0 h5"><%= "#{Education::Cohort.model_name.human(count: 2)} (#{cohorts.total_count})" %></h2> + </div> + <table class="table"> + <thead> + <tr> + <th><%= Education::Cohort.human_attribute_name('program') %></th> + <th><%= Education::Cohort.human_attribute_name('academic_year') %></th> + <th></th> + </tr> + </thead> + <tbody> + <% cohorts.each do |cohort| %> + <% program = cohort.program %> + <tr> + <td><%= link_to_if can?(:read, program), program, [:admin, program] %></td> + <td><%= program.level_i18n %></td> + <td><%= cohort.academic_year %></td> + <td class="text-end"> + <div class="btn-group" role="group"> + <%= link_to t('edit'), + '#', + class: button_classes if can?(:update, cohort) %> + <%= link_to t('delete'), + '#', + method: :delete, + data: { confirm: t('please_confirm') }, + class: button_classes_danger if can?(:destroy, cohort) %> + </div> + </td> + </tr> + <% end %> + </tbody> + </table> + + <% if cohorts.total_pages > 1 %> + <div class="card-footer"> + <%= paginate cohorts, theme: 'bootstrap-5', param_name: param_name %> + </div> + <% end %> + + </div> + +<% end %> diff --git a/app/views/server/universities/_form.html.erb b/app/views/server/universities/_form.html.erb index 3defd9c1efda9aeb3b8c2a43542566547fb9317e..a08d955d57cb8dd5b58ae9d2db276c7ecfce8559 100644 --- a/app/views/server/universities/_form.html.erb +++ b/app/views/server/universities/_form.html.erb @@ -35,13 +35,13 @@ <div class="row"> <div class="col-md-6"> <%= f.input :has_sso %> - <div id="sso-inputs"> + <div class="sso-inputs"> <%= f.input :sso_target_url, required: true %> <%= f.input :sso_cert, required: true %> <%= f.input :sso_name_identifier_format, required: true %> </div> </div> - <div class="col-md-6"> + <div class="col-md-6 sso-inputs"> <h4 class="mb-4"><%= University.human_attribute_name('sso_mapping') %></h4> <%= f.error_notification message: f.object.errors[:sso_mapping].to_sentence if f.object.errors[:sso_mapping].present? %> <%= render 'sso_mapping', university: university %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 413c3e8cf60e353600c964f9647c803282cc5671..013fe4bf78609dc146ad49d5be36e18ddb01edb5 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -47,6 +47,7 @@ en: sentence_without_link: Value inherited sentence_html: Value inherited from %{link} status: Inherited value + number_of_enqueued_tasks: "Number of enqueued tasks: %{tasks}" password_hint: Leave blank if you do not wish to change the password. successfully_created_html: "<i>%{model}</i> was successfully created." successfully_destroyed_html: "<i>%{model}</i> was successfully destroyed." diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 1e8778ab47e657036fd405f8e669a9cf92f14fe9..ad8733416ad22d7556982fa880d8af79d0c5b4a4 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -47,6 +47,7 @@ fr: sentence_without_link: Valeur héritée sentence_html: Valeur héritée de %{link} status: Valeur héritée + number_of_enqueued_tasks: "Nombre de tâches à traiter : %{tasks}" password_hint: Laissez vide si vous ne souhaitez pas modifier le mot de passe. successfully_created_html: "<i>%{model}</i> a bien été créé(e)." successfully_destroyed_html: "<i>%{model}</i> a bien été détruit(e)." diff --git a/config/locales/university/en.yml b/config/locales/university/en.yml index 821184b444454959fbb0fc717e722cf5888a6c48..c453abf00418bc7e77e019f9085367b8a6489e92 100644 --- a/config/locales/university/en.yml +++ b/config/locales/university/en.yml @@ -139,6 +139,9 @@ en: university: internal_key: Internal Key invoice_informations: Invoice informations + manage_alumni: Manage alumni + manage_cohorts: Manage cohorts + manage_experiences: Manage experiences person: administrator_roles: Administrator roles taught_programs: Taught programs diff --git a/config/locales/university/fr.yml b/config/locales/university/fr.yml index 11e6e050ef25099db72514b2bfc904e0fe9ba2e5..00d4d9d976dc08d43ea41a3fc9b10f81d79827a8 100644 --- a/config/locales/university/fr.yml +++ b/config/locales/university/fr.yml @@ -139,6 +139,9 @@ fr: university: internal_key: Clé interne invoice_informations: Données de facturation + manage_alumni: Gérer les alumni + manage_cohorts: Gérer les promotions + manage_experiences: Gérer les expériences professionnelles person: administrator_roles: Rôles administratifs taught_programs: Formations enseignées diff --git a/config/routes/admin/university.rb b/config/routes/admin/university.rb index fc1b270ad27b330583f7212c4015f9be007f5bdf..5106085dc6cb64aa953317c748c99e827750b6a1 100644 --- a/config/routes/admin/university.rb +++ b/config/routes/admin/university.rb @@ -7,7 +7,14 @@ namespace :university do namespace :alumni do resources :imports, only: [:index, :show, :new, :create] end - resources :alumni + resources :alumni, only: [:index, :show] do + member do + get 'edit_cohorts' => 'alumni#edit_cohorts' + patch 'edit_cohorts' => 'alumni#update_cohorts' + get 'edit_experience' => 'alumni#edit_experiences' + patch 'edit_experiences' => 'alumni#update_experiences' + end + end end resources :people, :organizations end diff --git a/db/schema.rb b/db/schema.rb index 4c5f75e298ca6a282c02fd174577cd38ba7d4d40..7b136e975811cbc6607a421b13c6ffdd891011f2 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -490,23 +490,6 @@ ActiveRecord::Schema.define(version: 2022_05_05_131539) do t.index ["university_id"], name: "index_education_schools_on_university_id" end - create_table "external_organizations", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| - t.string "title" - t.text "description" - t.string "address" - t.string "zipcode" - t.string "city" - t.string "country" - t.string "website" - t.string "phone" - t.string "mail" - t.boolean "active" - t.string "sirene" - t.integer "kind" - t.datetime "created_at", precision: 6, null: false - t.datetime "updated_at", precision: 6, null: false - end - create_table "languages", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "name" t.string "iso_code" @@ -697,8 +680,8 @@ ActiveRecord::Schema.define(version: 2022_05_05_131539) do t.string "linkedin" t.boolean "is_alumnus", default: false t.text "description_short" - t.string "name" t.boolean "is_author" + t.string "name" t.index ["university_id"], name: "index_university_people_on_university_id" t.index ["user_id"], name: "index_university_people_on_user_id" end