Skip to content

Commit

Permalink
Merge pull request #10217 from demarches-simplifiees/9827-export-rename
Browse files Browse the repository at this point in the history
ETQ instructeur, je peux renommer le contenu de mon export zip
  • Loading branch information
krichtof authored May 23, 2024
2 parents b3c2b46 + 0869168 commit 2761d18
Show file tree
Hide file tree
Showing 64 changed files with 1,781 additions and 257 deletions.
13 changes: 1 addition & 12 deletions app/assets/stylesheets/attestation_template_2_edit.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
min-height: 400px;
}

.editor {
.tiptap-editor {
// Visual zones
.header .flex-1,
h1 {
Expand Down Expand Up @@ -63,17 +63,6 @@
li p {
margin-bottom: 0;
}

// Tags
.fr-menu__list {
max-height: 500px;
}

.fr-tag:not(.fr-menu .fr-tag) {
// style span rendered by tiptap like a button/link tag
color: var(--text-action-high-blue-france);
background-color: var(--background-action-low-blue-france);
}
}

// scss-lint:disable SelectorFormat
Expand Down
71 changes: 71 additions & 0 deletions app/assets/stylesheets/exports.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
@import "constants";

.export-template-preview {
// From https://codepen.io/myramoki/pen/xZJjrr
.tree {
margin-left: 0;
}

.tree,
.tree ul {
padding: 0;
list-style: none;
position: relative;
}

.tree ul {
margin: 0 0 0 0.5em; // (indentation/2)
}

.tree:before,
.tree ul:before {
content: "";
display: block;
width: 0;
position: absolute;
top: 0;
bottom: 0;
left: 4px;
border-left: 1px dashed;
}

ul.tree:before {
border-left: none;
}

.tree li {
margin: 0;
padding: 0 1.5em; // indentation + .5em
line-height: 2em; // default list item's `line-height`
position: relative;
}

.tree > li {
padding-left: 0; // Don't indent first level
}

.tree li:before {
content: "";
display: block;
width: 10px; // same with indentation
height: 0;
border-top: 1px dashed;
margin-top: -1px; // border top width
position: absolute;
top: 1em; // (line-height/2)
left: 4px;
}

ul.tree > li:before {
border-top: none;
}

.tree li:last-child:before {
background: var(
--background-alt-blue-france
); // same with body background
height: auto;
top: 1em; // (line-height/2)
bottom: 0;
}
}
14 changes: 14 additions & 0 deletions app/assets/stylesheets/tiptap_editor.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@import "constants";

.tiptap-editor {
// Tags
.fr-menu__list {
max-height: 500px;
}

.fr-tag:not(.fr-menu .fr-tag) {
// style span rendered by tiptap like a button/link tag
color: var(--text-action-high-blue-france);
background-color: var(--background-action-low-blue-france);
}
}
12 changes: 9 additions & 3 deletions app/components/dossiers/export_dropdown_component.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
class Dossiers::ExportDropdownComponent < ApplicationComponent
include ApplicationHelper

def initialize(procedure:, statut: nil, count: nil, class_btn: nil, export_url: nil)
def initialize(procedure:, export_templates: nil, statut: nil, count: nil, class_btn: nil, export_url: nil)
@procedure = procedure
@export_templates = export_templates
@statut = statut
@count = count
@class_btn = class_btn
Expand All @@ -21,10 +22,15 @@ def allowed_format?(item)
item.fetch(:format) != :json || @procedure.active_revision.carte?
end

def download_export_path(export_format:, no_progress_notification: nil)
def download_export_path(export_format: nil, export_template_id: nil, no_progress_notification: nil)
@export_url.call(@procedure,
export_format: export_format,
export_format:,
export_template_id:,
statut: @statut,
no_progress_notification: no_progress_notification)
end

def export_templates
@export_templates
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,13 @@
- menu.with_item do
= link_to download_export_path(export_format: format), role: 'menuitem', data: { turbo_method: :post, turbo: true } do
= t(".everything_#{format}_html")

- if export_templates.present?
- export_templates.each do |export_template|
- menu.with_item do
= link_to download_export_path(export_template_id: export_template.id), role: 'menuitem', data: { turbo_method: :post, turbo: true } do
= "Exporter à partir du modèle #{export_template.name}"
- if feature_enabled?(:export_template)
- menu.with_item do
= link_to new_instructeur_export_template_path(procedure_id: params[:procedure_id]), role: 'menuitem' do
Ajouter un modèle d'export
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
- each_category do |category, tags, can_toggle_nullable|
.flex
%p.fr-label.fr-text--sm.fr-text--bold.fr-mb-1w= t(category, scope: ".categories")
- if category.present?
.flex
%p.fr-label.fr-text--sm.fr-text--bold.fr-mb-1w= t(category, scope: ".categories")

- if can_toggle_nullable
.fr-fieldset__element.fr-ml-4w
.fr-checkbox-group.fr-checkbox-group--sm
= check_box_tag("show_maybe_null", 1, false, data: { "no-autosubmit" => true, action: "change->attestation#toggleMaybeNull"})
= label_tag "show_maybe_null", for: :show_maybe_null do
Voir les champs facultatifs
%span.hidden.fr-hint-text Un champ non rempli restera vide dans l’attestation.
- if can_toggle_nullable
.fr-fieldset__element.fr-ml-4w
.fr-checkbox-group.fr-checkbox-group--sm
= check_box_tag("show_maybe_null", 1, false, data: { "no-autosubmit" => true, action: "change->attestation#toggleMaybeNull"})
= label_tag "show_maybe_null", for: :show_maybe_null do
Voir les champs facultatifs
%span.hidden.fr-hint-text Un champ non rempli restera vide dans l’attestation.

%ul.fr-tags-group{ data: { category: category } }
- tags.each do |tag|
Expand Down
6 changes: 5 additions & 1 deletion app/controllers/administrateurs/exports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ def download
private

def export_format
@export_format ||= params[:export_format]
@export_format ||= params[:export_format].presence || export_template&.kind
end

def export_template
@export_template ||= ExportTemplate.find(params[:export_template_id]) if params[:export_template_id].present?
end

def export_options
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/v2/dossiers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class API::V2::DossiersController < API::V2::BaseController
before_action :ensure_dossier_present

def pdf
@acls = PiecesJustificativesService.new(user_profile: Administrateur.new).acl_for_dossier_export(dossier.procedure)
@acls = PiecesJustificativesService.new(user_profile: Administrateur.new, export_template: nil).acl_for_dossier_export(dossier.procedure)
render(template: 'dossiers/show', formats: [:pdf])
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/instructeurs/dossiers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def show
@is_dossier_in_batch_operation = dossier.batch_operation.present?
respond_to do |format|
format.pdf do
@acls = PiecesJustificativesService.new(user_profile: current_instructeur).acl_for_dossier_export(dossier.procedure)
@acls = PiecesJustificativesService.new(user_profile: current_instructeur, export_template: nil).acl_for_dossier_export(dossier.procedure)
render(template: 'dossiers/show', formats: [:pdf])
end
format.all
Expand Down
100 changes: 100 additions & 0 deletions app/controllers/instructeurs/export_templates_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
module Instructeurs
class ExportTemplatesController < InstructeurController
before_action :set_procedure
before_action :set_groupe_instructeur, only: [:create, :update]
before_action :set_export_template, only: [:edit, :update, :destroy]
before_action :set_groupe_instructeurs
before_action :set_all_pj

def new
@export_template = ExportTemplate.new(kind: 'zip', groupe_instructeur: @groupe_instructeurs.first)
@export_template.set_default_values
end

def create
@export_template = @groupe_instructeur.export_templates.build(export_template_params)
@export_template.assign_pj_names(pj_params)
if @export_template.save
redirect_to exports_instructeur_procedure_path(procedure: @procedure), notice: "Le modèle d'export #{@export_template.name} a bien été créé"
else
flash[:alert] = @export_template.errors.full_messages
render :new
end
end

def edit
end

def update
@export_template.assign_attributes(export_template_params)
@export_template.groupe_instructeur = @groupe_instructeur
@export_template.assign_pj_names(pj_params)
if @export_template.save
redirect_to exports_instructeur_procedure_path(procedure: @procedure), notice: "Le modèle d'export #{@export_template.name} a bien été modifié"
else
flash[:alert] = @export_template.errors.full_messages
render :edit
end
end

def destroy
if @export_template.destroy
redirect_to exports_instructeur_procedure_path(procedure: @procedure), notice: "Le modèle d'export #{@export_template.name} a bien été supprimé"
else
redirect_to exports_instructeur_procedure_path(procedure: @procedure), alert: "Le modèle d'export #{@export_template.name} n'a pu être supprimé"
end
end

def preview
set_groupe_instructeur
@export_template = @groupe_instructeur.export_templates.build(export_template_params)
@export_template.assign_pj_names(pj_params)

@sample_dossier = @procedure.dossier_for_preview(current_instructeur)

render turbo_stream: turbo_stream.replace('preview', partial: 'preview', locals: { export_template: @export_template, procedure: @procedure, dossier: @sample_dossier })
end

private

def export_template_params
params.require(:export_template).permit(*export_params)
end

def set_procedure
@procedure = current_instructeur.procedures.find params[:procedure_id]
Sentry.configure_scope do |scope|
scope.set_tags(procedure: @procedure.id)
end
end

def set_export_template
@export_template = current_instructeur.export_templates.find(params[:id])
end

def set_groupe_instructeur
@groupe_instructeur = @procedure.groupe_instructeurs.find(params.require(:export_template)[:groupe_instructeur_id])
end

def set_groupe_instructeurs
@groupe_instructeurs = current_instructeur.groupe_instructeurs.where(procedure: @procedure)
end

def set_all_pj
@all_pj ||= @procedure.exportables_pieces_jointes
end

def export_params
[:name, :kind, :tiptap_default_dossier_directory, :tiptap_pdf_name]
end

def pj_params
@procedure = current_instructeur.procedures.find params[:procedure_id]
pj_params = []
@all_pj.each do |pj|
pj_params << "tiptap_pj_#{pj.stable_id}".to_sym
end
params.require(:export_template).permit(*pj_params)
end
end
end
8 changes: 7 additions & 1 deletion app/controllers/instructeurs/procedures_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ def stats
def exports
@procedure = procedure
@exports = Export.for_groupe_instructeurs(groupe_instructeur_ids).ante_chronological
@export_templates = current_instructeur.export_templates_for(@procedure).includes(:groupe_instructeur)
cookies.encrypted[cookies_export_key] = {
value: DateTime.current,
expires: Export::MAX_DUREE_GENERATION + Export::MAX_DUREE_CONSERVATION_EXPORT
Expand Down Expand Up @@ -324,13 +325,18 @@ def statut
end

def export_format
@export_format ||= params[:export_format]
@export_format ||= params[:export_format].presence || export_template&.kind
end

def export_template
@export_template ||= ExportTemplate.find(params[:export_template_id]) if params[:export_template_id].present?
end

def export_options
@export_options ||= {
time_span_type: params[:time_span_type],
statut: params[:statut],
export_template:,
procedure_presentation: params[:statut].present? ? procedure_presentation : nil
}.compact
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/users/dossiers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def index
end

def show
pj_service = PiecesJustificativesService.new(user_profile: current_user)
pj_service = PiecesJustificativesService.new(user_profile: current_user, export_template: nil)
respond_to do |format|
format.pdf do
@dossier = dossier_with_champs(pj_template: false)
Expand Down
11 changes: 8 additions & 3 deletions app/lib/active_storage/downloadable_file.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
require 'fog/openstack'

class ActiveStorage::DownloadableFile
def self.create_list_from_dossiers(dossiers:, user_profile:)
pj_service = PiecesJustificativesService.new(user_profile:)
def self.create_list_from_dossiers(dossiers:, user_profile:, export_template: nil)
pj_service = PiecesJustificativesService.new(user_profile:, export_template:)

pj_service.generate_dossiers_export(dossiers) + pj_service.liste_documents(dossiers)
files = []
DossierPreloader.new(dossiers).in_batches_with_block do |loaded_dossiers|
files += pj_service.generate_dossiers_export(loaded_dossiers) + pj_service.liste_documents(loaded_dossiers)
end

files
end

def self.cleanup_list_from_dossier(files)
Expand Down
2 changes: 1 addition & 1 deletion app/lib/recovery/exporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def initialize(dossier_ids:, file_path: FILE_PATH)
etablissement: :exercices,
revision: :procedure)
@dossiers = DossierPreloader.new(dossier_with_data,
includes_for_dossier: [:geo_areas, etablissement: :exercices],
includes_for_champ: [:geo_areas, etablissement: :exercices],
includes_for_etablissement: [:exercices]).all
@file_path = file_path
end
Expand Down
4 changes: 4 additions & 0 deletions app/models/champ.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ def child?
parent_id.present?
end

def stable_id_with_row
[row_id, stable_id].compact
end

# used for the `required` html attribute
# check visibility to avoid hidden required input
# which prevent the form from being sent.
Expand Down
Loading

0 comments on commit 2761d18

Please sign in to comment.