dashing-rails 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
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,25 @@
1
+ module Dashing
2
+ class EventsController < ApplicationController
3
+ include ActionController::Live
4
+
5
+ respond_to :html
6
+
7
+ def index
8
+ response.headers['Content-Type'] = 'text/event-stream'
9
+ response.headers['X-Accel-Buffering'] = 'no'
10
+
11
+ redis = Redis.new
12
+ redis.psubscribe("#{Dashing.config.redis_namespace}.*") do |on|
13
+ on.pmessage do |pattern, event, data|
14
+ response.stream.write("data: #{data}\n\n")
15
+ end
16
+ end
17
+ rescue IOError
18
+ logger.info "[Dashing][#{Time.now.utc.to_s}] Stream closed"
19
+ ensure
20
+ redis.quit
21
+ response.stream.close
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,50 @@
1
+ module Dashing
2
+ class WidgetsController < ApplicationController
3
+
4
+ before_filter :check_accessibility, only: :update
5
+ before_filter :check_widget_name, only: [:show, :update]
6
+ before_filter :prepend_view_paths, only: :show
7
+
8
+ rescue_from ActionView::MissingTemplate, with: :template_not_found
9
+
10
+ def show
11
+ render file: withdet_path
12
+ end
13
+
14
+ def update
15
+ data = params[:widget] || {}
16
+ hash = data.merge(id: params[:name], updatedAt: Time.now.utc.to_i)
17
+ Dashing.redis.publish("#{Dashing.config.redis_namespace}.create", hash.to_json)
18
+
19
+ render nothing: true
20
+ end
21
+
22
+ private
23
+
24
+ def check_widget_name
25
+ raise 'bad widget name' unless params[:name] =~ /\A[a-zA-z0-9_\-]+\z/
26
+ end
27
+
28
+ def withdet_path
29
+ "#{params[:name]}/#{params[:name]}"
30
+ end
31
+
32
+ def prepend_view_paths
33
+ prepend_view_path engine_view_path
34
+ prepend_view_path main_app_view_path
35
+ end
36
+
37
+ def engine_view_path
38
+ Dashing::Engine.root.join('app', 'views', 'dashing', 'default_widgets')
39
+ end
40
+
41
+ def main_app_view_path
42
+ Rails.root.join(Dashing.config.widgets_path)
43
+ end
44
+
45
+ def template_not_found
46
+ raise "Count not find template for widget #{params[:name]}. Define your widget in #{main_app_view_path}"
47
+ end
48
+
49
+ end
50
+ end
@@ -0,0 +1,4 @@
1
+ module Dashing
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,18 @@
1
+ class Dashing.Clock extends Dashing.Widget
2
+
3
+ ready: ->
4
+ setInterval(@startTime, 500)
5
+
6
+ startTime: =>
7
+ today = new Date()
8
+
9
+ h = today.getHours()
10
+ m = today.getMinutes()
11
+ s = today.getSeconds()
12
+ m = @formatTime(m)
13
+ s = @formatTime(s)
14
+ @set('time', h + ":" + m + ":" + s)
15
+ @set('date', today.toDateString())
16
+
17
+ formatTime: (i) ->
18
+ if i < 10 then "0" + i else i
@@ -0,0 +1,2 @@
1
+ <h1 data-bind="date"></h1>
2
+ <h2 data-bind="time"></h2>
@@ -0,0 +1,13 @@
1
+ // ----------------------------------------------------------------------------
2
+ // Sass declarations
3
+ // ----------------------------------------------------------------------------
4
+ $background-color: #dc5945;
5
+
6
+ // ----------------------------------------------------------------------------
7
+ // Widget-clock styles
8
+ // ----------------------------------------------------------------------------
9
+ .widget-clock {
10
+
11
+ background-color: $background-color;
12
+
13
+ }
@@ -0,0 +1,24 @@
1
+ class Dashing.Comments extends Dashing.Widget
2
+
3
+ @accessor 'quote', ->
4
+ "“#{@get('current_comment')?.body}”"
5
+
6
+ ready: ->
7
+ @currentIndex = 0
8
+ @commentElem = $(@node).find('.comment-container')
9
+ @nextComment()
10
+ @startCarousel()
11
+
12
+ onData: (data) ->
13
+ @currentIndex = 0
14
+
15
+ startCarousel: ->
16
+ setInterval(@nextComment, 8000)
17
+
18
+ nextComment: =>
19
+ comments = @get('comments')
20
+ if comments
21
+ @commentElem.fadeOut =>
22
+ @currentIndex = (@currentIndex + 1) % comments.length
23
+ @set 'current_comment', comments[@currentIndex]
24
+ @commentElem.fadeIn()
@@ -0,0 +1,7 @@
1
+ <h1 class="title" data-bind="title"></h1>
2
+ <div class="comment-container">
3
+ <h3><img data-bind-src='current_comment.avatar'/><span data-bind='current_comment.name' class="name"></span></h3>
4
+ <p class="comment" data-bind='quote'></p>
5
+ </div>
6
+
7
+ <p class="more-info" data-bind="moreinfo | raw"></p>
@@ -0,0 +1,33 @@
1
+ // ----------------------------------------------------------------------------
2
+ // Sass declarations
3
+ // ----------------------------------------------------------------------------
4
+ $background-color: #eb9c3c;
5
+
6
+ $title-color: rgba(255, 255, 255, 0.7);
7
+ $moreinfo-color: rgba(255, 255, 255, 0.7);
8
+
9
+ // ----------------------------------------------------------------------------
10
+ // Widget-comment styles
11
+ // ----------------------------------------------------------------------------
12
+ .widget-comments {
13
+
14
+ background-color: $background-color;
15
+
16
+ .title {
17
+ color: $title-color;
18
+ margin-bottom: 15px;
19
+ }
20
+
21
+ .name {
22
+ padding-left: 5px;
23
+ }
24
+
25
+ .comment-container {
26
+ display: none;
27
+ }
28
+
29
+ .more-info {
30
+ color: $moreinfo-color;
31
+ }
32
+
33
+ }
@@ -0,0 +1,35 @@
1
+ class Dashing.Graph extends Dashing.Widget
2
+
3
+ @accessor 'current', ->
4
+ return @get('displayedValue') if @get('displayedValue')
5
+ points = @get('points')
6
+ if points
7
+ points[points.length - 1].y
8
+
9
+ ready: ->
10
+ container = $(@node).parent()
11
+ # Gross hacks. Let's fix this.
12
+ width = (Dashing.widget_base_dimensions[0] * container.data("sizex")) + Dashing.widget_margins[0] * 2 * (container.data("sizex") - 1)
13
+ height = (Dashing.widget_base_dimensions[1] * container.data("sizey"))
14
+ @graph = new Rickshaw.Graph(
15
+ element: @node
16
+ width: width
17
+ height: height
18
+ series: [
19
+ {
20
+ color: "#fff",
21
+ data: [{x:0, y:0}]
22
+ }
23
+ ]
24
+ )
25
+
26
+ @graph.series[0].data = @get('points') if @get('points')
27
+
28
+ x_axis = new Rickshaw.Graph.Axis.Time(graph: @graph)
29
+ y_axis = new Rickshaw.Graph.Axis.Y(graph: @graph, tickFormat: Rickshaw.Fixtures.Number.formatKMBT)
30
+ @graph.render()
31
+
32
+ onData: (data) ->
33
+ if @graph
34
+ @graph.series[0].data = data.points
35
+ @graph.render()
@@ -0,0 +1,5 @@
1
+ <h1 class="title" data-bind="title"></h1>
2
+
3
+ <h2 class="value" data-bind="current | prettyNumber | prepend prefix"></h2>
4
+
5
+ <p class="more-info" data-bind="moreinfo"></p>
@@ -0,0 +1,65 @@
1
+ // ----------------------------------------------------------------------------
2
+ // Sass declarations
3
+ // ----------------------------------------------------------------------------
4
+ $background-color: #dc5945;
5
+
6
+ $title-color: rgba(255, 255, 255, 0.7);
7
+ $moreinfo-color: rgba(255, 255, 255, 0.3);
8
+ $tick-color: rgba(0, 0, 0, 0.4);
9
+
10
+
11
+ // ----------------------------------------------------------------------------
12
+ // Widget-graph styles
13
+ // ----------------------------------------------------------------------------
14
+ .widget-graph {
15
+
16
+ background-color: $background-color;
17
+ position: relative;
18
+
19
+
20
+ svg {
21
+ position: absolute;
22
+ opacity: 0.4;
23
+ fill-opacity: 0.4;
24
+ left: 0px;
25
+ top: 0px;
26
+ }
27
+
28
+ .title, .value {
29
+ position: relative;
30
+ z-index: 99;
31
+ }
32
+
33
+ .title {
34
+ color: $title-color;
35
+ }
36
+
37
+ .more-info {
38
+ color: $moreinfo-color;
39
+ font-weight: 600;
40
+ font-size: 20px;
41
+ margin-top: 0;
42
+ }
43
+
44
+ .x_tick {
45
+ position: absolute;
46
+ bottom: 0;
47
+ .title {
48
+ font-size: 20px;
49
+ color: $tick-color;
50
+ opacity: 0.5;
51
+ padding-bottom: 3px;
52
+ }
53
+ }
54
+
55
+ .y_ticks {
56
+ font-size: 20px;
57
+ fill: $tick-color;
58
+ fill-opacity: 1;
59
+ }
60
+
61
+ .domain {
62
+ display: none;
63
+ }
64
+
65
+ }
@@ -0,0 +1,9 @@
1
+ class Dashing.Iframe extends Dashing.Widget
2
+
3
+ ready: ->
4
+ # This is fired when the widget is done being rendered
5
+
6
+ onData: (data) ->
7
+ # Handle incoming data
8
+ # You can access the html node of this widget with `@node`
9
+ # Example: $(@node).fadeOut().fadeIn() will make the node flash each time data comes in.
@@ -0,0 +1 @@
1
+ <iframe data-bind-src="url" frameborder=0></iframe>
@@ -0,0 +1,8 @@
1
+ .widget-iframe {
2
+ padding: 3px 0px 0px 0px !important;
3
+
4
+ iframe {
5
+ width: 100%;
6
+ height: 100%;
7
+ }
8
+ }
@@ -0,0 +1,9 @@
1
+ class Dashing.Image extends Dashing.Widget
2
+
3
+ ready: ->
4
+ # This is fired when the widget is done being rendered
5
+
6
+ onData: (data) ->
7
+ # Handle incoming data
8
+ # You can access the html node of this widget with `@node`
9
+ # Example: $(@node).fadeOut().fadeIn() will make the node flash each time data comes in.
@@ -0,0 +1 @@
1
+ <img data-bind-src="image | prepend '/assets'" data-bind-width="width"/>
@@ -0,0 +1,13 @@
1
+ // ----------------------------------------------------------------------------
2
+ // Sass declarations
3
+ // ----------------------------------------------------------------------------
4
+ $background-color: #4b4b4b;
5
+
6
+ // ----------------------------------------------------------------------------
7
+ // Widget-image styles
8
+ // ----------------------------------------------------------------------------
9
+ .widget-image {
10
+
11
+ background-color: $background-color;
12
+
13
+ }
@@ -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,6 @@
1
+ class Dashing.List extends Dashing.Widget
2
+ ready: ->
3
+ if @get('unordered')
4
+ $(@node).find('ol').remove()
5
+ else
6
+ $(@node).find('ul').remove()
@@ -0,0 +1,18 @@
1
+ <h1 class="title" data-bind="title"></h1>
2
+
3
+ <ol>
4
+ <li data-foreach-item="items">
5
+ <span class="label" data-bind="item.label"></span>
6
+ <span class="value" data-bind="item.value"></span>
7
+ </li>
8
+ </ol>
9
+
10
+ <ul class="list-nostyle">
11
+ <li data-foreach-item="items">
12
+ <span class="label" data-bind="item.label"></span>
13
+ <span class="value" data-bind="item.value"></span>
14
+ </li>
15
+ </ul>
16
+
17
+ <p class="more-info" data-bind="moreinfo"></p>
18
+ <p class="updated-at" data-bind="updatedAtMessage"></p>
@@ -0,0 +1,60 @@
1
+ // ----------------------------------------------------------------------------
2
+ // Sass declarations
3
+ // ----------------------------------------------------------------------------
4
+ $background-color: #12b0c5;
5
+ $value-color: #fff;
6
+
7
+ $title-color: rgba(255, 255, 255, 0.7);
8
+ $label-color: rgba(255, 255, 255, 0.7);
9
+ $moreinfo-color: rgba(255, 255, 255, 0.7);
10
+
11
+ // ----------------------------------------------------------------------------
12
+ // Widget-list styles
13
+ // ----------------------------------------------------------------------------
14
+ .widget-list {
15
+
16
+ background-color: $background-color;
17
+ vertical-align: top;
18
+
19
+ .title {
20
+ color: $title-color;
21
+ }
22
+
23
+ ol, ul {
24
+ margin: 0 15px;
25
+ text-align: left;
26
+ color: $label-color;
27
+ }
28
+
29
+ ol {
30
+ list-style-position: inside;
31
+ }
32
+
33
+ li {
34
+ margin-bottom: 5px;
35
+ }
36
+
37
+ .list-nostyle {
38
+ list-style: none;
39
+ }
40
+
41
+ .label {
42
+ color: $label-color;
43
+ }
44
+
45
+ .value {
46
+ float: right;
47
+ margin-left: 12px;
48
+ font-weight: 600;
49
+ color: $value-color;
50
+ }
51
+
52
+ .updated-at {
53
+ color: rgba(0, 0, 0, 0.3);
54
+ }
55
+
56
+ .more-info {
57
+ color: $moreinfo-color;
58
+ }
59
+
60
+ }