|
409 | 409 | block)] |
410 | 410 | block')) |
411 | 411 |
|
| 412 | +(def ^:private built-in-status-markers |
| 413 | + {"TODO" :logseq.property/status.todo |
| 414 | + "LATER" :logseq.property/status.todo |
| 415 | + "NOW" :logseq.property/status.doing |
| 416 | + "DOING" :logseq.property/status.doing |
| 417 | + "DONE" :logseq.property/status.done |
| 418 | + "CANCELED" :logseq.property/status.canceled |
| 419 | + "CANCELLED" :logseq.property/status.canceled}) |
| 420 | + |
| 421 | +(def ^:private custom-status-marker? |
| 422 | + #{"WAIT" "WAITING" "IN-PROGRESS"}) |
| 423 | + |
| 424 | +(defn- find-status-choice-by-content |
| 425 | + [db marker] |
| 426 | + (some #(when (= marker (db-property/closed-value-content %)) %) |
| 427 | + (db-property/get-closed-property-values db :logseq.property/status))) |
| 428 | + |
| 429 | +(defn- build-status-choice-tx |
| 430 | + [marker block-uuid] |
| 431 | + (assoc (db-property-build/build-closed-value-block |
| 432 | + block-uuid |
| 433 | + :default |
| 434 | + marker |
| 435 | + {:db/ident :logseq.property/status} |
| 436 | + {}) |
| 437 | + :block/order (db-order/gen-key))) |
| 438 | + |
| 439 | +(defn- custom-marker-status-ref |
| 440 | + [db marker {:keys [import-state custom-status-tx]}] |
| 441 | + (or (get @(:custom-status-markers import-state) marker) |
| 442 | + (let [status-ref (if-let [status (find-status-choice-by-content db marker)] |
| 443 | + (:db/id status) |
| 444 | + (let [block-uuid (common-uuid/gen-uuid)] |
| 445 | + (swap! custom-status-tx conj (build-status-choice-tx marker block-uuid)) |
| 446 | + [:block/uuid block-uuid]))] |
| 447 | + (swap! (:custom-status-markers import-state) assoc marker status-ref) |
| 448 | + status-ref))) |
| 449 | + |
412 | 450 | (defn- update-block-marker |
413 | 451 | "If a block has a marker, convert it to a task object" |
414 | | - [block {:keys [log-fn]}] |
| 452 | + [block db {:keys [log-fn] :as options}] |
415 | 453 | (if-let [marker (:block/marker block)] |
416 | | - (let [old-to-new {"TODO" :logseq.property/status.todo |
417 | | - "LATER" :logseq.property/status.todo |
418 | | - "IN-PROGRESS" :logseq.property/status.doing |
419 | | - "NOW" :logseq.property/status.doing |
420 | | - "DOING" :logseq.property/status.doing |
421 | | - "DONE" :logseq.property/status.done |
422 | | - "WAIT" :logseq.property/status.backlog |
423 | | - "WAITING" :logseq.property/status.backlog |
424 | | - "CANCELED" :logseq.property/status.canceled |
425 | | - "CANCELLED" :logseq.property/status.canceled} |
426 | | - status-ident (or (old-to-new marker) |
427 | | - (do |
428 | | - (log-fn :invalid-todo (str (pr-str marker) " is not a valid marker so setting it to TODO")) |
429 | | - :logseq.property/status.todo))] |
| 454 | + (let [status-ident (cond |
| 455 | + (contains? built-in-status-markers marker) |
| 456 | + (built-in-status-markers marker) |
| 457 | + |
| 458 | + (custom-status-marker? marker) |
| 459 | + (custom-marker-status-ref db marker options) |
| 460 | + |
| 461 | + :else |
| 462 | + (do |
| 463 | + (log-fn :invalid-todo (str (pr-str marker) " is not a valid marker so setting it to TODO")) |
| 464 | + :logseq.property/status.todo))] |
430 | 465 | (-> block |
431 | 466 | (assoc :logseq.property/status status-ident) |
432 | 467 | (update :block/title string/replace-first (re-pattern (str marker "\\s*")) "") |
|
1850 | 1885 | (handle-embeds page-names-to-uuids walked-ast-blocks (select-keys options [:log-fn])) |
1851 | 1886 | (handle-quotes (select-keys options [:log-fn])) |
1852 | 1887 | (handle-math) |
1853 | | - (update-block-marker options) |
| 1888 | + (update-block-marker db options) |
1854 | 1889 | (update-block-priority options) |
1855 | 1890 | add-missing-timestamps |
1856 | 1891 | (dissoc :block/format :block.temp/ast-blocks) |
|
2105 | 2140 | :all-idents (atom {}) |
2106 | 2141 | ;; Set of children pages turned into classes by :property-parent-classes option |
2107 | 2142 | :classes-from-property-parents (atom #{}) |
| 2143 | + ;; Map of imported legacy task markers to their Status closed value lookup refs. |
| 2144 | + :custom-status-markers (atom {}) |
2108 | 2145 | ;; Map of block uuids to their :block/properties-text-values value. |
2109 | 2146 | ;; Used if a property value changes to :default |
2110 | 2147 | :block-properties-text-values (atom {}) |
|
2120 | 2157 | :upstream-properties (atom {}) |
2121 | 2158 | ;; Track per file class tx so that their tx isn't embedded in individual :block/tags and can be post processed |
2122 | 2159 | :classes-tx (atom []) |
| 2160 | + ;; Track per file Status closed values required by imported legacy task markers. |
| 2161 | + :custom-status-tx (atom []) |
2123 | 2162 | :user-options |
2124 | 2163 | (merge user-options |
2125 | 2164 | {:tag-classes (set (map string/lower-case (:tag-classes user-options))) |
|
2354 | 2393 | classes-tx @(:classes-tx tx-options) |
2355 | 2394 | {:keys [retract-page-tags-tx] pages-tx'' :pages-tx} (clean-extra-invalid-tags @conn pages-tx' classes-tx existing-pages) |
2356 | 2395 | classes-tx' (concat classes-tx retract-page-tags-tx) |
| 2396 | + custom-status-tx @(:custom-status-tx tx-options) |
2357 | 2397 | ;; Build indices |
2358 | 2398 | pages-index (->> (map #(select-keys % [:block/uuid]) pages-tx'') |
2359 | 2399 | (concat (map #(select-keys % [:block/uuid]) classes-tx)) |
|
2368 | 2408 | blocks-index (set/union (set block-ids) (set block-refs-ids)) |
2369 | 2409 | ;; Order matters. pages-index and blocks-index needs to come before their corresponding tx for |
2370 | 2410 | ;; uuids to be valid. Also upstream-properties-tx comes after blocks-tx to possibly override blocks |
2371 | | - tx (concat pages-index page-properties-tx property-page-properties-tx pages-tx'' classes-tx' blocks-index blocks-tx) |
| 2411 | + tx (concat pages-index page-properties-tx property-page-properties-tx pages-tx'' classes-tx' custom-status-tx blocks-index blocks-tx) |
2372 | 2412 | tx' (common-util/fast-remove-nils tx) |
2373 | 2413 | ;; _ (prn :tx-counts (map #(vector %1 (count %2)) |
2374 | 2414 | ;; [:pages-index :page-properties-tx :property-page-properties-tx :pages-tx' :classes-tx :blocks-index :blocks-tx] |
|
0 commit comments