my_dashboard 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (148) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +13 -0
  3. data/.travis.yml +9 -0
  4. data/CHANGELOG.md +23 -0
  5. data/Gemfile +20 -0
  6. data/MIT-LICENSE +20 -0
  7. data/README.md +223 -0
  8. data/Rakefile +7 -0
  9. data/app/assets/javascripts/my_dashboard/application.js +17 -0
  10. data/app/assets/javascripts/my_dashboard/my_dashboard.coffee +0 -0
  11. data/app/assets/stylesheets/my_dashboard/application.css +13 -0
  12. data/app/controllers/my_dashboard/application_controller.rb +23 -0
  13. data/app/controllers/my_dashboard/dashboards_controller.rb +31 -0
  14. data/app/controllers/my_dashboard/events_controller.rb +28 -0
  15. data/app/controllers/my_dashboard/widgets_controller.rb +45 -0
  16. data/app/helpers/my_dashboard/application_helper.rb +4 -0
  17. data/app/views/layouts/my_dashboard/dashboard.html.erb +30 -0
  18. data/app/views/my_dashboard/widgets/clock.html +2 -0
  19. data/app/views/my_dashboard/widgets/comments.html +7 -0
  20. data/app/views/my_dashboard/widgets/graph.html +5 -0
  21. data/app/views/my_dashboard/widgets/iframe.html +1 -0
  22. data/app/views/my_dashboard/widgets/image.html +1 -0
  23. data/app/views/my_dashboard/widgets/list.html +18 -0
  24. data/app/views/my_dashboard/widgets/meter.html +7 -0
  25. data/app/views/my_dashboard/widgets/number.html +11 -0
  26. data/app/views/my_dashboard/widgets/text.html +7 -0
  27. data/bin/rails +8 -0
  28. data/config/routes.rb +15 -0
  29. data/lib/assets/javascripts/my_dashboard.gridster.coffee +0 -0
  30. data/lib/generators/my_dashboard/install_generator.rb +36 -0
  31. data/lib/generators/my_dashboard/job_generator.rb +15 -0
  32. data/lib/generators/my_dashboard/widget_generator.rb +17 -0
  33. data/lib/generators/templates/dashboards/sample.html.erb +28 -0
  34. data/lib/generators/templates/initializer.rb +58 -0
  35. data/lib/generators/templates/jobs/new.rb +3 -0
  36. data/lib/generators/templates/jobs/sample.rb +9 -0
  37. data/lib/generators/templates/layouts/dashboard.html.erb +30 -0
  38. data/lib/generators/templates/widgets/index.css +12 -0
  39. data/lib/generators/templates/widgets/index.js +13 -0
  40. data/lib/generators/templates/widgets/new.coffee +9 -0
  41. data/lib/generators/templates/widgets/new.html +1 -0
  42. data/lib/generators/templates/widgets/new.scss +10 -0
  43. data/lib/my_dashboard.rb +50 -0
  44. data/lib/my_dashboard/configuration.rb +63 -0
  45. data/lib/my_dashboard/engine.rb +7 -0
  46. data/lib/my_dashboard/railtie.rb +31 -0
  47. data/lib/my_dashboard/version.rb +3 -0
  48. data/lib/tasks/my_dashboard_tasks.rake +4 -0
  49. data/my_dashboard.gemspec +31 -0
  50. data/spec/controllers/my_dashboard/application_controller_spec.rb +21 -0
  51. data/spec/controllers/my_dashboard/dashboards_controller_spec.rb +46 -0
  52. data/spec/controllers/my_dashboard/events_controller_spec.rb +11 -0
  53. data/spec/controllers/my_dashboard/widgets_controller_spec.rb +72 -0
  54. data/spec/dummy/README.rdoc +28 -0
  55. data/spec/dummy/Rakefile +6 -0
  56. data/spec/dummy/app/assets/images/.keep +0 -0
  57. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  58. data/spec/dummy/app/assets/javascripts/my_dashboard/widgets/foo.coffee +0 -0
  59. data/spec/dummy/app/assets/javascripts/my_dashboard/widgets/index.js +13 -0
  60. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  61. data/spec/dummy/app/assets/stylesheets/my_dashboard/widgets/foo.scss +0 -0
  62. data/spec/dummy/app/assets/stylesheets/my_dashboard/widgets/index.css +12 -0
  63. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  64. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  65. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  66. data/spec/dummy/app/jobs/sample.rb +9 -0
  67. data/spec/dummy/app/mailers/.keep +0 -0
  68. data/spec/dummy/app/models/.keep +0 -0
  69. data/spec/dummy/app/models/concerns/.keep +0 -0
  70. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  71. data/spec/dummy/app/views/layouts/my_dashboard/dashboard.html.erb +30 -0
  72. data/spec/dummy/app/views/my_dashboard/dashboards/foo.erb +0 -0
  73. data/spec/dummy/app/views/my_dashboard/dashboards/sample.html.erb +28 -0
  74. data/spec/dummy/app/views/my_dashboard/widgets/foo.html +0 -0
  75. data/spec/dummy/bin/bundle +3 -0
  76. data/spec/dummy/bin/rails +4 -0
  77. data/spec/dummy/bin/rake +4 -0
  78. data/spec/dummy/config.ru +4 -0
  79. data/spec/dummy/config/application.rb +23 -0
  80. data/spec/dummy/config/boot.rb +5 -0
  81. data/spec/dummy/config/database.yml +25 -0
  82. data/spec/dummy/config/environment.rb +5 -0
  83. data/spec/dummy/config/environments/development.rb +29 -0
  84. data/spec/dummy/config/environments/production.rb +80 -0
  85. data/spec/dummy/config/environments/test.rb +36 -0
  86. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  87. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  88. data/spec/dummy/config/initializers/inflections.rb +16 -0
  89. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  90. data/spec/dummy/config/initializers/my_dashboard.rb +58 -0
  91. data/spec/dummy/config/initializers/secret_token.rb +12 -0
  92. data/spec/dummy/config/initializers/session_store.rb +3 -0
  93. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  94. data/spec/dummy/config/locales/en.yml +23 -0
  95. data/spec/dummy/config/routes.rb +3 -0
  96. data/spec/dummy/lib/assets/.keep +0 -0
  97. data/spec/dummy/log/.keep +0 -0
  98. data/spec/dummy/public/404.html +58 -0
  99. data/spec/dummy/public/422.html +58 -0
  100. data/spec/dummy/public/500.html +57 -0
  101. data/spec/dummy/public/favicon.ico +0 -0
  102. data/spec/lib/generators/widget_generator_spec.rb +26 -0
  103. data/spec/lib/my_dashboard/configuration_spec.rb +66 -0
  104. data/spec/lib/my_dashboard_spec.rb +55 -0
  105. data/spec/spec_helper.rb +52 -0
  106. data/spec/support/controller_spec_helpers.rb +9 -0
  107. data/vendor/assets/fonts/my_dashboard/fontawesome-webfont.eot +0 -0
  108. data/vendor/assets/fonts/my_dashboard/fontawesome-webfont.svg +414 -0
  109. data/vendor/assets/fonts/my_dashboard/fontawesome-webfont.ttf +0 -0
  110. data/vendor/assets/fonts/my_dashboard/fontawesome-webfont.woff +0 -0
  111. data/vendor/assets/javascripts/my_dashboard/batman.jquery.js +163 -0
  112. data/vendor/assets/javascripts/my_dashboard/batman.js +13680 -0
  113. data/vendor/assets/javascripts/my_dashboard/d3-3.2.8.min.js +5 -0
  114. data/vendor/assets/javascripts/my_dashboard/default_widgets/clock.coffee +18 -0
  115. data/vendor/assets/javascripts/my_dashboard/default_widgets/comments.coffee +24 -0
  116. data/vendor/assets/javascripts/my_dashboard/default_widgets/graph.coffee +37 -0
  117. data/vendor/assets/javascripts/my_dashboard/default_widgets/iframe.coffee +9 -0
  118. data/vendor/assets/javascripts/my_dashboard/default_widgets/image.coffee +9 -0
  119. data/vendor/assets/javascripts/my_dashboard/default_widgets/index.js +13 -0
  120. data/vendor/assets/javascripts/my_dashboard/default_widgets/list.coffee +6 -0
  121. data/vendor/assets/javascripts/my_dashboard/default_widgets/meter.coffee +14 -0
  122. data/vendor/assets/javascripts/my_dashboard/default_widgets/number.coffee +25 -0
  123. data/vendor/assets/javascripts/my_dashboard/default_widgets/text.coffee +1 -0
  124. data/vendor/assets/javascripts/my_dashboard/es5-shim.js +1021 -0
  125. data/vendor/assets/javascripts/my_dashboard/index.js +21 -0
  126. data/vendor/assets/javascripts/my_dashboard/jquery.gridster.js +3987 -0
  127. data/vendor/assets/javascripts/my_dashboard/jquery.js +4 -0
  128. data/vendor/assets/javascripts/my_dashboard/jquery.knob.js +646 -0
  129. data/vendor/assets/javascripts/my_dashboard/jquery.leanModal.min.js +5 -0
  130. data/vendor/assets/javascripts/my_dashboard/jquery.timeago.js +184 -0
  131. data/vendor/assets/javascripts/my_dashboard/moment.min.js +6 -0
  132. data/vendor/assets/javascripts/my_dashboard/my_dashboard.coffee +0 -0
  133. data/vendor/assets/javascripts/my_dashboard/rickshaw-1.5.1.min.js +3 -0
  134. data/vendor/assets/stylesheets/my_dashboard/font-awesome.scss +1338 -0
  135. data/vendor/assets/stylesheets/my_dashboard/index.css +15 -0
  136. data/vendor/assets/stylesheets/my_dashboard/jquery.gridster.css +121 -0
  137. data/vendor/assets/stylesheets/my_dashboard/my_dashboard.scss +302 -0
  138. data/vendor/assets/stylesheets/my_dashboard/widgets/clock.scss +13 -0
  139. data/vendor/assets/stylesheets/my_dashboard/widgets/comments.scss +33 -0
  140. data/vendor/assets/stylesheets/my_dashboard/widgets/graph.scss +65 -0
  141. data/vendor/assets/stylesheets/my_dashboard/widgets/iframe.scss +8 -0
  142. data/vendor/assets/stylesheets/my_dashboard/widgets/image.scss +13 -0
  143. data/vendor/assets/stylesheets/my_dashboard/widgets/index.css +12 -0
  144. data/vendor/assets/stylesheets/my_dashboard/widgets/list.scss +60 -0
  145. data/vendor/assets/stylesheets/my_dashboard/widgets/meter.scss +35 -0
  146. data/vendor/assets/stylesheets/my_dashboard/widgets/number.scss +39 -0
  147. data/vendor/assets/stylesheets/my_dashboard/widgets/text.scss +32 -0
  148. metadata +373 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6921062316bf4ad1280f750f749cf920536bb003
