Coder Social home page Coder Social logo

alphabetical_paginate's People

Contributors

cbaines avatar dej611 avatar florianeck avatar fofr avatar h-lame avatar lingz avatar m2meier avatar nlevchuk avatar oleg-gr avatar sihugh avatar slant 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

alphabetical_paginate's Issues

Other language support

Hello guys! What you think about other language support? I need russian language support and I'm doing this right now. Can you merge my Pull Request with russian language?

Rails 4 Support

Hi, I'm a relative beginner and trying to deploy your gem.
After running bundle install I added the following to the controller

@investors, @alphaParams = Investor.alpha_paginate(params[:letter]){|investor| investor.l_name}

And put the code in the view to display
<%= alphabetical_paginate @investors %>

I get this error when trying to load the view "undefined method `alpha_paginate' for #Class:0x007fa040152a88"

This is dev environment, sqlite. Any hints would be welcome. Thanks!

SQL Injection

Hi,

Recently I was reviewing some code that contained an SQL injection vulnerability which I believe to originate from the use of alphabetical_paginate .

the code they used looked like
@users, @sorting_params = @users.alpha_paginate(
params[:startletter],
ALPHABETICAL_PAGINATE_CONFIG,
&:name
)

The injection was happening via
http://somesite.com/users?startletter=G

By passing
G' or 1='1
as the value of startletter it was possible to return all objects.

I think the fix should be to only take the first character, rather than the full string.

Feel free to contact me if you require further information.

Kind Regards
Mike

Should avoid multiple bindings

Every time alpha_paginate is used in the page it binds a new function to the click event: this means that if it is used as a header and a footer it will bind the same function twice, sending the same request two times at the server.

In practice, before binding the element with the handler it should check if the element is already bound.

Current

$(document).on("click", ".pagination#alpha a", function(e) {
        var url = location.href, 
        letter = $(this).data("letter");
        if (/letter/.test(url)) {
            url = url.replace(/letter=[^&]*/, "letter=" + letter);
        } 
        else {
            if (/\?/.test(url)) {
                url += "&letter=" + letter;
            } 
            else {
                url += "?letter=" + letter;
            }
        }
        $(".pagination").html(img);
        //$.load(url + " #pagination_table");
        $.get(url, function(result) {
            $(".pagination").html($(".pagination", result));
            $("#pagination_table").html($("#pagination_table", result));
        });
        history.pushState(null, document.title, url);
        e.preventDefault();
    });

Fixed

This should work:

var navbar = $(".pagination#alpha a");
// Pick the handler list: just a quick check for the jQuery version (see here: http://bugs.jquery.com/ticket/10589)
var handlers = navbar.data ? navbar.data('events').click : jQuery._data(navbar[0], 'events').click;

if (-1 !== $.inArray(onNavbarClick, handlers) {
    $(document).on("click", ".pagination#alpha a", onNavbarClick);
}

function onNavbarClick(e) {
        var url = location.href, 
        letter = $(this).data("letter");
        if (/letter/.test(url)) {
            url = url.replace(/letter=[^&]*/, "letter=" + letter);
        } 
        else {
            if (/\?/.test(url)) {
                url += "&letter=" + letter;
            } 
            else {
                url += "?letter=" + letter;
            }
        }
        $(".pagination").html(img);
        //$.load(url + " #pagination_table");
        $.get(url, function(result) {
            $(".pagination").html($(".pagination", result));
            $("#pagination_table").html($("#pagination_table", result));
        });
        history.pushState(null, document.title, url);
        e.preventDefault();
    });

It shouldn't show any pagination bar when no data is available

As in will_paginate, the pagination bar should be hidden when there's no data to paginate I think.

Seeing the following makes me assume that there's something else in a different letter:
screen shot 2015-02-22 at 18 30 12

While I see that this may have an impact on performances, it may prevent the user to try to attempt random clicks while browsing.

In will_paginate it just doesn't render the pagination bar when no data it's available:
screen shot 2015-02-22 at 18 30 25

With Js enabled there are multiple calls fired on each click

When the JS option is enabled (always by default) a script tag is appended in the DOM (as for this line here).

This behavior raises two different issues:

  • having the assets pipeline on (as recommended in production) the server will reply with an HTML 404 as the script should really be compiled with the others
  • If the script is served, it will load and bind to the link on the pagination bar an AJAX function.

This leads to this kind of behaviour:
screen shot 2015-03-29 at 17 41 44
Note: this is trigger by a single click, as you see the starting point is the same of all 4.

When the user clicks a couple of letters on the bar a massive number of requests start to hit the server.

While there are some solutions to fix such behavior it looks to me that this kind of things should really be implemented by the user himself rather than be in the bundle.

For instance a similar gem such will_paginate works this way - no AJAX support in the bundle - and adapt it to work with AJAX is not that hard: http://asciicasts.com/episodes/174-pagination-with-ajax

I'd propose to remove such option, or at least ship the JS file as a separate asset that can be included but no automagically included as it does right now.
Documenting on the WIKI how to enable it seems a reasonable solution to me and will make also the support of this gem much simpler.

