Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ETQ instructeur, je peux renommer le contenu de mon export zip #10217

Merged
merged 59 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
93ad0f4
[tiptap] convert tiptap json to path
krichtof Mar 2, 2024
474eb18
add export template migration
krichtof Mar 2, 2024
d1c3b84
add export template model
krichtof Mar 2, 2024
2492260
add pj for export template
krichtof Mar 3, 2024
25ab242
validate export template
krichtof Mar 3, 2024
bbb6309
procedure: add pieces_jointes_exportables_list
krichtof Mar 3, 2024
dbf46b1
extract DOSSIER_ID_TAG
krichtof Mar 3, 2024
a248eba
export template: set default values
krichtof Mar 3, 2024
95c308d
add specific tags
krichtof Mar 3, 2024
f5813b4
create and update export templates
krichtof Mar 3, 2024
a12d6b4
preview content export
krichtof Mar 3, 2024
7661b8b
add export_template to exports
krichtof Mar 8, 2024
7a39752
rename root directory in zip export
krichtof Mar 22, 2024
357c074
generate export with export_template
krichtof Mar 8, 2024
2a4bfdd
can use export template from export_dropdown_component
krichtof Mar 8, 2024
fd9335f
style editor tags
krichtof Mar 11, 2024
5aac2ec
rename editor css class
krichtof Mar 11, 2024
4a79ecf
add new export template link
krichtof Mar 12, 2024
be0c031
use export template for admin archives
krichtof Mar 12, 2024
93f1fd5
add export template lists
krichtof Mar 12, 2024
2c28d97
destroy export_template
krichtof Mar 12, 2024
43c862e
list export templates for groupes instructeur of current instructeur
krichtof Mar 13, 2024
9f715e8
add i18n for export template
krichtof Mar 15, 2024
8e8057d
add some specs to export template
krichtof Mar 20, 2024
aeb4bd2
add original-filename tag
krichtof Mar 19, 2024
565f6f4
make private some methods
krichtof Mar 20, 2024
4e1552a
add sample messagerie in preview
krichtof Mar 21, 2024
40d7b81
add some explanations for export template
krichtof Mar 26, 2024
213522f
remove useless tiptap controller
krichtof Mar 29, 2024
cec73e0
move preview to be aligned with form
krichtof Apr 5, 2024
e235131
add export template feature flag
krichtof Apr 9, 2024
6445337
refactor(pj_list): extract pj list in a concern and simplify
LeSim Apr 26, 2024
c8b3b4b
refactor: renaming
LeSim Apr 26, 2024
2dffa9a
refactor: extract preview
LeSim Apr 29, 2024
4a900d8
refactor(UI): add file extension and number to preview
LeSim Apr 30, 2024
c51792b
refactor(UI): move extension warning near pjs
LeSim Apr 30, 2024
1b734ae
refactor: simplify preview
LeSim Apr 29, 2024
6d757db
fix: champ.row_index and test pjs_for_champs
LeSim Apr 30, 2024
b656867
refactor(pj_service): do not query for pj_index
LeSim May 1, 2024
5858105
refactor(suffix): be consistent with index suffix
LeSim May 1, 2024
fe5c655
spec(perf): count sql queries for 10 dossiers
LeSim May 7, 2024
43fb1dd
refactor: remove target in tags
LeSim May 14, 2024
1c0bd3e
refactor: remove unused data
LeSim May 14, 2024
3af1cee
refactor: simplify
LeSim May 14, 2024
e0c867f
refactor: rename
LeSim May 14, 2024
d60e790
refactor: memoize flat_tags
LeSim May 14, 2024
4205204
refactor(tags_substitution): simplify
LeSim May 15, 2024
e8a175d
refactor: be explicite with memoization
LeSim May 15, 2024
080bcd8
refactor: DossierPreloader rename includes_for_dossier -> includes_fo…
LeSim May 15, 2024
fa7d5cf
fix test
LeSim May 15, 2024
9effa9e
perf(zip): preload_dossier earlier
LeSim May 17, 2024
a7e29c4
perf(spec): new count !
LeSim May 17, 2024
ca12a56
perf(zip): give champ to avoid seeking stable_id
LeSim May 17, 2024
6184b33
perf(preloader): preloader use batch for batches
LeSim May 17, 2024
8628ec1
perf(spec): new record !
LeSim May 17, 2024
e38999e
perf(pj service): compute row_id without extraneous requests
LeSim May 18, 2024
d3b7003
spec: fix
LeSim May 21, 2024
4fb03e3
fix: remove useless code
krichtof May 22, 2024
0869168
spec: test champs_id_row_index
LeSim May 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

Check warning on line 11 in app/controllers/instructeurs/export_templates_controller.rb

View check run for this annotation

Codecov / codecov/patch

app/controllers/instructeurs/export_templates_controller.rb#L10-L11

Added lines #L10 - L11 were not covered by tests
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)

Check warning on line 51 in app/controllers/instructeurs/export_templates_controller.rb

View check run for this annotation

Codecov / codecov/patch

app/controllers/instructeurs/export_templates_controller.rb#L49-L51

Added lines #L49 - L51 were not covered by tests

@sample_dossier = @procedure.dossier_for_preview(current_instructeur)

Check warning on line 53 in app/controllers/instructeurs/export_templates_controller.rb

View check run for this annotation

Codecov / codecov/patch

app/controllers/instructeurs/export_templates_controller.rb#L53

Added line #L53 was not covered by tests

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

Check warning on line 55 in app/controllers/instructeurs/export_templates_controller.rb

View check run for this annotation

Codecov / codecov/patch

app/controllers/instructeurs/export_templates_controller.rb#L55

Added line #L55 was not covered by tests
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

Check warning on line 95 in app/controllers/instructeurs/export_templates_controller.rb

View check run for this annotation

Codecov / codecov/patch

app/controllers/instructeurs/export_templates_controller.rb#L95

Added line #L95 was not covered by tests
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 @@
parent_id.present?
end

def stable_id_with_row
[row_id, stable_id].compact

Check warning on line 95 in app/models/champ.rb

View check run for this annotation

Codecov / codecov/patch

app/models/champ.rb#L95

Added line #L95 was not covered by tests
end

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