superuser 0.2.6 → 0.3.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.
@@ -1,10 +1,21 @@
1
1
  module Superuser
2
2
 
3
- class BaseController < ApplicationController
4
-
5
- layout 'superuser/application'
3
+ class BaseController < ApplicationController
6
4
 
5
+ layout 'superuser/application'
7
6
  before_action :authenticated_superuser
7
+
8
+ # ~~~~~~~~~ Pagy configuration ~~~~~~~~~
9
+ # pagy - include backend and frontend
10
+ include Pagy::Backend
11
+ include Pagy::Frontend
12
+ require 'pagy/extras/bootstrap'
13
+ # pagy - add helper_method for navigation
14
+ helper_method :pagy_nav
15
+ helper_method :pagy_bootstrap_nav
16
+ # pagy - Items per page
17
+ Pagy::VARS[:items] = 15
18
+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8
19
 
9
20
  private
10
21
 
@@ -13,40 +24,31 @@ module Superuser
13
24
  # example: redirect_to root_url if !current_user || current_user.role != 'admin'
14
25
  end
15
26
 
16
- def run_search(model)
17
-
18
- search_map = {'gt': '>', 'lt': '<', 'gte': '>=', 'lte': '<=', 'equal': '=', 'like': 'LIKE'}
19
-
20
- operator = search_map[params[:operator].downcase.to_sym]
27
+ def run_search(model)
28
+ search_map = {'gt': '>', 'lt': '<', 'gte': '>=', 'lte': '<=', 'equal': '=', 'like': 'LIKE'}
21
29
 
22
- val = (operator == 'LIKE' ? "%#{params[:search_value]}%" : params[:search_value])
30
+ operator = search_map[params[:operator].downcase.to_sym]
23
31
 
24
- results = model
25
- .where("cast(#{params[:search_field]} as text) #{operator} ?", val)
26
- .page(params[:page]).per(10)
32
+ val = (operator == 'LIKE' ? "%#{params[:search_value]}%" : params[:search_value])
27
33
 
28
- flash.now[:warning] = "Sorry! cannot find any #{params[:search_field].upcase} with the value #{operator} '#{params[:search_value]}' :(" if results.blank?
34
+ results =
35
+ pagy(
36
+ model.where("cast(#{params[:search_field]} as text) #{operator} ?", val)
37
+ )
29
38
 
30
- return results
39
+ flash.now[:warning] = "Sorry! cannot find any #{params[:search_field].upcase} with the value #{operator} '#{params[:search_value]}' :(" if results.blank?
31
40
 
32
- end
41
+ return results
42
+ end
33
43
 
34
44
  def flash_class(key)
35
-
36
- case key
37
-
38
- when "success" then "alert alert-success"
39
-
40
- when "warning" then "alert alert-warning"
41
-
42
- when "notice" then "alert alert-info"
43
-
44
- when "alert" then "alert alert-danger"
45
-
46
- end
47
-
48
- end
49
-
45
+ case key
46
+ when "success" then "alert alert-success"
47
+ when "warning" then "alert alert-warning"
48
+ when "notice" then "alert alert-info"
49
+ when "alert" then "alert alert-danger"
50
+ end
51
+ end
50
52
  helper_method :flash_class
51
53
 
52
54
  end
@@ -1,102 +1,70 @@
1
1
  module Superuser
2
2
 
3
- class <%= get_controller_name %>Controller < BaseController
3
+ class <%= get_controller_name %>Controller < BaseController
4
4
 
5
- # List all the (only) actions so it won't be applied to user's custom actions
5
+ # List all the (only) actions so it won't be applied to user's custom actions
6
6
 
7
- before_action :set_<%= resource %>, only: [:show, :edit, :update, :destroy]
7
+ before_action :set_<%= resource %>, only: [:show, :edit, :update, :destroy]
8
8
 
