Commit 672f387e authored by Heinz N. Gies's avatar Heinz N. Gies

Improve dataset import and add support for network resolvers

parent 0c533123
......@@ -118,10 +118,8 @@
(error resp))))))
(defn delete-path [data root path]
(pr "delete-path" root path)
(if (= 1 (count path))
(let [uuid (first path)]
(pr "deleting" uuid)
(om/transact! data [root :elements]
#(dissoc % uuid)))))
......
......@@ -5,7 +5,7 @@
[om.core :as om :include-macros true]
[cerberus.api :as api]
[cerberus.global :as global]
[cerberus.alert :refer [alerts]]
[cerberus.alert :refer [alerts raise]]
[cerberus.state :refer [set-state!]]))
(def root :datasets)
......@@ -23,8 +23,15 @@
(alerts "Dataset deleted." "Failed to delete dataset.")))
(defn import [url]
(api/post root [] {:url url}
(alerts "Dataset import started." "Dataset import failed.")))
(let [success "Dataset import started."
error "Dataset import failed."]
(api/post root [] {:url url}
{:success (fn [resp]
((api/post-success-fn root) resp)
(raise :success success))
:error #(raise :danger error)
503 #(raise :danger (str error " - not all services are available."))
404 #(raise :warning (str error " - not found."))})))
(defn from-vm [vm snapshot name version os desc]
(let [payload {:vm vm
......
......@@ -52,21 +52,21 @@
(will-mount [_]
(datasets/list data)
(doseq
; This kind of sucks, but we are changing the config data type,
; so at least with this something shows up, and it will be relatively
; easy to debug why the users config changes are not being used.
(doseq
;; This kind of sucks, but we are changing the config data type,
;; so at least with this something shows up, and it will be relatively
;; easy to debug why the users config changes are not being used.
[f (if (coll? (global/get "datasets" ["https://datasets.project-fifo.net/images/", "http://datasets.at/images"]))
(global/get "datasets" ["https://datasets.project-fifo.net/images/", "http://datasets.at/images"])
["https://datasets.project-fifo.net/images/", "http://datasets.at/images"])]
(go (let
[resp (<! (http/get f {:with-credentials? false
:headers {"Accept" "application/json"}}))]
(if (:success resp)
(om/transact! data [:remote-datasets f] (constantly (:body resp)))
(dbg/error "[datasets/import] error: " resp))))))
(global/get "datasets" ["https://datasets.project-fifo.net/images/", "http://datasets.at/images"])
["https://datasets.project-fifo.net/images/", "http://datasets.at/images"])]
(go (let
[resp (<! (http/get f {:with-credentials? false
:headers {"Accept" "application/json"}}))]
(if (:success resp)
(om/transact! data [:remote-datasets f] (constantly (:body resp)))
(dbg/error "[datasets/import] error: " resp))))))
om/IRenderState
......@@ -74,7 +74,6 @@
(let [datasets (:remote-datasets data)
installed? (or (get-in data [:datasets :elements]) {})
picked? (or (:data data) #{})]
(pr installed?)
(table
{:striped? true :condensed? true
:hover? true :responsive? true :id "remote-datasets"}
......@@ -88,18 +87,18 @@
(d/tbody
(for [source datasets]
(for [dataset (second source)]
(let [uuid (:uuid dataset)
source (first source)]
(d/tr
{:on-click #(om/transact! data (partial toggle-dataset (str source "/" uuid)))
:class (if (installed? uuid) "installed"
(if (picked? (str source "/" uuid)) "selected" "not-selected"))}
(d/td (:name dataset))
(d/td (:version dataset))
(d/td (dataset-type dataset))
(d/td (:published_at dataset))
(d/td
(let [uuid (:uuid dataset)
source (first source)]
(d/tr
{:on-click #(om/transact! data (partial toggle-dataset (str source "/" uuid)))
:class (if (installed? uuid) "installed"
(if (picked? (str source "/" uuid)) "selected" "not-selected"))}
(d/td (:name dataset))
(d/td (:version dataset))
(d/td (dataset-type dataset))
(d/td (:published_at dataset))
(d/td
(if (= "https" (:protocol (url/url source)))
(r/glyphicon {:glyph "lock"}))
(r/glyphicon {:glyph "lock"}))
(:host (url/url source)))
(d/td (fields/fmt-bytes :b (get-in dataset [:files 0 :size])))))))))))))
(d/td (fields/fmt-bytes :b (get-in dataset [:files 0 :size])))))))))))))
......@@ -29,3 +29,11 @@
(defn remove-iprange [uuid iprange]
(api/delete root [uuid :ipranges iprange]
(a-get uuid "IPRange removed." "Failed to remove IPRange.")))
(defn add-resolver [uuid resolver]
(api/put root [uuid :resolvers resolver] {}
(a-get uuid "Resolver added." "Failed to add resolver.")))
(defn remove-resolver [uuid resolver]
(api/delete root [uuid :resolvers resolver]
(a-get uuid "Resolver removed." "Failed to remove resolver.")))
......@@ -57,6 +57,40 @@
(r/glyphicon {:glyph "remove"}))))
current-ipranges)))))))))
(defn render-resolvers [app owner opts]
(reify
om/IRenderState
(render-state [_ _]
(let [id (get-in app [root :selected])
element (get-in app [root :elements id])
current-resolvers (sort (or (:resolvers element) ["8.8.8.8", "8.8.4.4"]))]
(r/well
{}
(row
(col
{:xs 10 :sm 4}
(i/input
{:type "text" :id "resolver"}))
(col
{:xs 2 :sm 1}
(b/button
{:bs-style "primary"
:className "pull-right"
:onClick #(networks/add-resolver id (val-by-id "resolver"))}
"Add"))
(col
{:xs 12 :sm 6}
(d/ul
(map
(fn [resolver]
(d/li
resolver
(b/button {:bs-size "xsmall"
:className "pull-right"
:onClick #(networks/remove-resolver id resolver)}
(r/glyphicon {:glyph "remove"}))))
current-resolvers)))))))))
(defn render-home [data owner opts]
(reify
om/IRenderState
......@@ -71,10 +105,11 @@
"IPRanges" (count (:ipranges data)))})))))
(def sections
{"" {:key 1 :fn #(om/build render-home %2) :title "General"}
"ipranges" {:key 2 :fn #(om/build render-ranges %1) :title "IP Ranges"}
"metadata" {:key 3 :fn #(om/build metadata/render
(:metadata %2) {:opts {:root "networks" :uuid (:uuid %2)}}) :title "Metadata"}})
{"" {:key 1 :fn #(om/build render-home %2) :title "General"}
"ipranges" {:key 2 :fn #(om/build render-ranges %1) :title "IP Ranges"}
"resolvers" {:key 3 :fn #(om/build render-resolvers %1) :title "Resolvers"}
"metadata" {:key 4 :fn #(om/build metadata/render
(:metadata %2) {:opts {:root "networks" :uuid (:uuid %2)}}) :title "Metadata"}})
(def render
(view/make
......
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