Merge pull request #8384 from tchak/refactor-procedure-detail-toggle
refactor(demarches): use turbo_stream template
This commit is contained in:
commit
f262ac4cf3
7 changed files with 32 additions and 20 deletions
|
@ -333,10 +333,10 @@ module Administrateurs
|
||||||
|
|
||||||
def detail
|
def detail
|
||||||
@procedure = Procedure.find(params[:id])
|
@procedure = Procedure.find(params[:id])
|
||||||
render turbo_stream: [
|
@show_detail = params[:show_detail]
|
||||||
turbo_stream.remove("procedure_detail_#{@procedure.id}"),
|
respond_to do |format|
|
||||||
turbo_stream.replace("procedure_#{@procedure.id}", partial: "detail", locals: { procedure: @procedure, show_detail: params[:show_detail] })
|
format.turbo_stream
|
||||||
]
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def all
|
def all
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { ApplicationController } from './application_controller';
|
import { ApplicationController } from './application_controller';
|
||||||
import { toggle } from '@utils';
|
import { show, hide } from '@utils';
|
||||||
const AUTOSUBMIT_DEBOUNCE_DELAY = 5000;
|
const AUTOSUBMIT_DEBOUNCE_DELAY = 5000;
|
||||||
|
|
||||||
export class AutosubmitController extends ApplicationController {
|
export class AutosubmitController extends ApplicationController {
|
||||||
|
@ -7,6 +7,7 @@ export class AutosubmitController extends ApplicationController {
|
||||||
|
|
||||||
declare readonly formTarget: HTMLFormElement;
|
declare readonly formTarget: HTMLFormElement;
|
||||||
declare readonly spinnerTarget: HTMLElement;
|
declare readonly spinnerTarget: HTMLElement;
|
||||||
|
declare readonly hasSpinnerTarget: boolean;
|
||||||
|
|
||||||
submit() {
|
submit() {
|
||||||
this.formTarget.requestSubmit();
|
this.formTarget.requestSubmit();
|
||||||
|
@ -18,7 +19,14 @@ export class AutosubmitController extends ApplicationController {
|
||||||
|
|
||||||
connect() {
|
connect() {
|
||||||
this.onGlobal('turbo:submit-start', () => {
|
this.onGlobal('turbo:submit-start', () => {
|
||||||
toggle(this.spinnerTarget);
|
if (this.hasSpinnerTarget) {
|
||||||
|
show(this.spinnerTarget);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.onGlobal('turbo:submit-end', () => {
|
||||||
|
if (this.hasSpinnerTarget) {
|
||||||
|
hide(this.spinnerTarget);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,4 +6,10 @@ class ProcedureDetail < OpenStruct
|
||||||
[I18n.t(attribute, scope: 'activerecord.attributes.procedure_export'), attribute]
|
[I18n.t(attribute, scope: 'activerecord.attributes.procedure_export'), attribute]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def administrateurs
|
||||||
|
Administrateurs.new(count: admin_count)
|
||||||
|
end
|
||||||
|
|
||||||
|
Administrateurs = Struct.new(:count)
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,7 +1,11 @@
|
||||||
%tr.procedure{ id: "procedure_#{procedure.id}" }
|
%tr.procedure{ id: "procedure_#{procedure.id}" }
|
||||||
%td
|
%td
|
||||||
= button_to detail_admin_procedure_path(procedure["id"]), params: show_detail ? {} : { show_detail: true }, method: :get, title: 'Cacher les détails', class: [ show_detail ? 'fr-icon-subtract-line':'fr-icon-add-line', "fr-icon--sm fr-mr-1w fr-mb-1w fr-text-action-high--blue-france fr-btn fr-btn--tertiary-no-outline"] do
|
- title = show_detail ? 'Cacher les détails de la démarche' : 'Afficher les détails de la démarche'
|
||||||
Cacher les détails
|
- icon = show_detail ? 'fr-icon-subtract-line' : 'fr-icon-add-line'
|
||||||
|
- params = show_detail ? {} : { show_detail: true }
|
||||||
|
= button_to detail_admin_procedure_path(procedure["id"]), method: :post, params:, title:, class: [icon, "fr-icon--sm fr-mr-1w fr-mb-1w fr-text-action-high--blue-france fr-btn fr-btn--tertiary-no-outline" ] do
|
||||||
|
= title
|
||||||
|
|
||||||
%td= procedure.libelle
|
%td= procedure.libelle
|
||||||
%td= procedure.id
|
%td= procedure.id
|
||||||
%td= procedure.administrateurs.count
|
%td= procedure.administrateurs.count
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
- content_for :results do
|
- content_for :results do
|
||||||
.main-filter-header.fr-my-3w
|
.main-filter-header.fr-my-3w
|
||||||
= form_with(url: all_admin_procedures_path, method: :get, html: {'data-autosubmit-target': 'form', role: 'search', class: 'search' }) do |f|
|
= form_with(url: all_admin_procedures_path, method: :get, html: { 'data-autosubmit-target': 'form', role: 'search', class: 'search' }) do |f|
|
||||||
- @filter.zone_ids&.each do |zone_id|
|
- @filter.zone_ids&.each do |zone_id|
|
||||||
= hidden_field_tag 'zone_ids[]', zone_id
|
= hidden_field_tag 'zone_ids[]', zone_id
|
||||||
- @filter.statuses&.each do |status|
|
- @filter.statuses&.each do |status|
|
||||||
|
@ -42,13 +42,5 @@
|
||||||
%th{ scope: 'col' } Date
|
%th{ scope: 'col' } Date
|
||||||
%tbody{ 'data-turbo': 'true' }
|
%tbody{ 'data-turbo': 'true' }
|
||||||
- @procedures.each do |procedure|
|
- @procedures.each do |procedure|
|
||||||
%tr.procedure{ id: "procedure_#{procedure['id']}" }
|
= render partial: 'detail', locals: { procedure: procedure, show_detail: false }
|
||||||
%td
|
|
||||||
= button_to detail_admin_procedure_path(procedure["id"]), params: { show_detail: true}, method: :get, title: 'Afficher details', class: "fr-icon-add-line fr-icon--sm fr-mr-1w fr-mb-1w fr-text-action-high--blue-france fr-btn fr-btn--tertiary-no-outline" do
|
|
||||||
Afficher details procedure
|
|
||||||
%td= procedure.libelle
|
|
||||||
%td= procedure.id
|
|
||||||
%td= procedure.admin_count
|
|
||||||
%td= t procedure.aasm_state, scope: 'activerecord.values.procedure.aasm_state'
|
|
||||||
%td= l(procedure.published_at, format: :message_date_without_time)
|
|
||||||
.fr-mt-2w= paginate @procedures, views_prefix: 'administrateurs'
|
.fr-mt-2w= paginate @procedures, views_prefix: 'administrateurs'
|
||||||
|
|
|
@ -1 +1,3 @@
|
||||||
= turbo_stream.after("procedure_#{@procedure.id}", partial: "detail", locals: { procedure: @procedure })
|
- if !@show_detail
|
||||||
|
= turbo_stream.remove "procedure_detail_#{@procedure.id}"
|
||||||
|
= turbo_stream.replace "procedure_#{@procedure.id}", partial: "detail", locals: { procedure: @procedure, show_detail: @show_detail }
|
||||||
|
|
|
@ -459,7 +459,7 @@ Rails.application.routes.draw do
|
||||||
end
|
end
|
||||||
|
|
||||||
member do
|
member do
|
||||||
get 'detail'
|
post 'detail'
|
||||||
get 'apercu'
|
get 'apercu'
|
||||||
get 'champs'
|
get 'champs'
|
||||||
get 'zones'
|
get 'zones'
|
||||||
|
|
Loading…
Add table
Reference in a new issue