Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleaned up the gravatar appearance on the profile and users pages. #142

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion resources/public/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,22 @@ a.novisited {color: #00e;}
color: black;
}

td a.user-profile-link {
display: block;
margin-top: 5px;
}

.user-profile-img{
float: left;
padding-right: 10px;
}

img.gravatar{
float: left;
display: inline;
margin-right: 5px;
}

#user-info{
float:right;
}
Expand Down Expand Up @@ -217,7 +233,6 @@ a.novisited {color: #00e;}
padding: 15px;
}


/*
* By default only show the text label for the "Following" column on
* the users page. If they have javascript turned on (detected
Expand Down Expand Up @@ -391,6 +406,7 @@ table.my-table {
table.my-table td {
text-align: left;
font-size: 12px;
vertical-align: middle;
}

tr.evenrow {
Expand Down
39 changes: 25 additions & 14 deletions resources/public/script/foreclojure.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,31 @@ $(document).ready(function() {
});
});

var difficulty = new Array();
difficulty["Elementary"] = 0;
difficulty["Easy"] = 1;
difficulty["Medium"] = 2;
difficulty["Hard"] = 3;
difficulty[""] = 4;

jQuery.fn.dataTableExt.oSort['difficulty-asc'] = function(a, b) {
return difficulty[a] - difficulty[b];
var difficulty = {
"Elementary": 0,
"Easy": 1,
"Medium": 2,
"Hard": 3,
"": 4
};

jQuery.fn.dataTableExt.oSort['difficulty-desc'] = function(a, b) {
return difficulty[b] - difficulty[a];
};
jQuery.fn.dataTableExt.afnSortData['difficulty'] = function(oSettings, iColumn)
{
var aData = [];
$('td:eq('+iColumn+')', oSettings.oApi._fnGetTrNodes(oSettings)).each(function () {
aData.push(difficulty[$(this).text()]);
});
return aData;
}

jQuery.fn.dataTableExt.afnSortData['user-name'] = function(oSettings, iColumn)
{
var aData = [];
$('td:eq('+iColumn+') a.user-profile-link', oSettings.oApi._fnGetTrNodes(oSettings)).each(function () {
aData.push($(this).text());
});
return aData;
}

function configureDataTables(){

Expand All @@ -81,7 +92,7 @@ function configureDataTables(){
"aaSorting": [[5, "desc"], [1, "asc"], [4, "desc"]],
"aoColumns": [
{"sType": "string"},
{"sType": "difficulty"},
{"sSortDataType": "difficulty", "sType": "numeric"},
{"sType": "string"},
{"sType": "string"},
{"sType": "numeric"},
Expand All @@ -105,7 +116,7 @@ function configureDataTables(){
"aaSorting": [[0, "asc"]],
"aoColumns": [
{"sType": "numeric"},
{"sType": "string"},
{"sSortDataType": "user-name"},
{"sType": "numeric"},
{"sType": "string"}
]
Expand Down
4 changes: 2 additions & 2 deletions src/foreclojure/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
[foreclojure.version :only [version-routes]]
[foreclojure.graphs :only [graph-routes]]
[foreclojure.mongo :only [prepare-mongo]]
[foreclojure.utils :only [wrap-uri-binding]]
[foreclojure.ring-utils :only [wrap-request-bindings]]
[foreclojure.periodic :only [schedule-task]]
[ring.adapter.jetty :only [run-jetty]]
[ring.middleware.reload :only [wrap-reload]]
Expand Down Expand Up @@ -47,7 +47,7 @@
#(wrap-reload % '(foreclojure.core))
identity))
session/wrap-stateful-session
wrap-uri-binding
wrap-request-bindings
handler/site
wrap-strip-trailing-slash))

Expand Down
3 changes: 2 additions & 1 deletion src/foreclojure/problems.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
[clojure.string :as s]
[ring.util.response :as response])
(:import [org.apache.commons.mail EmailException])
(:use [foreclojure.utils :only [from-mongo get-user get-solved login-link *url* flash-msg flash-error row-class approver? can-submit? send-email image-builder with-user as-int maybe-update escape-html]]
(:use [foreclojure.utils :only [from-mongo get-user get-solved login-link flash-msg flash-error row-class approver? can-submit? send-email image-builder with-user as-int maybe-update escape-html]]
[foreclojure.ring-utils :only [*url*]]
[foreclojure.template :only [def-page content-page]]
[foreclojure.social :only [tweet-link gist!]]
[foreclojure.feeds :only [create-feed]]
Expand Down
19 changes: 10 additions & 9 deletions src/foreclojure/ring.clj
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
(ns foreclojure.ring
(:require [clojure.java.io :as io]
[clojure.string :as s]
[compojure.route :as route])
(:import [java.net URL])
(:use [compojure.core :only [GET]]
[foreclojure.utils :only [strip-version-number]]
[useful.debug :only [?]]
[ring.util.response :only [response]]))
(:require [clojure.java.io :as io]
[clojure.string :as s]
[compojure.route :as route])
(:import [java.net URL])
(:use [compojure.core :only [GET]]
[foreclojure.version-utils :only [strip-version-number]]
[foreclojure.ring-utils :only [get-host]]
[useful.debug :only [?]]
[ring.util.response :only [response]]))

;; copied from compojure.route, modified to use File instead of Stream
(defn resources
Expand Down Expand Up @@ -45,7 +46,7 @@
(defn split-hosts [host-handlers]
(let [default (:default host-handlers)]
(fn [request]
(let [host (get-in request [:headers "host"])
(let [host (get-host request)
handler (or (host-handlers host) default)]
(handler request)))))

Expand Down
20 changes: 20 additions & 0 deletions src/foreclojure/ring_utils.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
(ns foreclojure.ring-utils
(:require [foreclojure.config :as config]))

(def ^:dynamic *url* nil) ; url of current request
(def ^:dynamic *host* nil) ; Host header sent by client
(def ^:dynamic *http-scheme* nil) ; keyword, :http or :https

(defn get-host [request]
(get-in request [:headers "host"]))

(defn wrap-request-bindings [handler]
(fn [req]
(binding [*url* (:uri req)
*host* (or (get-host req) "www.4clojure.com")
*http-scheme* (:scheme req)]
(handler req))))

(def static-url (if-let [host config/static-host]
#(str (name *http-scheme*) "://" host "/" %)
#(str "/" %)))
10 changes: 5 additions & 5 deletions src/foreclojure/static.clj
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
(ns foreclojure.static
(:use [compojure.core :only [defroutes GET]]
[foreclojure.problems :only [solved-stats]]
[foreclojure.config :only [repo-url]]
[foreclojure.utils :only [static-url]]
[foreclojure.template :only [def-page]]))
(:use [compojure.core :only [defroutes GET]]
[foreclojure.problems :only [solved-stats]]
[foreclojure.config :only [repo-url]]
[foreclojure.ring-utils :only [static-url]]
[foreclojure.template :only [def-page]]))

(def df
(let [df (java.text.DecimalFormat.)
Expand Down
12 changes: 7 additions & 5 deletions src/foreclojure/template.clj
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
(ns foreclojure.template
(:require [sandbar.stateful-session :as session])
(:use [hiccup.core :only [html]]
[hiccup.page-helpers :only [doctype javascript-tag link-to]]
[foreclojure.config :only [config repo-url]]
[foreclojure.utils :only [css js page-attributes rendering-info login-url approver? can-submit? static-url]]))
(:require [sandbar.stateful-session :as session])
(:use [hiccup.core :only [html]]
[hiccup.page-helpers :only [doctype javascript-tag link-to]]
[foreclojure.config :only [config repo-url]]
[foreclojure.utils :only [page-attributes rendering-info login-url approver? can-submit?]]
[foreclojure.ring-utils :only [static-url]]
[foreclojure.version-utils :only [css js]]))

;; Global wrapping template
(defn html-doc [body]
Expand Down
28 changes: 22 additions & 6 deletions src/foreclojure/users.clj
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
(ns foreclojure.users
(:require [ring.util.response :as response]
[clojure.string :as string]
[sandbar.stateful-session :as session])
(:use [foreclojure.utils :only [from-mongo row-class rank-class get-user with-user]]
[foreclojure.template :only [def-page content-page]]
[foreclojure.ring-utils :only [*http-scheme*]]
[foreclojure.config :only [config repo-url]]
[somnium.congomongo :only [fetch-one fetch update!]]
[compojure.core :only [defroutes GET POST]]
[hiccup.form-helpers :only [form-to hidden-field]]
[hiccup.page-helpers :only [link-to]]
[clojure.contrib.json :only [json-str]]))
[clojure.contrib.json :only [json-str]])
(:import org.apache.commons.codec.digest.DigestUtils))

(def golfer-tags (into [:contributor]
(when (:golfing-active config)
Expand All @@ -23,7 +26,7 @@
(defn get-users []
(from-mongo
(fetch :users
:only [:user :solved :contributor])))
:only [:user :solved :contributor :email])))

(defn get-ranked-users []
(let [users (get-users)
Expand Down Expand Up @@ -66,6 +69,18 @@
(link-to (str "mailto:" (email-address username))
username))



(let [canonical-email (comp string/trim string/lower-case)
md5 #(DigestUtils/md5Hex %)]
(defn gravatar-img [{:keys [email size class] :or {size 24}}]
(let [hash (md5 (canonical-email email))
url (str (name *http-scheme*) "://www.gravatar.com/avatar/"
hash "?s=" size "&d=identicon")]
[:img (conj {:src url, :alt "gravatar icon"
:width size :height size}
(when class {:class class}))])))

(defn format-user-ranking [{:keys [rank user contributor solved]}]
(when user
[:div
Expand Down Expand Up @@ -102,12 +117,12 @@
[:th {:style "width: 200px;"} "Username"]
[:th {:style "width: 180px;"} "Problems Solved"]
[:th "Following"]]]
(map-indexed (fn [rownum {:keys [_id position rank user contributor solved]}]
(map-indexed (fn [rownum {:keys [_id email position rank user contributor solved]}]
[:tr (row-class rownum)
[:td (rank-class position) rank]
[:td
(when contributor [:span.contributor "* "])
[:a.user-profile-link {:href (str "/user/" user)} user]]
(gravatar-img {:email email :class "gravatar"})
[:a.user-profile-link {:href (str "/user/" user)} user (when contributor [:span.contributor " *"])]]
[:td.centered (count solved)]
[:td (following-checkbox user-id following _id user)]])
user-set)])))
Expand Down Expand Up @@ -158,10 +173,11 @@

(def-page user-profile [username]
(let [page-title (str "User: " username)
user-id (:_id (get-user username))]
{user-id :_id email :email} (get-user username)]
{:title page-title
:content
(list
(gravatar-img {:email email, :size 80 :class "user-profile-img"})
[:div.user-profile-name page-title]
(if (session/session-get :user)
(with-user [{:keys [_id following]}]
Expand Down
31 changes: 1 addition & 30 deletions src/foreclojure/utils.clj
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,9 @@
[hiccup.form-helpers :only [label]]
[useful.fn :only [to-fix]]
[somnium.congomongo :only [fetch-one]]
[foreclojure.ring-utils :only [*url* static-url]]
[foreclojure.config :only [config repo-url]]))

(def ^{:dynamic true} *url* nil)

(defn wrap-uri-binding [handler]
(fn [req]
(binding [*url* (:uri req)]
(handler req))))

(defn as-int [s]
(if (integer? s) s,
(try (Integer. s)
Expand Down Expand Up @@ -158,29 +152,6 @@
(>= (count (get-solved username))
(:advanced-user-count config)))))

(let [prefix (str (when-let [host config/static-host]
(str "http://" host))
"/")]
(defn static-url [url]
(str prefix url)))

(let [version-suffix (str "__" git/tag)]
(defn add-version-number [file]
(let [[_ path ext] (re-find #"(.*)\.(.*)$" file)]
(str path version-suffix "." ext)))

(defn strip-version-number [file]
(string/replace file version-suffix "")))

(letfn [(wrap-versioning [f]
(fn [& files]
(for [file files]
(f (static-url (add-version-number file))))))]
(def js (wrap-versioning hiccup/include-js))
(def css (wrap-versioning hiccup/include-css)))



(defn image-builder
"Return a function for constructing an [:img] element from a keyword.

Expand Down
21 changes: 21 additions & 0 deletions src/foreclojure/version_utils.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
(ns foreclojure.version-utils
(:use [foreclojure.ring-utils :only [static-url]])
(:require [foreclojure.git :as git]
[foreclojure.config :as config]
[clojure.string :as string]
[hiccup.page-helpers :as hiccup]))

(let [version-suffix (str "__" git/tag)]
(defn add-version-number [file]
(let [[_ path ext] (re-find #"(.*)\.(.*)$" file)]
(str path version-suffix "." ext)))

(defn strip-version-number [file]
(string/replace file version-suffix "")))

(letfn [(wrap-versioning [f]
(fn [& files]
(for [file files]
(f (static-url (add-version-number file))))))]
(def js (wrap-versioning hiccup/include-js))
(def css (wrap-versioning hiccup/include-css)))