Просмотр исходного кода

feat(rtc): support list-graphs

rcmerci 2 лет назад
Родитель
Сommit
63a0ad67c2

+ 4 - 4
src/main/frontend/db/rtc/core.cljs

@@ -2,7 +2,9 @@
   "Main ns for rtc related fns"
   (:require-macros
    [frontend.db.rtc.macro :refer [with-sub-data-from-ws get-req-id get-result-ch]])
-  (:require [cljs.core.async :as async :refer [<! chan go go-loop]]
+  (:require [cljs-time.coerce :as tc]
+            [cljs-time.core :as t]
+            [cljs.core.async :as async :refer [<! chan go go-loop]]
             [cljs.core.async.interop :refer [p->c]]
             [clojure.set :as set]
             [frontend.db :as db]
@@ -13,10 +15,8 @@
             [frontend.modules.outliner.transaction :as outliner-tx]
             [frontend.util :as util]
             [malli.core :as m]
-            [malli.util :as mu]
             [malli.transform :as mt]
-            [cljs-time.core :as t]
-            [cljs-time.coerce :as tc]))
+            [malli.util :as mu]))
 
 
 (def state-schema

+ 24 - 5
src/main/frontend/db/rtc/debug_ui.cljs

@@ -1,5 +1,7 @@
 (ns frontend.db.rtc.debug-ui
   "Debug UI for rtc module"
+  (:require-macros
+   [frontend.db.rtc.macro :refer [with-sub-data-from-ws get-req-id get-result-ch]])
   (:require [frontend.ui :as ui]
             [rum.core :as rum]
             [frontend.db.rtc.core :as rtc-core]
@@ -57,6 +59,8 @@
   (rum/local nil ::ops)
   (rum/local nil ::ws-state)
   (rum/local nil ::download-graph-to-repo)
+  (rum/local nil ::remote-graphs)
+  (rum/local nil ::graph-uuid-to-download)
   [state]
   (let [s (rum/react debug-state)
         rtc-state (and s (rum/react (:*rtc-state s)))]
@@ -66,7 +70,14 @@
                                 (let [repo (state/get-current-repo)
                                       {:keys [local-tx ops]}
                                       (<! (p->c (op/<get-ops&local-tx repo)))
-                                      graph-uuid (<! (p->c (op/<get-graph-uuid repo)))]
+                                      graph-uuid (<! (p->c (op/<get-graph-uuid repo)))
+                                      graph-list (when (= :open rtc-state)
+                                                   (with-sub-data-from-ws s
+                                                     (<! (ws/<send! s {:req-id (get-req-id)
+                                                                       :action "list-graphs"
+                                                                       :graph-uuid "placeholder"}))
+                                                     (:graphs (<! (get-result-ch)))))]
+                                  (reset! (::remote-graphs state) (map :graph-uuid graph-list))
                                   (reset! (::local-tx state) local-tx)
                                   (reset! (::ops state) (count ops))
                                   (reset! (::graph-uuid state) graph-uuid)
@@ -77,7 +88,8 @@
                 :rtc-state rtc-state
                 :ws (and s (ws/get-state @(:*ws s)))
                 :local-tx @(::local-tx state)
-                :pending-ops @(::ops state)}
+                :pending-ops @(::ops state)
+                :remote-graphs @(::remote-graphs state)}
                (fipp/pprint {:width 20})
                with-out-str)]
      (if (or (nil? s)
@@ -87,17 +99,24 @@
 
        [:div.my-2
         [:div.my-2 (ui/button (str "send pending ops")
-                         {:on-click (fn [] (push-pending-ops))})]
+                              {:on-click (fn [] (push-pending-ops))})]
         [:div (ui/button "stop" {:on-click (fn [] (<stop))})]])
      [:hr]
      [:div.flex
+      ;; [:select
+      ;;  {:on-change (fn [e]
+      ;;                (let [value (util/evalue e)]
+      ;;                  (reset! (::graph-uuid-to-download state) value)))}
+      ;;  (for [graph-uuid @(::remote-graphs state)]
+      ;;    [:option {:key graph-uuid :value graph-uuid} graph-uuid])]
       (ui/button (str "download graph to")
                  {:class "mr-2"
                   :on-click (fn []
                               (go
                                 (when-let [repo @(::download-graph-to-repo state)]
-                                  (<! (<download-graph repo debug-graph-uuid))
-                                  (notification/show! "download graph successfully"))))})
+                                  (when-let [graph-uuid @(::graph-uuid-to-download state)]
+                                    (<! (<download-graph repo graph-uuid))
+                                    (notification/show! "download graph successfully")))))})
       (ui/ls-textarea {:on-change (fn [e] (reset! (::download-graph-to-repo state) (util/evalue e)))})]
      [:div.flex.my-2
       (ui/button (str "upload graph") {:on-click (fn []

+ 5 - 1
src/main/frontend/db/rtc/full_upload_download_graph.cljs

@@ -25,7 +25,11 @@
          (keep (fn [datoms]
                  (when (seq datoms)
                    (reduce
-                    (fn [r datom] (assoc r (:a datom) (:v datom)))
+                    (fn [r datom]
+                      (when (and (contains? #{:block/parent :block/left} (:a datom))
+                                 (not (pos-int? (:v datom))))
+                        (throw (ex-info "invalid block data" {:datom datom})))
+                      (assoc r (:a datom) (:v datom)))
                     {:db/id (:e (first datoms))}
                     datoms)))))))