Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix filtering for following column on all-users page. Issue #202. #228

Merged
merged 2 commits into from

2 participants

@nbeloglazov

No description provided.

src/foreclojure/users.clj
@@ -249,8 +249,13 @@
(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 get-sort-by-following-fn []
+ (let [following (if-user [{:keys [following]}]
+ (set following))]
@amalloy Owner
amalloy added a note

Indentation under if-user is wrong here. Should line up like an if.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
src/foreclojure/users.clj
@@ -249,8 +249,13 @@
(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 get-sort-by-following-fn []
+ (let [following (if-user [{:keys [following]}]
+ (set following))]
+ #(if (following (:_id %)) -1 1)))
@amalloy Owner
amalloy added a note

I don't really like the lambda syntax here. I think it reads better as a fn form so that the param (and optionally the function itself) can get a descriptive name to clarify what's going on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
src/foreclojure/users.clj
@@ -249,8 +249,13 @@
(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 get-sort-by-following-fn []
@amalloy Owner
amalloy added a note

I think I'd just name this sort-by-following. And please add a comment explaining why this thing that "looks" like a constant needs to be a nullary function - it depends on the mutable state for if-user.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@amalloy amalloy merged commit 9063385 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
2  resources/public/script/foreclojure.js
@@ -166,7 +166,7 @@ function configureDataTables(){
null,
null,
null,
- {"bSortable": false}
+ null
],
"iDisplayLength":100,
"bProcessing": true,
View
13 src/foreclojure/users.clj
@@ -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)))
Something went wrong with that request. Please try again.