wip, new version of add property test

pull/2456/head
Weihua Lu 2021-07-14 15:37:49 +08:00
parent 828e296f86
commit adbf5a1674
6 changed files with 93 additions and 17 deletions

View File

@ -1,14 +1,15 @@
(ns frontend.date (ns frontend.date
(:require [cljs-time.core :as t] (:require ["chrono-node" :as chrono]
[cljs-bean.core :as bean]
[cljs-time.coerce :as tc] [cljs-time.coerce :as tc]
[cljs-time.core :as t]
[cljs-time.format :as tf] [cljs-time.format :as tf]
[cljs-time.local :as tl] [cljs-time.local :as tl]
[frontend.state :as state]
[cljs-bean.core :as bean]
[frontend.util :as util]
[clojure.string :as string] [clojure.string :as string]
[frontend.state :as state]
[frontend.util :as util]
[goog.object :as gobj] [goog.object :as gobj]
["chrono-node" :as chrono])) [lambdaisland.glogi :as log]))
(defn nld-parse (defn nld-parse
[s] [s]
@ -100,6 +101,14 @@
([date] ([date]
(format date))) (format date)))
(defn journal-name-s [s]
(try
(journal-name (tf/parse s))
(catch js/Error e
(log/error :parse-journal-date {:message "Failed to parse date to journal name"
:date-str s})
nil)))
(defn today (defn today
[] []
(journal-name)) (journal-name))

View File

@ -44,7 +44,10 @@
(get* config (str "/items/" key))) (get* config (str "/items/" key)))
(comment (comment
(get* config "/collections" {:limit 1}) (get* config "/collections")
(get* config "/items" {:limit 3}) (get* config "/items" {:limit 3})
(get* config "/items" {:item-type "journalArticle"}) (get* config "/items" {:item-type "journalArticle"})
(item "JZCIN4K5")) (item "JZCIN4K5")
(item "RFYNAQTN")
(item "3V6N8ECQ")
)

View File

@ -2,6 +2,7 @@
(:require [clojure.string :as str] (:require [clojure.string :as str]
[frontend.util :as util] [frontend.util :as util]
[frontend.extensions.zotero.schema :as schema] [frontend.extensions.zotero.schema :as schema]
[frontend.date :as date]
[frontend.extensions.zotero.api :as api])) [frontend.extensions.zotero.api :as api]))
(defn item-type [item] (-> item :data :item-type)) (defn item-type [item] (-> item :data :item-type))
@ -44,14 +45,31 @@
(mapv (fn [{:keys [tag]}] (util/format "[[%s]]" tag))))] (mapv (fn [{:keys [tag]}] (util/format "[[%s]]" tag))))]
(str/join ", " tags))) (str/join ", " tags)))
(defn date->journal [item]
(let [date (-> item :data :date)]
(when-not (str/blank? date)
(->> (date/journal-name-s date)
(util/format "[[%s]]")))))
(defn wrap-in-doublequotes [m]
(->> m
(map (fn [[k v]]
(if (str/includes? (str v) ",")
[k (pr-str v)]
[k v])))
(into (array-map))))
(defn properties [item] (defn properties [item]
(let [fields (schema/fields "journalArticle") (let [fields (schema/fields "journalArticle")
authors (authors item) authors (authors item)
tags (tags item) tags (tags item)
date (date->journal item)
data (-> item :data data (-> item :data
(select-keys fields) (select-keys fields)
(wrap-in-doublequotes)
(assoc :authors authors (assoc :authors authors
:tags tags) :tags tags
:date date)
(dissoc :creators :extra))] (dissoc :creators :extra))]
(->> data (->> data
(remove (comp str/blank? second)) (remove (comp str/blank? second))

View File

@ -2,20 +2,61 @@
(:require [frontend.handler.page :as page-handler] (:require [frontend.handler.page :as page-handler]
[frontend.extensions.zotero.api :as zotero-api] [frontend.extensions.zotero.api :as zotero-api]
[cljs.core.async :refer [go <!]] [cljs.core.async :refer [go <!]]
[frontend.util.property :as property-util]
[frontend.handler.editor :as editor-handler]
[frontend.state :as state]
[frontend.db :as db]
[frontend.extensions.zotero.extractor :as extractor] [frontend.extensions.zotero.extractor :as extractor]
[clojure.string :as str])) [clojure.string :as str]))
;; FIXME need to quote the property value
(defn create-zotero-page [key] (defn create-zotero-page [key]
(go (go
(let [item (<! (zotero-api/item key)) (let [item (<! (zotero-api/item key))
{:keys [page-name properties]} (extractor/extract item)] {:keys [page-name properties]} (extractor/extract item)]
(page-handler/create! page-name {:redirect? false :format :markdown}) (page-handler/create! page-name {:redirect? false :format :markdown})
(doseq [[field value] properties] (editor-handler/api-insert-new-block!
(page-handler/page-add-property! page-name field value)) ""
{:page page-name
:properties properties})
(js/alert "finish")))) (js/alert "finish"))))
(comment (comment
(create-zotero-page "JAHCZRNB") (create-zotero-page "JAHCZRNB")
(create-zotero-page "RFYNAQTN")) (create-zotero-page "RFYNAQTN")
(create-zotero-page "3V6N8ECQ")
(def page-name (:page-name (extractor/extract zotero-api/rr)))
(def properties (:properties (extractor/extract zotero-api/rr)))
;; this is good
(editor-handler/api-insert-new-block!
"abcabc"
{:page page-name
;; :properties properties
})
;; outliner error
(editor-handler/api-insert-new-block!
""
{:page page-name
:properties properties})
#_
(item "3V6N8ECQ")
;; (db/get-page-blocks)
;; (page-handler/page-add-property! )
;; (editor-handler/insert-new-block-aux! )
;; (db/entity [:block/name (str/lower-case "@picardMITMediaLaboratory")])
;; (db/get-page-blocks "ccc")
;; (def block (state/get-edit-block))
#_
(editor-handler/save-block-if-changed!
block
(property-util/insert-property :markdown "xxx" :test "value")
{:force? true}))

View File

@ -38,7 +38,7 @@
#?(:cljs #?(:cljs
(defn transact! (defn transact!
[txs opts] [txs opts]
;; (util/pprint txs) (util/pprint txs)
(when (and (seq txs) (when (and (seq txs)
(not (:skip-transact? opts))) (not (:skip-transact? opts)))
(try (try

View File

@ -7482,6 +7482,11 @@ react-grid-layout@^0.16.6:
react-draggable "3.x" react-draggable "3.x"
react-resizable "1.x" react-resizable "1.x"
react-icon-base@2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/react-icon-base/-/react-icon-base-2.1.0.tgz#a196e33fdf1e7aaa1fda3aefbb68bdad9e82a79d"
integrity sha1-oZbjP98eeqof2jrvu2i9rZ6Cp50=
react-icons@^2.2.7: react-icons@^2.2.7:
version "2.2.7" version "2.2.7"
resolved "https://registry.yarnpkg.com/react-icons/-/react-icons-2.2.7.tgz#d7860826b258557510dac10680abea5ca23cf650" resolved "https://registry.yarnpkg.com/react-icons/-/react-icons-2.2.7.tgz#d7860826b258557510dac10680abea5ca23cf650"