Commit 9e2242b0 authored by Ricardo J. Mendez's avatar Ricardo J. Mendez

Color-coding link age

parent 961aa60d
......@@ -3,7 +3,7 @@
[relevance.data :as data]
[relevance.io :as io]
[relevance.migrations :as migrations]
[relevance.utils :refer [on-channel url-key host-key hostname is-http?]]
[relevance.utils :refer [on-channel url-key host-key hostname is-http? ms-day]]
[khroma.alarms :as alarms]
[khroma.context-menus :as menus]
[khroma.idle :as idle]
......@@ -31,9 +31,6 @@
(defn now [] (.now js/Date))
;; Clean-up parameters
(def day-in-ms 86400000)
;;;;-------------------------------------
......@@ -143,9 +140,9 @@
(let [migrated (migrations/migrate-to-latest loaded)
new-urls (->
(:url-times migrated)
(data/time-clean-up (- (now) (* 7 day-in-ms)) 30)
(data/time-clean-up (- (now) (* 14 day-in-ms)) 90)
(data/time-clean-up (- (now) (* 30 day-in-ms)) 300))
(data/time-clean-up (- (now) (* 7 ms-day)) 30)
(data/time-clean-up (- (now) (* 14 ms-day)) 90)
(data/time-clean-up (- (now) (* 30 ms-day)) 300))
new-sites (if (not= new-urls (:url-times migrated))
(data/accumulate-site-times new-urls)
(:site-times migrated))
......
......@@ -6,6 +6,21 @@
(:require-macros [cljs.core.async.macros :refer [go go-loop]]))
;;;;-------------------------------------
;;;; Values
;;;;-------------------------------------
(def ms-hour (* 60 60 1000))
(def ms-day 86400000)
(def ms-week (* 7 ms-day))
;;;;-------------------------------------
;;;; Functions
;;;;-------------------------------------
(defn on-channel
"Dispatches msg when there's content received on the channel returned by
function chan-f. Expects a dispatch function."
......
(ns relevance.display
(:require [relevance.utils :refer [on-channel from-transit time-display host-key hostname]]
(:require [relevance.utils :refer [on-channel from-transit time-display host-key hostname
ms-hour ms-day ms-week]]
[cljs.core.async :refer [>! <!]]
[cljs.core :refer [random-uuid]]
[cljsjs.react-bootstrap]
......@@ -187,7 +188,18 @@
title)
display (if (< 100 (count label))
(apply str (concat (take 100 label) "..."))
label)]
label)
age-ms (- (.now js/Date) (:ts tab))
;; Colors picked at http://www.w3schools.com/tags/ref_colorpicker.asp
color (cond
(< age-ms ms-hour) "#00ff00"
(< age-ms ms-day) "#00cc00"
(< age-ms (* 3 ms-day)) "#009900"
(< age-ms (* 7 ms-day)) "#ff8000"
(< age-ms (* 14 ms-day)) "#cc6600"
:else "#994c00"
)
]
^{:key i}
[:tr
[:td {:class "col-sm-2"}
......@@ -201,8 +213,8 @@
:height 16}])
display]]
[:td {:class "col-sm-2"}
(time-display (quot (- (.now js/Date) (:ts tab)) 1000))
]
[:i (merge {:class "fa fa-circle" :style {:color color}})]
(time-display (quot age-ms 1000))]
])))))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment