|
2 | 2 | (:require [hiccup2.core :as hiccup]
|
3 | 3 | [cemerick.url :refer [url]]
|
4 | 4 | [clojurians-log.time-util :as cl.tu]
|
| 5 | + [clojure.data.json :as json] |
5 | 6 | [clojure.string :as str]
|
6 | 7 | [clojurians-log.slack-messages :as slack-messages]
|
7 | 8 | [reitit.core]
|
|
16 | 17 | [messages ts]
|
17 | 18 | (some #(when (= (:message/ts %) ts) %) messages))
|
18 | 19 |
|
| 20 | +(defn jsfile [path] |
| 21 | + (when-let [f (io/file (io/resource (str "public" path)))] |
| 22 | + (let [ts (.lastModified f)] |
| 23 | + [:script |
| 24 | + {:src (str path "?version=" ts)}]))) |
19 | 25 |
|
20 | 26 | (defn stylesheet [path]
|
21 | 27 | (when-let [f (io/file (io/resource (str "public" path)))]
|
|
286 | 292 | :date day}))]
|
287 | 293 | [:lastmod day]]))])
|
288 | 294 |
|
| 295 | + |
| 296 | +(defn- page-head-stats [{:data/keys [title]}] |
| 297 | + [:head |
| 298 | + [:meta {:charset "utf-8"}] |
| 299 | + [:meta {:http-equiv "X-UA-Compatible" :content "IE=edge"}] |
| 300 | + [:meta {:content="width=device-width, initial-scale=1" :name "viewport"}] |
| 301 | + [:title title] |
| 302 | + [:link {:href "https://unpkg.com/sakura.css/css/sakura.css" |
| 303 | + :rel "stylesheet" |
| 304 | + :type "text/css"}] |
| 305 | + (stylesheet "/css/gh-fork-ribbon.min.css") |
| 306 | + [:script {:src "https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.4/Chart.min.js"}] |
| 307 | + ]) |
| 308 | + |
289 | 309 | (defn- message-stats-page-html [{:data/keys [message-stats] :as context}]
|
290 |
| - [:div |
291 |
| - [:h3 (str "Showing message stats between " |
292 |
| - (:day (first message-stats)) |
293 |
| - " to " |
294 |
| - (:day (last message-stats)))] |
295 |
| - [:table |
296 |
| - [:thead |
297 |
| - [:tr |
298 |
| - [:th "Day"] |
299 |
| - [:th "Message count"]]] |
300 |
| - [:tbody |
301 |
| - (for [day-stat message-stats] [:tr [:td (:day day-stat)] [:td (:msg-count day-stat)]])]] |
302 |
| - [:h4 "Total message count: " (reduce #(+ %1 (:msg-count %2)) 0 message-stats)]]) |
| 310 | + [:html |
| 311 | + (page-head-stats context) |
| 312 | + [:body |
| 313 | + [:div |
| 314 | + [:h4 "Slack message stats"] |
| 315 | + [:p |
| 316 | + [:strong {:style {:border-bottom "1px solid black"}} (:day (first message-stats))] |
| 317 | + " to " |
| 318 | + [:strong {:style {:border-bottom "1px solid black"}} (:day (last message-stats))]] |
| 319 | + [:div {:width "100%"} |
| 320 | + [:canvas#message-chart]] |
| 321 | + [:h4 "Total message count: " (reduce #(+ %1 (:msg-count %2)) 0 message-stats)] |
| 322 | + [:table |
| 323 | + [:thead |
| 324 | + [:tr |
| 325 | + [:th "Day"] |
| 326 | + [:th "Message count"]]] |
| 327 | + [:tbody |
| 328 | + (for [day-stat message-stats] [:tr [:td (:day day-stat)] [:td (:msg-count day-stat)]])]]] |
| 329 | + [:script#message-data {:type "application/json"} (json/write-str message-stats)] |
| 330 | + (jsfile "/js/stats.js")]]) |
303 | 331 |
|
304 | 332 | (defn log-page [context]
|
305 | 333 | (assoc context :response/html (log-page-html context)))
|
|
0 commit comments