smart_listing 1.2.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9e99ae401d68d2b6f4af5569bf2963fd8eafdb8f
4
- data.tar.gz: 8469a86376223350e45927863a7d7c8096c6fc98
3
+ metadata.gz: 0d036e38f0ade94d2360779aad5df71aa55044c9
4
+ data.tar.gz: 77fd8c742f4f0795e6bf6e20b0ef756b60083602
5
5
  SHA512:
6
- metadata.gz: 9cf884e1df41a3417a666929c7b66796bf87dbd6089d2c35891650ee178e5c5892c7e7b32c8a8c174f413810669fad3ebca402287b4aef6dc0a0346aa895b697
7
- data.tar.gz: 6b412d30392763ad1c5c227ec0261abd9922ffbf5f0f9c95c996b9cba745e9284b4009ffd6b27214edfaea36fef1260eece888168894f121aaee303a911b58f6
6
+ metadata.gz: 929c87c6a88255ea1a8e1510252f6d1c08578818d94490d6b7395ed6fb24133bb818250b1e1d54df092e4b42c36f79c23e31279bc457e8d414c8edc2cecb5f3c
7
+ data.tar.gz: ad3fb94f079e41cbbc6d6ef8e56f00703a94fc93b954a522ab35a8ff4977e1b214b12cda9e89581f0a5aa008b9c4ca565a1bc37f8f75174bbad56aff50ebe1b9
data/README.md CHANGED
@@ -73,7 +73,7 @@ smart_listing_render(:users)
73
73
  - unless smart_listing.empty?
74
74
  %table
75
75
  %thead
76
- %tr
76
+ %tr
77
77
  %th User name
78
78
  %th Email
79
79
  %tbody
@@ -82,7 +82,7 @@ smart_listing_render(:users)
82
82
  %td= user.name
83
83
  %td= user.email
84
84
 
85
- = smart_listing.paginate
85
+ = smart_listing.paginate
86
86
  - else
87
87
  %p.warning No records!
88
88
  ```
@@ -112,7 +112,7 @@ SmartListing supports two modes of sorting: implicit and explicit. Implicit mode
112
112
  - unless smart_listing.empty?
113
113
  %table
114
114
  %thead
115
- %tr
115
+ %tr
116
116
  %th= smart_listing.sortable "User name", :name
117
117
  %th= smart_listing.sortable "Email", :email
118
118
  %tbody
@@ -121,12 +121,12 @@ SmartListing supports two modes of sorting: implicit and explicit. Implicit mode
121
121
  %td= user.name
122
122
  %td= user.email
123
123
 
124
- = smart_listing.paginate
124
+ = smart_listing.paginate
125
125
  - else
126
126
  %p.warning No records!
127
127
  ```
128
128
 
129
- In this case `:name` and `:email` are sorting column names. `Builder#sortable` renders special link containing column name and sort order (either `asc`, `desc`, or empty value).
129
+ In this case `:name` and `:email` are sorting column names. `Builder#sortable` renders special link containing column name and sort order (either `asc`, `desc`, or empty value).
130
130
 
131
131
  You can also specify default sort order in the controller:
132
132
 
@@ -136,7 +136,7 @@ You can also specify default sort order in the controller:
136
136
 
137
137
  Implicit mode is convenient with simple data sets. In case you want to sort by joined column names, we advise you to use explicit sorting:
138
138
  ```ruby
139
- @users = smart_listing_create :users, User.active.joins(:stats), partial: "users/listing",
139
+ @users = smart_listing_create :users, User.active.joins(:stats), partial: "users/listing",
140
140
  sort_attributes: [[:last_signin, "stats.last_signin_at"]],
141
141
  default_sort: {last_signin: "desc"}
142
142
  ```
@@ -153,7 +153,7 @@ In order to allow managing and editing list items, we need to reorganize our vie
153
153
  - unless smart_listing.empty?
154
154
  %table
155
155
  %thead
156
- %tr
156
+ %tr
157
157
  %th= smart_listing.sortable "User name", "name"
158
158
  %th= smart_listing.sortable "Email", "email"
159
159
  %th
@@ -161,9 +161,9 @@ In order to allow managing and editing list items, we need to reorganize our vie
161
161
  - smart_listing.collection.each do |user|
