Merge pull request #7094 from tchak/feat-persisted-preview
feat(dossier): use real dossier for preview
This commit is contained in:
commit
be2318b128
16 changed files with 69 additions and 42 deletions
|
@ -44,7 +44,7 @@ module Administrateurs
|
||||||
end
|
end
|
||||||
|
|
||||||
def apercu
|
def apercu
|
||||||
@dossier = procedure_without_control.draft_revision.new_dossier
|
@dossier = procedure_without_control.draft_revision.dossier_for_preview(current_user)
|
||||||
@tab = apercu_tab
|
@tab = apercu_tab
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -45,11 +45,9 @@ class Champs::SiretController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_etablisement
|
def find_etablisement
|
||||||
if params[:champ_id].present?
|
@champ = policy_scope(Champ).find(params[:champ_id])
|
||||||
@champ = policy_scope(Champ).find(params[:champ_id])
|
@etablissement = @champ.etablissement
|
||||||
@etablissement = @champ&.etablissement
|
@procedure_id = @champ.dossier.procedure.id
|
||||||
end
|
|
||||||
@procedure_id = @champ&.dossier&.procedure&.id || 'aperçu'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_etablissement_with_siret
|
def find_etablissement_with_siret
|
||||||
|
@ -57,7 +55,7 @@ class Champs::SiretController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def clear_siret_and_etablissement
|
def clear_siret_and_etablissement
|
||||||
@champ&.update!(value: '')
|
@champ.update!(value: '')
|
||||||
@etablissement&.destroy
|
@etablissement&.destroy
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -62,7 +62,7 @@ module ApplicationHelper
|
||||||
|
|
||||||
def render_champ(champ)
|
def render_champ(champ)
|
||||||
champ_selector = "##{champ.input_group_id}"
|
champ_selector = "##{champ.input_group_id}"
|
||||||
form_html = render 'shared/dossiers/edit', dossier: champ.dossier, apercu: false
|
form_html = render 'shared/dossiers/edit', dossier: champ.dossier
|
||||||
champ_html = Nokogiri::HTML.fragment(form_html).at_css(champ_selector).to_s
|
champ_html = Nokogiri::HTML.fragment(form_html).at_css(champ_selector).to_s
|
||||||
# rubocop:disable Rails/OutputSafety
|
# rubocop:disable Rails/OutputSafety
|
||||||
raw("document.querySelector('#{champ_selector}').outerHTML = \"#{escape_javascript(champ_html)}\";")
|
raw("document.querySelector('#{champ_selector}').outerHTML = \"#{escape_javascript(champ_html)}\";")
|
||||||
|
|
|
@ -23,7 +23,7 @@ export type DeleteFeatures = (params: {
|
||||||
|
|
||||||
export function useFeatureCollection(
|
export function useFeatureCollection(
|
||||||
initialFeatureCollection: FeatureCollection,
|
initialFeatureCollection: FeatureCollection,
|
||||||
{ url, enabled = true }: { url: string; enabled: boolean }
|
{ url }: { url: string }
|
||||||
) {
|
) {
|
||||||
const [error, onError] = useError();
|
const [error, onError] = useError();
|
||||||
const [featureCollection, setFeatureCollection] = useState(
|
const [featureCollection, setFeatureCollection] = useState(
|
||||||
|
@ -96,9 +96,6 @@ export function useFeatureCollection(
|
||||||
source = SOURCE_SELECTION_UTILISATEUR,
|
source = SOURCE_SELECTION_UTILISATEUR,
|
||||||
external = false
|
external = false
|
||||||
}) => {
|
}) => {
|
||||||
if (!enabled) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
const newFeatures: Feature[] = [];
|
const newFeatures: Feature[] = [];
|
||||||
for (const feature of features) {
|
for (const feature of features) {
|
||||||
|
@ -117,7 +114,7 @@ export function useFeatureCollection(
|
||||||
onError('Le polygone dessiné n’est pas valide.');
|
onError('Le polygone dessiné n’est pas valide.');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[enabled, url, updateFeatureCollection, addFeatures, onError]
|
[url, updateFeatureCollection, addFeatures, onError]
|
||||||
);
|
);
|
||||||
|
|
||||||
const updateFeatures = useCallback<UpdateFatures>(
|
const updateFeatures = useCallback<UpdateFatures>(
|
||||||
|
@ -126,9 +123,6 @@ export function useFeatureCollection(
|
||||||
source = SOURCE_SELECTION_UTILISATEUR,
|
source = SOURCE_SELECTION_UTILISATEUR,
|
||||||
external = false
|
external = false
|
||||||
}) => {
|
}) => {
|
||||||
if (!enabled) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
const newFeatures: Feature[] = [];
|
const newFeatures: Feature[] = [];
|
||||||
for (const feature of features) {
|
for (const feature of features) {
|
||||||
|
@ -154,14 +148,11 @@ export function useFeatureCollection(
|
||||||
onError('Le polygone dessiné n’est pas valide.');
|
onError('Le polygone dessiné n’est pas valide.');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[enabled, url, updateFeatureCollection, addFeatures, onError]
|
[url, updateFeatureCollection, addFeatures, onError]
|
||||||
);
|
);
|
||||||
|
|
||||||
const deleteFeatures = useCallback<DeleteFeatures>(
|
const deleteFeatures = useCallback<DeleteFeatures>(
|
||||||
async ({ features, external = false }) => {
|
async ({ features, external = false }) => {
|
||||||
if (!enabled) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
const deletedFeatures = [];
|
const deletedFeatures = [];
|
||||||
for (const feature of features) {
|
for (const feature of features) {
|
||||||
|
@ -183,7 +174,7 @@ export function useFeatureCollection(
|
||||||
onError('Le polygone n’a pas pu être supprimé.');
|
onError('Le polygone n’a pas pu être supprimé.');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[enabled, url, updateFeatureCollection, removeFeatures, onError]
|
[url, updateFeatureCollection, removeFeatures, onError]
|
||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -16,19 +16,17 @@ import { FlashMessage } from '../shared/FlashMessage';
|
||||||
export default function MapEditor({
|
export default function MapEditor({
|
||||||
featureCollection: initialFeatureCollection,
|
featureCollection: initialFeatureCollection,
|
||||||
url,
|
url,
|
||||||
options,
|
options
|
||||||
preview
|
|
||||||
}: {
|
}: {
|
||||||
featureCollection: FeatureCollection;
|
featureCollection: FeatureCollection;
|
||||||
url: string;
|
url: string;
|
||||||
preview: boolean;
|
|
||||||
options: { layers: string[] };
|
options: { layers: string[] };
|
||||||
}) {
|
}) {
|
||||||
const [cadastreEnabled, setCadastreEnabled] = useState(false);
|
const [cadastreEnabled, setCadastreEnabled] = useState(false);
|
||||||
|
|
||||||
const { featureCollection, error, ...actions } = useFeatureCollection(
|
const { featureCollection, error, ...actions } = useFeatureCollection(
|
||||||
initialFeatureCollection,
|
initialFeatureCollection,
|
||||||
{ url, enabled: !preview }
|
{ url }
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -54,14 +52,14 @@ export default function MapEditor({
|
||||||
<DrawLayer
|
<DrawLayer
|
||||||
featureCollection={featureCollection}
|
featureCollection={featureCollection}
|
||||||
{...actions}
|
{...actions}
|
||||||
enabled={!preview && !cadastreEnabled}
|
enabled={!cadastreEnabled}
|
||||||
/>
|
/>
|
||||||
{options.layers.includes('cadastres') ? (
|
{options.layers.includes('cadastres') ? (
|
||||||
<>
|
<>
|
||||||
<CadastreLayer
|
<CadastreLayer
|
||||||
featureCollection={featureCollection}
|
featureCollection={featureCollection}
|
||||||
{...actions}
|
{...actions}
|
||||||
enabled={!preview && cadastreEnabled}
|
enabled={cadastreEnabled}
|
||||||
/>
|
/>
|
||||||
<div className="cadastres-selection-control mapboxgl-ctrl-group">
|
<div className="cadastres-selection-control mapboxgl-ctrl-group">
|
||||||
<button
|
<button
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
# last_commentaire_updated_at :datetime
|
# last_commentaire_updated_at :datetime
|
||||||
# motivation :text
|
# motivation :text
|
||||||
# private_search_terms :text
|
# private_search_terms :text
|
||||||
|
# for_procedure_preview :boolean
|
||||||
# processed_at :datetime
|
# processed_at :datetime
|
||||||
# search_terms :text
|
# search_terms :text
|
||||||
# state :string
|
# state :string
|
||||||
|
@ -205,13 +206,14 @@ class Dossier < ApplicationRecord
|
||||||
scope :not_archived, -> { where(archived: false) }
|
scope :not_archived, -> { where(archived: false) }
|
||||||
scope :hidden_by_user, -> { where.not(hidden_by_user_at: nil) }
|
scope :hidden_by_user, -> { where.not(hidden_by_user_at: nil) }
|
||||||
scope :hidden_by_administration, -> { where.not(hidden_by_administration_at: nil) }
|
scope :hidden_by_administration, -> { where.not(hidden_by_administration_at: nil) }
|
||||||
scope :visible_by_user, -> { where(hidden_by_user_at: nil) }
|
scope :visible_by_user, -> { where(for_procedure_preview: false).or(where(for_procedure_preview: nil)).where(hidden_by_user_at: nil) }
|
||||||
scope :visible_by_administration, -> {
|
scope :visible_by_administration, -> {
|
||||||
state_not_brouillon
|
state_not_brouillon
|
||||||
.where(hidden_by_administration_at: nil)
|
.where(hidden_by_administration_at: nil)
|
||||||
.merge(visible_by_user.or(state_not_en_construction))
|
.merge(visible_by_user.or(state_not_en_construction))
|
||||||
}
|
}
|
||||||
scope :visible_by_user_or_administration, -> { visible_by_user.or(visible_by_administration) }
|
scope :visible_by_user_or_administration, -> { visible_by_user.or(visible_by_administration) }
|
||||||
|
scope :for_procedure_preview, -> { where(for_procedure_preview: true) }
|
||||||
|
|
||||||
scope :order_by_updated_at, -> (order = :desc) { order(updated_at: order) }
|
scope :order_by_updated_at, -> (order = :desc) { order(updated_at: order) }
|
||||||
scope :order_by_created_at, -> (order = :asc) { order(depose_at: order, created_at: order, id: order) }
|
scope :order_by_created_at, -> (order = :asc) { order(depose_at: order, created_at: order, id: order) }
|
||||||
|
@ -542,7 +544,7 @@ class Dossier < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def can_transition_to_en_construction?
|
def can_transition_to_en_construction?
|
||||||
brouillon? && procedure.dossier_can_transition_to_en_construction?
|
brouillon? && procedure.dossier_can_transition_to_en_construction? && !for_procedure_preview?
|
||||||
end
|
end
|
||||||
|
|
||||||
def can_repasser_en_instruction?
|
def can_repasser_en_instruction?
|
||||||
|
@ -1244,7 +1246,7 @@ class Dossier < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def send_draft_notification_email
|
def send_draft_notification_email
|
||||||
if brouillon? && !procedure.declarative?
|
if brouillon? && !procedure.declarative? && !for_procedure_preview?
|
||||||
DossierMailer.notify_new_draft(self).deliver_later
|
DossierMailer.notify_new_draft(self).deliver_later
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -132,6 +132,19 @@ class ProcedureRevision < ApplicationRecord
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def dossier_for_preview(user)
|
||||||
|
dossier = Dossier
|
||||||
|
.create_with(groupe_instructeur: procedure.defaut_groupe_instructeur_for_new_dossier)
|
||||||
|
.find_or_initialize_by(revision: self, user: user, for_procedure_preview: true, state: Dossier.states.fetch(:brouillon))
|
||||||
|
|
||||||
|
if dossier.new_record?
|
||||||
|
dossier.build_default_individual
|
||||||
|
dossier.save!
|
||||||
|
end
|
||||||
|
|
||||||
|
dossier
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def compare_attestation_template(from_at, to_at)
|
def compare_attestation_template(from_at, to_at)
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
active: @tab == 'annotations-privees')
|
active: @tab == 'annotations-privees')
|
||||||
|
|
||||||
- if @tab == 'dossier'
|
- if @tab == 'dossier'
|
||||||
= render partial: "shared/dossiers/edit", locals: { dossier: @dossier, apercu: true }
|
= render partial: "shared/dossiers/edit", locals: { dossier: @dossier }
|
||||||
- else
|
- else
|
||||||
.container
|
.container
|
||||||
= form_for @dossier, url: '', method: :get, html: { class: 'form' } do |f|
|
= form_for @dossier, url: '', method: :get, html: { class: 'form' } do |f|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
.dossier-edit.container
|
.dossier-edit.container
|
||||||
= render partial: "shared/dossiers/submit_is_over", locals: { dossier: dossier }
|
= render partial: "shared/dossiers/submit_is_over", locals: { dossier: dossier }
|
||||||
|
|
||||||
- if apercu
|
- if dossier.for_procedure_preview?
|
||||||
- form_options = { url: '', method: :get }
|
- form_options = { url: '', method: :get }
|
||||||
- elsif dossier.brouillon?
|
- elsif dossier.brouillon?
|
||||||
- form_options = { url: brouillon_dossier_url(dossier), method: :patch }
|
- form_options = { url: brouillon_dossier_url(dossier), method: :patch }
|
||||||
|
@ -18,7 +18,7 @@
|
||||||
= t('views.shared.dossiers.edit.autosave')
|
= t('views.shared.dossiers.edit.autosave')
|
||||||
- else
|
- else
|
||||||
Pour enregistrer votre dossier et le reprendre plus tard, cliquez sur le bouton « Enregistrer le brouillon » en bas à gauche du formulaire.
|
Pour enregistrer votre dossier et le reprendre plus tard, cliquez sur le bouton « Enregistrer le brouillon » en bas à gauche du formulaire.
|
||||||
- if !apercu && dossier.france_connect_information.present?
|
- if dossier.france_connect_information.present?
|
||||||
= render partial: "shared/dossiers/france_connect_informations", locals: { user_information: dossier.france_connect_information }
|
= render partial: "shared/dossiers/france_connect_informations", locals: { user_information: dossier.france_connect_information }
|
||||||
- if notice_url(dossier.procedure).present?
|
- if notice_url(dossier.procedure).present?
|
||||||
= link_to notice_url(dossier.procedure), target: '_blank', rel: 'noopener', class: 'button notice', title: "Pour vous aider à remplir votre dossier, vous pouvez consulter le guide de cette démarche." do
|
= link_to notice_url(dossier.procedure), target: '_blank', rel: 'noopener', class: 'button notice', title: "Pour vous aider à remplir votre dossier, vous pouvez consulter le guide de cette démarche." do
|
||||||
|
@ -40,7 +40,7 @@
|
||||||
= render partial: "shared/dossiers/editable_champs/editable_champ",
|
= render partial: "shared/dossiers/editable_champs/editable_champ",
|
||||||
locals: { champ: champ, form: champ_form }
|
locals: { champ: champ, form: champ_form }
|
||||||
|
|
||||||
- if !apercu
|
- if !dossier.for_procedure_preview?
|
||||||
.dossier-edit-sticky-footer
|
.dossier-edit-sticky-footer
|
||||||
.send-dossier-actions-bar
|
.send-dossier-actions-bar
|
||||||
- if dossier.brouillon?
|
- if dossier.brouillon?
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
- preview = !champ.persisted?
|
= react_component("MapEditor", { featureCollection: champ.to_feature_collection, url: champs_carte_features_path(champ), options: champ.render_options }, class: "carte-#{champ.id}")
|
||||||
- url = champs_carte_features_path(preview ? 'preview' : champ)
|
|
||||||
= react_component("MapEditor", { featureCollection: champ.to_feature_collection, url: url, preview: preview, options: champ.render_options }, class: "carte-#{champ.id}")
|
|
||||||
|
|
||||||
.geo-areas
|
.geo-areas
|
||||||
= render partial: 'shared/champs/carte/geo_areas', locals: { champ: champ, editing: true }
|
= render partial: 'shared/champs/carte/geo_areas', locals: { champ: champ, editing: true }
|
||||||
|
|
|
@ -7,6 +7,6 @@
|
||||||
.dossier-container
|
.dossier-container
|
||||||
.dossier-header.sub-header
|
.dossier-header.sub-header
|
||||||
.container
|
.container
|
||||||
= render partial: "shared/dossiers/header", locals: { dossier: @dossier, apercu: false }
|
= render partial: "shared/dossiers/header", locals: { dossier: @dossier }
|
||||||
|
|
||||||
= render partial: "shared/dossiers/edit", locals: { dossier: @dossier, apercu: false }
|
= render partial: "shared/dossiers/edit", locals: { dossier: @dossier }
|
||||||
|
|
|
@ -7,4 +7,4 @@
|
||||||
= render partial: 'users/dossiers/show/header', locals: { dossier: @dossier }
|
= render partial: 'users/dossiers/show/header', locals: { dossier: @dossier }
|
||||||
|
|
||||||
.container
|
.container
|
||||||
= render partial: "shared/dossiers/edit", locals: { dossier: @dossier, apercu: false }
|
= render partial: "shared/dossiers/edit", locals: { dossier: @dossier }
|
||||||
|
|
6
db/migrate/20220315124100_add_preview_to_dossiers.rb
Normal file
6
db/migrate/20220315124100_add_preview_to_dossiers.rb
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
class AddPreviewToDossiers < ActiveRecord::Migration[6.1]
|
||||||
|
def change
|
||||||
|
add_column :dossiers, :for_procedure_preview, :boolean
|
||||||
|
change_column_default :dossiers, :for_procedure_preview, false
|
||||||
|
end
|
||||||
|
end
|
|
@ -10,7 +10,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 2022_04_25_140107) do
|
ActiveRecord::Schema.define(version: 2022_04_26_140107) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
@ -314,6 +314,7 @@ ActiveRecord::Schema.define(version: 2022_04_25_140107) do
|
||||||
t.datetime "en_construction_close_to_expiration_notice_sent_at"
|
t.datetime "en_construction_close_to_expiration_notice_sent_at"
|
||||||
t.interval "en_construction_conservation_extension", default: "PT0S"
|
t.interval "en_construction_conservation_extension", default: "PT0S"
|
||||||
t.datetime "en_instruction_at"
|
t.datetime "en_instruction_at"
|
||||||
|
t.boolean "for_procedure_preview", default: false
|
||||||
t.bigint "groupe_instructeur_id"
|
t.bigint "groupe_instructeur_id"
|
||||||
t.datetime "groupe_instructeur_updated_at"
|
t.datetime "groupe_instructeur_updated_at"
|
||||||
t.datetime "hidden_at"
|
t.datetime "hidden_at"
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
namespace :after_party do
|
||||||
|
desc 'Deployment task: set_default_for_procedure_preview_on_dossiers'
|
||||||
|
task set_default_for_procedure_preview_on_dossiers: :environment do
|
||||||
|
puts "Running deploy task 'set_default_for_procedure_preview_on_dossiers'"
|
||||||
|
|
||||||
|
Dossier
|
||||||
|
.where(for_procedure_preview: nil)
|
||||||
|
.in_batches(of: 5_000)
|
||||||
|
.update_all(for_procedure_preview: false)
|
||||||
|
|
||||||
|
# Update task as completed. If you remove the line below, the task will
|
||||||
|
# run with every deploy (or every time you call after_party:run).
|
||||||
|
AfterParty::TaskRecord
|
||||||
|
.create version: AfterParty::TaskRecorder.new(__FILE__).timestamp
|
||||||
|
end
|
||||||
|
end
|
|
@ -23,7 +23,11 @@ describe Administrateurs::ProceduresController, type: :controller do
|
||||||
get :apercu, params: { id: procedure.id }
|
get :apercu, params: { id: procedure.id }
|
||||||
end
|
end
|
||||||
|
|
||||||
it { expect(response).to have_http_status(:ok) }
|
it do
|
||||||
|
expect(response).to have_http_status(:ok)
|
||||||
|
expect(procedure.dossiers.visible_by_user).to be_empty
|
||||||
|
expect(procedure.dossiers.for_procedure_preview).not_to be_empty
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
let(:procedure_params) {
|
let(:procedure_params) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue