{"action":"created","comment":{"url":"https://api.github.com/repos/dpla/primary-source-sets/pulls/comments/49531310","id":49531310,"diff_hunk":"@@ -34,14 +33,27 @@ def self.unpublished_sets\n   end\n \n   ##\n+  # Order SourceSets by a given parameter.\n+  # If a parameter is not included in the sort_params hash, it will be ignored.\n+  # By default, it will order by 'recently_added'.\n+  # @param order String or nil\n+  # @return ActiveRecord::Relation\n+  def self.order_by(order)\n+    sort_params = { 'recently_added' => { created_at: :desc },\n+                    'chronology_desc' => { year: :desc },\n+                    'chronology_asc' => { year: :asc } }\n+    order(sort_params[order] || sort_params['recently_added'])\n+  end\n+\n+  ##\n   # Get SourceSets associated with all of the specified tags.\n   # EACH returned SourceSet will have ALL of the tags.\n   # If no tags are specified, return all SourceSets.\n-  # @param tags [Array<String>]\n+  # @param tags [Array<String>] or nil\n   # @return [Array<SourceSet>]\n   def self.with_tags(tags)\n     return all unless tags.present?\n-    tags.map { |tag| with_tag(tag) }.inject(:&)\n+    tags.map { |tag| with_tag(tag) }.inject(:&).to_a","path":"app/models/source_set.rb","position":34,"original_position":34,"commit_id":"6a95bf2b811b8cafc396c73a817f265df674e7c4","original_commit_id":"6a95bf2b811b8cafc396c73a817f265df674e7c4","user":{"login":"AudreyAltman","id":3615206,"avatar_url":"https://avatars.githubusercontent.com/u/3615206?v=3","gravatar_id":"","url":"https://api.github.com/users/AudreyAltman","html_url":"https://github.com/AudreyAltman","followers_url":"https://api.github.com/users/AudreyAltman/followers","following_url":"https://api.github.com/users/AudreyAltman/following{/other_user}","gists_url":"https://api.github.com/users/AudreyAltman/gists{/gist_id}","starred_url":"https://api.github.com/users/AudreyAltman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AudreyAltman/subscriptions","organizations_url":"https://api.github.com/users/AudreyAltman/orgs","repos_url":"https://api.github.com/users/AudreyAltman/repos","events_url":"https://api.github.com/users/AudreyAltman/events{/privacy}","received_events_url":"https://api.github.com/users/AudreyAltman/received_events","type":"User","site_admin":false},"body":"This is just correcting a bug I found.  Without `to_a` the method may return either an `Array` or an `ActiveRecord::Relation`.  This way, it always returns an `Array`.","created_at":"2016-01-12T23:30:49Z","updated_at":"2016-01-12T23:30:49Z","html_url":"https://github.com/dpla/primary-source-sets/pull/101#discussion_r49531310","pull_request_url":"https://api.github.com/repos/dpla/primary-source-sets/pulls/101","_links":{"self":{"href":"https://api.github.com/repos/dpla/primary-source-sets/pulls/comments/49531310"},"html":{"href":"https://github.com/dpla/primary-source-sets/pull/101#discussion_r49531310"},"pull_request":{"href":"https://api.github.com/repos/dpla/primary-source-sets/pulls/101"}}},"pull_request":{"url":"https://api.github.com/repos/dpla/primary-source-sets/pulls/101","id":55833589,"html_url":"https://github.com/dpla/primary-source-sets/pull/101","diff_url":"https://github.com/dpla/primary-source-sets/pull/101.diff","patch_url":"https://github.com/dpla/primary-source-sets/pull/101.patch","issue_url":"https://api.github.com/repos/dpla/primary-source-sets/issues/101","number":101,"state":"open","locked":false,"title":"order sets by date created or year","user":{"login":"AudreyAltman","id":3615206,"avatar_url":"https://avatars.githubusercontent.com/u/3615206?v=3","gravatar_id":"","url":"https://api.github.com/users/AudreyAltman","html_url":"https://github.com/AudreyAltman","followers_url":"https://api.github.com/users/AudreyAltman/followers","following_url":"https://api.github.com/users/AudreyAltman/following{/other_user}","gists_url":"https://api.github.com/users/AudreyAltman/gists{/gist_id}","starred_url":"https://api.github.com/users/AudreyAltman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AudreyAltman/subscriptions","organizations_url":"https://api.github.com/users/AudreyAltman/orgs","repos_url":"https://api.github.com/users/AudreyAltman/repos","events_url":"https://api.github.com/users/AudreyAltman/events{/privacy}","received_events_url":"https://api.github.com/users/AudreyAltman/received_events","type":"User","site_admin":false},"body":"This introduces a feature that allows users to sort sets by `created_date` and `year` on the `sets#index` view.  \r\n\r\nThe sort option is included in the URI as an `order` param.  For example: `/sets?order=recently_added'`  The application recognizes three legitimate `order` params, `recently_added`, `chronology_asc`, and `chronology_desc`.  Any other `order` param is ignored.  If there is no legitimate `order` param, it defaults to `recently_added`.\r\n\r\nChanges include:\r\n\r\n* A method in the `SourceSet` model that parses the `order` param and adds sort options to a database query.\r\n\r\n* Updating the `source_sets#index` controller method.\r\n\r\n* Adding a dropdown menu to the view so users can select a sort option.\r\n\r\n* Unobtrusive JavaScript.  If JavaScript is disabled, a form submit button will appear.  If JavaScript is enabled, the form submit button will be hidden and the dropdown menu will auto-submit upon change.\r\n\r\nThis addresses [ticket #8205](https://issues.dp.la/issues/8205).","created_at":"2016-01-12T23:29:11Z","updated_at":"2016-01-12T23:30:49Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e69b18612fa0b42e08c707d61b46eba8baf61286","assignee":{"login":"markbreedlove","id":5550828,"avatar_url":"https://avatars.githubusercontent.com/u/5550828?v=3","gravatar_id":"","url":"https://api.github.com/users/markbreedlove","html_url":"https://github.com/markbreedlove","followers_url":"https://api.github.com/users/markbreedlove/followers","following_url":"https://api.github.com/users/markbreedlove/following{/other_user}","gists_url":"https://api.github.com/users/markbreedlove/gists{/gist_id}","starred_url":"https://api.github.com/users/markbreedlove/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/markbreedlove/subscriptions","organizations_url":"https://api.github.com/users/markbreedlove/orgs","repos_url":"https://api.github.com/users/markbreedlove/repos","events_url":"https://api.github.com/users/markbreedlove/events{/privacy}","received_events_url":"https://api.github.com/users/markbreedlove/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/dpla/primary-source-sets/pulls/101/commits","review_comments_url":"https://api.github.com/repos/dpla/primary-source-sets/pulls/101/comments","review_comment_url":"https://api.github.com/repos/dpla/primary-source-sets/pulls/comments{/number}","comments_url":"https://api.github.com/repos/dpla/primary-source-sets/issues/101/comments","statuses_url":"https://api.github.com/repos/dpla/primary-source-sets/statuses/6a95bf2b811b8cafc396c73a817f265df674e7c4","head":{"label":"dpla:feature/order-by","ref":"feature/order-by","sha":"6a95bf2b811b8cafc396c73a817f265df674e7c4","user":{"login":"dpla","id":1252916,"avatar_url":"https://avatars.githubusercontent.com/u/1252916?v=3","gravatar_id":"","url":"https://api.github.com/users/dpla","html_url":"https://github.com/dpla","followers_url":"https://api.github.com/users/dpla/followers","following_url":"https://api.github.com/users/dpla/following{/other_user}","gists_url":"https://api.github.com/users/dpla/gists{/gist_id}","starred_url":"https://api.github.com/users/dpla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dpla/subscriptions","organizations_url":"https://api.github.com/users/dpla/orgs","repos_url":"https://api.github.com/users/dpla/repos","events_url":"https://api.github.com/users/dpla/events{/privacy}","received_events_url":"https://api.github.com/users/dpla/received_events","type":"Organization","site_admin":false},"repo":{"id":41165715,"name":"primary-source-sets","full_name":"dpla/primary-source-sets","owner":{"login":"dpla","id":1252916,"avatar_url":"https://avatars.githubusercontent.com/u/1252916?v=3","gravatar_id":"","url":"https://api.github.com/users/dpla","html_url":"https://github.com/dpla","followers_url":"https://api.github.com/users/dpla/followers","following_url":"https://api.github.com/users/dpla/following{/other_user}","gists_url":"https://api.github.com/users/dpla/gists{/gist_id}","starred_url":"https://api.github.com/users/dpla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dpla/subscriptions","organizations_url":"https://api.github.com/users/dpla/orgs","repos_url":"https://api.github.com/users/dpla/repos","events_url":"https://api.github.com/users/dpla/events{/privacy}","received_events_url":"https://api.github.com/users/dpla/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/dpla/primary-source-sets","description":"App for managing sets of educational resources","fork":false,"url":"https://api.github.com/repos/dpla/primary-source-sets","forks_url":"https://api.github.com/repos/dpla/primary-source-sets/forks","keys_url":"https://api.github.com/repos/dpla/primary-source-sets/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dpla/primary-source-sets/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dpla/primary-source-sets/teams","hooks_url":"https://api.github.com/repos/dpla/primary-source-sets/hooks","issue_events_url":"https://api.github.com/repos/dpla/primary-source-sets/issues/events{/number}","events_url":"https://api.github.com/repos/dpla/primary-source-sets/events","assignees_url":"https://api.github.com/repos/dpla/primary-source-sets/assignees{/user}","branches_url":"https://api.github.com/repos/dpla/primary-source-sets/branches{/branch}","tags_url":"https://api.github.com/repos/dpla/primary-source-sets/tags","blobs_url":"https://api.github.com/repos/dpla/primary-source-sets/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dpla/primary-source-sets/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dpla/primary-source-sets/git/refs{/sha}","trees_url":"https://api.github.com/repos/dpla/primary-source-sets/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dpla/primary-source-sets/statuses/{sha}","languages_url":"https://api.github.com/repos/dpla/primary-source-sets/languages","stargazers_url":"https://api.github.com/repos/dpla/primary-source-sets/stargazers","contributors_url":"https://api.github.com/repos/dpla/primary-source-sets/contributors","subscribers_url":"https://api.github.com/repos/dpla/primary-source-sets/subscribers","subscription_url":"https://api.github.com/repos/dpla/primary-source-sets/subscription","commits_url":"https://api.github.com/repos/dpla/primary-source-sets/commits{/sha}","git_commits_url":"https://api.github.com/repos/dpla/primary-source-sets/git/commits{/sha}","comments_url":"https://api.github.com/repos/dpla/primary-source-sets/comments{/number}","issue_comment_url":"https://api.github.com/repos/dpla/primary-source-sets/issues/comments{/number}","contents_url":"https://api.github.com/repos/dpla/primary-source-sets/contents/{+path}","compare_url":"https://api.github.com/repos/dpla/primary-source-sets/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dpla/primary-source-sets/merges","archive_url":"https://api.github.com/repos/dpla/primary-source-sets/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dpla/primary-source-sets/downloads","issues_url":"https://api.github.com/repos/dpla/primary-source-sets/issues{/number}","pulls_url":"https://api.github.com/repos/dpla/primary-source-sets/pulls{/number}","milestones_url":"https://api.github.com/repos/dpla/primary-source-sets/milestones{/number}","notifications_url":"https://api.github.com/repos/dpla/primary-source-sets/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dpla/primary-source-sets/labels{/name}","releases_url":"https://api.github.com/repos/dpla/primary-source-sets/releases{/id}","created_at":"2015-08-21T16:21:41Z","updated_at":"2016-01-11T16:14:41Z","pushed_at":"2016-01-12T23:29:11Z","git_url":"git://github.com/dpla/primary-source-sets.git","ssh_url":"git@github.com:dpla/primary-source-sets.git","clone_url":"https://github.com/dpla/primary-source-sets.git","svn_url":"https://github.com/dpla/primary-source-sets","homepage":"http://dp.la/primary-source-sets","size":649,"stargazers_count":1,"watchers_count":1,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":6,"forks":0,"open_issues":6,"watchers":1,"default_branch":"develop"}},"base":{"label":"dpla:develop","ref":"develop","sha":"2d7afe814e720b503986b8a6a43590e2749f9e30","user":{"login":"dpla","id":1252916,"avatar_url":"https://avatars.githubusercontent.com/u/1252916?v=3","gravatar_id":"","url":"https://api.github.com/users/dpla","html_url":"https://github.com/dpla","followers_url":"https://api.github.com/users/dpla/followers","following_url":"https://api.github.com/users/dpla/following{/other_user}","gists_url":"https://api.github.com/users/dpla/gists{/gist_id}","starred_url":"https://api.github.com/users/dpla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dpla/subscriptions","organizations_url":"https://api.github.com/users/dpla/orgs","repos_url":"https://api.github.com/users/dpla/repos","events_url":"https://api.github.com/users/dpla/events{/privacy}","received_events_url":"https://api.github.com/users/dpla/received_events","type":"Organization","site_admin":false},"repo":{"id":41165715,"name":"primary-source-sets","full_name":"dpla/primary-source-sets","owner":{"login":"dpla","id":1252916,"avatar_url":"https://avatars.githubusercontent.com/u/1252916?v=3","gravatar_id":"","url":"https://api.github.com/users/dpla","html_url":"https://github.com/dpla","followers_url":"https://api.github.com/users/dpla/followers","following_url":"https://api.github.com/users/dpla/following{/other_user}","gists_url":"https://api.github.com/users/dpla/gists{/gist_id}","starred_url":"https://api.github.com/users/dpla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dpla/subscriptions","organizations_url":"https://api.github.com/users/dpla/orgs","repos_url":"https://api.github.com/users/dpla/repos","events_url":"https://api.github.com/users/dpla/events{/privacy}","received_events_url":"https://api.github.com/users/dpla/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/dpla/primary-source-sets","description":"App for managing sets of educational resources","fork":false,"url":"https://api.github.com/repos/dpla/primary-source-sets","forks_url":"https://api.github.com/repos/dpla/primary-source-sets/forks","keys_url":"https://api.github.com/repos/dpla/primary-source-sets/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dpla/primary-source-sets/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dpla/primary-source-sets/teams","hooks_url":"https://api.github.com/repos/dpla/primary-source-sets/hooks","issue_events_url":"https://api.github.com/repos/dpla/primary-source-sets/issues/events{/number}","events_url":"https://api.github.com/repos/dpla/primary-source-sets/events","assignees_url":"https://api.github.com/repos/dpla/primary-source-sets/assignees{/user}","branches_url":"https://api.github.com/repos/dpla/primary-source-sets/branches{/branch}","tags_url":"https://api.github.com/repos/dpla/primary-source-sets/tags","blobs_url":"https://api.github.com/repos/dpla/primary-source-sets/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dpla/primary-source-sets/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dpla/primary-source-sets/git/refs{/sha}","trees_url":"https://api.github.com/repos/dpla/primary-source-sets/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dpla/primary-source-sets/statuses/{sha}","languages_url":"https://api.github.com/repos/dpla/primary-source-sets/languages","stargazers_url":"https://api.github.com/repos/dpla/primary-source-sets/stargazers","contributors_url":"https://api.github.com/repos/dpla/primary-source-sets/contributors","subscribers_url":"https://api.github.com/repos/dpla/primary-source-sets/subscribers","subscription_url":"https://api.github.com/repos/dpla/primary-source-sets/subscription","commits_url":"https://api.github.com/repos/dpla/primary-source-sets/commits{/sha}","git_commits_url":"https://api.github.com/repos/dpla/primary-source-sets/git/commits{/sha}","comments_url":"https://api.github.com/repos/dpla/primary-source-sets/comments{/number}","issue_comment_url":"https://api.github.com/repos/dpla/primary-source-sets/issues/comments{/number}","contents_url":"https://api.github.com/repos/dpla/primary-source-sets/contents/{+path}","compare_url":"https://api.github.com/repos/dpla/primary-source-sets/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dpla/primary-source-sets/merges","archive_url":"https://api.github.com/repos/dpla/primary-source-sets/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dpla/primary-source-sets/downloads","issues_url":"https://api.github.com/repos/dpla/primary-source-sets/issues{/number}","pulls_url":"https://api.github.com/repos/dpla/primary-source-sets/pulls{/number}","milestones_url":"https://api.github.com/repos/dpla/primary-source-sets/milestones{/number}","notifications_url":"https://api.github.com/repos/dpla/primary-source-sets/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dpla/primary-source-sets/labels{/name}","releases_url":"https://api.github.com/repos/dpla/primary-source-sets/releases{/id}","created_at":"2015-08-21T16:21:41Z","updated_at":"2016-01-11T16:14:41Z","pushed_at":"2016-01-12T23:29:11Z","git_url":"git://github.com/dpla/primary-source-sets.git","ssh_url":"git@github.com:dpla/primary-source-sets.git","clone_url":"https://github.com/dpla/primary-source-sets.git","svn_url":"https://github.com/dpla/primary-source-sets","homepage":"http://dp.la/primary-source-sets","size":649,"stargazers_count":1,"watchers_count":1,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":6,"forks":0,"open_issues":6,"watchers":1,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/dpla/primary-source-sets/pulls/101"},"html":{"href":"https://github.com/dpla/primary-source-sets/pull/101"},"issue":{"href":"https://api.github.com/repos/dpla/primary-source-sets/issues/101"},"comments":{"href":"https://api.github.com/repos/dpla/primary-source-sets/issues/101/comments"},"review_comments":{"href":"https://api.github.com/repos/dpla/primary-source-sets/pulls/101/comments"},"review_comment":{"href":"https://api.github.com/repos/dpla/primary-source-sets/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/dpla/primary-source-sets/pulls/101/commits"},"statuses":{"href":"https://api.github.com/repos/dpla/primary-source-sets/statuses/6a95bf2b811b8cafc396c73a817f265df674e7c4"}}}}