adminsite 3.1.2 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (29) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/app/admin_configs/adminsite/adminsite_page_admin_config.rb +1 -1
  4. data/app/assets/javascripts/adminsite/admin/filters.js.coffee +13 -0
  5. data/app/assets/javascripts/adminsite/admin/hide_and_show.js.coffee +2 -6
  6. data/app/assets/stylesheets/adminsite/admin/base.scss +115 -77
  7. data/app/controllers/adminsite/admin/resources_controller.rb +8 -7
  8. data/app/controllers/adminsite/admin_application_controller.rb +1 -1
  9. data/app/controllers/adminsite/admin_user_sessions_controller.rb +1 -1
  10. data/app/helpers/admin/adminsite_application_helper.rb +33 -131
  11. data/app/helpers/admin/adminsite_menu_helper.rb +80 -0
  12. data/app/helpers/admin/adminsite_search_form_helper.rb +39 -0
  13. data/app/models/adminsite/ability.rb +1 -0
  14. data/app/views/adminsite/admin/adminsite_page_layouts/index.html.haml +1 -1
  15. data/app/views/adminsite/admin/adminsite_pages/index.html.haml +2 -2
  16. data/app/views/adminsite/admin/crud/show.html.haml +2 -1
  17. data/app/views/adminsite/admin/resources/_filters.html.haml +28 -0
  18. data/app/views/adminsite/admin/resources/_list.haml +2 -2
  19. data/app/views/adminsite/admin/resources/_search_form.html.haml +8 -7
  20. data/app/views/adminsite/admin/resources/edit.haml +3 -2
  21. data/app/views/adminsite/admin/resources/index.haml +6 -8
  22. data/app/views/adminsite/admin/resources/new.haml +2 -1
  23. data/app/views/adminsite/admin/resources/show.haml +3 -2
  24. data/app/views/adminsite/admin_user_sessions/new.html.haml +1 -1
  25. data/app/views/layouts/adminsite/admin.html.haml +6 -12
  26. data/config/locales/da.devise.yaml +3 -2
  27. data/config/locales/en.devise.yaml +3 -3
  28. data/lib/adminsite/version.rb +1 -1
  29. metadata +6 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 06c18d1d88578bccb15d3f24022297b7cae33c26
4
- data.tar.gz: 2dda15695344d571481cd23d58814fe487d368e7
3
+ metadata.gz: d94fdef568c79b7bcf4bbd483d17b44459ef266c
4
+ data.tar.gz: 40eabefb8e62f71f42225bec10e965f994940f62
5
5
  SHA512:
6
- metadata.gz: d2daf28f2f355c5c56bbbd5b7de46d541f6eb15d68acb0cbd91debd4c0bd247f21e701e18aa116651adc2244545dc8d5bc768bb94ddb0c8e3ebc4ffe146e0d00
7
- data.tar.gz: 550493a1d5b4f0b3025e14235a4cb604a9b2aa8e369af220e20c688f49daf29bad060a075916666c6523cc7cc5aafed2debb39378a48143c04888b9b6f92b16a
6
+ metadata.gz: dc45991fcde7d78b295285661130598397aafd04f14463d296feef9d79e5ba5a7826b66466379f980863cb1090ef62f4f3ea8d5ff2243998d5e2f92557c079b0
7
+ data.tar.gz: 757cc09d1ae378fa23c9e03d8438e7361301dd5e2c4331867f438034ae7856a2a59a7a4adb937637a29dc2509b7337eda59a3369ab3a4d87cbca14dc967c907e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- adminsite (3.1.2)
4
+ adminsite (3.2.0)
5
5
  actionpack-page_caching
6
6
  cancancan (~> 1.10)
7
7
  codemirror-rails (>= 4.8)
@@ -6,7 +6,7 @@ module Adminsite
6
6
  :url,
7
7
  :requires_login,
8
8
  :cacheable,
9
- :page_layout_id,
9
+ :page_layout,
10
10
  :updated_at
11
11
  ]
12
12
  end
@@ -0,0 +1,13 @@
1
+ jQuery(document).on 'page:change', ->
2
+ close_btns = $('body.adminsite #search_filters ul button').on "click", ->
3
+ btn = jQuery(this)
4
+ op = btn.attr('data-filter-op')
5
+ value = btn.attr('data-filter-value')
6
+ column = btn.attr('data-filter-column')
7
+ search_pattern = '&q[' + column + '_' + op + ']=' + value
8
+ # console.log(column, op, value, search_pattern)
9
+ current_url = decodeURIComponent(window.location.search)
10
+ next_url = current_url.replace(search_pattern, '')
11
+ window.location.search = next_url
12
+ return
13
+ return
@@ -9,13 +9,9 @@ Adminsite.selectedRow = (param) ->
9
9
  return
10
10
 
11
11
  Adminsite.showSearchForm = ->
12
- $('.search_form form').show()
13
- $('.search_form a#show').hide()
14
- $('.search_form a#hide').show()
12
+ $('form.search').show(200)
15
13
  return
16
14
 
17
15
  Adminsite.hideSearchForm = ->
18
- $('.search_form form').hide()
19
- $('.search_form a#show').show()
20
- $('.search_form a#hide').hide()
16
+ $('form.search').hide(200)
21
17
  return
