|
258 | 258 | :logseq.property.class/extends |
259 | 259 | (:db/id extend)))) |
260 | 260 |
|
| 261 | +(defn- resolve-tag-eid [this class-uuid-or-ident-or-title] |
| 262 | + (let [eid (if (number? class-uuid-or-ident-or-title) |
| 263 | + class-uuid-or-ident-or-title |
| 264 | + (let [title-or-ident (-> (if-not (string? class-uuid-or-ident-or-title) |
| 265 | + (str class-uuid-or-ident-or-title) |
| 266 | + class-uuid-or-ident-or-title) |
| 267 | + (string/replace #"^:+" ""))] |
| 268 | + (if (text/namespace-page? title-or-ident) |
| 269 | + (keyword title-or-ident) |
| 270 | + (if (util/uuid-string? title-or-ident) |
| 271 | + (when-let [id (sdk-utils/uuid-or-throw-error title-or-ident)] |
| 272 | + [:block/uuid id]) |
| 273 | + (keyword (api-block/resolve-class-prefix-for-db this) title-or-ident)))))] |
| 274 | + eid)) |
| 275 | + |
261 | 276 | (defn get-tag [class-uuid-or-ident-or-title] |
262 | 277 | (this-as this |
263 | | - (let [eid (if (number? class-uuid-or-ident-or-title) |
264 | | - class-uuid-or-ident-or-title |
265 | | - (let [title-or-ident (-> (if-not (string? class-uuid-or-ident-or-title) |
266 | | - (str class-uuid-or-ident-or-title) |
267 | | - class-uuid-or-ident-or-title) |
268 | | - (string/replace #"^:+" ""))] |
269 | | - (if (text/namespace-page? title-or-ident) |
270 | | - (keyword title-or-ident) |
271 | | - (if (util/uuid-string? title-or-ident) |
272 | | - (when-let [id (sdk-utils/uuid-or-throw-error title-or-ident)] |
273 | | - [:block/uuid id]) |
274 | | - (keyword (api-block/resolve-class-prefix-for-db this) title-or-ident))))) |
275 | | - tag (db/entity eid)] |
276 | | - (when (ldb/class? tag) |
277 | | - (sdk-utils/result->js tag))))) |
| 278 | + (let [eid (resolve-tag-eid this class-uuid-or-ident-or-title) |
| 279 | + tag (db/entity eid)] |
| 280 | + (when (ldb/class? tag) |
| 281 | + (sdk-utils/result->js tag))))) |
278 | 282 |
|
279 | 283 | (defn get-tags-by-name [name] |
280 | 284 | (when-let [tags (some->> (entity-util/get-pages-by-name (db-conn/get-db) name) |
|
304 | 308 | (sdk-utils/result->js (db/get-case-page tag-id))))) |
305 | 309 |
|
306 | 310 | (defn add-block-tag [id-or-name tag-id] |
307 | | - (p/let [repo (state/get-current-repo) |
308 | | - tag (db-async/<get-block repo tag-id) |
309 | | - block (db-async/<get-block repo id-or-name)] |
310 | | - (when-not (ldb/class? tag) |
311 | | - (throw (ex-info (str "Not a tag: " tag-id) |
312 | | - {:tag tag}))) |
313 | | - (when (and tag block) |
314 | | - (db-page-handler/add-tag repo (:db/id block) tag)))) |
| 311 | + (this-as this |
| 312 | + (p/let [repo (state/get-current-repo) |
| 313 | + block (db-async/<get-block repo id-or-name) |
| 314 | + tag-eid (resolve-tag-eid this tag-id) |
| 315 | + tag (or (db/entity tag-eid) |
| 316 | + (db-async/<get-block repo tag-id))] |
| 317 | + (when-not (ldb/class? tag) |
| 318 | + (throw (ex-info (str "Not a tag: " tag-id) |
| 319 | + {:tag (pr-str tag)}))) |
| 320 | + (when (and tag block) |
| 321 | + (db-page-handler/add-tag repo (:db/id block) tag))))) |
315 | 322 |
|
316 | 323 | (defn remove-block-tag [id-or-name tag-id] |
317 | | - (p/let [repo (state/get-current-repo) |
318 | | - block (db-async/<get-block repo id-or-name) |
319 | | - tag (db-async/<get-block repo tag-id)] |
320 | | - (when-not (ldb/class? tag) |
321 | | - (throw (ex-info (str "Not a tag: " tag-id) |
322 | | - {:tag tag}))) |
323 | | - (when (and block tag) |
324 | | - (db-property-handler/delete-property-value! |
325 | | - (:db/id block) :block/tags (:db/id tag))))) |
| 324 | + (this-as this |
| 325 | + (p/let [repo (state/get-current-repo) |
| 326 | + block (db-async/<get-block repo id-or-name) |
| 327 | + tag-eid (resolve-tag-eid this tag-id) |
| 328 | + tag (or (db/entity tag-eid) |
| 329 | + (db-async/<get-block repo tag-id))] |
| 330 | + (when-not (ldb/class? tag) |
| 331 | + (throw (ex-info (str "Not a tag: " tag-id) |
| 332 | + {:tag tag}))) |
| 333 | + (when (and block tag) |
| 334 | + (db-property-handler/delete-property-value! |
| 335 | + (:db/id block) :block/tags (:db/id tag)))))) |
326 | 336 |
|
327 | 337 | (defn set-block-icon |
328 | 338 | [block-id icon-type icon-name] |
|
342 | 352 | :id (if (= icon-type "emoji") |
343 | 353 | (:id (first (name->emoji icon-name))) |
344 | 354 | icon-name)}))) |
| 355 | + |
345 | 356 | (defn remove-block-icon |
346 | 357 | [block-id] |
347 | 358 | (p/let [repo (state/get-current-repo) |
|
0 commit comments