dashing-rails 1.0.0

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.
Files changed (120) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.md +161 -0
  3. data/Rakefile +6 -0
  4. data/app/assets/fonts/dashing/fontawesome-webfont.eot +0 -0
  5. data/app/assets/fonts/dashing/fontawesome-webfont.svg +255 -0
  6. data/app/assets/fonts/dashing/fontawesome-webfont.ttf +0 -0
  7. data/app/assets/fonts/dashing/fontawesome-webfont.woff +0 -0
  8. data/app/assets/javascripts/dashing/application.js +27 -0
  9. data/app/assets/javascripts/dashing/dashing-src.coffee +110 -0
  10. data/app/assets/javascripts/dashing/dashing.coffee +18 -0
  11. data/app/assets/stylesheets/dashing/application.css +17 -0
  12. data/app/assets/stylesheets/dashing/dashing.scss +250 -0
  13. data/app/controllers/dashing/application_controller.rb +15 -0
  14. data/app/controllers/dashing/dashboards_controller.rb +31 -0
  15. data/app/controllers/dashing/events_controller.rb +25 -0
  16. data/app/controllers/dashing/widgets_controller.rb +50 -0
  17. data/app/helpers/dashing/application_helper.rb +4 -0
  18. data/app/views/dashing/default_widgets/clock/clock.coffee +18 -0
  19. data/app/views/dashing/default_widgets/clock/clock.html +2 -0
  20. data/app/views/dashing/default_widgets/clock/clock.scss +13 -0
  21. data/app/views/dashing/default_widgets/comments/comments.coffee +24 -0
  22. data/app/views/dashing/default_widgets/comments/comments.html +7 -0
  23. data/app/views/dashing/default_widgets/comments/comments.scss +33 -0
  24. data/app/views/dashing/default_widgets/graph/graph.coffee +35 -0
  25. data/app/views/dashing/default_widgets/graph/graph.html +5 -0
  26. data/app/views/dashing/default_widgets/graph/graph.scss +65 -0
  27. data/app/views/dashing/default_widgets/iframe/iframe.coffee +9 -0
  28. data/app/views/dashing/default_widgets/iframe/iframe.html +1 -0
  29. data/app/views/dashing/default_widgets/iframe/iframe.scss +8 -0
  30. data/app/views/dashing/default_widgets/image/image.coffee +9 -0
  31. data/app/views/dashing/default_widgets/image/image.html +1 -0
  32. data/app/views/dashing/default_widgets/image/image.scss +13 -0
  33. data/app/views/dashing/default_widgets/index.css +12 -0
  34. data/app/views/dashing/default_widgets/index.js +13 -0
  35. data/app/views/dashing/default_widgets/list/list.coffee +6 -0
  36. data/app/views/dashing/default_widgets/list/list.html +18 -0
  37. data/app/views/dashing/default_widgets/list/list.scss +60 -0
  38. data/app/views/dashing/default_widgets/meter/meter.coffee +14 -0
  39. data/app/views/dashing/default_widgets/meter/meter.html +7 -0
  40. data/app/views/dashing/default_widgets/meter/meter.scss +35 -0
  41. data/app/views/dashing/default_widgets/number/number.coffee +24 -0
  42. data/app/views/dashing/default_widgets/number/number.html +11 -0
  43. data/app/views/dashing/default_widgets/number/number.scss +39 -0
  44. data/app/views/dashing/default_widgets/text/text.coffee +1 -0
  45. data/app/views/dashing/default_widgets/text/text.html +7 -0
  46. data/app/views/dashing/default_widgets/text/text.scss +32 -0
  47. data/app/views/layouts/dashing/dashboard.html.erb +30 -0
  48. data/config/routes.rb +15 -0
  49. data/lib/assets/javascripts/batman.jquery.js +163 -0
  50. data/lib/assets/javascripts/batman.js +13680 -0
  51. data/lib/assets/javascripts/d3.v2.min.js +4 -0
  52. data/lib/assets/javascripts/dashing.gridster.coffee +35 -0
  53. data/lib/assets/javascripts/es5-shim.js +1021 -0
  54. data/lib/assets/javascripts/jquery.gridster.js +2890 -0
  55. data/lib/assets/javascripts/jquery.js +4 -0
  56. data/lib/assets/javascripts/jquery.knob.js +646 -0
  57. data/lib/assets/javascripts/jquery.leanModal.min.js +5 -0
  58. data/lib/assets/javascripts/jquery.timeago.js +184 -0
  59. data/lib/assets/javascripts/moment.min.js +6 -0
  60. data/lib/assets/javascripts/rickshaw.min.js +2 -0
  61. data/lib/assets/stylesheets/font-awesome.css +303 -0
  62. data/lib/assets/stylesheets/jquery.gridster.css +57 -0
  63. data/lib/dashing.rb +29 -0
  64. data/lib/dashing/configuration.rb +26 -0
  65. data/lib/dashing/engine.rb +13 -0
  66. data/lib/dashing/version.rb +3 -0
  67. data/lib/generators/dashing/install_generator.rb +32 -0
  68. data/lib/generators/dashing/job_generator.rb +15 -0
  69. data/lib/generators/templates/dashboards/sample.html.erb +28 -0
  70. data/lib/generators/templates/initializer.rb +50 -0
  71. data/lib/generators/templates/jobs/new.rb +3 -0
  72. data/lib/generators/templates/jobs/sample.rb +9 -0
  73. data/lib/generators/templates/widgets/index.css +12 -0
  74. data/lib/generators/templates/widgets/index.js +13 -0
  75. data/lib/tasks/dashing_tasks.rake +4 -0
  76. data/spec/controllers/dashing/dashboards_controller_spec.rb +42 -0
  77. data/spec/controllers/dashing/events_controller_spec.rb +11 -0
  78. data/spec/controllers/dashing/widgets_controller_spec.rb +61 -0
  79. data/spec/dummy/README.rdoc +28 -0
  80. data/spec/dummy/Rakefile +6 -0
  81. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  82. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  83. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  84. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  85. data/spec/dummy/app/views/dashing/dashboards/foo.erb +0 -0
  86. data/spec/dummy/app/views/dashing/widgets/foo/foo.coffee +0 -0
  87. data/spec/dummy/app/views/dashing/widgets/foo/foo.html +0 -0
  88. data/spec/dummy/app/views/dashing/widgets/foo/foo.scss +0 -0
  89. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  90. data/spec/dummy/app/views/layouts/dashing/dashboard.html.erb +30 -0
  91. data/spec/dummy/bin/bundle +3 -0
  92. data/spec/dummy/bin/rails +4 -0
  93. data/spec/dummy/bin/rake +4 -0
  94. data/spec/dummy/config.ru +4 -0
  95. data/spec/dummy/config/application.rb +23 -0
  96. data/spec/dummy/config/boot.rb +5 -0
  97. data/spec/dummy/config/database.yml +25 -0
  98. data/spec/dummy/config/environment.rb +5 -0
  99. data/spec/dummy/config/environments/development.rb +29 -0
  100. data/spec/dummy/config/environments/production.rb +80 -0
  101. data/spec/dummy/config/environments/test.rb +36 -0
  102. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  103. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  104. data/spec/dummy/config/initializers/inflections.rb +16 -0
  105. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  106. data/spec/dummy/config/initializers/secret_token.rb +12 -0
  107. data/spec/dummy/config/initializers/session_store.rb +3 -0
  108. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  109. data/spec/dummy/config/locales/en.yml +23 -0
  110. data/spec/dummy/config/routes.rb +4 -0
  111. data/spec/dummy/db/test.sqlite3 +0 -0
  112. data/spec/dummy/log/test.log +27 -0
  113. data/spec/dummy/public/404.html +58 -0
  114. data/spec/dummy/public/422.html +58 -0
  115. data/spec/dummy/public/500.html +57 -0
  116. data/spec/dummy/public/favicon.ico +0 -0
  117. data/spec/lib/dashing/configuration_spec.rb +43 -0
  118. data/spec/lib/dashing_spec.rb +41 -0
  119. data/spec/spec_helper.rb +44 -0
  120. metadata +342 -0
