Permalink
Browse files

Merge pull request #228 from nbeloglazov/following-sort

Fix filtering for following column on all-users page. Issue #202.
  • Loading branch information...
2 parents 7805acc + ec8cc3b commit 90633853946e4dec6228189a5e6e2086bfa76ce2 @amalloy amalloy committed Sep 4, 2012
Showing with 12 additions and 3 deletions.
  1. +1 −1 resources/public/script/foreclojure.js
  2. +11 −2 src/foreclojure/users.clj
@@ -166,7 +166,7 @@ function configureDataTables(){
null,
null,
null,
- {"bSortable": false}
+ null
],
"iDisplayLength":100,
"bProcessing": true,
View
@@ -249,8 +249,17 @@
(defn datatable-paging [start length users]
(take length (drop start users)))
-(let [column-sorts [:rank :user (comp count :solved)]]
- (defn datatable-sort-cols [sort-col users]
+(defn sort-by-following
+ "Get function for sorting by following for current user.
+ We need nullary function to create sort function because 'following' set depends on current user."
+ []
+ (let [following (if-user [{:keys [following]}]
+ (set following))]
+ (fn [user]
+ (if (contains? following (:_id user)) -1 1))))
+
+(defn datatable-sort-cols [sort-col users]
+ (let [column-sorts [:rank :user (comp count :solved) (sort-by-following)]]
(if-let [sort-fn (get column-sorts sort-col)]
(sort-by sort-fn users)
users)))

0 comments on commit 9063385

Please sign in to comment.