Skip to content

Commit

Permalink
Merge pull request #10465 from colinux/attestations-v2-prod
Browse files Browse the repository at this point in the history
ETQ admin je peux activer la délivrance des attestations v2 (sous feature flag)
  • Loading branch information
colinux authored Jun 24, 2024
2 parents 5ac2315 + 617c0e4 commit ccf5b25
Show file tree
Hide file tree
Showing 42 changed files with 722 additions and 256 deletions.
30 changes: 0 additions & 30 deletions app/assets/stylesheets/forms.scss
Original file line number Diff line number Diff line change
Expand Up @@ -623,40 +623,10 @@ textarea::placeholder {
color: $dark-grey;
}

@media (max-width: 62em) {

.padded-fixed-footer {
padding-top: 120px;
}
}

@media (min-width: 62em) {

.padded-fixed-footer {
padding-top: 60px;
}
}

[data-fr-theme="dark"] .fixed-footer {
border-top: 2px solid var(--background-action-low-blue-france-hover);
background-color: var(--background-action-low-blue-france);
}

.mandatory {
fill: currentColor;
}

.fixed-footer {
border-top: 2px solid $blue-france-500;
position: fixed;
bottom: 0;
left: 0;
right: 0;
padding-top: $default-padding;
background-color: $white;
z-index: 2;
}

.fr-menu__list {
padding: $default-spacer;
overflow-y: auto;
Expand Down
49 changes: 49 additions & 0 deletions app/assets/stylesheets/sticky.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
@import "constants";

.fixed-footer {
border-top: 2px solid var(--border-plain-blue-france);
position: fixed;
bottom: 0;
left: 0;
right: 0;
padding-top: $default-padding;
background-color: var(--background-default-grey);
z-index: 2;
}

@media (max-width: 62em) {
.padded-fixed-footer {
padding-top: 120px;
}
}

@media (min-width: 62em) {
.padded-fixed-footer {
padding-top: 60px;
}
}

[data-fr-theme="dark"] .fixed-footer {
background-color: var(--background-action-low-blue-france);
}

.sticky-header {
padding-top: $default-padding;
padding-bottom: $default-padding;

&-container {
position: sticky;
top: 0;
left: 0;
right: 0;
z-index: 800;
}

&-warning {
background-color: var(--background-contrast-warning);
}

p {
margin: 0;
}
}
16 changes: 16 additions & 0 deletions app/components/autosave_notice_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

class AutosaveNoticeComponent < ApplicationComponent
attr_reader :label_scope

def initialize(success:, label_scope:)
@success = success
@label_scope = label_scope
end

def success? = @success

def label
success? ? t(".#{label_scope}.saved") : t(".#{label_scope}.error")
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
en:
form:
saved: 'Form saved'
error: 'Form in error'
attestation:
saved: 'Attestation saved'
error: 'Attestation in error'
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
fr:
form:
saved: 'Formulaire enregistré'
error: 'Formulaire en erreur'
attestation:
saved: 'Attestation enregistrée'
error: 'Attestation en erreur'
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#autosave-notice.fr-badge.fr-badge--sm{ class: class_names("fr-badge--success" => success?, "fr-badge--error" => !success?) }
= label
2 changes: 2 additions & 0 deletions app/components/dsfr/callout_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def theme_class
"fr-callout--brown-caramel"
when :success
"fr-callout--green-emeraude"
when :neutral
# default
else
"fr-background-alt--blue-france"
end
Expand Down
4 changes: 1 addition & 3 deletions app/components/dsfr/input_errorable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,7 @@ def input_opts(other_opts = {})
})
end

if autoresize?
@opts.deep_merge!(data: { controller: 'autoresize' })
end
@opts.deep_merge!(data: { controller: token_list(@opts.dig(:data, :controller), 'autoresize' => autoresize?) })

@opts
end
Expand Down
8 changes: 8 additions & 0 deletions app/components/procedure/card/attestation_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ def initialize(procedure:)

private

def edit_attestation_path
if @procedure.attestation_templates_v2.any? || @procedure.feature_enabled?(:attestation_v2)
helpers.edit_admin_procedure_attestation_template_v2_path(@procedure)
else
helpers.edit_admin_procedure_attestation_template_path(@procedure)
end
end

def error_messages
@procedure.errors.messages_for(:attestation_template).to_sentence
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.fr-col-6.fr-col-md-4.fr-col-lg-3
= link_to edit_admin_procedure_attestation_template_path(@procedure), class: 'fr-tile fr-enlarge-link' do
= link_to edit_attestation_path, class: 'fr-tile fr-enlarge-link' do
.fr-tile__body.flex.column.align-center.justify-between
- if @procedure.attestation_template&.activated?
%div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,9 @@ def show
format.pdf do
html = render_to_string('/administrateurs/attestation_template_v2s/show', layout: 'attestation', formats: [:html])

headers = {
'Content-Type' => 'application/json',
'X-Request-Id' => Current.request_id
}

body = {
html: html,
upstream_context: {
procedure_id: @procedure.id,
path: request.path,
user_id: current_user.id
}
}.to_json

response = Typhoeus.post(WEASYPRINT_URL, headers:, body:)

