add filtered and sorted columns to export
This commit is contained in:
parent
603c2a108e
commit
954d232a47
3 changed files with 22 additions and 4 deletions
|
@ -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)
|
||||
|
||||
|
|
|
@ -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
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue