my_dashboard 0.4.1
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 +7 -0
- data/.gitignore +13 -0
- data/.travis.yml +9 -0
- data/CHANGELOG.md +23 -0
- data/Gemfile +20 -0
- data/MIT-LICENSE +20 -0
- data/README.md +223 -0
- data/Rakefile +7 -0
- data/app/assets/javascripts/my_dashboard/application.js +17 -0
- data/app/assets/javascripts/my_dashboard/my_dashboard.coffee +0 -0
- data/app/assets/stylesheets/my_dashboard/application.css +13 -0
- data/app/controllers/my_dashboard/application_controller.rb +23 -0
- data/app/controllers/my_dashboard/dashboards_controller.rb +31 -0
- data/app/controllers/my_dashboard/events_controller.rb +28 -0
- data/app/controllers/my_dashboard/widgets_controller.rb +45 -0
- data/app/helpers/my_dashboard/application_helper.rb +4 -0
- data/app/views/layouts/my_dashboard/dashboard.html.erb +30 -0
- data/app/views/my_dashboard/widgets/clock.html +2 -0
- data/app/views/my_dashboard/widgets/comments.html +7 -0
- data/app/views/my_dashboard/widgets/graph.html +5 -0
- data/app/views/my_dashboard/widgets/iframe.html +1 -0
- data/app/views/my_dashboard/widgets/image.html +1 -0
- data/app/views/my_dashboard/widgets/list.html +18 -0
- data/app/views/my_dashboard/widgets/meter.html +7 -0
- data/app/views/my_dashboard/widgets/number.html +11 -0
- data/app/views/my_dashboard/widgets/text.html +7 -0
- data/bin/rails +8 -0
- data/config/routes.rb +15 -0
- data/lib/assets/javascripts/my_dashboard.gridster.coffee +0 -0
- data/lib/generators/my_dashboard/install_generator.rb +36 -0
- data/lib/generators/my_dashboard/job_generator.rb +15 -0
- data/lib/generators/my_dashboard/widget_generator.rb +17 -0
- data/lib/generators/templates/dashboards/sample.html.erb +28 -0
- data/lib/generators/templates/initializer.rb +58 -0
- data/lib/generators/templates/jobs/new.rb +3 -0
- data/lib/generators/templates/jobs/sample.rb +9 -0
- data/lib/generators/templates/layouts/dashboard.html.erb +30 -0
- data/lib/generators/templates/widgets/index.css +12 -0
- data/lib/generators/templates/widgets/index.js +13 -0
- data/lib/generators/templates/widgets/new.coffee +9 -0
- data/lib/generators/templates/widgets/new.html +1 -0
- data/lib/generators/templates/widgets/new.scss +10 -0
- data/lib/my_dashboard.rb +50 -0
- data/lib/my_dashboard/configuration.rb +63 -0
- data/lib/my_dashboard/engine.rb +7 -0
- data/lib/my_dashboard/railtie.rb +31 -0
- data/lib/my_dashboard/version.rb +3 -0
- data/lib/tasks/my_dashboard_tasks.rake +4 -0
- data/my_dashboard.gemspec +31 -0
- data/spec/controllers/my_dashboard/application_controller_spec.rb +21 -0
- data/spec/controllers/my_dashboard/dashboards_controller_spec.rb +46 -0
- data/spec/controllers/my_dashboard/events_controller_spec.rb +11 -0
- data/spec/controllers/my_dashboard/widgets_controller_spec.rb +72 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/images/.keep +0 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/javascripts/my_dashboard/widgets/foo.coffee +0 -0
- data/spec/dummy/app/assets/javascripts/my_dashboard/widgets/index.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/assets/stylesheets/my_dashboard/widgets/foo.scss +0 -0
- data/spec/dummy/app/assets/stylesheets/my_dashboard/widgets/index.css +12 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/controllers/concerns/.keep +0 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/jobs/sample.rb +9 -0
- data/spec/dummy/app/mailers/.keep +0 -0
- data/spec/dummy/app/models/.keep +0 -0
- data/spec/dummy/app/models/concerns/.keep +0 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/app/views/layouts/my_dashboard/dashboard.html.erb +30 -0
- data/spec/dummy/app/views/my_dashboard/dashboards/foo.erb +0 -0
- data/spec/dummy/app/views/my_dashboard/dashboards/sample.html.erb +28 -0
- data/spec/dummy/app/views/my_dashboard/widgets/foo.html +0 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +23 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +29 -0
- data/spec/dummy/config/environments/production.rb +80 -0
- data/spec/dummy/config/environments/test.rb +36 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/my_dashboard.rb +58 -0
- data/spec/dummy/config/initializers/secret_token.rb +12 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +3 -0
- data/spec/dummy/lib/assets/.keep +0 -0
- data/spec/dummy/log/.keep +0 -0
- data/spec/dummy/public/404.html +58 -0
- data/spec/dummy/public/422.html +58 -0
- data/spec/dummy/public/500.html +57 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/lib/generators/widget_generator_spec.rb +26 -0
- data/spec/lib/my_dashboard/configuration_spec.rb +66 -0
- data/spec/lib/my_dashboard_spec.rb +55 -0
- data/spec/spec_helper.rb +52 -0
- data/spec/support/controller_spec_helpers.rb +9 -0
- data/vendor/assets/fonts/my_dashboard/fontawesome-webfont.eot +0 -0
- data/vendor/assets/fonts/my_dashboard/fontawesome-webfont.svg +414 -0
- data/vendor/assets/fonts/my_dashboard/fontawesome-webfont.ttf +0 -0
- data/vendor/assets/fonts/my_dashboard/fontawesome-webfont.woff +0 -0
- data/vendor/assets/javascripts/my_dashboard/batman.jquery.js +163 -0
- data/vendor/assets/javascripts/my_dashboard/batman.js +13680 -0
- data/vendor/assets/javascripts/my_dashboard/d3-3.2.8.min.js +5 -0
- data/vendor/assets/javascripts/my_dashboard/default_widgets/clock.coffee +18 -0
- data/vendor/assets/javascripts/my_dashboard/default_widgets/comments.coffee +24 -0
- data/vendor/assets/javascripts/my_dashboard/default_widgets/graph.coffee +37 -0
- data/vendor/assets/javascripts/my_dashboard/default_widgets/iframe.coffee +9 -0
- data/vendor/assets/javascripts/my_dashboard/default_widgets/image.coffee +9 -0
- data/vendor/assets/javascripts/my_dashboard/default_widgets/index.js +13 -0
- data/vendor/assets/javascripts/my_dashboard/default_widgets/list.coffee +6 -0
- data/vendor/assets/javascripts/my_dashboard/default_widgets/meter.coffee +14 -0
- data/vendor/assets/javascripts/my_dashboard/default_widgets/number.coffee +25 -0
- data/vendor/assets/javascripts/my_dashboard/default_widgets/text.coffee +1 -0
- data/vendor/assets/javascripts/my_dashboard/es5-shim.js +1021 -0
- data/vendor/assets/javascripts/my_dashboard/index.js +21 -0
- data/vendor/assets/javascripts/my_dashboard/jquery.gridster.js +3987 -0
- data/vendor/assets/javascripts/my_dashboard/jquery.js +4 -0
- data/vendor/assets/javascripts/my_dashboard/jquery.knob.js +646 -0
- data/vendor/assets/javascripts/my_dashboard/jquery.leanModal.min.js +5 -0
- data/vendor/assets/javascripts/my_dashboard/jquery.timeago.js +184 -0
- data/vendor/assets/javascripts/my_dashboard/moment.min.js +6 -0
- data/vendor/assets/javascripts/my_dashboard/my_dashboard.coffee +0 -0
- data/vendor/assets/javascripts/my_dashboard/rickshaw-1.5.1.min.js +3 -0
- data/vendor/assets/stylesheets/my_dashboard/font-awesome.scss +1338 -0
- data/vendor/assets/stylesheets/my_dashboard/index.css +15 -0
- data/vendor/assets/stylesheets/my_dashboard/jquery.gridster.css +121 -0
- data/vendor/assets/stylesheets/my_dashboard/my_dashboard.scss +302 -0
- data/vendor/assets/stylesheets/my_dashboard/widgets/clock.scss +13 -0
- data/vendor/assets/stylesheets/my_dashboard/widgets/comments.scss +33 -0
- data/vendor/assets/stylesheets/my_dashboard/widgets/graph.scss +65 -0
- data/vendor/assets/stylesheets/my_dashboard/widgets/iframe.scss +8 -0
- data/vendor/assets/stylesheets/my_dashboard/widgets/image.scss +13 -0
- data/vendor/assets/stylesheets/my_dashboard/widgets/index.css +12 -0
- data/vendor/assets/stylesheets/my_dashboard/widgets/list.scss +60 -0
- data/vendor/assets/stylesheets/my_dashboard/widgets/meter.scss +35 -0
- data/vendor/assets/stylesheets/my_dashboard/widgets/number.scss +39 -0
- data/vendor/assets/stylesheets/my_dashboard/widgets/text.scss +32 -0
- 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
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
|
+
[](https://codeclimate.com/github/danilovaz/my_dashboard)
|
4
|
+
[](https://codeclimate.com/github/danilovaz/my_dashboard)[](https://coveralls.io/github/danilovaz/my_dashboard?branch=master)
|
5
|
+
[](https://travis-ci.org/danilovaz/my_dashboard)
|
6
|
+
[](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,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
|
File without changes
|
@@ -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
|