third_prestige_rails_admin_charts 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +51 -0
- data/Rakefile +27 -0
- data/app/assets/javascripts/rails_admin_charts/application.coffee +3 -0
- data/app/views/rails_admin/main/_chart.html.erb +56 -0
- data/app/views/rails_admin/main/charts.html.erb +4 -0
- data/config/initializers/rails_admin_charts.rb +19 -0
- data/config/locales/en.yml +7 -0
- data/lib/rails_admin_charts/engine.rb +7 -0
- data/lib/rails_admin_charts/rails_admin/config/actions/charts.rb +30 -0
- data/lib/rails_admin_charts/version.rb +3 -0
- data/lib/rails_admin_charts.rb +33 -0
- data/lib/tasks/rails_admin_charts_tasks.rake +4 -0
- metadata +98 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0f8f1083eea1355e1285deddad4e28b1bc369d51
|
4
|
+
data.tar.gz: 829cdbbb70a092fc9e9970eb1de703f0e5e2f243
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 816de75c600888aff1b901786231823c9be67d459a5b6d83127f3b69a5d2a8970c2f63251164e5c854a4984deb31a7836a3e29441d84eb8ab96d1a9bf34e6165
|
7
|
+
data.tar.gz: 5ecb264fb1f3f4e282d93c9fc03c1d3ef7143c91d5852327a75304b766d9da2fe68325dc8474c1aa2cc173674fcd13ce704a4e68877f050db4d5ac792263dbdf
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2013 YOURNAME
|
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,51 @@
|
|
1
|
+
= RailsAdminCharts
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
In your `Gemfile`, add the following dependency:
|
6
|
+
|
7
|
+
gem 'rails_admin_charts'
|
8
|
+
|
9
|
+
Run:
|
10
|
+
|
11
|
+
$ bundle install
|
12
|
+
|
13
|
+
This will include the lazy_high_charts gem and add the assets to the pipeline.
|
14
|
+
|
15
|
+
In your RailsAdmin initializer (`app/config/initializers/rails_admin.rb`), enable the action by adding:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
config.actions do
|
19
|
+
charts
|
20
|
+
end
|
21
|
+
```
|
22
|
+
|
23
|
+
For any model where you wish to display a chart (defaults to a cumulative total showing the last 100 days), add the following just under the class declaration:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
include RailsAdminCharts
|
27
|
+
```
|
28
|
+
|
29
|
+
This adds the methods `delta_records_since` and `total_records_since` to your model, alongside `graph_data` which utilises them.
|
30
|
+
The data displayed in the chart can be altered by overriding the class method `graph_data` in your model, for example in the case of a User model using single table inheritance:
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
def self.graph_data since=30.days.ago
|
34
|
+
[
|
35
|
+
{
|
36
|
+
name: 'Admin Users',
|
37
|
+
pointInterval: point_interval = 1.day * 1000,
|
38
|
+
pointStart: start_point = since.to_i * 1000,
|
39
|
+
data: self.where(type: 'Admin').delta_records_since(since)
|
40
|
+
},
|
41
|
+
{
|
42
|
+
name: 'Standard Users',
|
43
|
+
pointInterval: point_interval,
|
44
|
+
pointStart: start_point,
|
45
|
+
data: self.where(type: nil).delta_records_since(since)
|
46
|
+
}
|
47
|
+
]
|
48
|
+
end
|
49
|
+
```
|
50
|
+
|
51
|
+
This project uses MIT-LICENSE.
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'rdoc/task'
|
9
|
+
rescue LoadError
|
10
|
+
require 'rdoc/rdoc'
|
11
|
+
require 'rake/rdoctask'
|
12
|
+
RDoc::Task = Rake::RDocTask
|
13
|
+
end
|
14
|
+
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
17
|
+
rdoc.title = 'RailsAdminCharts'
|
18
|
+
rdoc.options << '--line-numbers'
|
19
|
+
rdoc.rdoc_files.include('README.md')
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
Bundler::GemHelper.install_tasks
|
27
|
+
|
@@ -0,0 +1,56 @@
|
|
1
|
+
<script type="text/javascript">
|
2
|
+
$(function () {
|
3
|
+
var chart;
|
4
|
+
$(document).ready(function() {
|
5
|
+
chart = new Highcharts.Chart({
|
6
|
+
chart: {
|
7
|
+
renderTo: 'growth_rate'
|
8
|
+
},
|
9
|
+
title: {
|
10
|
+
text: '<%= @abstract_model.to_s.pluralize %>'
|
11
|
+
},
|
12
|
+
xAxis: {
|
13
|
+
type: 'datetime'
|
14
|
+
},
|
15
|
+
// yAxis: {
|
16
|
+
// title: {
|
17
|
+
// text: 'Counts'
|
18
|
+
// }
|
19
|
+
// },
|
20
|
+
tooltip: {
|
21
|
+
formatter: function() {
|
22
|
+
return ''+
|
23
|
+
Highcharts.dateFormat('%e. %b', this.x) +' -> '+ this.y;
|
24
|
+
}
|
25
|
+
},
|
26
|
+
plotOptions: {
|
27
|
+
spline: {
|
28
|
+
lineWidth: 4,
|
29
|
+
states: {
|
30
|
+
hover: {
|
31
|
+
lineWidth: 5
|
32
|
+
}
|
33
|
+
},
|
34
|
+
marker: {
|
35
|
+
enabled: false,
|
36
|
+
states: {
|
37
|
+
hover: {
|
38
|
+
enabled: true,
|
39
|
+
symbol: 'circle',
|
40
|
+
radius: 5,
|
41
|
+
lineWidth: 1
|
42
|
+
}
|
43
|
+
}
|
44
|
+
}
|
45
|
+
}
|
46
|
+
},
|
47
|
+
series: <%=raw @abstract_model.model.graph_data(100.days.ago).to_json %>,
|
48
|
+
navigation: {
|
49
|
+
menuItemStyle: {
|
50
|
+
fontSize: '10px'
|
51
|
+
}
|
52
|
+
}
|
53
|
+
});
|
54
|
+
});
|
55
|
+
});
|
56
|
+
</script>
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'rails_admin/main_controller'
|
2
|
+
module RailsAdmin
|
3
|
+
class MainController < RailsAdmin::ApplicationController
|
4
|
+
def charts
|
5
|
+
get_model
|
6
|
+
#get_object
|
7
|
+
action = RailsAdmin::Config::Actions.find(:charts)
|
8
|
+
#@authorization_adapter.try(:authorize, action.authorization_key, @abstract_model, @object)
|
9
|
+
@action = action.with({controller: self, abstract_model: @abstract_model})
|
10
|
+
@page_name = wording_for(:title)
|
11
|
+
#
|
12
|
+
#if request.get?
|
13
|
+
#elsif request.post?
|
14
|
+
#end
|
15
|
+
#redirect_to back_or_index
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module RailsAdmin
|
2
|
+
module Config
|
3
|
+
module Actions
|
4
|
+
class Charts < RailsAdmin::Config::Actions::Base
|
5
|
+
RailsAdmin::Config::Actions.register(self)
|
6
|
+
|
7
|
+
register_instance_option :collection? do
|
8
|
+
true
|
9
|
+
end
|
10
|
+
|
11
|
+
register_instance_option :visible do
|
12
|
+
bindings[:abstract_model].model < RailsAdminCharts
|
13
|
+
end
|
14
|
+
|
15
|
+
register_instance_option :http_methods do
|
16
|
+
[:get, :post, :delete]
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
register_instance_option :pjax? do
|
21
|
+
false
|
22
|
+
end
|
23
|
+
|
24
|
+
register_instance_option :link_icon do
|
25
|
+
'icon-bar-chart'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'lazy_high_charts/engine'
|
2
|
+
require 'rails_admin_charts/engine'
|
3
|
+
|
4
|
+
module RailsAdminCharts
|
5
|
+
def self.included(base)
|
6
|
+
base.extend(ClassMethods)
|
7
|
+
end
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
def total_records_since(since = 30.days.ago)
|
11
|
+
totals, before_count = self.group('DATE(created_at)').count, self.where('created_at < ?', since.to_date).count
|
12
|
+
(since.to_date..Date.today).each_with_object([]) { |day, a| a << (a.last || before_count) + (totals[day] || 0) }
|
13
|
+
end
|
14
|
+
|
15
|
+
def delta_records_since(since = 30.days.ago)
|
16
|
+
deltas = self.group('DATE(created_at)').count
|
17
|
+
(since.to_date..Date.today).map { |date| deltas[date] || 0 }
|
18
|
+
end
|
19
|
+
|
20
|
+
def graph_data since=30.days.ago
|
21
|
+
[
|
22
|
+
{
|
23
|
+
name: model_name.pluralize,
|
24
|
+
pointInterval: 1.day * 1000,
|
25
|
+
pointStart: since.to_i * 1000,
|
26
|
+
data: self.total_records_since(since)
|
27
|
+
}
|
28
|
+
]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
require 'rails_admin_charts/rails_admin/config/actions/charts'
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: third_prestige_rails_admin_charts
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.6
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Paul Geraghty
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rails_admin
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>'
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>'
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: lazy_high_charts
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.4.3
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.4.3
|
55
|
+
description: Per-Model HighCharts for Rails Admin
|
56
|
+
email:
|
57
|
+
- pgeraghty07@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- app/assets/javascripts/rails_admin_charts/application.coffee
|
63
|
+
- app/views/rails_admin/main/_chart.html.erb
|
64
|
+
- app/views/rails_admin/main/charts.html.erb
|
65
|
+
- config/initializers/rails_admin_charts.rb
|
66
|
+
- config/locales/en.yml
|
67
|
+
- lib/rails_admin_charts/engine.rb
|
68
|
+
- lib/rails_admin_charts/rails_admin/config/actions/charts.rb
|
69
|
+
- lib/rails_admin_charts/version.rb
|
70
|
+
- lib/rails_admin_charts.rb
|
71
|
+
- lib/tasks/rails_admin_charts_tasks.rake
|
72
|
+
- MIT-LICENSE
|
73
|
+
- Rakefile
|
74
|
+
- README.md
|
75
|
+
homepage: https://github.com/pgeraghty/rails_admin_charts
|
76
|
+
licenses: []
|
77
|
+
metadata: {}
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 2.0.3
|
95
|
+
signing_key:
|
96
|
+
specification_version: 4
|
97
|
+
summary: Charts for Rails Admin
|
98
|
+
test_files: []
|