GithubHelp home page GithubHelp logo

sology / smart_listing Goto Github PK

View Code? Open in Web Editor NEW
478.0 478.0 137.0 401 KB

Ruby on Rails data listing gem with built-in sorting, filtering and in-place editing.

Home Page: http://showcase.sology.eu/smart_listing

License: MIT License

Ruby 70.17% HTML 26.90% JavaScript 2.22% CSS 0.70%

smart_listing's People

Contributors

aaklak avatar akostadinov avatar ardahaal avatar blackcofla avatar boy-papan avatar bval avatar gcorbel avatar georgedewar avatar kitabatake avatar korun avatar ljachymczyk avatar marcintichoniuk avatar nfilzi avatar phoffer avatar sevgibson avatar tylerhunt avatar wynksaiddestroy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

smart_listing's Issues

undefined method `per' for ActiveRecord

I'm really excited to use this gem, unfortunately I get the error "undefined method `per' for <ActiveRecord::Relation::..." when using smart_listing_create in my controller

def index
    smart_listing_create(:projects, @projects, partial: "projects/list")
end

What is this method and why is it undefined?

CSS issue for smart_listing show action

Hello,

I' ve noticed, that automatically generated show action link has something like this in its CSS:

a.show
    display: block !important

The issue is I did not want for it to be displayed as block, so I had to overwrite this in my CSS with more classes and another !important. This is a problem, because !important is generally a bad practice in CSS, as people can wonder why their modifications don' t just work if they oversee it or don' t look into the CSS, and also I think that it should have the same options as other actions by default - the user can then change it for their project if they want to.

Add Search

I'd love to see global search/filtering ability added

Update row

Hi

I have a very simple smart_listing with an action, based on the in place editing example :

    %tbody
      - smart_listing.collection.decorate.each do |golf|
        %tr.editable
          = smart_listing.render object: golf, partial: "admin/homepage/promoted_golfs/row", locals: { object: golf }
%td.actions= smart_listing_item_actions [ { name: :custom, url:  toggle_admin_homepage_promoted_golf_path(object), method: :put, icon: "glyphicon #{object.promoted? ? 'glyphicon-remove-circle' : 'glyphicon-ok-circle' }", remote: true } ]

The call is ok and returns :

var smart_listing = $('#golfs').smart_listing();
smart_listing.update(41, true, "<td>41<\/td>\n<td>Golf de Guerville<\/td>\n<td>35.0<\/td>\n<td>55<\/td>\n<td>\n  <span class=\'glyphicon glyphicon-ok\'><\/span>\n<\/td>\n<td class=\'actions\'>\n  <span>\n  <a data-method=\"put\" data-remote=\"true\" href=\"/admin/homepage/promoted_golfs/golf-de-guerville/toggle\" name=\"custom\" rel=\"nofollow\"><span class=\"glyphicon glyphicon-remove-circle\"><\/span><\/a>\n  <\/span>\n<\/td>\n");

But the row is not updated, and there's no js errors showing up

If you have any idea why, I've been stucked on this for an hour now

Using wrong ajax URL when turbolinks activated

Steps to reproduce in an app with turbolinks:

  1. Visit a page that doesn't use smart_listing (e.g. faq page, /faq)
  2. Click on a link that leads to the page using smart_listing (e.g. /books)
  3. Click on a filter or anything that causes a reload of the results

When using the standard smart_listing configuration, it tries to load the results from /faq?filter1=val&filter2=val. Internally, smart_listing is calling $.rails.handleRemote which cannot find a proper URL/ href so that $.ajax is using a cached version of location.href (which points the initially loaded URL /faq).

Workaround: Adding an explicit href to smart_listing_create call: smart_listing_create ..., href: books_path

