godmin 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +24 -0
  3. data/.hound.yml +2 -0
  4. data/.rubocop.yml +7 -0
  5. data/.travis.yml +7 -0
  6. data/Gemfile +11 -0
  7. data/MIT-LICENSE +20 -0
  8. data/README.md +523 -0
  9. data/Rakefile +34 -0
  10. data/app/assets/images/godmin/.keep +0 -0
  11. data/app/assets/javascripts/godmin/application.js +19 -0
  12. data/app/assets/javascripts/godmin/batch_actions.js +42 -0
  13. data/app/assets/javascripts/godmin/navigation.js +9 -0
  14. data/app/assets/javascripts/godmin/select_tags.js +8 -0
  15. data/app/assets/stylesheets/godmin/application.css.scss +62 -0
  16. data/app/views/godmin/application/welcome.html.erb +65 -0
  17. data/app/views/godmin/resource/_actions.html.erb +10 -0
  18. data/app/views/godmin/resource/_batch_actions.html.erb +12 -0
  19. data/app/views/godmin/resource/_breadcrumb.html.erb +21 -0
  20. data/app/views/godmin/resource/_errors.html.erb +9 -0
  21. data/app/views/godmin/resource/_filters.html.erb +23 -0
  22. data/app/views/godmin/resource/_form.html.erb +12 -0
  23. data/app/views/godmin/resource/_pagination.html.erb +6 -0
  24. data/app/views/godmin/resource/_scopes.html.erb +11 -0
  25. data/app/views/godmin/resource/_table.html.erb +36 -0
  26. data/app/views/godmin/resource/columns/_actions.html.erb +11 -0
  27. data/app/views/godmin/resource/edit.html.erb +5 -0
  28. data/app/views/godmin/resource/index.html.erb +17 -0
  29. data/app/views/godmin/resource/new.html.erb +5 -0
  30. data/app/views/godmin/resource/show.html.erb +1 -0
  31. data/app/views/godmin/sessions/new.html.erb +9 -0
  32. data/app/views/godmin/shared/_navigation.html.erb +29 -0
  33. data/app/views/kaminari/_first_page.html.erb +3 -0
  34. data/app/views/kaminari/_gap.html.erb +3 -0
  35. data/app/views/kaminari/_last_page.html.erb +3 -0
  36. data/app/views/kaminari/_next_page.html.erb +3 -0
  37. data/app/views/kaminari/_page.html.erb +3 -0
  38. data/app/views/kaminari/_paginator.html.erb +15 -0
  39. data/app/views/kaminari/_prev_page.html.erb +3 -0
  40. data/app/views/layouts/godmin/_content.html.erb +13 -0
  41. data/app/views/layouts/godmin/_layout.html.erb +13 -0
  42. data/app/views/layouts/godmin/application.html.erb +17 -0
  43. data/app/views/layouts/godmin/login.html.erb +18 -0
  44. data/bin/rails +8 -0
  45. data/config/locales/en.yml +41 -0
  46. data/config/locales/sv.yml +41 -0
  47. data/config/routes.rb +2 -0
  48. data/godmin.gemspec +32 -0
  49. data/lib/generators/godmin/authentication/authentication_generator.rb +61 -0
  50. data/lib/generators/godmin/install/install_generator.rb +34 -0
  51. data/lib/generators/godmin/policy/policy_generator.rb +29 -0
  52. data/lib/generators/godmin/resource/resource_generator.rb +56 -0
  53. data/lib/godmin.rb +24 -0
  54. data/lib/godmin/application.rb +37 -0
  55. data/lib/godmin/authentication.rb +35 -0
  56. data/lib/godmin/authentication/sessions.rb +45 -0
  57. data/lib/godmin/authentication/user.rb +27 -0
  58. data/lib/godmin/authorization.rb +30 -0
  59. data/lib/godmin/authorization/policy.rb +40 -0
  60. data/lib/godmin/authorization/policy_finder.rb +28 -0
  61. data/lib/godmin/engine.rb +4 -0
  62. data/lib/godmin/generators/base.rb +13 -0
  63. data/lib/godmin/helpers/application.rb +6 -0
  64. data/lib/godmin/helpers/batch_actions.rb +17 -0
  65. data/lib/godmin/helpers/filters.rb +108 -0
  66. data/lib/godmin/helpers/tables.rb +41 -0
  67. data/lib/godmin/helpers/translations.rb +19 -0
  68. data/lib/godmin/rails.rb +36 -0
  69. data/lib/godmin/resolver.rb +46 -0
  70. data/lib/godmin/resource.rb +126 -0
  71. data/lib/godmin/resource/batch_actions.rb +45 -0
  72. data/lib/godmin/resource/filters.rb +41 -0
  73. data/lib/godmin/resource/ordering.rb +25 -0
  74. data/lib/godmin/resource/pagination.rb +11 -0
  75. data/lib/godmin/resource/scopes.rb +49 -0
  76. data/lib/godmin/version.rb +3 -0
  77. data/lib/tasks/godmin_tasks.rake +4 -0
  78. data/test/dummy/README.rdoc +28 -0
  79. data/test/dummy/Rakefile +6 -0
  80. data/test/dummy/app/assets/images/.keep +0 -0
  81. data/test/dummy/app/assets/javascripts/application.js +13 -0
  82. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  83. data/test/dummy/app/controllers/application_controller.rb +5 -0
  84. data/test/dummy/app/controllers/concerns/.keep +0 -0
  85. data/test/dummy/app/helpers/application_helper.rb +2 -0
  86. data/test/dummy/app/mailers/.keep +0 -0
  87. data/test/dummy/app/models/.keep +0 -0
  88. data/test/dummy/app/models/concerns/.keep +0 -0
  89. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  90. data/test/dummy/bin/bundle +3 -0
  91. data/test/dummy/bin/rails +4 -0
  92. data/test/dummy/bin/rake +4 -0
  93. data/test/dummy/config.ru +4 -0
  94. data/test/dummy/config/application.rb +23 -0
  95. data/test/dummy/config/boot.rb +5 -0
  96. data/test/dummy/config/database.yml +25 -0
  97. data/test/dummy/config/environment.rb +5 -0
  98. data/test/dummy/config/environments/development.rb +29 -0
  99. data/test/dummy/config/environments/production.rb +80 -0
  100. data/test/dummy/config/environments/test.rb +36 -0
  101. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  102. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  103. data/test/dummy/config/initializers/inflections.rb +16 -0
  104. data/test/dummy/config/initializers/mime_types.rb +5 -0
  105. data/test/dummy/config/initializers/secret_token.rb +12 -0
  106. data/test/dummy/config/initializers/session_store.rb +3 -0
  107. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  108. data/test/dummy/config/locales/en.yml +23 -0
  109. data/test/dummy/config/routes.rb +4 -0
  110. data/test/dummy/db/test.sqlite3 +0 -0
  111. data/test/dummy/lib/assets/.keep +0 -0
  112. data/test/dummy/public/404.html +58 -0
  113. data/test/dummy/public/422.html +58 -0
  114. data/test/dummy/public/500.html +57 -0
  115. data/test/dummy/public/favicon.ico +0 -0
  116. data/test/godmin_test.rb +7 -0
  117. data/test/integration/navigation_test.rb +10 -0
  118. data/test/lib/godmin/policy_finder_test.rb +30 -0
  119. data/test/lib/godmin/resolver_test.rb +31 -0
  120. data/test/test_helper.rb +21 -0
  121. data/vendor/assets/images/godmin/chosen-sprite.png +0 -0
  122. data/vendor/assets/images/godmin/chosen-sprite@2x.png +0 -0
  123. data/vendor/assets/javascripts/.keep +0 -0
  124. data/vendor/assets/stylesheets/.keep +0 -0
  125. metadata +361 -0
