From 6a45c706eba333d73acb6ccf0e8e45392049f689 Mon Sep 17 00:00:00 2001 From: Arnaud Levy <contact@arnaudlevy.com> Date: Tue, 16 Jan 2024 14:28:42 +0100 Subject: [PATCH] Better --- Gemfile.lock | 36 +++++++++---------- .../block/component/agenda_category.rb | 17 +++++++++ .../{category.rb => post_category.rb} | 2 +- .../communication/block/template/agenda.rb | 2 +- .../communication/block/template/post.rb | 2 +- .../communication/website/agenda/event.rb | 2 +- .../_edit.html.erb | 0 .../_show.html.erb | 0 .../_snippet.html.erb | 0 .../_static.html.erb | 0 .../components/post_category/_edit.html.erb | 14 ++++++++ .../components/post_category/_show.html.erb | 1 + .../post_category/_snippet.html.erb | 1 + .../components/post_category/_static.html.erb | 1 + 14 files changed, 56 insertions(+), 22 deletions(-) create mode 100644 app/models/communication/block/component/agenda_category.rb rename app/models/communication/block/component/{category.rb => post_category.rb} (74%) rename app/views/admin/communication/blocks/components/{category => agenda_category}/_edit.html.erb (100%) rename app/views/admin/communication/blocks/components/{category => agenda_category}/_show.html.erb (100%) rename app/views/admin/communication/blocks/components/{category => agenda_category}/_snippet.html.erb (100%) rename app/views/admin/communication/blocks/components/{category => agenda_category}/_static.html.erb (100%) create mode 100644 app/views/admin/communication/blocks/components/post_category/_edit.html.erb create mode 100644 app/views/admin/communication/blocks/components/post_category/_show.html.erb create mode 100644 app/views/admin/communication/blocks/components/post_category/_snippet.html.erb create mode 100644 app/views/admin/communication/blocks/components/post_category/_static.html.erb diff --git a/Gemfile.lock b/Gemfile.lock index f6aff8c2f..5d59a6187 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -123,8 +123,8 @@ GEM autoprefixer-rails (10.4.16.0) execjs (~> 2) aws-eventstream (1.3.0) - aws-partitions (1.877.0) - aws-sdk-core (3.190.1) + aws-partitions (1.880.0) + aws-sdk-core (3.190.2) aws-eventstream (~> 1, >= 1.3.0) aws-partitions (~> 1, >= 1.651.0) aws-sigv4 (~> 1.8) @@ -142,7 +142,7 @@ GEM bcrypt (3.1.20) bigdecimal (3.1.5) bindex (0.8.1) - bootsnap (1.17.0) + bootsnap (1.17.1) msgpack (~> 1.2) bootstrap (5.3.2) autoprefixer-rails (>= 9.1.0) @@ -152,7 +152,7 @@ GEM rails (>= 3.1) breadcrumbs_on_rails (4.1.0) railties (>= 5.0) - bugsnag (6.26.0) + bugsnag (6.26.1) concurrent-ruby (~> 1.0) builder (3.2.4) byebug (11.1.3) @@ -180,7 +180,7 @@ GEM citeproc (~> 1.0, >= 1.0.9) csl (~> 2.0) cocoon (1.2.15) - concurrent-ruby (1.2.2) + concurrent-ruby (1.2.3) connection_pool (2.4.1) countries (5.7.1) unaccent (~> 0.3) @@ -221,7 +221,7 @@ GEM devise-i18n (1.12.0) devise (>= 4.9.0) docile (1.4.0) - domain_name (0.6.20231109) + domain_name (0.6.20240107) drb (2.2.0) ruby2_keywords encryptor (3.0.0) @@ -234,10 +234,8 @@ GEM faceted_search (3.6.2) font-awesome-sass rails (>= 5.2.0) - faraday (2.8.1) - base64 - faraday-net_http (>= 2.0, < 3.1) - ruby2_keywords (>= 0.0.4) + faraday (2.9.0) + faraday-net_http (>= 2.0, < 3.2) faraday-cookie_jar (0.0.7) faraday (>= 0.8.0) http-cookie (~> 1.0.0) @@ -248,11 +246,12 @@ GEM faraday-gzip (1.0.0) faraday (>= 1.0) zlib (~> 2.1) - faraday-http-cache (2.5.0) + faraday-http-cache (2.5.1) faraday (>= 0.8) faraday-multipart (1.0.4) multipart-post (~> 2) - faraday-net_http (3.0.2) + faraday-net_http (3.1.0) + net-http faraday-retry (2.2.0) faraday (~> 2.0) fastimage (2.3.0) @@ -309,9 +308,9 @@ GEM mini_magick (>= 4.9.5, < 5) ruby-vips (>= 2.0.17, < 3) io-console (0.7.1) - irb (1.11.0) + irb (1.11.1) rdoc - reline (>= 0.3.8) + reline (>= 0.4.2) jbuilder (2.11.5) actionview (>= 5.0.0) activesupport (>= 5.0.0) @@ -371,14 +370,15 @@ GEM nokogiri (~> 1.13) mini_magick (4.12.0) mini_mime (1.1.5) - minitest (5.20.0) + minitest (5.21.1) msgpack (1.7.2) multi_xml (0.6.0) multipart-post (2.3.0) mustermann (3.0.0) ruby2_keywords (~> 0.0.1) mutex_m (0.2.0) - namae (1.1.1) + namae (1.2.0) + racc (~> 1.7) nesty (1.0.2) net-http (0.4.1) uri @@ -423,7 +423,7 @@ GEM time uri orm_adapter (0.5.0) - parser (3.3.0.2) + parser (3.3.0.4) ast (~> 2.4.1) racc pexels (0.5.0) @@ -490,7 +490,7 @@ GEM ffi (~> 1.0) rdoc (6.6.2) psych (>= 4.0.0) - regexp_parser (2.8.3) + regexp_parser (2.9.0) reline (0.4.2) io-console (~> 0.5) requests (1.0.2) diff --git a/app/models/communication/block/component/agenda_category.rb b/app/models/communication/block/component/agenda_category.rb new file mode 100644 index 000000000..70061fd9b --- /dev/null +++ b/app/models/communication/block/component/agenda_category.rb @@ -0,0 +1,17 @@ +class Communication::Block::Component::AgendaCategory < Communication::Block::Component::Base + + def category + return unless website + website.agenda_categories.find_by(id: data) + end + + def dependencies + [category] + end + + def translate! + return unless category.present? + @data = category.find_or_translate!(template.language).id + end + +end diff --git a/app/models/communication/block/component/category.rb b/app/models/communication/block/component/post_category.rb similarity index 74% rename from app/models/communication/block/component/category.rb rename to app/models/communication/block/component/post_category.rb index 262d4daf1..858e6a229 100644 --- a/app/models/communication/block/component/category.rb +++ b/app/models/communication/block/component/post_category.rb @@ -1,4 +1,4 @@ -class Communication::Block::Component::Category < Communication::Block::Component::Base +class Communication::Block::Component::PostCategory < Communication::Block::Component::Base def category return unless website diff --git a/app/models/communication/block/template/agenda.rb b/app/models/communication/block/template/agenda.rb index 0cd13610d..2085c5518 100644 --- a/app/models/communication/block/template/agenda.rb +++ b/app/models/communication/block/template/agenda.rb @@ -19,7 +19,7 @@ class Communication::Block::Template::Agenda < Communication::Block::Template::B :selection, :categories ] - has_component :category_id, :category + has_component :category_id, :agenda_category has_component :description, :rich_text has_component :quantity, :number, options: 3 has_component :time, :option, options: AUTHORIZED_SCOPES diff --git a/app/models/communication/block/template/post.rb b/app/models/communication/block/template/post.rb index e437000d9..93b6af897 100644 --- a/app/models/communication/block/template/post.rb +++ b/app/models/communication/block/template/post.rb @@ -15,7 +15,7 @@ class Communication::Block::Template::Post < Communication::Block::Template::Bas :categories ] has_component :posts_quantity, :number, options: 3 - has_component :category_id, :category + has_component :category_id, :post_category def category category_id_component.category diff --git a/app/models/communication/website/agenda/event.rb b/app/models/communication/website/agenda/event.rb index e24d795ca..6e58e6bd8 100644 --- a/app/models/communication/website/agenda/event.rb +++ b/app/models/communication/website/agenda/event.rb @@ -75,7 +75,7 @@ class Communication::Website::Agenda::Event < ApplicationRecord scope :published, -> { where(published: true) } scope :draft, -> { where(published: false) } - scope :for_category, -> (category_id) { joins(:categories).where(communication_website_categories: { id: category_id }).distinct } + scope :for_category, -> (category_id) { joins(:categories).where(communication_website_agenda_categories: { id: category_id }).distinct } def git_path(website) return unless website.id == communication_website_id && published diff --git a/app/views/admin/communication/blocks/components/category/_edit.html.erb b/app/views/admin/communication/blocks/components/agenda_category/_edit.html.erb similarity index 100% rename from app/views/admin/communication/blocks/components/category/_edit.html.erb rename to app/views/admin/communication/blocks/components/agenda_category/_edit.html.erb diff --git a/app/views/admin/communication/blocks/components/category/_show.html.erb b/app/views/admin/communication/blocks/components/agenda_category/_show.html.erb similarity index 100% rename from app/views/admin/communication/blocks/components/category/_show.html.erb rename to app/views/admin/communication/blocks/components/agenda_category/_show.html.erb diff --git a/app/views/admin/communication/blocks/components/category/_snippet.html.erb b/app/views/admin/communication/blocks/components/agenda_category/_snippet.html.erb similarity index 100% rename from app/views/admin/communication/blocks/components/category/_snippet.html.erb rename to app/views/admin/communication/blocks/components/agenda_category/_snippet.html.erb diff --git a/app/views/admin/communication/blocks/components/category/_static.html.erb b/app/views/admin/communication/blocks/components/agenda_category/_static.html.erb similarity index 100% rename from app/views/admin/communication/blocks/components/category/_static.html.erb rename to app/views/admin/communication/blocks/components/agenda_category/_static.html.erb diff --git a/app/views/admin/communication/blocks/components/post_category/_edit.html.erb b/app/views/admin/communication/blocks/components/post_category/_edit.html.erb new file mode 100644 index 000000000..645f43d0b --- /dev/null +++ b/app/views/admin/communication/blocks/components/post_category/_edit.html.erb @@ -0,0 +1,14 @@ +<% categories = collection(block.about&.website.post_categories.for_language(block.language)) %> +<label class="form-label" + :for="<%= dom_id.html_safe %>"> + <%= label %> +</label> +<select :id="<%= dom_id.html_safe %>" + class="form-select select mb-3" + v-model="<%= model %>.<%= property %>"> + <% categories.each_with_index do |category, index| %> + <option value="<%= category[:id] %>"> + <%= category[:label].html_safe %> + </option> + <% end %> +</select> diff --git a/app/views/admin/communication/blocks/components/post_category/_show.html.erb b/app/views/admin/communication/blocks/components/post_category/_show.html.erb new file mode 100644 index 000000000..1a4ddd3f7 --- /dev/null +++ b/app/views/admin/communication/blocks/components/post_category/_show.html.erb @@ -0,0 +1 @@ +<%= component.category.to_s %> diff --git a/app/views/admin/communication/blocks/components/post_category/_snippet.html.erb b/app/views/admin/communication/blocks/components/post_category/_snippet.html.erb new file mode 100644 index 000000000..1a4ddd3f7 --- /dev/null +++ b/app/views/admin/communication/blocks/components/post_category/_snippet.html.erb @@ -0,0 +1 @@ +<%= component.category.to_s %> diff --git a/app/views/admin/communication/blocks/components/post_category/_static.html.erb b/app/views/admin/communication/blocks/components/post_category/_static.html.erb new file mode 100644 index 000000000..a871dde97 --- /dev/null +++ b/app/views/admin/communication/blocks/components/post_category/_static.html.erb @@ -0,0 +1 @@ +<%= indentation %><%= '- ' if list %><%= property %>: <%= value %> -- GitLab