Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 49 lines (42 sloc) 1.362 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
(ns foreclojure.users
  (:use [foreclojure utils config]
        somnium.congomongo
        compojure.core
        [hiccup.page-helpers :only (link-to)]))

(def golfer-tags (into [:contributor]
                       (when (:golfing-active config)
                         [:golfer])))

(defn get-user-id [name]
  (:_id
   (fetch-one :users
              :where {:user name}
              :only [:_id])))

(defn get-users []
  (let [users (from-mongo
               (fetch :users
                      :only [:user :solved :contributor]))
        sortfn (comp count :solved)]
    (reverse (sort-by sortfn users))))

(defn golfer? [user]
  (some user golfer-tags))

(def-page users-page []
  [:div
   [:span.contributor "*"] " "
   (link-to "https://github.com/dbyrne/4clojure" "4clojure contributor")]
  [:br]
  [:table#user-table.my-table
   [:thead
    [:tr
     [:th {:style "width: 40px;"} "Rank"]
     [:th "Username"]
     [:th "Problems Solved"]]]
   (map-indexed #(vec [:tr (row-class %1)
                       [:td (inc %1)]
                       [:td
                        (when (:contributor %2)
                          [:span.contributor "* "])
                        (:user %2)]
                       [:td {:class "centered"} (count (:solved %2))]])
                (get-users))])

(defroutes users-routes
  (GET "/users" [] (users-page)))
Something went wrong with that request. Please try again.