Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

AO3-4987 Add POST pagination support for admin email bulk search #3175

Open
wants to merge 5 commits into
from

Conversation

Projects
None yet
4 participants
Contributor

hatal175 commented Nov 20, 2017

Issue

https://otwarchive.atlassian.net/browse/AO3-4987

Purpose

I've changed the form method of the bulk email search to get instead of post. The paginate works now. I would like a code review on that though. Not entirely sure why it was post in the first place - they went to the same function anyway.

Testing

Recreation steps in the bug report.

Credit

Tal Hayon

Please use he.

I happen to be working on a different issue on this page so I added in your changes and I can confirm that they work - the pagination works correctly and the list of emails isn't removed. 👍

Hmm, actually, I was a bit too quick to cry victory. It has come back to me why I had to make this a POST action in the first place. The reason I added this bulk search was to enable Open Doors to search all the emails addresses for an import; this means at least hundreds, if not thousands of email addresses. A GET request can't handle that many as the URI becomes too large for the server and/or the browser, so this will need a different approach.

I'll consult with the committee but we'll probably have to close this, apndmaybe give up on paginating the results on the same page, unless you can think of a solution that can both accommodate a large number of email addresses and preserve pagination?

Contributor

hatal175 commented Nov 20, 2017

app/helpers/post_pagination_helper.rb
@@ -0,0 +1,11 @@
+module PostPaginationHelper
@houndci-bot

houndci-bot Nov 22, 2017

Missing magic comment # frozen_string_literal: true.

app/renderers/post_link_renderer.rb
@@ -0,0 +1,33 @@
+class PostLinkRenderer < WillPaginate::ActionView::LinkRenderer
@houndci-bot

houndci-bot Nov 22, 2017

Missing magic comment # frozen_string_literal: true.

app/renderers/post_link_renderer.rb
+class PostLinkRenderer < WillPaginate::ActionView::LinkRenderer
+ def previous_or_next_page(page, text, classname)
+ if page
+ submit(text, page,classname,:class => classname)
@houndci-bot

houndci-bot Nov 22, 2017

Space missing after comma.
Use the new Ruby 1.9 hash syntax.

app/renderers/post_link_renderer.rb
+ if page
+ submit(text, page,classname,:class => classname)
+ else
+ tag(:span, text, :class => classname + ' disabled')
@houndci-bot

houndci-bot Nov 22, 2017

Use the new Ruby 1.9 hash syntax.

app/renderers/post_link_renderer.rb
+
+ def page_number(page)
+ if page == current_page
+ tag(:em, page, :class => 'current')
@houndci-bot

houndci-bot Nov 22, 2017

Use the new Ruby 1.9 hash syntax.

app/renderers/post_link_renderer.rb
+ if page == current_page
+ tag(:em, page, :class => 'current')
+ else
+ submit(page, page,nil,:rel => rel_value(page))
@houndci-bot

houndci-bot Nov 22, 2017

Space missing after comma.
Use the new Ruby 1.9 hash syntax.

app/renderers/post_link_renderer.rb
+ def submit(text, target, target_name, attributes = {})
+ string_attributes = attributes.inject('') do |attrs, pair|
+ unless pair.last.nil?
+ attrs << %( #{pair.first}="#{CGI::escapeHTML(pair.last.to_s)}")
@houndci-bot

houndci-bot Nov 22, 2017

Do not use :: for method calls.

app/renderers/post_link_renderer.rb
+ %(<input#{string_attributes} type="submit" name="page" value="#{text}">)
+ else
+ %(<input type="hidden" name="#{target_name}_value" value="#{target}">) +
+ %(<input#{string_attributes} type="submit" name="#{target_name}" value="#{text}">)
@houndci-bot

houndci-bot Nov 22, 2017

Use 2 (not 4) spaces for indenting an expression spanning multiple lines.

app/renderers/post_link_renderer.rb
+class PostLinkRenderer < WillPaginate::ActionView::LinkRenderer
+ def previous_or_next_page(page, text, classname)
+ if page
+ submit(text, page, classname,class: classname)
@houndci-bot

houndci-bot Nov 22, 2017

Space missing after comma.

app/renderers/post_link_renderer.rb
+ end
+
+ def submit(text, target, target_name, attributes = {})
+ string_attributes = attributes.inject(''.dup) do |attrs, pair|
@houndci-bot

houndci-bot Nov 22, 2017

Use unary plus to get an unfrozen string literal.

app/renderers/post_link_renderer.rb
+class PostLinkRenderer < WillPaginate::ActionView::LinkRenderer
+ def previous_or_next_page(page, text, classname)
+ if page
+ submit(text, page, classname,class: classname)
@houndci-bot

houndci-bot Nov 22, 2017

Space missing after comma.

app/renderers/post_link_renderer.rb
+ end
+
+ def submit(text, target, target_name, attributes = {})
+ string_attributes = attributes.inject(''.dup) do |attrs, pair|
@houndci-bot

houndci-bot Nov 22, 2017

Use unary plus to get an unfrozen string literal.

Contributor

hatal175 commented Nov 22, 2017

I think I managed to create a decently designed post paginator. Mind taking a look?

Contributor

ariana-paris commented Nov 25, 2017

I patched up my local Archive installation and I can confirm that your link renderer works correctly and allows the form to handle hundreds of emails while also correctly paginating the results. \o/

Just one thing, we already have a will_paginate renderer called PaginationListLinkRenderer, which lives in lib and is hooked in by a will_paginate() override in ApplicationHelper. It makes some changes to how the links are rendered and it would be nice if the new POST pagination was the same (I think the main visual difference was just the current page link being in an em in your code, and a span in the one currently in use)

Also, I think it would make sense for both renderers to live in the same folder distinct from lib, so if you could also move the existing one to join yours in app/renderers, that would be great! (we're still bogged down in putting out fires, so there's time before this will be merged)

app/renderers/post_link_renderer.rb
+ if page
+ submit(text, page, classname, class: classname)
+ else
+ tag(:span, text, class: classname + ' disabled')
@ariana-paris

ariana-paris Nov 25, 2017

Contributor

Can you use double quotes throughout as that is our standard?

app/renderers/post_link_renderer.rb
+
+ def page_number(page)
+ if page == current_page
+ tag(:em, page, class: 'current')
@ariana-paris

ariana-paris Nov 25, 2017

Contributor

This is one of the differences with our current PaginationListLinkRenderer: the existing one renders spans instead of ems, so it would be nice if this one did too so that the post pagination looks the same as the pagination we have elsewhere on the site (but maybe have a look at our existing renderer and see if there are any other differences too)

@ariana-paris ariana-paris changed the title from AO3-4987 Switch admin email bulk search to get so paginate will work to AO3-4987 Add POST pagination support for admin email bulk search Nov 25, 2017

AO3-4987 Code review fixes
* Moved post pagination files into lib

* Based link renderer on existing ao3 renderer
+ end
+
+ def page_number(page, remote = nil)
+ unless page == current_page
@houndci-bot

houndci-bot Nov 25, 2017

Do not use unless with else. Rewrite these with the positive case first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment