alchemy-solidus 7.2.0 → 7.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/config/alchemy_solidus/manifest.js +1 -0
- data/app/components/alchemy/admin/link_dialog/product_tab.rb +57 -0
- data/app/components/alchemy/admin/product_select.rb +44 -0
- data/app/decorators/models/spree/spree_product_decorator.rb +15 -0
- data/app/javascript/alchemy_solidus/components/product_select.js +41 -0
- data/app/javascript/alchemy_solidus.js +1 -0
- data/config/importmap.rb +3 -0
- data/config/initializers/alchemy.rb +1 -0
- data/lib/alchemy/solidus/engine.rb +11 -0
- data/lib/alchemy/solidus/version.rb +1 -1
- metadata +10 -6
- data/app/views/alchemy/admin/pages/_product_link.html.erb +0 -30
- data/app/views/alchemy/admin/pages/_product_link_script.html.erb +0 -47
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 823fe7fab5027f254ca1440418ca0f5957e3e4825dba007096b8fd5268694141
|
4
|
+
data.tar.gz: cb223e06aa86c2a2cffed82b594e03d6febe9004b0fe55787b47b2ce76a5c3a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
@@ -7,6 +7,21 @@ module Spree
|
|
7
7
|
base.has_many :alchemy_ingredients, class_name: "Alchemy::Ingredients::SpreeProduct", as: :related_object, dependent: :nullify
|
8
8
|
end
|
9
9
|
|
10
|
+
private
|
11
|
+
|
12
|
+
# Overwritten Solidus' default behavior
|
13
|
+
#
|
14
|
+
# The Solidus implementation did not trigger `touch` on taxons, but
|
15
|
+
# updated the `updated_at` timestamp in an `update_all`.
|
16
|
+
#
|
17
|
+
# Since we want to invalidate ingredient spree taxons cache as well
|
18
|
+
# we need to use `touch` here and use the `after_touch` callback of
|
19
|
+
# Spree::Taxon
|
20
|
+
#
|
21
|
+
def touch_taxons
|
22
|
+
taxons.each(&:touch)
|
23
|
+
end
|
24
|
+
|
10
25
|
::Spree::Product.prepend self
|
11
26
|
end
|
12
27
|
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"
|
data/config/importmap.rb
ADDED
@@ -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
|
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.
|
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-
|
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,7 +16,7 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 7.0.
|
19
|
+
version: 7.2.0.rc1
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: '8'
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 7.0.
|
29
|
+
version: 7.2.0.rc1
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '8'
|
@@ -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>
|