From 208e15a561c461e2cf9a72df1a341174a8fa346f Mon Sep 17 00:00:00 2001 From: pabois <pierreandre.boissinot@noesya.coop> Date: Mon, 11 Apr 2022 15:54:57 +0200 Subject: [PATCH] close #304 --- .../communication/extranets_controller.rb | 2 +- app/models/communication/extranet.rb | 4 ++ .../website => concerns}/with_abouts.rb | 2 +- .../admin/communication/_abouts.html.erb | 41 ++++++++++++++++++ .../communication/extranets/_form.html.erb | 3 +- .../communication/extranets/index.html.erb | 9 +++- .../communication/extranets/show.html.erb | 10 ++++- .../communication/websites/_form.html.erb | 42 +------------------ config/locales/communication/en.yml | 13 ++++-- config/locales/communication/fr.yml | 9 +++- ...02_add_about_to_communication_extranets.rb | 6 +++ db/schema.rb | 5 ++- test/fixtures/communication/extranets.yml | 3 ++ test/models/communication/extranet_test.rb | 3 ++ 14 files changed, 98 insertions(+), 54 deletions(-) rename app/models/{communication/website => concerns}/with_abouts.rb (89%) create mode 100644 app/views/admin/communication/_abouts.html.erb create mode 100644 db/migrate/20220411133002_add_about_to_communication_extranets.rb diff --git a/app/controllers/admin/communication/extranets_controller.rb b/app/controllers/admin/communication/extranets_controller.rb index c4ca5d22a..01296ea7e 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 4d22aba55..f04134752 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 a94242cd5..55d5b9248 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 000000000..f236cd7d2 --- /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 bcd279d9f..c1d3e253a 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 94ba71708..5a83cd771 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 c2ce9ea94..2569f1707 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 220ece4d6..d1d031fc3 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 1ff23d913..b358f93a7 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 b34316691..b93bab6e8 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 000000000..b42deb0e9 --- /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 2417eca45..e83f950a6 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 bc8e28dc2..776fd724d 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 6230afc9a..54e7cf1a8 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 -- GitLab