alchemy-solidus 7.2.1 → 7.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7e50bb72fd9136b75ae2b8ea66ca80acb37edf3322f2aa750e0ca1f9bc5e1071
4
- data.tar.gz: b6cbccde4616f51672baf1b45df5f06d11ad63edf13fdb0c1a6f100ee0b9e819
3
+ metadata.gz: 46d8a3b3de7124d7a00825bd35e9f96ca0fe16f13b6d3dbcda7e31cd47367c46
4
+ data.tar.gz: '09cf18eece796eb7f3439eea4dd76ce60f44d9c268631e47e72d10fa1648cd9d'
5
5
  SHA512:
6
- metadata.gz: a8324f5ffbf7fc02fd449f30d6b3bb80378cf188b3b4f6f966bcf95b467437160f0511e37eabf1e19ee6a6ae4bf970fb4491b5f6c99989dff9abf1fdedc59fb1
7
- data.tar.gz: 5dd149df193cfe5638e9abd2d73d127d6c334de0d2a7ab7cebc868b98e34249af41796b4ad3518b9b1a35d50796c616f8609da2d1fee924df41c7c8288369365
6
+ metadata.gz: b33362b6ed914b1f180346296f4d0a5d62e47e42754bde997649737cd4d440c2a2d9cfdaea9acce67fa935c01db82eb93e0d6e5af1f1ba2afd60a30906f48bc8
7
+ data.tar.gz: db8d3049d169f31d31843199125781fd42dd72c2109168853f445fe144be62626d3d8ad9b2e1f5472a4e8b0afb378c982298076dcc7d422a4d96a6a4fb613c4a
data/README.md CHANGED
@@ -30,8 +30,9 @@ This version runs with Solidus v4.0 and up.
30
30
 
31
31
  ### Alchemy
32
32
 
33
- This version runs with Alchemy v7.0 and v7.1
33
+ This version runs with Alchemy v7.2
34
34
 
35
+ - For a Alchemy 7.0/7.1 compatible version please use the `7.2-stable` branch or `7.2` gem version.
35
36
  - For a Alchemy 6.x compatible version please use the `5.0-stable` branch or `5.0` gem version.
36
37
  - For a Alchemy 5.x compatible version please use the `4.1-stable` branch or `4.1` gem version.
37
38
  - For a Alchemy 4.x compatible version please use the `3.1-stable` branch or `3.3` gem version.
@@ -0,0 +1 @@
1
+ //= link_tree ../../../javascript .js
@@ -1,32 +1,55 @@
1
1
  //= require alchemy/solidus/admin/select2_config
2
2
 