Potential fix to discuss: The default value for href is nil (https://github.com/Sology/smart_listing/blob/master/lib/smart_listing.rb#L35), perhaps we should set it the current path via url_for?

undefined method `like' for ....

Hi,

Firstly great gem!

I'm getting

undefined method `like' for #Assignment::ActiveRecord_Relation:0x007f783b3c9d70

Any ideas? Rails 4.1

Custom locals for smart_listing partials

I want to be able to pass additional locals for partials used in smart_listing (for example form or list, which are passed by me in smart_listing_item or smart_listing_render). Right now it is not possible.

`jquery-rails` should not be a dependency

It should be up to the gem user to decide how to integrate jQuery in her project.

For example, I use jQuery via bower and I don't want to add jquery-rails as a dependency of my project.

multiple filters in controls_for

When creating an array for bulk actions, only the last id gets passed to params on submit.

I created 12 checkboxes with the name status_id[]. At any given point, it would only pass in the last id instead of an array. A short term "workaround" i found was adding passing in the id into the array, but then instead of an array of values, you would get an array of key value pairs.

Feature Request: Store current page, sort, etc. in cookie/session

Several users have complained to me that when they return to the listing page (with Smart Listing) the list has started from the beginning again.

It would be great to be able to store the current details in the users session or a cookie so that when they return to the page it would load to the same spot as before, with sort/filter/paging etc.

I have multiple pages with different lists if that makes a difference.

Changelog is outdated

Although the current version is 1.1.2 the changelog only covers changes up to version 1.1.0.

smart_listing_controls_for not auto-submitting when values changed

@ljachymczyk I'm having some trouble getting smart_listing_controls_for to auto-submit and update the list.. From what I can tell, the HTML is rendered exactly the same as the demo on http://showcase.sology.eu/smart_listing under 'Controls Form'

Here's the code for the filter bar:

<%= smart_listing_controls_for(:photos, {class: "form-inline text-right"}) do %>
  <div class="form-group filter input-append">
    <%= hidden_field_tag :date_start, date_start.to_i %>
    <%= hidden_field_tag :date_end, date_end.to_i %>
  </div>
<% end %>

Does it make a difference if it's a hidden_field_tag versus a text_field_tag? And just to confirm, it should live outside the smart_listing_render partial?

Export data

It will be awesome to have a way to export the filtered data.

Sorting with dates, through methods, ...

1. Methods

Right now we can sort by columns of models and joined models.
Is it possible to sort through a method ?
I tried to use an attr_reader :my_method but it does not work.

class Subscription < ActiveRecord::Base
   ....
  def commitment_end
    @commitment_end = start_at.advance(months: commitment_period.to_i)
  end
end
        %th= smart_listing.sortable t('.end_of_commitment'), :commitment_end

And within sort_attributes : [:commitment_end, 'subscriptions.commitment_end']

2. Dates

When sorting dates, it seems the sort messes up like its a string and sort by alpha...

    smart_listing_create(:users, @users, partial: 'admin/users/listing_red',
                         array: true,
                         kaminari_options: { theme: 'bootstrap3' },
                         sort_attributes: [
                          [:start_at, 'subscriptions.start_at'],
                          [:lastname, 'lastname'],
                          [:firstname, 'firstname'],
                          [:email, 'email']
                         ],
                         default_sort: { start_at: 'desc' }
                         )
        %th= smart_listing.sortable User.human_attribute_name(:lastname), :lastname
        %th= smart_listing.sortable User.human_attribute_name(:firstname), :firstname
        %th= smart_listing.sortable User.human_attribute_name(:email), :email
        %th= smart_listing.sortable t('.started_at'), :start_at

My start_at columns seems not to be sorted at all, whereas others works ok.

undefined local variable or method `smart_listing'

I've read through the readme numerous times and, as far as I can tell, am doing everything exactly as you have it, but continue to get this error with the pagination links and I don't understand why.

controller:
class PlayersController < ApplicationController

require 'will_paginate/array'

include SmartListing::Helper::ControllerExtensions
helper SmartListing::Helper

def index
@players = smart_listing_create :players,
Player.includes(:contracts).includes(:subcontracts).text_search(params[:query]),
partial: "players/players_info_fields"
end
...
end

players#index:
<%= smart_listing_render :players %>

/players/_players_info_fields.html.erb (cutting out a lot of stuff here):
<% @players.each do |player| %>
player.blah
player.blah2
etc

<% end %>
<%= smart_listing.paginate %>
<%= smart_listing.pagination_per_page_links %>

That's where I keep getting the errors. I don't get it. I've tried changing both of those to be @players instead of smart_listing and when I do that, I get "wrong number of arguments (0 for 1)" for @players.paginate.

I've tried:
smart_listing(:players).paginate
@players.smart_listing.paginate
smart_listing(@players).paginate

None of them work. I don't understand why and this is getting extremely frustrating.

config :page_sizes is not update

I try to change config from default [3, 10, 20 ,50, 100] to [300] in production
and [3] in development

but seem like gem doesn't paginate as i expected and js also cache

Config not effective

Hi,

I tried to configure the default per_page through the SmartListing.configure block, with the helper and all, but it did not work. I tried to doi through Kaminari, but it does not work either !
I want a per_page to 25 but it seems stucked to 10.
Event with the page_size option (wich I have to implement manually as config does not works at all) when I click 25, it keeps 10 rows, same for 30, but it does works for 50.
This drive me crazy,

any idea ?

Filter inputs fire off excessive requests to backend when gaining focus

Currently using a filter as per example

.filter.input-append
= text_field_tag :filter, '', class: "search", placeholder: "Type name here", autocomplete: "off"
%button.btn.disabled{type: "submit"}
%i.icon.icon-search

When ever the page containing the filter input gains or loses focus it fires off the request to the backend to retrieve the data. It would make sense to change this so that upon only a keypress up or if the value has actually changed that it sends the request.

Im not sure if there is a use case for it to re send the request every time the page gains focus, for most users tabbing between browser pages is common and its starting to send enormous amounts of traffic without real value.

The new form is not showed correcly

I'm trying to use this :

<%= smart_listing_item :sightings, :new, @sighting, "sightings/form" %>

The form is a simple form but the result appenned is something like <form></form>fields. I made some test and I have this result :

$('table').first().html('<form>a</form>')
$('table').first().html() // return "<form></form>a"
$('.content').first().html('<form>a</form>')
$('.content').first().html() // return "<form>a</form>"

The first case is correct and the second is not. All childs of 'table' do the samething. I am using the latest version of twitter-bootstrap, rails, etc.

It do the same thing with Chrome and Firefox.

I don't have any idea. Do you have a solution?

Thanks.

Can't use filters

Can you explain why following your examples exactly for the filtering continues to result in either:

undefined method like' for #<Array or undefined methodlike' for #<ActiveRecord::Relation
?

I've tried using Model.all and Model.scope and it's the same issue every time. It's getting extremely frustrating to try and figure out why I'm forced to set my smart_listing_collection as array: true but then can't use filtering. And if I turn array: true off, I get

undefined method `page' for #<Array:

What is the trick to using filters on my models? I don't want to use a scope, I just want to return all records in my smart_listing table and allow users to filter by name or year (it's a collection of music albums).

