Skip to content

Commit f637c1a

Browse files
authored
Merge pull request #117 from clojureverse/fix-username-link
[WIP] Fix username link
2 parents 930826a + 38c7ff5 commit f637c1a

File tree

6 files changed

+93
-27
lines changed

6 files changed

+93
-27
lines changed

bin/librato_report.sh

100644100755
File mode changed.

bin/nginx_report.rb

100644100755
File mode changed.

src/clojurians_log/db/queries.clj

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,15 @@
109109
db
110110
ids))
111111

112+
(defn user-profile
113+
"returing all the data about the user acording to the user id slack number"
114+
[db id]
115+
(ffirst (d/q '[:find (pull ?user [*])
116+
:in $ ?id
117+
:where [?user :user/slack-id ?id]]
118+
db
119+
id)))
120+
112121
(defn thread-messages
113122
"Retrieve all child messages for the given parent threads"
114123
[db parent-tss]

src/clojurians_log/routes.clj

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"Attach thread messages as :message/children to their parent message"
3232
[messages thread-messages]
3333
(let [messages-by-thread-ts (group-by :message/thread-ts thread-messages)]
34-
(map (fn[msg]
34+
(map (fn [msg]
3535
(if-let [children (get messages-by-thread-ts (:message/ts msg))]
3636
(assoc msg :message/children children)
3737
msg))
@@ -132,6 +132,14 @@
132132
views/about
133133
response/render))
134134

135+
(defn user-profile-route [{:keys [endpoint path-params] :as request}]
136+
(let [db (db-from-endpoint endpoint)]
137+
(-> request
138+
make-context
139+
(assoc :data/user-profile (queries/user-profile db (:user-id path-params)))
140+
views/user-profile-route
141+
response/render)))
142+
135143
(defn sitemap-route [{:keys [endpoint] :as request}]
136144
(let [config @(get-in endpoint [:config :value])
137145
db (db-from-endpoint endpoint)]
@@ -156,16 +164,18 @@
156164
(def routes
157165
[["/" {:name :clojurians-log.routes/index
158166
:get index-route}]
167+
["/_/_/users/{user-id}" {:name :clojurians-log.routes/user-profile-route
168+
:get user-profile-route}]
159169
["/x/x/x/about" {:name :clojurians-log.routes/about
160170
:get about-route}]
161171
["/x/x/x/sitemap" {:name :clojurians-log.routes/sitemap
162172
:get sitemap-route}]
163-
["/x/x/x/healthcheck" {:name :clojurians-log.routes/healthcheck,
173+
["/x/x/x/healthcheck" {:name :clojurians-log.routes/healthcheck
164174
:get healthcheck-route}]
165-
["/{channel}" {:name :clojurians-log.routes/channel,
175+
["/{channel}" {:name :clojurians-log.routes/channel
166176
:get channel-history-route}]
167-
["/{channel}/{date}" {:name :clojurians-log.routes/channel-date,
177+
["/{channel}/{date}" {:name :clojurians-log.routes/channel-date
168178
:get log-route}]
169-
["/{channel}/{date}/{ts}" {:name :clojurians-log.routes/message,
170-
:get log-route}]
171-
["/_/stats/{from-date}/{to-date}" {:name :clojurians-log.routes/message-stats :get message-stats-route}]])
179+
["/{channel}/{date}/{ts}" {:name :clojurians-log.routes/message :get log-route}]
180+
["/_/stats/{from-date}/{to-date}" {:name :clojurians-log.routes/message-stats
181+
:get message-stats-route}]])

src/clojurians_log/styles.clj

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,4 +416,28 @@
416416
:line-height "1.33rem"}]
417417
[:ul {:padding-left "1rem"}]
418418
[:li {:list-style-type "disc"}]]
419-
)
419+
420+
[:.user-profile-page
421+
[:h2 {:text-align "center"
422+
:margin-top "20px"
423+
:font-family "sans-serif"}]
424+
[:section {:box-shadow "0 4px 8px 0 rgba(0, 0, 0, 0.2)"
425+
:max-width "350px"
426+
:margin "auto"
427+
:text-align "center"
428+
:font-family "sans-serif"}]
429+
[:img {:width "95%"
430+
:border-radius "80%"
431+
:padding "8px 0px"}]
432+
[:.real-name {:color "grey"
433+
:font-size "18px"}]
434+
[:.talk-on-slack {:border "none"
435+
:outline "0"
436+
:display "inline-block"
437+
:padding "8px 0px"
438+
:color "white"
439+
:background-color "#000"
440+
:text-align "center"
441+
:cursor "pointer"
442+
:width "100%"
443+
:font-size "18px"}]])

src/clojurians_log/views.clj

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@
170170
:date future-date})}
171171
[:div.day-next ">"]])]]])
172172