data/Rakefile ADDED
@@ -0,0 +1,34 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Godmin'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+
22
+ Bundler::GemHelper.install_tasks
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'lib'
28
+ t.libs << 'test'
29
+ t.pattern = 'test/**/*_test.rb'
30
+ t.verbose = false
31
+ end
32
+
33
+
34
+ task default: :test
File without changes
@@ -0,0 +1,19 @@
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
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require bootstrap
16
+ //= require select2
17
+ //= require godmin/batch_actions
18
+ //= require godmin/navigation
19
+ //= require godmin/select_tags
@@ -0,0 +1,42 @@
1
+ (function($) {
2
+ $(function() {
3
+ $form = $('#batch-actions-form');
4
+ $selectAll = $form.find('.batch-actions-select-all');
5
+ $selectNone = $form.find('.batch-actions-select-none');
6
+
7
+ var setSelectToAll = function() {
8
+ $selectAll.removeClass('hidden');
9
+ $selectNone.addClass('hidden');
10
+ };
11
+
12
+ var setSelectToNone = function() {
13
+ $selectAll.addClass('hidden');
14
+ $selectNone.removeClass('hidden');
15
+ };
16
+
17
+ $form.find('.batch-actions-select').on('click', function() {
18
+ if ($form.find('input:checkbox:checked').length > 0) {
19
+ $form.find('input:checkbox').prop('checked', false).trigger('change');
20
+ setSelectToAll();
21
+ } else {
22
+ $form.find('input:checkbox').prop('checked', true).trigger('change');
23
+ setSelectToNone();
24
+ }
25
+ });
26
+
27
+ $form.find('input:checkbox').on('change', function() {
28
+ if ($form.find('input:checkbox:checked').length) {
29
+ $('.batch-actions-action-link').removeClass('hidden');
30
+ setSelectToNone();
31
+ } else {
32
+ $('.batch-actions-action-link').addClass('hidden');
33
+ setSelectToAll();
34
+ }
35
+ });
36
+
37
+ $(document).delegate('.batch-actions-action-link', 'click.rails', function() {
38
+ $form.find('#batch-actions-action').val($(this).data('value'));
39
+ $form.submit();
40
+ });
41
+ });
42
+ }(jQuery));
@@ -0,0 +1,9 @@
1
+ (function($) {
2
+ $(function() {
3
+ $('.navbar-nav .dropdown').each(function() {
4
+ if ($(this).find('li').length === 0) {
5
+ $(this).remove();
6
+ }
7
+ });
8
+ });
9
+ }(jQuery));
@@ -0,0 +1,8 @@
1
+ (function($) {
2
+ $(function() {
3
+ $('.select-tag').select2({
4
+ allowClear: true,
5
+ width: '170px'
6
+ });
7
+ });
8
+ }(jQuery));
@@ -0,0 +1,62 @@
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
+ */
13
+
14
+ @import "bootstrap";
15
+ @import "select2";
16
+ @import "select2-bootstrap";
17
+
18
+ body {
19
+ margin-bottom: 20px;
20
+ }
21
+
22
+ #login {
23
+ margin-top: 20px;
24
+ }
25
+
26
+ #scopes {
27
+ margin-bottom: 20px;
28
+ }
29
+
30
+ #filters {
31
+ .filter {
32
+ min-width: 170px;
33
+ }
34
+ }
35
+
36
+ #actions {
37
+ @include clearfix();
38
+ margin-bottom: 20px;
39
+ }
40
+
41
+ #table {
42
+ td {
43
+ vertical-align: middle;
44
+ }
45
+ }
46
+
47
+ .pagination {
48
+ margin: 0 0 10px 0;
49
+ }
50
+
51
+ .highlight {
52
+ -webkit-animation: highlight 3s;
53
+ }
54
+
55
+ @-webkit-keyframes highlight {
56
+ from {
57
+ background: #fffbcc;
58
+ }
59
+ to {
60
+ background: none;
61
+ }
62
+ }
@@ -0,0 +1,65 @@
1
+ <div class="row">
2
+ <div class="col-md-8">
3
+ <div class="jumbotron">
4
+ <h1>Welcome aboard</h1>
5
+ <p>
6
+ You are now experiencing, first-hand, the power of Godmin:
7
+ an admin framework for Rails 4+, tweakable to the max.
8
+ </p>
9
+ <p>
10
+ <a href="https://github.com/varvet/godmin/" class="btn btn-primary btn-lg" role="button">
11
+ <span class="glyphicon glyphicon-book"></span>
12
+ Browse the documentation
13
+ </a>
14
+ </p>
15
+ </div>
16
+ <div class="row">
17
+ <div class="col-md-6">
18
+ <div class="panel panel-default">
19
+ <div class="panel-heading">Scopes</div>
20
+ <div class="panel-body">
21
+ <p>Scopes are a way of sectioning resources, useful for quick navigation.</p>
22
+ <%= link_to "Read more about scopes", "#" %>
23
+ </div>
24
+ </div>
25
+ </div>
26
+ <div class="col-md-6">
27
+ <div class="panel panel-default">
28
+ <div class="panel-heading">Filters</div>
29
+ <div class="panel-body">
30
+ <p>Filters offer great flexibility when it comes to searching for resources.</p>
31
+ <%= link_to "Read more about filters", "#" %>
32
+ </div>
33
+ </div>
34
+ </div>
35
+ </div>
36
+ <div class="row">
37
+ <div class="col-md-6">
38
+ <div class="panel panel-default">
39
+ <div class="panel-heading">Batch actions</div>
40
+ <div class="panel-body">
41
+ <p>Batch actions are an easy way to perform the same action on multiple resources.</p>
42
+ <%= link_to "Read more about batch actions", "#" %>
43
+ </div>
44
+ </div>
45
+ </div>
46
+ <div class="col-md-6">
47
+ <div class="panel panel-default">
48
+ <div class="panel-heading">Resource fetching</div>
49
+ <div class="panel-body">
50
+ <p>Control which resources to fetch, and apply arbitrary conditions, such as sorting.</p>
51
+ <%= link_to "Read more about resource fetching", "#" %>
52
+ </div>
53
+ </div>
54
+ </div>
55
+ </div>
56
+ </div>
57
+ <div class="col-md-4">
58
+ <div class="panel panel-default">
59
+ <div class="panel-heading">Version</div>
60
+ <div class="panel-body">
61
+ You are running Godmin <%= Godmin::VERSION %>
62
+ </div>
63
+ </div>
64
+ </div>
65
+ </div>
@@ -0,0 +1,10 @@
1
+ <div id="actions">
2
+ <div class="pull-left">
3
+ <%= render partial: "batch_actions" %>
4
+ </div>
5
+ <div class="pull-right">
6
+ <% unless authorization_enabled? && !policy(@resources).create? %>
7
+ <%= link_to t("helpers.submit.create", model: @resource_class.model_name.human), [:new, @resource_class.to_s.underscore], class: "btn btn-default" %>
8
+ <% end %>
9
+ </div>
10
+ </div>
@@ -0,0 +1,12 @@
1
+ <% if batch_action_map.present? %>
2
+ <%= link_to translate_scoped("batch_actions.select_all"), "#", class: "btn btn-default batch-actions-select batch-actions-select-all" %>
3
+ <%= link_to translate_scoped("batch_actions.deselect_all"), "#", class: "btn btn-default batch-actions-select batch-actions-select-none hidden" %>
4
+
5
+ <div class="btn-group">
6
+ <% batch_action_map.each do |name, options| %>
7
+ <%= batch_action_link(name, options) %>
8
+ <% end %>
9
+ </div>
10
+
11
+ <%= hidden_field_tag "batch_action[action]", nil, id: "batch-actions-action" %>
12
+ <% end %>
@@ -0,0 +1,21 @@
1
+ <ol class="breadcrumb">
2
+ <% if index %>
3
+ <li class="active">
4
+ <%= @resource_class.model_name.human(count: 2) %>
5
+ </li>
6
+ <% else %>
7
+ <li>
8
+ <%= link_to @resource_class.model_name.human(count: 2), @resource_class %>
9
+ </li>
10
+ <% end %>
11
+ </li>
12
+ <% unless index %>
13
+ <li class="active">
14
+ <% if @resource.new_record? %>
15
+ <%= t("helpers.submit.create", model: @resource_class.model_name.human) %>
16
+ <% else %>
17
+ <%= @resource.to_s %>
18
+ <% end %>
19
+ </li>
20
+ <% end %>
21
+ </ol>
@@ -0,0 +1,9 @@
1
+ <% if errors.present? %>
2
+ <div class="alert alert-danger">
3
+ <ul class="list-unstyled">
4
+ <% errors.full_messages.each do |error| %>
5
+ <li><%= error %></li>
6
+ <% end %>
7
+ </ul>
8
+ </div>
9
+ <% end %>
@@ -0,0 +1,23 @@
1
+ <div id="filters" class="panel panel-default">
2
+ <div class="panel-body">
3
+ <%= form_tag params, method: :get, class: "form-inline" do %>
4
+
5
+ <%= hidden_field_tag :scope, nil, value: params[:scope] %>
6
+ <%= hidden_field_tag :order, nil, value: params[:order] %>
7
+
8
+ <% filter_map.each do |name, options| %>
9
+ <div class="filter form-group">
10
+ <%= label_tag name, translate_scoped("filters.labels.#{name}", default: name.to_s.titleize) %><br>
11
+ <%= filter_input_tag name, options %>
12
+ </div>
13
+ <% end %>
14
+
15
+ <div class="pull-right">
16
+ <label>&nbsp;</label><br>
17
+ <%= button_tag translate_scoped("filters.buttons.apply"), class: "btn btn-default" %>
18
+ <%= link_to translate_scoped("filters.buttons.clear"), polymorphic_path(@resource_class, scope: params[:scope], order: params[:order]), class: "btn btn-default" %>
19
+ </div>
20
+
21
+ <% end %>
22
+ </div>
23
+ </div>
@@ -0,0 +1,12 @@
1
+ <%= simple_form_for @resource, html: { role: "form" } do |f| %>
2
+ <% attrs_for_form.each do |attr| %>
3
+ <div class="form-group">
4
+ <% if @resource_class.column_names.include? attr.to_s %>
5
+ <%= f.input attr, error: false, input_html: { class: "form-control" } %>
6
+ <% else %>
7
+ <%= f.association attr, error: false, input_html: { class: "form-control chosen" } %>
8
+ <% end %>
9
+ </div>
10
+ <% end %>
11
+ <%= f.button :submit, class: "btn btn-default" %>
12
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <div class="pull-left">
2
+ <%= paginate @resources %>
3
+ </div>
4
+ <div class="pull-right">
5
+ <%= page_entries_info @resources %>
6
+ </div>
@@ -0,0 +1,11 @@
1
+ <% unless scope_map.empty? %>
2
+ <div id="scopes">
3
+ <ul class="nav nav-tabs">
4
+ <% scope_map.each do |name, options| %>
5
+ <li class="<%= "active" if params[:scope] == name.to_s %>">
6
+ <%= link_to translate_scoped("scopes.#{name.to_s.underscore}", default: name.to_s.titleize), url_for(params.merge(scope: name, only_path: true).except(:page)) %>
7
+ </li>
8
+ <% end %>
9
+ </ul>
10
+ </div>
11
+ <% end %>
@@ -0,0 +1,36 @@
1
+ <div id="table" class="table-responsive">
2
+ <table class="table table-bordered table-hover">
3
+ <tr>
4
+ <% if batch_action_map.present? %>
5
+ <th></th>
6
+ <% end %>
7
+ <% attrs_for_index.each do |attr| %>
8
+ <th>
9
+ <%= column_header attr %>
10
+ </th>
11
+ <% end %>
12
+ <th></th>
13
+ </tr>
14
+ <% @resources.each do |resource| %>
15
+ <% if flash[:batch_actioned_ids] && flash[:batch_actioned_ids].include?(resource.id) %>
16
+ <tr class="highlight">
17
+ <% else %>
18
+ <tr>
19
+ <% end %>
20
+ <% if batch_action_map.present? %>
21
+ <td align="center">
22
+ <%= check_box_tag "batch_action[items][#{resource.id}]" %>
23
+ </td>
24
+ <% end %>
25
+ <% attrs_for_index.each do |attr| %>
26
+ <td>
27
+ <%= column_value(resource, attr) %>
28
+ </td>
29
+ <% end %>
30
+ <td>
31
+ <%= render partial: "columns/actions", locals: { resource: resource } %>
32
+ </td>
33
+ </tr>
34
+ <% end %>
35
+ </table>
36
+ </div>
@@ -0,0 +1,11 @@
1
+ <div class="btn-group btn-group-sm pull-right">
2
+ <% unless authorization_enabled? && !policy(resource).show? %>
3
+ <%= link_to translate_scoped("column_actions.show"), resource, class: "btn btn-default" %>
4
+ <% end %>
5
+ <% unless authorization_enabled? && !policy(resource).edit? %>
6
+ <%= link_to translate_scoped("column_actions.edit"), [:edit, resource], class: "btn btn-default" %>
7
+ <% end %>
8
+ <% unless authorization_enabled? && !policy(resource).destroy? %>
9
+ <%= link_to translate_scoped("column_actions.destroy"), resource, method: :delete, data: { confirm: translate_scoped("column_actions.confirm_message") }, class: "btn btn-danger" %>
10
+ <% end %>
11
+ </div>
@@ -0,0 +1,5 @@
1
+ <%= render partial: "breadcrumb", locals: { index: false } %>
2
+
3
+ <%= render partial: "errors", locals: { errors: @resource.errors } %>
4
+
5
+ <%= render partial: "form" %>
@@ -0,0 +1,17 @@
1
+ <%= render partial: "breadcrumb", locals: { index: true } %>
2
+
3
+ <%= render partial: "scopes" %>
4
+
5
+ <% if filter_map.present? %>
6
+ <%= render partial: "filters" %>
7
+ <% end %>
8
+
9
+ <%= form_tag [:batch_action, @resource_class], id: "batch-actions-form" do %>
10
+
11
+ <%= render partial: "actions" %>
12
+
13
+ <%= render partial: "table" %>
14
+
15
+ <% end %>
16
+
17
+ <%= render partial: "pagination" %>