rails_admin_mydash 0.1.6 → 0.1.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b67b99bbf01affa133bba7810b3acf636cf4bd31
4
- data.tar.gz: a6a54c5e092385610db8b80e610f5d7d8b59617f
3
+ metadata.gz: d4e2fbef2752b495ea75283d3859c5cd1d559034
4
+ data.tar.gz: 6c0aed6ea36fdb41af371cd7acab87cb281f52a6
5
5
  SHA512:
6
- metadata.gz: 919e091bf8e8e5cddc4eb636ae0ef4b1837a4e6043dcc9c5433b8353ca84f55b748ba246dac749c2bf2bdeae23f7b857e5ab0895a17a2208ab2fb752cdcb5214
7
- data.tar.gz: 06012d90886d783d6a0e7ae24411849063c74d9a5a82691667508caba30242430c7e24b9de60441506448a133cba5f13b933fa2c1158c1531baf324e43a6d593
6
+ metadata.gz: e2a971bb5a0fda8ba30d76f6bc0e6ab9653d41e97a9eb202ebb6fb19d14f586e3f6f995ec23f24b8c9521af92f0eee226aa71113e1f06f81f85bc5ed30fb1711
7
+ data.tar.gz: ec4b39eba036a12f63c1f932bc1b03ab7405703e26023e740e8bf96ce4a589c3a0b228fbc9915a3d3799ea988631699c15cc50013116c52bef1aa3d1bb413c09
data/README.md CHANGED
@@ -4,15 +4,17 @@ A rails_admin alternative dashboard. It overrides the default dashboard componen
4
4
 
5
5
  Features:
6
6
 
7
- - show the last 3 records for each model (useful to reach the last items easily)
7
+ - last 3 records for each model (useful to reach the last items easily)
8
8
 
9
- - show optionally admin notices (to show informations to the users)
9
+ - Google Analytics data if enabled
10
10
 
11
- - show auditing / history table if enabled
11
+ - admin notices if enabled (to show informations to the users)
12
12
 
13
- - hid breadcrump and nav tabs on the dashboard
13
+ - auditing / history table if enabled
14
14
 
15
- - disable counters progress bars (minor performance improvement)
15
+ - no breadcrump and nav tabs on the dashboard
16
+
17
+ - no counters progress bars (minor performance improvement)
16
18
 
17
19
  ## Installation
18
20
 
@@ -20,6 +22,35 @@ Features:
20
22
 
21
23
  - Execute `bundle`
22
24
 