173+
(defn slack-url [ctx & parts]
174+
(apply str
175+
(get-in ctx [:request :clojurians-log.application/slack-instance])
176+
parts))
177+
173178
(defn- single-message
174179
"Returns the hiccup of a single message"
175180
[{:keys [request]
@@ -178,26 +183,26 @@
178183
{:message/keys [user inst user text thread-ts ts] :as message}]
179184

180185
(let [{:user/keys [name slack-id]
181-
:user-profile/keys [display-name real-name image-48]} user
182-
slack-instance (:clojurians-log.application/slack-instance request)]
183-
186+
:user-profile/keys [display-name real-name image-48]} user]
184187
;; things in the profile
185188
;; :image_512 :email :real_name_normalized :image_48 :image_192 :real_name :image_72 :image_24
186189
;; :avatar_hash :title :team :image_32 :display_name :display_name_normalized
187-
(list [:div.message
188-
{:id (cl.tu/format-inst-id inst) :class (when (thread-child? message) "thread-msg")}
189-
[:a.message_profile-pic {:href (str slack-instance "/team/" slack-id) :style (str "background-image: url(" image-48 ");")}]
190-
[:a.message_username {:href (str slack-instance "/team/" slack-id)}
191-
(some #(when-not (str/blank? %) %) [display-name real-name name])]
192-
[:span.message_timestamp [:a {:rel "nofollow"
193-
:href (path-for context
194-
:clojurians-log.routes/message
195-
{:channel (:channel/name channel)
196-
:date date
197-
:ts ts})}
198-
(cl.tu/format-inst-time inst)]]
199-
[:span.message_star]
200-
[:span.message_content [:p (slack-messages/message->hiccup text usernames emojis)]]])))
190+
[:div.message
191+
{:id (cl.tu/format-inst-id inst) :class (when (thread-child? message) "thread-msg")}
192+
[:a.message_profile-pic {:href (slack-url context "/users/x/x/" slack-id)
193+
:style (str "background-image: url(" image-48 ");")}]
194+
;;[:a.message_username {:href (str slack-instance "/team/" slack-id)}
195+
[:a.message_username {:href (str "/_/_/users/" slack-id)}
196+
(some #(when-not (str/blank? %) %) [display-name real-name name])]
197+
[:span.message_timestamp [:a {:rel "nofollow"
198+
:href (path-for context
199+
:clojurians-log.routes/message
200+
{:channel (:channel/name channel)
201+
:date date
202+
:ts ts})}
203+
(cl.tu/format-inst-time inst)]]
204+
[:span.message_star]
205+
[:span.message_content [:p (slack-messages/message->hiccup text usernames emojis)]]]))
201206

202207
(defn- message-hiccup
203208
"Returns either a single message hiccup, or if the given message starts a thread,
@@ -280,6 +285,21 @@
280285
[:section#about
281286
(:data/about-hiccup context)]]]])
282287

288+
(defn- user-profile-html [context]
289+
[:html.user-profile-page
290+
(page-head context)
291+
[:body
292+
[:h2 "User Profile"]
293+
[:section
294+
(let [user-profile (get-in context [:data/user-profile])
295+
{:user-profile/keys [display-name real-name image-192]
296+
:user/keys [slack-id]} user-profile]
297+
(list
298+
[:img {:src image-192 :alt (str display-name " avatar")}]
299+
[:h1 display-name]
300+
[:p.real-name real-name]
301+
[:a.talk-on-slack {:href (slack-url context "/team/" slack-id)} "let's talk on Slack"]))]]])
302+
283303
(defn- sitemap-xml [{:data/keys [channel-day-tuples http-origin] :as context}]
284304
[:urlset {:xmlns "http://www.sitemaps.org/schemas/sitemap/0.9"}
285305
(for [[{:channel/keys [name]} channel-days] channel-day-tuples]
@@ -312,7 +332,7 @@
312332
[:body
313333
[:div
314334
[:h4 "Slack message stats"]
315-
[:p
335+
[:p
316336
[:strong {:style {:border-bottom "1px solid black"}} (:day (first message-stats))]
317337
" to "
318338
[:strong {:style {:border-bottom "1px solid black"}} (:day (last message-stats))]]
@@ -341,8 +361,11 @@
341361
(defn about [context]
342362
(assoc context :response/html (about-html context)))
343363

364+
(defn user-profile-route [context]
365+
(assoc context :response/html (user-profile-html context)))
366+
344367
(defn sitemap [context]
345368
(assoc context :response/xml (sitemap-xml context)))
346369

347370
(defn message-stats-page [context]
348-
(assoc context :response/html (message-stats-page-html context)))
371+
(assoc context :response/html (message-stats-page-html context)))

0 commit comments

Comments
 (0)