Group by issue

How can I use smat listing with group by?

I have within the controller:

@stats = smart_listing_create(:stats, Log.group('cmd').order('1 DESC').count(:cmd), partial: "stats/list")

I can see at the console:

Started GET "/stats" for 10.0.16.12 at 2015-02-25 18:28:24 +0100
Processing by StatsController#index as HTML
   (31.9ms)  SELECT COUNT("logs"."cmd") AS count_cmd, cmd AS cmd FROM "logs" GROUP BY cmd
Completed 500 Internal Server Error in 35ms

NoMethodError (undefined method `page' for #<Hash:0x007f62a9a98270>):
  app/controllers/stats_controller.rb:11:in `index'

Is it possible to use the group by? Can you help me?

Missing show-action for in-place editing

I tried to add a show-action that works in-place, but I just saw, that there are several places, where I have to dig into your code:

  • a new show.js.erb
  • additions in smart_listing.coffee.erb
  • adding :showto smart_listing_item in helpers/smart_listing/helper.rb
  • etc...
    I would appreciate just having it in your next release. Should be really simple for you :-)

The functional need is simple: I have got a lot of more fields in a data entity than I will show as table columns.

kaminari pagination views

Hi

This is a truly awesome gem, just what i have been looking for.

Only one issue that i have which is how i can override the kaminari views.

I have generated them as kaminari docs suggest, they are just never used.

