storytime-admin 0.2.0 → 0.2.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 +4 -4
- data/app/assets/javascripts/storytime_admin.js +1 -3
- data/app/assets/javascripts/storytime_admin/selects.coffee +2 -0
- data/app/controllers/storytime_admin/application_controller.rb +21 -8
- data/app/helpers/storytime_admin/application_helper.rb +6 -2
- data/app/views/storytime_admin/application/_fields.html.haml +4 -1
- data/app/views/storytime_admin/application/_headers.html.haml +2 -2
- data/app/views/storytime_admin/application/_row.html.haml +1 -1
- data/app/views/storytime_admin/application/_search.html.haml +6 -0
- data/app/views/storytime_admin/application/index.html.haml +4 -1
- data/lib/generators/storytime_admin/resource/templates/controller.rb +24 -8
- data/lib/storytime_admin/engine.rb +2 -0
- data/lib/storytime_admin/to_csv.rb +22 -0
- data/lib/storytime_admin/version.rb +1 -1
- metadata +32 -6
- data/app/assets/javascripts/storytime_admin/table_links.js.coffee +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca19df95337b36317294b2f754e5618c013ce9c5
|
4
|
+
data.tar.gz: 973448d39e10756f75e3ada1ea30321fa6f67680
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e67229b9729669500efd655813a239cffb66e00da0539e23e04769b8e3f7121f8d6d3c523094bfb4ecc20d6fb661ac13905de5d2b14235e40feee65b297ee4da
|
7
|
+
data.tar.gz: ee22c05cbaefed41c890cf7817de81a9f8903e9e223bff967f1d3bfef8ad972f938c53c27b7ff11ed72e4fc45bcbbf3923c7a2489d95eab695a31b481d5e2cfb
|
@@ -8,12 +8,21 @@ module StorytimeAdmin
|
|
8
8
|
before_action :ensure_admin!
|
9
9
|
before_action :load_model, only: [:edit, :update, :destroy]
|
10
10
|
|
11
|
-
helper_method :model, :model_display_name, :model_display_name_pluralized, :model_name,
|
11
|
+
helper_method :model, :model_display_name, :model_display_name_pluralized, :model_name,
|
12
12
|
:model_sym, :sort_column, :sort_direction, :admin_controller?, :headers,
|
13
|
-
:form_attributes, :index_attr, :current_user, :polymorphic_route_components
|
13
|
+
:form_attributes, :index_attr, :current_user, :polymorphic_route_components, :search_keys
|
14
14
|
|
15
15
|
def index
|
16
|
-
@
|
16
|
+
@collection_before_pagination = model.all
|
17
|
+
@collection_before_pagination = @collection_before_pagination.where("#{search_keys.join(' ILIKE :q OR ')} ILIKE :q", q: "%#{params[:search]}%") if search_keys.length > 0 && params[:search].present?
|
18
|
+
yield @collection_before_pagination if block_given?
|
19
|
+
@collection_before_pagination = @collection_before_pagination.order("#{sort_column} #{sort_direction}")
|
20
|
+
@collection = @collection_before_pagination.page(params[:page]).per(20)
|
21
|
+
|
22
|
+
respond_to do |format|
|
23
|
+
format.html
|
24
|
+
format.csv { send_data @collection_before_pagination.to_csv, filename: "#{model_name.underscore.pluralize}-#{Date.today}.csv" }
|
25
|
+
end
|
17
26
|
end
|
18
27
|
|
19
28
|
def new
|
@@ -66,7 +75,7 @@ module StorytimeAdmin
|
|
66
75
|
end
|
67
76
|
end
|
68
77
|
|
69
|
-
def attributes
|
78
|
+
def attributes
|
70
79
|
@attributes ||= model.columns.map(&:name)
|
71
80
|
end
|
72
81
|
|
@@ -88,11 +97,11 @@ module StorytimeAdmin
|
|
88
97
|
|
89
98
|
def index_attr
|
90
99
|
if attributes.include?("title")
|
91
|
-
|
100
|
+
{ "title" => "title" }
|
92
101
|
elsif attributes.include?("name")
|
93
|
-
|
102
|
+
{ "name" => "name" }
|
94
103
|
else
|
95
|
-
|
104
|
+
{ "id" => "id" }
|
96
105
|
end
|
97
106
|
end
|
98
107
|
|
@@ -121,13 +130,17 @@ module StorytimeAdmin
|
|
121
130
|
end
|
122
131
|
|
123
132
|
def sort_column
|
124
|
-
|
133
|
+
params[:sort] || "#{model.name.tableize}.id"
|
125
134
|
end
|
126
135
|
|
127
136
|
def sort_direction
|
128
137
|
%w[asc desc].include?(params[:direction]) ? params[:direction] : "asc"
|
129
138
|
end
|
130
139
|
|
140
|
+
def search_keys
|
141
|
+
[]
|
142
|
+
end
|
143
|
+
|
131
144
|
def admin_controller?
|
132
145
|
true
|
133
146
|
end
|
@@ -30,11 +30,15 @@ module StorytimeAdmin
|
|
30
30
|
direction = column == sort_column && sort_direction == "asc" ? "desc" : "asc"
|
31
31
|
direction_arrow = if column == sort_column
|
32
32
|
direction == "asc" ? icon("caret-up") : icon("caret-down")
|
33
|
-
else
|
33
|
+
else
|
34
34
|
nil
|
35
35
|
end
|
36
36
|
|
37
|
-
link_to "#{title} #{direction_arrow}".html_safe,
|
37
|
+
link_to "#{title} #{direction_arrow}".html_safe, params.merge(sort: column, direction: direction, page: nil)
|
38
|
+
end
|
39
|
+
|
40
|
+
def has_many_association?(model, attribute)
|
41
|
+
model.reflect_on_all_associations(:has_many).map(&:name).include?(attribute)
|
38
42
|
end
|
39
43
|
end
|
40
44
|
end
|
@@ -1,3 +1,3 @@
|
|
1
|
-
- index_attr.each do |attribute|
|
1
|
+
- index_attr.each do |sort, attribute|
|
2
2
|
%th{:class => "sort_by"}
|
3
|
-
= sortable(attribute.
|
3
|
+
= sortable(sort, attribute.titleize)
|
@@ -1,2 +1,2 @@
|
|
1
|
-
- index_attr.each do |attribute|
|
1
|
+
- index_attr.each do |sort, attribute|
|
2
2
|
%td= object.send(attribute)
|
@@ -0,0 +1,6 @@
|
|
1
|
+
= form_tag [model], method: :get, class: "form-inline" do
|
2
|
+
= hidden_field_tag :direction, params[:direction] if params[:direction].present?
|
3
|
+
= hidden_field_tag :sort, params[:sort] if params[:sort].present?
|
4
|
+
.form-group
|
5
|
+
= text_field_tag :search, params[:search], class: 'form-control input-sm'
|
6
|
+
= submit_tag "Search", name: nil, class: "btn btn-primary btn-sm btn-outline"
|
@@ -6,5 +6,8 @@
|
|
6
6
|
= link_to "New #{model_display_name}", [:new, model_sym], class: "btn btn-sm btn-primary btn-outline pull-right"
|
7
7
|
%h3.scroll-panel-title= model_display_name_pluralized
|
8
8
|
.scroll-panel-body
|
9
|
+
= render 'search' if search_keys.length > 0
|
10
|
+
|
9
11
|
= render 'table'
|
10
|
-
= paginate @collection, theme: 'twitter-bootstrap-3'
|
12
|
+
= paginate @collection, theme: 'twitter-bootstrap-3'
|
13
|
+
%p= link_to "Download CSV", [storytime_admin, model, format: :csv]
|
@@ -12,7 +12,7 @@ module StorytimeAdmin
|
|
12
12
|
# end
|
13
13
|
|
14
14
|
##########################################
|
15
|
-
### Add attributes here to exclude them
|
15
|
+
### Add attributes here to exclude them
|
16
16
|
### from permitted_params
|
17
17
|
##########################################
|
18
18
|
# def permitted_params_blacklist
|
@@ -20,7 +20,7 @@ module StorytimeAdmin
|
|
20
20
|
# end
|
21
21
|
|
22
22
|
##########################################
|
23
|
-
### Add attributes here to use the default
|
23
|
+
### Add attributes here to use the default
|
24
24
|
### form but exclude additional attributes
|
25
25
|
##########################################
|
26
26
|
# def form_blacklist
|
@@ -28,18 +28,34 @@ module StorytimeAdmin
|
|
28
28
|
# end
|
29
29
|
|
30
30
|
##########################################
|
31
|
-
### If you are using the default index
|
32
|
-
### template, this controls which attributes
|
31
|
+
### If you are using the default index
|
32
|
+
### template, this controls which attributes
|
33
33
|
### are used in the table
|
34
34
|
##########################################
|
35
35
|
# def index_attr
|
36
36
|
# if attributes.include?("title")
|
37
|
-
#
|
37
|
+
# { "title" => "title" }
|
38
38
|
# elsif attributes.include?("name")
|
39
|
-
#
|
39
|
+
# { "name" => "name" }
|
40
40
|
# else
|
41
|
-
#
|
41
|
+
# { "id" => "id" }
|
42
42
|
# end
|
43
43
|
# end
|
44
|
+
|
45
|
+
##########################################
|
46
|
+
### Add attributes here to be able to
|
47
|
+
### search by
|
48
|
+
##########################################
|
49
|
+
# def search_keys
|
50
|
+
# ["name"]
|
51
|
+
# end
|
52
|
+
|
53
|
+
##########################################
|
54
|
+
### Add additional attributes such as
|
55
|
+
### assocations to be included in the form
|
56
|
+
# ##########################################
|
57
|
+
# def form_attributes
|
58
|
+
# @form_attributes ||= super + ["associated_model"]
|
59
|
+
# end
|
44
60
|
end
|
45
|
-
end
|
61
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module StorytimeAdmin
|
2
|
+
module ToCsv
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
module ClassMethods
|
6
|
+
def csv_columns
|
7
|
+
column_names
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_csv
|
11
|
+
CSV.generate(headers: true) do |csv|
|
12
|
+
csv << self.csv_columns
|
13
|
+
all.each do |record|
|
14
|
+
csv << self.csv_columns.map{ |attr| record.send(attr) }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
ActiveRecord::Base.send :include, StorytimeAdmin::ToCsv
|
metadata
CHANGED
@@ -1,29 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: storytime-admin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Van Der Beek
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-12-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '4.0'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '5.1'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- - "
|
27
|
+
- - ">="
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: '4.0'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '5.1'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: kaminari
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -59,6 +65,9 @@ dependencies:
|
|
59
65
|
- - ">="
|
60
66
|
- !ruby/object:Gem::Version
|
61
67
|
version: '4.0'
|
68
|
+
- - "<"
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '4.2'
|
62
71
|
type: :runtime
|
63
72
|
prerelease: false
|
64
73
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -66,6 +75,9 @@ dependencies:
|
|
66
75
|
- - ">="
|
67
76
|
- !ruby/object:Gem::Version
|
68
77
|
version: '4.0'
|
78
|
+
- - "<"
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '4.2'
|
69
81
|
- !ruby/object:Gem::Dependency
|
70
82
|
name: jquery-rails
|
71
83
|
requirement: !ruby/object:Gem::Requirement
|
@@ -73,6 +85,9 @@ dependencies:
|
|
73
85
|
- - ">="
|
74
86
|
- !ruby/object:Gem::Version
|
75
87
|
version: '3.0'
|
88
|
+
- - "<"
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '4.2'
|
76
91
|
type: :runtime
|
77
92
|
prerelease: false
|
78
93
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -80,6 +95,9 @@ dependencies:
|
|
80
95
|
- - ">="
|
81
96
|
- !ruby/object:Gem::Version
|
82
97
|
version: '3.0'
|
98
|
+
- - "<"
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '4.2'
|
83
101
|
- !ruby/object:Gem::Dependency
|
84
102
|
name: haml-rails
|
85
103
|
requirement: !ruby/object:Gem::Requirement
|
@@ -115,6 +133,9 @@ dependencies:
|
|
115
133
|
- - ">="
|
116
134
|
- !ruby/object:Gem::Version
|
117
135
|
version: '4.0'
|
136
|
+
- - "<="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 5.0.6
|
118
139
|
type: :runtime
|
119
140
|
prerelease: false
|
120
141
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -122,6 +143,9 @@ dependencies:
|
|
122
143
|
- - ">="
|
123
144
|
- !ruby/object:Gem::Version
|
124
145
|
version: '4.0'
|
146
|
+
- - "<="
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: 5.0.6
|
125
149
|
- !ruby/object:Gem::Dependency
|
126
150
|
name: font-awesome-sass
|
127
151
|
requirement: !ruby/object:Gem::Requirement
|
@@ -273,7 +297,7 @@ files:
|
|
273
297
|
- README.rdoc
|
274
298
|
- Rakefile
|
275
299
|
- app/assets/javascripts/storytime_admin.js
|
276
|
-
- app/assets/javascripts/storytime_admin/
|
300
|
+
- app/assets/javascripts/storytime_admin/selects.coffee
|
277
301
|
- app/assets/stylesheets/storytime_admin.css.scss
|
278
302
|
- app/assets/stylesheets/storytime_admin/_content.css.scss
|
279
303
|
- app/assets/stylesheets/storytime_admin/_tables.css.scss
|
@@ -287,6 +311,7 @@ files:
|
|
287
311
|
- app/views/storytime_admin/application/_navigation.html.haml
|
288
312
|
- app/views/storytime_admin/application/_object.html.haml
|
289
313
|
- app/views/storytime_admin/application/_row.html.haml
|
314
|
+
- app/views/storytime_admin/application/_search.html.haml
|
290
315
|
- app/views/storytime_admin/application/_table.html.haml
|
291
316
|
- app/views/storytime_admin/application/edit.html.haml
|
292
317
|
- app/views/storytime_admin/application/index.html.haml
|
@@ -297,6 +322,7 @@ files:
|
|
297
322
|
- lib/generators/storytime_admin/resource/templates/controller.rb
|
298
323
|
- lib/storytime_admin.rb
|
299
324
|
- lib/storytime_admin/engine.rb
|
325
|
+
- lib/storytime_admin/to_csv.rb
|
300
326
|
- lib/storytime_admin/version.rb
|
301
327
|
- lib/tasks/admin_tasks.rake
|
302
328
|
homepage: http://www.github.com/flyoverworks/storytime-admin
|
@@ -319,7 +345,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
319
345
|
version: '0'
|
320
346
|
requirements: []
|
321
347
|
rubyforge_project:
|
322
|
-
rubygems_version: 2.
|
348
|
+
rubygems_version: 2.4.5.1
|
323
349
|
signing_key:
|
324
350
|
specification_version: 4
|
325
351
|
summary: Admin engine originally created for Storytime
|