Commit 827b776a authored by Heinz N. Gies's avatar Heinz N. Gies

Nicer handling of 404s

parent 9e0324f2
<!DOCTYPE html>
<html>
<head>
<link href="css/bootstrap.min.css" rel="stylesheet" type="text/css">
<link href="css/style.css" rel="stylesheet" type="text/css">
<!--link href="css/bootstrap.min.css" rel="stylesheet" type="text/css">
<link href="css/style.css" rel="stylesheet" type="text/css"-->
<!--link href="css/bootstrap-dark.min.css" rel="stylesheet" type="text/css">
<link href="css/dark.css" rel="stylesheet" type="text/css"-->
<link href="css/dark.css" rel="stylesheet" type="text/css"-->
<script src="/config/config.js" type="text/javascript"></script>
<script type="text/javascript">
function add_css(file) {
var link = document.createElement( "link" );
link.href = file;
link.type = "text/css";
link.rel = "stylesheet";
link.media = "screen,print";
document.getElementsByTagName( "head" )[0].appendChild( link );
};
if (Config.theme == "dark") {
add_css("css/bootstrap-dark.min.css");
add_css("css/dark.css");
} else {
add_css("css/bootstrap.min.css");
add_css("css/style.css");
}
</script>
</head>
<body>
<div id="app"></div>
<script src="/config/config.js" type="text/javascript"></script>
<script src="/js/app.js" type="text/javascript"></script>
</body>
</html>
......@@ -8,6 +8,7 @@
[cerberus.http :as http]
[cerberus.howl :as howl]
[clojure.string :refer [join]]
[cerberus.alert :refer [raise]]
[cerberus.utils :refer [goto value-by-key]]
[cerberus.state :refer [app-state path-vec set-state! delete-state!]]))
......@@ -15,15 +16,16 @@
(set-state! :token false)
(goto))
(defn to-state
([state-path req]
(go (let [resp (<! req)]
(set-state! state-path (js->clj (:body resp))))))
([state-path req map-fn]
(go (let [resp (<! req)]
(if (= 401 (:status resp))
(check-login)
(set-state! state-path (map map-fn (js->clj (:body resp)))))))))
(defn to-state [error-dest state-path req]
(go (let [resp (<! req)]
(condp = (:status resp)
401 (check-login)
404 (do
(raise :warning (str (name (first state-path)) " " (nth state-path 2) " not found!"))
(pr error-dest)
(if error-dest (goto error-dest))
(delete-state! state-path))
200 (set-state! state-path (js->clj (:body resp)))))))
(defn full-list
([path]
......@@ -36,7 +38,6 @@
(str path "?full-list=true&full-list-fields=" fields)
(str path "?full-list=true")))
(defn list
([data root]
(list data root nil))
......@@ -66,9 +67,12 @@
(reduce dissoc old deleted))))))))))
(defn get [root uuid]
(to-state [root :elements uuid] (http/get [root uuid])))
(to-state false [root :elements uuid] (http/get [root uuid])))
(defn get-page [root uuid]
(to-state (str "/" (name root)) [root :elements uuid] (http/get [root uuid])))
(defn join-and [other-fn]
(fn join-and* [resp]
......
......@@ -16,6 +16,9 @@
(def get (partial api/get root))
(defn get-page [uuid]
(api/get-page root uuid))
(defn a-get [uuid success error]
(assoc (alerts success error) :always #(get uuid)))
......
......@@ -130,4 +130,4 @@
"metadata" {:key 4 :fn #(om/build metadata/render
(:metadata %2) {:opts {:root "clients" :uuid (:uuid %2)}}) :title "Metadata"}})
(def render (view/make root sections clients/get :name-fn :name))
(def render (view/make root sections clients/get-page :name-fn :name))
......@@ -15,6 +15,9 @@
(def get (partial api/get root))
(defn get-page [uuid]
(api/get-page root uuid))
(defn a-get [uuid success error]
(assoc (alerts success error) :always #(get uuid)))
......
......@@ -88,7 +88,7 @@
(:metadata %2) {:opts {:root "datasets" :uuid (:uuid %2)}}) :title "Metadata"}})
(def render
(view/make root sections datasets/get
(view/make root sections datasets/get-page
:name-fn #(if-let [homepage (get-in % [:metadata :homepage])]
(d/a {:href homepage} (str (:name %) " (" (:type %) ")"))
(str (:name %) " (" (:type %) ")"))))
......@@ -16,5 +16,8 @@
(def get (partial api/get root))
(defn get-page [uuid]
(api/get-page root uuid))
(defn delete [data uuid]
(api/delete data root [uuid] (alerts "DTrace script deleted." "Failed to delete DTrace SCript")))
......@@ -29,5 +29,5 @@
(def render
(view/make
root sections
dtrace/get
dtrace/get-page
:name-fn :name))
......@@ -17,6 +17,9 @@
(def get (partial api/get root))
(defn get-page [uuid]
(api/get-page root uuid))
(defn a-get [uuid success error]
(assoc (alerts success error) :always #(get uuid)))
......
......@@ -177,4 +177,4 @@
root sections
:mount-fn (fn [uuid data]
(groupings/list data))
groupings/get))
groupings/get-page))
......@@ -17,6 +17,9 @@
(def get (partial api/get root))
(defn get-page [uuid]
(api/get-page root uuid))
(defn a-get [uuid success error]
(assoc (alerts success error) :always #(get uuid)))
......
......@@ -262,7 +262,7 @@
(def render
(view/make
root sections
hypervisors/get
hypervisors/get-page
:init-state {:edit-alias false}
:mount-fn (fn [uuid data]
(metrics/start-timer! (partial tick uuid)))
......
......@@ -14,5 +14,8 @@
(def get (partial api/get root))
(defn get-page [uuid]
(api/get-page root uuid))
(defn delete [data uuid]
(api/delete data root [uuid] (alerts "IPRange deleted." "Failed to delete IPRange.")))
......@@ -72,4 +72,4 @@
"metadata" {:key 3 :fn #(om/build metadata/render
(:metadata %2) {:opts {:root "ipranges" :uuid (:uuid %2)}}) :title "Metadata"}})
(def render (view/make root sections ipranges/get :name-fn :name))
(def render (view/make root sections ipranges/get-page :name-fn :name))
......@@ -16,6 +16,9 @@
(def get (partial api/get root))
(defn get-page [uuid]
(api/get-page root uuid))
(defn a-get [uuid success error]
(assoc (alerts success error) :always #(get uuid)))
......
......@@ -114,7 +114,7 @@
(def render
(view/make
root sections
networks/get
networks/get-page
:mount-fn (fn [uuid data]
(ipranges/list data))
:name-fn :name))
......@@ -16,6 +16,8 @@
(api/list data root list-fields))
(def get (partial api/get root))
(defn get-page [uuid]
(api/get-page root uuid))
(defn a-get [uuid success error]
(assoc (alerts success error) :always #(get uuid)))
......
......@@ -410,7 +410,7 @@
(def render
(view/make
root sections orgs/get
root sections orgs/get-page
:mount-fn (fn [uuid data]
(orgs/list data)
(networks/list data)
......
......@@ -13,6 +13,8 @@
(api/list data root))
(def get (partial api/get root))
(defn get-page [uuid]
(api/get-page root uuid))
(defn a-delete [uuid success error]
(assoc (alerts success error) :success #(swap! app-state update-in [root :elements]
......
......@@ -91,4 +91,4 @@
"metadata" {:key 3 :fn #(om/build metadata/render
(:metadata %2) {:opts {:root "packages" :uuid (:uuid %2)}}) :title "Metadata"}})
(def render (view/make root sections packages/get :name-fn :name))
(def render (view/make root sections packages/get-page :name-fn :name))
......@@ -16,6 +16,8 @@
(api/list data root list-fields))
(def get (partial api/get root))
(defn get-page [uuid]
(api/get-page root uuid))
(defn a-get [uuid success error]
(assoc (alerts success error) :always #(get uuid)))
......
......@@ -48,4 +48,4 @@
(:metadata %2) {:opts {:root "roles" :uuid (:uuid %2)}}) :title "Metadata"}})
(def render
(view/make root sections roles/get :name-fn :name))
(view/make root sections roles/get-page :name-fn :name))
......@@ -47,6 +47,7 @@
(set-state! [:vms :section] (:section params))
(set-view! :vms :show)))
(defroute "/datasets" {:as params}
(set-view! :datasets :list))
......
......@@ -20,6 +20,9 @@
(defn get [uuid]
(api/get root uuid))
(defn get-page [uuid]
(api/get-page root uuid))
(defn a-get [uuid success error]
(assoc (alerts success error) :always #(get uuid)))
......
......@@ -483,7 +483,7 @@
(def render
(view/make
root sections
users/get
users/get-page
:mount-fn (fn [uuid data]
(orgs/list data)
(clients/list data)
......
......@@ -23,6 +23,10 @@
(howl/join uuid)
(api/get root uuid))
(defn get-page [uuid]
(howl/join uuid)
(api/get-page root uuid))
(defn a-get [uuid success error]
(assoc (alerts success error) :always #(api/get root uuid)))
......
......@@ -38,7 +38,6 @@
(def token-path "sessions/one_time_token")
(defn has-delegates? [vm]
(pr "data:" (get-in vm [:config :datasets]))
(not (empty? (:datasets (:config vm)))))
(defn open-with-ott [path]
......@@ -1070,6 +1069,7 @@
(defn tick [uuid local-timer]
(let [app @app-state]
(if (and
(get-in app [root :elements uuid])
(not= (get-in app [root :elements uuid :metrics]) :no-metrics)
(= (get-in app [root :selected]) uuid)
(= (:section app) :vms))
......@@ -1079,7 +1079,7 @@
(def render
(view/make
root sections
vms/get
vms/get-page
:mount-fn (fn [uuid {:type type :as data}]
(metrics/start-timer! (partial tick uuid))
(orgs/list data)
......@@ -1089,7 +1089,6 @@
(groupings/list data)
(ipranges/list data))
:name-fn (fn [{:keys [state uuid hypervisor] {alias :alias} :config :as vm} data]
(pr "info:" (get-in vm [:info :vnc]))
(d/div
{}
alias " "
......
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