Skip to content

Commit

Permalink
Merge commit 'e499361'
Browse files Browse the repository at this point in the history
* commit 'e499361':
  Rails 5 support and Kaminari update
  Fix some rspecs bugs.
  Fix handling of nested controls params.
  Fix smart_listing helper method 'render_list'
  Update readme to include info about 'show' item action. Sology#54
  Add ability to pass locals to list view. Closes Sology#70
  New trigger event.
  Better handling of nested controls params
  Fix controls form not fading out the list. Sology#51
  Handle different modes of new item insertion
  Config now includes element templates.
  Version bump.
  • Loading branch information
vvondra committed Mar 22, 2018
2 parents b8ab8a5 + e499361 commit 586e5d9
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 23 deletions.
10 changes: 10 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
- Rails 5 support and Kaminari update [akostadinov]
- Better handling of nested controls params
- Fix controls not fading out list. Related to #51
- Config now includes element templates
- Add ability to pass locals to list view [GeorgeDewar]

1.1.2
-----------
- Some bugfixing: #20, #46, #58

1.1.0
-----------

Expand Down
21 changes: 13 additions & 8 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
PATH
remote: .
specs:
smart_listing (1.1.1)
smart_listing (1.1.2)
coffee-rails
jquery-rails
kaminari (~> 0.16.1)
kaminari (~> 0.17)
rails (>= 3.2)

GEM
Expand Down Expand Up @@ -66,17 +66,19 @@ GEM
railties (>= 3.0, < 5.0)
thor (>= 0.14, < 2.0)
json (1.8.1)
kaminari (0.16.1)
kaminari (0.17.0)
actionpack (>= 3.0.0)
activesupport (>= 3.0.0)
mail (2.6.3)
mime-types (>= 1.16, < 3)
mime-types (2.4.3)
mini_portile (0.6.0)
mini_portile2 (2.1.0)
minitest (5.4.2)
multi_json (1.10.1)
nokogiri (1.6.3.1)
mini_portile (= 0.6.0)
nokogiri (1.6.8)
mini_portile2 (~> 2.1.0)
pkg-config (~> 1.1.7)
pkg-config (1.1.7)
rack (1.5.2)
rack-test (0.6.2)
rack (>= 1.0)
Expand Down Expand Up @@ -136,9 +138,12 @@ PLATFORMS

DEPENDENCIES
bootstrap-sass
capybara
capybara-webkit
capybara (~> 2.4.4)
capybara-webkit (~> 1.3.1)
database_cleaner
rspec-rails
smart_listing!
sqlite3

BUNDLED WITH
1.12.5
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,10 @@ New partial for user (`users/user`) may look like this:
```haml
%td= user.name
%td= user.email
%td.actions= smart_listing_item_actions [{name: :edit, url: edit_user_path(user)}, {name: :destroy, url: user_path(user)}]
%td.actions= smart_listing_item_actions [{name: :show, url: user_path(user)}, {name: :edit, url: edit_user_path(user)}, {name: :destroy, url: user_path(user)}]
```
`smart_listing_item_actions` renders here links that allow to edit and destroy user item. `:edit` and `:destroy` are built-in actions, you can also define your `:custom` actions. Again. `<td>`'s class `actions` is important.
`smart_listing_item_actions` renders here links that allow to edit and destroy user item. `:show`, `:edit` and `:destroy` are built-in actions, you can also define your `:custom` actions. Again. `<td>`'s class `actions` is important.
Controller actions referenced by above urls are again plain Ruby on Rails actions that render JS like:
Expand Down
28 changes: 24 additions & 4 deletions app/assets/javascripts/smart_listing.coffee.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ class window.SmartListing
@selector: (name)->
@options["constants"]["selectors"][name]

@element_template: (name)->
@options["constants"]["element_templates"][name]

@config: Config


Expand Down Expand Up @@ -186,6 +189,8 @@ class window.SmartListing
new_item_placeholder.html(content)
new_item_placeholder.addClass(SmartListing.config.class("inline_editing"))

@container.trigger("smart_listing:new", new_item_placeholder)

@fadeLoaded()

create: (id, success, content) =>
Expand All @@ -196,10 +201,17 @@ class window.SmartListing
new_item_placeholder.addClass(SmartListing.config.class("hidden"))
new_item_action.removeClass(SmartListing.config.class("hidden"))

new_item = $("<tr />").addClass(SmartListing.config.class("editable"))
new_item = $(SmartListing.config.element_template("row")).addClass(SmartListing.config.class("editable"))
new_item.attr("data-#{SmartListing.config.data_attribute("id")}", id)
new_item.html(content)
new_item_placeholder.before(new_item)

if new_item_placeholder.length != 0
if new_item_placeholder.data("insert-mode") == "after"
new_item_placeholder.after(new_item)
else
new_item_placeholder.before(new_item)
else
@content.append(new_item)

