From 0ade114cac8292e7a5ef6cf9f4a2ef56e14f2f55 Mon Sep 17 00:00:00 2001 From: Arnaud Levy Date: Thu, 16 Jul 2026 20:11:58 +0200 Subject: [PATCH 01/14] JSON picker --- .../communication/library/files_controller.rb | 8 ++- app/models/communication/file/picker.rb | 65 +++++++++++++++++++ .../library/files/_picker.html.erb | 0 .../library/files/index.json.jbuilder | 0 .../library/files/picker.json.jbuilder | 12 ++++ config/routes/admin/communication.rb | 2 +- 6 files changed, 84 insertions(+), 3 deletions(-) create mode 100644 app/models/communication/file/picker.rb delete mode 100644 app/views/admin/communication/library/files/_picker.html.erb delete mode 100644 app/views/admin/communication/library/files/index.json.jbuilder create mode 100644 app/views/admin/communication/library/files/picker.json.jbuilder diff --git a/app/controllers/admin/communication/library/files_controller.rb b/app/controllers/admin/communication/library/files_controller.rb index 7092e9a40e..f2fc659a0e 100644 --- a/app/controllers/admin/communication/library/files_controller.rb +++ b/app/controllers/admin/communication/library/files_controller.rb @@ -30,8 +30,12 @@ def direct_upload @file = @localization.file end - def pick - # TODO generic picker + def picker + @picker = Communication::File::Picker.new( + @files, + current_language, + params + ) end def edit diff --git a/app/models/communication/file/picker.rb b/app/models/communication/file/picker.rb new file mode 100644 index 0000000000..f6e8da7580 --- /dev/null +++ b/app/models/communication/file/picker.rb @@ -0,0 +1,65 @@ +class Communication::File::Picker + attr_reader :objects, :language, :params + + def initialize(objects, language, params) + @objects = objects + @language = language + @params = params.to_unsafe_hash + end + + def parameters + { + search: search, + filters: filters, + sorts: sorts, + pagination: pagination + } + end + + def paginated_objects + @paginated_objects ||= objects.ordered(language).page(params[:page]) + end + + protected + + def search + '' + end + + def filters + [ + { + id: 'categories', + name: 'Catégories', + values: [ + { id: 'cat-1', name: 'Catégorie 1', selected: false } + ] + } + ] + end + + def sorts + [ + { + id: 'date-desc', + name: 'Trier du plus récent au plus ancien', + selected: true + }, + { + id: 'date-asc', + name: 'Trier du plus ancien au plus récent', + selected: false + } + ] + end + + def pagination + { + current_page: paginated_objects.current_page, + limit_value: paginated_objects.limit_value, + total_count: paginated_objects.total_count, + total_pages: paginated_objects.total_pages + } + end + +end \ No newline at end of file diff --git a/app/views/admin/communication/library/files/_picker.html.erb b/app/views/admin/communication/library/files/_picker.html.erb deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/app/views/admin/communication/library/files/index.json.jbuilder b/app/views/admin/communication/library/files/index.json.jbuilder deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/app/views/admin/communication/library/files/picker.json.jbuilder b/app/views/admin/communication/library/files/picker.json.jbuilder new file mode 100644 index 0000000000..58c74dc4f3 --- /dev/null +++ b/app/views/admin/communication/library/files/picker.json.jbuilder @@ -0,0 +1,12 @@ +json.parameters @picker.parameters +json.results @picker.paginated_objects do |file| + l10n = file.localized_in(current_language) + json.id file.id + json.name l10n.name + json.icon l10n.icon + json.snippet render( + partial: 'admin/communication/library/files/file', + locals: { file: file }, + formats: [:html] + ) +end \ No newline at end of file diff --git a/config/routes/admin/communication.rb b/config/routes/admin/communication.rb index 58cfb1278f..2d1e372e30 100644 --- a/config/routes/admin/communication.rb +++ b/config/routes/admin/communication.rb @@ -292,7 +292,7 @@ resources :files do collection do post 'direct-upload' => 'files#direct_upload', as: :direct_upload - post 'pick' => 'files#pick', as: :pick + get 'picker' => 'files#picker', as: :picker, defaults: { format: :json } resources :categories, controller: '/admin/communication/library/files/categories', as: 'file_categories' do collection do post :reorder From 21c022ebc8da5c7713fc227137391b4adb96f193 Mon Sep 17 00:00:00 2001 From: Arnaud Levy Date: Thu, 16 Jul 2026 21:54:23 +0200 Subject: [PATCH 02/14] picker --- .../apps/blocks-editor/components/Editor.vue | 8 +- app/javascript/apps/components/Picker.vue | 172 ++++++++++++++++++ app/models/communication/file/picker.rb | 4 +- .../blocks/components/file/_edit.html.erb | 4 + .../library/files/picker.json.jbuilder | 8 +- 5 files changed, 188 insertions(+), 8 deletions(-) create mode 100644 app/javascript/apps/components/Picker.vue diff --git a/app/javascript/apps/blocks-editor/components/Editor.vue b/app/javascript/apps/blocks-editor/components/Editor.vue index 5befbb3e0b..524a41feb0 100644 --- a/app/javascript/apps/blocks-editor/components/Editor.vue +++ b/app/javascript/apps/blocks-editor/components/Editor.vue @@ -6,6 +6,7 @@ import CodeInput from './inputs/CodeInput.vue'; import UploadInput from './inputs/UploadInput.vue'; import FileUploadInput from './inputs/FileUploadInput.vue'; import MultiImageInput from './inputs/MultiImageInput.vue'; +import Picker from '../../components/Picker.vue'; // Renders the block-edit form fetched from the server, mounts a fresh inner // Vue app on it for reactive v-model bindings, and unmounts on close. @@ -143,12 +144,13 @@ export default { }, }); - this.innerApp.component('draggable', VueDraggableNext); - this.innerApp.component('RichTextInput', RichTextInput); this.innerApp.component('CodeInput', CodeInput); - this.innerApp.component('UploadInput', UploadInput); + this.innerApp.component('draggable', VueDraggableNext); this.innerApp.component('FileUploadInput', FileUploadInput); this.innerApp.component('MultiImageInput', MultiImageInput); + this.innerApp.component('Picker', Picker); + this.innerApp.component('RichTextInput', RichTextInput); + this.innerApp.component('UploadInput', UploadInput); this.innerApp.mount(root); }, diff --git a/app/javascript/apps/components/Picker.vue b/app/javascript/apps/components/Picker.vue new file mode 100644 index 0000000000..c858939e15 --- /dev/null +++ b/app/javascript/apps/components/Picker.vue @@ -0,0 +1,172 @@ + + + diff --git a/app/models/communication/file/picker.rb b/app/models/communication/file/picker.rb index f6e8da7580..862e1d9830 100644 --- a/app/models/communication/file/picker.rb +++ b/app/models/communication/file/picker.rb @@ -42,12 +42,12 @@ def sorts [ { id: 'date-desc', - name: 'Trier du plus récent au plus ancien', + name: 'Les plus récents d\'abord', selected: true }, { id: 'date-asc', - name: 'Trier du plus ancien au plus récent', + name: 'Les plus anciens d\'abord', selected: false } ] diff --git a/app/views/admin/communication/blocks/components/file/_edit.html.erb b/app/views/admin/communication/blocks/components/file/_edit.html.erb index 87e5fe62a0..46d4e2079d 100644 --- a/app/views/admin/communication/blocks/components/file/_edit.html.erb +++ b/app/views/admin/communication/blocks/components/file/_edit.html.erb @@ -4,6 +4,10 @@ remove = t('admin.communication.blocks.components.file.input.remove') hint = file_hint if hint.blank? accept ||= '*' %> + + Date: Thu, 16 Jul 2026 22:29:46 +0200 Subject: [PATCH 03/14] Pagination --- app/javascript/apps/components/Picker.vue | 66 ++++++------------- .../apps/components/picker/Pagination.vue | 55 ++++++++++++++++ app/models/communication/file/picker.rb | 8 ++- 3 files changed, 80 insertions(+), 49 deletions(-) create mode 100644 app/javascript/apps/components/picker/Pagination.vue diff --git a/app/javascript/apps/components/Picker.vue b/app/javascript/apps/components/Picker.vue index c858939e15..68c55db0c0 100644 --- a/app/javascript/apps/components/Picker.vue +++ b/app/javascript/apps/components/Picker.vue @@ -1,11 +1,10 @@ + + diff --git a/app/models/communication/file/picker.rb b/app/models/communication/file/picker.rb index 862e1d9830..0e3494c3da 100644 --- a/app/models/communication/file/picker.rb +++ b/app/models/communication/file/picker.rb @@ -9,7 +9,7 @@ def initialize(objects, language, params) def parameters { - search: search, + term: term, filters: filters, sorts: sorts, pagination: pagination @@ -17,12 +17,14 @@ def parameters end def paginated_objects - @paginated_objects ||= objects.ordered(language).page(params[:page]) + @paginated_objects ||= objects.ordered(language) + .page(params[:page]) + #.per(2) end protected - def search + def term '' end From 37a3631e1b3fab921ee664cc4a00e3db77488f44 Mon Sep 17 00:00:00 2001 From: Arnaud Levy Date: Thu, 16 Jul 2026 22:41:33 +0200 Subject: [PATCH 04/14] Components --- app/javascript/apps/components/Picker.vue | 47 ++++--------------- .../apps/components/picker/Pagination.vue | 22 ++++----- .../apps/components/picker/Parameters.vue | 47 +++++++++++++++++++ app/models/communication/file/picker.rb | 4 +- 4 files changed, 69 insertions(+), 51 deletions(-) create mode 100644 app/javascript/apps/components/picker/Parameters.vue diff --git a/app/javascript/apps/components/Picker.vue b/app/javascript/apps/components/Picker.vue index 68c55db0c0..6de861abb5 100644 --- a/app/javascript/apps/components/Picker.vue +++ b/app/javascript/apps/components/Picker.vue @@ -1,10 +1,12 @@ @@ -95,42 +94,14 @@ export default {