Bootstrap 3 responsive wrapping issue on small screens

When viewing a page using a small width screen (e.g. iPhone), the pagination block wraps twice. This isn't really a problem, except that it wraps over the top of the table it is paginating thus obscuring the first few rows of the table.

Preserve existing page variables?

Here is my existing query.

@workingaccount = Account.find(params[:id])
@accounts, @alphaParams = Account.alphabetical.all.alpha_paginate(params[:letter], {:default_field => "all", :others => true, :js => false, :bootstrap3 => true, :paginate_all => true}){|account| account.name}

Is there a way to preserve the existing page variable?

account/?id=5&letter=all

It would be great if you could add existing page variable to the call like such

@accounts, @alphaParams = Account.alphabetical.all.alpha_paginate(params[:letter], {:default_field => "all", :others => true, :js => false, :bootstrap3 => true, :paginate_all => true, param=>{:id => params[:id]}}){|account| account.name}

This is how will_paginate handles it

<%= will_paginate @accounts, :params => {:id => params[:id]}, :class => 'pagination' %>

DB mode doesn't work

Db mode doesn't work with the recent updates (include_all and language support). The file controller_helper.rb needs fixing. Initially I was getting an error that letters_range is not defined, which is easily fixed by defining params[:language] in controller_helper.rb, but the logic still needs to be written.

Also, in non-db mode it doesn't work either... It gives just one field 0. Have you been getting similar results?

Pluck

Can I use pluck with this gem?

Sorting is Case Sensitive

Great plugin, thanks. I just noticed that the sorting is case sensitive, so I have to manually sort the records in order to get them to display correctly.

Is there a way to get the sort working case insensitive? At this point I'm just going to sort_by the array, until I find a better solution...

Issue with multiple instances

Using Rails 3, last version of alphabetical_paginate, bootstrap 3 (with the :bootstrap3 flag set ) it works fine for the first instance:
screen shot 2014-03-27 at 19 30 18

While with the second one there are some issues with the All link:
screen shot 2014-03-27 at 19 30 27

Extra details:

  • The only flag used in the alpha_paginate is :bootstrap3 => true

How to preserve all letters?

I have come up with this ugly solution

@q = Country.only_countries.search(params[:q])
 @countries, @alphaParams = Country.only_countries.alpha_paginate(params[:letter], {support_language: :ru, js: false}){ |c| c.name }
 @countries, _ = @q.result.alpha_paginate(params[:letter], {support_language: :ru, js: false}){ |c| c.name }

Is there any way to do it properly?

Duplicate pagination_table element created on navigation

When navigate from one letter to another with the paginator a duplicate of the #pagination_table element is created.
screen shot 2014-03-28 at 07 39 21

It is added only when a link on the pagination bar is used: on first load there's only a single element #pagination_table.

Note: on the page there are two instances of the paginator.

Ajax loading on navbar not triggered, if other click handlers present

Is suspect a bug here:

if (!handlers || -1 !== $.inArray(onNavbarClick, handlers.click)) {

Maybe I'm misreading your code, but should the !== in ...

if (!handlers || -1 !== $.inArray(onNavbarClick, handlers.click)) {

... not actually be a ===? I debugged it and in my case, since there are already some click events present, it jumps over it. ($.inArray() returns -1 if nothing is found. But if nothing is found, don't we want to add our click handler?)

Support cyrilic and english later in conjunction

The gem has support for the Russian language, but it is available when you switch the locale of the application. But you have not considered an option when the data for pagination, regardless of the application language can be in Russian and in English? For example a list of user names, or a list of surnames.

Sorry for my English, I do not know him very well

Put navigation below wrapped table

Is there a way to configure your gem to put the pagination navigation below the table that's wrapped in the <div id="pagination_table"></div>?

Pagination index is not printing properly

Hi I am using the alphabertical_paginate gem and everything is working as expected except for the line: <%= alphabetical_paginate @alphaParams %>

This prints down the page like so:
.a
.b
.c
etc

whereas I want it to print like:
.a .b .c .d .e etc

the code is:
in the controller:
@Breeds, @alphaParams = Breed.all.alpha_paginate(params[:letter]){|breed| breed.breedName}
in index.html.erb:
<%= alphabetical_paginate @alphaParams %>

I am new to ruby on rails, is there anything that comes to mind that I may be doing wrong ?

Thanking you in advance
Leah

Support for Bootstrap 3.0

Please can you add support for Bootstrap 3?

Bootstrap 3 dispenses with the styling using div and applies it directly to the ul tag.

support for RTL farsi language

Hi
I want to use your useful gem for my website which is a persian(farsi) RTL language website. I have a Plant model I want to paginate by its column :name which is filled with farsi words.
Farsi 32 Letters are: "الف ب پ ت ث ج چ ح خ د ذ ر ز ژ

س ش ص ض ط ظ ع غ ف ق ک

گ ل م ن و ه ی"

I would be so glad if you help me.
Thanks

"Titleize" letters

I want to 'Titleize' output letters. Either it should be another additional option, like a :titleize_letters, or do it by default? What do you think?

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.