2022-11-21 16:32:17 +01:00
|
|
|
class Dossiers::BatchOperationComponent < ApplicationComponent
|
|
|
|
attr_reader :statut, :procedure
|
|
|
|
|
|
|
|
def initialize(statut:, procedure:)
|
|
|
|
@statut = statut
|
|
|
|
@procedure = procedure
|
|
|
|
end
|
|
|
|
|
|
|
|
def render?
|
2023-01-04 11:51:22 +01:00
|
|
|
['a-suivre', 'traites', 'suivis'].include?(@statut)
|
2022-11-21 16:32:17 +01:00
|
|
|
end
|
|
|
|
|
2023-01-06 20:07:53 +01:00
|
|
|
def operations_for_dossier(dossier)
|
|
|
|
case dossier.state
|
|
|
|
when Dossier.states.fetch(:en_construction)
|
2023-01-11 11:50:12 +01:00
|
|
|
[BatchOperation.operations.fetch(:passer_en_instruction), BatchOperation.operations.fetch(:follow)]
|
2023-01-06 20:07:53 +01:00
|
|
|
when Dossier.states.fetch(:en_instruction)
|
|
|
|
[BatchOperation.operations.fetch(:accepter)]
|
|
|
|
when Dossier.states.fetch(:accepte), Dossier.states.fetch(:refuse), Dossier.states.fetch(:sans_suite)
|
|
|
|
[BatchOperation.operations.fetch(:archiver)]
|
|
|
|
else
|
|
|
|
[]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2022-11-21 16:32:17 +01:00
|
|
|
def available_operations
|
|
|
|
case @statut
|
2023-01-04 11:51:22 +01:00
|
|
|
when 'a-suivre' then
|
|
|
|
{
|
|
|
|
options:
|
|
|
|
[
|
|
|
|
{
|
|
|
|
label: t(".operations.follow"),
|
|
|
|
operation: BatchOperation.operations.fetch(:follow)
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
2022-11-21 16:32:17 +01:00
|
|
|
when 'traites' then
|
2022-12-15 17:35:50 +01:00
|
|
|
{
|
|
|
|
options:
|
|
|
|
[
|
|
|
|
{
|
|
|
|
label: t(".operations.archiver"),
|
|
|
|
operation: BatchOperation.operations.fetch(:archiver)
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
2022-12-12 10:02:33 +01:00
|
|
|
when 'suivis' then
|
2022-12-15 17:35:50 +01:00
|
|
|
{
|
|
|
|
options:
|
|
|
|
[
|
|
|
|
|
|
|
|
{
|
|
|
|
label: t(".operations.passer_en_instruction"),
|
|
|
|
operation: BatchOperation.operations.fetch(:passer_en_instruction)
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
label: t(".operations.accepter"),
|
|
|
|
operation: BatchOperation.operations.fetch(:accepter)
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
2022-11-21 16:32:17 +01:00
|
|
|
else
|
2022-12-15 17:35:50 +01:00
|
|
|
{
|
|
|
|
options: []
|
|
|
|
}
|
2022-11-21 16:32:17 +01:00
|
|
|
end
|
|
|
|
end
|
2022-12-12 10:28:23 +01:00
|
|
|
|
|
|
|
def icons
|
|
|
|
{
|
2023-01-04 11:51:22 +01:00
|
|
|
accepter: 'fr-icon-success-line',
|
2022-12-12 10:28:23 +01:00
|
|
|
archiver: 'fr-icon-folder-2-line',
|
2023-01-04 11:51:22 +01:00
|
|
|
follow: 'fr-icon-star-line',
|
|
|
|
passer_en_instruction: 'fr-icon-edit-line'
|
2022-12-12 10:28:23 +01:00
|
|
|
}
|
|
|
|
end
|
2022-11-21 16:32:17 +01:00
|
|
|
end
|