@@ -1,6 +1,5 @@
1
1
  body.adminsite {
2
2
  font: 13px/1.231 sans-serif;
3
- *font-size: small;
4
3
 
5
4
  &, input, select, textarea, button {
6
5
  margin: 0;
@@ -22,9 +21,6 @@ body.adminsite {
22
21
  &:hover, &:active {
23
22
  outline: none;
24
23
  }
25
- &:hover img {
26
- background: #fff;
27
- }
28
24
  }
29
25
  .left {
30
26
  float: left;
@@ -60,40 +56,30 @@ body.adminsite {
60
56
  margin-bottom: 8px;
61
57
  }
62
58
  #wrapper {
63
- margin-left: 20px;
64
- margin-right: 20px;
59
+ margin: 0 20px;
60
+ overflow: auto;
65
61
  }
66
62
  hr {
67
63
  border: dashed black;
68
64
  border-width: 1px 0 0;
69
65
  height: 0;
70
66
  }
71
- #header {
67
+ header {
72
68
  margin: 0;
73
- clear: both;
74
69
  padding: 20px;
75
- bottom: 40px;
76
70
  background-color: #e7e7e7;
77
71
  background: -moz-linear-gradient(bottom, #fff, #f0f0f0 17%, #fff 18%, #c0c0c0 19%, #e7e7e7 20%, #e7e7e7);
78
72
  background: -webkit-gradient(linear, left bottom, left top, from(#fff), color-stop(17%, #f0f0f0), color-stop(18%, #fff), color-stop(19%, #c0c0c0), color-stop(20%, #e7e7e7), to(#e7e7e7));
79
73
  border-top: 6px solid #595959;
80
- }
81
- #header_left {
82
- float: left;
83
74
  h2 {
84
75
  font-size: 135%;
85
76
  margin: 0;
86
77
  padding: 0;
87
78
  }
88
- a:hover img {
89
- background: #e7e7e7;
90
- }
91
79
  }
92
- #header_right {
93
- float: left;
94
- clear: left;
80
+ #action_bar {
95
81
  font-size: 85%;
96
- margin-top: 0.2em;
82
+ margin: 0.2em 20px 1.5em;
97
83
  a {
98
84
  background-color: rgba(0, 0, 0, 0.2);
99
85
  background-repeat: no-repeat;
@@ -101,18 +87,16 @@ body.adminsite {
101
87
  border-radius: 4px;
102
88
  -moz-border-radius: 4px;
103
89
  -webkit-border-radius: 4px;
104
- display: block;
105
- float: left;
106
90
  margin-right: 0.5em;
107
91
  padding: 0.2em;
108
92
  text-decoration: none;
109
93
  &:hover {
110
94
  background-color: rgba(0, 0, 0, 0.7);
111
95
  }
112
- &.add, &.back {
96
+ &.add, &.back, &.new {
113
97
  padding-left: 18px;
114
98
  }
115
- &.add {
99
+ &.add, &.new {
116
100
  background-image: asset-url('adminsite/admin/add.png');
117
101
  }
118
102
  &.back {
@@ -120,6 +104,109 @@ body.adminsite {
120
104
  }
121
105
  }
122
106
  }
107
+ #filters {
108
+ border: 1px solid #ccc;
109
+ margin: 0.2em 20px 1.5em;
110
+ & > div {
111
+ margin:0;
112
+ }
113
+ legend {
114
+ margin:0;
115
+ padding: 0 0.3em;
116
+ }
117
+ label {
118
+ display: inline;
119
+ margin: 0;
120
+ }
121
+ ul {
122
+ display: inline;
123
+ list-style-type: none;
124
+ margin: 0;
125
+ padding: 0;
126
+ li {
127
+ display: inline;
128
+ }
129
+ }
130
+ #scopes {
131
+ margin-bottom: 1em;
132
+ li {
133
+ border-left: 1px solid black;
134
+ padding: 0 0.3em 0 0.5em;
135
+ &:first-child {
136
+ border-left: 0;
137
+ padding-left: 0;
138
+ }
139
+ .count {
140
+ color: #ccc;
141
+ }
142
+ a:link, a:visited {
143
+ text-decoration: none;
144
+ white-space: nowrap;
145
+ }
146
+ }
147
+ }
148
+ #search_filters ul {
149
+ padding: 0 5px 0 0;
150
+ li {
151
+ border: 1px solid #ccc;
152
+ border-radius: 10px 0 0 10px;
153
+ margin: 0 5px;
154
+ padding: 3px 3px 3px 10px;
155
+ }
156
+ button {
157
+ background-color: transparent;
158
+ border: 0;
159
+ font-weight: bold;
160
+ }
161
+ }
162
+ }
163
+
164
+ form.search {
165
+ position: absolute;
166
+ top: 240px;
167
+ left: 110px;
168
+ border: 1px solid #595959;
169
+ border-radius: 5px;
170
+ box-shadow: 5px 5px 5px 0px rgba(0, 0, 17, 0.7);
171
+ margin: 0 0 15px;
172
+ .titlebar {
173
+ background-color: #e7e7e7;
174
+ border-bottom: 1px solid #e3e3e3;
175
+ border-radius: 5px 5px 0 0;
176
+ font-weight: bold;
177
+ padding: 10px;
178
+ button {
179
+ float:right;
180
+ background-color: transparent;
181
+ border: none;
182
+ font-size: 120%;
183
+ margin-top: -2px;
184
+ }
185
+ }
186
+ .content {
187
+ background-color: #eee;
188
+ border-radius: 0 0 5px 5px;
189
+ padding: 10px;
190
+ }
191
+ label {
192
+ display: inline-block;
193
+ min-width: 7em;
194
+ }
195
+ ul {
196
+ margin: 0;
197
+ padding: 0;
198
+ li {
199
+ white-space: nowrap;
200
+ min-width: 100px;
201
+ max-width: 450px;
202
+ margin-bottom: 0px;
203
+ margin-right: 0px;
204
+ list-style: none;
205
+ height: 35px;
206
+ }
207
+ }
208
+ }
209
+
123
210
  .clearfix {
124
211
  zoom: 1;
125
212
  &:before {
@@ -136,21 +223,6 @@ body.adminsite {
136
223
  clear: both;
137
224
  }
138
225
  }
139
- #footer {
140
- position: fixed;
141
- border-top: 1px solid #ddd;
142
- border-bottom: 10px solid #f5f5f5;
143
- background: #f5f5f5;
144
- width: 100%;
145
- left: 0;
146
- bottom: 0;
147
- text-align: center;
148
- color: #aaa;
149
- font-size: 10px;
150
- z-index: 10000;
151
- opacity: 0.9;
152
- margin-top: 100px;
153
- }
154
226
  pre {
155
227
  background-color: #eee;
156
228
  padding: 10px;
@@ -449,15 +521,15 @@ body.adminsite {
449
521
  .submit {
450
522
  float: right;
451
523
  }
452
- &#loginform .submit {
453
- float: none;
454
- text-align: right;
455
- }
456
524
  p {
457
525
  margin-bottom: 24px;
458
526
  }
459
527
  }
460
528
  #loginform {
529
+ .submit {
530
+ float: none;
531
+ text-align: right;
532
+ }
461
533
  #adminsite_admin_user_email, #adminsite_admin_user_password {
462
534
  -moz-background-clip: border;
463
535
  -moz-background-inline-policy: continuous;
@@ -489,47 +561,13 @@ body.adminsite {
489
561
  }
490
562
  }
491
563
 
492
- .search_form {
493
- margin-bottom: 20px;
494
-
495
- form > div {
496
- background-color: #eee;
497
- padding: 5px;
498
- border: 1px solid #ccc;
499
- border-radius: 5px;
500
- overflow: auto;
501
- .actions {
502
- float: left;
503
- }
504
- }
505
- ul {
506
- margin: 9px;
507
- padding: 9px;
508
- li
509
- {
510
- min-width: 100px;
511
- max-width: 330px;
512
- margin-bottom: 20px;
513
- margin-right: 40px;
514
- list-style: none;
515
- float: left;
516
- height: 35px;
517
- }
518
- }
519
- .actions {
520
- // margin-top: 10px;
521
- clear: both;
522
- margin: 20px;
523
- }
524
- }
525
-
526
564
  .select_row {
527
565
  width: 12px;
528
566
  height: 12px;
529
567
  background-color: #cccccc;
530
568
  }
531
569
 
532
- table tr.selected{
570
+ table tr.selected {
533
571
  background-color: #d9e4ec;
534
572
  &:nth-child(odd) {background-color: #D1DCE4}
535
573
  .select_row {
@@ -47,10 +47,11 @@ class Adminsite::Admin::ResourcesController < Adminsite::Admin::CrudController
47
47
  end
48
48
 
49
49
  def index
50
- @q = resources.order(order_params).ransack(params[:q])
50
+ @q = scope_resources.ransack(params[:q])
51
51
  @resources = @q.result.page(params[:page])
52
52
  @ransack_params = ransack_params
53
- @show_search_form = @ransack_params[:q].try(:except, :s).present?
53
+ @search_params = @ransack_params[:q].try(:except, :s)
54
+ @show_search_form = @search_params.present?
54
55
  render :json => @resources if api_call?
55
56
  end
56
57
 
@@ -79,12 +80,12 @@ class Adminsite::Admin::ResourcesController < Adminsite::Admin::CrudController
79
80
  @current_admin_menu ||= params[:admin_menu]
80
81
  end
81
82
 
82
- def admin_resource_path(id = nil, action = nil)
83
+ def admin_resource_path(id = nil, action = nil, options = {})
83
84
  path = self.class.remove_namespace(params[:controller], ['adminsite'])
84
85
  path = path.gsub('/','_')
85
86
  path = path.singularize if (action || id).present? && action.to_s != 'search'
86
87
  path = "#{action}_#{path}" if action.present?
87
- send("#{path}_path", id, admin_menu: current_admin_menu)
88
+ send("#{path}_path", id, {admin_menu: current_admin_menu}.merge(options) )
88
89
  end
89
90
 
90
91
  protected
@@ -101,12 +102,12 @@ class Adminsite::Admin::ResourcesController < Adminsite::Admin::CrudController
101
102
  @resource ||= resources.find(params[:id])
102
103
  end
103
104
 
104
- def resources
105
- if filter_scopes.present?
105
+ def scope_resources
106
+ if filter_scopes.present?
106
107
  eval("resource_class.#{filter_scopes.join('.')}")
107
108
  else
108
109
  self.class.resource_class.all
109
- end
110
+ end.order(order_params)
110
111
  end
111
112
 
112
113
  def resource_params
@@ -2,7 +2,7 @@
2
2
  # Likewise, all the methods added will be available for all controllers.
3
3
 
4
4
  class Adminsite::AdminApplicationController < ActionController::Base
5
- helper :all, "admin/adminsite_application"
5
+ helper "admin/adminsite_application"
6
6
  layout 'adminsite/admin'
7
7
 
8
8
  before_filter :authenticate_adminsite_admin_user!
@@ -12,7 +12,7 @@ class Adminsite::AdminUserSessionsController < Devise::SessionsController
12
12
  end
13
13
 
14
14
  def after_sign_in_path_for(resource_or_scope)
15
- params[:redirect_to] || session["adminsite_admin_user_return_to"] || admin_dashboard_index_path
15
+ params[:redirect_to] || session["adminsite_admin_user_return_to"] || admin_dashboard_index_path(admin_menu: 'Dashboard')
16
16
  end
17
17
 
18
18
 
@@ -1,41 +1,5 @@
1
1
  module Admin::AdminsiteApplicationHelper
2
2
 
3
- def column_of_attr(search_attr)
4
- return if search_attr.blank?
5
- resource_class.columns.each{|c| return c if c.name == search_attr.to_s.downcase }
6
- nil
7
- end
8
-
9
- def input_type_of_column(column)
10
- case
11
- when column.sql_type.match(/\Acharacter varying/)
12
- return :string
13
- when column.sql_type.match(/\Atimestamp/)
14
- return :date
15
- when column.sql_type.match(/\integer/)
16
- return :number
17
- else
18
- column.sql_type.try(:to_sym)
19
- end
20
- end
21
-
22
- def ransack_predicate_input_type(input_type)
23
- case input_type
24
- when :boolean
25
- return [:eq]
26
- when :text
27
- return [:eq, :cont]
28
- when :string
29
- return [:eq, :cont]
30
- when :date
31
- return [:lteq, :gteq]
32
- when :number
33
- return [:eq, :lteq, :gteq]
34
- else
35
- [:eq]
36
- end
37
- end
38
-
39
3
  def format_response_value(value, add_td_wrappers = true)
40
4
  value = value.url if defined?(PictureUploader) && value.is_a?(PictureUploader)
41
5
  response = ''
@@ -57,97 +21,20 @@ module Admin::AdminsiteApplicationHelper
57
21
  value.is_a?(String) && value.match(/\A[\/]|\Ahttp[s]*:/)
58
22
  end
59
23
 
60
- def image_extensions
61
- %w(.png .gif .jpg .tif)
62
- end
63
-
64
24
  def is_image?(path)
65
25
  image_extensions.include?( File.extname(path).split('?').first.try(:downcase) )
66
26
  end
67
27
 
28
+ def image_extensions
29
+ %w(.png .gif .jpg .tif)
30
+ end
31
+
68
32
  def error_messages_for(obj)
69
33
  return if obj.errors.blank?
70
34
  msgs = obj.errors.full_messages.collect{|msg| "<li>#{ h msg }</li>" }
71
35
  raw ['<ul>', msgs, '</ul>'].flatten.join
72
36
  end
73
37
 
74
- def recognize_path(path)
75
- return {} if path.try(:strip).blank?
76
- begin
77
- return Adminsite::Engine.routes.recognize_path(path) # '/admin/profiles'
78
- return Rails.application.routes.recognize_path(path)
79
- rescue Exception => e
80
- end
81
- end
82
-
83
- def current_admin_menu
84
- @current_admin_menu ||= params[:admin_menu]
85
- end
86
-
87
- def menu_item(label, url, child_controller_names = [], klasses = nil, method = nil, admin_menu = label)
88
- result = ''
89
- child_menus = []
90
-
91
- child_controller_names_authorized = child_controller_names.select do |child_controller_name|
92
- controller_class_name = "#{child_controller_name}_controller".classify
93
- controller_class = eval("defined?(Adminsite::" + "#{controller_class_name}) ? Adminsite::#{controller_class_name} : Adminsite::Admin::#{controller_class_name}".classify)
94
- can?(:read, controller_class.new.authorize_resource_class)
95
- end
96
-
97
- if current_url?(url, label) || ( child_controller_active?(child_controller_names) && current_admin_menu == admin_menu)
98
- child_controller_names_authorized.each do |child_controller_name|
99
- child_menus << content_menu_item(child_controller_name, admin_menu, nil, nil )
100
- end
101
- end
102
- child_menus = child_menus.compact
103
-
104
- if child_controller_names_authorized.count > 0
105
- html_options = {method: method}
106
- html_options[:title] = current_adminsite_admin_user.email if klasses == 'log_out'
107
- link = link_to(label, "#{url}?admin_menu=#{admin_menu}", html_options)
108
- result = raw "<li class='#{html_classes(url, nil, klasses, admin_menu, label )}'>#{link}</li>"
109
-
110
- content_for(:content_menu, child_menus.join("\n").html_safe )
111
- end
112
- result
113
- end
114
-
115
- def content_menu_label(url, controller_name)
116
- menu_controller = recognize_path(url)[:controller]
117
- return controller_name.titlecase if menu_controller.blank?
118
- eval("#{menu_controller}_controller".classify).content_menu_label
119
- end
120
-
121
- def content_menu_item(controller_name, admin_menu, klasses, method )
122
- if controller_name != controller_name.pluralize
123
- url = eval("admin_#{controller_name}_index_path")
124
- else
125
- url = eval("admin_#{controller_name}_path")
126
- end
127
- link = link_to(content_menu_label(url, controller_name), "#{url}?admin_menu=#{admin_menu}", method: method, )
128
- raw "<li class='#{html_classes(url, controller_name, klasses, admin_menu )}'>#{link}</li>"
129
- end
130
-
131
- def current_url?(url, label = '')
132
- if label.present?
133
- return request.fullpath == "#{url}?admin_menu=#{label}"
134
- else
135
- return request.fullpath == url
136
- end
137
- end
138
-
139
- def child_controller_active?(child_controller_names)
140
- child_controller_names.include?(controller.controller_name)
141
- end
142
-
143
- def html_classes(url, controller_name, klasses = nil, admin_menu = '', label = '')
144
- result = []
145
- result |= [klasses].flatten if klasses.present?
146
- result |= ['current'] if current_url?(url, admin_menu)
147
- result |= ['active'] if current_admin_menu == label || controller_name == controller.controller_name
148
- result.join(' ')
149
- end
150
-
151
38
  def label_resource
152
39
  @resource.send(resource_admin_config.label_attribute)
153
40
  end
@@ -160,41 +47,56 @@ module Admin::AdminsiteApplicationHelper
160
47
  label_resource_class.pluralize
161
48
  end
162
49
 
163
- def link_to_back(text, path = admin_resource_path)
164
- link_to text, path, :class => 'back'
50
+ def link_to_back(text = 'Back', path = admin_resource_path)
51
+ link_to text, path, :class => 'action back'
165
52
  end
166
53
 
167
54
  def link_to_new(text, path = admin_resource_path(nil, :new) )
168
- link_to text, path, :class => 'add'
55
+ link_to text, path, :class => 'action new'
169
56
  end
170
57
 
171
- def link_to_show(resource)
172
- link_to image_tag('adminsite/admin/magnifier.png', :size => '16x16'), admin_resource_path(resource.id), target: '_blank'
58
+ def link_to_show(resource, text = '')
59
+ link_to h(text) + image_tag('adminsite/admin/magnifier.png', :size => '16x16'), admin_resource_path(resource.id), :class => 'resource_action show'
173
60
  end
174
61
 
175
- def link_to_edit(resource)
176
- link_to image_tag('adminsite/admin/pencil.png', :size => '16x16'), admin_resource_path(resource.id, :edit)
62
+ def link_to_edit(resource, text = '')
63
+ link_to h(text) + image_tag('adminsite/admin/pencil.png', :size => '16x16'), admin_resource_path(resource.id, :edit), :class => 'resource_action edit' if can?(:edit, resource)
177
64
  end
178
65
 
179
66
  def link_to_destroy(resource)
180
- link_to image_tag('adminsite/admin/cross.png', :size => '16x16'), admin_resource_path(resource.id), data: { :confirm => 'Are you sure?'} , :method => :delete
67
+ link_to image_tag('adminsite/admin/cross.png', :size => '16x16'), admin_resource_path(resource.id), :class => 'resource_action destroy', data: { :confirm => 'Are you sure?'} , :method => :delete if can?(:destroy, resource)
181
68
  end
182
69
 
183
70
  def display_resource_value(resource, attr, add_td_wrappers = true)
184
71
  value = nil
185
72
  attr.to_s.split('.').each{|a| value = (value || resource).send(a) }
186
- value = display_referenced_resource(value) if value.is_a?(ActiveRecord::Base)
187
- if value.is_a?(ActiveRecord::Associations::CollectionProxy)
73
+ value = display_referenced_resource(value, false) if value.is_a?(ActiveRecord::Base)
74
+ if value.is_a?(ActiveRecord::Associations::CollectionProxy) or value.is_a?(Array)
188
75
  value = value.collect do |r|
189
- label = Adminsite::AdminConfig::Base.admin_config_of_class(r.class, nil, current_adminsite_admin_user).label_attribute(r)
190
- display_resource_value(r, label, false)
76
+ if r.is_a?(ActiveRecord::Base)
77
+ display_referenced_resource(r, false)
78
+ else
79
+ r
80
+ end
191
81
  end.join(', ')
192
82
  end
193
83
  format_response_value(value, add_td_wrappers).html_safe
194
84
  end
195
85
 
196
- def display_referenced_resource(resource)
197
- link_to resource.title, send("edit_admin_#{resource.class.name.underscore.gsub('/','_')}_path", resource.id, admin_menu: params[:admin_menu])
86
+ def display_referenced_resource(resource, add_td_wrappers = true)
87
+ label_attr = Adminsite::AdminConfig::Base.admin_config_of_class(resource.class, nil, current_adminsite_admin_user).label_attribute(resource)
88
+ label = display_resource_value(resource, label_attr, add_td_wrappers)
89
+ begin
90
+ if can?(:edit, resource)
91
+ link_to label, send("edit_admin_#{resource.class.name.underscore.gsub('/','_')}_path", resource.id, admin_menu: params[:admin_menu])
92
+ elsif can?(:read, resource)
93
+ link_to label, send("admin_#{resource.class.name.underscore.gsub('/','_')}_path", resource.id, admin_menu: params[:admin_menu])
94
+ else
95
+ label
96
+ end
97
+ rescue
98
+ return label
99
+ end
198
100
  end
199
101
 
200
102
  def publish_form_input(form, form_input)
@@ -0,0 +1,80 @@
1
+ module Admin::AdminsiteMenuHelper
2
+
3
+ def recognize_path(path)
4
+ return {} if path.try(:strip).blank?
5
+ begin
6
+ return Adminsite::Engine.routes.recognize_path(path) # '/admin/profiles'
7
+ return Rails.application.routes.recognize_path(path)
8
+ rescue Exception => e
9
+ end
10
+ end
11
+
12
+ def current_admin_menu
13
+ @current_admin_menu ||= params[:admin_menu]
14
+ end
15
+
16
+ def menu_item(label, url, child_controller_names = [], klasses = nil, method = nil, admin_menu = label)
17
+ result = ''
18
+ child_menus = []
19
+
20
+ child_controller_names_authorized = child_controller_names.select do |child_controller_name|
21
+ controller_class_name = "#{child_controller_name}_controller".classify
22
+ controller_class = eval("defined?(Adminsite::" + "#{controller_class_name}) ? Adminsite::#{controller_class_name} : Adminsite::Admin::#{controller_class_name}".classify)
23
+ can?(:read, controller_class.new.authorize_resource_class)
24
+ end
25
+
26
+ if current_url?(url, label) || ( child_controller_active?(child_controller_names) && current_admin_menu == admin_menu)
27
+ child_controller_names_authorized.each do |child_controller_name|
28
+ child_menus << content_menu_item(child_controller_name, admin_menu, nil, nil )
29
+ end
30
+ end
31
+ child_menus = child_menus.compact
32
+
33
+ if child_controller_names_authorized.count > 0
34
+ html_options = {method: method}
35
+ html_options[:title] = current_adminsite_admin_user.email if klasses == 'log_out'
36
+ link = link_to(label, "#{url}?admin_menu=#{admin_menu}", html_options)
37
+ result = raw "<li class='#{html_classes(url, nil, klasses, admin_menu, label )}'>#{link}</li>"
38
+
39
+ content_for(:content_menu, child_menus.join("\n").html_safe )
40
+ end
41
+ result
42
+ end
43
+
44
+ def content_menu_label(url, controller_name)
45
+ menu_controller = recognize_path(url)[:controller]
46
+ return controller_name.titlecase if menu_controller.blank?
47
+ eval("#{menu_controller}_controller".classify).content_menu_label
48
+ end
49
+
50
+ def content_menu_item(controller_name, admin_menu, klasses, method )
51
+ if controller_name != controller_name.pluralize
52
+ url = eval("admin_#{controller_name}_index_path")
53
+ else
54
+ url = eval("admin_#{controller_name}_path")
55
+ end
56
+ link = link_to(content_menu_label(url, controller_name), "#{url}?admin_menu=#{admin_menu}", method: method, )
57
+ raw "<li class='#{html_classes(url, controller_name, klasses, admin_menu )}'>#{link}</li>"
58
+ end
59
+
60
+ def current_url?(url, label = '')
61
+ if label.present?
62
+ return request.fullpath == "#{url}?admin_menu=#{label}"
63
+ else
64
+ return request.fullpath == url
65
+ end
66
+ end
67
+
68
+ def child_controller_active?(child_controller_names)
69
+ child_controller_names.include?(controller.controller_name)
70
+ end
71
+
72
+ def html_classes(url, controller_name, klasses = nil, admin_menu = '', label = '')
73
+ result = []
74
+ result |= [klasses].flatten if klasses.present?
75
+ result |= ['current'] if current_url?(url, admin_menu)
76
+ result |= ['active'] if current_admin_menu == label || controller_name == controller.controller_name
77
+ result.join(' ')
78
+ end
79
+
80
+ end
@@ -0,0 +1,39 @@
1
+ module Admin::AdminsiteSearchFormHelper
2
+
3
+ def column_of_attr(search_attr)
4
+ return if search_attr.blank?
5
+ resource_class.columns.each{|c| return c if c.name == search_attr.to_s.downcase }
6
+ nil
7
+ end
8
+
9
+ def input_type_of_column(column)
10
+ case
11
+ when column.sql_type.match(/\Acharacter varying/)
12
+ return :string
13
+ when column.sql_type.match(/\Atimestamp/)
14
+ return :date
15
+ when column.sql_type.match(/\integer/)
16
+ return :number
17
+ else
18
+ column.sql_type.try(:to_sym)
19
+ end
20
+ end
21
+
22
+ def ransack_predicate_input_type(input_type)
23
+ case input_type
24
+ when :boolean
25
+ return [:eq]
26
+ when :text
27
+ return [:eq, :cont]
28
+ when :string
29
+ return [:eq, :cont]
30
+ when :date
31
+ return [:lteq, :gteq]
32
+ when :number
33
+ return [:eq, :lteq, :gteq]
34
+ else
35
+ [:eq]
36
+ end
37
+ end
38
+
39
+ end
@@ -20,6 +20,7 @@ module Adminsite
20
20
  # can :read, Adminsite::FileAsset
21
21
  end
22
22
  can :manage, Adminsite::AdminUserSessionsController
23
+ can :read, Adminsite::Admin::DashboardController
23
24
  end
24
25
  end
25
26
  end
@@ -4,6 +4,6 @@
4
4
  - content_for :header_left do
5
5
  = "Listing #{label_resource_class_plural}"
6
6
  - content_for :header_right do
7
- = link_to_new "New #{label_resource_class}", admin_resource_path(nil, 'new')
7
+ = link_to_new "New #{label_resource_class}"
8
8
  There are no page layouts. Go ahead and
9
9
  #{link_to 'add the first one', new_admin_adminsite_page_layout_path}.
@@ -4,13 +4,13 @@
4
4
  - content_for :header_left do
5
5
  = "Listing #{label_resource_class_plural}"
6
6
  - content_for :header_right do
7
- = link_to_new "New #{label_resource_class}", admin_resource_path(nil, 'new')
7
+ = link_to_new "New #{label_resource_class}"
8
8
  There are no pages. Go ahead and
9
9
  #{link_to 'add the first one', new_admin_adminsite_page_path}.
10
10
  - else
11
11
  - content_for :header_left do
12
12
  = "Listing #{label_resource_class_plural}"
13
13
  - content_for :header_right do
14
- = link_to_new "New #{label_resource_class}", admin_resource_path(nil, 'new')
14
+ = link_to_new "New #{label_resource_class}"
15
15
  You should #{link_to 'add a page layout', new_admin_adminsite_page_layout_path}
16
16
  before adding your first page.
@@ -1,7 +1,8 @@
1
1
  - content_for :header_left do
2
2
  = controller_name
3
3
  - content_for :header_right do
4
- = link_to_back 'Back', url_for(controller: controller_name, action: :index )
4
+ #show_actions
5
+ = link_to_back 'Back', url_for(controller: controller_name, action: :index )
5
6
 
6
7
  - if Rails.env.development?
7
8
  please override in '/app/views/adminsite/admin/#{controller_name}/show.html.haml'
@@ -0,0 +1,28 @@
1
+ %fieldset#filters
2
+ %legend Filters
3
+ #scopes
4
+ - if resource_admin_config.actions_index.any?
5
+ %label Predefined filters:
6
+ %ul
7
+ - resource_admin_config.scopes.each do |scope|
8
+ - scope_label = "#{scope.to_s.titlecase} <span class=\"count\">(#{resource_class.send(scope).ransack(params[:q]).result.count})</span>".html_safe
9
+ - scope_path = "#{admin_resource_path(nil,nil,@ransack_params )}&scope=#{scope}"
10
+ %li #{link_to scope_label, scope_path}
11
+ - if resource_admin_config.attributes_search.any?
12
+ #search_filters
13
+ %label |
14
+ Search filters (
15
+ %a#show{ onclick: "Adminsite.showSearchForm();" }
16
+ = @search_params.present? ? 'Edit' : 'New'
17
+ ) |
18
+ - if @search_params.present?
19
+ %ul
20
+ - @search_params.map do |q|
21
+ - op = q.first.split('_').last
22
+ - column = q.first.chomp("_#{op}")
23
+ - value = q.last
24
+ %li<
25
+ #{column.gsub('_',' ').capitalize} |
26
+ #{Ransack::Translate.predicate(op)}: |
27
+ '#{value}' |
28
+ %button{type: 'button', "data-filter-column" => column, "data-filter-value" => q.last, "data-filter-op" => op } ×
@@ -14,7 +14,7 @@
14
14
  - @resources.each do |resource|
15
15
  %tr{onclick: 'Adminsite.selectedRow(this);'}
16
16
  - if resource_admin_config.actions_placement == :left
17
- %td.actions
17
+ %td.actions.resource_actions
18
18
  %ul
19
19
  - resource_admin_config.default_member_actions(resource).each do |action|
20
20
  %li= send("link_to_#{action}", resource)
@@ -23,7 +23,7 @@
23
23
  - resource_admin_config.attributes_index.each do |attr|
24
24
  = display_resource_value(resource, attr)
25
25
  - if resource_admin_config.actions_placement == :right
26
- %td.actions
26
+ %td.actions.resource_actions
27
27
  %ul
28
28
  - resource_admin_config.default_member_actions(resource).each do |action|
29
29
  %li= send("link_to_#{action}", resource)
@@ -1,10 +1,11 @@
1
1
  - if resource_admin_config.attributes_search.any?
2
- .search_form
3
- %a#show{onclick: 'Adminsite.showSearchForm();', style: "#{'display:none' if @show_search_form}" } Show Filters
4
- %a#hide{onclick: 'Adminsite.hideSearchForm();', style: "#{'display:none' unless @show_search_form}" } Hide Filters
5
- = search_form_for(@q, :url => admin_resource_path(nil), method: :get, html: { style: "#{'display:none' unless @show_search_form}"} ) do |f|
6
- = hidden_field_tag :admin_menu, params[:admin_menu]
7
- %div{id: "#{controller_name}-search"}
2
+ = search_form_for(@q, :url => admin_resource_path(nil), method: :get, html: { class: 'search', style: 'display:none' } ) do |f|
3
+ = hidden_field_tag :admin_menu, params[:admin_menu]
4
+ %div{id: "#{controller_name}-search"}
5
+ .titlebar
6
+ Filters
7
+ %button{ type: 'button', onclick: 'Adminsite.hideSearchForm();'} ×
8
+ .content
8
9
  %ul
9
10
  - resource_admin_config.attributes_search.each do |search_attr|
10
11
  - if (column = column_of_attr(search_attr)).present?
@@ -13,7 +14,7 @@
13
14
  - input_type = input_type_of_column(column)
14
15
  - predicates = ransack_predicate_input_type(input_type)
15
16
  - show_predicate_select = predicates.count > 1
16
- - field_value = (@ransack_params[:q] || {})["#{search_attr}_#{p_value}"]
17
+ - field_value = (@search_params || {})["#{search_attr}_#{p_value}"]
17
18
  = f.label("#{search_attr}")
18
19
 
19
20
  - if show_predicate_select
@@ -1,8 +1,9 @@
1
1
  - content_for :header_left do
2
2
  = "Edit #{label_resource_class}: '#{label_resource}'"
3
- = link_to_show @resource if resource_admin_config.default_member_actions(@resource).include?(:show)
4
3
  - content_for :header_right do
5
- = link_to_back 'Back', admin_resource_path
4
+ #action_bar
5
+ = link_to_back
6
+ = link_to_show @resource, 'Show ' if resource_admin_config.default_member_actions(@resource).include?(:show)
6
7
 
7
8
  = error_messages_for @resource
8
9
 
@@ -2,12 +2,10 @@
2
2
  = "Listing #{label_resource_class_plural}"
3
3
  - if resource_admin_config.actions_index.any?
4
4
  - content_for :header_right do
5
- - resource_admin_config.actions_index.each do |action|
6
- = send("link_to_#{action}", action.to_s.titlecase)
7
- - resource_admin_config.scopes.each do |scope|
8
- = link_to "#{scope.to_s.titlecase} (#{resource_class.send(scope).count})", "#{admin_resource_path}&scope=#{scope}"
9
-
10
- = render :partial => 'search_form'
11
-
12
- = render :partial => 'list'
5
+ #action_bar
6
+ - resource_admin_config.actions_index.each do |action|
7
+ = send("link_to_#{action}", action.to_s.titlecase)
8
+ = render partial: 'filters'
9
+ = render partial: 'search_form'
13
10
 
11
+ = render partial: 'list'
@@ -1,7 +1,8 @@
1
1
  - content_for :header_left do
2
2
  = "New #{label_resource_class}"
3
3
  - content_for :header_right do
4
- = link_to_back 'Back', admin_resource_path
4
+ #action_bar
5
+ = link_to_back
5
6
 
6
7
  = error_messages_for @resource
7
8
 
@@ -1,8 +1,9 @@
1
1
  - content_for :header_left do
2
2
  = "Show #{label_resource_class}: '#{label_resource}'"
3
- = link_to_edit @resource if resource_admin_config.default_member_actions(@resource).include?(:edit)
4
3
  - content_for :header_right do
5
- = link_to_back 'Back', admin_resource_path
4
+ #action_bar
5
+ = link_to_back
6
+ = link_to_edit @resource, 'Edit ' if resource_admin_config.default_member_actions(@resource).include?(:edit)
6
7
 
7
8
  .formtastic
8
9
  %table
@@ -4,7 +4,7 @@
4
4
  %label
5
5
  E-mail:
6
6
  %br
7
- = f.text_field :email, :type => 'email'
7
+ = f.text_field :email, :type => 'email', :autofocus => 'autofocus'
8
8
  %p
9
9
  %label
10
10
  Password:
@@ -1,10 +1,8 @@
1
1
  !!!
2
- %html{ "lang" => "en" }
2
+ %html{ lang: "en" }
3
3
  %head
4
- %meta{ "charset" => "utf-8" }
5
- %title
6
- Administration:
7
- = controller.action_name.capitalize
4
+ %meta{ charset: "utf-8" }
5
+ %title Administration: #{controller.action_name.capitalize}
8
6
  = stylesheet_link_tag 'adminsite'
9
7
  = javascript_include_tag 'adminsite'
10
8
  %body.adminsite
@@ -20,12 +18,8 @@
20
18
  = flash[:error]
21
19
  = flash[:alert]
22
20
 
23
- #header
24
- #header_left
25
- %h2
26
- = yield :header_left
27
- #header_right
28
- = yield :header_right
29
- .clearfix
21
+ %header
22
+ %h2= yield :header_left
23
+ = yield(:header_right)
30
24
  #wrapper
31
25
  = yield
@@ -39,8 +39,9 @@ da:
39
39
  update_needs_confirmation: "Din konto er blevet opdateret, men vi er nødt til at bekræfte din nye email. Check venligst din mail og klik på bekræftelses linket for at bekræfte din nye email."
40
40
  updated: "Din konto er opdateret."
41
41
  sessions:
42
- signed_in: "Du er nu logget ind."
43
- signed_out: "Du er nu logget ud."
42
+ signed_in: " "
43
+ signed_out: " "
44
+ already_signed_out: " "
44
45
  unlocks:
45
46
  send_instructions: 'Om få minutter vil du modtage en email med instruktioner om genåbning af din konto.'
46
47
  send_paranoid_instructions: 'Hvis din e-mail adresse findes i vores database vil du modtage in e-mail med instutioner om hvordan du kan låse din konto op.'
@@ -41,9 +41,9 @@ en:
41
41
  update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and follow the confirm link to confirm your new email address."
42
42
  updated: "Your account has been updated successfully."
43
43
  sessions:
44
- signed_in: "Signed in successfully."
45
- signed_out: "Signed out successfully."
46
- already_signed_out: "Signed out successfully."
44
+ signed_in: " "
45
+ signed_out: " "
46
+ already_signed_out: " "
47
47
  unlocks:
48
48
  send_instructions: "You will receive an email with instructions for how to unlock your account in a few minutes."
49
49
  send_paranoid_instructions: "If your account exists, you will receive an email with instructions for how to unlock it in a few minutes."
@@ -1,3 +1,3 @@
1
1
  module Adminsite
2
- VERSION = "3.1.2" unless defined?(Adminsite::VERSION)
2
+ VERSION = "3.2.0" unless defined?(Adminsite::VERSION)
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: adminsite
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.2
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robin Wunderlin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-12 00:00:00.000000000 Z
11
+ date: 2016-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -273,6 +273,7 @@ files:
273
273
  - app/assets/images/adminsite/admin/spinner.gif
274
274
  - app/assets/javascripts/adminsite/admin.js.coffee
275
275
  - app/assets/javascripts/adminsite/admin/code_editor.js.coffee
276
+ - app/assets/javascripts/adminsite/admin/filters.js.coffee
276
277
  - app/assets/javascripts/adminsite/admin/hide_and_show.js.coffee
277
278
  - app/assets/javascripts/adminsite/admin/inputs/multi_select_box_input.js.coffee
278
279
  - app/assets/stylesheets/adminsite/admin.scss
@@ -293,6 +294,8 @@ files:
293
294
  - app/controllers/adminsite/admin_user_sessions_controller.rb
294
295
  - app/controllers/adminsite/contents_controller.rb
295
296
  - app/helpers/admin/adminsite_application_helper.rb
297
+ - app/helpers/admin/adminsite_menu_helper.rb
298
+ - app/helpers/admin/adminsite_search_form_helper.rb
296
299
  - app/helpers/admin_application_helper.rb
297
300
  - app/inputs/adminsite/multi_select_box_input.rb
298
301
  - app/models/adminsite/ability.rb
@@ -312,6 +315,7 @@ files:
312
315
  - app/views/adminsite/admin/crud/index.html.haml
313
316
  - app/views/adminsite/admin/crud/show.html.haml
314
317
  - app/views/adminsite/admin/iframe/index.haml
318
+ - app/views/adminsite/admin/resources/_filters.html.haml
315
319
  - app/views/adminsite/admin/resources/_form.haml
316
320
  - app/views/adminsite/admin/resources/_list.haml
317
321
  - app/views/adminsite/admin/resources/_search_form.html.haml