diff --git a/app/controllers/admin/communication/contents_controller.rb b/app/controllers/admin/communication/contents_controller.rb new file mode 100644 index 0000000000000000000000000000000000000000..ff344cda5f4cd5c317525ee6fe728c11f649decb --- /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 7a991bcb3d0d23cb7c2ac24e2d1bbdeebc6e65e7..9e72a7a0343b443c8682b3416c0117be539e787a 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 0000000000000000000000000000000000000000..6a7beb1f8928e9e56f982ffc30e1da589e915dd6 --- /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 0000000000000000000000000000000000000000..78200449958af13e845ed3a8f8c1d20c97060576 --- /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 0000000000000000000000000000000000000000..e9b2189d3202323f9e22928c78e1ac1798e44a89 --- /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 0000000000000000000000000000000000000000..d34ab2bc5978b8e88803848b52fa315ec2530341 --- /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 03c198bee398a7926d380d7c743350a55534db43..bdc98ea30130036ab2b7f18f052bc191d7279e66 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