chartkick-remote 1.1.6 → 1.1.7

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
  SHA1:
3
- metadata.gz: b23f76a69dd77e75b2e4a692ecfb52dc48273c63
4
- data.tar.gz: d2eed42d77b27092177b8fc6d4da6d38bb3b9d08
3
+ metadata.gz: 0655801c196c86eb2b4df610851bd01cfe75824a
4
+ data.tar.gz: 53b374e3dcf082410e144bb944d0cd39dd22cabe
5
5
  SHA512:
6
- metadata.gz: ba0639eda196a091f434ae52a6603f3e8a78f5a806d43b4a8f01256069685551560b6be29d56ef19c354619a76b4daa5ebc19972c27ed07939b41f4497e729ad
7
- data.tar.gz: 004a0af71d3e2bc386dea0caa3e66e0c7e61cbaf6e73b7973acd2e5a41cd7bd35011ba7ff3edec45f099a460cd6a14fa00a124f0e3a81e77a3eda1dc47447a65
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
- standalone = options.delete(:standalone)
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
- if skip
44
- result = '<div>Skipped</div>'.html_safe
45
- else
46
- result = send(:"#{type}_without_remote", data_source, options)
47
- end
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 remote && standalone
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
 
@@ -1,5 +1,5 @@
1
1
  module Chartkick
2
2
  module Remote
3
- VERSION = "1.1.6"
3
+ VERSION = "1.1.7"
4
4
  end
5
5
  end
@@ -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 :div, 'Skipped' #, count: 1
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chartkick-remote
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.6
4
+ version: 1.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew S. Brown