Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Use search as file-view #173

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 0 additions & 47 deletions src/cljs/witan/ui/controllers/datastore.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,6 @@

(declare on-query-response)

(defn select-current!
[id]
(when id
(data/swap-app-state! :app/datastore assoc :ds/current id)))

(defn reset-properties!
[id]
(when id
(data/swap-app-state! :app/datastore update :ds/file-properties dissoc id)))

(defn reset-file-edit-metadata!
([]
(reset-file-edit-metadata! nil))
Expand Down Expand Up @@ -132,27 +122,6 @@
(defmulti on-query-response
(fn [[k v]] k))

(defmethod on-query-response
:datastore/metadata-by-id
[[_ data]]
(if (:error data)
(let [id (first (get-in data [:original :params]))
tries (data/get-in-app-state :app/datastore :ds/query-tries)]
(if (< tries 3)
(js/setTimeout
#(do
(data/swap-app-state! :app/datastore update :ds/query-tries inc)
(send-single-file-item-query! id))
1000)
(do
(log/warn "File" id "is not accessible.")
(data/swap-app-state! :app/datastore assoc :ds/error :string/file-inaccessible)
(data/swap-app-state! :app/datastore assoc :ds/query-tries 0))))
(do
(data/swap-app-state! :app/datastore assoc :ds/query-tries 0)
(save-file-metadata! data)
(set-title! (:kixi.datastore.metadatastore/name data)))))

(defmethod on-query-response
:error
[[o data]]
Expand Down Expand Up @@ -908,22 +877,6 @@
(data/swap-app-state! :app/create-datapack dissoc :cdp/error)
(set-title! (get-string :string/create-new-datapack)))

(def subview-query-param :d)

(defmethod on-route-change
:app/data
[{:keys [args]}]
(data/swap-app-state! :app/datastore dissoc :ds/error)
(data/swap-app-state! :app/datastore assoc :ds/pending? true)
(data/swap-app-state! :app/datastore assoc :ds/confirming-delete? false)
(data/swap-app-state! :app/datastore assoc :ds/data-view-subview-idx
(utils/query-param-int subview-query-param 0 10))
(let [id (get-in args [:route/params :id])]
(send-single-file-item-query! id)
(reset-properties! id)
(select-current! id)
(set-title! (get-string :string/title-data-loading))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defonce subscriptions
Expand Down
67 changes: 67 additions & 0 deletions src/cljs/witan/ui/controllers/search.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,42 @@
:ks/search->result
{search resp}))

(defn reset-file-edit-metadata!
([]
(reset-file-edit-metadata! nil))
([md]
(data/swap-app-state! :app/datastore assoc :ds/file-metadata-editing md)))

(defn save-file-metadata!
[{:keys [kixi.datastore.metadatastore/id] :as payload}]
(when id
(log/debug "Saving file metadata..." id)
(data/swap-app-state! :app/datastore assoc-in [:ds/file-metadata id] payload)
(when (= id (data/get-in-app-state :app/datastore :ds/file-metadata-editing :kixi.datastore.metadatastore/id))
(reset-file-edit-metadata! payload))))

(defmethod on-query-response
:search/metadata-by-id
[[_ data]]
(if (:error data)
(let [id (first (get-in data [:original :params]))
tries (data/get-in-app-state :app/datastore :ds/query-tries)]
(if (< tries 3)
(js/setTimeout
#(do
(data/swap-app-state! :app/datastore update :ds/query-tries inc)
(send-single-file-item-query! id))
1000)
(do
(log/warn "File" id "is not accessible.")
(data/swap-app-state! :app/datastore assoc :ds/error :string/file-inaccessible)
(data/swap-app-state! :app/datastore assoc :ds/query-tries 0))))
(do
(log/debug "Metadata-by-id:" data)
(data/swap-app-state! :app/datastore assoc :ds/query-tries 0)
(save-file-metadata! data)
(set-title! (:kixi.datastore.metadatastore/name data)))))

(defn datapacks-cache-search
[search]
(dissoc search :from))
Expand Down Expand Up @@ -199,5 +235,36 @@
(handle :dashboard query-params)
(set-title! (get-string :string/title-data-dashboard))))

(def subview-query-param :d)

(defn send-single-file-item-query!
[id]
(data/query {:search/metadata-by-id [[id]]}
on-query-response))

(defn reset-properties!
[id]
(when id
(data/swap-app-state! :app/datastore update :ds/file-properties dissoc id)))

(defn select-current!
[id]
(when id
(data/swap-app-state! :app/datastore assoc :ds/current id)))

(defmethod on-route-change
:app/data
[{:keys [args]}]
(data/swap-app-state! :app/datastore dissoc :ds/error)
(data/swap-app-state! :app/datastore assoc :ds/pending? true)
(data/swap-app-state! :app/datastore assoc :ds/confirming-delete? false)
(data/swap-app-state! :app/datastore assoc :ds/data-view-subview-idx
(utils/query-param-int subview-query-param 0 10))
(let [id (get-in args [:route/params :id])]
(send-single-file-item-query! id)
(reset-properties! id)
(select-current! id)
(set-title! (get-string :string/title-data-loading))))

(defonce subscriptions
(do (data/subscribe-topic :data/route-changed on-route-change)))