hide journals in page graph

add "Show Journals" toggle in page-graph-inner
add :right-side-bar/show-journals in en and it (dicts.cljc)
add "include-journals" parameter to db/get-pages-that-mentioned-page
add "show-journal" parameter to graph-handler/build-page-graph
pull/6120/head
8N9KT 2022-07-20 18:44:05 +02:00
parent 37f1d738b9
commit 83d51ab23f
4 changed files with 36 additions and 14 deletions

View File

@ -434,6 +434,7 @@
(defonce *orphan-pages? (atom true)) (defonce *orphan-pages? (atom true))
(defonce *builtin-pages? (atom nil)) (defonce *builtin-pages? (atom nil))
(defonce *excluded-pages? (atom true)) (defonce *excluded-pages? (atom true))
(defonce *show-journals-in-page-graph? (atom nil))
(rum/defc ^:large-vars/cleanup-todo graph-filters < rum/reactive (rum/defc ^:large-vars/cleanup-todo graph-filters < rum/reactive
[graph settings n-hops] [graph settings n-hops]
@ -630,9 +631,22 @@
graph (update graph :nodes #(filter-graph-nodes % search-graph-filters))] graph (update graph :nodes #(filter-graph-nodes % search-graph-filters))]
(global-graph-inner graph settings theme))) (global-graph-inner graph settings theme)))
(rum/defc page-graph-inner < rum/static (rum/defc page-graph-inner < rum/reactive
[_page graph dark?] [_page graph dark?]
(let [ show-journals-in-page-graph? (rum/react *show-journals-in-page-graph?) ]
[:div.sidebar-item.flex-col [:div.sidebar-item.flex-col
[:div.flex.items-center.justify-between.mb-0
[:span (t :right-side-bar/show-journals)]
[:div.mt-1
(ui/toggle show-journals-in-page-graph? ;my-val;
(fn []
(let [value (not show-journals-in-page-graph?)]
(reset! *show-journals-in-page-graph? value)
;(set-setting! :show-journals-in-page-graph? value)
))
true)]
]
(graph/graph-2d {:nodes (:nodes graph) (graph/graph-2d {:nodes (:nodes graph)
:links (:links graph) :links (:links graph)
:width 600 :width 600
@ -640,7 +654,7 @@
:dark? dark? :dark? dark?
:register-handlers-fn :register-handlers-fn
(fn [graph] (fn [graph]
(graph-register-handlers graph (atom nil) (atom nil) dark?))})]) (graph-register-handlers graph (atom nil) (atom nil) dark?))})]))
(rum/defc page-graph < db-mixins/query rum/reactive (rum/defc page-graph < db-mixins/query rum/reactive
[] []
@ -650,9 +664,10 @@
(date/today)) (date/today))
theme (:ui/theme @state/state) theme (:ui/theme @state/state)
dark? (= theme "dark") dark? (= theme "dark")
show-journals-in-page-graph (rum/react *show-journals-in-page-graph?)
graph (if (util/uuid-string? page) graph (if (util/uuid-string? page)
(graph-handler/build-block-graph (uuid page) theme) (graph-handler/build-block-graph (uuid page) theme)
(graph-handler/build-page-graph page theme))] (graph-handler/build-page-graph page theme show-journals-in-page-graph))]
(when (seq (:nodes graph)) (when (seq (:nodes graph))
(page-graph-inner page graph dark?)))) (page-graph-inner page graph dark?))))

View File