9
- # GET /<%= resources %>
10
- def index
11
-
12
- if params[:search]
13
-
14
- @<%= resources %> = run_search(<%= get_model %>)
15
-
16
- else
17
-
18
- @<%= resources %> = <%= get_model %>.page(params[:page]).per(10)
19
-
20
- end
21
-
22
- end
23
-
24
- # GET /<%= resources %>/1
25
- def show
26
-
27
- end
28
-
29
- # GET /<%= resources %>/new
30
- def new
31
-
32
- @<%= resource %> = <%= get_model %>.new
33
-
34
- end
35
-
36
- # GET /<%= resources %>/1/edit
37
- def edit
38
-
39
- end
40
-
41
- # POST /<%= resources %>
42
- def create
43
-
44
- @<%= resource %> = <%= get_model %>.new(<%= resource %>_params)
45
-
46
- if @<%= resource %>.save
47
-
48
- redirect_to [:superuser, @<%= resource %>], notice: "<%= resource %> was successfully created."
49
-
50
- else
51
-
52
- render :new
53
-
54
- end
55
-
56
- end
57
-
58
- # PATCH/PUT /<%= resources %>/1
59
- def update
60
-
61
- if @<%= resource %>.update(<%= resource %>_params)
62
-
63
- redirect_to [:superuser, @<%= resource %>], notice: "<%= resource %> was successfully updated."
64
-
65
- else
66
-
67
- render :edit
68
-
69
- end
70
-
71
- end
72
-
73
- # DELETE /<%= resources %>/1
74
- def destroy
75
-
76
- @<%= resource %>.destroy
77
-
78
- redirect_to [:superuser, :<%= resources %>], notice: "<%= resource %> was successfully destroyed."
79
-
80
- end
9
+ # GET /<%= resources %>
10
+ def index
11
+ if params[:search]
12
+ @pagy, @<%= resources %> = run_search(<%= get_model %>)
13
+ else
14
+ @pagy, @<%= resources %> = pagy(<%= get_model %>)
15
+ end
16
+ end
81
17
 
82
- private
83
- # Use callbacks to share common setup or constraints between actions.
18
+ # GET /<%= resources %>/1
19
+ def show
20
+ end
84
21
 
22
+ # GET /<%= resources %>/new
23
+ def new
24
+ @<%= resource %> = <%= get_model %>.new
25
+ end
85
26
 
86
- # Only allow a trusted parameter "white list" through.
87
- def <%= resource %>_params
27
+ # GET /<%= resources %>/1/edit
28
+ def edit
29
+ end
88
30
 
89
- params.require(:<%= resource %>).permit(<%= editable_attributes.map { |a| ":" + a[:name] }.join(', ') %>)
31
+ # POST /<%= resources %>
32
+ def create
33
+ @<%= resource %> = <%= get_model %>.new(<%= resource %>_params)
34
+ if @<%= resource %>.save
35
+ redirect_to [:superuser, @<%= resource %>], notice: "<%= resource %> was successfully created."
36
+ else
37
+ render :new
38
+ end
39
+ end
90
40
 
91
- end
41
+ # PATCH/PUT /<%= resources %>/1
42
+ def update
43
+ if @<%= resource %>.update(<%= resource %>_params)
44
+ redirect_to [:superuser, @<%= resource %>], notice: "<%= resource %> was successfully updated."
45
+ else
46
+ render :edit
47
+ end
48
+ end
92
49
 
50
+ # DELETE /<%= resources %>/1
51
+ def destroy
52
+ @<%= resource %>.destroy
53
+ redirect_to [:superuser, :<%= resources %>], notice: "<%= resource %> was successfully destroyed."
54
+ end
93
55
 
94
- def set_<%= resource %>
56
+ private
57
+ # Use callbacks to share common setup or constraints between actions.
95
58
 
96
- @<%= resource %> = <%= get_model %>.find(params[:id])
59
+ # Only allow a trusted parameter "white list" through.
60
+ def <%= resource %>_params
61
+ params.require(:<%= resource %>).permit(<%= editable_attributes.map { |a| ":" + a[:name] }.join(', ') %>)
62
+ end
97
63
 
98
- end
64
+ def set_<%= resource %>
65
+ @<%= resource %> = <%= get_model %>.find(params[:id])
66
+ end
99
67
 
100
- end
68
+ end
101
69
 
102
70
  end
@@ -1,10 +1,8 @@
1
1
  module Superuser
2
2
 
3
- class DashboardController < BaseController
4
-
5
- def index
6
- end
7
-
3
+ class DashboardController < BaseController
4
+ def index
8
5
  end
6
+ end
9
7
 
10
8
  end
@@ -1,311 +1,280 @@
1
1
  $navbar-height: 68px;
2
2
 
3
3
  html{
4
- height: 100%;
4
+ height: 100%;
5
5
  }
6
- body{
7
- background: #F2F2F2;
8
- }
9
-
10
- .attribute-line{
11
- padding: 0.8rem;
12
6
 
13
- &:nth-child(even){
14
- background: #EFEFEF;
15
- }
16
-
17
- &:nth-child(odd){
18
- background: #FAFAFA;
19
- }
20
- }
7
+ body{
8
+ background: #F2F2F2;
9
+ }
21
10
 
11
+ .attribute-line{
12
+ padding: 0.8rem;
13
+ &:nth-child(even){
14
+ background: #EFEFEF;
15
+ }
16
+ &:nth-child(odd){
17
+ background: #FAFAFA;
18
+ }
19
+ }
22
20
 
