Skip to content

Commit

Permalink
project cards, fix asset handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mhuebert committed Jan 14, 2024
1 parent 3371ec3 commit 22935d0
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 47 deletions.
3 changes: 2 additions & 1 deletion src/sb/app/board/data.cljc
Expand Up @@ -70,7 +70,7 @@
(? :entity/social-feed)
(? :entity/deleted-at)
(? :entity/created-by)

(? :entity/uploads)
(? :board/custom-css)
(? :board/custom-js)
(? :board/home-page-message)
Expand Down Expand Up @@ -130,6 +130,7 @@
:membership/roles])

(def project-fields `[~@entity.data/listing-fields
:entity/field-entries
{:entity/video [:video/url]}
{:entity/parent [:entity/id]}
{:membership/_entity [~@entity.data/id-fields
Expand Down
1 change: 1 addition & 0 deletions src/sb/app/collection/data.cljc
Expand Up @@ -8,6 +8,7 @@
:entity/kind
:collection/boards
:entity/title
(? :entity/uploads)
(? :entity/domain-name)
(? :image/avatar)
(? :image/background)]}})
1 change: 1 addition & 0 deletions src/sb/app/entity/data.cljc
Expand Up @@ -66,6 +66,7 @@
:entity/website {:doc "External website for entity"
s- :http/url}
:entity/social-feed {s- :social/feed}
:entity/uploads (sch/ref :many)
:entity/images {s- [:map-of
[:qualified-keyword {:namespace :image}]
:http/url]}
Expand Down
10 changes: 7 additions & 3 deletions src/sb/app/field/ui.cljc
Expand Up @@ -624,9 +624,13 @@
:field.type/prose [prose-field ?entry props]
(str "no match" field))))

(defn show-image-list:card [{:keys [image-list/images]}]
(when-let [{:keys [entity/id]} (first images)]
[:img.max-h-80 {:src (asset.ui/asset-src id :card)}]))
(defn show-image-list:card [field {:keys [image-list/images]}]
(when-let [image (first images)]
[:img.max-h-80 {:src (asset.ui/asset-src image :card)}]))

(comment
(sb.server.datalevin/entity [:entity/id #uuid "b30e4733-0c90-3491-be07-99af22250f92"])
(sch/kind #uuid "b30e4733-0c90-3491-be07-99af22250f92"))

(ui/defview show-prose:card [field {:as m :prose/keys [format string]}]
(when-not (str/blank? string)
Expand Down
2 changes: 1 addition & 1 deletion src/sb/app/membership/data.cljc
Expand Up @@ -54,7 +54,7 @@
:entity/kind
:membership/entity
:membership/member

(? :entity/uploads)
(? :membership/inactive?)
(? :membership/email-frequency)
(? :entity/custom-tags)
Expand Down
1 change: 1 addition & 0 deletions src/sb/app/org/data.cljc
Expand Up @@ -19,6 +19,7 @@
:entity/title
:entity/kind
:entity/created-by
(? :entity/uploads)
(? :image/avatar)
(? :image/background)
(? :image/sub-header)
Expand Down
1 change: 1 addition & 0 deletions src/sb/app/project/data.cljc
Expand Up @@ -46,6 +46,7 @@
:entity/parent
:entity/title
:entity/created-at
(? :entity/uploads)
(? :entity/updated-at)
(? :entity/draft?)
(? :entity/archived?)
Expand Down
6 changes: 4 additions & 2 deletions src/sb/app/project/ui.cljc
Expand Up @@ -203,17 +203,19 @@
{:as entity
:keys [entity/parent
entity/title
entity/description
entity/field-entries
membership/roles]}]
(let [board-members (->> (:membership/_entity entity) (mapv :membership/member))]
[:a.flex-v.hover:bg-gray-100.rounded-lg.bg-slate-100.py-3.gap-3.
{:href (routing/entity-path entity 'ui/show)}


[:div.flex.relative.gap-3.items-start.px-3.cursor-default.flex-auto
[:div.flex-grow.flex-v.gap-1
[:div.leading-snug.line-clamp-2.font-semibold.text-lg title]
[:div.text-gray-500.contents (field.ui/show-entries project-fields field-entries)]]]
[:div.text-gray-500 description]
[:div.text-gray-500.contents
(field.ui/show-entries project-fields field-entries)]]]

;; TEAM
[:div.flex.flex-wrap.gap-2.px-3
Expand Down
3 changes: 2 additions & 1 deletion src/sb/build.clj
Expand Up @@ -7,7 +7,8 @@
[sb.migrate.one-time :as one-time]
[sb.routing :as routing]
[sb.server.core]
[sb.transit :as t]))
[sb.transit :as t]
[sb.util :as u]))

(comment
(require '[shadow.cljs.devtools.api :as shadow])
Expand Down
56 changes: 27 additions & 29 deletions src/sb/migrate/one_time.clj
Expand Up @@ -450,8 +450,6 @@
(re-find #"youtube" v) v
:else (str "https://www.youtube.com/watch?v=" v))))

(def ^:dynamic *assets* nil)

(defn parse-fields [managed-by-k to-k]
(fn [m]
(if-some [field-ks (->> (keys m)
Expand All @@ -460,30 +458,32 @@
(let [managed-by (managed-by-k m)]
(try
(reduce (fn [m k]
(let [field-id (composite-uuid :field
(to-uuid :board managed-by)
(to-uuid :field (subs (name k) 6)))
v (m k)
field-type (:field/type (@!all-fields field-id))
(let [field-id (composite-uuid :field
(to-uuid :board managed-by)
(to-uuid :field (subs (name k) 6)))
v (m k)
field-type (:field/type (@!all-fields field-id))
image-list-assets (when (= field-type :field.type/image-list)
(mapv assets/link-asset (cond-> v (string? v) vector)))
;; NOTE - we ignore fields that do not have a spec
entry-value (when field-type
(case field-type
:field.type/image-list (let [v (cond-> v (string? v) vector)]
(when (seq v)
(let [assets (mapv assets/link-asset v)]
(some-> *assets* (swap! into assets))
{:image-list/images (mapv #(select-keys % [:entity/id]) assets)})))
:field.type/link-list {:link-list/links
(mapv #(rename-keys % {:label :link/label
:url :link/url}) v)}
:field.type/select {:select/value v}
:field.type/prose (prose v)
:field.type/video {:video/url (video-url v)}
(throw (Exception. (str "Field type not found "
{:field/type field-type
:field-spec/id field-id
})))))]
entry-value (when field-type
(case field-type
:field.type/image-list (when (seq image-list-assets)
{:image-list/images (mapv #(select-keys % [:entity/id])
image-list-assets)})
:field.type/link-list {:link-list/links
(mapv #(rename-keys % {:label :link/label
:url :link/url}) v)}
:field.type/select {:select/value v}
:field.type/prose (prose v)
:field.type/video {:video/url (video-url v)}
(throw (Exception. (str "Field type not found "
{:field/type field-type
:field-spec/id field-id
})))))]
(-> (dissoc m k)
(cond-> (seq image-list-assets)
(update :entity/uploads (fnil into []) image-list-assets))
(cond-> entry-value
(assoc-in [to-k field-id] entry-value)))))
m
Expand Down Expand Up @@ -1268,11 +1268,9 @@

(defn all-entities
"Flat list of all entities (no inline nesting)" []
(binding [*assets* (atom [])]
(let [entities (into []
(flatten-entities-xf)
(root-entities))]
(into entities @*assets*))))
(into []
(flatten-entities-xf)
(root-entities)))

(defn contains-somewhere?
"Deep walk of a data structure to see if `v` exists anywhere inside it (via =)"
Expand Down
21 changes: 11 additions & 10 deletions src/sb/server/assets.clj
Expand Up @@ -2,15 +2,13 @@
(:require [amazonica.aws.s3 :as s3]
[clj-http.client :as http]
[clojure.java.io :as io]
[ring.util.response :as resp]
[sb.authorize :as az]
[re-db.api :as db]
[sb.server.datalevin :as dl]
[sb.server.env :as env]
[sb.server.images :as images]
[sb.util :as u]
[sb.validate :as sv]
[sb.validate :as validate]
[re-db.api :as db]))
[sb.validate :as validate]))

(defn init-db!
"Ensure current bucket is in the db"
Expand Down Expand Up @@ -117,8 +115,7 @@
(or (dl/entity lookup-ref)
(do (dl/transact! [(-> #:asset.variant{:provider (:db/id provider)
:params param-string}
(validate/assert :asset.variant/as-map)
(assoc :db/id -1))])
(validate/assert :asset.variant/as-map))])
(dl/entity lookup-ref)))))

(defn ensure-content-type!
Expand All @@ -144,7 +141,8 @@
(case (:asset.provider/type provider)
:asset.provider/s3 (str (:s3/bucket-host provider)
"/"
(:entity/id asset))))
(:entity/id asset))
(throw (ex-info "Unknown provider" {:provider provider :asset (datalevin.core/touch asset)}))))

(defn asset-link [asset]
(or (:asset/link asset)
Expand Down Expand Up @@ -185,6 +183,9 @@
(variant-link asset variant)))))

(comment
(variant-link! (datalevin.core/entity @(re-db.api/conn) [:entity/id #uuid "b3665e87-4be8-301d-94e3-4417038ed016"])
{:op "bound" :width 200 :height 200}
))
(let [entity-id [:entity/id #uuid"b30e4733-0c90-3491-be07-99af22250f92"]
profile-pic [:entity/id #uuid "b3665e87-4be8-301d-94e3-4417038ed016"]]
#_(variant-link! (datalevin.core/entity @(re-db.api/conn) entitiy-id)
{:op "bound" :width 200 :height 200}
)
(datalevin.core/touch (datalevin.core/entity @(re-db.api/conn) entity-id))))

0 comments on commit 22935d0

Please sign in to comment.