162
162
  %tr.editable{data: {id: user.id}}
163
163
  = smart_listing.render partial: 'users/user', locals: {user: user}
164
- = smart_listing.item_new colspan: 3, link: new_user_path
164
+ = smart_listing.item_new colspan: 3, link: new_user_path
165
165
 
166
- = smart_listing.paginate
166
+ = smart_listing.paginate
167
167
  - else
168
168
  %p.warning No records!
169
169
  ```
@@ -174,7 +174,7 @@ In order to allow managing and editing list items, we need to reorganize our vie
174
174
  <%= smart_listing_item :users, :new, @new_user, "users/form" %>
175
175
  ```
176
176
 
177
- Note that `new` action does not need to create SmartListing (via `smart_listing_create`). It just initializes `@new_user` and renders JS view.
177
+ Note that `new` action does not need to create SmartListing (via `smart_listing_create`). It just initializes `@new_user` and renders JS view.
178
178
 
179
179
  New partial for user (`users/user`) may look like this:
180
180
  ```haml
@@ -204,10 +204,10 @@ Partial name supplied to `smart_listing_item` (`users/form`) references `@user`
204
204
 
205
205
  = form_for object, url: object.new_record? ? users_path : user_path(object), remote: true do |f|
206
206
  %p
207
- Name:
207
+ Name:
208
208
  = f.text_field :name
209
209
  %p
210
- Email:
210
+ Email:
211
211
  = f.text_field :email
212
212
  %p= f.submit "Save"
213
213
  ```
@@ -228,7 +228,7 @@ SmartListing controls allow you to change somehow presented data. This is typica
228
228
  .filter.input-append
229
229
  = text_field_tag :filter, '', class: "search", placeholder: "Type name here", autocomplete: "off"
230
230
  %button.btn.disabled{type: "submit"}
231
- %i.icon.icon-search
231
+ %span.glyphicon.glyphicon-search
232
232
  ```
233
233
 
234
234
  This gives you nice Bootstrap-enabled filter field with keychange handler. Of course you can use any other form fields in controls too.
@@ -262,7 +262,7 @@ SmartListing.configure(:awesome_profile) do |config|
262
262
  end
263
263
  ```
264
264
 
265
- In order to use this profile, create helper method named `smart_listing_config_profile` returning profile name and put into your JS `SmartListing.config.merge()` function call. `merge()` function expects parameter with config attributes hash or reads body data-attribute named `smart-listing-config`. Hash of config attributes can be obtained by using helper method `SmartListing.config(:awesome_profile).to_json`.
265
+ In order to use this profile, create helper method named `smart_listing_config_profile` returning profile name and put into your JS `SmartListing.config.merge()` function call. `merge()` function expects parameter with config attributes hash or reads body data-attribute named `smart-listing-config`. Hash of config attributes can be obtained by using helper method `SmartListing.config(:awesome_profile).to_json`.
266
266
 
267
267
  ## Not enough?
268
268
 
@@ -24,6 +24,9 @@ class window.SmartListing
24
24
  @element_template: (name)->
25
25
  @options["constants"]["element_templates"][name]
26
26
 
27
+ @bootstrap_commands: (name)->
28
+ @options["constants"]["bootstrap_commands"][name]
29
+
27
30
  @config: Config
28
31
 
29
32
 
@@ -319,8 +322,8 @@ $.fn.smart_listing.observeField = (field, opts = {}) ->
319
322
  , 400)
320
323
 
321
324
  $.fn.smart_listing.showPopover = (elem, body) ->
322
- elem.popover("destroy")
323
- elem.popover(content: body, html: true, trigger: "manual", title: null)
325
+ elem.popover(SmartListing.config.bootstrap_commands("popover_destroy"))
326
+ elem.popover(content: body, html: true, trigger: "manual")
324
327
  elem.popover("show")
325
328
 
326
329
  $.fn.smart_listing.showConfirmation = (confirmation_elem, msg, confirm_callback) ->
@@ -333,12 +336,12 @@ $.fn.smart_listing.showConfirmation = (confirmation_elem, msg, confirm_callback)
333
336
  editable = $(event.currentTarget).closest(SmartListing.config.class_name("editable"))
