diff --git a/app/controllers/admin/communication/extranets_controller.rb b/app/controllers/admin/communication/extranets_controller.rb index c4ca5d22ae83ccda613e1cc2fbb91ec39ca43b1f..01296ea7e713ddcbd76ba7104cced914e88a7b2c 100644 --- a/app/controllers/admin/communication/extranets_controller.rb +++ b/app/controllers/admin/communication/extranets_controller.rb @@ -55,6 +55,6 @@ class Admin::Communication::ExtranetsController < Admin::Communication::Applicat def extranet_params params.require(:communication_extranet) - .permit(:name, :domain, :logo, :logo_delete) + .permit(:name, :domain, :about_type, :about_id, :logo, :logo_delete) end end diff --git a/app/models/communication/extranet.rb b/app/models/communication/extranet.rb index 4d22aba55404c4e436f3ce97998dadb1c8fda678..f041347526c323c78bc734599153063ab7fc6629 100644 --- a/app/models/communication/extranet.rb +++ b/app/models/communication/extranet.rb @@ -3,14 +3,17 @@ # Table name: communication_extranets # # id :uuid not null, primary key +# about_type :string indexed => [about_id] # domain :string # name :string # created_at :datetime not null # updated_at :datetime not null +# about_id :uuid indexed => [about_type] # university_id :uuid not null, indexed # # Indexes # +# index_communication_extranets_on_about (about_type,about_id) # index_communication_extranets_on_university_id (university_id) # # Foreign Keys @@ -18,6 +21,7 @@ # fk_rails_c2268c7ebd (university_id => universities.id) # class Communication::Extranet < ApplicationRecord + include WithAbouts include WithUniversity validates_presence_of :name, :domain diff --git a/app/models/communication/website/with_abouts.rb b/app/models/concerns/with_abouts.rb similarity index 89% rename from app/models/communication/website/with_abouts.rb rename to app/models/concerns/with_abouts.rb index a94242cd5d3fa5b5e7c848e47d5784e0bfdd9870..55d5b9248d63c320926a1196bd6e30cfee7d5af8 100644 --- a/app/models/communication/website/with_abouts.rb +++ b/app/models/concerns/with_abouts.rb @@ -1,4 +1,4 @@ -module Communication::Website::WithAbouts +module WithAbouts extend ActiveSupport::Concern included do diff --git a/app/views/admin/communication/_abouts.html.erb b/app/views/admin/communication/_abouts.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..f236cd7d2f0a741e8382b9b6aba866dfe3eec102 --- /dev/null +++ b/app/views/admin/communication/_abouts.html.erb @@ -0,0 +1,41 @@ +<%= f.input :about_type, + collection: Communication::Website.about_types, + input_html: { data: { conditional: true }, id: "about_type" }, + label_method: lambda { |object| + I18n.t("#{i18n_key}#{object}") + }, + include_blank: false %> +<div class="d-none" + data-conditional-source="about_type" + data-conditional-value="Education::School"> + <%= f.input :about_id, + collection: current_university.education_schools.ordered, + label: Education::School.model_name.human, + include_blank: false %> +</div> +<div class="d-none" + data-conditional-source="about_type" + data-conditional-value="Education::Program"> + <%= f.input :about_id, + collection: collection_tree(current_university.education_programs), + label: Education::Program.model_name.human, + label_method: ->(p) { sanitize p[:label] }, + value_method: ->(p) { p[:id] }, + include_blank: false %> +</div> +<div class="d-none" + data-conditional-source="about_type" + data-conditional-value="Research::Journal"> + <%= f.input :about_id, + collection: current_university.research_journals, + label: Research::Journal.model_name.human, + include_blank: false %> +</div> +<div class="d-none" + data-conditional-source="about_type" + data-conditional-value="Research::Laboratory"> + <%= f.input :about_id, + collection: current_university.research_laboratories, + label: Research::Laboratory.model_name.human, + include_blank: false %> +</div> diff --git a/app/views/admin/communication/extranets/_form.html.erb b/app/views/admin/communication/extranets/_form.html.erb index bcd279d9ffa618ad56fafa8680f599cfabc4c410..c1d3e253a04e72f3221b7ca89cb4eb748dd76c00 100644 --- a/app/views/admin/communication/extranets/_form.html.erb +++ b/app/views/admin/communication/extranets/_form.html.erb @@ -8,7 +8,7 @@ <div class="card-body"> <%= f.input :name %> <%= f.input :domain %> - + <%= render 'admin/communication/abouts', f: f, i18n_key: 'activerecord.attributes.communication/extranet.about_' %> </div> </div> </div> @@ -23,7 +23,6 @@ input_html: { accept: '.jpg,.jpeg,.png,.svg' }, preview: 200, direct_upload: true %> - </div> </div> </div> diff --git a/app/views/admin/communication/extranets/index.html.erb b/app/views/admin/communication/extranets/index.html.erb index 94ba7170829cd03ec1157b54785b6d814fe17d3d..5a83cd771fb1dd1cba9de0a92262a70f34f43302 100644 --- a/app/views/admin/communication/extranets/index.html.erb +++ b/app/views/admin/communication/extranets/index.html.erb @@ -3,8 +3,11 @@ <table class="<%= table_classes %>"> <thead> <tr> - <th><%= Communication::Website.human_attribute_name('name') %></th> - <th><%= Communication::Website.human_attribute_name('url') %></th> + <th><%= Communication::Extranet.human_attribute_name('name') %></th> + <th><%= Communication::Extranet.human_attribute_name('domain') %></th> + <th><%= Communication::Extranet.human_attribute_name('about_type') %></th> + <th><%= Communication::Extranet.human_attribute_name('about') %></th> + <th></th> <th></th> </tr> </thead> @@ -13,6 +16,8 @@ <tr> <td><%= link_to extranet, [:admin, extranet] %></td> <td><%= link_to extranet.url, extranet.url, target: :_blank %></td> + <td><%= I18n.t("activerecord.attributes.communication/extranet.about_#{extranet.about_type}") %></td> + <td><%= link_to extranet.about, [:admin, extranet.about] if extranet.about %></td> <td class="text-end"> <div class="btn-group" role="group"> <%= edit_link extranet %> diff --git a/app/views/admin/communication/extranets/show.html.erb b/app/views/admin/communication/extranets/show.html.erb index c2ce9ea944e5c45dd612257f2c26632899a2d777..2569f1707d1d78be6387188287de3106bdb88c0f 100644 --- a/app/views/admin/communication/extranets/show.html.erb +++ b/app/views/admin/communication/extranets/show.html.erb @@ -1,8 +1,14 @@ <% content_for :title, @extranet %> <% content_for :title_right do %> - <%= link_to @extranet.url, @extranet.url, target: :_blank %> -<% end unless @extranet.url.blank? %> + <% unless @extranet.url.blank? %> + <%= link_to @extranet.url, @extranet.url, target: :_blank %><br> + <% end %> + <%= I18n.t("activerecord.attributes.communication/extranet.about_#{@extranet.about_type}") %> + <% if @extranet.about %> + (<%= link_to @extranet.about, [:admin, @extranet.about] unless @extranet.about.nil? %>) + <% end %> +<% end %> <% content_for :action_bar_right do %> <%= edit_link @extranet %> diff --git a/app/views/admin/communication/websites/_form.html.erb b/app/views/admin/communication/websites/_form.html.erb index 220ece4d693cce3ff9f2de051829b7c10fe8312e..d1d031fc376d11cd812e4c43788ecf932e24e8a1 100644 --- a/app/views/admin/communication/websites/_form.html.erb +++ b/app/views/admin/communication/websites/_form.html.erb @@ -8,47 +8,7 @@ <div class="card-body"> <%= f.input :name %> <%= f.input :url %> - <%= f.input :about_type, - collection: Communication::Website.about_types, - input_html: { data: { conditional: true } }, - label_method: lambda { |object| - I18n.t("activerecord.attributes.communication/website.about_#{object}") - }, - include_blank: false %> - <div class="d-none" - data-conditional-source="communication_website_about_type" - data-conditional-value="Education::School"> - <%= f.input :about_id, - collection: current_university.education_schools.ordered, - label: Education::School.model_name.human, - include_blank: false %> - </div> - <div class="d-none" - data-conditional-source="communication_website_about_type" - data-conditional-value="Education::Program"> - <%= f.input :about_id, - collection: collection_tree(current_university.education_programs), - label: Education::Program.model_name.human, - label_method: ->(p) { sanitize p[:label] }, - value_method: ->(p) { p[:id] }, - include_blank: false %> - </div> - <div class="d-none" - data-conditional-source="communication_website_about_type" - data-conditional-value="Research::Journal"> - <%= f.input :about_id, - collection: current_university.research_journals, - label: Research::Journal.model_name.human, - include_blank: false %> - </div> - <div class="d-none" - data-conditional-source="communication_website_about_type" - data-conditional-value="Research::Laboratory"> - <%= f.input :about_id, - collection: current_university.research_laboratories, - label: Research::Laboratory.model_name.human, - include_blank: false %> - </div> + <%= render 'admin/communication/abouts', f: f, i18n_key: 'activerecord.attributes.communication/website.about_' %> </div> </div> </div> diff --git a/config/locales/communication/en.yml b/config/locales/communication/en.yml index 1ff23d913840d4440c8d2edae290aa04719da5e7..b358f93a78cdef6be18069b995be72e6b9171a4e 100644 --- a/config/locales/communication/en.yml +++ b/config/locales/communication/en.yml @@ -36,12 +36,19 @@ en: other: Posts all: All posts attributes: - communication/extranet: - title: Title - domain: Domain communication/block: name: Name template: Kind of block + communication/extranet: + about: About + about_: Independent extranet (no specific subject) + about_Education::Program: Program extranet + about_Education::School: School extranet + about_Research::Journal: Journal extranet + about_Research::Laboratory: Laboratory extranet + about_type: About + title: Title + domain: Domain communication/website: about: About about_: Independent website (no specific subject) diff --git a/config/locales/communication/fr.yml b/config/locales/communication/fr.yml index b34316691f629e8338bfeca2d72b71b15f627be7..b93bab6e8286db1b8a6e9126e62fe40d3d7e9ed6 100644 --- a/config/locales/communication/fr.yml +++ b/config/locales/communication/fr.yml @@ -40,6 +40,13 @@ fr: title: Titre template: Type de bloc communication/extranet: + about: Sujet de l'extranet + about_: Extranet indépendant (aucun sujet) + about_Education::Program: Extranet d'une formation + about_Education::School: Extranet d'une école + about_Research::Journal: Extranet d'une revue scientifique + about_Research::Laboratory: Extranet d'un laboratoire + about_type: Type d'extranet name: Nom domain: Domaine communication/website: @@ -49,7 +56,7 @@ fr: about_Education::School: Site d'école about_Research::Journal: Site de revue scientifique about_Research::Laboratory: Site de laboratoire - about_type: Sujet du site + about_type: Type de site name: Nom url: URL communication/website/category: diff --git a/db/migrate/20220411133002_add_about_to_communication_extranets.rb b/db/migrate/20220411133002_add_about_to_communication_extranets.rb new file mode 100644 index 0000000000000000000000000000000000000000..b42deb0e9a6ef1e9562967a04a4b885ebf1a61ed --- /dev/null +++ b/db/migrate/20220411133002_add_about_to_communication_extranets.rb @@ -0,0 +1,6 @@ +class AddAboutToCommunicationExtranets < ActiveRecord::Migration[6.1] + def change + add_reference :communication_extranets, :about, polymorphic: true, type: :uuid + + end +end diff --git a/db/schema.rb b/db/schema.rb index 2417eca45698ed6143e3a9654d29d3d9678c7e01..e83f950a6cc38e1e2d6be0db503fb67fb03976e7 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_04_08_105051) do +ActiveRecord::Schema.define(version: 2022_04_11_133002) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" @@ -99,6 +99,9 @@ ActiveRecord::Schema.define(version: 2022_04_08_105051) do t.string "domain" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false + t.string "about_type" + t.uuid "about_id" + t.index ["about_type", "about_id"], name: "index_communication_extranets_on_about" t.index ["university_id"], name: "index_communication_extranets_on_university_id" end diff --git a/test/fixtures/communication/extranets.yml b/test/fixtures/communication/extranets.yml index bc8e28dc28879f1b8d9154076ecc63db7e04380b..776fd724dd5f024e021fce80b2a6c2d36c36bae3 100644 --- a/test/fixtures/communication/extranets.yml +++ b/test/fixtures/communication/extranets.yml @@ -3,14 +3,17 @@ # Table name: communication_extranets # # id :uuid not null, primary key +# about_type :string indexed => [about_id] # domain :string # name :string # created_at :datetime not null # updated_at :datetime not null +# about_id :uuid indexed => [about_type] # university_id :uuid not null, indexed # # Indexes # +# index_communication_extranets_on_about (about_type,about_id) # index_communication_extranets_on_university_id (university_id) # # Foreign Keys diff --git a/test/models/communication/extranet_test.rb b/test/models/communication/extranet_test.rb index 6230afc9a5003701d77724c0def02121a97d160e..54e7cf1a80e1fe893549cc7327a91a469e705468 100644 --- a/test/models/communication/extranet_test.rb +++ b/test/models/communication/extranet_test.rb @@ -3,14 +3,17 @@ # Table name: communication_extranets # # id :uuid not null, primary key +# about_type :string indexed => [about_id] # domain :string # name :string # created_at :datetime not null # updated_at :datetime not null +# about_id :uuid indexed => [about_type] # university_id :uuid not null, indexed # # Indexes # +# index_communication_extranets_on_about (about_type,about_id) # index_communication_extranets_on_university_id (university_id) # # Foreign Keys