3
- $.fn.alchemyVariantSelect = function(options) {
4
- var config = Alchemy.Solidus.getSelect2Config(options)
3
+ $.fn.alchemyVariantSelect = function (options) {
4
+ const config = Alchemy.Solidus.getSelect2Config(options)
5
5
 
6
- this.select2($.extend(true, config, {
7
- ajax: {
8
- data: function(term, page) {
9
- return {
10
- q: $.extend({
11
- product_name_or_sku_cont: term
12
- }, options.query_params),
13
- page: page
14
- }
6
+ function formatSelection(variant) {
7
+ return variant.options_text
8
+ ? `${variant.name} - ${variant.options_text}`
9
+ : variant.name
10
+ }
11
+
12
+ function formatResult(variant, _el, query) {
13
+ const matchTerm = new RegExp(query.term, "gi")
14
+ const formatMatch = (match) => `<em>${match}</em>`
15
+ const name = variant.name.replace(matchTerm, formatMatch)
16
+ const sku = variant.sku.replace(matchTerm, formatMatch)
17
+ return `
18
+ <div class="variant-select-result">
19
+ <div>
20
+ <span>${name}</span>
21
+ </div>
22
+ <div>
23
+ <span>${variant.options_text}</span>
24
+ <span>${sku}</span>
25
+ </div>
26
+ </div>
27
+ `
28
+ }
29
+
30
+ this.select2(
31
+ $.extend(true, config, {
32
+ ajax: {
33
+ data: function (term, page) {
34
+ return {
35
+ q: $.extend(
36
+ {
37
+ product_name_or_sku_cont: term,
38
+ },
39
+ options.query_params
40
+ ),
41
+ page: page,
42
+ }
43
+ },
44
+ results: function (data, page) {
45
+ return {
46
+ results: data.variants,
47
+ more: page * data.per_page < data.total_count,
48
+ }
49
+ },
15
50
  },
16
- results: function(data, page) {
17
- return {
18
- results: data.variants.map(function(variant) {
19
- return {
20
- id: variant.id,
21
- text: variant.frontend_display
22
- }
23
- }),
24
- more: page * data.per_page < data.total_count
25
- }
26
- }
27
- },
28
- formatSelection: function(variant) {
29
- return variant.text || variant.frontend_display
30
- }
31
- }))
51
+ formatSelection,
52
+ formatResult,
53
+ })
54
+ )
32
55
  }
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Alchemy
4
+ module Admin
5
+ module LinkDialog
6
+ class ProductTab < BaseTab
7
+ delegate :alchemy, :current_alchemy_user, :spree, to: :helpers
8
+
9
+ def self.product_select_class
10
+ ProductSelect
11
+ end
12
+
13
+ def title
14
+ Alchemy.t("link_overlay_tab_label.product")
15
+ end
16
+
17
+ def self.panel_name
18
+ :product
19
+ end
20
+
21
+ def fields
22
+ [
23
+ product_select,
24
+ title_input,
25
+ target_select
26
+ ]
27
+ end
28
+
29
+ def message
30
+ render_message(:info, content_tag("h3", Alchemy.t(:choose_product_to_link)))
31
+ end
32
+
33
+ private
34
+
35
+ def product
36
+ slug = url&.match(/products\/(?<slug>[\w-]+)/)&.captures
37
+ return unless slug
38
+
39
+ @_product ||= Spree::Product.find_by(slug: slug)
40
+ end
41
+
42
+ def product_select
43
+ label = label_tag("product_link", Alchemy.t(:product), class: "control-label")
44
+ input = text_field_tag("product_link", product && url, id: "product_link",
45
+ placeholder: Alchemy.t(:search_product, scope: "solidus"),
46
+ class: "alchemy_selectbox")
47
+ select = render self.class.product_select_class.new(
48
+ current_alchemy_user.spree_api_key,
49
+ product: product,
50
+ url: spree.api_products_path
51
+ ).with_content(input)
52
+ content_tag("div", label + select, class: "input select")
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,44 @@
1
+ module Alchemy
2
+ module Admin
3
+ class ProductSelect < ViewComponent::Base
4
+ delegate :spree, to: :helpers
5
+
6
+ attr_reader :api_key, :product, :url, :query_params
7
+
8
+ def initialize(api_key, product: nil, url: nil, query_params: nil)
9
+ @api_key = api_key
10
+ @product = product
11
+ @url = url
12
+ @query_params = query_params
13
+ end
14
+
15
+ def call
16
+ content_tag("alchemy-product-select", content, attributes)
17
+ end
18
+
19
+ private
20
+
21
+ def attributes
22
+ attrs = {
23
+ url: url || spree.api_products_path,
24
+ "api-key": api_key
25
+ }
26
+
27
+ attrs[:"query-params"] = query_params.to_json if query_params
28
+
29
+ if product
30
+ attrs[:selection] = serialized_selection
31
+ end
32
+
33
+ attrs
34
+ end
35
+
36
+ def serialized_selection
37
+ {
38
+ name: product.name,
39
+ slug: product.slug
40
+ }.to_json
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,41 @@
1
+ export default class ProductSelect extends HTMLElement {
2
+ connectedCallback() {
3
+ const input = this.querySelector("#product_link")
4
+ input.classList.add("alchemy_selectbox")
5
+
6
+ $(input).alchemyProductSelect({
7
+ baseUrl: this.url,
8
+ apiToken: this.apiToken,
9
+ initSelection: this._initSelection.bind(this),
10
+ formatResultObject: this._formatResult.bind(this),
11
+ })
12
+ }
13
+
14
+ get url() {
15
+ return this.getAttribute("url")
16
+ }
17
+
18
+ get apiToken() {
19
+ return this.getAttribute("api-key")
20
+ }
21
+
22
+ _initSelection(_$el, callback) {
23
+ const selection = this.getAttribute("selection")
24
+ const product = JSON.parse(selection)
25
+ callback(this._formatResult(product))
26
+ }
27
+
28
+ _formatResult(product) {
29
+ return {
30
+ id: `${Spree.mountedAt()}products/${product.slug}`,
31
+ text: product.name,
32
+ }
33
+ }
34
+
35
+ _searchQuery(value) {
36
+ const slug = value.replace(`${Spree.mountedAt()}products/`, "")
37
+ return `q[slug_eq]=${slug}`
38
+ }
39
+ }
40
+
41
+ customElements.define("alchemy-product-select", ProductSelect)
@@ -0,0 +1 @@
1
+ import "alchemy_solidus/components/product_select"
@@ -10,6 +10,25 @@
10
10
  <% end %>
11
11
  <% end %>
12
12
 
13
+ <style>
14
+ .variant-select-result > * {
15
+ display: flex;
16
+ justify-content: space-between;
17
+ min-height: 16px;
18
+
19
+ > span {
20
+ display: inline-block;
21
+ overflow: hidden;
22
+ text-overflow: ellipsis;
23
+ white-space: nowrap;
24
+ }
25
+
26
+ &:last-child {
27
+ color: hsl(224, 8%, 63%);
28
+ }
29
+ }
30
+ </style>
31
+
13
32
  <script>
14
33
  $('#<%= spree_variant_editor.form_field_id(:variant_id) %>').alchemyVariantSelect({
15
34
  placeholder: "<%= Alchemy.t(:search_variant, scope: 'solidus') %>",
@@ -19,7 +38,8 @@
19
38
  <% if spree_variant_editor.variant %>
20
39
  initialSelection: {
21
40
  id: <%= spree_variant_editor.variant.id %>,
22
- text: "<%= spree_variant_editor.variant.name %>"
41
+ name: "<%= spree_variant_editor.variant.name %>",
42
+ options_text: "<%= spree_variant_editor.variant.options_text %>"
23
43
  }
24
44
  <% end %>
25
45
  })
@@ -0,0 +1,3 @@
1
+ Alchemy.importmap.pin "alchemy_solidus", to: "alchemy_solidus.js", preload: true
2
+ Alchemy.importmap.pin_all_from Alchemy::Solidus::Engine.root.join("app/javascript/alchemy_solidus"),
3
+ under: "alchemy_solidus", preload: true
@@ -52,4 +52,5 @@ end
52
52
 
53
53
  Rails.application.config.after_initialize do
54
54
  Alchemy::Modules.register_module(alchemy_module)
55
+ Alchemy.link_dialog_tabs.add(Alchemy::Admin::LinkDialog::ProductTab)
55
56
  end
@@ -10,6 +10,17 @@ module Alchemy
10
10
  include SolidusSupport::EngineExtensions
11
11
  engine_name "alchemy_solidus"
12
12
 
13
+ initializer "alchemy_solidus.assets", before: "alchemy.importmap" do |app|
14
+ Alchemy.admin_importmaps.add({
15
+ importmap_path: root.join("config/importmap.rb"),
16
+ source_paths: [
17
+ root.join("app/javascript")
18
+ ],
19
+ name: engine_name
20
+ })
21
+ app.config.assets.precompile << "alchemy_solidus/manifest.js"
22
+ end
23
+
13
24
  config.to_prepare do
14
25
  Alchemy.register_ability ::Spree::Ability
15
26
  ::Spree::Ability.register_ability ::Alchemy::Permissions
@@ -1,5 +1,5 @@
1
1
  module Alchemy
2
2
  module Solidus
3
- VERSION = "7.2.1"
3
+ VERSION = "7.3.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alchemy-solidus
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.2.1
4
+ version: 7.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas von Deyen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-05-23 00:00:00.000000000 Z
11
+ date: 2024-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: alchemy_cms
@@ -16,20 +16,20 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 7.0.0
19
+ version: 7.2.0.rc1
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '7.2'
22
+ version: '8'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: 7.0.0
29
+ version: 7.2.0.rc1
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '7.2'
32
+ version: '8'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: solidus_core
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -240,17 +240,22 @@ files:
240
240
  - LICENSE
241
241
  - README.md
242
242
  - Rakefile
243
+ - app/assets/config/alchemy_solidus/manifest.js
243
244
  - app/assets/javascripts/alchemy/solidus/admin.js
244
245
  - app/assets/javascripts/alchemy/solidus/admin/product_select.js
245
246
  - app/assets/javascripts/alchemy/solidus/admin/select2_config.js
246
247
  - app/assets/javascripts/alchemy/solidus/admin/taxon_select.js
247
248
  - app/assets/javascripts/alchemy/solidus/admin/variant_select.js
249
+ - app/components/alchemy/admin/link_dialog/product_tab.rb
250
+ - app/components/alchemy/admin/product_select.rb
248
251
  - app/components/alchemy/ingredients/spree_product_view.rb
249
252
  - app/components/alchemy/ingredients/spree_taxon_view.rb
250
253
  - app/components/alchemy/ingredients/spree_variant_view.rb
251
254
  - app/decorators/models/spree/spree_product_decorator.rb
252
255
  - app/decorators/models/spree/spree_taxon_decorator.rb
253
256
  - app/decorators/models/spree/spree_variant_decorator.rb
257
+ - app/javascript/alchemy_solidus.js
258
+ - app/javascript/alchemy_solidus/components/product_select.js
254
259
  - app/models/alchemy/ingredients/spree_product.rb
255
260
  - app/models/alchemy/ingredients/spree_taxon.rb
256
261
  - app/models/alchemy/ingredients/spree_variant.rb
@@ -259,8 +264,6 @@ files:
259
264
  - app/overrides/alchemy/admin/pages/link/product_link_panel.html.erb.deface
260
265
  - app/overrides/alchemy/admin/pages/link/product_link_sl_tab.html.erb.deface
261
266
  - app/overrides/alchemy/admin/pages/link/product_link_tab.html.erb.deface
262
- - app/views/alchemy/admin/pages/_product_link.html.erb
263
- - app/views/alchemy/admin/pages/_product_link_script.html.erb
264
267
  - app/views/alchemy/ingredients/_spree_product_editor.html.erb
265
268
  - app/views/alchemy/ingredients/_spree_product_view.html.erb
266
269
  - app/views/alchemy/ingredients/_spree_taxon_editor.html.erb
@@ -268,6 +271,7 @@ files:
268
271
  - app/views/alchemy/ingredients/_spree_variant_editor.html.erb
269
272
  - app/views/alchemy/ingredients/_spree_variant_view.html.erb
270
273
  - app/views/spree/admin/shared/_alchemy_sub_menu.html.erb
274
+ - config/importmap.rb
271
275
  - config/initializers/alchemy.rb
272
276
  - config/initializers/spree.rb
273
277
  - config/locales/alchemy_solidus.de.yml
@@ -1,30 +0,0 @@
1
- <form data-link-form-type="product">
2
- <%= render_message do %>
3
- <h3><%= Alchemy.t(:choose_product_to_link) %></h3>
4
- <% end %>
5
- <div class="input select">
6
- <label for="product_link" class="control-label">
7
- <%= Spree::Product.model_name.human %>
8
- </label>
9
- <input type="text" id="product_link" class="alchemy_selectbox full_width">
10
- </div>
11
- <div class="input text">
12
- <label for="product_link_title" class="control-label">
13
- <%= Alchemy.t(:link_title) %>
14
- </label>
15
- <%= text_field_tag "product_link_title", '', class: 'link_title' %>
16
- </div>
17
- <div class="input select">
18
- <label for="product_link_target" class="control-label">
19
- <%= Alchemy.t("Open Link in") %>
20
- </label>
21
- <%= select_tag 'product_link_target',
22
- options_for_select(Alchemy::Page.link_target_options),
23
- class: 'alchemy_selectbox link_target' %>
24
- </div>
25
- <div class="submit">
26
- <%= button_tag Alchemy.t(:apply), class: "create-link button", data: { link_type: "product" } %>
27
- </div>
28
- </form>
29
-
30
- <%= render "product_link_script" %>
@@ -1,47 +0,0 @@
1
- <script>
2
- var $tabs = $("#overlay_tabs")
3
-
4
- $tabs.on("SelectLinkTab.Alchemy", function(event, data) {
5
- $("#product_link").select2("val", data.link.attr("href"))
6
- })
7
- $("#product_link").alchemyProductSelect({
8
- placeholder: "<%= Alchemy.t(:search_product, scope: "solidus") %>",
9
- apiToken: "<%= current_alchemy_user.spree_api_key %>",
10
- baseUrl: "<%= spree.api_products_path %>",
11
- formatResultObject(product) {
12
- return {
13
- id: Spree.mountedAt() + "products/"+ product.slug,
14
- text: product.name,
15
- }
16
- },
17
- initSelection($element, callback) {
18
- var query = $element.val().replace(Spree.mountedAt() + "products/", "")
19
- $.ajax({
20
- url: "<%= spree.api_products_path %>",
21
- data: {
22
- q: { slug_eq: query },
23
- page: 1,
24
- per_page: 1
25
- },
26
- headers: {
27
- Authorization: "Bearer <%= current_alchemy_user.spree_api_key %>"
28
- }
29
- }).done(function(data) {
30
- var product = data.products[0]
31
- if (product) {
32
- callback({
33
- id: Spree.mountedAt() + "products/"+ product.slug,
34
- text: product.name
35
- })
36
- if (typeof $tabs.tabs === "function") {
37
- $tabs.tabs("option", "active",
38
- $("#overlay_tabs > div").index($("#overlay_tab_product_link"))
39
- )
40
- } else {
41
- $tabs.get(0).show('overlay_tab_product_link')
42
- }
43
- }
44
- })
45
- },
46
- })
47
- </script>