@@ -0,0 +1,57 @@
1
+ /*! gridster.js - v0.1.0 - 2012-08-14
2
+ * http://gridster.net/
3
+ * Copyright (c) 2012 ducksboard; Licensed MIT */
4
+
5
+ .gridster {
6
+ position:relative;
7
+ }
8
+
9
+ .gridster > * {
10
+ margin: 0 auto;
11
+ -webkit-transition: height .4s;
12
+ -moz-transition: height .4s;
13
+ -o-transition: height .4s;
14
+ -ms-transition: height .4s;
15
+ transition: height .4s;
16
+ }
17
+
18
+ .gridster .gs_w{
19
+ z-index: 2;
20
+ position: absolute;
21
+ }
22
+
23
+ .ready .gs_w:not(.preview-holder) {
24
+ -webkit-transition: opacity .3s, left .3s, top .3s;
25
+ -moz-transition: opacity .3s, left .3s, top .3s;
26
+ -o-transition: opacity .3s, left .3s, top .3s;
27
+ transition: opacity .3s, left .3s, top .3s;
28
+ }
29
+
30
+ .gridster .preview-holder {
31
+ z-index: 1;
32
+ position: absolute;
33
+ background-color: #fff;
34
+ border-color: #fff;
35
+ opacity: 0.3;
36
+ }
37
+
38
+ .gridster .player-revert {
39
+ z-index: 10!important;
40
+ -webkit-transition: left .3s, top .3s!important;
41
+ -moz-transition: left .3s, top .3s!important;
42
+ -o-transition: left .3s, top .3s!important;
43
+ transition: left .3s, top .3s!important;
44
+ }
45
+
46
+ .gridster .dragging {
47
+ z-index: 10!important;
48
+ -webkit-transition: all 0s !important;
49
+ -moz-transition: all 0s !important;
50
+ -o-transition: all 0s !important;
51
+ transition: all 0s !important;
52
+ }
53
+
54
+ /* Uncomment this if you set helper : "clone" in draggable options */
55
+ /*.gridster .player {
56
+ opacity:0;
57
+ }*/
@@ -0,0 +1,29 @@
1
+ module Dashing
2
+ class << self
3
+
4
+ delegate :scheduler, :redis, to: :config
5
+
6
+ attr_accessor :configuration
7
+
8
+ def config
9
+ self.configuration ||= Configuration.new
10
+ end
11
+
12
+ def configure
13
+ yield config
14
+ end
15
+
16
+ def first_dashboard
17
+ files = Dir[Rails.root.join(config.dashboards_path, '*')].collect { |f| File.basename(f, '.*') }
18
+ files.sort.first
19
+ end
20
+
21
+ def send_event(id, data)
22
+ redis.publish("#{Dashing.config.redis_namespace}.create", data.merge(id: id, updatedAt: Time.now.utc.to_i).to_json)
23
+ end
24
+
25
+ end
26
+ end
27
+
28
+ require 'dashing/configuration'
29
+ require 'dashing/engine'
@@ -0,0 +1,26 @@
1
+ require 'rufus-scheduler'
2
+ require 'redis'
3
+
4
+ module Dashing
5
+ class Configuration
6
+
7
+ attr_accessor :scheduler, :redis, :view_path, :jobs_path, :redis_namespace,
8
+ :engine_path, :dashboards_path, :dashboard_layout,
9
+ :widgets_path, :default_dashboard, :auth_token
10
+
11
+ def initialize
12
+ @scheduler = ::Rufus::Scheduler.new
13
+ @redis = ::Redis.new
14
+ @redis_namespace = 'dashing_events'
15
+ @view_path = 'app/views/dashing/'
16
+ @jobs_path = 'app/jobs/'
17
+ @engine_path = '/dashing'
18
+ @dashboards_path = 'app/views/dashing/dashboards/'
19
+ @dashboard_layout = 'dashing/dashboard'
20
+ @widgets_path = 'app/views/dashing/widgets/'
21
+ @default_dashboard = nil
22
+ @auth_token = nil
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,13 @@
1
+ module Dashing
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace Dashing
4
+
5
+ config.assets.paths << Dashing::Engine.root.join('app', 'assets', 'fonts')
6
+ config.assets.paths << Dashing::Engine.root.join('app', 'views', 'dashing')
7
+ config.assets.paths << Dashing.config.view_path
8
+
9
+ initializer 'require dashing jobs' do
10
+ Dir[Rails.root.join(Dashing.config.jobs_path, '**', '*.rb')].each { |file| require file }
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module Dashing
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,32 @@
1
+ module Dashing
2
+ module Generators
3
+ class InstallGenerator < ::Rails::Generators::Base
4
+
5
+ source_root File.expand_path('../../templates', __FILE__)
6
+
7
+ desc 'Creates a Dashing initializer for your application.'
8
+
9
+ def install
10
+ route 'mount Dashing::Engine, at: Dashing.config.engine_path'
11
+ end
12
+
13
+ def copy_initializer
14
+ template 'initializer.rb', 'config/initializers/dashing.rb'
15
+ end
16
+
17
+ def copy_dashboard
18
+ template 'dashboards/sample.html.erb', 'app/views/dashing/dashboards/sample.html.erb'
19
+ end
20
+
21
+ def copy_widget_manifests
22
+ template 'widgets/index.css', 'app/views/dashing/widgets/index.css'
23
+ template 'widgets/index.js', 'app/views/dashing/widgets/index.js'
24
+ end
25
+
26
+ def copy_job
27
+ template 'jobs/sample.rb', 'app/jobs/sample.rb'
28
+ end
29
+
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,15 @@
1
+ module Dashing
2
+ module Generators
3
+ class JobGenerator < ::Rails::Generators::NamedBase
4
+
5
+ source_root File.expand_path('../../templates', __FILE__)
6
+
7
+ desc 'Creates a new Dashing job.'
8
+
9
+ def job
10
+ template 'jobs/new.rb', "app/jobs/#{file_name}.rb"
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,28 @@
1
+ <%% content_for :title do %>
2
+ My super sweet dashboard
3
+ <%% end %>
4
+
5
+ <div class="gridster">
6
+ <ul>
7
+ <li data-row="1" data-col="1" data-sizex="2" data-sizey="1">
8
+ <div data-id="welcome" data-view="Text" data-title="Hello" data-text="This is your shiny new dashboard." data-moreinfo="Protip: You can drag the widgets around!"></div>
9
+ </li>
10
+
11
+ <li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
12
+ <div data-id="synergy" data-view="Meter" data-title="Synergy" data-min="0" data-max="100"></div>
13
+ </li>
14
+
15
+ <li data-row="1" data-col="1" data-sizex="1" data-sizey="2">
16
+ <div data-id="buzzwords" data-view="List" data-unordered="true" data-title="Buzzwords" data-moreinfo="# of times said around the office"></div>
17
+ </li>
18
+
19
+ <li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
20
+ <div data-id="valuation" data-view="Number" data-title="Current Valuation" data-moreinfo="In billions" data-prefix="$"></div>
21
+ </li>
22
+
23
+ <li data-row="1" data-col="1" data-sizex="2" data-sizey="1">
24
+ <div data-id="convergence" data-view="Graph" data-title="Convergence" style="background-color:#ff9618"></div>
25
+ </li>
26
+ </ul>
27
+ <center><div style="font-size: 12px">Try this: curl -d '{ "auth_token": "YOUR_AUTH_TOKEN", "text": "Hey, Look what I can do!" }' \http://<%%= request.host %>:<%%= request.port %>/widgets/welcome</div></center>
28
+ </div>
@@ -0,0 +1,50 @@
1
+ # Use this hook to configure Dashing bahaviors.
2
+ Dashing.configure do |config|
3
+ # Scheduler instance.
4
+ # config.scheduler = ::Rufus::Scheduler.new
5
+
6
+ # Redis instance.
7
+ # config.redis = ::Redis.new
8
+
9
+ # Redis namespace when pushing new data.
10
+ # config.redis_namespace = 'dashing_events'
11
+
12
+ # Dashing come with default widgets using css and coffeescript.
13
+ # You can create your own widgets by creating a new folder at the following
14
+ # path by default: `/app/views/dashing/`
15
+ #
16
+ # A widget folder is composed of:
17
+ # - an HTML file used for layout and bindings
18
+ # - a SCSS file for styles
19
+ # - a coffeescript file which allows you to handle incoming data & functionality
20
+ #
21
+ # CSS and JS file will be added to the asset path and the asset pipeline automatically.
22
+ #
23
+ # More information at http://shopify.github.io/dashing/
24
+ # config.view_path = 'app/views/dashing/'
25
+
26
+ # rufus-scheduler worker path
27
+ # config.jobs_path = 'app/jobs/'
28
+
29
+ # Engine path to use for accessing engine's routes.
30
+ # Ex: http://your_app/dashing/dashboard/my_dashboard_name
31
+ # config.engine_path = '/dashing'
32
+
33
+ # The dashboards path used to find dashboards.
34
+ # config.dashboards_path = 'app/views/dashing/dashboards/'
35
+
36
+ # The Dashing layout used to display metrics.
37
+ # config.dashboard_layout = 'dashing/dashboard'
38
+
39
+ # The widgets path used to find your custom widgets.
40
+ # Dashing provide default widgets.
41
+ # config.widgets_path = 'app/views/dashing/widgets/'
42
+
43
+ # Default dashboard name to load when going to /dashing/dashboards
44
+ # config.default_dashboard = nil
45
+
46
+ # A secure random string to authenticate with for curl requests.
47
+ # Put nil if you don't want to use authentication.
48
+ # You can use SecureRandom.hex to generate a hex.
49
+ # config.auth_token = nil
50
+ end
@@ -0,0 +1,3 @@
1
+ Dashing.scheduler.every '1s' do
2
+ Dashing.send_event('widget_id', { value: rand(100) })
3
+ end
@@ -0,0 +1,9 @@
1
+ current_valuation = 0
2
+
3
+ Dashing.scheduler.every '2s' do
4
+ last_valuation = current_valuation
5
+ current_valuation = rand(100)
6
+
7
+ Dashing.send_event('valuation', { current: current_valuation, last: last_valuation })
8
+ Dashing.send_event('synergy', { value: rand(100) })
9
+ end
@@ -0,0 +1,12 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_tree .
12
+ */
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // the compiled file.
9
+ //
10
+ // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
+ // GO AFTER THE REQUIRES BELOW.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :dashing do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dashing::DashboardsController do
4
+
5
+ describe 'GET "index"' do
6
+
7
+ def action
8
+ get :index, use_route: :dashing
9
+ end
10
+
11
+ it 'responds success' do
12
+ action
13
+ expect(response).to be_success
14
+ end
15
+
16
+ end
17
+
18
+ describe 'GET "show"' do
19
+
20
+ def action(params = {})
21
+ get :show, params.merge(use_route: :dashing)
22
+ end
23
+
24
+ context 'when template exists' do
25
+
26
+ it 'responds success' do
27
+ action(name: 'foo')
28
+ expect(response).to be_success
29
+ end
30
+
31
+ end
32
+
33
+ context 'when template does not exist' do
34
+
35
+ it { expect { action }.to raise_error }
36
+ it { expect { action(name: 'bar') }.to raise_error }
37
+
38
+ end
39
+
40
+ end
41
+
42
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dashing::EventsController do
4
+
5
+ describe 'GET "index"' do
6
+
7
+ pending 'Require multithreads spec'
8
+
9
+ end
10
+
11
+ end
@@ -0,0 +1,61 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dashing::WidgetsController do
4
+
5
+ describe 'GET "show"' do
6
+
7
+ def action(params = {})
8
+ get :show, params.merge(use_route: :dashing)
9
+ end
10
+
11
+ context 'when default template exists' do
12
+
13
+ it 'responds success' do
14
+ action(name: 'text')
15
+ expect(response).to be_success
16
+ end
17
+
18
+ end
19
+
20
+ context 'when template exists in main app' do
21
+
22
+ it 'responds success' do
23
+ action(name: 'foo')
24
+ expect(response).to be_success
25
+ end
26
+
27
+ end
28
+
29
+ context 'when template does not exist' do
30
+
31
+ it { expect { action }.to raise_error }
32
+ it { expect { action(name: 'bar') }.to raise_error }
33
+
34
+ end
35
+
36
+ end
37
+
38
+ describe 'PUT "update"' do
39
+
40
+ def action(params = {})
41
+ put :update, params.merge(use_route: :dashing)
42
+ end
43
+
44
+ context 'when valid' do
45
+
46
+ it 'responds success' do
47
+ action(name: 'foo')
48
+ expect(response).to be_success
49
+ end
50
+
51
+ end
52
+
53
+ context 'when not valid' do
54
+
55
+ it { expect { action }.to raise_error }
56
+
57
+ end
58
+
59
+ end
60
+
61
+ end
@@ -0,0 +1,28 @@
1
+ == README
2
+
3
+ This README would normally document whatever steps are necessary to get the
4
+ application up and running.
5
+
6
+ Things you may want to cover:
7
+
8
+ * Ruby version
9
+
10
+ * System dependencies
11
+
12
+ * Configuration
13
+
14
+ * Database creation
15
+
16
+ * Database initialization
17
+
18
+ * How to run the test suite
19
+
20
+ * Services (job queues, cache servers, search engines, etc.)
21
+
22
+ * Deployment instructions
23
+
24
+ * ...
25
+
26
+
27
+ Please feel free to use a different markup language if you do not plan to run
28
+ <tt>rake doc:app</tt>.