334
337
  confirm_callback(confirmation_elem)
335
338
  $(confirmation_elem).click()
336
- $(confirmation_elem).popover("destroy")
339
+ $(confirmation_elem).popover(SmartListing.config.bootstrap_commands("popover_destroy"))
337
340
  )
338
341
  .append(" ")
339
342
  .append($("<button/>").html("No").addClass("btn btn-small").click (event) =>
340
343
  editable = $(event.currentTarget).closest(SmartListing.config.class_name("editable"))
341
- $(confirmation_elem).popover("destroy")
344
+ $(confirmation_elem).popover(SmartListing.config.bootstrap_commands("popover_destroy"))
342
345
  )
343
346
  )
344
347
 
@@ -438,4 +441,4 @@ ready = ->
438
441
  $(SmartListing.config.class_name("controls")).smart_listing_controls()
439
442
 
440
443
  $(document).ready ready
441
- $(document).on "page:load", ready
444
+ $(document).on "page:load turbolinks:load", ready
@@ -11,6 +11,7 @@ module SmartListing
11
11
  name = (args[0] || options[:name] || controller_name).to_sym
12
12
  collection = args[1] || options[:collection] || smart_listing_collection
13
13
 
14
+ view_context = self.respond_to?(:controller) ? controller.view_context : self.view_context
14
15
  options = {:config_profile => view_context.smart_listing_config_profile}.merge(options)
15
16
 
16
17
  list = SmartListing::Base.new(name, collection, options)
@@ -1,3 +1,3 @@
1
1
  var smart_listing = $('#<%= name %>').smart_listing();
2
2
  smart_listing.setAutoshow(false);
3
- smart_listing.create(<%= id || 0 %>, <%= object.persisted? %>, "<%= escape_javascript(render(:partial => part, :locals => {object_key => object})) %>");
3
+ smart_listing.create(<%= (id || 0).to_json.html_safe %>, <%= object.persisted? %>, "<%= escape_javascript(render(:partial => part, :locals => {object_key => object})) %>");
@@ -1,6 +1,6 @@
1
1
  var smart_listing = $('#<%= name %>').smart_listing();
2
2
  smart_listing.setAutoshow(true);
3
- smart_listing.create(<%= id || 0 %>, <%= object.persisted? %>, "<%= escape_javascript(render(:partial => part, :locals => {object_key => object})) %>");
3
+ smart_listing.create(<%= (id || 0).to_json.html_safe %>, <%= object.persisted? %>, "<%= escape_javascript(render(:partial => part, :locals => {object_key => object})) %>");
4
4
  <% if object.persisted? %>
5
5
  smart_listing.new_item("<%= escape_javascript(render(:partial => new.last, :locals => {object_key => new.first})) %>");
6
6
  <% end %>
@@ -1,2 +1,2 @@
1
1
  var smart_listing = $('#<%= name.to_s %>').smart_listing();
2
- smart_listing.destroy(<%= id %>, <%= object.destroyed? %>);
2
+ smart_listing.destroy(<%= id.to_json.html_safe %>, <%= object.destroyed? %>);
@@ -1,2 +1,2 @@
1
1
  var smart_listing = $('#<%= name %>').smart_listing();
2
- smart_listing.edit(<%= id %>, "<%= escape_javascript(render(:partial => part, :locals => {object_key => object})) %>");
2
+ smart_listing.edit(<%= id.to_json.html_safe %>, "<%= escape_javascript(render(:partial => part, :locals => {object_key => object})) %>");
@@ -1,2 +1,2 @@
1
1
  var smart_listing = $('#<%= name %>').smart_listing();
2
- smart_listing.remove(<%= id %>);
2
+ smart_listing.remove(<%= id.to_json.html_safe %>);
@@ -1,2 +1,2 @@
1
1
  var smart_listing = $('#<%= name %>').smart_listing();
2
- smart_listing.update(<%= id %>, <%= valid.nil? ? object.valid? : valid %>, "<%= escape_javascript(render(:partial => part, :locals => {object_key => object})) %>");
2
+ smart_listing.update(<%= id.to_json.html_safe %>, <%= valid.nil? ? object.valid? : valid %>, "<%= escape_javascript(render(:partial => part, :locals => {object_key => object})) %>");
@@ -5,7 +5,7 @@ module SmartListing
5
5
 
