godmin 0.9.1 → 0.9.2
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 +4 -4
- data/CHANGELOG.md +20 -0
- data/README.md +50 -2
- data/app/assets/javascripts/godmin/application.js +2 -2
- data/app/assets/javascripts/godmin/select_tags.js +4 -5
- data/app/assets/stylesheets/godmin/application.css.scss +8 -3
- data/app/views/godmin/resource/_form.html.erb +3 -3
- data/app/views/godmin/resource/_pagination.html.erb +37 -3
- data/config/locales/en.yml +7 -13
- data/config/locales/sv.yml +7 -13
- data/godmin.gemspec +3 -4
- data/lib/generators/godmin/install/install_generator.rb +10 -0
- data/lib/godmin.rb +1 -2
- data/lib/godmin/application.rb +2 -0
- data/lib/godmin/resource.rb +54 -12
- data/lib/godmin/resource/pagination.rb +52 -1
- data/lib/godmin/version.rb +1 -1
- metadata +38 -58
- data/app/views/kaminari/_first_page.html.erb +0 -3
- data/app/views/kaminari/_gap.html.erb +0 -3
- data/app/views/kaminari/_last_page.html.erb +0 -3
- data/app/views/kaminari/_next_page.html.erb +0 -3
- data/app/views/kaminari/_page.html.erb +0 -3
- data/app/views/kaminari/_paginator.html.erb +0 -15
- data/app/views/kaminari/_prev_page.html.erb +0 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 62c5f761bf1def69547eca0aea4158bc21ced800
|
|
4
|
+
data.tar.gz: 1027b1f89f1daafc1a7a5ce448688bffbb85e08a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 196f2f7e4b36f756781d6607435488340754335108adb37cf060307b4ad7829cc6cd9ae53555e9d84bcd907486693ed3f41457b5b8115d048464d606487da8a2
|
|
7
|
+
data.tar.gz: 0341ae1349120f246ec2f12e6b9986b9c88fb272b0ce0ffaaf23fff58ac935126724c0af4e4a1e4379c9b36f10030052210f9f0091bc61f816a0e582c82a6f8e
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
### 0.9.2 - 2014-12-09
|
|
4
|
+
Features
|
|
5
|
+
- Replaces select2 with [selectize](http://brianreavis.github.io/selectize.js/)
|
|
6
|
+
- Adds flash messages (https://github.com/varvet/godmin/issues/26)
|
|
7
|
+
- Adds redirect hooks (https://github.com/varvet/godmin/issues/27)
|
|
8
|
+
- Replaces kaminari
|
|
9
|
+
|
|
10
|
+
Bug fixes
|
|
11
|
+
- Form fallbacks to regular input instead of association. (https://github.com/varvet/godmin/issues/18)
|
|
12
|
+
- Install generator adds `require "godmin"` if it is installed in an engine.
|
|
13
|
+
- Fixes default permitted params to work with multiword models.
|
|
14
|
+
|
|
15
|
+
### 0.9.1 - 2014-11-18
|
|
16
|
+
Bug fixes
|
|
17
|
+
- Removed rails executable from /bin folder.
|
|
18
|
+
|
|
19
|
+
### 0.9.0 - 2014-11-17
|
|
20
|
+
Public release.
|
data/README.md
CHANGED
|
@@ -16,6 +16,7 @@ Godmin is an admin engine for Rails 4+.
|
|
|
16
16
|
- [Filters](#filters)
|
|
17
17
|
- [Batch actions](#batch-actions)
|
|
18
18
|
- [Resource fetching](#resource-fetching)
|
|
19
|
+
- [Redirecting](#redirecting)
|
|
19
20
|
- [Views](#views)
|
|
20
21
|
- [Models](#models)
|
|
21
22
|
- [Authentication](#authentication)
|
|
@@ -24,6 +25,7 @@ Godmin is an admin engine for Rails 4+.
|
|
|
24
25
|
- [Authorization](#authorization)
|
|
25
26
|
- [Localization](#localization)
|
|
26
27
|
- [Contributors](#contributors)
|
|
28
|
+
- [License](#license)
|
|
27
29
|
|
|
28
30
|
## Installation
|
|
29
31
|
|
|
@@ -62,12 +64,12 @@ gem "admin", path: "admin"
|
|
|
62
64
|
|
|
63
65
|
Mount the engine in the application's `config/routes.rb`:
|
|
64
66
|
```ruby
|
|
65
|
-
mount Admin::Engine, at: "
|
|
67
|
+
mount Admin::Engine, at: "admin"
|
|
66
68
|
```
|
|
67
69
|
|
|
68
70
|
Add the gem to the engine's gemspec, `admin/admin.gemspec`:
|
|
69
71
|
```ruby
|
|
70
|
-
s.add_dependency
|
|
72
|
+
s.add_dependency "godmin", "~> x.x.x"
|
|
71
73
|
```
|
|
72
74
|
|
|
73
75
|
Run the install generator within the scope of the engine, i.e. note the leading `admin/`:
|
|
@@ -107,6 +109,8 @@ class ApplicationController < ActionController::Base
|
|
|
107
109
|
end
|
|
108
110
|
```
|
|
109
111
|
|
|
112
|
+
If Godmin was installed inside an engine, a `require "godmin"` statement is placed in `{namespace}/lib/{namespace}.rb`.
|
|
113
|
+
|
|
110
114
|
And finally, the `app/views/layouts` folder is removed by default, so as not to interfere with the Godmin layouts. It can be added back in case you wish to override the built in layouts.
|
|
111
115
|
|
|
112
116
|
## Getting started
|
|
@@ -302,6 +306,50 @@ class ArticlesController
|
|
|
302
306
|
end
|
|
303
307
|
```
|
|
304
308
|
|
|
309
|
+
### Redirecting
|
|
310
|
+
|
|
311
|
+
By default the user is redirected to the resource show page after create and update. To change this, there are four controller methods that can be overridden: `redirect_after_create`, `redirect_after_update`, `redirect_after_save`, and `redirect_after_destroy`.
|
|
312
|
+
|
|
313
|
+
For instance, to have the article controller redirect to the index page after both create and update:
|
|
314
|
+
|
|
315
|
+
```ruby
|
|
316
|
+
class ArticlesController
|
|
317
|
+
include Godmin::Resource
|
|
318
|
+
|
|
319
|
+
def redirect_after_save
|
|
320
|
+
articles_path
|
|
321
|
+
end
|
|
322
|
+
end
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
Or, to have the article controller redirect to the index page after create and the edit page after update:
|
|
326
|
+
|
|
327
|
+
```ruby
|
|
328
|
+
class ArticlesController
|
|
329
|
+
include Godmin::Resource
|
|
330
|
+
|
|
331
|
+
def redirect_after_create
|
|
332
|
+
articles_path
|
|
333
|
+
end
|
|
334
|
+
|
|
335
|
+
def redirect_after_update
|
|
336
|
+
edit_article_path(@resource)
|
|
337
|
+
end
|
|
338
|
+
end
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
If you wish to change the behaviour for every resource controller, consider creating a common resource controller that your other controllers can inherit from:
|
|
342
|
+
|
|
343
|
+
```ruby
|
|
344
|
+
class ResourceController < ApplicationController
|
|
345
|
+
include Godmin::Resource
|
|
346
|
+
|
|
347
|
+
def redirect_after_save
|
|
348
|
+
resource_class.model_name.route_key.to_sym
|
|
349
|
+
end
|
|
350
|
+
end
|
|
351
|
+
```
|
|
352
|
+
|
|
305
353
|
## Views
|
|
306
354
|
|
|
307
355
|
It is easy to override view templates and partials in Godmin, both globally and per resource. All you have to do is place a file with an identical name in your `app/views` directory. For instance, to override the `godmin/resource/index.html.erb` template for all resources, place a file under `app/views/resource/index.html.erb`. If you only wish to override it for articles, place it instead under `app/views/articles/index.html.erb`.
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
//
|
|
13
13
|
//= require jquery
|
|
14
14
|
//= require jquery_ujs
|
|
15
|
-
//= require bootstrap
|
|
16
|
-
//= require
|
|
15
|
+
//= require bootstrap-sprockets
|
|
16
|
+
//= require selectize
|
|
17
17
|
//= require godmin/batch_actions
|
|
18
18
|
//= require godmin/navigation
|
|
19
19
|
//= require godmin/select_tags
|
|
@@ -11,9 +11,10 @@
|
|
|
11
11
|
*= require_self
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
+
@import "bootstrap-sprockets";
|
|
14
15
|
@import "bootstrap";
|
|
15
|
-
@import "
|
|
16
|
-
@import "
|
|
16
|
+
@import "selectize";
|
|
17
|
+
@import "selectize.bootstrap3";
|
|
17
18
|
|
|
18
19
|
body {
|
|
19
20
|
margin-bottom: 20px;
|
|
@@ -28,7 +29,7 @@ body {
|
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
#filters {
|
|
31
|
-
.filter {
|
|
32
|
+
.filter .form-control {
|
|
32
33
|
min-width: 170px;
|
|
33
34
|
}
|
|
34
35
|
}
|
|
@@ -48,6 +49,10 @@ body {
|
|
|
48
49
|
margin: 0 0 10px 0;
|
|
49
50
|
}
|
|
50
51
|
|
|
52
|
+
.pagination-entries {
|
|
53
|
+
line-height: 35px;
|
|
54
|
+
}
|
|
55
|
+
|
|
51
56
|
.highlight {
|
|
52
57
|
-webkit-animation: highlight 3s;
|
|
53
58
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
<%= simple_form_for @resource, html: { role: "form" } do |f| %>
|
|
2
2
|
<% attrs_for_form.each do |attr| %>
|
|
3
3
|
<div class="form-group">
|
|
4
|
-
<% if @resource_class.
|
|
5
|
-
<%= f.
|
|
4
|
+
<% if @resource_class.reflect_on_association(attr) %>
|
|
5
|
+
<%= f.association attr, error: false, input_html: { class: "form-control select-tag" } %>
|
|
6
6
|
<% else %>
|
|
7
|
-
<%= f.
|
|
7
|
+
<%= f.input attr, error: false, input_html: { class: "form-control" } %>
|
|
8
8
|
<% end %>
|
|
9
9
|
</div>
|
|
10
10
|
<% end %>
|
|
@@ -1,6 +1,40 @@
|
|
|
1
1
|
<div class="pull-left">
|
|
2
|
-
|
|
2
|
+
<% if total_pages > 1 %>
|
|
3
|
+
<nav>
|
|
4
|
+
<ul class="pagination">
|
|
5
|
+
<% unless pages.first == 1 && current_page == pages.first %>
|
|
6
|
+
<li><%= link_to translate_scoped("pagination.first"), params.merge(page: 1) %></li>
|
|
7
|
+
<li><%= link_to "«", params.merge(page: current_page - 1) %></li>
|
|
8
|
+
<% end %>
|
|
9
|
+
<% unless pages.first == 1 %>
|
|
10
|
+
<li class="disabled"><%= link_to "…" %></li>
|
|
11
|
+
<% end %>
|
|
12
|
+
<% pages.each do |page| %>
|
|
13
|
+
<li class="<%= "active" if page == current_page %>">
|
|
14
|
+
<%= link_to page, params.merge(page: page) %>
|
|
15
|
+
</li>
|
|
16
|
+
<% end %>
|
|
17
|
+
<% unless pages.last == total_pages %>
|
|
18
|
+
<li class="disabled"><%= link_to "…" %></li>
|
|
19
|
+
<% end %>
|
|
20
|
+
<% unless pages.last == total_pages && current_page == pages.last %>
|
|
21
|
+
<li><%= link_to "»", params.merge(page: current_page + 1) %></li>
|
|
22
|
+
<li><%= link_to translate_scoped("pagination.last"), params.merge(page: total_pages) %></li>
|
|
23
|
+
<% end %>
|
|
24
|
+
</ul>
|
|
25
|
+
</nav>
|
|
26
|
+
<% end %>
|
|
3
27
|
</div>
|
|
4
|
-
<div class="pull-right">
|
|
5
|
-
|
|
28
|
+
<div class="pagination-entries pull-right hidden-xs">
|
|
29
|
+
<% if @resources.length == 0 %>
|
|
30
|
+
<%= translate_scoped("pagination.entries.zero", {
|
|
31
|
+
resource: @resource_class.model_name.human(count: @resources.length).downcase
|
|
32
|
+
}) %>
|
|
33
|
+
<% else %>
|
|
34
|
+
<%= translate_scoped("pagination.entries.other", {
|
|
35
|
+
resource: @resource_class.model_name.human(count: @resources.length).downcase,
|
|
36
|
+
count: @resources.length,
|
|
37
|
+
total: total_resources
|
|
38
|
+
}) %>
|
|
39
|
+
<% end %>
|
|
6
40
|
</div>
|
data/config/locales/en.yml
CHANGED
|
@@ -23,19 +23,13 @@ en:
|
|
|
23
23
|
signed_in: Signed in
|
|
24
24
|
signed_out: Signed out
|
|
25
25
|
failed_sign_in: Invalid credentials
|
|
26
|
-
|
|
26
|
+
flash:
|
|
27
|
+
create: "%{resource} was successfully created"
|
|
28
|
+
update: "%{resource} was successfully updated"
|
|
29
|
+
destroy: "%{resource} was successfully destroyed"
|
|
27
30
|
pagination:
|
|
28
31
|
first: "First"
|
|
29
32
|
last: "Last"
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
helpers:
|
|
34
|
-
page_entries_info:
|
|
35
|
-
one_page:
|
|
36
|
-
display_entries:
|
|
37
|
-
zero: "No %{entry_name} found"
|
|
38
|
-
one: "Displaying 1 %{entry_name}"
|
|
39
|
-
other: "Displaying all %{count} %{entry_name}"
|
|
40
|
-
more_pages:
|
|
41
|
-
display_entries: "Displaying %{entry_name} %{first} - %{last} of %{total} in total"
|
|
33
|
+
entries:
|
|
34
|
+
zero: "No %{resource} found"
|
|
35
|
+
other: "Showing %{count} out of %{total} %{resource}"
|
data/config/locales/sv.yml
CHANGED
|
@@ -23,19 +23,13 @@ sv:
|
|
|
23
23
|
signed_in: Loggade in
|
|
24
24
|
signed_out: Loggade ut
|
|
25
25
|
failed_sign_in: Fel inloggningsuppgifter
|
|
26
|
-
|
|
26
|
+
flash:
|
|
27
|
+
create: "%{resource} skapades"
|
|
28
|
+
update: "%{resource} uppdaterades"
|
|
29
|
+
destroy: "%{resource} togs bort"
|
|
27
30
|
pagination:
|
|
28
31
|
first: "Första"
|
|
29
32
|
last: "Sista"
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
helpers:
|
|
34
|
-
page_entries_info:
|
|
35
|
-
one_page:
|
|
36
|
-
display_entries:
|
|
37
|
-
zero: "Inga %{entry_name} hittades"
|
|
38
|
-
one: "Visar 1 %{entry_name}"
|
|
39
|
-
other: "Visar alla %{count} %{entry_name}"
|
|
40
|
-
more_pages:
|
|
41
|
-
display_entries: "Visar %{first} - %{last} av %{total} %{entry_name}"
|
|
33
|
+
entries:
|
|
34
|
+
zero: "Inga %{resource} funna"
|
|
35
|
+
other: "Visar %{count} av %{total} %{resource}"
|
data/godmin.gemspec
CHANGED
|
@@ -8,7 +8,7 @@ Gem::Specification.new do |gem|
|
|
|
8
8
|
gem.name = "godmin"
|
|
9
9
|
gem.version = Godmin::VERSION
|
|
10
10
|
gem.authors = ["Jens Ljungblad", "Linus Pettersson", "Varvet"]
|
|
11
|
-
gem.email = ["
|
|
11
|
+
gem.email = ["info@varvet.se"]
|
|
12
12
|
gem.homepage = "https://github.com/varvet/godmin"
|
|
13
13
|
gem.summary = "Godmin is an admin engine for Rails 4+"
|
|
14
14
|
gem.description = "Godmin is an admin engine for Rails 4+"
|
|
@@ -20,12 +20,11 @@ Gem::Specification.new do |gem|
|
|
|
20
20
|
gem.require_paths = ["lib"]
|
|
21
21
|
|
|
22
22
|
gem.add_dependency "bcrypt", "~> 3.1.7"
|
|
23
|
-
gem.add_dependency "bootstrap-sass", "~> 3.
|
|
23
|
+
gem.add_dependency "bootstrap-sass", "~> 3.3.1.0"
|
|
24
24
|
gem.add_dependency "coffee-rails", [">= 4.0", "< 4.2"]
|
|
25
|
-
gem.add_dependency "kaminari", "~> 0.16.1"
|
|
26
25
|
gem.add_dependency "rails", [">= 4.0", "< 4.2"]
|
|
27
26
|
gem.add_dependency "sass-rails", [">= 4.0", "< 4.2"]
|
|
28
|
-
gem.add_dependency "
|
|
27
|
+
gem.add_dependency "selectize-rails", "~> 0.11.2"
|
|
29
28
|
gem.add_dependency "simple_form", "~> 3.0.0"
|
|
30
29
|
|
|
31
30
|
gem.add_development_dependency "sqlite3"
|
|
@@ -28,6 +28,16 @@ class Godmin::InstallGenerator < Godmin::Generators::Base
|
|
|
28
28
|
end
|
|
29
29
|
end
|
|
30
30
|
|
|
31
|
+
def require_library_if_namespaced
|
|
32
|
+
return unless namespace
|
|
33
|
+
|
|
34
|
+
inject_into_file "lib/#{namespace}.rb", before: "require" do
|
|
35
|
+
<<-END.strip_heredoc
|
|
36
|
+
require "godmin"
|
|
37
|
+
END
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
31
41
|
def remove_layouts
|
|
32
42
|
remove_dir "app/views/layouts"
|
|
33
43
|
end
|
data/lib/godmin.rb
CHANGED
data/lib/godmin/application.rb
CHANGED
data/lib/godmin/resource.rb
CHANGED
|
@@ -22,8 +22,6 @@ module Godmin
|
|
|
22
22
|
include Godmin::Resource::Ordering
|
|
23
23
|
include Godmin::Resource::Pagination
|
|
24
24
|
|
|
25
|
-
respond_to :html, :json
|
|
26
|
-
|
|
27
25
|
before_action :set_resource_class
|
|
28
26
|
before_action :set_resources, only: :index
|
|
29
27
|
before_action :set_resource, only: [:show, :new, :edit, :update, :destroy]
|
|
@@ -61,34 +59,58 @@ module Godmin
|
|
|
61
59
|
end
|
|
62
60
|
|
|
63
61
|
def index
|
|
64
|
-
|
|
62
|
+
respond_to do |format|
|
|
63
|
+
format.html
|
|
64
|
+
format.json { render json: @resources.to_json }
|
|
65
|
+
end
|
|
65
66
|
end
|
|
66
67
|
|
|
67
68
|
def show
|
|
68
|
-
|
|
69
|
+
respond_to do |format|
|
|
70
|
+
format.html
|
|
71
|
+
format.json { render json: @resource.to_json }
|
|
72
|
+
end
|
|
69
73
|
end
|
|
70
74
|
|
|
71
75
|
def new
|
|
72
|
-
respond_with(@resource)
|
|
73
76
|
end
|
|
74
77
|
|
|
75
78
|
def edit
|
|
76
|
-
respond_with(@resource)
|
|
77
79
|
end
|
|
78
80
|
|
|
79
81
|
def create
|
|
80
|
-
@resource = resource_class.
|
|
81
|
-
|
|
82
|
+
@resource = resource_class.new(resource_params)
|
|
83
|
+
|
|
84
|
+
respond_to do |format|
|
|
85
|
+
if @resource.save
|
|
86
|
+
format.html { redirect_to redirect_after_create, notice: redirect_flash_message }
|
|
87
|
+
format.json { render :show, status: :created, location: @resource }
|
|
88
|
+
else
|
|
89
|
+
format.html { render :edit }
|
|
90
|
+
format.json { render json: @resource.errors, status: :unprocessable_entity }
|
|
91
|
+
end
|
|
92
|
+
end
|
|
82
93
|
end
|
|
83
94
|
|
|
84
95
|
def update
|
|
85
|
-
|
|
86
|
-
|
|
96
|
+
respond_to do |format|
|
|
97
|
+
if @resource.update(resource_params)
|
|
98
|
+
format.html { redirect_to redirect_after_update, notice: redirect_flash_message }
|
|
99
|
+
format.json { render :show, status: :ok, location: @resource }
|
|
100
|
+
else
|
|
101
|
+
format.html { render :edit }
|
|
102
|
+
format.json { render json: @resource.errors, status: :unprocessable_entity }
|
|
103
|
+
end
|
|
104
|
+
end
|
|
87
105
|
end
|
|
88
106
|
|
|
89
107
|
def destroy
|
|
90
108
|
@resource.destroy
|
|
91
|
-
|
|
109
|
+
|
|
110
|
+
respond_to do |format|
|
|
111
|
+
format.html { redirect_to redirect_after_destroy, notice: redirect_flash_message }
|
|
112
|
+
format.json { head :no_content }
|
|
113
|
+
end
|
|
92
114
|
end
|
|
93
115
|
|
|
94
116
|
# Gives the view access to the list of column names
|
|
@@ -119,8 +141,28 @@ module Godmin
|
|
|
119
141
|
authorize(@resource) if authorization_enabled?
|
|
120
142
|
end
|
|
121
143
|
|
|
144
|
+
def redirect_after_create
|
|
145
|
+
redirect_after_save
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
def redirect_after_update
|
|
149
|
+
redirect_after_save
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
def redirect_after_save
|
|
153
|
+
@resource
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
def redirect_after_destroy
|
|
157
|
+
resource_class.model_name.route_key.to_sym
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
def redirect_flash_message
|
|
161
|
+
translate_scoped("flash.#{action_name}", resource: @resource.class.model_name.human)
|
|
162
|
+
end
|
|
163
|
+
|
|
122
164
|
def resource_params
|
|
123
|
-
params.require(resource_class.name.
|
|
165
|
+
params.require(resource_class.name.underscore.to_sym).permit(attrs_for_form)
|
|
124
166
|
end
|
|
125
167
|
end
|
|
126
168
|
end
|
|
@@ -3,8 +3,59 @@ module Godmin
|
|
|
3
3
|
module Pagination
|
|
4
4
|
extend ActiveSupport::Concern
|
|
5
5
|
|
|
6
|
+
WINDOW_SIZE = 7
|
|
7
|
+
|
|
8
|
+
included do
|
|
9
|
+
helper_method :current_page
|
|
10
|
+
helper_method :pages
|
|
11
|
+
helper_method :total_pages
|
|
12
|
+
helper_method :total_resources
|
|
13
|
+
end
|
|
14
|
+
|
|
6
15
|
def apply_pagination(resources)
|
|
7
|
-
resources.
|
|
16
|
+
resources.limit(pagination_limit).offset(pagination_offset)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
private
|
|
20
|
+
|
|
21
|
+
def current_page
|
|
22
|
+
params[:page].present? ? params[:page].to_i : 1
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def pagination_limit
|
|
26
|
+
self.class.per_page
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def pagination_offset
|
|
30
|
+
(params[:page].to_i * self.class.per_page) - self.class.per_page
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def pages
|
|
34
|
+
pages = (1..total_pages).to_a
|
|
35
|
+
|
|
36
|
+
return pages unless total_pages > WINDOW_SIZE
|
|
37
|
+
|
|
38
|
+
if current_page < WINDOW_SIZE
|
|
39
|
+
pages.slice(0, WINDOW_SIZE)
|
|
40
|
+
elsif current_page > (total_pages - WINDOW_SIZE)
|
|
41
|
+
pages.slice(-WINDOW_SIZE, WINDOW_SIZE)
|
|
42
|
+
else
|
|
43
|
+
pages.slice(pages.index(current_page) - (WINDOW_SIZE / 2), WINDOW_SIZE)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def total_pages
|
|
48
|
+
(total_resources.to_f / self.class.per_page).ceil
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def total_resources
|
|
52
|
+
resources.limit(nil).offset(nil).count
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
module ClassMethods
|
|
56
|
+
def per_page
|
|
57
|
+
10
|
|
58
|
+
end
|
|
8
59
|
end
|
|
9
60
|
end
|
|
10
61
|
end
|
data/lib/godmin/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: godmin
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.9.
|
|
4
|
+
version: 0.9.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jens Ljungblad
|
|
@@ -10,163 +10,150 @@ authors:
|
|
|
10
10
|
autorequire:
|
|
11
11
|
bindir: bin
|
|
12
12
|
cert_chain: []
|
|
13
|
-
date: 2014-
|
|
13
|
+
date: 2014-12-09 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: bcrypt
|
|
17
17
|
requirement: !ruby/object:Gem::Requirement
|
|
18
18
|
requirements:
|
|
19
|
-
- - ~>
|
|
19
|
+
- - "~>"
|
|
20
20
|
- !ruby/object:Gem::Version
|
|
21
21
|
version: 3.1.7
|
|
22
22
|
type: :runtime
|
|
23
23
|
prerelease: false
|
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
|
25
25
|
requirements:
|
|
26
|
-
- - ~>
|
|
26
|
+
- - "~>"
|
|
27
27
|
- !ruby/object:Gem::Version
|
|
28
28
|
version: 3.1.7
|
|
29
29
|
- !ruby/object:Gem::Dependency
|
|
30
30
|
name: bootstrap-sass
|
|
31
31
|
requirement: !ruby/object:Gem::Requirement
|
|
32
32
|
requirements:
|
|
33
|
-
- - ~>
|
|
33
|
+
- - "~>"
|
|
34
34
|
- !ruby/object:Gem::Version
|
|
35
|
-
version: 3.
|
|
35
|
+
version: 3.3.1.0
|
|
36
36
|
type: :runtime
|
|
37
37
|
prerelease: false
|
|
38
38
|
version_requirements: !ruby/object:Gem::Requirement
|
|
39
39
|
requirements:
|
|
40
|
-
- - ~>
|
|
40
|
+
- - "~>"
|
|
41
41
|
- !ruby/object:Gem::Version
|
|
42
|
-
version: 3.
|
|
42
|
+
version: 3.3.1.0
|
|
43
43
|
- !ruby/object:Gem::Dependency
|
|
44
44
|
name: coffee-rails
|
|
45
45
|
requirement: !ruby/object:Gem::Requirement
|
|
46
46
|
requirements:
|
|
47
|
-
- -
|
|
47
|
+
- - ">="
|
|
48
48
|
- !ruby/object:Gem::Version
|
|
49
49
|
version: '4.0'
|
|
50
|
-
- - <
|
|
50
|
+
- - "<"
|
|
51
51
|
- !ruby/object:Gem::Version
|
|
52
52
|
version: '4.2'
|
|
53
53
|
type: :runtime
|
|
54
54
|
prerelease: false
|
|
55
55
|
version_requirements: !ruby/object:Gem::Requirement
|
|
56
56
|
requirements:
|
|
57
|
-
- -
|
|
57
|
+
- - ">="
|
|
58
58
|
- !ruby/object:Gem::Version
|
|
59
59
|
version: '4.0'
|
|
60
|
-
- - <
|
|
60
|
+
- - "<"
|
|
61
61
|
- !ruby/object:Gem::Version
|
|
62
62
|
version: '4.2'
|
|
63
|
-
- !ruby/object:Gem::Dependency
|
|
64
|
-
name: kaminari
|
|
65
|
-
requirement: !ruby/object:Gem::Requirement
|
|
66
|
-
requirements:
|
|
67
|
-
- - ~>
|
|
68
|
-
- !ruby/object:Gem::Version
|
|
69
|
-
version: 0.16.1
|
|
70
|
-
type: :runtime
|
|
71
|
-
prerelease: false
|
|
72
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
73
|
-
requirements:
|
|
74
|
-
- - ~>
|
|
75
|
-
- !ruby/object:Gem::Version
|
|
76
|
-
version: 0.16.1
|
|
77
63
|
- !ruby/object:Gem::Dependency
|
|
78
64
|
name: rails
|
|
79
65
|
requirement: !ruby/object:Gem::Requirement
|
|
80
66
|
requirements:
|
|
81
|
-
- -
|
|
67
|
+
- - ">="
|
|
82
68
|
- !ruby/object:Gem::Version
|
|
83
69
|
version: '4.0'
|
|
84
|
-
- - <
|
|
70
|
+
- - "<"
|
|
85
71
|
- !ruby/object:Gem::Version
|
|
86
72
|
version: '4.2'
|
|
87
73
|
type: :runtime
|
|
88
74
|
prerelease: false
|
|
89
75
|
version_requirements: !ruby/object:Gem::Requirement
|
|
90
76
|
requirements:
|
|
91
|
-
- -
|
|
77
|
+
- - ">="
|
|
92
78
|
- !ruby/object:Gem::Version
|
|
93
79
|
version: '4.0'
|
|
94
|
-
- - <
|
|
80
|
+
- - "<"
|
|
95
81
|
- !ruby/object:Gem::Version
|
|
96
82
|
version: '4.2'
|
|
97
83
|
- !ruby/object:Gem::Dependency
|
|
98
84
|
name: sass-rails
|
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|
|
100
86
|
requirements:
|
|
101
|
-
- -
|
|
87
|
+
- - ">="
|
|
102
88
|
- !ruby/object:Gem::Version
|
|
103
89
|
version: '4.0'
|
|
104
|
-
- - <
|
|
90
|
+
- - "<"
|
|
105
91
|
- !ruby/object:Gem::Version
|
|
106
92
|
version: '4.2'
|
|
107
93
|
type: :runtime
|
|
108
94
|
prerelease: false
|
|
109
95
|
version_requirements: !ruby/object:Gem::Requirement
|
|
110
96
|
requirements:
|
|
111
|
-
- -
|
|
97
|
+
- - ">="
|
|
112
98
|
- !ruby/object:Gem::Version
|
|
113
99
|
version: '4.0'
|
|
114
|
-
- - <
|
|
100
|
+
- - "<"
|
|
115
101
|
- !ruby/object:Gem::Version
|
|
116
102
|
version: '4.2'
|
|
117
103
|
- !ruby/object:Gem::Dependency
|
|
118
|
-
name:
|
|
104
|
+
name: selectize-rails
|
|
119
105
|
requirement: !ruby/object:Gem::Requirement
|
|
120
106
|
requirements:
|
|
121
|
-
- - ~>
|
|
107
|
+
- - "~>"
|
|
122
108
|
- !ruby/object:Gem::Version
|
|
123
|
-
version:
|
|
109
|
+
version: 0.11.2
|
|
124
110
|
type: :runtime
|
|
125
111
|
prerelease: false
|
|
126
112
|
version_requirements: !ruby/object:Gem::Requirement
|
|
127
113
|
requirements:
|
|
128
|
-
- - ~>
|
|
114
|
+
- - "~>"
|
|
129
115
|
- !ruby/object:Gem::Version
|
|
130
|
-
version:
|
|
116
|
+
version: 0.11.2
|
|
131
117
|
- !ruby/object:Gem::Dependency
|
|
132
118
|
name: simple_form
|
|
133
119
|
requirement: !ruby/object:Gem::Requirement
|
|
134
120
|
requirements:
|
|
135
|
-
- - ~>
|
|
121
|
+
- - "~>"
|
|
136
122
|
- !ruby/object:Gem::Version
|
|
137
123
|
version: 3.0.0
|
|
138
124
|
type: :runtime
|
|
139
125
|
prerelease: false
|
|
140
126
|
version_requirements: !ruby/object:Gem::Requirement
|
|
141
127
|
requirements:
|
|
142
|
-
- - ~>
|
|
128
|
+
- - "~>"
|
|
143
129
|
- !ruby/object:Gem::Version
|
|
144
130
|
version: 3.0.0
|
|
145
131
|
- !ruby/object:Gem::Dependency
|
|
146
132
|
name: sqlite3
|
|
147
133
|
requirement: !ruby/object:Gem::Requirement
|
|
148
134
|
requirements:
|
|
149
|
-
- -
|
|
135
|
+
- - ">="
|
|
150
136
|
- !ruby/object:Gem::Version
|
|
151
137
|
version: '0'
|
|
152
138
|
type: :development
|
|
153
139
|
prerelease: false
|
|
154
140
|
version_requirements: !ruby/object:Gem::Requirement
|
|
155
141
|
requirements:
|
|
156
|
-
- -
|
|
142
|
+
- - ">="
|
|
157
143
|
- !ruby/object:Gem::Version
|
|
158
144
|
version: '0'
|
|
159
145
|
description: Godmin is an admin engine for Rails 4+
|
|
160
146
|
email:
|
|
161
|
-
-
|
|
147
|
+
- info@varvet.se
|
|
162
148
|
executables: []
|
|
163
149
|
extensions: []
|
|
164
150
|
extra_rdoc_files: []
|
|
165
151
|
files:
|
|
166
|
-
- .gitignore
|
|
167
|
-
- .hound.yml
|
|
168
|
-
- .rubocop.yml
|
|
169
|
-
- .travis.yml
|
|
152
|
+
- ".gitignore"
|
|
153
|
+
- ".hound.yml"
|
|
154
|
+
- ".rubocop.yml"
|
|
155
|
+
- ".travis.yml"
|
|
156
|
+
- CHANGELOG.md
|
|
170
157
|
- Gemfile
|
|
171
158
|
- MIT-LICENSE
|
|
172
159
|
- README.md
|
|
@@ -194,13 +181,6 @@ files:
|
|
|
194
181
|
- app/views/godmin/resource/show.html.erb
|
|
195
182
|
- app/views/godmin/sessions/new.html.erb
|
|
196
183
|
- app/views/godmin/shared/_navigation.html.erb
|
|
197
|
-
- app/views/kaminari/_first_page.html.erb
|
|
198
|
-
- app/views/kaminari/_gap.html.erb
|
|
199
|
-
- app/views/kaminari/_last_page.html.erb
|
|
200
|
-
- app/views/kaminari/_next_page.html.erb
|
|
201
|
-
- app/views/kaminari/_page.html.erb
|
|
202
|
-
- app/views/kaminari/_paginator.html.erb
|
|
203
|
-
- app/views/kaminari/_prev_page.html.erb
|
|
204
184
|
- app/views/layouts/godmin/_content.html.erb
|
|
205
185
|
- app/views/layouts/godmin/_layout.html.erb
|
|
206
186
|
- app/views/layouts/godmin/application.html.erb
|
|
@@ -293,17 +273,17 @@ require_paths:
|
|
|
293
273
|
- lib
|
|
294
274
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
295
275
|
requirements:
|
|
296
|
-
- -
|
|
276
|
+
- - ">="
|
|
297
277
|
- !ruby/object:Gem::Version
|
|
298
278
|
version: '0'
|
|
299
279
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
300
280
|
requirements:
|
|
301
|
-
- -
|
|
281
|
+
- - ">="
|
|
302
282
|
- !ruby/object:Gem::Version
|
|
303
283
|
version: '0'
|
|
304
284
|
requirements: []
|
|
305
285
|
rubyforge_project:
|
|
306
|
-
rubygems_version: 2.2.
|
|
286
|
+
rubygems_version: 2.2.0
|
|
307
287
|
signing_key:
|
|
308
288
|
specification_version: 4
|
|
309
289
|
summary: Godmin is an admin engine for Rails 4+
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
<%= paginator.render do -%>
|
|
2
|
-
<ul class="pagination">
|
|
3
|
-
<%= first_page_tag unless current_page.first? %>
|
|
4
|
-
<%= prev_page_tag unless current_page.first? %>
|
|
5
|
-
<% each_page do |page| -%>
|
|
6
|
-
<% if page.left_outer? || page.right_outer? || page.inside_window? -%>
|
|
7
|
-
<%= page_tag page %>
|
|
8
|
-
<% elsif !page.was_truncated? -%>
|
|
9
|
-
<%= gap_tag %>
|
|
10
|
-
<% end -%>
|
|
11
|
-
<% end -%>
|
|
12
|
-
<%= next_page_tag unless current_page.last? %>
|
|
13
|
-
<%= last_page_tag unless current_page.last? %>
|
|
14
|
-
</ul>
|
|
15
|
-
<% end -%>
|