infopark_dashboard 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.
Files changed (47) hide show
  1. data/CHANGELOG.md +1 -0
  2. data/LICENSE +3 -0
  3. data/README.md +92 -0
  4. data/Rakefile +12 -0
  5. data/app/assets/javascripts/infopark_dashboard/dashboard.js +16 -0
  6. data/app/assets/stylesheets/infopark_dashboard/dashboard.css +19 -0
  7. data/app/assets/stylesheets/infopark_dashboard/print.css +11 -0
  8. data/app/controllers/infopark_dashboard/dashboard_controller.rb +47 -0
  9. data/app/models/infopark_dashboard/attribute.rb +39 -0
  10. data/app/models/infopark_dashboard/cms_stats.rb +31 -0
  11. data/app/models/infopark_dashboard/crm_stats.rb +23 -0
  12. data/app/models/infopark_dashboard/editor.rb +11 -0
  13. data/app/models/infopark_dashboard/gem.rb +31 -0
  14. data/app/models/infopark_dashboard/meta_stats.rb +35 -0
  15. data/app/models/infopark_dashboard/obj_class.rb +50 -0
  16. data/app/models/infopark_dashboard/resource.rb +49 -0
  17. data/app/views/infopark_dashboard/dashboard/content.html.haml +17 -0
  18. data/app/views/infopark_dashboard/dashboard/content/_cms_stats.html.haml +52 -0
  19. data/app/views/infopark_dashboard/dashboard/content/_crm_stats.html.haml +42 -0
  20. data/app/views/infopark_dashboard/dashboard/content/_recently_published.html.haml +33 -0
  21. data/app/views/infopark_dashboard/dashboard/help.html.haml +13 -0
  22. data/app/views/infopark_dashboard/dashboard/help/_gem.html.haml +16 -0
  23. data/app/views/infopark_dashboard/dashboard/help/_links.html.haml +30 -0
  24. data/app/views/infopark_dashboard/dashboard/help/_updates.html.haml +25 -0
  25. data/app/views/infopark_dashboard/dashboard/objects.html.haml +16 -0
  26. data/app/views/infopark_dashboard/dashboard/objects/_attribute.html.haml +38 -0
  27. data/app/views/infopark_dashboard/dashboard/objects/_attributes.html.haml +2 -0
  28. data/app/views/infopark_dashboard/dashboard/objects/_global_attribute_details.html.haml +13 -0
  29. data/app/views/infopark_dashboard/dashboard/objects/_mandatory_attributes.html.haml +6 -0
  30. data/app/views/infopark_dashboard/dashboard/objects/_obj_class.html.haml +29 -0
  31. data/app/views/infopark_dashboard/dashboard/objects/_obj_class_details.html.haml +13 -0
  32. data/app/views/infopark_dashboard/dashboard/objects/_preset_attributes.html.haml +12 -0
  33. data/app/views/infopark_dashboard/dashboard/people.html.haml +32 -0
  34. data/app/views/layouts/infopark_dashboard/dashboard.haml +45 -0
  35. data/app/views/layouts/infopark_dashboard/dashboard/_flash_message.html.haml +5 -0
  36. data/app/views/layouts/infopark_dashboard/dashboard/_flash_messages.html.haml +11 -0
  37. data/app/views/layouts/infopark_dashboard/dashboard/_nav_link.html.haml +5 -0
  38. data/app/views/layouts/infopark_dashboard/dashboard/_navigation.html.haml +18 -0
  39. data/app/views/layouts/infopark_dashboard/dashboard/_workspace_toggle.html.haml +16 -0
  40. data/config/routes.rb +7 -0
  41. data/lib/infopark_dashboard.rb +10 -0
  42. data/lib/infopark_dashboard/configuration.rb +55 -0
  43. data/lib/infopark_dashboard/dashboard.rb +14 -0
  44. data/lib/infopark_dashboard/engine.rb +13 -0
  45. data/lib/infopark_dashboard/rake/configuration_helper.rb +21 -0
  46. data/lib/infopark_dashboard/version.rb +3 -0
  47. metadata +253 -0