6
6
  def self.banner #:nodoc:
7
7
  <<-BANNER.chomp
8
- rails g smart_listing:install
8
+ rails g smart_listing:install
9
9
 
10
10
  Copies initializer file
11
11
  BANNER
@@ -15,6 +15,6 @@ BANNER
15
15
  def copy_views
16
16
  template 'initializer.rb', 'config/initializers/smart_listing.rb'
17
17
  end
18
- end
19
- end
18
+ end
19
+ end
20
20
  end
@@ -85,4 +85,8 @@ SmartListing.configure do |config|
85
85
  config.constants :element_templates, {
86
86
  #:row => "<tr />",
87
87
  }
88
+
89
+ config.constants :bootstrap_commands, {
90
+ #:popover_destroy => "destroy", # Bootstrap 4 requries dipsose instead of destroy
91
+ }
88
92
  end
@@ -5,7 +5,7 @@ module SmartListing
5
5
 
6
6
  def self.banner #:nodoc:
7
7
  <<-BANNER.chomp
8
- rails g smart_listing:views
8
+ rails g smart_listing:views
9
9
 
10
10
  Copies all smart listing partials templates to your application.
11
11
  BANNER
@@ -18,6 +18,6 @@ BANNER
18
18
  copy_file f, "app/views/smart_listing/#{f}"
19
19
  end
20
20
  end
21
- end
22
- end
21
+ end
22
+ end
23
23
  end
data/lib/smart_listing.rb CHANGED
@@ -68,8 +68,8 @@ module SmartListing
68
68
  end
69
69
 
70
70
  if @options[:array]
71
- if @sort && @sort.any? # when array we sort only by first attribute
72
- i = sort_keys.index{|x| x[0] == @sort.first[0]}
71
+ if @sort && !@sort.empty? # when array we sort only by first attribute
72
+ i = sort_keys.index{|x| x[0] == @sort.to_h.first[0]}
73
73
  @collection = @collection.sort do |x, y|
74
74
  xval = x
75
75
  yval = y
@@ -83,7 +83,7 @@ module SmartListing
83
83
  if xval.nil? || yval.nil?
84
84
  xval.nil? ? 1 : -1
85
85
  else
86
- if @sort.first[1] == "asc"
86
+ if @sort.to_h.first[1] == "asc"
87
87
  (xval <=> yval) || (xval && !yval ? 1 : -1)
88
88
  else
89
89
  (yval <=> xval) || (yval && !xval ? 1 : -1)
@@ -94,13 +94,13 @@ module SmartListing
94
94
  if @options[:paginate] && @per_page > 0
95
95
  @collection = ::Kaminari.paginate_array(@collection).page(@page).per(@per_page)
96
96
  if @collection.length == 0
97
- @collection = @collection.page(@collection.num_pages)
97
+ @collection = @collection.page(@collection.total_pages)
98
98
  end
99
99
  end
100
100
  else
101
101
  # let's sort by all attributes
102
102
  #
103
- @collection = @collection.order(sort_keys.collect{|s| "#{s[1]} #{@sort[s[0]]}" if @sort[s[0]]}.compact) if @sort && @sort.any?
103
+ @collection = @collection.order(sort_keys.collect{|s| "#{s[1]} #{@sort[s[0]]}" if @sort[s[0]]}.compact) if @sort && !@sort.empty?
104
104
 
105
105
  if @options[:paginate] && @per_page > 0
106
106
  @collection = @collection.page(@page).per(@per_page)
@@ -97,6 +97,9 @@ module SmartListing
97
97
  },
98
98
  :element_templates => {
99
99
  :row => "<tr />",
100
+ },
101
+ :bootstrap_commands => {
102
+ :popover_destroy => "destroy",
100
103
  }
101
104
  }
102
105
  }.freeze
@@ -1,3 +1,3 @@
1
1
  module SmartListing
2
- VERSION = "1.2.0"
2
+ VERSION = "1.2.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smart_listing
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sology
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-29 00:00:00.000000000 Z
11
+ date: 2017-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails