chartkick-remote 1.1.6 → 1.1.7
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 +4 -4
- data/lib/chartkick/remote/helper.rb +19 -14
- data/lib/chartkick/remote/version.rb +1 -1
- data/spec/controllers/remote_spec.rb +13 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0655801c196c86eb2b4df610851bd01cfe75824a
|
4
|
+
data.tar.gz: 53b374e3dcf082410e144bb944d0cd39dd22cabe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf6ba0aa6def8bbbefbf3422aeb22a9d126b8a4bd6a93c9f1486d3622dfb5cff250baee8d292b890ddb1dd1b74ed8c437bfe740916bd5dfd679a58f3762f5d95
|
7
|
+
data.tar.gz: 43c8828817139754ba395074d24a92c1bd029b654dc2a058700a4d6971b2c50dbf63747fbe0385247949e7d3504b875053822710511f7c7fafdf78d4a0234b12
|
@@ -23,14 +23,8 @@ module Chartkick::Remote
|
|
23
23
|
options = options.dup
|
24
24
|
options.reverse_merge!(controller.chartkick_options) if controller.respond_to?(:chartkick_options)
|
25
25
|
|
26
|
-
|
27
|
-
remote = options.delete(:remote)
|
28
|
-
skip = false
|
29
|
-
|
30
|
-
if remote
|
26
|
+
if remote = options.delete(:remote)
|
31
27
|
@remote_chart_id = (@remote_chart_id || 0) + 1
|
32
|
-
chart_id = controller.params[:_chartkick_remote_chart_id]
|
33
|
-
skip = params[:_chartkick_remote_standalone] && chart_id.to_s != @remote_chart_id.to_s
|
34
28
|
controller.chartkick_remote_blocks ||= {}
|
35
29
|
controller.chartkick_remote_blocks[@remote_chart_id] = block
|
36
30
|
data_source = url_for(params.
|
@@ -40,17 +34,28 @@ module Chartkick::Remote
|
|
40
34
|
data_source = block.call
|
41
35
|
end
|
42
36
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
37
|
+
result = send(:"#{type}_without_remote", data_source, options)
|
38
|
+
|
39
|
+
result = apply_standalone_mode(result) if options.delete(:standalone) && remote
|
40
|
+
|
41
|
+
result
|
42
|
+
end
|
43
|
+
|
44
|
+
def apply_standalone_mode(result)
|
45
|
+
standalone_enabled = params[:_chartkick_remote_standalone].present?
|
46
|
+
|
47
|
+
skip = standalone_enabled && controller.params[:_chartkick_remote_chart_id].to_s != @remote_chart_id.to_s
|
48
48
|
|
49
|
-
if
|
49
|
+
if skip || !standalone_enabled
|
50
|
+
result = '<div>Skipped by Standalone Mode</div>'.html_safe if standalone_enabled
|
50
51
|
standalone_link = link_to 'Standalone',
|
51
52
|
url_for(params.merge(_chartkick_remote_chart_id: @remote_chart_id,
|
52
53
|
_chartkick_remote_standalone: 1))
|
53
|
-
|
54
|
+
result += standalone_link.html_safe
|
55
|
+
elsif standalone_enabled && !skip
|
56
|
+
standalone_link = link_to 'Exit Standalone Mode',
|
57
|
+
url_for(params.except(:_chartkick_remote_chart_id,
|
58
|
+
:_chartkick_remote_standalone))
|
54
59
|
result += standalone_link.html_safe
|
55
60
|
end
|
56
61
|
|
@@ -42,10 +42,22 @@ describe Chartkick::Remote, type: :controller do
|
|
42
42
|
chartkick_remote standalone: true
|
43
43
|
end
|
44
44
|
|
45
|
+
it "shows a link to enter standalone mode" do
|
46
|
+
get :index, format: :html
|
47
|
+
|
48
|
+
expect(response.body).to have_tag :a, { text: 'Standalone', href: '/anonymous.html?_chartkick_remote' }
|
49
|
+
end
|
50
|
+
|
45
51
|
it "does not show any other charts but the selected chart" do
|
46
52
|
get :index, _chartkick_remote_chart_id: 1, _chartkick_remote_standalone: 1, format: :html
|
47
53
|
|
48
|
-
expect(response.body).to have_tag :
|
54
|
+
expect(response.body).to have_tag :a, { text: 'Exit Standalone Mode', href: '/anonymous.html' }
|
55
|
+
end
|
56
|
+
|
57
|
+
it "shows a link to exit standalone mode" do
|
58
|
+
get :index, _chartkick_remote_chart_id: 1, _chartkick_remote_standalone: 1, format: :html
|
59
|
+
|
60
|
+
expect(response.body).to have_tag :a, { text: 'Exit Standalone Mode', href: '/anonymous.html' }
|
49
61
|
end
|
50
62
|
end
|
51
63
|
end
|