23
21
  .footer{
24
- padding: 16px;
25
- // height: 40px;
26
- // line-height: 40px;
27
- // font-size: 1rem;
28
- // bottom: 0;
29
- // color: #67757c;
30
- // left: 0px;
31
- // position: absolute;
32
- // right: 0;
33
- border-top: 1px solid rgba(120, 130, 140, 0.13);
34
- background: #ffffff;
22
+ padding: 16px;
23
+ // height: 40px;
24
+ // line-height: 40px;
25
+ // font-size: 1rem;
26
+ // bottom: 0;
27
+ // color: #67757c;
28
+ // left: 0px;
29
+ // position: absolute;
30
+ // right: 0;
31
+ border-top: 1px solid rgba(120, 130, 140, 0.13);
32
+ background: #ffffff;
35
33
  }
36
34
  a{
37
- color: #17a2b8;
38
- &:hover{
39
- color: #2C8199;
40
- }
41
- }
42
- .alert{
43
- text-transform: capitalize;
44
- }
45
- .alert-danger{
46
- color: #EC005F;
47
- border-color: #EC005F;
48
- background-color: #fff9f9;
49
- border-radius: 0;
50
- }
35
+ color: #17a2b8;
36
+ &:hover{
37
+ color: #2C8199;
38
+ }
39
+ }
51
40
 