i really just need to make them not center align and have the class pagination-sm.

Any thoughts?

And many thanks again for the gem.

Sortable helper not working for me - please help!

Love the gem guys. I successfully implemented it on a previous project. I am building a simple app now and really struggling with an error when trying to sort and paginate a simple table of sent messages in an outbox:

ActionController::UrlGenerationError in Messages#sent

No route matches {:action=>"sent", :authenticity_token=>nil, :controller=>"Messages", :sentbox_smart_listing=>{"page"=>nil, "per_page"=>20, "sort"=>{"receiver_id"=>"asc"}}, :utf8=>nil}

The issue is when I include the sortable helper (also the issue appears when I paginate records), e.g:
%th= smart_listing.sortable "Recipient", :receiver_id

My routes are defined as:

get 'messages/trash' => 'messages#trash'

get 'messages/sent' => 'messages#sent'

resources :messages

My smart_listing create code is as follows:

sentbox_scope = Message.where('sender_id = ?', current_user.id).order("created_at DESC")
sentbox_scope = sentbox_scope.like(params[:filter]) if params[:filter]
@sentbox = smart_listing_create(:sentbox, sentbox_scope, array: true, page_sizes: [20], partial: "messages/sentbox")

I have included the appropriate sent.js.erb file as well as the partial. I can trigger the issue when paginating with just 1 record too - so it seems to me that the helper is not working.

I have successfully used this gem on another project so I am pretty sure it's just me doing something wrong - but can't figure out what!!!

Any help would be much appreciated.

Thanks,
James

Sorting on integer value not numerical order

I have a list that is being sorted on the numerical order

some values in the column = ["3", "5", "8", "4", "1", "2", "9", "10", "7", "6"]

sorted results = ["1", "10", "2", "3", "4", "5", "6", "7", "8", "9"]

How can I get this to be on integer value NOT numerical order?

