From da704c5a48a95c7ac6926b4ecc4f41682c99a322 Mon Sep 17 00:00:00 2001 From: Arnaud Levy <contact@arnaudlevy.com> Date: Mon, 24 Jul 2023 08:22:43 +0200 Subject: [PATCH] preparing for remote --- .../communication/contents_controller.rb | 20 +++++++++ .../blocks/content/_editor.html.erb | 44 +++---------------- .../contents/_structure.html.erb | 7 +++ .../communication/contents/_write.html.erb | 24 ++++++++++ .../communication/contents/structure.html.erb | 1 + .../communication/contents/write.html.erb | 1 + config/routes/admin/communication.rb | 4 ++ 7 files changed, 64 insertions(+), 37 deletions(-) create mode 100644 app/controllers/admin/communication/contents_controller.rb create mode 100644 app/views/admin/communication/contents/_structure.html.erb create mode 100644 app/views/admin/communication/contents/_write.html.erb create mode 100644 app/views/admin/communication/contents/structure.html.erb create mode 100644 app/views/admin/communication/contents/write.html.erb diff --git a/app/controllers/admin/communication/contents_controller.rb b/app/controllers/admin/communication/contents_controller.rb new file mode 100644 index 000000000..ff344cda5 --- /dev/null +++ b/app/controllers/admin/communication/contents_controller.rb @@ -0,0 +1,20 @@ +class Admin::Communication::ContentsController < Admin::Communication::ApplicationController + before_action :load_about + layout false + + # /admin/communication/contents/Communication::Website::Page/a788f3ab-a3a8-4d26-9440-6cb12fbf442c/write + def write + end + + # /admin/communication/contents/Communication::Website::Page/a788f3ab-a3a8-4d26-9440-6cb12fbf442c/structure + def structure + end + + protected + + def load_about + @about = PolymorphicObjectFinder.find(params, :about) + raise_403_unless @about.university == current_university + raise_403_unless can?(:edit, @about) + end +end \ No newline at end of file diff --git a/app/views/admin/communication/blocks/content/_editor.html.erb b/app/views/admin/communication/blocks/content/_editor.html.erb index 7a991bcb3..9e72a7a03 100644 --- a/app/views/admin/communication/blocks/content/_editor.html.erb +++ b/app/views/admin/communication/blocks/content/_editor.html.erb @@ -9,12 +9,12 @@ mode_expert = about.headings.many? <ul class="nav nav-tabs justify-content-md-end"> <li class="nav-item small"> <a class="nav-link active" - id="mode-content-tab" + id="mode-write-tab" data-bs-toggle="tab" - data-bs-target="#mode-content" + data-bs-target="#mode-write" type="button" role="tab" - aria-controls="mode-content" + aria-controls="mode-write" aria-selected="true"> Écrire le contenu </a> @@ -35,9 +35,9 @@ mode_expert = about.headings.many? <% end %> <div class="tab-content"> <div class="tab-pane fade show active" - id="mode-content" + id="mode-write" role="tabpanel" - aria-labelledby="mode-content-tab" + aria-labelledby="mode-write-tab" tabindex="0"> <% if mode_expert %> <div class="row"> @@ -46,30 +46,7 @@ mode_expert = about.headings.many? </div> </div> <% end %> - <div class=" content-editor__elements - content-editor--write - content-editor__elements__root - js-content-editor-sortable-container" - id="content-editor-elements-root"> - <% about.blocks.without_heading.ordered.each do |block| %> - <%= render 'admin/communication/blocks/block', block: block %> - <% end %> - <% about.headings.root.ordered.each do |heading| %> - <%= render 'admin/communication/blocks/headings/heading', heading: heading %> - <% end %> - </div> - <div class="content-editor__actions row mt-5"> - <div class="col-lg-4"> - <%= link_to t('admin.communication.blocks.headings.add'), - new_admin_communication_heading_path(about_id: about.id, about_type: about.class.name), - class: 'py-5 px-2 d-block bg-light text-center border h4' if can? :create, Communication::Block::Heading %> - </div> - <div class="col-lg-8"> - <%= link_to t('admin.communication.blocks.add'), - new_admin_communication_block_path(about_id: about.id, about_type: about.class.name), - class: 'py-5 px-2 d-block bg-light text-center border h4' if can? :create, Communication::Block %> - </div> - </div> + <%= render 'admin/communication/contents/write', about: about %> </div> <div class="tab-pane fade" id="mode-structure" @@ -81,14 +58,7 @@ mode_expert = about.headings.many? <p class="text-lg-end text-muted small mt-2">Dans le mode "Organiser le plan", vous ne voyez pas les blocs mais seulement les titres. Lorsque vous déplacez un titre, tous les blocs suivent. C'est le mode idéal pour ranger les documents longs.</p> </div> </div> - - <div class=" content-editor__elements - content-editor--organize - js-content-editor-sortable-container"> - <% about.headings.root.ordered.each do |heading| %> - <%= render 'admin/communication/blocks/headings/heading', heading: heading, hide_blocks: true %> - <% end %> - </div> + <%= render 'admin/communication/contents/structure', about: about %> </div> </div> diff --git a/app/views/admin/communication/contents/_structure.html.erb b/app/views/admin/communication/contents/_structure.html.erb new file mode 100644 index 000000000..6a7beb1f8 --- /dev/null +++ b/app/views/admin/communication/contents/_structure.html.erb @@ -0,0 +1,7 @@ +<div class=" content-editor__elements + content-editor--organize + js-content-editor-sortable-container"> + <% about.headings.root.ordered.each do |heading| %> + <%= render 'admin/communication/blocks/headings/heading', heading: heading, hide_blocks: true %> + <% end %> +</div> diff --git a/app/views/admin/communication/contents/_write.html.erb b/app/views/admin/communication/contents/_write.html.erb new file mode 100644 index 000000000..782004499 --- /dev/null +++ b/app/views/admin/communication/contents/_write.html.erb @@ -0,0 +1,24 @@ +<div class=" content-editor__elements + content-editor--write + content-editor__elements__root + js-content-editor-sortable-container" + id="content-editor-elements-root"> + <% about.blocks.without_heading.ordered.each do |block| %> + <%= render 'admin/communication/blocks/block', block: block %> + <% end %> + <% about.headings.root.ordered.each do |heading| %> + <%= render 'admin/communication/blocks/headings/heading', heading: heading %> + <% end %> +</div> +<div class="content-editor__actions row mt-5"> + <div class="col-lg-4"> + <%= link_to t('admin.communication.blocks.headings.add'), + new_admin_communication_heading_path(about_id: about.id, about_type: about.class.name), + class: 'py-5 px-2 d-block bg-light text-center border h4' if can? :create, Communication::Block::Heading %> + </div> + <div class="col-lg-8"> + <%= link_to t('admin.communication.blocks.add'), + new_admin_communication_block_path(about_id: about.id, about_type: about.class.name), + class: 'py-5 px-2 d-block bg-light text-center border h4' if can? :create, Communication::Block %> + </div> +</div> \ No newline at end of file diff --git a/app/views/admin/communication/contents/structure.html.erb b/app/views/admin/communication/contents/structure.html.erb new file mode 100644 index 000000000..e9b2189d3 --- /dev/null +++ b/app/views/admin/communication/contents/structure.html.erb @@ -0,0 +1 @@ +<%= render 'admin/communication/contents/structure', about: @about %> \ No newline at end of file diff --git a/app/views/admin/communication/contents/write.html.erb b/app/views/admin/communication/contents/write.html.erb new file mode 100644 index 000000000..d34ab2bc5 --- /dev/null +++ b/app/views/admin/communication/contents/write.html.erb @@ -0,0 +1 @@ +<%= render 'admin/communication/contents/write', about: @about %> \ No newline at end of file diff --git a/config/routes/admin/communication.rb b/config/routes/admin/communication.rb index 03c198bee..bdc98ea30 100644 --- a/config/routes/admin/communication.rb +++ b/config/routes/admin/communication.rb @@ -65,6 +65,10 @@ namespace :communication do end end end + scope "/contents/:about_type/:about_id", as: :contents, controller: 'contents' do + get :write + get :structure + end resources :blocks, controller: 'blocks', except: [:index] do collection do resources :headings, controller: 'blocks/headings', except: [:index, :show] do -- GitLab