4
+ data.tar.gz: 9ed70991cdcbea1d76d96303a916f75d50d845d2
5
+ SHA512:
6
+ metadata.gz: f80dc506499fe6ac919db9a73fa39bf7e47a5da63d688ba07a6d2c65e238d8788ad42857b79061010d2eaee7032917af9479e68aab8669be17eca7e57e0d2520
7
+ data.tar.gz: 3f1b4b8a365a5025e4e4e8f3eb4e3108b6783f455c9e07363d2f5e32d16aea8ae9cf867ecf4cff8ab9aec810519183d62e3b874236c849cf34807ea8dca3f83d
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ .bundle/
2
+ log/*.log
3
+ pkg/
4
+ Gemfile.lock
5
+ spec/dummy/db/*.sqlite3
6
+ spec/dummy/db/*.sqlite3-journal
7
+ spec/dummy/log/*.log
8
+ spec/dummy/tmp/
9
+ spec/dummy/.sass-cache
10
+ .coveralls.yml
11
+ coverage/
12
+ test_widget.*
13
+ .DS_Store
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ bundler_args: "--without development"
2
+ language: ruby
3
+ rvm:
4
+ - 2.0.0
5
+ - 2.2.0
6
+ - 2.3.0
7
+ env:
8
+ global:
9
+ secure: R4h1vcshVXcsPmJEAspuY/XBHxyNXbh3jhD7y4VMOZ4MuIgL4Yy+OeMY/+mB74zsbsU/vpcL4gSR72G3so3s/Z/5f8B1CjOlPuIx2W5xlX0O0Duj7dNhWv5MxV2l5lseVEJlN1x+gowfnRJRFWCfzpNSaMRPCrCndQJuWfJyAI27q1HR6kH5Y+AYN6lRssUK1ecNeWlT95COj3l53bgztZr4LPvM0w6B15HR3flJo8B1e/VokLYG3ScjbcZQCU1OItE8mi/CgCkwzIZ7KkBmhsMEPx8to9Ud1ETXwQ+0waGWtbhTxvoRR3ArZsNS4oJfT9hfDTKZIWnQhMXmE9xS+qy2UnW5xF81ng8+bX3/saR0k1LYgVKgWn4NjwUkBw+TD+q1UErqdG2aQbFQqMqsd2+XCbYZW807F/5BxAVPQuQ2h/aMbseO/iFmJctKiCXHO1r4P0X0TkEcYVd3tw34YZM/yczgcXOWSbCKRThjBWCE/zK7S4Rsx0sUn3acRhMCNb26LaLPQctLeGK9UdOf/y5d07SmZ6TSWs9QXVHhBw1RKX1p+n8guZXjuIxQCFsWRGwBlQ14kEovMUrPfsFj2E74C2r3BVXs73PniVe+46e3uvfZYok5tp9PKQgeCm6oH5uROBOw7eCa1UsWYfujzIbMPPFHergjNOev6I34UyE=
data/CHANGELOG.md ADDED
@@ -0,0 +1,23 @@
1
+ ## 0.4.1 (05/17/2016)
2
+
3
+ * Add FlexBox support
4
+ * Removes Batman.js
5
+
6
+ ## 0.3.1 (05/17/2016)
7
+
8
+ * Add Code Climate integration
9
+ * Add Travis CI integration
10
+ * Add Coveralls integration
11
+ * Fix bug method Configuration doesn't load
12
+
13
+ ## 0.2.1 (05/16/2016)
14
+
15
+ * Fix broken parameter .gemspec
16
+
17
+ ## 0.2.0 (05/16/2016)
18
+
19
+ * Add badges for Issues Count, Code Climate, Build Status and Dependency Status
20
+
21
+ ## 0.1.0 (05/16/2016)
22
+
23
+ * Initial public release - [@danilovaz](https://github.com/danilovaz)
data/Gemfile ADDED
@@ -0,0 +1,20 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Declare your gem's dependencies in my_dashboard.gemspec.
4
+ # Bundler will treat runtime dependencies like base dependencies, and
5
+ # development dependencies will be added by default to the :development group.
6
+ gemspec
7
+
8
+ # Declare any dependencies that are still in development here instead of in
9
+ # your gemspec. These might include edge Rails or gems from your path or
10
+ # Git. Remember to move these dependencies to your gemspec before releasing
11
+ # your gem to rubygems.org.
12
+
13
+ group :test, :development do
14
+ gem 'sqlite3'
15
+ gem 'rspec-rails', '~> 2.14'
16
+ gem 'simplecov', require: false
17
+ gem 'coveralls', require: false
18
+ gem 'generator_spec', require: false
19
+ gem 'codeclimate-test-reporter', require: false
20
+ end
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2016 Danilo Vaz
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,223 @@
1
+ # my_dashboard
2
+
3
+ [![Issue Count](https://codeclimate.com/github/danilovaz/my_dashboard/badges/issue_count.svg)](https://codeclimate.com/github/danilovaz/my_dashboard)
4
+ [![Code Climate](https://codeclimate.com/github/danilovaz/my_dashboard/badges/gpa.svg)](https://codeclimate.com/github/danilovaz/my_dashboard)[![Coverage Status](https://coveralls.io/repos/github/danilovaz/my_dashboard/badge.svg?branch=master)](https://coveralls.io/github/danilovaz/my_dashboard?branch=master)
5
+ [![Build Status](https://travis-ci.org/danilovaz/my_dashboard.svg?branch=master)](https://travis-ci.org/danilovaz/my_dashboard)
6
+ [![Dependency Status](https://gemnasium.com/badges/github.com/danilovaz/my_dashboard.svg)](https://gemnasium.com/github.com/danilovaz/my_dashboard)
7
+
8
+ my_dashboard is the Rails Engine version of [Dashing by Shopify](http://shopify.github.io/dashing/) who **uses flexbox** instead [gridster](http://gridster.net/). This is totally inspired by [Dashing-Rails](https://github.com/gottfrois/dashing-rails).
9
+ A huge thanks to Shopify and [Pierre-Louis Gottfrois](https://github.com/gottfrois) for their great work.
10
+
11
+ <img src="https://dl.dropboxusercontent.com/u/29838807/dashing-rails.png" width="600" />
12
+
13
+ ## Introduction
14
+
15
+ my_dashboard is a Rails engine that lets you build beautiful dashboards with [flexbox]().
16
+
17
+ Check out our demo over [here]().
18
+
19
+ Key features:
20
+
21
+ * Use premade widgets, or fully create your own with scss, html, and javascript.
22
+ * Dashboards tottally responsive's using all the power of FlexBox.
23
+ * Widgets harness the power of data bindings to keep things DRY and simple. Powered by batman.js.
24
+ * Use the API to push data to your dashboards, or make use of a simple ruby DSL for fetching data.
25
+ * Drag & Drop interface for re-arranging your widgets.
26
+ * Host your dashboards on Heroku in less than 30 seconds.
27
+
28
+ ## Requirements
29
+
30
+ * Ruby >=1.9.3
31
+ * Rails 4
32
+ * Redis
33
+ * Multi Threaded server ([puma](https://github.com/puma/puma), [rainbows](http://rainbows.rubyforge.org/))
34
+
35
+
36
+ ## Getting Started
37
+
38
+ 1. Install the gem by adding the following in your `Gemfile`:
39
+
40
+ ```ruby
41
+ gem 'my_dashboard'
42
+ ```
43
+
44
+ 2. Install puma server by adding the following in your `Gemfile`:
45
+
46
+ ```ruby
47
+ gem 'puma'
48
+ ```
49
+
50
+ 3. Bundle install
51
+
52
+ ```
53
+ $ bundle
54
+ ```
55
+
56
+ 4. Install the dependencies using the following command:
57
+
58
+ ```
59
+ $ rails g my_dashboard:install
60
+ ```
61
+
62
+ 5. Start redis server:
63
+
64
+ ```
65
+ $ redis-server
66
+ ```
67
+
68
+ 6. Open `config/environments/development.rb` and add:
69
+
70
+ ```ruby
71
+ config.allow_concurrency = true
72
+ ```
73
+
74
+ 7. Start your server (must be a multi threaded server - See [Requirements](https://github.com/danilovaz/my_dashboard#requirements))
75
+
76
+ ```
77
+ $ rails s
78
+ ```
79
+
80
+ 8. Point your browser at [http://localhost:3000/my_dashboard/dashboards](http://localhost:3000/my_dashboard/dashboards) and have fun!
81
+
82
+
83
+ **Important Note:** *We need to update the configuration in development to handle multiple requests at the same time. One request for the page we’re working on, and another request for the Server Sent Event controller.*
84
+
85
+ - - -
86
+
87
+ Every new my_dashboard project comes with sample widgets & sample dashboards for you to explore. The directory is setup as follows:
88
+
89
+ * `app/views/my_dashboard/dashboards` — One .erb file for each dashboard that contains the layout for the widgets.
90
+ * `app/jobs` — Your ruby jobs for fetching data (e.g for calling third party APIs like twitter).
91
+ * `app/assets/javascripts/my_dashboard/widgets/` — A widget's name `.js` file containing your widget's js.
92
+ * `app/assets/stylesheets/my_dashboard/widgets/` — A widget's name `.scss` file containing your widget's css.
93
+ * `app/views/my_dashboard/widgets/` — A widget's name `.html` file containing your widget's html.
94
+ * `app/views/layouts/my_dashboard/` — All your custom layouts where your dashboards and widgets will be included.
95
+
96
+ ## Getting Data Into Your Widgets
97
+
98
+ Providing data to widgets is easy. You specify which widget you want using a widget id, and then pass in the JSON data. There are two ways to do this:
99
+
100
+ ### Jobs
101
+
102
+ my_dashboard uses [rufus-scheduler](http://rufus.rubyforge.org/rufus-scheduler/) to schedule jobs. You can make a new job with `rails g my_dashboard:job sample_job`, which will create a file in the jobs directory called `sample_job.rb`.
103
+
104
+ Example:
105
+
106
+ ```ruby
107
+ # :first_in sets how long it takes before the job is first run. In this case, it is run immediately
108
+ MyDashboard.scheduler.every '1m', first_in: 1.second.since do |job|
109
+ MyDashboard.send_event('karma', { current: rand(1000) })
110
+ end
111
+ ```
112
+
113
+ This job will run every minute, and will send a random number to ALL widgets that have `data-id` set to `"karma"`.
114
+
115
+ You send data using the following method:
116
+
117
+ ```ruby
118
+ MyDashboard.send_event(widget_id, json_formatted_data)
119
+ ```
120
+
121
+ Jobs are where you put stuff such as fetching metrics from a database, or calling a third party API like Twitter. Since the data fetch is happening in only one place, it means that all instances of widgets are in sync.
122
+
123
+ [Server Sent Events](http://www.html5rocks.com/en/tutorials/eventsource/basics/) are used in order to stream data to the dashboards.
124
+
125
+ ### Redis
126
+
127
+ my_dashboard uses [Redis](http://redis.io/) to push and pull data and feed your widgets. Since my_dashboard [Requirements](https://github.com/danilovaz/my_dashboard#requirements) can be quite frustrating, I thought it might be useful to use redis.
128
+
129
+ This way you can have a seperate Rails 4 application (with puma) running your dashboards and push your data to redis from your main Rails 3 application for example.
130
+
131
+ You can specify my_dashboard redis credentials in `config/initializers/my_dashboard.rb`:
132
+
133
+ ```ruby
134
+ config.redis_host = '127.0.0.1'
135
+ config.redis_port = '6379'
136
+ config.redis_password = '123456'
137
+ ```
138
+
139
+ By default my_dashboard subscribed to the following namespace in redis:
140
+
141
+ ```
142
+ my_dashboard_events.*
143
+ ```
144
+
145
+ where `*` can be anything. This give you all the flexibility you need to push to redis. For example the `send_event` method provided by my_dashboard uses the following namespace:
146
+
147
+ ```ruby
148
+ redis.publish("my_dashboard_events.create", {})
149
+ ```
150
+
151
+ You can configure the redis namespace in `config/initializers/my_dashboard.rb`:
152
+
153
+ ```ruby
154
+ config.redis_namespace = 'your_redis_namespace'
155
+ ```
156
+
157
+ ### API
158
+
159
+ #### Widgets
160
+
161
+ Your widgets can be updated directly over HTTP. Post the data you want in json to `/my_dashboard/widgets/widget_id`. For security, you will also have to include your `auth_token` (which you can generate in `config/initializers/my_dashboard.rb`).
162
+
163
+ Example:
164
+
165
+ ```
166
+ curl -X PUT http://localhost:3000/my_dashboard/widgets/welcome -d "widget[text]=my_dashboard is awesome"
167
+ ```
168
+
169
+ or
170
+
171
+ ```
172
+ curl -X PUT http://localhost:3000/my_dashboard/widgets/karma -d "widget[current]=100" -d "auth_token=YOUR_AUTH_TOKEN"
173
+ ```
174
+
175
+ or
176
+
177
+ ```ruby
178
+ HTTParty.post('http://localhost:3000/my_dashboard/widgets/karma',
179
+ body: { auth_token: "YOUR_AUTH_TOKEN", current: 1000 }.to_json)
180
+ ```
181
+
182
+ #### Dasboards
183
+
184
+ The `reload` action provided by [Shopify Dashing](http://shopify.github.io/dashing/) is currently not available.
185
+
186
+ ## Create a new Widget
187
+
188
+ In order to create or add a custom widget to my_dashboard, simply follow the following steps:
189
+
190
+ 1. Run `$ rails g my_dashboard:widget my_widget`
191
+
192
+ 2. Edit `app/views/my_dashboard/widgets/my_widget.html`
193
+
194
+ 3. Edit `app/assets/javascripts/my_dashboard/widgets/my_widget.js`
195
+
196
+ 4. Edit `app/assets/stylesheets/my_dashboard/widgets/my_widget.scss`
197
+
198
+ ## Additional Resources
199
+
200
+ Check out the [wiki](https://github.com/danilovaz/my_dashboard/wiki) for interesting tips such as hosting on Heroku, adding authentication or adding custom widgets.
201
+
202
+ ## Browser Compatibility
203
+
204
+ Tested in Chrome, Safari 6+, and Firefox 15+.
205
+
206
+ Does not work in Internet Explorer because it relies on [Server Sent Events](http://www.html5rocks.com/en/tutorials/eventsource/basics/).
207
+
208
+ ## Contributors
209
+
210
+ * [Shopify Dashing contributors](https://github.com/Shopify/dashing/graphs/contributors)
211
+ * [Dashing-rails contributors](https://github.com/gottfrois/dashing-rails/contributors)
212
+ * [my_dashboard contributors](https://github.com/danilovaz/my_dashboard/contributors)
213
+
214
+
215
+ Special thanks to [Pierre-Louis Gottfrois](https://github.com/gottfrois) for his [Dashing-rails](https://github.com/gottfrois/dashing-rails).
216
+
217
+ All contributions are more than welcome; especially new widgets with supports for flexbox and responsive.
218
+
219
+ Please add spec to your Pull Requests and run them using: ```$ rake```
220
+
221
+ ## License
222
+
223
+ my_dashboard is released under the [MIT license](https://github.com/danilovaz/my_dashboard/blob/master/MIT-LICENSE)
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new('spec')
5
+
6
+ task default: :spec
7
+ task test: :spec
@@ -0,0 +1,17 @@
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 my_dashboard
14
+ //= require_tree .
15
+ //= require my_dashboard.gridster
16
+ //= require default_widgets
17
+ //= require widgets
@@ -0,0 +1,13 @@
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 my_dashboard
12
+ *= require_tree .
13
+ */
@@ -0,0 +1,23 @@
1
+ module MyDashboard
2
+ class ApplicationController < ActionController::Base
3
+
4
+ before_filter :authentication_with_devise
5
+
6
+ private
7
+
8
+ def authentication_with_devise
9
+ MyDashboard.config.devise_allowed_models.each do |model|
10
+ self.send("authenticate_#{model.to_s}!")
11
+ end
12
+ end
13
+
14
+ def check_accessibility
15
+ auth_token = params.delete(:auth_token)
16
+ if !MyDashboard.config.auth_token || auth_token == MyDashboard.config.auth_token
17
+ true
18
+ else
19
+ render nothing: true, status: 401 and return
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,31 @@
1
+ module MyDashboard
2
+ class DashboardsController < ApplicationController
3
+
4
+ before_filter :check_dashboard_name, only: :show
5
+
6
+ rescue_from ActionView::MissingTemplate, with: :template_not_found
7
+
8
+ def index
9
+ render file: dashboard_path(MyDashboard.config.default_dashboard || MyDashboard.first_dashboard || ''), layout: MyDashboard.config.dashboard_layout_path
10
+ end
11
+
12
+ def show
13
+ render file: dashboard_path(params[:name]), layout: MyDashboard.config.dashboard_layout_path
14
+ end
15
+
16
+ private
17
+
18
+ def check_dashboard_name
19
+ raise 'bad dashboard name' unless params[:name] =~ /\A[a-zA-z0-9_\-]+\z/
20
+ end
21
+
22
+ def dashboard_path(name)
23
+ MyDashboard.config.dashboards_views_path.join(name)
24
+ end
25
+
26
+ def template_not_found
27
+ raise "Count not find template for dashboard '#{params[:name]}'. Define your dashboard in #{dashboard_path('')}"
28
+ end
29
+
30
+ end
31
+ end
@@ -0,0 +1,28 @@
1
+ module MyDashboard
2
+ class EventsController < ApplicationController
3
+ include ActionController::Live
4
+
5
+ def index
6
+ response.headers['Content-Type'] = 'text/event-stream'
7
+ response.headers['X-Accel-Buffering'] = 'no'
8
+ response.stream.write latest_events
9
+
10
+ @redis = MyDashboard.redis
11
+ @redis.psubscribe("#{MyDashboard.config.redis_namespace}.*") do |on|
12
+ on.pmessage do |pattern, event, data|
13
+ response.stream.write("data: #{data}\n\n")
14
+ end
15
+ end
16
+ rescue IOError
17
+ logger.info "[MyDashboard][#{Time.now.utc.to_s}] Stream closed"
18
+ ensure
19
+ @redis.quit
20
+ response.stream.close
21
+ end
22
+
23
+ def latest_events
24
+ events = MyDashboard.redis.hvals("#{MyDashboard.config.redis_namespace}.latest")
25
+ events.map { |v| "data: #{v}\n\n" }.join
26
+ end
27
+ end
28
+ end