if response.success?
send_data(response.body, filename: 'attestation.pdf', type: 'application/pdf', disposition: 'inline')
else
raise StandardError.new("PDF Generation failed: #{response.return_code} #{response.status_message}")
end
pdf = WeasyprintService.generate_pdf(html, procedure_id: @procedure.id, path: request.path, user_id: current_user.id)

send_data(pdf, filename: 'attestation.pdf', type: 'application/pdf', disposition: 'inline')
end
end
end
Expand Down Expand Up @@ -77,6 +59,19 @@ def edit

def update
attestation_params = editor_params

# toggle activation
if @attestation_template.persisted? && @attestation_template.activated? != cast_bool(attestation_params[:activated])
@procedure.attestation_templates.v2.update_all(activated: attestation_params[:activated])
render :update && return
end

if @attestation_template.published? && should_edit_draft?
@attestation_template = @attestation_template.dup
@attestation_template.state = :draft
@attestation_template.procedure = @procedure
end

logo_file = attestation_params.delete(:logo)
signature_file = attestation_params.delete(:signature)

Expand All @@ -88,27 +83,60 @@ def update
attestation_params[:signature] = uninterlace_png(signature_file)
end

if !@attestation_template.update(attestation_params)
flash.alert = "Le modèle de l’attestation contient des erreurs et n'a pas pu être enregistré. Corriger les erreurs."
end
@attestation_template.assign_attributes(attestation_params)

render :update
if @attestation_template.invalid?
flash.alert = "L’attestation contient des erreurs et n'a pas pu être enregistrée. Corriger les erreurs."
else
# - draft just published
if @attestation_template.published? && should_edit_draft?
published = @procedure.attestation_templates.published

@attestation_template.transaction do
were_published = published.destroy_all
@attestation_template.save!
flash.notice = were_published.any? ? "La nouvelle version de l’attestation a été publiée." : "L’attestation a été publiée."
end

redirect_to edit_admin_procedure_attestation_template_v2_path(@procedure)
else
# - draft updated
# - or, attestation already published, without need for publication (draft procedure)
@attestation_template.save!
render :update
end
end
end

def create = update

def reset
@procedure.attestation_templates_v2.draft&.destroy_all

flash.notice = "Les modifications ont été réinitialisées."
redirect_to edit_admin_procedure_attestation_template_v2_path(@procedure)
end

private

def ensure_feature_active
redirect_to root_path if !@procedure.feature_enabled?(:attestation_v2)
end

def retrieve_attestation_template
@attestation_template = @procedure.attestation_template_v2 || @procedure.build_attestation_template_v2(json_body: AttestationTemplate::TIPTAP_BODY_DEFAULT)
v2s = @procedure.attestation_templates_v2
@attestation_template = v2s.find(&:draft?) || v2s.find(&:published?) || build_default_attestation
end

def build_default_attestation
state = should_edit_draft? ? :draft : :published
@procedure.build_attestation_template(version: 2, json_body: AttestationTemplate::TIPTAP_BODY_DEFAULT, activated: true, state:)
end

def should_edit_draft? = !@procedure.brouillon?

def editor_params
params.required(:attestation_template).permit(:official_layout, :label_logo, :label_direction, :tiptap_body, :footer, :logo, :signature, :activated)
params.required(:attestation_template).permit(:activated, :official_layout, :label_logo, :label_direction, :tiptap_body, :footer, :logo, :signature, :activated, :state)
end
end
end
2 changes: 1 addition & 1 deletion app/controllers/administrateurs/procedures_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def show
revision_types_de_champ: { type_de_champ: { piece_justificative_template_attachment: :blob } }
},
attestation_template_v1: [],
attestation_template_v2: [],
attestation_templates_v2: [],
initiated_mail: [],
received_mail: [],
closed_mail: [],
Expand Down
7 changes: 4 additions & 3 deletions app/controllers/instructeurs/dossiers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ def geo_data
end

def apercu_attestation
@attestation = dossier.attestation_template.render_attributes_for(dossier: dossier)

render 'administrateurs/attestation_templates/show', formats: [:pdf]
send_data dossier.attestation_template.send(:build_pdf, dossier),
filename: 'attestation.pdf',
type: 'application/pdf',
disposition: 'inline'
end

def bilans_bdf
Expand Down
43 changes: 43 additions & 0 deletions app/javascript/controllers/sticky_top_controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { ApplicationController } from './application_controller';

export class StickyTopController extends ApplicationController {
// Ajusts top of sticky top components when there is a sticky header.

connect(): void {
const header = document.getElementById('sticky-header');

if (!header) {
return;
}

this.adjustTop(header);

window.addEventListener('resize', () => this.adjustTop(header));

this.listenHeaderMutations(header);
}

private listenHeaderMutations(header: HTMLElement) {
const config = { childList: true, subtree: true };

const callback: MutationCallback = (mutationsList) => {
for (const mutation of mutationsList) {
if (mutation.type === 'childList') {
this.adjustTop(header);
break;
}
}
};

const observer = new MutationObserver(callback);
observer.observe(header, config);
}

private adjustTop(header: HTMLElement) {
const headerHeight = header.clientHeight;

if (headerHeight > 0) {
(this.element as HTMLElement).style.top = `${headerHeight + 8}px`;
}
}
}
Loading

0 comments on commit ccf5b25

Please sign in to comment.