rails_admin_charts 0.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3173317b0a201925dff86d07cec93089900493c2
4
+ data.tar.gz: 65a39407acc0330a8025dd315b005ed3060cbed7
5
+ SHA512:
6
+ metadata.gz: 1fa7af9bc6248ba0e00ff4357c905338a799ae6107e084a078c92053cd8e4596338f062938496f5b539f773258be3ef5f7b7d595fb8218e73b7de68f5025573d
7
+ data.tar.gz: ee91b7271539d2a0b1423cd9ca83d4ec57fc099ac9d5172029a2063b21e13fbb41cf74cd78ae68b01cc9677cb3f6b7bf9fc1fc5ad5293de80f18881643ad5f89
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,43 @@
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
+ 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:
16
+
17
+ ```ruby
18
+ include RailsAdminCharts
19
+ ```
20
+
21
+ This adds the methods `delta_records_since` and `total_records_since` to your model, alongside `graph_data` which utilises them.
22
+ 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:
23
+
24
+ ```ruby
25
+ def self.graph_data since=30.days.ago
26
+ [
27
+ {
28
+ name: 'Admin Users',
29
+ pointInterval: point_interval = 1.day * 1000,
30
+ pointStart: start_point = since.to_i * 1000,
31
+ data: self.where(user_type: 'Admin').delta_records_since(since)
32
+ },
33
+ {
34
+ name: 'Standard Users',
35
+ pointInterval: point_interval,
36
+ pointStart: start_point,
37
+ data: self.where(user_type: nil).delta_records_since(since)
38
+ }
39
+ ]
40
+ end
41
+ ```
42
+
43
+ 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,3 @@
1
+ #= require highcharts
2
+ #= require exporting
3
+ # TEST LOADING
@@ -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,3 @@
1
+ = javascript_include_tag 'rails_admin_charts/application'
2
+ #growth_rate style="min-width: 400px; height: 400px;"
3
+ == render 'chart'
@@ -0,0 +1,18 @@
1
+ module RailsAdmin
2
+ class MainController < RailsAdmin::ApplicationController
3
+ def charts
4
+ get_model
5
+ #get_object
6
+ action = RailsAdmin::Config::Actions.find(:charts)
7
+ #@authorization_adapter.try(:authorize, action.authorization_key, @abstract_model, @object)
8
+ @action = action.with({controller: self, abstract_model: @abstract_model})
9
+ @page_name = wording_for(:title)
10
+ #
11
+ #if request.get?
12
+ #elsif request.post?
13
+ #end
14
+ #redirect_to back_or_index
15
+ end
16
+ end
17
+
18
+ end
@@ -0,0 +1,7 @@
1
+ en:
2
+ admin:
3
+ actions:
4
+ charts:
5
+ title: Charts
6
+ menu: Charts
7
+ breadcrumb: Charts
@@ -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'
@@ -0,0 +1,7 @@
1
+ module RailsAdminCharts
2
+ class Engine < ::Rails::Engine
3
+ initializer 'RailsAdmin precompile hook', group: :all do |app|
4
+ #app.config.assets.precompile += %w(application.js)
5
+ end
6
+ end
7
+ 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,3 @@
1
+ module RailsAdminCharts
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :rails_admin_charts do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_admin_charts
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Paul Geraghty
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-12 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.13
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.13
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.2
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.2
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.slim
65
+ - config/initializers/rails_admin_charts.rb
66
+ - config/locales/en.yml
67
+ - lib/tasks/rails_admin_charts_tasks.rake
68
+ - lib/rails_admin_charts/rails_admin/config/actions/charts.rb
69
+ - lib/rails_admin_charts/version.rb
70
+ - lib/rails_admin_charts/engine.rb
71
+ - lib/rails_admin_charts.rb
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: []