diff --git a/Gemfile b/Gemfile index 29e38b90da24f82d72433b1afc6353795b5cd6f2..4563b472786745f9eede8517a6ec878d6e4dce01 100644 --- a/Gemfile +++ b/Gemfile @@ -14,6 +14,7 @@ gem "bootstrap5-kaminari-views" gem "breadcrumbs_on_rails" gem "bugsnag" gem "cancancan", "3.3.0" +gem "caxlsx_rails", "~> 0.6.3" gem "cocoon", "~> 1.2" gem "country_select" gem "curation"#, path: "../../arnaudlevy/curation" diff --git a/Gemfile.lock b/Gemfile.lock index c6eafd15e38227c1001b3f9a28dfdc1e700ada11..0e9871c0f06fe9521de550c740743bea2411e847 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -145,6 +145,14 @@ GEM rack-test (>= 0.6.3) regexp_parser (>= 1.5, < 3.0) xpath (~> 3.2) + caxlsx (3.3.0) + htmlentities (~> 4.3, >= 4.3.4) + marcel (~> 1.0) + nokogiri (~> 1.10, >= 1.10.4) + rubyzip (>= 1.3.0, < 3) + caxlsx_rails (0.6.3) + actionpack (>= 3.1) + caxlsx (>= 3.0) cocoon (1.2.15) concurrent-ruby (1.2.2) countries (5.3.1) @@ -568,6 +576,7 @@ DEPENDENCIES byebug cancancan (= 3.3.0) capybara (>= 3.26) + caxlsx_rails (~> 0.6.3) cocoon (~> 1.2) country_select curation diff --git a/app/assets/javascripts/extranet.js b/app/assets/javascripts/extranet.js index 3c9f58a03895bb50778a8ac9d5bc527d2eb3d50b..acfd1811ba7440b3a839c8868adee361bf550d1c 100644 --- a/app/assets/javascripts/extranet.js +++ b/app/assets/javascripts/extranet.js @@ -11,7 +11,6 @@ //= require simple_form_bs5_file_input //= require summernote/summernote-bs5 //= require gdpr/cookie_consent -//= require leaflet //= require autocomplete-rails //= require_tree ./application/plugins //= require_tree ./extranet diff --git a/app/assets/javascripts/map.js b/app/assets/javascripts/map.js new file mode 100644 index 0000000000000000000000000000000000000000..6ed1c2e64f40998b5b6f83dea5127b13e5a5bd26 --- /dev/null +++ b/app/assets/javascripts/map.js @@ -0,0 +1 @@ +//= require leaflet diff --git a/app/controllers/admin/communication/extranets/contacts_controller.rb b/app/controllers/admin/communication/extranets/contacts_controller.rb index d74dbda0e861fa1935b9d89dced9a2aa059aa2e7..53b19b0f630f3e392565e50583550e2ca4e459c8 100644 --- a/app/controllers/admin/communication/extranets/contacts_controller.rb +++ b/app/controllers/admin/communication/extranets/contacts_controller.rb @@ -1,7 +1,22 @@ class Admin::Communication::Extranets::ContactsController < Admin::Communication::Extranets::ApplicationController def index - @persons = current_university.people.ordered.page params[:persons_page] - @organizations = current_university.organizations.ordered.page params[:organizations_page] + @people = current_university.people.ordered + @organizations = current_university.organizations.ordered + respond_to do |format| + format.html { + @people = @people.page params[:persons_page] + @organizations = @organizations.page params[:organizations_page] + } + format.xlsx { + # could be 2 differents controllers in Contacts/People & Contacts/Organizations, each with an index export + @export = params['export'] + filename = "#{@export}-#{Time.now.strftime("%Y%m%d%H%M%S")}.xlsx" + response.headers['Content-Disposition'] = "attachment; filename=#{filename}" + render @export + } + end + + breadcrumb add_breadcrumb Communication::Extranet.human_attribute_name(:feature_contacts) end @@ -26,4 +41,4 @@ class Admin::Communication::Extranets::ContactsController < Admin::Communication object_id = params[:objectId] @object = object_type.constantize.find object_id end -end \ No newline at end of file +end diff --git a/app/models/concerns/with_country.rb b/app/models/concerns/with_country.rb new file mode 100644 index 0000000000000000000000000000000000000000..0dcc66b76dbd04da2e2792c032552d43353a022d --- /dev/null +++ b/app/models/concerns/with_country.rb @@ -0,0 +1,20 @@ +module WithCountry + extend ActiveSupport::Concern + + def country_name + return if country_iso.blank? + country_iso.translations[I18n.locale.to_s] || country_common_name + end + + def country_common_name + return if country_iso.blank? + country_iso.common_name || country_iso.iso_short_name + end + + private + + def country_iso + return @country_iso if defined?(@country_iso) + @country_iso ||= country.blank? ? nil : ISO3166::Country[country] + end +end diff --git a/app/models/concerns/with_geolocation.rb b/app/models/concerns/with_geolocation.rb index df92252bd5228b5eefd05626eeca2dc4a85820d6..2e975c0c70baf772f08fa5e373c9120009b76aa7 100644 --- a/app/models/concerns/with_geolocation.rb +++ b/app/models/concerns/with_geolocation.rb @@ -17,7 +17,7 @@ module WithGeolocation string += "#{address}<br>" if address.present? string += "#{address_additional}<br>" if address_additional.present? string += "#{zipcode} #{city}" - string += "<br>#{ISO3166::Country[country]}" if country + string += "<br>#{country_common_name}" if country string end @@ -42,4 +42,4 @@ module WithGeolocation def full_street_address_changed? address_changed? || zipcode_changed? || city_changed? end -end \ No newline at end of file +end diff --git a/app/models/education/school.rb b/app/models/education/school.rb index 78ab3e1fc5fbae0c810d23ff5a7feca6ab1d30a7..b98be91e95cdfe440cc1a17aac51e782080d4353 100644 --- a/app/models/education/school.rb +++ b/app/models/education/school.rb @@ -25,6 +25,7 @@ # class Education::School < ApplicationRecord include Sanitizable + include WithCountry include WithGit include Aboutable include WithPrograms # must come before WithAlumni and WithTeam diff --git a/app/models/research/laboratory.rb b/app/models/research/laboratory.rb index a70817fe92d6ce36ecdc4f0a4259a6b3b775099a..78a882d2565d6445604c5e37db9b8a4a3830257a 100644 --- a/app/models/research/laboratory.rb +++ b/app/models/research/laboratory.rb @@ -23,6 +23,7 @@ class Research::Laboratory < ApplicationRecord include Aboutable include Sanitizable + include WithCountry include WithGit belongs_to :university diff --git a/app/models/university.rb b/app/models/university.rb index 321f21333ed82efcb40e446851f6b5da3df545f0..832286fc48813ba4c745e414fb7d446a95739a5f 100644 --- a/app/models/university.rb +++ b/app/models/university.rb @@ -41,6 +41,7 @@ class University < ApplicationRecord # We don't include Sanitizable because too many complex attributes. We handle it below. include WithPeopleAndOrganizations include WithCommunication + include WithCountry include WithEducation include WithIdentifier include WithInvoice diff --git a/app/models/university/organization.rb b/app/models/university/organization.rb index 26ec7059d1f864b72ae4e27ff8894ce0e799b61a..54f1e9ba8afd6d5c1c2390e626813ce792d1177c 100644 --- a/app/models/university/organization.rb +++ b/app/models/university/organization.rb @@ -43,6 +43,7 @@ class University::Organization < ApplicationRecord include Sanitizable include WithBlobs include WithBlocks + include WithCountry include WithGeolocation include WithGit include WithPermalink diff --git a/app/models/university/person.rb b/app/models/university/person.rb index 59a9e253f76cc059df0e179dbfeccaf13e0dff9b..1475b5beeaa888976b69047a7edada51f60aed55 100644 --- a/app/models/university/person.rb +++ b/app/models/university/person.rb @@ -57,6 +57,7 @@ class University::Person < ApplicationRecord include WithUniversity include WithGit include WithBlobs + include WithCountry include WithEducation include WithExperiences include WithSlug diff --git a/app/views/admin/communication/extranets/contacts/index.html.erb b/app/views/admin/communication/extranets/contacts/index.html.erb index 9c0b638d69cc7b58fa37ec32d7e904833e08b193..d737b23932ba03a2c273dc7128da4c66f7b22592 100644 --- a/app/views/admin/communication/extranets/contacts/index.html.erb +++ b/app/views/admin/communication/extranets/contacts/index.html.erb @@ -1,29 +1,32 @@ <% content_for :title, Communication::Extranet.human_attribute_name(:feature_contacts) %> <%= render 'admin/communication/extranets/sidebar' do %> - <%= osuny_panel University::Person.model_name.human(count: 2) do %> + <% action = link_to t('export'), + admin_communication_extranet_contacts_path(extranet_id: @extranet.id, export: 'people', format: :xlsx), + class: button_classes('ms-1') if can?(:show, University::Person) %> + <%= osuny_panel University::Person.model_name.human(count: 2), action: action do %> <div class="table-responsive"> <table class="<%= table_classes%>"> <tbody> - <% @persons.each do |person| %> + <% @people.each do |person| %> <tr> <td><%= link_to person, [:admin, person] %></td> <td><%= person.email %></td> <td> <% if @extranet.connected?(person) %> - <%= link_to 'DƩconnecter', + <%= link_to 'DƩconnecter', disconnect_admin_communication_extranet_contacts_path( - extranet_id: @extranet.id, - objectId: person.id, + extranet_id: @extranet.id, + objectId: person.id, objectType: person.class ), class: button_classes_danger, method: :post %> <% else %> - <%= link_to 'Connecter', + <%= link_to 'Connecter', connect_admin_communication_extranet_contacts_path( - extranet_id: @extranet.id, - objectId: person.id, + extranet_id: @extranet.id, + objectId: person.id, objectType: person.class ), class: button_classes, @@ -35,9 +38,12 @@ </tbody> </table> </div> - <%= paginate @persons, theme: 'bootstrap-5', param_name: :persons_page %> + <%= paginate @people, theme: 'bootstrap-5', param_name: :persons_page %> <% end %> - <%= osuny_panel University::Organization.model_name.human(count: 2) do %> + <% action = link_to t('export'), + admin_communication_extranet_contacts_path(extranet_id: @extranet.id, export: 'organizations', format: :xlsx), + class: button_classes('ms-1') if can?(:show, University::Person) %> + <%= osuny_panel University::Organization.model_name.human(count: 2), action: action do %> <div class="table-responsive"> <table class="<%= table_classes%>"> <tbody> @@ -46,19 +52,19 @@ <td><%= link_to organization, [:admin, organization] %></td> <td> <% if @extranet.connected?(organization) %> - <%= link_to 'DƩconnecter', + <%= link_to 'DƩconnecter', disconnect_admin_communication_extranet_contacts_path( - extranet_id: @extranet.id, - objectId: organization.id, + extranet_id: @extranet.id, + objectId: organization.id, objectType: organization.class ), class: button_classes_danger, method: :post %> <% else %> - <%= link_to 'Connecter', + <%= link_to 'Connecter', connect_admin_communication_extranet_contacts_path( - extranet_id: @extranet.id, - objectId: organization.id, + extranet_id: @extranet.id, + objectId: organization.id, objectType: organization.class ), class: button_classes, @@ -72,4 +78,4 @@ </div> <%= paginate @organizations, theme: 'bootstrap-5', param_name: :organizations_page %> <% end %> -<% end %> \ No newline at end of file +<% end %> diff --git a/app/views/admin/communication/extranets/contacts/organizations.xlsx.axlsx b/app/views/admin/communication/extranets/contacts/organizations.xlsx.axlsx new file mode 100644 index 0000000000000000000000000000000000000000..a0e20d1940857097b2d9c4de0409c45f737f64b3 --- /dev/null +++ b/app/views/admin/communication/extranets/contacts/organizations.xlsx.axlsx @@ -0,0 +1,60 @@ +wb = xlsx_package.workbook +wb.add_worksheet(name: "index") do |sheet| + options = [ + University::Organization.human_attribute_name('name'), + University::Organization.human_attribute_name('address_name'), + University::Organization.human_attribute_name('address'), + University::Organization.human_attribute_name('address_additional'), + University::Organization.human_attribute_name('zipcode'), + University::Organization.human_attribute_name('city'), + University::Organization.human_attribute_name('country'), + University::Organization.human_attribute_name('kind'), + University::Organization.human_attribute_name('siren'), + University::Organization.human_attribute_name('phone'), + University::Organization.human_attribute_name('url'), + University::Organization.human_attribute_name('email'), + University::Organization.human_attribute_name('linkedin'), + University::Organization.human_attribute_name('twitter') + ] + + types = [ + :string, + :string, + :string, + :string, + :string, + :string, + :string, + :string, + :string, + :string, + :string, + :string, + :string, + :string, + :string + ] + + sheet.add_row options, types: Array.new(types.length) { |_| :string } + + @organizations.each do |organization| + infos = [ + organization.name, + organization.address_name, + organization.address, + organization.address_additional, + organization.zipcode, + organization.city, + organization.country_name, + organization.kind_i18n, + organization.siren, + organization.phone, + organization.url, + organization.email, + organization.linkedin, + organization.twitter.present? ? "@#{organization.twitter}" : '' + ] + + sheet.add_row infos, types: types + end +end diff --git a/app/views/admin/communication/extranets/contacts/people.xlsx.axlsx b/app/views/admin/communication/extranets/contacts/people.xlsx.axlsx new file mode 100644 index 0000000000000000000000000000000000000000..c140b04f01bedf73417b250998aaeba24e4b4ee3 --- /dev/null +++ b/app/views/admin/communication/extranets/contacts/people.xlsx.axlsx @@ -0,0 +1,62 @@ +wb = xlsx_package.workbook +wb.add_worksheet(name: "index") do |sheet| + options = [ + University::Person.human_attribute_name('last_name'), + University::Person.human_attribute_name('first_name'), + University::Person.human_attribute_name('email'), + University::Person.human_attribute_name('gender'), + University::Person.human_attribute_name('address'), + University::Person.human_attribute_name('zipcode'), + University::Person.human_attribute_name('city'), + University::Person.human_attribute_name('country'), + University::Person.human_attribute_name('birthdate'), + University::Person.human_attribute_name('phone_personal'), + University::Person.human_attribute_name('phone_professional'), + University::Person.human_attribute_name('phone_mobile'), + University::Person.human_attribute_name('url'), + University::Person.human_attribute_name('linkedin'), + University::Person.human_attribute_name('twitter') + ] + + types = [ + :string, + :string, + :string, + :string, + :string, + :string, + :string, + :string, + :string, + :string, + :string, + :string, + :string, + :string, + :string + ] + + sheet.add_row options, types: Array.new(types.length) { |_| :string } + + @people.each do |person| + infos = [ + person.last_name, + person.first_name, + person.email, + person.gender.present? ? t("activerecord.attributes.university/person.genders.#{person.gender}") : '', + person.address, + person.zipcode, + person.city, + person.country_name, + person.birthdate.present? ? l(person.birthdate, format: :birthday) : '', + person.phone_personal, + person.phone_professional, + person.phone_mobile, + person.url, + person.linkedin, + person.twitter.present? ? "@#{person.twitter}" : '' + ] + + sheet.add_row infos, types: types + end +end diff --git a/app/views/admin/communication/extranets/documents/categories/index.html.erb b/app/views/admin/communication/extranets/documents/categories/index.html.erb index f8b438112df99b3345eae07b2560ca25e3af9f8e..7cd4d3774dd5d3382d98bf7ab013c7e185333701 100644 --- a/app/views/admin/communication/extranets/documents/categories/index.html.erb +++ b/app/views/admin/communication/extranets/documents/categories/index.html.erb @@ -5,5 +5,5 @@ <% end %> <% content_for :action_bar_right do %> - <%= create_link Communication::Extranet::Post::Category %> + <%= create_link Communication::Extranet::Document::Category %> <% end %> \ No newline at end of file diff --git a/app/views/admin/communication/extranets/posts/categories/index.html.erb b/app/views/admin/communication/extranets/posts/categories/index.html.erb index a8f70232c95d8a7fe1eb0593b351925e49ca8191..421c1358200a4fba552eb203b200d2fee0a8d24f 100644 --- a/app/views/admin/communication/extranets/posts/categories/index.html.erb +++ b/app/views/admin/communication/extranets/posts/categories/index.html.erb @@ -5,5 +5,5 @@ <% end %> <% content_for :action_bar_right do %> - <%= create_link Communication::Extranet::Document::Category %> + <%= create_link Communication::Extranet::Post::Category %> <% end %> \ No newline at end of file diff --git a/app/views/admin/education/schools/static.html.erb b/app/views/admin/education/schools/static.html.erb index bb1396b0e79a9e9e3f51b36b2821a731bf83d6e4..01bafc82144f5793d2658cc13da7e7ab18309292 100644 --- a/app/views/admin/education/schools/static.html.erb +++ b/app/views/admin/education/schools/static.html.erb @@ -9,7 +9,7 @@ zipcode: > city: > <%= @about.city %> country: > - <%= ISO3166::Country[@about.country].translations[@about.country.downcase] %> + <%= @about.country_common_name %> phone: > <%= @about.phone %> <% if administrator_involvements.any? %> diff --git a/app/views/admin/research/laboratories/static.html.erb b/app/views/admin/research/laboratories/static.html.erb index 01b70fa3db984a8df8b173f8ac1ed56dcd58aa4d..e294a824d91ba5419a878940eb7eeca6960545fe 100644 --- a/app/views/admin/research/laboratories/static.html.erb +++ b/app/views/admin/research/laboratories/static.html.erb @@ -8,5 +8,5 @@ zipcode: > city: > <%= @about.city %> country: > - <%= ISO3166::Country[@about.country].translations[@about.country.downcase] %> + <%= @about.country_common_name %> --- diff --git a/app/views/admin/university/organizations/show.html.erb b/app/views/admin/university/organizations/show.html.erb index 46dd34a5f1e7a11749586f6d6b25a1faf1b83bab..fdf5454779cb2c5be4806cf596f75e662efef0aa 100644 --- a/app/views/admin/university/organizations/show.html.erb +++ b/app/views/admin/university/organizations/show.html.erb @@ -26,7 +26,7 @@ <% if @organization.country.present? %> <div class="col-xxl-6"> <%= osuny_label University::Organization.human_attribute_name('country') %> - <p><%= ISO3166::Country[@organization.country].common_name %></p> + <p><%= @organization.country_name %></p> </div> <% end %> <% if @organization.geolocated? %> diff --git a/app/views/admin/university/people/_main_infos.html.erb b/app/views/admin/university/people/_main_infos.html.erb index caf29a011f6bd692f23ab23100d5f483841c730a..9211f6b14809bc4cfbae3d44673a34fb0d0f94eb 100644 --- a/app/views/admin/university/people/_main_infos.html.erb +++ b/app/views/admin/university/people/_main_infos.html.erb @@ -29,7 +29,7 @@ <p><%= l(person.birthdate, format: :birthday) %></p> </div> <% end %> - <% [:address, :zipcode, :city, :country].each do |property| %> + <% [:address, :zipcode, :city].each do |property| %> <% value = person.send property %> <% next if value.blank? %> <div class="col-md-6"> @@ -37,6 +37,12 @@ <p><%= value %></p> </div> <% end %> + <% if person.country.present? %> + <div class="col-md-6"> + <%= osuny_label University::Person.human_attribute_name(:country) %> + <p><%= person.country_name %></p> + </div> + <% end %> </div> <% unless person.biography.blank? %> <%= osuny_label University::Person.human_attribute_name('biography') %> diff --git a/app/views/extranet/contacts/organizations/show.html.erb b/app/views/extranet/contacts/organizations/show.html.erb index 4998e9356fb1b41b0b242c03079ce8d37138f8d5..58b5deeec5fc624b61a4f64cdc744031abc1f185 100644 --- a/app/views/extranet/contacts/organizations/show.html.erb +++ b/app/views/extranet/contacts/organizations/show.html.erb @@ -64,6 +64,8 @@ </dd> <% end %> <% if @organization.geolocated? %> + <%# Include map.js before call Leaflet (map helper) %> + <%= javascript_include_tag 'map' %> <dt><%= University::Organization.human_attribute_name(:map) %></dt> <dl><%= map( center: { diff --git a/app/views/extranet/organizations/show.html.erb b/app/views/extranet/organizations/show.html.erb index 0c6394a26b6b4c23d11efb0fd894d7e380ec959b..0042d2c29493816f9eccde170f0460bc4514713a 100644 --- a/app/views/extranet/organizations/show.html.erb +++ b/app/views/extranet/organizations/show.html.erb @@ -56,7 +56,7 @@ <% if @organization.country.present? %> <div class="col-xxl-6"> <%= osuny_label University::Organization.human_attribute_name('country') %> - <p><%= ISO3166::Country[@organization.country].common_name %></p> + <p><%= @organization.country_common_name %></p> </div> <% end %> <% if @organization.geolocated? %> diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb index e7f0e9b1057fe98db3e11af11878db810b5d9ec4..07ca293a6920106c19334d1b478c93f9f6ea124a 100644 --- a/config/initializers/mime_types.rb +++ b/config/initializers/mime_types.rb @@ -1,6 +1,3 @@ # Be sure to restart your server when you modify this file. - -# Add new mime types for use in respond_to blocks: -# Mime::Type.register "text/richtext", :rtf -# Mime::Type.register "text/css", :css +Mime::Type.register "application/xls", :xlsx Mime::Type.register "application/xml", :xml, %w( text/xml application/x-xml ) diff --git a/config/locales/en.yml b/config/locales/en.yml index 56de4b0f1de4e3d1c3fffac4742cb6e1bf294c56..f06aaeeba4ceb0837df7712edc899d0aa6c93c2f 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -173,6 +173,7 @@ en: finished: Finished finished_with_errors: Finished with errors pending: Pending + export: Export (xlsx) false: No featured_image: title: Image diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 711fa805dbedff947b0f666147be92f0b97f1ddb..f351c0fcd1bedd3c4f0e5b72ac865e71071d899f 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -173,6 +173,7 @@ fr: finished: TraitƩ finished_with_errors: TraitƩ avec des erreurs pending: En cours de traitement + export: Exporter (xlsx) false: Non featured_image: title: Image diff --git a/db/schema.rb b/db/schema.rb index e8777f0bc621a360385e022e8e5a31ad57029770..a47a0f1993c3aa56fdb9e59385075a70a6f64199 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -240,18 +240,6 @@ ActiveRecord::Schema[7.0].define(version: 2023_03_10_083029) do t.index ["communication_website_post_id", "communication_website_category_id"], name: "post_category" end - create_table "communication_website_connections", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| - t.uuid "university_id", null: false - t.uuid "website_id", null: false - t.string "object_type", null: false - t.uuid "object_id", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.index ["object_type", "object_id"], name: "index_communication_website_connections_on_object" - t.index ["university_id"], name: "index_communication_website_connections_on_university_id" - t.index ["website_id"], name: "index_communication_website_connections_on_website_id" - end - create_table "communication_website_git_files", id: :uuid, default: -> { "public.gen_random_uuid()" }, force: :cascade do |t| t.string "previous_path" t.string "about_type", null: false @@ -1058,8 +1046,6 @@ ActiveRecord::Schema[7.0].define(version: 2023_03_10_083029) do add_foreign_key "communication_website_categories", "education_programs", column: "program_id" add_foreign_key "communication_website_categories", "languages" add_foreign_key "communication_website_categories", "universities" - add_foreign_key "communication_website_connections", "communication_websites", column: "website_id" - add_foreign_key "communication_website_connections", "universities" add_foreign_key "communication_website_git_files", "communication_websites", column: "website_id" add_foreign_key "communication_website_imported_authors", "communication_website_imported_websites", column: "website_id" add_foreign_key "communication_website_imported_authors", "universities"