@ -1120,18 +1120,23 @@
;; get pages who mentioned this page ;; get pages who mentioned this page
;; TODO: use :block/_refs ;; TODO: use :block/_refs
(defn get-pages-that-mentioned-page (defn get-pages-that-mentioned-page
[repo page] [repo page include-journals]
(when (conn/get-db repo) (when (conn/get-db repo)
(let [page-id (:db/id (db-utils/entity [:block/name (util/safe-page-name-sanity-lc page)])) (let [page-id (:db/id (db-utils/entity [:block/name (util/safe-page-name-sanity-lc page)]))
pages (page-alias-set repo page) pages (page-alias-set repo page)
query-base '[:find ?mentioned-page-name
:in $ ?pages ?page-name
:where
[?block :block/refs ?p]
[(contains? ?pages ?p)]
[?block :block/page ?mentioned-page]
[?mentioned-page :block/name ?mentioned-page-name]]
query (if include-journals
query-base
(conj query-base '[?mentioned-page :block/journal? false]))
mentioned-pages (->> (react/q repo [:frontend.db.react/page<-pages page-id] {:use-cache? false} mentioned-pages (->> (react/q repo [:frontend.db.react/page<-pages page-id] {:use-cache? false}
'[:find ?mentioned-page-name query
:in $ ?pages ?page-name
:where
[?block :block/refs ?p]
[(contains? ?pages ?p)]
[?block :block/page ?mentioned-page]
[?mentioned-page :block/name ?mentioned-page-name]]
pages pages
page) page)
react react

View File

@ -68,6 +68,7 @@
:right-side-bar/all-pages "All pages" :right-side-bar/all-pages "All pages"
:right-side-bar/flashcards "Flashcards" :right-side-bar/flashcards "Flashcards"
:right-side-bar/new-page "New page" :right-side-bar/new-page "New page"
:right-side-bar/show-journals "Show Journals"
:left-side-bar/journals "Journals" :left-side-bar/journals "Journals"
:left-side-bar/new-page "New page" :left-side-bar/new-page "New page"
:left-side-bar/nav-favorites "Favorites" :left-side-bar/nav-favorites "Favorites"
@ -3204,6 +3205,7 @@
:right-side-bar/all-pages "Tutte le pagine" :right-side-bar/all-pages "Tutte le pagine"
:right-side-bar/flashcards "Flashcard" :right-side-bar/flashcards "Flashcard"
:right-side-bar/new-page "Nuova pagina" :right-side-bar/new-page "Nuova pagina"
:right-side-bar/show-journals "Mostra diari"
:left-side-bar/journals "Diario" :left-side-bar/journals "Diario"
:left-side-bar/new-page "Nuova pagina" :left-side-bar/new-page "Nuova pagina"
:left-side-bar/nav-favorites "Preferiti" :left-side-bar/nav-favorites "Preferiti"

View File

@ -120,7 +120,7 @@
:page-name->original-name page-name->original-name}))))) :page-name->original-name page-name->original-name})))))
(defn build-page-graph (defn build-page-graph
[page theme] [page theme show-journal]
(let [dark? (= "dark" theme)] (let [dark? (= "dark" theme)]
(when-let [repo (state/get-current-repo)] (when-let [repo (state/get-current-repo)]
(let [page (util/page-name-sanity-lc page) (let [page (util/page-name-sanity-lc page)
@ -128,7 +128,7 @@
tags (:tags (:block/properties page-entity)) tags (:tags (:block/properties page-entity))
tags (remove #(= page %) tags) tags (remove #(= page %) tags)
ref-pages (db/get-page-referenced-pages repo page) ref-pages (db/get-page-referenced-pages repo page)
mentioned-pages (db/get-pages-that-mentioned-page repo page) mentioned-pages (db/get-pages-that-mentioned-page repo page show-journal)
namespaces (db/get-all-namespace-relation repo) namespaces (db/get-all-namespace-relation repo)
links (concat links (concat
namespaces namespaces
@ -148,7 +148,7 @@
(let [ref-pages (-> (map first (db/get-page-referenced-pages repo page)) (let [ref-pages (-> (map first (db/get-page-referenced-pages repo page))
(set) (set)
(set/intersection other-pages)) (set/intersection other-pages))
mentioned-pages (-> (map first (db/get-pages-that-mentioned-page repo page)) mentioned-pages (-> (map first (db/get-pages-that-mentioned-page repo page show-journal))
(set) (set)
(set/intersection other-pages))] (set/intersection other-pages))]
(concat (concat