52
- // ======== Form Errors ==========
53
- .error_title{
54
- font-size: 1.2rem;
55
- padding-bottom: 0.6rem;
56
- border-bottom: 1px solid #F46770;
41
+ .alert{
42
+ text-transform: capitalize;
57
43
  }
58
- // ======== End Form Errors ======
59
- // ======== Navbar ==========
60
- .navbar{
61
- background: #FFF;
62
- height: $navbar-height;
63
- // line-height: 68px;
64
- box-shadow: 0 1px 6px rgba(0, 0, 0, 0.06);
65
- }
66
44
 
67
- .navbar-brand{
68
- font-size: 1.6rem;
69
- font-weight: 700;
70
- text-transform: capitalize;
71
- }
45
+ .alert-danger{
46
+ color: #EC005F;
47
+ border-color: #EC005F;
48
+ background-color: #fff9f9;
49
+ border-radius: 0;
50
+ }
72
51
 
73
- .navbar-brand .logo_part_1{
74
- color: #F24D68;
75
- }
52
+ // ======== Form Errors ==========
53
+ .error_title{
54
+ font-size: 1.2rem;
55
+ padding-bottom: 0.6rem;
56
+ border-bottom: 1px solid #F46770;
57
+ }
76
58
 
77
- .navbar-brand .logo_part_2{
78
- color: #424534;
79
- }
59
+ // ======== Navbar ==========
60
+ .navbar{
61
+ background: #FFF;
62
+ height: $navbar-height;
63
+ // line-height: 68px;
64
+ box-shadow: 0 1px 6px rgba(0, 0, 0, 0.06);
65
+ }
80
66
 
81
- .navbar-light .navbar-brand:hover{
82
- color: #fff;
83
- }
67
+ .navbar-brand{
68
+ font-size: 1.6rem;
69
+ font-weight: 700;
70
+ text-transform: capitalize;
71
+ }
84
72
 
85
- .navbar .navbar-toggler{
73
+ .navbar-brand .logo_part_1{
74
+ color: #F24D68;
75
+ }
86
76
 
87
- font-size: .9rem;
88
- padding: .2rem;
89
- }
90
- .navbar-light .navbar-toggler{
91
- border: 0 none;
92
- }
77
+ .navbar-brand .logo_part_2{
78
+ color: #424534;
79
+ }
93
80
 
94
- // ======== End Navbar ==========
81
+ .navbar-light .navbar-brand:hover{
82
+ color: #fff;
83
+ }
95
84
 
85
+ .navbar .navbar-toggler{
86
+ font-size: .9rem;
87
+ padding: .2rem;
88
+ }
89
+ .navbar-light .navbar-toggler{
90
+ border: 0 none;
91
+ }
96
92
 
97
93
  // ======== Sidebar ==========
98
- .sidebar{
99
- width: 240px;
100
- position: fixed;
101
- top:68px;
102
- left: 0;
103
- height: 100%;
104
- /*background: #242a33;*/
105
- background: #fff;
106
- background: #F46770;
107
-
108
- }
109
-
110
- .sidebar .sidebar_title{
111
- color: #F2F2F2;
112
- border-bottom: 1px solid #EFEFEF;
113
- padding: 0.8rem;
114
- font-weight: 600;
115
- font-size: 1.2rem;
116
- }
117
-
118
- .sidebar .sidebar_item, .sidebar .sidebar_dashboard_link{
119
- text-transform: capitalize;
120
- a{
121
- transition: 0.3s;
122
- color: #F2F2F2;
123
- padding: 0.6rem 1.2rem;
124
- display: block;
125
- text-decoration: none;
126
- &:hover, &:focus, &:active{
127
- background: #FFF;
128
- color: #F46770;
129
- }
130
- }
131
- }
94
+ .sidebar{
95
+ width: 240px;
96
+ position: fixed;
97
+ top:68px;
98
+ left: 0;
99
+ height: 100%;
100
+ /*background: #242a33;*/
101
+ background: #fff;
102
+ background: #F46770;
103
+ }
132
104
 
133
- // ======== End Sidebar ==========
105
+ .sidebar .sidebar_title{
106
+ color: #F2F2F2;
107
+ border-bottom: 1px solid #EFEFEF;
108
+ padding: 0.8rem;
109
+ font-weight: 600;
110
+ font-size: 1.2rem;
111
+ }
134
112
 
113
+ .sidebar .sidebar_item, .sidebar .sidebar_dashboard_link{
114
+ text-transform: capitalize;
115
+ a{
116
+ transition: 0.3s;
117
+ color: #F2F2F2;
118
+ padding: 0.6rem 1.2rem;
119
+ display: block;
120
+ text-decoration: none;
121
+ &:hover, &:focus, &:active{
122
+ background: #FFF;
123
+ color: #F46770;
124
+ }
125
+ }
126
+ }
135
127
 
136
128
  // ======== Main content ==========
137
- .main-content{
138
- position: relative;
139
- margin-left: 240px;
140
- margin-top: 68px;
141
- padding: 15px 0 15px;
142
- }
143
-
144
- .main-content .content{
145
- background: white;
146
- padding: 2rem;
147
-
148
- h1{
149
- font-weight: normal;
150
- margin-top: 0;
151
- margin-bottom: 0.4rem;
152
- color: #455A65;
153
- font-size: 1.5rem;
154
- text-transform: capitalize;
155
- }
156
-
157
- .card{
158
- display: block;
159
- margin-top: 1rem;
160
- }
161
- }
162
-
163
- // ======== End Main content ==========
129
+ .main-content{
130
+ position: relative;
131
+ margin-left: 240px;
132
+ margin-top: 68px;
133
+ padding: 15px 0 15px;
134
+ }
164
135
 
136
+ .main-content .content{
137
+ background: white;
138
+ padding: 2rem;
139
+ h1{
140
+ font-weight: normal;
141
+ margin-top: 0;
142
+ margin-bottom: 0.4rem;
143
+ color: #455A65;
144
+ font-size: 1.5rem;
145
+ text-transform: capitalize;
146
+ }
147
+ .card{
148
+ display: block;
149
+ margin-top: 1rem;
150
+ }
151
+ }
165
152
 
166
153
  // ======== Bootstrap button ===========
167
154
  .btn{
168
- border-radius: 0.2rem;
155
+ border-radius: 0.2rem;
169
156
  }
170
- .btn-group-lg>.btn, .btn-lg{
171
- font-size: 1.1rem;
172
- }
173
- // ======== End Bootstrap button ==========
174
-
175
157
 
176
- .form-control:focus{
177
- border-color: #e5d200;
178
- box-shadow: none;
158
+ .btn-group-lg>.btn, .btn-lg{
159
+ font-size: 1.1rem;
179
160
  }
180
161
 
181
162
  .dropdown button{
182
- font-size: 0.9rem;
163
+ font-size: 0.9rem;
183
164
  }
184
165
 
185
- // .dropdown-menu{
186
- // left: auto;
187
- // right: 0;
188
- // float: right;
189
- // }
166
+ // ======== focus effect ==========
167
+ .form-control:focus{
168
+ border-color: #e5d200;
169
+ box-shadow: none;
170
+ }
190
171
 
191
172
  .dropdown-item:focus{
192
- background-color: #E9EAEF;
193
- color: #333;
173
+ background-color: #E9EAEF;
174
+ color: #333;
194
175
  }
195
176
 
196
177
  // ======= Table =========
197
178
  .table{
198
- thead th{
199
- text-transform: capitalize;
200
- font-weight: 700;
201
- padding: 0.9rem 0.75rem;
202
- }
203
- td{
204
- padding: 0.9rem 0.75rem;
205
- vertical-align: middle;
206
- }
207
-
208
- tr{
209
- cursor: default;
210
- transition: 0.3s;
211
- }
212
- tr:hover{
213
- background-color: #F8F9FA !important;
214
- }
179
+ thead th{
180
+ text-transform: capitalize;
181
+ font-weight: 700;
182
+ padding: 0.9rem 0.75rem;
183
+ }
184
+ td{
185
+ padding: 0.9rem 0.75rem;
186
+ vertical-align: middle;
187
+ }
188
+ tr{
189
+ cursor: default;
190
+ transition: 0.3s;
191
+ }
192
+ tr:hover{
193
+ background-color: #F8F9FA !important;
194
+ }
215
195
  }
216
- // ===== End Table ======
217
-
218
196
 
219
197
  // ======== Search Form ====================
220
198
 
221
199
  .search_form{
222
- input[type=text], select, textarea{
223
- width: auto;
224
- margin-bottom: 0.4rem;
225
- }
226
- .btn{
227
- margin-top: -0.1rem;
228
- }
200
+ input[type=text], select, textarea{
201
+ width: auto;
202
+ margin-bottom: 0.4rem;
203
+ }
204
+ .btn{
205
+ margin-top: -0.1rem;
206
+ }
229
207
  }
230
208
 
231
- // ======= End Search Form =================
232
-
233
-
234
209
  // ======== Kaminari Pagination ===========
210
+
235
211
  .pagination{
236
- .page-link{
237
- color: #444;
238
- }
239
- .page-item.active .page-link{
240
- color: #FFFFFF;
241
- background-color: #F46770;
242
- border-color: #F46770;
243
- }
212
+ .page-link{
213
+ color: #444;
214
+ }
215
+ .page-item.active .page-link{
216
+ color: #FFFFFF;
217
+ background-color: #F46770;
218
+ border-color: #F46770;
219
+ }
244
220
  }
245
221
 
246
- .kaminari_pagination nav{
247
- display: inline-block;
248
- ul{
249
- margin-bottom: 0;
250
- }
222
+ .pagy_pagination nav{
223
+ display: inline-block;
224
+ ul{
225
+ margin-bottom: 0;
226
+ }
251
227
  }
252
- // ======= End Kaminari Pagination =========
228
+
229
+ // ======= media query =========
253
230
 
254
231
  @media (max-width: 1064px) {
255
- .search_form{
256
- .condition-label{
257
- display: block;
258
- }
259
- }
232
+ .search_form{
233
+ .condition-label{
234
+ display: block;
235
+ }
236
+ }
260
237
  }
261
238
 
262
239
  @media (max-width: 960px) {
263
- .search_form{
264
- input[type=text], select, textarea{
265
- width: 100% !important;
266
- display: block !important;
267
- margin-bottom: 0.4rem;
268
- }
269
- }
240
+ .search_form{
241
+ input[type=text], select, textarea{
242
+ width: 100% !important;
243
+ display: block !important;
244
+ margin-bottom: 0.4rem;
245
+ }
246
+ }
270
247
  }
271
248
 
272
249
  @media (max-width: 768px) {
273
-
274
- .sidebar{
275
- left: 0;
276
- width: 180px;
277
- }
278
-
279
- .main-content{
280
- margin-left: 180px;
281
- }
282
- }
250
+ .sidebar{
251
+ left: 0;
252
+ width: 180px;
253
+ }
254
+ .main-content{
255
+ margin-left: 180px;
256
+ }
257
+ }
283
258
 
284
259
  @media (max-width: 576px) {
285
-
286
- .search_form{
287
- margin-top: 1rem;
288
- }
289
-
290
- .sidebar{
291
- // display: none;
292
- // position: absolute;
293
- // width: 240px;
294
- //left: -240px;
295
- transform: translateX(-240px);
296
- transition-duration: 0.3s;
297
- z-index: 99999;
298
- }
299
-
300
- .main-content{
301
- margin-left: auto;
302
-
303
- }
304
-
305
- .open-sidebar{
306
- .sidebar{
307
- transform: translateX(0px);
308
-
309
- }
310
- }
311
- }
260
+ .search_form{
261
+ margin-top: 1rem;
262
+ }
263
+ .sidebar{
264
+ // display: none;
265
+ // position: absolute;
266
+ // width: 240px;
267
+ //left: -240px;
268
+ transform: translateX(-240px);
269
+ transition-duration: 0.3s;
270
+ z-index: 99999;
271
+ }
272
+ .main-content{
273
+ margin-left: auto;
274
+ }
275
+ .open-sidebar{
276
+ .sidebar{
277
+ transform: translateX(0px);
278
+ }
279
+ }
280
+ }