|
|
@@ -5,34 +5,32 @@
|
|
|
[cljs-time.core :as t]
|
|
|
[cljs-time.local :as tl]
|
|
|
[clojure.string :as string]
|
|
|
- [frontend.config :as config]
|
|
|
[frontend.commands :as commands]
|
|
|
[frontend.components.block :as component-block]
|
|
|
[frontend.components.editor :as editor]
|
|
|
[frontend.components.macro :as component-macro]
|
|
|
[frontend.components.select :as component-select]
|
|
|
[frontend.components.svg :as svg]
|
|
|
+ [frontend.config :as config]
|
|
|
[frontend.context.i18n :refer [t]]
|
|
|
[frontend.date :as date]
|
|
|
[frontend.db :as db]
|
|
|
- [logseq.db :as ldb]
|
|
|
[frontend.db-mixins :as db-mixins]
|
|
|
[frontend.db.query-dsl :as query-dsl]
|
|
|
[frontend.db.query-react :as query-react]
|
|
|
+ [frontend.format.mldoc :as mldoc]
|
|
|
[frontend.handler.editor :as editor-handler]
|
|
|
[frontend.handler.property :as property-handler]
|
|
|
[frontend.handler.property.file :as property-file]
|
|
|
- [frontend.handler.block :as block-handler]
|
|
|
[frontend.modules.shortcut.core :as shortcut]
|
|
|
[frontend.state :as state]
|
|
|
[frontend.template :as template]
|
|
|
[frontend.ui :as ui]
|
|
|
[frontend.util :as util]
|
|
|
- [frontend.format.mldoc :as mldoc]
|
|
|
[frontend.util.file-based.drawer :as drawer]
|
|
|
[frontend.util.persist-var :as persist-var]
|
|
|
- [logseq.graph-parser.property :as gp-property]
|
|
|
[logseq.common.util.page-ref :as page-ref]
|
|
|
+ [logseq.graph-parser.property :as gp-property]
|
|
|
[logseq.shui.ui :as shui]
|
|
|
[medley.core :as medley]
|
|
|
[rum.core :as rum]))
|
|
|
@@ -121,22 +119,15 @@
|
|
|
|
|
|
(defn- reset-block-card-properties!
|
|
|
[block]
|
|
|
- (let [repo (state/get-current-repo)]
|
|
|
- (if (config/db-based-graph? repo)
|
|
|
- (do
|
|
|
- (property-handler/remove-block-property! repo (:block/uuid block) :logseq.property.fsrs/state)
|
|
|
- (property-handler/remove-block-property! repo (:block/uuid block) :logseq.property.fsrs/due))
|
|
|
- (save-block-card-properties! block {card-last-interval-property -1
|
|
|
- card-repeats-property 0
|
|
|
- card-last-easiness-factor-property 2.5
|
|
|
- card-last-reviewed-property "nil"
|
|
|
- card-next-schedule-property "nil"
|
|
|
- card-last-score-property "nil"}))))
|
|
|
-
|
|
|
+ (save-block-card-properties! block {card-last-interval-property -1
|
|
|
+ card-repeats-property 0
|
|
|
+ card-last-easiness-factor-property 2.5
|
|
|
+ card-last-reviewed-property "nil"
|
|
|
+ card-next-schedule-property "nil"
|
|
|
+ card-last-score-property "nil"}))
|
|
|
|
|
|
;;; used by other ns
|
|
|
|
|
|
-
|
|
|
(defn card-block?
|
|
|
[block]
|
|
|
(let [card-entity (db/get-page card-hash-tag)
|
|
|
@@ -199,11 +190,9 @@
|
|
|
[-1 1 ef next-of-matrix]
|
|
|
[(fix-2f next-interval) (+ 1 repeats) (fix-2f next-ef) next-of-matrix])))
|
|
|
|
|
|
-
|
|
|
;;; ================================================================
|
|
|
;;; card protocol
|
|
|
|
|
|
-
|
|
|
(defprotocol ICard
|
|
|
(get-root-block [this]))
|
|
|
|
|
|
@@ -213,7 +202,6 @@
|
|
|
|
|
|
(show-cycle-config [this phase]))
|
|
|
|
|
|
-
|
|
|
(defn- has-cloze?
|
|
|
[blocks]
|
|
|
(->> (map :block/title blocks)
|
|
|
@@ -283,8 +271,8 @@
|
|
|
query-string)
|
|
|
{query* :query :keys [sort-by rules]} (query-dsl/parse query-string {:db-graph? (config/db-based-graph? repo)})
|
|
|
query** (util/concat-without-nil
|
|
|
- [['?b :block/refs '?br] ['?br :block/name card-hash-tag]]
|
|
|
- (if (coll? (first query*)) query* [query*]))]
|
|
|
+ [['?b :block/refs '?br] ['?br :block/name card-hash-tag]]
|
|
|
+ (if (coll? (first query*)) query* [query*]))]
|
|
|
(when-let [query' (query-dsl/query-wrapper query**
|
|
|
{:blocks? true
|
|
|
:block-attrs [:db/id :block/properties]})]
|
|
|
@@ -318,11 +306,9 @@
|
|
|
{:total (count blocks)
|
|
|
:result sort-by-next-schedule}))
|
|
|
|
|
|
-
|
|
|
;;; ================================================================
|
|
|
;;; operations
|
|
|
|
|
|
-
|
|
|
(defn- get-next-interval
|
|
|
[card score]
|
|
|
{:pre [(and (<= score 5) (>= score 0))
|
|
|
@@ -635,8 +621,8 @@
|
|
|
(fn [{:keys [toggle-fn]}]
|
|
|
[:div.ml-1.text-sm.font-medium.cursor
|
|
|
{:on-pointer-down (fn [e]
|
|
|
- (util/stop e)
|
|
|
- (toggle-fn))}
|
|
|
+ (util/stop e)
|
|
|
+ (toggle-fn))}
|
|
|
[:span.flex (if (string/blank? query-string) (t :flashcards/modal-select-all) query-string)
|
|
|
[:span {:style {:margin-top 2}}
|
|
|
(svg/caret-down)]]])
|
|
|
@@ -678,8 +664,8 @@
|
|
|
{:icon "letter-a"
|
|
|
:intent "link"
|
|
|
:on-click (fn [e]
|
|
|
- (util/stop e)
|
|
|
- (swap! *preview-mode? not)
|
|
|
+ (util/stop e)
|
|
|
+ (swap! *preview-mode? not)
|
|
|
(reset! *card-index 0))
|
|
|
:button-props {:id "preview-all-cards"}
|
|
|
:small? true}
|
|
|
@@ -705,8 +691,8 @@
|
|
|
(when (and (not modal?) (not @*preview-mode?))
|
|
|
{:on-click (fn []
|
|
|
(shui/dialog-open!
|
|
|
- #(cards (assoc config :modal? true) {:query-string query-string})
|
|
|
- {:id :srs}))})
|
|
|
+ #(cards (assoc config :modal? true) {:query-string query-string})
|
|
|
+ {:id :srs}))})
|
|
|
(let [view-fn (if modal? view-modal view)
|
|
|
blocks (if @*preview-mode? query-result review-cards)
|
|
|
blocks (if @*random-mode? (shuffle blocks) blocks)]
|
|
|
@@ -793,52 +779,24 @@
|
|
|
"given a block struct, adds the #card to title and returns
|
|
|
a seq of [original-block new-content-string]"
|
|
|
[block]
|
|
|
- (when-let [content (:block/title block)]
|
|
|
- (let [format (:block/format block)
|
|
|
- content (-> (property-file/remove-built-in-properties-when-file-based
|
|
|
- (state/get-current-repo) (:block/format block) content)
|
|
|
- (drawer/remove-logbook))
|
|
|
- [title body] (mldoc/get-title&body content format)]
|
|
|
- [block (str title " #" card-hash-tag "\n" body)])))
|
|
|
-
|
|
|
-(defn- get-operating-blocks
|
|
|
- [block-ids]
|
|
|
- (some->> block-ids
|
|
|
- (map (fn [id] (db/entity [:block/uuid id])))
|
|
|
- (seq)
|
|
|
- block-handler/get-top-level-blocks
|
|
|
- (remove ldb/property?)))
|
|
|
+ (when-let [content (:block/title block)]
|
|
|
+ (let [format (:block/format block)
|
|
|
+ content (-> (property-file/remove-built-in-properties-when-file-based
|
|
|
+ (state/get-current-repo) (:block/format block) content)
|
|
|
+ (drawer/remove-logbook))
|
|
|
+ [title body] (mldoc/get-title&body content format)]
|
|
|
+ [block (str title " #" card-hash-tag "\n" body)])))
|
|
|
|
|
|
(defn batch-make-cards!
|
|
|
([] (batch-make-cards! (state/get-selection-block-ids)))
|
|
|
([block-ids]
|
|
|
- (if (config/db-based-graph? (state/get-current-repo))
|
|
|
- (let [blocks (get-operating-blocks block-ids)
|
|
|
- block-ids (map :block/uuid blocks)]
|
|
|
- (when (seq block-ids)
|
|
|
- (property-handler/batch-set-block-property! (state/get-current-repo)
|
|
|
- block-ids
|
|
|
- :block/tags
|
|
|
- (:db/id (db/entity :logseq.class/Card)))))
|
|
|
- (let [valid-blocks (->> block-ids
|
|
|
- (map #(db/entity [:block/uuid %]))
|
|
|
- (remove card-block?)
|
|
|
- (map #(db/pull [:block/uuid (:block/uuid %)])))
|
|
|
- blocks (map add-card-tag-to-block valid-blocks)]
|
|
|
- (when-not (empty? blocks)
|
|
|
- (editor-handler/save-blocks! blocks))))))
|
|
|
-
|
|
|
-(defn make-block-a-card!
|
|
|
- [block-id]
|
|
|
- (if (config/db-based-graph? (state/get-current-repo))
|
|
|
- (when-let [block-ids (when block-id [block-id])]
|
|
|
- (batch-make-cards! block-ids))
|
|
|
- (when-let [block (db/entity [:block/uuid block-id])]
|
|
|
- (let [block-content (add-card-tag-to-block block)
|
|
|
- new-content (get block-content 1)]
|
|
|
- (editor-handler/save-block! (state/get-current-repo) block-id new-content)))))
|
|
|
-
|
|
|
-
|
|
|
+ (let [valid-blocks (->> block-ids
|
|
|
+ (map #(db/entity [:block/uuid %]))
|
|
|
+ (remove card-block?)
|
|
|
+ (map #(db/pull [:block/uuid (:block/uuid %)])))
|
|
|
+ blocks (map add-card-tag-to-block valid-blocks)]
|
|
|
+ (when-not (empty? blocks)
|
|
|
+ (editor-handler/save-blocks! blocks)))))
|
|
|
|
|
|
(defonce *due-cards-interval (atom nil))
|
|
|
|