From 954d232a478758667527ca232986ee48b3da0c31 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Tue, 15 Oct 2024 13:30:31 +0200 Subject: [PATCH] add filtered and sorted columns to export --- app/models/export.rb | 14 +++++++++++--- ..._filtered_and_sorted_column_to_exports_table.rb | 8 ++++++++ db/schema.rb | 4 +++- 3 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 db/migrate/20241014084333_add_filtered_and_sorted_column_to_exports_table.rb diff --git a/app/models/export.rb b/app/models/export.rb index 58fbdfc9c..c2332510c 100644 --- a/app/models/export.rb +++ b/app/models/export.rb @@ -37,6 +37,9 @@ class Export < ApplicationRecord has_one_attached :file + attribute :sorted_column, :sorted_column + attribute :filtered_columns, :filtered_column, array: true + validates :format, :groupe_instructeurs, :key, presence: true scope :ante_chronological, -> { order(updated_at: :desc) } @@ -66,10 +69,13 @@ class Export < ApplicationRecord end def filtered? - procedure_presentation_id.present? + filtered_columns.present? end def self.find_or_create_fresh_export(format, groupe_instructeurs, user_profile, time_span_type: time_span_types.fetch(:everything), statut: statuts.fetch(:tous), procedure_presentation: nil, export_template: nil) + filtered_columns = Array.wrap(procedure_presentation&.filters_for(statut)) + sorted_column = procedure_presentation&.sorted_column + attributes = { format:, export_template:, @@ -88,7 +94,9 @@ class Export < ApplicationRecord create!(**attributes, groupe_instructeurs:, user_profile:, procedure_presentation:, - procedure_presentation_snapshot: procedure_presentation&.snapshot) + procedure_presentation_snapshot: procedure_presentation&.snapshot, + filtered_columns:, + sorted_column:) end def self.for_groupe_instructeurs(groupe_instructeurs_ids) @@ -136,7 +144,7 @@ class Export < ApplicationRecord if since.present? dossiers.visible_by_administration.where('dossiers.depose_at > ?', since) - elsif procedure_presentation.present? + elsif filtered_columns.present? || sorted_column.present? instructeur = instructeur_from(user_profile) filtered_sorted_ids = DossierFilterService.filtered_sorted_ids(dossiers, statut, filtered_columns, sorted_column, instructeur) diff --git a/db/migrate/20241014084333_add_filtered_and_sorted_column_to_exports_table.rb b/db/migrate/20241014084333_add_filtered_and_sorted_column_to_exports_table.rb new file mode 100644 index 000000000..64d4c398c --- /dev/null +++ b/db/migrate/20241014084333_add_filtered_and_sorted_column_to_exports_table.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +class AddFilteredAndSortedColumnToExportsTable < ActiveRecord::Migration[7.0] + def change + add_column :exports, :filtered_columns, :jsonb, array: true, default: [], null: false + add_column :exports, :sorted_column, :jsonb + end +end diff --git a/db/schema.rb b/db/schema.rb index 30d626290..93aea3e2b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2024_09_29_141825) do +ActiveRecord::Schema[7.0].define(version: 2024_10_14_084333) do # These are extensions that must be enabled in order to support this database enable_extension "pg_buffercache" enable_extension "pg_stat_statements" @@ -628,12 +628,14 @@ ActiveRecord::Schema[7.0].define(version: 2024_09_29_141825) do t.datetime "created_at", precision: nil, null: false t.integer "dossiers_count" t.bigint "export_template_id" + t.jsonb "filtered_columns", default: [], null: false, array: true t.string "format", null: false t.bigint "instructeur_id" t.string "job_status", default: "pending", null: false t.text "key", null: false t.bigint "procedure_presentation_id" t.jsonb "procedure_presentation_snapshot" + t.jsonb "sorted_column" t.string "statut", default: "tous" t.string "time_span_type", default: "everything", null: false t.datetime "updated_at", precision: nil, null: false