lingz / alphabetical_paginate Goto Github PK
View Code? Open in Web Editor NEWAn Alphabetical Pagination gem for Ruby on Rails
License: MIT License
An Alphabetical Pagination gem for Ruby on Rails
License: MIT License
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?
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!
When the bootstrap 3 flag is used, a <ul>
tag is opened but never gets closed:
I think line 59 should read:
(params[:bootstrap3] ? "</ul>" : "</div>")
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
Several pull requests have been merged recently in master
but the published gem is still pointing to a pretty old version.
master
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.
$(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();
});
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();
});
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:
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:
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:
HTML 404
as the script should really be compiled with the othersThis leads to this kind of behaviour:
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.
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.
Currently for all instances the same ID is used: this limit the use of the pagination tool to one per page.
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 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?
Hello, is there way to make pagination with 'Av' or 'Ava' ?
I want to set count of letters to 2, or 3, depending on count rows in db
Can I use pluck with this gem?
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...
Haven't checked in non-db yet. I might fix it later, but if someone wants to fix it now, go ahead
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?
Is suspect a bug here:
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?)
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
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>
?
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
Please can you add support for Bootstrap 3?
Bootstrap 3 dispenses with the styling using div and applies it directly to the ul tag.
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
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?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.