25
+ ## Google Analytics
26
+
27
+ - To enable Google Analytics follow this guide: [Google Analytics Embed API](https://developers.google.com/analytics/devguides/reporting/embed/v1/getting-started)
28
+
29
+ - Set the options in rails_admin config:
30
+
31
+ ```ruby
32
+ # In config.actions block:
33
+ dashboard do
34
+ ga_key 'XXX.apps.googleusercontent.com'
35
+ ga_chart_id 'ga:YYYYYYYYY'
36
+ ga_start_date '60daysAgo'
37
+ ga_end_date '30daysAgo'
38
+ ga_metrics 'ga:sessions,ga:pageviews'
39
+ end
40
+ ```
41
+
42
+ Options:
43
+
44
+ - ga_key: required - CLIENT_ID parameter (obtained from [Google API Client Libraries](https://developers.google.com/api-client-library/javascript/start/start-js#Setup) - [ID client OAuth 2.0](https://console.developers.google.com/apis/credentials))
45
+
46
+ - ga_chart_id: optional - chart to show, if not specified the selector is shown
47
+
48
+ - ga_start_date: optional - starting date, default: '30daysAgo'
49
+
50
+ - ga_end_date: optional - ending date, default: 'yesterday'
51
+
52
+ - ga_metrics: optional - type of data to show, default: 'ga:sessions'
53
+
23
54
  ## Admin notices
24
55
 
25
56
  - Create and apply a migration:
@@ -0,0 +1,78 @@
1
+ :css
2
+ #ga-auth-button { color: #888; font-style: italic; text-align: center; }
3
+ #ga-timeline { overflow-x: scroll; }
4
+ #ga-timeline .gapi-analytics-data-chart > div > div { margin: 0 auto; }
5
+ #ga-view-selector table { margin: 5px auto 0 auto; }
6
+
7
+ .panel.panel-info
8
+ .panel-heading
9
+ %h3.panel-title= t 'admin.dashboard.google_analytics'
10
+ .panel-body
11
+ %section#ga-auth-button
12
+ %section#ga-view-selector
13
+ %section#ga-timeline
14
+
15
+ :javascript
16
+ var gapi_init = false;
17
+ if( !$('#gapi-script').length ) {
18
+ // Include once
19
+ (function(w,d,s,g,js,fjs){
20
+ g=w.gapi||(w.gapi={});g.analytics={q:[],ready:function(cb){this.q.push(cb)}};
21
+ js=d.createElement(s);fjs=d.getElementsByTagName(s)[0];
22
+ js.id='gapi-script';
23
+ js.src='https://apis.google.com/js/platform.js';
24
+ fjs.parentNode.insertBefore(js,fjs);js.onload=function(){g.load('analytics')};
25
+ }(window,document,'script'));
26
+ gapi_init = true;
27
+ }
28
+
29
+ :javascript
30
+ var timeline;
31
+ var ga_chart_id = '#{@action.ga_chart_id}';
32
+ var ga_metrics = '#{@action.ga_metrics ? @action.ga_metrics : "ga:sessions"}';
33
+ var ga_start_date = '#{@action.ga_start_date ? @action.ga_start_date : "30daysAgo"}';
34
+ var ga_end_date = '#{@action.ga_end_date ? @action.ga_end_date : "yesterday"}';
35
+ var ga_client_id = '#{@action.ga_key}';
36
+ gapi.analytics.ready(function() {
37
+ // >> Create the view selector.
38
+ if( !ga_chart_id ) {
39
+ var viewSelector = new gapi.analytics.ViewSelector({
40
+ container: 'ga-view-selector'
41
+ });
42
+ viewSelector.on( 'change', function( ids ) {
43
+ // console.log( ids );
44
+ timeline.set( { query: { ids: ids } } ).execute();
45
+ });
46
+ }
47
+ // >> Create the timeline chart.
48
+ timeline = new gapi.analytics.googleCharts.DataChart({
49
+ reportType: 'ga',
50
+ query: {
51
+ 'dimensions': 'ga:date',
52
+ 'metrics': ga_metrics,
53
+ 'start-date': ga_start_date,
54
+ 'end-date': ga_end_date,
55
+ },
56
+ chart: {
57
+ type: 'LINE',
58
+ container: 'ga-timeline'
59
+ }
60
+ });
61
+ if( gapi_init ) {
62
+ // >> Authorize the user.
63
+ gapi.analytics.auth.authorize({
64
+ container: 'ga-auth-button',
65
+ clientid: ga_client_id,
66
+ });
67
+ // >> Hook up the components to work together.
68
+ gapi.analytics.auth.on('success', function(response) {
69
+ if( ga_chart_id ) timeline.set( { query: { ids: ga_chart_id } } ).execute();
70
+ else viewSelector.execute();
71
+ $('#ga-auth-button').fadeOut( 500 );
72
+ });
73
+ }
74
+ else {
75
+ if( ga_chart_id ) timeline.set( { query: { ids: ga_chart_id } } ).execute();
76
+ else viewSelector.execute();
77
+ }
78
+ });
@@ -4,42 +4,50 @@
4
4
  td.c2 { text-align: center; }
5
5
 
6
6
  %div#mydash
7
- - if @admin_notices
7
+ .row
8
+ - if @action.ga_key
9
+ %div{class:@action.ga_key ? 'col-md-7' : 'col-md-12'}
10
+ = render partial: 'analytics_embed'
11
+ - if @admin_notices && @admin_notices.any?
12
+ %div{class:@action.ga_key ? 'col-md-5' : 'col-md-12'}
13
+ %div.panel.panel-info
14
+ %div.panel-heading
15
+ %h3.panel-title= t 'admin.dashboard.notices'
16
+ / %div.panel-body
17
+ %table.table
18
+ - @admin_notices.each do |notice|
19
+ %tr
20
+ %td= notice.message
21
+ - if @abstract_models
8
22
  %div.panel.panel-info
9
23
  %div.panel-heading
10
- %h3.panel-title= t 'admin.dashboard.notices'
11
- / %div.panel-body
12
- %table.table
13
- - @admin_notices.each do |notice|
24
+ %h3.panel-title= t 'admin.dashboard.records'
25
+ %table.table.table-condensed.table-striped.dashboard-table
26
+ %thead
14
27
  %tr
15
- %td= notice.message
16
- - if @abstract_models
17
- %table.table.table-condensed.table-striped.dashboard-table
18
- %thead
19
- %tr
20
- %th.shrink.model-name= t 'admin.table_headers.model_name'
21
- %th.shrink.records= t 'admin.table_headers.records'
22
- %th.last-records= t 'admin.table_headers.last_records'
23
- %th.shrink.controls
24
- %tbody
25
- - @abstract_models.each do |abstract_model|
26
- - if authorized? :index, abstract_model
27
- - index_path = index_path(model_name: abstract_model.to_param)
28
- - row_class = "#{cycle("odd", "even")}#{" link" if index_path} #{abstract_model.param_key}_links"
29
- %tr{class: row_class, :"data-link" => index_path}
30
- %td.c1
31
- %span.show= link_to capitalize_first_letter(abstract_model.config.label_plural), index_path, class: 'pjax'
32
- %td.c2
33
- - if @count[abstract_model.model.name]
34
- = @count[abstract_model.model.name]
35
- %td.c3
36
- - if @last_rows[abstract_model.model.name]
37
- %div.last-records-list
38
- - @last_rows[abstract_model.model.name].each do |row|
39
- - if row.respond_to?( :name ) && ( show_action = action(:show, abstract_model, row) )
40
- %div.last-records-item= link_to(row.name, url_for(action: show_action.action_name, model_name: abstract_model.to_param, id: row.id), class: 'pjax')
41
- %td.c4.links
42
- %ul.inline.list-inline= menu_for :collection, abstract_model, nil, true
28
+ %th.shrink.model-name= t 'admin.table_headers.model_name'
29
+ %th.shrink.records= t 'admin.table_headers.records'
30
+ %th.last-records= t 'admin.table_headers.last_records'
31
+ %th.shrink.controls
32
+ %tbody
33
+ - @abstract_models.each do |abstract_model|
34
+ - if authorized? :index, abstract_model
35
+ - index_path = index_path(model_name: abstract_model.to_param)
36
+ - row_class = "#{cycle("odd", "even")}#{" link" if index_path} #{abstract_model.param_key}_links"
37
+ %tr{class: row_class, :"data-link" => index_path}
38
+ %td.c1
39
+ %span.show= link_to capitalize_first_letter(abstract_model.config.label_plural), index_path, class: 'pjax'
40
+ %td.c2
41
+ - if @count[abstract_model.model.name]
42
+ = @count[abstract_model.model.name]
43
+ %td.c3
44
+ - if @last_rows[abstract_model.model.name]
45
+ %div.last-records-list
46
+ - @last_rows[abstract_model.model.name].each do |row|
47
+ - if row.respond_to?( :name ) && ( show_action = action(:show, abstract_model, row) )
48
+ %div.last-records-item= link_to(row.name, url_for(action: show_action.action_name, model_name: abstract_model.to_param, id: row.id), class: 'pjax')
49
+ %td.c4.links
50
+ %ul.inline.list-inline= menu_for :collection, abstract_model, nil, true
43
51
  - if @auditing_adapter && authorized?(:history_index)
44
52
  #block-tables.block
45
53
  .content
@@ -48,6 +48,26 @@ RailsAdmin::Config::Actions::Dashboard.class_eval do
48
48
  false
49
49
  end
50
50
 
51
+ register_instance_option :ga_chart_id do
52
+ nil
53
+ end
54
+
55
+ register_instance_option :ga_end_date do
56
+ 'yesterday'
57
+ end
58
+
59
+ register_instance_option :ga_key do
60
+ nil
61
+ end
62
+
63
+ register_instance_option :ga_metrics do
64
+ 'ga:sessions'
65
+ end
66
+
67
+ register_instance_option :ga_start_date do
68
+ '30daysAgo'
69
+ end
70
+
51
71
  register_instance_option :last_records do
52
72
  3
53
73
  end
@@ -1,3 +1,3 @@
1
1
  module RailsAdminMydash
2
- VERSION = '0.1.6'
2
+ VERSION = '0.1.8'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_admin_mydash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mattia Roccoberton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-01 00:00:00.000000000 Z
11
+ date: 2017-02-05 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: An alternative dashboard for rails_admin
14
14
  email:
@@ -20,6 +20,7 @@ files:
20
20
  - MIT-LICENSE
21
21
  - README.md
22
22
  - Rakefile
23
+ - app/views/rails_admin/main/_analytics_embed.html.haml
23
24
  - app/views/rails_admin/main/_mydashboard_history.html.haml
24
25
  - app/views/rails_admin/main/dashboard.html.haml
25
26
  - lib/rails_admin_mydash.rb