alchemy-solidus 7.2.1 → 7.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7e50bb72fd9136b75ae2b8ea66ca80acb37edf3322f2aa750e0ca1f9bc5e1071
4
- data.tar.gz: b6cbccde4616f51672baf1b45df5f06d11ad63edf13fdb0c1a6f100ee0b9e819
3
+ metadata.gz: 823fe7fab5027f254ca1440418ca0f5957e3e4825dba007096b8fd5268694141
4
+ data.tar.gz: cb223e06aa86c2a2cffed82b594e03d6febe9004b0fe55787b47b2ce76a5c3a0
5
5
  SHA512:
6
- metadata.gz: a8324f5ffbf7fc02fd449f30d6b3bb80378cf188b3b4f6f966bcf95b467437160f0511e37eabf1e19ee6a6ae4bf970fb4491b5f6c99989dff9abf1fdedc59fb1
7
- data.tar.gz: 5dd149df193cfe5638e9abd2d73d127d6c334de0d2a7ab7cebc868b98e34249af41796b4ad3518b9b1a35d50796c616f8609da2d1fee924df41c7c8288369365
6
+ metadata.gz: ff3cadb5fc31dc7603910e487cbaf59e13edf00f764ddb38af6dcd25f745b53e83a286ece56829acb34bcda3711210cb6144ae1cf3488a95cf00a0c48c06ecf2
7
+ data.tar.gz: 061dbe3d8ccf9c1884dac806d44737f9e6e5f0d605da197f517200f2fd2a40dd0a1820c5b08e28d62d02eb3deb07346dbb3de68e55fc91c4b2344844e7efa755
@@ -0,0 +1 @@
1
+ //= link_tree ../../../javascript .js
@@ -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"
@@ -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.0"
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.0
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-24 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>