-
Notifications
You must be signed in to change notification settings - Fork 257
Issue894: Marks spreadsheet: sort by User Name, Last Name, First Name, Section. #928
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
bf0833d
sorting functionality for username, firstname, lastname, and section …
kiramccoan a995bdc
adding sort_by cookie for grades
kiramccoan 9622074
asc/desc works over pagination
kiramccoan d81cd2e
sorting works with per page drop down
kiramccoan d74c733
Jump to works only as for last name, so dont display it for other sor…
kiramccoan 58e6051
Fix indentation, and push ordering into get_filtered_items method
kiramccoan 074f407
limit sorting to tas and admins
kiramccoan 1c064ca
only display section for tas and admins
kiramccoan 9fa9447
adding functional test for cookies in grade forms controller
kiramccoan d32b73e
Push sort and order into query. Fix line characters to 80
kiramccoan c013306
strip out uncessary fields in pagination helper
kiramccoan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| require 'will_paginate' | ||
|
|
||
| =begin How to Use the Grades Entry Form Pagination Helper | ||
| hash requires: | ||
| :model * the type of data that needs pagination | ||
| :per_pages * an array of integers, each integer representing | ||
| a selection of pagination size for the user | ||
| :filters * a list of possible filters that can be applied | ||
| to the data of type :model | ||
| a name for each filter | ||
| :display * the text the user sees | ||
| :proc => lambda * the processing done to each instance of the :model | ||
| :sorts | ||
| for each sort | ||
| "name" * the string that will appear in the URL of a GET | ||
| or AJAX request | ||
| => lambda * the lambda expression that handles the sorting | ||
| =end | ||
| module GradeEntryFormsPaginationHelper | ||
| # For the hash that's passed to handle_ap_event, these are the required | ||
| # fields. | ||
| AP_REQUIRED_KEYS = [:model, :filters] | ||
| AP_DEFAULT_PER_PAGE = 30 | ||
| AP_DEFAULT_PAGE = 1 | ||
|
|
||
| def handle_paginate_event(hash, object_hash, params) | ||
| # First, let's make sure we have the required fields. | ||
| # I'll take the keys from the hash, and difference it from | ||
| # the AP_REQUIRED_FIELDS. If there are any symbols left over | ||
| # in the difference, the hash wasn't complete, and we should bail out. | ||
| if (AP_REQUIRED_KEYS - hash.keys).size > 0 | ||
| # Fail loud, fail proud | ||
| raise "handle_paginate_event received an incomplete parameter hash" | ||
| end | ||
| # Ok, we have everything we need, let's get to work | ||
| filter = params[:filter] | ||
| desc = params[:desc] | ||
| sorts = hash[:sorts] | ||
| filters = hash[:filters] | ||
| if(!filters.include?(filter)) | ||
| raise "Could not find filter #{filter}" | ||
| end | ||
| items = get_filtered_items(hash, filter, params[:sort_by], desc) | ||
| if params[:per_page].blank? | ||
| params[:per_page] = AP_DEFAULT_PER_PAGE | ||
| end | ||
| if params[:page].blank? | ||
| params[:page] = AP_DEFAULT_PAGE | ||
| end | ||
|
|
||
| return items.paginate(:per_page => params[:per_page], :page => params[:page]).clone, items.size | ||
|
|
||
| end | ||
|
|
||
| def get_filters(params) | ||
| result = {} | ||
| params[:filters].each do |filter_key, filter| | ||
| result[filter[:display]] = filter_key | ||
| end | ||
| return result | ||
| end | ||
|
|
||
| def get_filtered_items(hash, filter, sort_by, desc) | ||
| if !desc.blank? | ||
| order = "DESC" | ||
| else | ||
| order = "ASC" | ||
| end | ||
|
|
||
| items = hash[:filters][filter][:proc].call(sort_by, order) | ||
|
|
||
| return items | ||
| end | ||
|
|
||
| end | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better to retrieve items in the right order in the first place. This retrieves items and later reverses the list if desc is not blank. I.e. does things twice where once is more than enough.