@container.trigger("smart_listing:create:success", new_item)

Expand Down Expand Up @@ -361,11 +373,19 @@ $.fn.smart_listing_controls = () ->
# serialize form and merge it with smart listing params
prms = {}
$.each controls.serializeArray(), (i, field) ->
prms[field.name] = field.value
if field.name.endsWith("[]")
field_name = field.name.slice(0, field.name.length - 2)
if Array.isArray(prms[field_name])
prms[field_name].push field.value
else
prms[field_name] = [field.value]
else
prms[field.name] = field.value

prms = $.extend(smart_listing.params(), prms)
smart_listing.params(prms)

container.trigger("ajax:before")
smart_listing.fadeLoading()
smart_listing.reload()

$(this).each () ->
Expand Down
11 changes: 7 additions & 4 deletions app/helpers/smart_listing/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ def update options = {}
end

# Renders the main partial (whole list)
def render_list
def render_list locals = {}
if @smart_listing.partial
@template.render :partial => @smart_listing.partial, :locals => {:smart_listing => self}
@template.render :partial => @smart_listing.partial, :locals => {:smart_listing => self}.merge(locals || {})
end
end

Expand Down Expand Up @@ -180,6 +180,7 @@ def max_count?
private

def sanitize_params params
params = params.permit! if params.respond_to?(:permit!)
params.merge(UNSAFE_PARAMS)
end

Expand Down Expand Up @@ -229,8 +230,9 @@ def smart_listing_for name, *args, &block
end

def smart_listing_render name = controller_name, *args
options = args.extract_options!
smart_listing_for(name, *args) do |smart_listing|
concat(smart_listing.render_list)
concat(smart_listing.render_list(options[:locals]))
end
end

Expand Down Expand Up @@ -328,7 +330,8 @@ def smart_listing_update *args
smart_listing_config.data_attributes(:params) => smart_listing.all_params,
smart_listing_config.data_attributes(:max_count) => smart_listing.max_count,
smart_listing_config.data_attributes(:item_count) => smart_listing.count,
}
},
:locals => options[:locals] || {}
})
end

Expand Down
2 changes: 1 addition & 1 deletion app/views/smart_listing/_update_list.js.erb
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
var smart_listing = $('#<%= name %>').smart_listing();
smart_listing.update_list("<%= escape_javascript(render(:partial => part, :locals => {:smart_listing => smart_listing})) %>", <%= smart_listing_data.to_json.html_safe %>);
smart_listing.update_list("<%= escape_javascript(render(:partial => part, :locals => {:smart_listing => smart_listing}.merge(locals))) %>", <%= smart_listing_data.to_json.html_safe %>);
4 changes: 4 additions & 0 deletions lib/generators/smart_listing/templates/initializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,8 @@
#:filtering_input => ".filter input",
#:pagination_count => ".pagination-per-page .count",
}

config.constants :element_templates, {
#:row => "<tr />",
}
end
7 changes: 7 additions & 0 deletions lib/smart_listing/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ class Configuration
:filtering_icon => "button span",
:filtering_input => ".filter input",
:pagination_count => ".pagination-per-page .count",
},
:element_templates => {
:row => "<tr />",
}
}
}.freeze
Expand Down Expand Up @@ -129,6 +132,10 @@ def selectors key
@options[:constants].try(:[], :selectors).try(:[], key) || DEFAULTS[:constants][:selectors][key]
end

def element_templates key
@options[:constants].try(:[], :element_templates).try(:[], key) || DEFAULTS[:constants][:element_templates][key]
end

def global_options value = nil
if value && !value.empty?
@options[:global_options] ||= {}
Expand Down
2 changes: 1 addition & 1 deletion lib/smart_listing/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module SmartListing
VERSION = "1.1.1"
VERSION = "1.1.2"
end
6 changes: 3 additions & 3 deletions smart_listing.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ Gem::Specification.new do |s|

s.add_dependency "rails", ">=3.2"
s.add_dependency "coffee-rails"
s.add_dependency "kaminari", "~> 0.16.1"
s.add_dependency "kaminari", "~> 0.17"
s.add_dependency "jquery-rails"

s.add_development_dependency "bootstrap-sass"

s.add_development_dependency "sqlite3"
s.add_development_dependency "rspec-rails"

s.add_development_dependency "capybara"
s.add_development_dependency "capybara-webkit"
s.add_development_dependency "capybara", "~> 2.4.4"
s.add_development_dependency "capybara-webkit", "~> 1.3.1"
s.add_development_dependency "database_cleaner"
end
1 change: 1 addition & 0 deletions spec/helpers/smart_listing/helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
module SmartListing::Helper
class UsersController < ApplicationController
include ControllerExtensions
helper SmartListing::Helper

attr_accessor :smart_listings

Expand Down

0 comments on commit 586e5d9

Please sign in to comment.