diff --git a/app/assets/stylesheets/admin/preview.sass b/app/assets/stylesheets/admin/preview.sass index 7db0e22bde6f5296ad0d3743e4a1a4acbdabbae7..3a78e66b89330dea7dd8a46262e9b1d4ecaed079 100644 --- a/app/assets/stylesheets/admin/preview.sass +++ b/app/assets/stylesheets/admin/preview.sass @@ -1,11 +1,20 @@ .preview .modal-body - background: black - text-align: center + background: #EEEEEE overflow: hidden + padding: 0 + text-align: center + transition: padding 0.5s ease iframe + background: white + box-shadow: 0 3px 20px rgba(0, 0, 0, 0.1) height: 100% - transition: width 0.5s ease + transition: width 0.5s ease, height 0.5s ease + &--mobile, &--tablet + .modal-body + padding: 2rem + iframe + border-radius: 10px &--mobile iframe width: 415px diff --git a/app/controllers/admin/communication/blocks_controller.rb b/app/controllers/admin/communication/blocks_controller.rb index a7247dd3c566e8f79f2dc267387e99e845477e37..fa543158404e5ed3bc9f83f253dbcaeea7ae82cb 100644 --- a/app/controllers/admin/communication/blocks_controller.rb +++ b/app/controllers/admin/communication/blocks_controller.rb @@ -48,6 +48,11 @@ class Admin::Communication::BlocksController < Admin::Communication::Application end end + def duplicate + redirect_to [:edit, :admin, @block.duplicate], + notice: t('admin.successfully_duplicated_html', model: @block.to_s) + end + def destroy path = about_path @block.destroy @@ -80,6 +85,6 @@ class Admin::Communication::BlocksController < Admin::Communication::Application def block_params params.require(:communication_block) - .permit(:about_id, :about_type, :template_kind, :title, :data) + .permit(:about_id, :about_type, :template_kind, :title, :data, :published) end end diff --git a/app/controllers/admin/communication/websites/pages_controller.rb b/app/controllers/admin/communication/websites/pages_controller.rb index c6c290817899f759a8648cd5b61c6146260fafc3..b7c8e6a92b9c313266f33ed7f1a74eb749d8fce1 100644 --- a/app/controllers/admin/communication/websites/pages_controller.rb +++ b/app/controllers/admin/communication/websites/pages_controller.rb @@ -71,6 +71,11 @@ class Admin::Communication::Websites::PagesController < Admin::Communication::We end end + def duplicate + redirect_to [:admin, @page.duplicate], + notice: t('admin.successfully_duplicated_html', model: @page.to_s) + end + def destroy if @page.is_special_page? redirect_back(fallback_location: admin_communication_website_page_path(@page), alert: t('admin.communication.website.pages.delete_special_page_notice')) diff --git a/app/helpers/admin/application_helper.rb b/app/helpers/admin/application_helper.rb index 172a0b59cf999863426330d2436783dfd1cbfc25..cc6a12f4ccadeb73c05adfbceead0adecd7d68df 100644 --- a/app/helpers/admin/application_helper.rb +++ b/app/helpers/admin/application_helper.rb @@ -45,6 +45,14 @@ module Admin::ApplicationHelper aria-controls=\"preview\">#{ t 'preview.button'}</button>" end + def duplicate_link(object) + link_to t('admin.duplicate'), + [:duplicate, :admin, object], + method: :post, + data: { confirm: t('please_confirm') }, + class: button_classes('btn-light') + end + def button_classes(additional = '', **options) classes = "btn btn-primary btn-xs #{additional}" classes += ' disabled' if options[:disabled] diff --git a/app/models/communication/block.rb b/app/models/communication/block.rb index 5c07c25e34b97c83456e3d4760d2f57641102443..ed2a58be0fcdc11991209a21ef9281f3a321b895 100644 --- a/app/models/communication/block.rb +++ b/app/models/communication/block.rb @@ -6,6 +6,7 @@ # about_type :string indexed => [about_id] # data :jsonb # position :integer default(0), not null +# published :boolean default(TRUE) # template_kind :integer default(NULL), not null # title :string # created_at :datetime not null @@ -59,6 +60,8 @@ class Communication::Block < ApplicationRecord utilities: [:files, :definitions, :embed] } + scope :published, -> { where(published: true) } + before_save :attach_template_blobs after_commit :save_and_sync_about, on: [:update, :destroy] @@ -90,6 +93,12 @@ class Communication::Block < ApplicationRecord @template = nil end + def duplicate + block = self.dup + block.save + block + end + def to_s title.blank? ? "#{Communication::Block.model_name.human} #{position}" : "#{title}" diff --git a/app/models/communication/website/page.rb b/app/models/communication/website/page.rb index ad4e22bd9ef15307423e01999ed6457684374a37..85c2006d56dd76368a4f13c530897f78ceea8c49 100644 --- a/app/models/communication/website/page.rb +++ b/app/models/communication/website/page.rb @@ -145,6 +145,18 @@ class Communication::Website::Page < ApplicationRecord "/#{language.iso_code}" if website.languages.any? && language_id end + def duplicate + page = self.dup + page.published = false + page.save + blocks.each do |block| + b = block.duplicate + b.about = page + b.save + end + page + end + def to_s "#{title}" end diff --git a/app/views/admin/application/_preview.html.erb b/app/views/admin/application/_preview.html.erb index 4a90bc7fe3250e74681f6d896dda9bbb9e42f1d8..71a273aacac194868332fa8eec2b78cac7cd7a1d 100644 --- a/app/views/admin/application/_preview.html.erb +++ b/app/views/admin/application/_preview.html.erb @@ -5,11 +5,11 @@ <h5 class="modal-title h4"><%= t 'preview.title' %></h5> <div class="btn-group m-auto" role="group" aria-label="Basic example"> <button type="button" class="btn btn-primary preview__button" data-mode="mobile"> - <i class="fas fa-mobile"></i> + <i class="fas fa-mobile-alt"></i> <%= t 'preview.mobile' %> </button> <button type="button" class="btn btn-light preview__button" data-mode="tablet"> - <i class="fas fa-tablet"></i> + <i class="fas fa-tablet-alt"></i> <%= t 'preview.tablet' %> </button> <button type="button" class="btn btn-light preview__button" data-mode="desktop"> @@ -19,7 +19,7 @@ </div> <button type="button" class="btn-close ms-0" data-bs-dismiss="modal" aria-label="Close"></button> </div> - <div class="modal-body p-2"> + <div class="modal-body"> <iframe src="<%= request.path %>/preview" loading="lazy"></iframe> </div> </div> diff --git a/app/views/admin/communication/blocks/_list.html.erb b/app/views/admin/communication/blocks/_list.html.erb index 8aff89419416a1bd71fc61cfbf2578891a66bd2e..4f407759b07e695e229ca57b0b80b846bf9db95f 100644 --- a/app/views/admin/communication/blocks/_list.html.erb +++ b/app/views/admin/communication/blocks/_list.html.erb @@ -24,7 +24,7 @@ </thead> <tbody data-sortable data-sort-url="<%= reorder_admin_communication_blocks_path %>"> <% about.blocks.ordered.each do |block| %> - <tr data-id="<%= block.id %>"> + <tr data-id="<%= block.id %>" class="<%= 'draft' unless block.published? %>"> <% if can? :reorder, Communication::Block %> <td><i class="fa fa-bars handle"></i></td> <% end %> @@ -32,10 +32,10 @@ <td><%= block.template_kind_i18n %></td> <td><%= render 'admin/application/a11y/status', about: block %></td> <td class="text-end"> - <%= edit_link block %> - <%= link_to 'Dependencies', - [:admin, block], - class: button_classes('btn-light') if current_user.server_admin? %> + <div class="btn-group"> + <%= duplicate_link block %> + <%= edit_link block %> + </div> </td> </tr> <% end %> diff --git a/app/views/admin/communication/blocks/_preview.html.erb b/app/views/admin/communication/blocks/_preview.html.erb index d58b3fae33005bda346eafe47995ffa252eb1d6f..a716dae7f1ddb8dc5cbb6d75f9da972595d7c4a6 100644 --- a/app/views/admin/communication/blocks/_preview.html.erb +++ b/app/views/admin/communication/blocks/_preview.html.erb @@ -1,4 +1,4 @@ -<% about.blocks.ordered.each do |block| %> +<% about.blocks.published.ordered.each do |block| %> <section class="block-<%= block.template_kind %>"> <div class="container"> <div class="block-content"> diff --git a/app/views/admin/communication/blocks/_static.html.erb b/app/views/admin/communication/blocks/_static.html.erb index f48693db8af3b0f27d902061e6799268d68a02e2..73a53873c086579463f866a439cd3bfb47a5e67e 100644 --- a/app/views/admin/communication/blocks/_static.html.erb +++ b/app/views/admin/communication/blocks/_static.html.erb @@ -1,6 +1,6 @@ <% if about.blocks.any? %> blocks: -<% about.blocks.ordered.each do |block| +<% about.blocks.published.ordered.each do |block| @block = block @university = about.university %> diff --git a/app/views/admin/communication/blocks/edit.html.erb b/app/views/admin/communication/blocks/edit.html.erb index a19e7e624604c9952c316a4a902fbba1db24c3e6..940c473ec23af60f7dbb6806b0974377a349e4b5 100644 --- a/app/views/admin/communication/blocks/edit.html.erb +++ b/app/views/admin/communication/blocks/edit.html.erb @@ -13,6 +13,10 @@ <div class="col-xxl-3 col-lg-6"> <%= f.input :title %> </div> + <div class="col-xxl-3 col-lg-6"> + <label class="form-label d-none d-lg-block"> </label> + <%= f.input :published %> + </div> </div> <%= render "admin/communication/blocks/templates/#{@block.template_kind}/edit", f: f %> </div> diff --git a/app/views/admin/communication/blocks/templates/call_to_action/_edit.html.erb b/app/views/admin/communication/blocks/templates/call_to_action/_edit.html.erb index fff0006a12e0a0898d9738fd2d24463282a67e99..a624c9d2509b677cd450a420791bac037ba3b20e 100644 --- a/app/views/admin/communication/blocks/templates/call_to_action/_edit.html.erb +++ b/app/views/admin/communication/blocks/templates/call_to_action/_edit.html.erb @@ -20,30 +20,26 @@ </div> <h3 class="h4"><%= t '.buttons' %></h3> -<div v-for="(element, index) in data.elements" class="list-group"> - <div class="list-group-item"> - <div class="flex-fill"> - <div class="row mb-n2"> - <div class="col-lg-3"> - <%= block_component_edit :title, template: @element %> - </div> - <div class="col-lg-4"> - <%= block_component_edit :url, template: @element %> - </div> - <div class="col-lg-4"> - <label class="form-label d-none d-xl-block"> </label> - <%= block_component_edit :target_blank, template: @element %> - </div> - <div class="col-lg-1"> - <a class="btn btn-sm btn-danger float-end" - v-on:click="data.elements.splice(data.elements.indexOf(element), 1)"> - <i class="fas fa-times"></i> - </a> - </div> +<div class="list-group"> + <div v-for="(element, index) in data.elements" class="list-group-item"> + <div class="row mb-n3"> + <div class="col-lg-3"> + <%= block_component_edit :title, template: @element %> + </div> + <div class="col-lg-4"> + <%= block_component_edit :url, template: @element %> + </div> + <div class="col-lg-4"> + <label class="form-label d-none d-xl-block"> </label> + <%= block_component_edit :target_blank, template: @element %> + </div> + <div class="col-lg-1"> + <a class="btn btn-sm btn-danger float-end" + v-on:click="data.elements.splice(data.elements.indexOf(element), 1)"> + <i class="fas fa-times"></i> + </a> </div> - </div> - </div> </div> <div v-if="data.elements.length < 3" class="mt-3"> diff --git a/app/views/admin/communication/blocks/templates/partners/_edit.html.erb b/app/views/admin/communication/blocks/templates/partners/_edit.html.erb index d079fb2f41b93c4be9a80fb87a02bac7e8c34a8f..4741592e62edaece279adecaaa6057f63ee75c4a 100644 --- a/app/views/admin/communication/blocks/templates/partners/_edit.html.erb +++ b/app/views/admin/communication/blocks/templates/partners/_edit.html.erb @@ -13,12 +13,12 @@ </a> </div> <div class="flex-fill"> - <div class="row mb-n3"> + <div class="row"> <div class="col-lg-4"> <%= block_component_edit :id, template: @element, label: '' %> </div> </div> - <div class="row mb-n3" v-if="!element.id"> + <div class="row" v-if="!element.id"> <div class="col-lg-4"> <%= block_component_edit :name, template: @element %> </div> diff --git a/app/views/admin/communication/websites/_sidebar.html.erb b/app/views/admin/communication/websites/_sidebar.html.erb index c9b6d1d07be8bf13de08dc88b074b9aa0d2f70f7..2c170bb7653e10cc31c9d3345220424ffc906ff3 100644 --- a/app/views/admin/communication/websites/_sidebar.html.erb +++ b/app/views/admin/communication/websites/_sidebar.html.erb @@ -10,18 +10,18 @@ icon: Icon::COMMUNICATION_WEBSITE_HOME, ability: can?(:read, @website) }, - { - title: t('admin.communication.website.pages.structure'), - path: admin_communication_website_pages_path(website_id: @website), - icon: Icon::COMMUNICATION_WEBSITE_PAGES, - ability: can?(:read, Communication::Website::Page) - }, { title: Communication::Website::Post.model_name.human(count: 2), path: admin_communication_website_posts_path(website_id: @website), icon: Icon::COMMUNICATION_WEBSITE_POST, ability: can?(:read, Communication::Website::Post) }, + { + title: t('admin.communication.website.pages.structure'), + path: admin_communication_website_pages_path(website_id: @website), + icon: Icon::COMMUNICATION_WEBSITE_PAGES, + ability: can?(:read, Communication::Website::Page) + }, { title: Communication::Website::Menu.model_name.human(count: 2), path: admin_communication_website_menus_path(website_id: @website), diff --git a/app/views/admin/communication/websites/categories/_form.html.erb b/app/views/admin/communication/websites/categories/_form.html.erb index 4f541fc6b91383181ef9e27d1ec186c426afe5e5..ca666d4069c86caa7ba19209dfef336b8cb73d4b 100644 --- a/app/views/admin/communication/websites/categories/_form.html.erb +++ b/app/views/admin/communication/websites/categories/_form.html.erb @@ -10,7 +10,7 @@ </div> <div class="card-body"> <%= f.input :name %> - <%= f.input :text, as: :summernote %> + <%= f.input :text %> </div> </div> <div class="card"> diff --git a/app/views/admin/communication/websites/categories/static.html.erb b/app/views/admin/communication/websites/categories/static.html.erb index 6d3b3a71493bd56077b705613117b413c24102f0..99e07cb40c59b68339343a7c23a1b1901a2cb08e 100644 --- a/app/views/admin/communication/websites/categories/static.html.erb +++ b/app/views/admin/communication/websites/categories/static.html.erb @@ -8,5 +8,6 @@ position: <%= @about.position %> <%= render 'admin/communication/unsplash/static' %> description: > <%= prepare_text_for_static @about.description %> +description_short: > + <%= prepare_text_for_static @about.text %> --- -<%= prepare_html_for_static @about.text, @about.university %> diff --git a/app/views/admin/communication/websites/pages/_treebranch.html.erb b/app/views/admin/communication/websites/pages/_treebranch.html.erb index 370aac563f0fdb3dffa7a8562a91506164fed5eb..47459b77cb0ef3f89570c4337ac36c47a8e379b9 100644 --- a/app/views/admin/communication/websites/pages/_treebranch.html.erb +++ b/app/views/admin/communication/websites/pages/_treebranch.html.erb @@ -28,6 +28,7 @@ <span class="me-3 show-on-hover"><%= t("communication.website.pages.defaults.#{page.kind}.admin_description") %></span> <% end %> <div class="btn-group"> + <%= duplicate_link page if page.is_regular_page?%> <%= edit_link page %> <%= destroy_link page, confirm_message: page.children.any? ? t('please_confirm_with_children') : t('please_confirm') if page.is_regular_page? %> </div> diff --git a/config/locales/communication/en.yml b/config/locales/communication/en.yml index 13bef18e41ec344cfe97346ea2dc73c161f85f6d..9e5ff82da493839f35f4c0d1f63937a82bed19e9 100644 --- a/config/locales/communication/en.yml +++ b/config/locales/communication/en.yml @@ -39,6 +39,7 @@ en: communication/block: name: Name template: Kind of block + published: Published? communication/extranet: about: About about_: Independent extranet @@ -67,7 +68,7 @@ en: communication/website/category: children: Children categories description: Meta Description - text: Text + text: Lead text featured_image: Featured image featured_image_alt: Alt text name: Name diff --git a/config/locales/communication/fr.yml b/config/locales/communication/fr.yml index 8926caa388db665b430a8e511212f3de46557b83..e7d418ad4774496865ffdb7c7e348c9498dae8c5 100644 --- a/config/locales/communication/fr.yml +++ b/config/locales/communication/fr.yml @@ -39,6 +39,7 @@ fr: communication/block: title: Titre template: Type de bloc + published: Publié ? communication/extranet: about: Sujet de l'extranet about_: Extranet indépendant @@ -67,7 +68,7 @@ fr: communication/website/category: children: Catégories enfants description: Meta Description - text: Texte + text: Chapô featured_image: Image à la une featured_image_alt: Texte alternatif name: Nom diff --git a/config/locales/en.yml b/config/locales/en.yml index 2c57fa25b03437b8f9b46a1e774716cdb5345e9a..82bc9e24a232212eee5b800b5468d5fd2d2334e7 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -87,6 +87,7 @@ en: admin: attachment_not_available: Attachment not available dashboard: Dashboard + duplicate: Duplicate infos: Informations inheritance: sentence_without_link: Value inherited @@ -98,6 +99,7 @@ en: password_hint: Leave blank if you do not wish to change the password. successfully_created_html: "<i>%{model}</i> was successfully created." successfully_destroyed_html: "<i>%{model}</i> was successfully destroyed." + successfully_duplicated_html: "<i>%{model}</i> was successfully duplicated." successfully_quit_html: "<i>%{model}</i> successfully quit <i>%{target}</i>." successfully_removed_html: "<i>%{model}</i> was successfully removed." successfully_updated_html: "<i>%{model}</i> was successfully updated." diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 2482496e188f3ae1dfef099eaedf4d1d0cdb6f66..fd26c5dc1488ac215b4166b63a44853ddaa37f4a 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -90,6 +90,7 @@ fr: admin: attachment_not_available: Impossible d'accéder à l'élément dashboard: Tableau de bord + duplicate: Dupliquer infos: Informations inheritance: sentence_without_link: Valeur héritée @@ -101,6 +102,7 @@ fr: password_hint: Laissez vide si vous ne souhaitez pas modifier le mot de passe. successfully_created_html: "<i>%{model}</i> a bien été créé(e)." successfully_destroyed_html: "<i>%{model}</i> a bien été détruit(e)." + successfully_duplicated_html: "<i>%{model}</i> a bien été dupliqué(e)." successfully_quit_html: "<i>%{model}</i> a bien quitté <i>%{target}</i>." successfully_removed_html: "<i>%{model}</i> a bien été retiré(e)." successfully_updated_html: "<i>%{model}</i> a bien été mis(e) à jour." diff --git a/config/routes/admin/communication.rb b/config/routes/admin/communication.rb index e8e5152c5402e022459a4c9650fe37e4dd2b9bd3..c8f3af92d272bf049aa7c52cf9552f8fa054dd93 100644 --- a/config/routes/admin/communication.rb +++ b/config/routes/admin/communication.rb @@ -15,6 +15,7 @@ namespace :communication do get :children get :static get :preview + post :duplicate end end resources :categories, controller: 'websites/categories' do @@ -55,6 +56,9 @@ namespace :communication do collection do post :reorder end + member do + post :duplicate + end end resources :extranets, controller: 'extranets' resources :alumni do diff --git a/db/migrate/20220704164321_add_published_to_communication_blocks.rb b/db/migrate/20220704164321_add_published_to_communication_blocks.rb new file mode 100644 index 0000000000000000000000000000000000000000..ad458b5e3aea11bf08b2080aea0b3ba8a5d56d5a --- /dev/null +++ b/db/migrate/20220704164321_add_published_to_communication_blocks.rb @@ -0,0 +1,5 @@ +class AddPublishedToCommunicationBlocks < ActiveRecord::Migration[6.1] + def change + add_column :communication_blocks, :published, :boolean, default: true + end +end diff --git a/db/schema.rb b/db/schema.rb index a2425b0647abfc1ec7271ad351396b9deb9dfb5d..4f00b3b0a3e588c5ca90964c5d72ce6745413436 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_07_01_064111) do +ActiveRecord::Schema.define(version: 2022_07_04_164321) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" @@ -89,6 +89,7 @@ ActiveRecord::Schema.define(version: 2022_07_01_064111) do t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false t.string "title" + t.boolean "published", default: true t.index ["about_type", "about_id"], name: "index_communication_website_blocks_on_about" t.index ["university_id"], name: "index_communication_blocks_on_university_id" end