diff --git a/app/controllers/admin/communication/website/index_pages_controller.rb b/app/controllers/admin/communication/website/index_pages_controller.rb new file mode 100644 index 0000000000000000000000000000000000000000..8dc1e395cdec7aad8f4d319a9bf9d67c4a180335 --- /dev/null +++ b/app/controllers/admin/communication/website/index_pages_controller.rb @@ -0,0 +1,49 @@ +class Admin::Communication::Website::IndexPagesController < Admin::Communication::Website::ApplicationController + before_action :get_index_page, :ensure_abilities, only: [:edit, :update] + + def index + authorize! :read, Communication::Website::IndexPage + breadcrumb + @kinds = Communication::Website::IndexPage.kinds + end + + def edit + breadcrumb + add_breadcrumb @index_page + end + + def update + # if @index_page.update_and_sync(index_page_params) + if @index_page.update(index_page_params) + redirect_to admin_communication_website_indexes_path(@website), notice: t('admin.successfully_updated_html', model: Communication::Website::IndexPage.model_name.human) + else + breadcrumb + add_breadcrumb @index_page + render :edit, status: :unprocessable_entity + end + end + + protected + + def get_index_page + @index_page = @website.index_pages.where(kind: params[:kind]).first_or_initialize + end + + def ensure_abilities + authorize! :update, @index_page + end + + def breadcrumb + super + add_breadcrumb Communication::Website::IndexPage.model_name.human(count: 2), admin_communication_website_indexes_path(@website) + end + + + def index_page_params + params.require(:communication_website_index_page) + .permit( + :title, :description, :text, :featured_image, :featured_image_delete, + :featured_image_infos, :featured_image_alt + ) + end +end diff --git a/app/models/communication/website.rb b/app/models/communication/website.rb index 02de212c3d181ad74edc9c7c3b732d89c47b0b48..f3abb7a6ead4d460b55ca177650988a8711727c3 100644 --- a/app/models/communication/website.rb +++ b/app/models/communication/website.rb @@ -37,6 +37,7 @@ class Communication::Website < ApplicationRecord include WithGitRepository include WithHome include WithImport + include WithIndexPages include WithMenuItems include WithStructure diff --git a/app/models/communication/website/home.rb b/app/models/communication/website/home.rb index e35d331f377e598439ec04feb6943c2d1aeb18a6..00353bdc29900672e5fe998248be50318b553a78 100644 --- a/app/models/communication/website/home.rb +++ b/app/models/communication/website/home.rb @@ -6,6 +6,7 @@ # description :text # featured_image_alt :string # github_path :text +# text_new :text # created_at :datetime not null # updated_at :datetime not null # communication_website_id :uuid not null, indexed diff --git a/app/models/communication/website/index_page.rb b/app/models/communication/website/index_page.rb new file mode 100644 index 0000000000000000000000000000000000000000..e923e672b8c5e1a5bcb9c303013bd34384b935a1 --- /dev/null +++ b/app/models/communication/website/index_page.rb @@ -0,0 +1,48 @@ +# == Schema Information +# +# Table name: communication_website_index_pages +# +# id :uuid not null, primary key +# description :text +# featured_image_alt :string +# kind :integer +# path :string +# text :text +# title :string +# created_at :datetime not null +# updated_at :datetime not null +# communication_website_id :uuid not null, indexed +# university_id :uuid not null, indexed +# +# Indexes +# +# idx_comm_website_index_page_on_communication_website_id (communication_website_id) +# index_communication_website_index_pages_on_university_id (university_id) +# +# Foreign Keys +# +# fk_rails_5cd2482227 (communication_website_id => communication_websites.id) +# fk_rails_7eb45227ae (university_id => universities.id) +# +class Communication::Website::IndexPage < ApplicationRecord + + enum kind: { home: 0, + communication_posts: 10, + education_programs: 20, + research_articles: 30, research_volumes: 32, + persons: 100, administrators: 110, authors: 120, researchers: 130, teachers: 140 + } + + belongs_to :university + belongs_to :website, foreign_key: :communication_website_id + + has_one_attached_deletable :featured_image + + validates :title, :path, presence: true + + def to_s + Communication::Website::IndexPage.human_attribute_name("kind_#{kind}") + end + + +end diff --git a/app/models/communication/website/page.rb b/app/models/communication/website/page.rb index 4a81253e0070ce429948cdf519765335cfd96bca..c72e01cc657d6382c1048e1f9ce4e13592462362 100644 --- a/app/models/communication/website/page.rb +++ b/app/models/communication/website/page.rb @@ -12,6 +12,7 @@ # position :integer default(0), not null # published :boolean default(FALSE) # slug :string +# text_new :text # title :string # created_at :datetime not null # updated_at :datetime not null diff --git a/app/models/communication/website/with_index_pages.rb b/app/models/communication/website/with_index_pages.rb new file mode 100644 index 0000000000000000000000000000000000000000..37eb649163c3d3606cca863599848c8918ca75aa --- /dev/null +++ b/app/models/communication/website/with_index_pages.rb @@ -0,0 +1,11 @@ +module Communication::Website::WithIndexPages + extend ActiveSupport::Concern + + included do + has_many :index_pages, + class_name: 'Communication::Website::IndexPage', + foreign_key: :communication_website_id, + dependent: :destroy + end + +end diff --git a/app/models/education/program.rb b/app/models/education/program.rb index 4396afb139e0ed0ba87bb3148ae45937dbc4a7a6..9abd988e96d3f1c9c75cb32f48b67e4630aa1557 100644 --- a/app/models/education/program.rb +++ b/app/models/education/program.rb @@ -3,16 +3,29 @@ # Table name: education_programs # # id :uuid not null, primary key +# accessibility_new :text # capacity :integer +# contacts_new :text +# content_new :text # continuing :boolean # description :text +# duration_new :text # ects :integer +# evaluation_new :text # featured_image_alt :string # level :integer # name :string +# objectives_new :text +# opportunities_new :text +# other_new :text # path :string +# pedagogy_new :text # position :integer default(0) +# prerequisites_new :text +# pricing_new :text # published :boolean default(FALSE) +# registration_new :text +# results_new :text # slug :string # created_at :datetime not null # updated_at :datetime not null diff --git a/app/models/research/journal/article.rb b/app/models/research/journal/article.rb index bfe4270b1f2ebc51197cebd6e0d5abcd76fd2678..3ff64d1093a41146aa9c9ee78e2b7fc03833624f 100644 --- a/app/models/research/journal/article.rb +++ b/app/models/research/journal/article.rb @@ -5,12 +5,12 @@ # id :uuid not null, primary key # abstract :text # keywords :text -# old_text :text # position :integer # published :boolean default(FALSE) # published_at :datetime # references :text # slug :string +# text_new :text # title :string # created_at :datetime not null # updated_at :datetime not null diff --git a/app/models/research/laboratory/axis.rb b/app/models/research/laboratory/axis.rb index 372f8165f5f7340b4ad1749e4fe27f8b48faf77d..5556990de730a60877322bdc79974b3085253335 100644 --- a/app/models/research/laboratory/axis.rb +++ b/app/models/research/laboratory/axis.rb @@ -7,6 +7,7 @@ # name :string # position :integer # short_name :string +# text_new :text # created_at :datetime not null # updated_at :datetime not null # research_laboratory_id :uuid not null, indexed diff --git a/app/models/university/person.rb b/app/models/university/person.rb index 311541fc3cbd5ef26c5e72858c0243da12a238aa..8f25ccd6d549213397050f95e310eb72ee3221ca 100644 --- a/app/models/university/person.rb +++ b/app/models/university/person.rb @@ -3,6 +3,7 @@ # Table name: university_people # # id :uuid not null, primary key +# biography_new :text # description :text # email :string # first_name :string diff --git a/app/models/university/person/administrator.rb b/app/models/university/person/administrator.rb index 422bbd69544b4216ae726f1afd368d7eda1c3c79..45c0cf4c7c389a6029fadf3018d75465cccc01b2 100644 --- a/app/models/university/person/administrator.rb +++ b/app/models/university/person/administrator.rb @@ -3,6 +3,7 @@ # Table name: university_people # # id :uuid not null, primary key +# biography_new :text # description :text # email :string # first_name :string diff --git a/app/models/university/person/author.rb b/app/models/university/person/author.rb index eee35eb4270c38c23a153466120b59931f94b2ac..1bb44c1eb9111e6857654761c402c169e7b2db21 100644 --- a/app/models/university/person/author.rb +++ b/app/models/university/person/author.rb @@ -3,6 +3,7 @@ # Table name: university_people # # id :uuid not null, primary key +# biography_new :text # description :text # email :string # first_name :string diff --git a/app/models/university/person/researcher.rb b/app/models/university/person/researcher.rb index 165f8868de5ca732c2aaba98710ed05c2a8d40f0..207a0919a838b9554625946d10b22f74952b33e1 100644 --- a/app/models/university/person/researcher.rb +++ b/app/models/university/person/researcher.rb @@ -3,6 +3,7 @@ # Table name: university_people # # id :uuid not null, primary key +# biography_new :text # description :text # email :string # first_name :string diff --git a/app/models/university/person/teacher.rb b/app/models/university/person/teacher.rb index 59c75c7b3ee28e7ba59219af8296e984e58c0047..18518ba9231e6231cbe06d3b9aa4b3b96f6cce7d 100644 --- a/app/models/university/person/teacher.rb +++ b/app/models/university/person/teacher.rb @@ -3,6 +3,7 @@ # Table name: university_people # # id :uuid not null, primary key +# biography_new :text # description :text # email :string # first_name :string diff --git a/app/views/admin/communication/website/index_pages/edit.html.erb b/app/views/admin/communication/website/index_pages/edit.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..44ea023b4a14a953dc96efd0a2208b8dcfc60577 --- /dev/null +++ b/app/views/admin/communication/website/index_pages/edit.html.erb @@ -0,0 +1,47 @@ +<% content_for :title, Communication::Website::IndexPage.human_attribute_name("kind_#{@index_page.kind}") %> + +<%= render 'admin/communication/websites/sidebar' do %> + + <%= simple_form_for @index_page, url: admin_communication_website_index_path(website_id: @website.id, kind: @index_page.kind) do |f| %> + <div class="row"> + <div class="col-md-8"> + <div class="card flex-fill w-100"> + <div class="card-header"> + <h5 class="card-title mb-0"><%= t('content') %></h5> + </div> + <div class="card-body"> + <%= f.input :title %> + <%= f.input :path, + input_html: { + class: 'js-slug-input', + data: { source: '#communication_website_index_page_title' } + } %> + <%= f.input :description %> + <%= f.input :text, as: :rich_text_area %> + </div> + </div> + </div> + <div class="col-md-4"> + <div class="card flex-fill w-100"> + <div class="card-header"> + <h5 class="card-title mb-0"><%= t('activerecord.attributes.communication/website/page.featured_image') %></h5> + </div> + <div class="card-body"> + <%= f.input :featured_image, + as: :single_deletable_file, + direct_upload: true, + label: false, + input_html: { accept: '.jpg,.jpeg,.png' }, + preview: true + %> + <%= f.input :featured_image_alt %> + </div> + </div> + </div> + </div> + <% content_for :action_bar_right do %> + <%= submit f %> + <% end %> + <% end %> + +<% end %> diff --git a/app/views/admin/communication/website/index_pages/index.html.erb b/app/views/admin/communication/website/index_pages/index.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..c1ede975aec9279822d899bf23499b8eac961784 --- /dev/null +++ b/app/views/admin/communication/website/index_pages/index.html.erb @@ -0,0 +1,11 @@ +<% content_for :title, t('activerecord.models.communication/website/index_page.other') %> + +<%= render 'admin/communication/websites/sidebar' do %> + + <ul> + <% @kinds.each do |key, value| %> + <li><%= link_to Communication::Website::IndexPage.human_attribute_name("kind_#{key}"), admin_communication_website_index_path(website_id: @website.id, kind: key) %></li> + <% end %> + </ul> + +<% end %> diff --git a/app/views/admin/communication/websites/_sidebar.html.erb b/app/views/admin/communication/websites/_sidebar.html.erb index e2c09d29dcd7cd1712cc2d8d9256362a4f02ba9a..07a6d26daaa14437458bf5f6db897473b1fdc318 100644 --- a/app/views/admin/communication/websites/_sidebar.html.erb +++ b/app/views/admin/communication/websites/_sidebar.html.erb @@ -39,6 +39,11 @@ path: admin_communication_website_menus_path(website_id: @website), ability: can?(:read, Communication::Website::Category) }, + { + title: Communication::Website::IndexPage.model_name.human(count: 2), + path: admin_communication_website_indexes_path(website_id: @website), + ability: can?(:read, Communication::Website::IndexPage) + }, { title: Communication::Website::Structure.model_name.human, path: admin_communication_website_structure_path(website_id: @website), diff --git a/config/locales/communication/fr.yml b/config/locales/communication/fr.yml index c59adc6e002d75a01a485bf8f9c7a73b1579ff10..e3601da89dded1f4b523089ae146128c1529a0d0 100644 --- a/config/locales/communication/fr.yml +++ b/config/locales/communication/fr.yml @@ -16,6 +16,9 @@ fr: communication/website/imported/website: one: Site importé other: Sites importés + communication/website/index_page: + one: Page d'index + other: Pages d'index communication/website/menu: one: Menu other: Menus @@ -54,6 +57,23 @@ fr: text: Texte featured_image: Image à la une featured_image_alt: Texte alternatif + communication/website/index_page: + description: Description (SEO) + featured_image: Image à la une + featured_image_alt: Texte alternatif + kind_home: Accueil + kind_communication_posts: Actualités + kind_education_programs: Formations + kind_research_articles: Articles + kind_research_volumes: Volumes + kind_persons: Équipe + kind_administrators: Équipe administrative + kind_authors: Équipe éditoriale + kind_researchers: Équipe de recherche + kind_teachers: Équipe pédagogique + slug: Slug + text: Texte + title: Titre communication/website/imported/category: original: Original communication/website/imported/medium: diff --git a/config/routes/admin/communication.rb b/config/routes/admin/communication.rb index 705d9fb2837234f6e43b74e2a6e065d920712c27..5325fc2832e5b76193f00bc2e056459d67578a7c 100644 --- a/config/routes/admin/communication.rb +++ b/config/routes/admin/communication.rb @@ -38,5 +38,9 @@ namespace :communication do end get 'structure' => 'website/structure#edit' patch 'structure' => 'website/structure#update' + + get 'indexes' => 'website/index_pages#index' + get 'indexes/:kind' => 'website/index_pages#edit', as: :index + patch 'indexes/:kind' => 'website/index_pages#update' end end diff --git a/db/migrate/20220214144924_create_communication_website_index_pages.rb b/db/migrate/20220214144924_create_communication_website_index_pages.rb new file mode 100644 index 0000000000000000000000000000000000000000..d009994cf8a5faa2cb7899471475a4f8f4bfb218 --- /dev/null +++ b/db/migrate/20220214144924_create_communication_website_index_pages.rb @@ -0,0 +1,21 @@ +class CreateCommunicationWebsiteIndexPages < ActiveRecord::Migration[6.1] + def change + create_table :communication_website_index_pages, id: :uuid do |t| + t.references :university, null: false, foreign_key: true, type: :uuid + t.references :communication_website, + null: false, + foreign_key: { to_table: :communication_websites }, + type: :uuid, + index: { name: 'idx_comm_website_index_page_on_communication_website_id' } + + t.string :title + t.string :path + t.text :description + t.text :text + t.string :featured_image_alt + t.integer :kind + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index f18cf9d8e339870c4fa2278fd359150f27a4ac29..3a9315c5c172064ed2ab8b4a612e6ebcd7a824eb 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_02_10_105040) do +ActiveRecord::Schema.define(version: 2022_02_14_144924) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" @@ -126,6 +126,7 @@ ActiveRecord::Schema.define(version: 2022_02_10_105040) do t.text "github_path" t.string "featured_image_alt" t.text "description" + t.text "text_new" t.index ["communication_website_id"], name: "idx_comm_website_homes_on_communication_website_id" t.index ["university_id"], name: "index_communication_website_homes_on_university_id" end @@ -238,6 +239,21 @@ ActiveRecord::Schema.define(version: 2022_02_10_105040) do t.index ["website_id"], name: "index_communication_website_imported_websites_on_website_id" end + create_table "communication_website_index_pages", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + t.uuid "university_id", null: false + t.uuid "communication_website_id", null: false + t.string "title" + t.string "path" + t.text "description" + t.text "text" + t.string "featured_image_alt" + t.integer "kind" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.index ["communication_website_id"], name: "idx_comm_website_index_page_on_communication_website_id" + t.index ["university_id"], name: "index_communication_website_index_pages_on_university_id" + end + create_table "communication_website_menu_items", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "website_id", null: false @@ -288,6 +304,7 @@ ActiveRecord::Schema.define(version: 2022_02_10_105040) do t.text "github_path" t.uuid "related_category_id" t.string "featured_image_alt" + t.text "text_new" t.index ["about_type", "about_id"], name: "index_communication_website_pages_on_about" t.index ["communication_website_id"], name: "index_communication_website_pages_on_communication_website_id" t.index ["parent_id"], name: "index_communication_website_pages_on_parent_id" @@ -407,6 +424,19 @@ ActiveRecord::Schema.define(version: 2022_02_10_105040) do t.text "description" t.boolean "published", default: false t.string "featured_image_alt" + t.text "accessibility_new" + t.text "contacts_new" + t.text "duration_new" + t.text "evaluation_new" + t.text "objectives_new" + t.text "opportunities_new" + t.text "other_new" + t.text "pedagogy_new" + t.text "prerequisites_new" + t.text "pricing_new" + t.text "registration_new" + t.text "content_new" + t.text "results_new" t.index ["parent_id"], name: "index_education_programs_on_parent_id" t.index ["university_id"], name: "index_education_programs_on_university_id" end @@ -448,7 +478,6 @@ ActiveRecord::Schema.define(version: 2022_02_10_105040) do create_table "research_journal_articles", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "title" - t.text "old_text" t.datetime "published_at" t.uuid "university_id", null: false t.uuid "research_journal_id", null: false @@ -462,6 +491,7 @@ ActiveRecord::Schema.define(version: 2022_02_10_105040) do t.string "slug" t.boolean "published", default: false t.integer "position" + t.text "text_new" t.index ["research_journal_id"], name: "index_research_journal_articles_on_research_journal_id" t.index ["research_journal_volume_id"], name: "index_research_journal_articles_on_research_journal_volume_id" t.index ["university_id"], name: "index_research_journal_articles_on_university_id" @@ -525,6 +555,7 @@ ActiveRecord::Schema.define(version: 2022_02_10_105040) do t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false t.string "short_name" + t.text "text_new" t.index ["research_laboratory_id"], name: "index_research_laboratory_axes_on_research_laboratory_id" t.index ["university_id"], name: "index_research_laboratory_axes_on_university_id" end @@ -578,6 +609,7 @@ ActiveRecord::Schema.define(version: 2022_02_10_105040) do t.text "description" t.boolean "habilitation", default: false t.boolean "tenure", default: false + t.text "biography_new" t.index ["university_id"], name: "index_university_people_on_university_id" t.index ["user_id"], name: "index_university_people_on_user_id" end @@ -680,6 +712,8 @@ ActiveRecord::Schema.define(version: 2022_02_10_105040) do add_foreign_key "communication_website_imported_posts", "universities" add_foreign_key "communication_website_imported_websites", "communication_websites", column: "website_id" add_foreign_key "communication_website_imported_websites", "universities" + add_foreign_key "communication_website_index_pages", "communication_websites" + add_foreign_key "communication_website_index_pages", "universities" add_foreign_key "communication_website_menu_items", "communication_website_menu_items", column: "parent_id" add_foreign_key "communication_website_menu_items", "communication_website_menus", column: "menu_id" add_foreign_key "communication_website_menu_items", "communication_websites", column: "website_id" diff --git a/test/fixtures/research/laboratory/axes.yml b/test/fixtures/research/laboratory/axes.yml index 51a668b6624c3851ba74e0016f84ffd54a5f5247..1ff6715cc3683b92cfac45e891a5d28d35047dec 100644 --- a/test/fixtures/research/laboratory/axes.yml +++ b/test/fixtures/research/laboratory/axes.yml @@ -7,6 +7,7 @@ # name :string # position :integer # short_name :string +# text_new :text # created_at :datetime not null # updated_at :datetime not null # research_laboratory_id :uuid not null, indexed diff --git a/test/models/research/laboratory/axis_test.rb b/test/models/research/laboratory/axis_test.rb index 909fb0dd87343a26630336b64b75ee32b03c67cf..0ed57cec560d0ee30ea592ce89f14472526cc58b 100644 --- a/test/models/research/laboratory/axis_test.rb +++ b/test/models/research/laboratory/axis_test.rb @@ -7,6 +7,7 @@ # name :string # position :integer # short_name :string +# text_new :text # created_at :datetime not null # updated_at :datetime not null # research_laboratory_id :uuid not null, indexed