From e0ff010f3ac7c124adc691227f540ecfa57baad0 Mon Sep 17 00:00:00 2001 From: Arnaud Levy <contact@arnaudlevy.com> Date: Thu, 16 Mar 2023 16:30:14 +0100 Subject: [PATCH] person --- .../admin/university/people_controller.rb | 6 ++++ app/models/university/person.rb | 4 +++ .../show/special_pages/_organization.html.erb | 2 +- .../pages/show/special_pages/_person.html.erb | 33 +++++++++++++++++++ .../university/people/search.json.jbuilder | 5 +++ config/locales/university/en.yml | 4 ++- config/locales/university/fr.yml | 2 ++ config/routes/admin/university.rb | 1 + 8 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 app/views/admin/communication/websites/pages/show/special_pages/_person.html.erb create mode 100644 app/views/admin/university/people/search.json.jbuilder diff --git a/app/controllers/admin/university/people_controller.rb b/app/controllers/admin/university/people_controller.rb index 4031b759a..cc00d27b1 100644 --- a/app/controllers/admin/university/people_controller.rb +++ b/app/controllers/admin/university/people_controller.rb @@ -24,7 +24,13 @@ class Admin::University::PeopleController < Admin::University::ApplicationContro response.headers['Content-Disposition'] = "attachment; filename=#{filename}" } end + end + def search + @term = params[:term].to_s + @people = current_university.people + .for_search_term(@term) + .ordered end def show diff --git a/app/models/university/person.rb b/app/models/university/person.rb index 4a36bbd6c..f419d5bce 100644 --- a/app/models/university/person.rb +++ b/app/models/university/person.rb @@ -178,6 +178,10 @@ class University::Person < ApplicationRecord "#{first_name} #{last_name}" end + def to_s_with_mail + "#{to_s} (#{email})" + end + def to_s_alphabetical "#{last_name} #{first_name}" end diff --git a/app/views/admin/communication/websites/pages/show/special_pages/_organization.html.erb b/app/views/admin/communication/websites/pages/show/special_pages/_organization.html.erb index a07683e43..c6e8954b0 100644 --- a/app/views/admin/communication/websites/pages/show/special_pages/_organization.html.erb +++ b/app/views/admin/communication/websites/pages/show/special_pages/_organization.html.erb @@ -7,7 +7,7 @@ label: false, as: :autocomplete, url: search_admin_university_organizations_path(lang: nil, website_id: nil), - placeholder: t("extranet.experiences.search_organization"), + placeholder: t("university.organization.search"), input_html: { data: { type: 'University::Organization', diff --git a/app/views/admin/communication/websites/pages/show/special_pages/_person.html.erb b/app/views/admin/communication/websites/pages/show/special_pages/_person.html.erb new file mode 100644 index 000000000..e8ff91c4a --- /dev/null +++ b/app/views/admin/communication/websites/pages/show/special_pages/_person.html.erb @@ -0,0 +1,33 @@ +<% +@people = @website.connected_people.ordered.page params[:page] +%> +<%= osuny_panel University::Person.model_name.human(count: 2) do %> + <%= simple_form_for :association, class_name: 'association' do |f| %> + <%= f.input :name, + label: false, + as: :autocomplete, + url: search_admin_university_people_path(lang: nil, website_id: nil), + placeholder: t("university.person.search"), + input_html: { + data: { + type: 'University::Person', + target: connect_admin_communication_website_page_path(@page) + } + } + %> + <% end %> + <table class="<%= table_classes%>"> + <tbody> + <% @people.each do |person| %> + <tr> + <td><%= link_to person, [:admin, person] %></td> + <td><%= link_to 'Déconnecter', + disconnect_admin_communication_website_page_path(@page, objectId: person.id, objectType: person.class), + class: button_classes_danger, + method: :post %></td> + </tr> + <% end %> + </tbody> + </table> + <%= paginate @people, theme: 'bootstrap-5' %> +<% end %> diff --git a/app/views/admin/university/people/search.json.jbuilder b/app/views/admin/university/people/search.json.jbuilder new file mode 100644 index 000000000..d2c8e6f1f --- /dev/null +++ b/app/views/admin/university/people/search.json.jbuilder @@ -0,0 +1,5 @@ +json.array! @people do |person| + json.id person.id + json.label person.to_s_with_mail + json.value person.to_s_with_mail +end \ No newline at end of file diff --git a/config/locales/university/en.yml b/config/locales/university/en.yml index d34e01717..1cf1aaa50 100644 --- a/config/locales/university/en.yml +++ b/config/locales/university/en.yml @@ -213,7 +213,8 @@ en: manage_alumni: Manage alumni manage_cohorts: Manage cohorts manage_experiences: Manage experiences - organisation: + organization: + search: Search by name 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>)." logo: Logo @@ -228,6 +229,7 @@ en: import_hint_html: "Possible values for <i>gender</i> are: m (male), f (female) and n (non binary).<br><i>Phone_professional</i>, <i>phone_personal</i>, <i>mobile</i> and <i>zipcode</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>).<br><i>Social_twitter</i> field should have no @." title: Experiences imports personal_data_warning: Warning! The information provided below can be publicly visible on the websites and the extranets about you. + search: Search by name taught_programs: Taught programs sso: SSO sso_key: SSO Key diff --git a/config/locales/university/fr.yml b/config/locales/university/fr.yml index 04fec52d2..e3f76315a 100644 --- a/config/locales/university/fr.yml +++ b/config/locales/university/fr.yml @@ -214,6 +214,7 @@ fr: manage_cohorts: Gérer les promotions manage_experiences: Gérer les expériences professionnelles organization: + search: Rechercher par nom d'organisation employees: Employé·e·s import_hint_html: "Les valeurs possibles pour <i>kind</i> sont : company, non_profit, government.<br>Les champs <i>siren</i>, <i>nic</i>, <i>zipcode</i> et <i>phone</i> doivent être au format texte, pas nombre.<br>Le champ <i>country</i> doit contenir le code ISO 3166 du pays, sur 2 caratères en majuscule (<a href=\"https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes\" target=\_blank\">liste</a>)" logo: Logo @@ -227,6 +228,7 @@ fr: import_btn: Importer des expériences import_hint_html: "Les valeurs pour <i>gender</i> peuvent être m (masculin), f (féminin) et n (non binaire).<br>Les champs <i>phone_professional</i>, <i>phone_personal</i>, <i>mobile</i> et <i>zipcode</i> doivent être au format texte, pas nombre.<br>Le champ <i>country</i> doit contenir le code ISO 3166 du pays, sur 2 caratères en majuscule (<a href=\"https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes\" target=\_blank\">liste</a>)<br>Le champ <i>social_twitter</i> ne doit pas contenir d'@." title: Imports d'expériences + search: Rechercher par nom de personne personal_data_warning: Attention ! Les informations renseignées ici sont susceptibles d'être visibles publiquement sur les sites web et les extranets vous concernant. taught_programs: Formations enseignées sso: SSO diff --git a/config/routes/admin/university.rb b/config/routes/admin/university.rb index d5dd18cce..af658daef 100644 --- a/config/routes/admin/university.rb +++ b/config/routes/admin/university.rb @@ -16,6 +16,7 @@ namespace :university do end resources :people do collection do + get :search, defaults: { format: 'json' } resources :categories, controller: 'people/categories', as: 'person_categories' end member do -- GitLab