data/CHANGELOG.md ADDED
@@ -0,0 +1 @@
1
+ # Changelog
data/LICENSE ADDED
@@ -0,0 +1,3 @@
1
+ Copyright (c) 2009 - 2013 Infopark AG (http://www.infopark.com)
2
+
3
+ This software can be used and modified under the LGPLv3. Please refer to http://www.gnu.org/licenses/lgpl-3.0.html for the license text.
data/README.md ADDED
@@ -0,0 +1,92 @@
1
+ # Infopark Dashboard
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/infopark_dashboard.png)](http://badge.fury.io/rb/infopark_dashboard)
4
+ [![Code Climate](https://codeclimate.com/github/infopark/infopark_dashboard.png)](https://codeclimate.com/github/infopark/infopark_dashboard)
5
+ [![Dependency Status](https://gemnasium.com/infopark/infopark_dashboard.png)](https://gemnasium.com/infopark/infopark_dashboard)
6
+
7
+ Infopark Dashboard is an addition to an [Infopark](https://infopark.de) Ruby on Rails project, that
8
+ displays project meta data. It allows to get an overview of used CMS object classes and its
9
+ attributes and other, statistic values by providing a mountable engine.
10
+
11
+
12
+ ## Installation and Usage
13
+
14
+ Include the gem into your Gemfile:
15
+
16
+ ```
17
+ group :development do
18
+ gem 'infopark_dashboard'
19
+ end
20
+ ```
21
+
22
+ The gem provides a mountable engine, which may be attached to your Ruby on Rails application by
23
+ extending your ```routes.rb```:
24
+
25
+ ```
26
+ if defined?(InfoparkDashboard)
27
+ mount InfoparkDashboard::Engine => "/cms/dashboard"
28
+ end
29
+ ```
30
+
31
+ Note that the dashboard does not use an authorization layer and is only accessible using
32
+ local requests.
33
+
34
+ ## Testing
35
+
36
+ You can run the dashboard's tests by simply calling:
37
+
38
+ $ rake spec
39
+
40
+ In order to run the tests successfully, you need to provide the ```config/rails_connector.yml```
41
+ and ```config/custom_cloud.yml``` file (see 'Contributing') and put them in the gem's ```config```
42
+ directory. Do not worry, your credentials are .gitignored by default.
43
+
44
+
45
+ ## Changelog
46
+
47
+ See [Changelog](https://github.com/infopark/infopark_dashboard/blob/master/CHANGELOG.md) for more
48
+ details.
49
+
50
+
51
+ ## Contributing
52
+
53
+ We would be very happy and thankful if you open new issues in order to further improve Infopark
54
+ Dashboard. If you want to go a step further and extend the functionality or fix a problem, you can
55
+ do so any time by following the steps below.
56
+
57
+ 1. Signup for a [free Infopark account](http://www.infopark.de/) and setup a test CRM
58
+ and CMS component in the Infopark console.
59
+
60
+ 2. Fork and clone the Infopark Dashboard GitHub repository.
61
+
62
+ git clone git@github.com:_username_/infopark_dashboard.git
63
+ cd infopark_dashboard
64
+
65
+ 3. We suggest using [rbenv](https://github.com/sstephenson/rbenv/). Anyway, compare your local Ruby
66
+ version with the version given in `.ruby-version` and install it if necessary.
67
+
68
+ ruby --version
69
+
70
+ 3. Download the configuration files for your Ruby on Rails application from the Infopark console
71
+ and copy them to your gem's `config` folder.
72
+
73
+ config/rails_connector.yml
74
+ config/custom_cloud.yml
75
+
76
+
77
+ 4. Create the bundle and run all test to make sure everything is working before you add your own
78
+ changes. You find some more details about testing above in the __Testing__ section.
79
+
80
+ bundle
81
+ rake spec
82
+
83
+ 5. Create your feature branch and create a pull request for the `develop` branch. Please take a
84
+ look at the already existing generators and rake tasks to get an impression of our coding style
85
+ and the general architecture.
86
+
87
+
88
+ ## License
89
+ Copyright (c) 2009 - 2013 Infopark AG (http://www.infopark.com)
90
+
91
+ This software can be used and modified under the LGPLv3. Please refer to
92
+ http://www.gnu.org/licenses/lgpl-3.0.html for the license text.
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env rake
2
+
3
+ require 'bundler/setup'
4
+ Bundler::GemHelper.install_tasks
5
+
6
+ require 'yard'
7
+ YARD::Rake::YardocTask.new
8
+
9
+ require 'rspec/core/rake_task'
10
+ RSpec::Core::RakeTask.new(:spec)
11
+
12
+ task default: :spec
@@ -0,0 +1,16 @@
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 jquery
14
+ //= require jquery_ujs
15
+ //= require twitter/bootstrap
16
+ //= require_tree .
@@ -0,0 +1,19 @@
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_self
12
+ *= require twitter/bootstrap
13
+ *= require twitter/bootstrap-responsive
14
+ *= require_tree .
15
+ */
16
+
17
+ body {
18
+ padding: 60px 0 0 0;
19
+ }
@@ -0,0 +1,11 @@
1
+ @media print {
2
+ .nav, .navbar {
3
+ display: none;
4
+ }
5
+
6
+ p, h2, h3 {
7
+ page-break-after: avoid;
8
+ orphans: 3;
9
+ widows: 3;
10
+ }
11
+ }
@@ -0,0 +1,47 @@
1
+ module InfoparkDashboard
2
+ class DashboardController < ApplicationController
3
+ before_filter :require_local!
4
+
5
+ def objects
6
+ @workspaces = RailsConnector::CmsRestApi.get('workspaces')['results']
7
+
8
+ @current_workspace = @workspaces.detect do |workspace|
9
+ workspace['id'] == RailsConnector::Workspace.current.id
10
+ end
11
+
12
+ @workspaces.each do |workspace|
13
+ workspace['title'] ||= 'Published'
14
+ end
15
+
16
+ @meta_stats = MetaStats.new
17
+ end
18
+
19
+ def help
20
+ @gems = InfoparkDashboard::Gem.all
21
+ end
22
+
23
+ def people
24
+ @editors = Editor.all
25
+ end
26
+
27
+ def content
28
+ @cms_stats = CmsStats.new
29
+ @crm_stats = CrmStats.new
30
+ end
31
+
32
+ private
33
+
34
+ def require_local!
35
+ unless local_request?
36
+ render(
37
+ text: '<p>For security purposes, this information is only available to local requests.</p>',
38
+ status: :forbidden
39
+ )
40
+ end
41
+ end
42
+
43
+ def local_request?
44
+ Rails.configuration.consider_all_requests_local || request.local?
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,39 @@
1
+ module InfoparkDashboard
2
+ class Attribute < Resource
3
+ def self.namespace
4
+ 'attributes'
5
+ end
6
+
7
+ attr_accessor :id
8
+ attr_accessor :name
9
+ attr_accessor :type
10
+ attr_accessor :values
11
+ attr_accessor :title
12
+ attr_accessor :min_size
13
+ attr_accessor :max_size
14
+
15
+ def initialize(attributes = {})
16
+ if attributes.is_a?(String)
17
+ attributes = self.class.fetch(attributes)
18
+ end
19
+
20
+ super(attributes)
21
+ end
22
+
23
+ def title?
24
+ title.present?
25
+ end
26
+
27
+ def values?
28
+ values.present?
29
+ end
30
+
31
+ def min_size?
32
+ min_size.present?
33
+ end
34
+
35
+ def max_size?
36
+ max_size.present?
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,31 @@
1
+ module InfoparkDashboard
2
+ class CmsStats
3
+ attr_reader :published_objects
4
+ attr_reader :websites
5
+ attr_reader :homepages
6
+ attr_reader :resources
7
+ attr_reader :widgets
8
+ attr_reader :recently_published
9
+
10
+ def initialize
11
+ published_workspace.as_current do
12
+ @published_objects = Obj.all.size
13
+ @websites = Obj.where(:_obj_class, :equals, 'Website').size
14
+ @homepages = Obj.where(:_obj_class, :equals, 'Homepage').size
15
+ @resources = Obj.where(:_path, :starts_with, '/resources').and_not(:_obj_class, :equals, 'Container').size
16
+ @widgets = Obj.where(:_obj_class, :contains_prefix, 'Widget').size
17
+ @recently_published = Obj.all.order(:_last_changed).reverse_order.take(20)
18
+ end
19
+ end
20
+
21
+ def workspaces
22
+ @workspaces ||= RailsConnector::CmsRestApi.get('workspaces')['results'].size
23
+ end
24
+
25
+ private
26
+
27
+ def published_workspace
28
+ RailsConnector::Workspace.find('published')
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,23 @@
1
+ module InfoparkDashboard
2
+ class CrmStats
3
+ def contacts
4
+ @contacts ||= Infopark::Crm::Contact.search(params: {}).size
5
+ end
6
+
7
+ def accounts
8
+ @accounts ||= Infopark::Crm::Account.search(params: {}).size
9
+ end
10
+
11
+ def mailings
12
+ @mailings ||= Infopark::Crm::Mailing.search(params: {}).size
13
+ end
14
+
15
+ def events
16
+ @events ||= Infopark::Crm::Event.search(params: {}).size
17
+ end
18
+
19
+ def activities
20
+ @activities ||= Infopark::Crm::Activity.search(params: {}).size
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,11 @@
1
+ require 'infopark_crm_connector'
2
+
3
+ module InfoparkDashboard
4
+ class Editor
5
+ def self.all
6
+ Infopark::Crm::Contact.all.select do |contact|
7
+ contact.login.present? && contact.role_names.include?('superuser')
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,31 @@
1
+ module InfoparkDashboard
2
+ class Gem
3
+ def self.all
4
+ %w(infopark_rails_connector infopark_crm_connector infopark_dashboard rails bundler).map do |name|
5
+ new(name)
6
+ end
7
+ end
8
+
9
+ attr_accessor :name
10
+
11
+ def initialize(name)
12
+ @name = name
13
+ end
14
+
15
+ def rubygems_url
16
+ @rubygems_url ||= "https://rubygems.org/gems/#{name}"
17
+ end
18
+
19
+ def version
20
+ @version ||= ::Gem.loaded_specs[name].try(:version)
21
+ end
22
+
23
+ def latest_version
24
+ @latest_version ||= ::Gem.latest_version_for(name)
25
+ end
26
+
27
+ def latest?
28
+ version == latest_version
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,35 @@
1
+ module InfoparkDashboard
2
+ class MetaStats
3
+ def maximum_attributes
4
+ @maximum_attributes ||= max_group_size(grouped_attributes).second.size.to_f
5
+ end
6
+
7
+ def grouped_attributes
8
+ @grouped_attributes ||= attributes.group_by(&:type)
9
+ end
10
+
11
+ def obj_classes_count
12
+ obj_classes.size
13
+ end
14
+
15
+ def obj_classes
16
+ @obj_classes ||= ObjClass.all
17
+ end
18
+
19
+ def global_attributes_count
20
+ global_attributes.size
21
+ end
22
+
23
+ def global_attributes
24
+ @attributes ||= Attribute.all
25
+ end
26
+
27
+ private
28
+
29
+ def max_group_size(hash)
30
+ hash.max do |a, b|
31
+ a.second.size <=> b.second.size
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,50 @@
1
+ module InfoparkDashboard
2
+ class ObjClass < Resource
3
+ def self.namespace
4
+ 'obj_classes'
5
+ end
6
+
7
+ attr_accessor :id
8
+ attr_accessor :name
9
+ attr_accessor :type
10
+ attr_accessor :is_active
11
+ attr_accessor :title
12
+ attr_accessor :attributes
13
+ attr_accessor :mandatory_attributes
14
+ attr_accessor :preset_attributes
15
+
16
+ def active?
17
+ is_active
18
+ end
19
+
20
+ def title?
21
+ title.present?
22
+ end
23
+
24
+ def attributes
25
+ @attributes.map do |definition|
26
+ Attribute.new(definition)
27
+ end
28
+ end
29
+
30
+ def attributes?
31
+ attributes.present?
32
+ end
33
+
34
+ def mandatory_attributes?
35
+ mandatory_attributes.present?
36
+ end
37
+
38
+ def preset_attributes?
39
+ preset_attributes.present?
40
+ end
41
+
42
+ def count
43
+ Rails.cache.fetch("#{self.class.cache_key(id)}_count") do
44
+ RailsConnector::Workspace.find('published').as_current do
45
+ Obj.where(:_obj_class, :equals, id).size
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end