Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add filtering and disable all links for non-javascript users

  • Loading branch information...
commit 5c257076a22ecf69bfbbf3b4c684613958ecfb9e 1 parent c573972
@gigasquid gigasquid authored
View
7 resources/public/css/style.css
@@ -238,6 +238,13 @@ img.gravatar{
padding: 15px;
}
+#server-user-table{
+ float: left;
+ width: 100%;
+ padding: 15px;
+}
+
+
/*
* By default only show the text label for the "Following" column on
* the users page. If they have javascript turned on (detected
View
2  resources/public/script/foreclojure.js
@@ -39,6 +39,8 @@ $(document).ready(function() {
return false;
});
+ $("#all-users-link").html("[show <a href=\"/users/all\">all</a>]");
+
$("#user-table").addClass("js-enabled");
$("#user-table input.following").live("click", function(e) {
View
22 src/foreclojure/users.clj
@@ -162,7 +162,7 @@
:content
(content-page
{:heading "Top 100 Users"
- :heading-note (list "[show " (link-to "/users/all" "all") "]")
+ :heading-note [:span#all-users-link]
:sub-heading (list (format-user-ranking user-ranking)
[:span.contributor "*"] "&nbsp;"
(link-to repo-url "4clojure contributor"))
@@ -280,29 +280,35 @@
(defn datatable-sort [users sort-col sort-dir]
(-> users (datatable-sort-cols sort-col) (datatable-sort-dir sort-dir)))
+(defn datatable-filter [users str]
+ (if str
+ (filter #(< -1 (.indexOf (if (:user %) (:user %) "") str)) users)
+ users))
+
(defn datatable-process [users params]
(let [display-start (Integer. (params :iDisplayStart))
display-length (Integer. (params :iDisplayLength))
sort-col (Integer. (params :iSortCol_0))
- sort-dir (params :sSortDir_0)]
+ sort-dir (params :sSortDir_0)
+ search-str (params :sSearch)]
(-> users
(datatable-sort sort-col sort-dir)
- (datatable-paging display-start display-length))))
+ (datatable-paging display-start display-length)
+ generate-datatable-users-list)))
(defn user-datatable-query [params]
(let [
ranked-users (get-ranked-users)
+ search-str (params :sSearch)
+ filtered-users (datatable-filter ranked-users search-str)
page-users (datatable-process
- (generate-datatable-users-list ranked-users)
+ filtered-users
params)]
- (println params)
- (println page-users)
{:sEcho (params :sEcho)
:iTotalRecords (str (count ranked-users))
- :iTotalDisplayRecords (str (count ranked-users))
+ :iTotalDisplayRecords (str (count filtered-users))
:aaData page-users}))
-
(defroutes users-routes
(GET "/users" [] (top-users-page))
(GET "/users/all" [] (all-users-page))
View
5 test/foreclojure/test/users.clj
@@ -41,3 +41,8 @@
(:user (first (datatable-sort users 1 "asc"))) => "user1"
(:user (first (datatable-sort users 1 "desc"))) => "user9"))
+(deftest user-datatables-filter
+ (facts "about filtering the username by text"
+ (:user (first (datatable-filter users "4"))) => "user4"
+ (:user (second (datatable-filter users "1"))) => "user10"
+ (count (datatable-filter users nil)) => 10))
Please sign in to comment.
Something went wrong with that request. Please try again.