undefined method `smart_listing_update'

I getting this error with this line in the index.js.erb file:
<%= smart_listing_update(:persons) %>

I'm new to Rails and probaly misunderstood some point in the README. I just can't see what I'm doing wrong after go through instructions for some many times now. It might be the the helpers missing or something. I'm including the helpers in the app/controllers/application_controller.rb file.

I'm sorry if it's not an issue. I'm on the 1.0.0 version.

Sort on an icon column

Is it possible to sort on a column with an icon instead of a standard name?

e.g. I use this to signify a user's email address <i class="fa fa-envelope"></i> (via Font Awesome) and I would like to allow sorting on it.

Incompatible with Turbolinks?

I've experienced an issue with smart_listing and turbolinks. If a site is rendered via turbolinks (without a full reload) jQuerys ready() method won't be triggered. Therefore parts like

$(function() {
  $('.smart-listing').smart_listing();
  return $('.smart-listing-controls').smart_listing_controls();
});

wont' work. I simply installed the jquery-turbolinks gem to solve the problem, but maybe you want to have look at the issue.

Thanks for your effort and passion you put in this lovely gem

Sort link don't work with sort_attributes

Hi,

When I activate the option sort_attributes in my controller, links to sort in my view no longer work. sorts are blockes on asc.

# My controller
def index
    @plots = smart_listing_create(
              :plots,
              Plot.joins(:camping),
              partial: "plots/listing",
              sort_attributes: [[:camping_name, "campings.name"],[:number, "number"],[:surface, "surface"]],
              #sort_dirs: [nil, "asc", "desc"],
              default_sort: {number: "asc"})
end
# My view
- unless smart_listing.empty?
  %table.table
    %thead
      %tr
        %th= smart_listing.sortable Plot.human_attribute_name(:number), "number"
        %th= smart_listing.sortable Plot.human_attribute_name(:surface), "surface"
        %th= smart_listing.sortable Plot.human_attribute_name(:camping), "camping_name"
        %th= Plot.human_attribute_name(:comment)

Thx

Smart_listing_create only contains three results

This looks like a fantastic gem, but I'm having a strange issue.

@restaurants = Restaurant.all
returns 32 results, but

@restaurants = smart_listing_create(:restaurants, Restaurant.all, partial: "restaurants/list")
only returns 3. Am I doing something stupid?

More sorting options

I would like to have some more options for the sortable helper:

  • Ability to set a default sort order for first click on a column (start with desc instead of asc)
  • Skip nil sort in cycle (3rd click would not trigger a nil sort - this could be a global setting)

Not compatible with Mongoid

So, although this works amazingly well with ActiveRecord, I was concerned because I could not use this gem. So, I made this fork, but I'm still not 100% sure of its backwards compatibility with ActiveRecord. Would this team be willing to support Mongoid and ActiveRecord, or should I continue to pursue this on my own?

Simplification and refactoring

Hi,

I think the project needs a simplification. It would be perfect if, to do an admin interface, we just have to do this :

class UserController < ApplicationController
  smart_listing :crud
end

With this simple function call, the controller must have default actions which have the views to do a in place editing like in the demo.

To have a simple list, it should be possible to replace smart_listing :crud by smart_listing :list. All actions and views must to be overwritable.

I can pass some times to do it but, before to start, I need unit tests and acceptances specs. I also need to have a support from Sology.

Please, can you do the tests?

Thanks!

Performance Issue

The page rendering is too slow in my app, could it be due to that i'm using slim as template engine?.

Here are some logs.

Started GET "/groups?groups_smart_listing%5Bpage%5D=&groups_smart_listing%5Bper_page%5D=10&groups_smart_listing%5Bsort%5D%5Bname%5D=desc" for 10.0.2.2 at 2014-05-22 21:13:27 -0400
Processing by GroupsController#index as JS
  Parameters: {"groups_smart_listing"=>{"page"=>"", "per_page"=>"10", "sort"=>{"name"=>"desc"}}}
   (2.0ms)  SELECT COUNT(*) FROM "groups"
  Rendered smart_listing/_sortable.html.slim (1.5ms)
  Group Load (7.5ms)  SELECT  "groups".* FROM "groups"   ORDER BY name desc LIMIT 10 OFFSET 0
  Rendered smart_listing/_action_delete.html.slim (0.5ms)
  Rendered groups/_group.html.slim (310.0ms)
  Rendered smart_listing/_action_delete.html.slim (0.7ms)
  Rendered groups/_group.html.slim (494.2ms)
  Rendered smart_listing/_action_delete.html.slim (0.8ms)
  Rendered groups/_group.html.slim (396.5ms)
  Rendered smart_listing/_action_delete.html.slim (0.9ms)
  Rendered groups/_group.html.slim (459.3ms)
  Rendered smart_listing/_action_delete.html.slim (0.7ms)
  Rendered groups/_group.html.slim (472.6ms)
  Rendered smart_listing/_action_delete.html.slim (1.8ms)
  Rendered groups/_group.html.slim (474.5ms)
  Rendered smart_listing/_action_delete.html.slim (4.4ms)
  Rendered groups/_group.html.slim (456.4ms)
  Rendered smart_listing/_action_delete.html.slim (1.4ms)
  Rendered groups/_group.html.slim (435.2ms)
  Rendered smart_listing/_action_delete.html.slim (0.5ms)
  Rendered groups/_group.html.slim (473.0ms)
  Rendered smart_listing/_action_delete.html.slim (0.6ms)
  Rendered groups/_group.html.slim (551.8ms)
  CACHE (0.0ms)  SELECT COUNT(*) FROM "groups"
  Rendered smart_listing/_pagination_per_page_link.html.slim (0.3ms)
  Rendered smart_listing/_pagination_per_page_link.html.slim (0.3ms)
  Rendered smart_listing/_pagination_per_page_link.html.slim (0.5ms)
  Rendered smart_listing/_pagination_per_page_links.html.slim (1412.1ms)
  Rendered groups/_list.html.slim (11373.5ms)
  Rendered /usr/local/rvm/gems/ruby-2.1.0@betsman/gems/smart_listing-1.0.0/app/views/smart_listing/_update_list.js.erb (11879.7ms)
  Rendered groups/index.js.slim (12185.2ms)
Completed 200 OK in 12716ms (Views: 12701.6ms | ActiveRecord: 9.6ms)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.