Merge pull request #7674 from betagouv/fix_pj_template
fix(editeur_de_champ): permet d'ajouter à nouveau un template au pjs
This commit is contained in:
commit
15e623fd3d
5 changed files with 31 additions and 3 deletions
|
@ -31,6 +31,19 @@ module Administrateurs
|
|||
end
|
||||
end
|
||||
|
||||
def piece_justificative_template
|
||||
type_de_champ = draft.find_and_ensure_exclusive_use(params[:stable_id])
|
||||
|
||||
if type_de_champ.piece_justificative_template.attach(params[:blob_signed_id])
|
||||
@coordinate = draft.coordinate_for(type_de_champ)
|
||||
@morphed = [champ_component_from(@coordinate)]
|
||||
|
||||
render :create
|
||||
else
|
||||
render json: { errors: @champ.errors.full_messages }, status: 422
|
||||
end
|
||||
end
|
||||
|
||||
def move
|
||||
flash.notice = "Formulaire enregistré"
|
||||
draft.move_type_de_champ(params[:stable_id], params[:position].to_i)
|
||||
|
@ -95,7 +108,6 @@ module Administrateurs
|
|||
:drop_down_other,
|
||||
:drop_down_secondary_libelle,
|
||||
:drop_down_secondary_description,
|
||||
:piece_justificative_template,
|
||||
editable_options: [
|
||||
:cadastres,
|
||||
:unesco,
|
||||
|
|
|
@ -23,6 +23,8 @@ module ChampHelper
|
|||
def auto_attach_url(object)
|
||||
if object.is_a?(Champ)
|
||||
champs_piece_justificative_url(object.id)
|
||||
elsif object.is_a?(TypeDeChamp)
|
||||
piece_justificative_template_admin_procedure_type_de_champ_url(stable_id: object.stable_id, procedure_id: object.procedure.id)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ import {
|
|||
isTextInputElement
|
||||
} from '@utils';
|
||||
import { useIntersection } from 'stimulus-use';
|
||||
|
||||
import { AutoUpload } from '../shared/activestorage/auto-upload';
|
||||
import { ApplicationController } from './application_controller';
|
||||
|
||||
export class TypeDeChampEditorController extends ApplicationController {
|
||||
|
@ -71,7 +71,7 @@ export class TypeDeChampEditorController extends ApplicationController {
|
|||
}
|
||||
|
||||
private onInput(event: Event) {
|
||||
const target = event.target as HTMLElement & { form?: HTMLFormElement };
|
||||
const target = event.target as HTMLInputElement;
|
||||
|
||||
// mark input as touched so we know to not overwrite it's value with next re-render
|
||||
target.setAttribute('data-touched', 'true');
|
||||
|
@ -79,6 +79,9 @@ export class TypeDeChampEditorController extends ApplicationController {
|
|||
if (target.form && isTextInputElement(target)) {
|
||||
this.#dirtyForms.add(target.form);
|
||||
this.debounce(this.save, 600);
|
||||
} else if (target.form && target.type == 'file' && target.files?.length) {
|
||||
const autoupload = new AutoUpload(target, target.files[0]);
|
||||
autoupload.start();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -484,6 +484,7 @@ Rails.application.routes.draw do
|
|||
patch :move
|
||||
patch :move_up
|
||||
patch :move_down
|
||||
put :piece_justificative_template
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -14,6 +14,16 @@ describe 'As an administrateur I can edit types de champ', js: true do
|
|||
expect(page).to have_content('Formulaire enregistré')
|
||||
end
|
||||
|
||||
scenario "adding a piece justificative template" do
|
||||
add_champ
|
||||
select('Pièce justificative', from: 'Type de champ')
|
||||
|
||||
find('.attachment input[type=file]').attach_file(Rails.root + 'spec/fixtures/files/file.pdf')
|
||||
|
||||
# Expect the files to be uploaded immediately
|
||||
expect(page).to have_text('file.pdf')
|
||||
end
|
||||
|
||||
scenario "adding multiple champs" do
|
||||
# Champs are created when clicking the 'Add field' button
|
||||
add_champs(count: 3)
|
||||
|
|
Loading…
Add table
Reference in a new issue