From 67169fccd8c6ef3b130df7dd6b12f8976dd0c09a Mon Sep 17 00:00:00 2001 From: martintomas Date: Fri, 12 Jan 2024 18:48:06 +0100 Subject: [PATCH 1/2] fix: Trix image attachments --- Gemfile.lock | 34 ++++++++++++------------ app/assets/stylesheets/admin/trix.scss | 26 ++++++++++++++++++ app/assets/stylesheets/tpi/_pages.scss | 19 +++++++++++++ app/decorators/news_article_decorator.rb | 4 +-- app/inputs/trix_input.rb | 2 ++ app/javascript/packs/admin.js | 3 +++ bin/yarn | 2 +- package.json | 3 ++- yarn.lock | 16 ++++++++++- 9 files changed, 86 insertions(+), 23 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 0f465b0b6..db2dffc10 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -163,7 +163,7 @@ GEM activerecord (>= 5.a) database_cleaner-core (~> 2.0.0) database_cleaner-core (2.0.1) - date (3.3.3) + date (3.3.4) declarative (0.0.20) devise (4.8.1) bcrypt (~> 3.0) @@ -208,8 +208,8 @@ GEM formtastic_i18n (0.7.0) friendly_id (5.4.2) activerecord (>= 4.0.0) - globalid (1.1.0) - activesupport (>= 5.0) + globalid (1.2.1) + activesupport (>= 6.1) google-apis-core (0.7.0) addressable (~> 2.5, >= 2.5.1) googleauth (>= 0.16.2, < 2.a) @@ -281,7 +281,7 @@ GEM listen (3.0.8) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) - loofah (2.21.3) + loofah (2.22.0) crass (~> 1.0.2) nokogiri (>= 1.12.0) mail (2.8.1) @@ -295,24 +295,24 @@ GEM method_source (1.0.0) mini_magick (4.11.0) mini_mime (1.1.5) - mini_portile2 (2.8.4) - minitest (5.19.0) + mini_portile2 (2.8.5) + minitest (5.21.1) msgpack (1.5.3) multi_json (1.15.0) - net-imap (0.3.7) + net-imap (0.4.9.1) date net-protocol net-pop (0.1.2) net-protocol - net-protocol (0.2.1) + net-protocol (0.2.2) timeout net-scp (1.2.1) net-ssh (>= 2.6.5) - net-smtp (0.3.3) + net-smtp (0.4.0.1) net-protocol net-ssh (7.0.1) - nio4r (2.5.9) - nokogiri (1.15.4) + nio4r (2.7.0) + nokogiri (1.16.0) mini_portile2 (~> 2.8.2) racc (~> 1.4) optimist (3.0.1) @@ -338,7 +338,7 @@ GEM public_suffix (4.0.7) puma (5.6.7) nio4r (~> 2.0) - racc (1.7.1) + racc (1.7.3) rack (2.2.8) rack-cors (1.1.1) rack (>= 2.0.0) @@ -379,7 +379,7 @@ GEM rake (>= 12.2) thor (~> 1.0) rainbow (3.1.1) - rake (13.0.6) + rake (13.1.0) ransack (2.6.0) activerecord (>= 6.0.4) activesupport (>= 6.0.4) @@ -487,7 +487,7 @@ GEM spring-watcher-listen (2.0.1) listen (>= 2.7, < 4.0) spring (>= 1.2, < 3.0) - sprockets (4.2.0) + sprockets (4.2.1) concurrent-ruby (~> 1.0) rack (>= 2.2.4, < 4) sprockets-rails (3.4.2) @@ -502,10 +502,10 @@ GEM diff-lcs patience_diff test-prof (1.0.9) - thor (1.2.2) + thor (1.3.0) tilt (2.0.10) timecop (0.9.5) - timeout (0.4.0) + timeout (0.4.1) trailblazer-option (0.1.2) turbolinks (5.2.1) turbolinks-source (~> 5.2) @@ -543,7 +543,7 @@ GEM rails (>= 3.2.16) xpath (3.2.0) nokogiri (~> 1.8) - zeitwerk (2.6.11) + zeitwerk (2.6.12) PLATFORMS ruby diff --git a/app/assets/stylesheets/admin/trix.scss b/app/assets/stylesheets/admin/trix.scss index 7799bb54d..153cf5f25 100644 --- a/app/assets/stylesheets/admin/trix.scss +++ b/app/assets/stylesheets/admin/trix.scss @@ -15,3 +15,29 @@ trix-toolbar { } } } + +.trix-editor, .trix-content { + font-size: 1rem; + + .attachment { + &__caption { + display: none; + } + } + + .attachment--preview { + //position: relative; + //float: left; + //width: auto; + //margin: 10px 10px 10px 0; + text-align: center; + max-width: 100%; + padding: 0; + } + + &:after { + content: ''; + display: block; + clear: both; + } +} diff --git a/app/assets/stylesheets/tpi/_pages.scss b/app/assets/stylesheets/tpi/_pages.scss index 3678e66f7..144a4860e 100644 --- a/app/assets/stylesheets/tpi/_pages.scss +++ b/app/assets/stylesheets/tpi/_pages.scss @@ -47,6 +47,25 @@ $margin-between-list-items: 20px; margin-top: 30px; margin-bottom: 30px; } + + .attachment { + &--preview { + //position: relative; + //float: left; + //margin: 10px 10px 10px 0; + text-align: center; + max-width: 100%; + padding: 0; + + img { + margin: 0; + } + } + + &__caption { + display: none; + } + } } .pages__content { diff --git a/app/decorators/news_article_decorator.rb b/app/decorators/news_article_decorator.rb index 14ea5f497..068870b93 100644 --- a/app/decorators/news_article_decorator.rb +++ b/app/decorators/news_article_decorator.rb @@ -15,8 +15,6 @@ def tpi_sector_links end def preview_url - h.tpi_publication_url( - model, {type: 'NewsArticle', host: Rails.configuration.try(:tpi_domain)}.compact - ) + h.show_news_article_tpi_publication_path(model, {host: Rails.configuration.try(:tpi_domain)}.compact) end end diff --git a/app/inputs/trix_input.rb b/app/inputs/trix_input.rb index 66d1a9d81..cafeae800 100644 --- a/app/inputs/trix_input.rb +++ b/app/inputs/trix_input.rb @@ -3,6 +3,8 @@ def to_html input_wrapping do editor_tag_params = { input: input_html_options[:id], + 'data-direct-upload-url': Rails.application.routes.url_helpers.rails_direct_uploads_path, + 'data-blob-url-template': Rails.application.routes.url_helpers.rails_service_blob_path(':signed_id', ':filename'), class: 'trix-content' } diff --git a/app/javascript/packs/admin.js b/app/javascript/packs/admin.js index e8f5a70b9..a64fb43c0 100644 --- a/app/javascript/packs/admin.js +++ b/app/javascript/packs/admin.js @@ -1 +1,4 @@ import 'admin'; + +require('@rails/activestorage'); +require('@rails/actiontext'); diff --git a/bin/yarn b/bin/yarn index 4700a9e63..9fab2c350 100755 --- a/bin/yarn +++ b/bin/yarn @@ -3,7 +3,7 @@ APP_ROOT = File.expand_path('..', __dir__) Dir.chdir(APP_ROOT) do yarn = ENV["PATH"].split(File::PATH_SEPARATOR). select { |dir| File.expand_path(dir) != __dir__ }. - product(["yarn", "yarn.exe"]). + product(["yarn", "yarn.cmd", "yarn.ps1"]). map { |dir, file| File.expand_path(file, dir) }. find { |file| File.executable?(file) } diff --git a/package.json b/package.json index 8709a5afd..f0dc15c65 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "@hotwired/stimulus": "^3.1.0", "@hotwired/stimulus-webpack-helpers": "^1.0.1", "@rails/actioncable": "^6.0.3-3", + "@rails/actiontext": "^6.1.7-6", "@rails/activestorage": "^6.0.3-3", "@rails/ujs": "^6.0.3-3", "@rails/webpacker": "^5.2.1", @@ -63,7 +64,7 @@ "react_ujs": "^2.6.0", "simple-statistics": "^7.1.0", "tiny-slider": "^2.9.3", - "trix": "^1.2.4", + "trix": "^1.2.0", "turbolinks": "^5.2.0" }, "devDependencies": { diff --git a/yarn.lock b/yarn.lock index 897b2ba39..f44d0df65 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1241,6 +1241,20 @@ resolved "https://registry.yarnpkg.com/@rails/actioncable/-/actioncable-6.0.5.tgz#a889f25b0c13ea0215d747e32fa3d1a52967f17b" integrity sha512-79sIsTpIoHnJ6pRHKaC6h5NMRpY+VZD4mqOKN/035X1ehxHgToDWvgMZ4jV5y1qeObg4enmNESmgeKoImYGzOw== +"@rails/actiontext@^6.1.7-6": + version "6.1.7" + resolved "https://registry.yarnpkg.com/@rails/actiontext/-/actiontext-6.1.7.tgz#62997bda1d938743ed36bb802885592b01bc6782" + integrity sha512-o3TYFeFzDQKR22EGqE9qqJ6SD4DM+cATw8nioPtrRkIlAsBIHeaV0h4Kok1sDXyNjXiJztCr89CsfV7YXnYFmw== + dependencies: + "@rails/activestorage" "^6.0.0" + +"@rails/activestorage@^6.0.0": + version "6.1.7" + resolved "https://registry.yarnpkg.com/@rails/activestorage/-/activestorage-6.1.7.tgz#5aaae9f4d10800fdb4fd6fe26fd8b4218579c6e3" + integrity sha512-h++k8LBLns4O8AqzdaFp1TsCLP9VSc2hgWI37bjzJ+4D995X7Rd8kdkRmXRaNAUlHDJgy6RpnbhBJ5oiIgWTDw== + dependencies: + spark-md5 "^3.0.0" + "@rails/activestorage@^6.0.3-3": version "6.0.5" resolved "https://registry.yarnpkg.com/@rails/activestorage/-/activestorage-6.0.5.tgz#446e4b3f45bf1d4e1c6fd0b8b6e2566cb70c2b18" @@ -8724,7 +8738,7 @@ topojson-client@^3.0.0: dependencies: commander "2" -trix@^1.2.4: +trix@^1.2.0: version "1.3.1" resolved "https://registry.yarnpkg.com/trix/-/trix-1.3.1.tgz#ccce8d9e72bf0fe70c8c019ff558c70266f8d857" integrity sha512-BbH6mb6gk+AV4f2as38mP6Ucc1LE3OD6XxkZnAgPIduWXYtvg2mI3cZhIZSLqmMh9OITEpOBCCk88IVmyjU7bA== From 3f88f8b0266f3ed00890a9804f6d7bdb4b0fd11f Mon Sep 17 00:00:00 2001 From: martintomas Date: Mon, 15 Jan 2024 12:18:23 +0100 Subject: [PATCH 2/2] chore: Update of obsolete libraries --- Gemfile | 2 +- Gemfile.lock | 54 ++++++++++++++++---------------- app/models/application_record.rb | 8 +++++ 3 files changed, 36 insertions(+), 28 deletions(-) diff --git a/Gemfile b/Gemfile index ead806a4e..a366fac7e 100644 --- a/Gemfile +++ b/Gemfile @@ -18,7 +18,7 @@ gem 'bootsnap', '>= 1.4.2', require: false gem 'activerecord-import' gem 'acts_as_list' -gem 'activeadmin', '2.9.0' # TODO: update when csv export is fixed, check bom options +gem 'activeadmin' gem 'activeadmin_addons' gem 'devise', '>= 4.7.1' gem 'cancancan' diff --git a/Gemfile.lock b/Gemfile.lock index db2dffc10..738747b4a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -43,15 +43,15 @@ GEM actionpack addressable active_material (1.5.2) - activeadmin (2.9.0) + activeadmin (3.2.0) arbre (~> 1.2, >= 1.2.1) - formtastic (>= 3.1, < 5.0) - formtastic_i18n (~> 0.4) + formtastic (>= 3.1) + formtastic_i18n (>= 0.4) inherited_resources (~> 1.7) - jquery-rails (~> 4.2) - kaminari (~> 1.0, >= 1.2.1) - railties (>= 5.2, < 6.2) - ransack (~> 2.1, >= 2.1.1) + jquery-rails (>= 4.2) + kaminari (>= 1.2.1) + railties (>= 6.1) + ransack (>= 4.0) activeadmin_addons (1.9.0) active_material railties @@ -97,9 +97,9 @@ GEM rake (>= 10.4, < 14.0) appsignal (3.4.6) rack - arbre (1.5.0) - activesupport (>= 3.0.0, < 7.1) - ruby2_keywords (>= 0.0.2, < 1.0) + arbre (1.7.0) + activesupport (>= 3.0.0) + ruby2_keywords (>= 0.0.2) ast (2.4.2) attr_extras (6.2.5) babel-source (5.8.35) @@ -203,8 +203,8 @@ GEM ffi (1.15.5) font-awesome-rails (4.7.0.8) railties (>= 3.2, < 8.0) - formtastic (4.0.0) - actionpack (>= 5.2.0) + formtastic (5.0.0) + actionpack (>= 6.0.0) formtastic_i18n (0.7.0) friendly_id (5.4.2) activerecord (>= 4.0.0) @@ -244,7 +244,7 @@ GEM multi_json (~> 1.11) os (>= 0.9, < 2.0) signet (>= 0.16, < 2.a) - has_scope (0.8.0) + has_scope (0.8.2) actionpack (>= 5.2) activesupport (>= 5.2) htmlentities (4.3.4) @@ -254,12 +254,12 @@ GEM image_processing (1.12.2) mini_magick (>= 4.9.5, < 5) ruby-vips (>= 2.0.17, < 3) - inherited_resources (1.13.1) - actionpack (>= 5.2, < 7.1) - has_scope (~> 0.6) - railties (>= 5.2, < 7.1) - responders (>= 2, < 4) - jquery-rails (4.5.0) + inherited_resources (1.14.0) + actionpack (>= 6.0) + has_scope (>= 0.6) + railties (>= 6.0) + responders (>= 2) + jquery-rails (4.6.0) rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) @@ -336,7 +336,7 @@ GEM i18n (>= 0.5.0) railties (>= 5.0.0) public_suffix (4.0.7) - puma (5.6.7) + puma (5.6.8) nio4r (~> 2.0) racc (1.7.3) rack (2.2.8) @@ -380,9 +380,9 @@ GEM thor (~> 1.0) rainbow (3.1.1) rake (13.1.0) - ransack (2.6.0) - activerecord (>= 6.0.4) - activesupport (>= 6.0.4) + ransack (4.1.1) + activerecord (>= 6.1.5) + activesupport (>= 6.1.5) i18n rb-fsevent (0.11.2) rb-inotify (0.10.1) @@ -401,9 +401,9 @@ GEM request_store (1.5.1) rack (>= 1.4) require_all (3.0.0) - responders (3.0.1) - actionpack (>= 5.0) - railties (>= 5.0) + responders (3.1.1) + actionpack (>= 5.2) + railties (>= 5.2) retriable (3.1.2) rexml (3.2.6) roo (2.10.0) @@ -550,7 +550,7 @@ PLATFORMS DEPENDENCIES active_link_to - activeadmin (= 2.9.0) + activeadmin activeadmin_addons activerecord-import acts_as_list diff --git a/app/models/application_record.rb b/app/models/application_record.rb index 5032f8f51..39e29d9ab 100644 --- a/app/models/application_record.rb +++ b/app/models/application_record.rb @@ -4,4 +4,12 @@ class ApplicationRecord < ActiveRecord::Base def self.array_to_enum_hash(array) array.map { |el| [el, el] }.to_h end + + def self.ransackable_associations(_auth_object = nil) + @ransackable_associations ||= reflect_on_all_associations.map { |a| a.name.to_s } + end + + def self.ransackable_attributes(_auth_object = nil) + @ransackable_attributes ||= column_names + _ransackers.keys + _ransack_aliases.keys + attribute_aliases.keys + end end