mirror of
https://github.com/penpot/penpot.git
synced 2025-05-11 00:56:38 +02:00
🎉 Add page ordering (with d&d).
This commit is contained in:
parent
11f54f51ea
commit
04d364225c
7 changed files with 91 additions and 51 deletions
|
@ -11,6 +11,7 @@
|
|||
(:require
|
||||
[clojure.spec.alpha :as s]
|
||||
[promesa.core :as p]
|
||||
[uxbox.common.data :as d]
|
||||
[uxbox.common.pages :as cp]
|
||||
[uxbox.common.exceptions :as ex]
|
||||
[uxbox.common.spec :as us]
|
||||
|
@ -106,6 +107,33 @@
|
|||
|
||||
|
||||
|
||||
;; --- Mutation: Sort Pages
|
||||
|
||||
(s/def ::page-ids (s/every ::us/uuid :kind vector?))
|
||||
(s/def ::reorder-pages
|
||||
(s/keys :req-un [::profile-id ::file-id ::page-ids]))
|
||||
|
||||
(declare update-page-ordering)
|
||||
|
||||
(sm/defmutation ::reorder-pages
|
||||
[{:keys [profile-id file-id page-ids]}]
|
||||
(db/with-atomic [conn db/pool]
|
||||
(p/run! #(update-page-ordering conn file-id %)
|
||||
(d/enumerate page-ids))
|
||||
nil))
|
||||
|
||||
(def ^:private sql:update-page-ordering
|
||||
"update page
|
||||
set ordering = $1
|
||||
where id = $2 and file_id = $3")
|
||||
|
||||
(defn- update-page-ordering
|
||||
[conn file-id [ordering page-id]]
|
||||
(-> (db/query-one conn [sql:update-page-ordering ordering page-id file-id])
|
||||
(p/then su/constantly-nil)))
|
||||
|
||||
|
||||
|
||||
;; --- Mutation: Generate Share Token
|
||||
|
||||
(declare assign-page-share-token)
|
||||
|
|
|
@ -93,7 +93,7 @@
|
|||
and (fp_r.is_admin = true or
|
||||
fp_r.is_owner = true or
|
||||
fp_r.can_edit = true)
|
||||
window pages_w as (partition by f.id order by pg.created_at
|
||||
window pages_w as (partition by f.id order by pg.ordering
|
||||
range between unbounded preceding
|
||||
and unbounded following)
|
||||
order by f.modified_at desc")
|
||||
|
@ -182,7 +182,7 @@
|
|||
where f.id = $1
|
||||
and f.deleted_at is null
|
||||
and pg.deleted_at is null
|
||||
window pages_w as (partition by f.id order by pg.created_at
|
||||
window pages_w as (partition by f.id order by pg.ordering
|
||||
range between unbounded preceding
|
||||
and unbounded following)")
|
||||
|
||||
|
@ -229,22 +229,6 @@
|
|||
(check-edition-permissions! conn profile-id id)
|
||||
(retrieve-file conn id)))
|
||||
|
||||
;; --- Query: Project Files
|
||||
|
||||
;; (declare retrieve-project-files)
|
||||
|
||||
;; (s/def ::project-files
|
||||
;; (s/keys :req-un [::profile-id]
|
||||
;; :opt-un [::project-id]))
|
||||
|
||||
;; (sq/defquery ::project-files
|
||||
;; [{:keys [project-id] :as params}]
|
||||
;; (retrieve-project-files db/pool params))
|
||||
|
||||
;; (defn retrieve-project-files
|
||||
;; [conn {:keys [profile-id project-id]}]
|
||||
;; (-> (db/query conn [sql:project-files profile-id project-id])
|
||||
;; (p/then' (partial mapv decode-row))))
|
||||
|
||||
;; --- Helpers
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
and (fp_r.is_admin = true or
|
||||
fp_r.is_owner = true or
|
||||
fp_r.can_edit = true)
|
||||
window pages_w as (partition by f.id order by pg.created_at
|
||||
window pages_w as (partition by f.id order by pg.ordering
|
||||
range between unbounded preceding
|
||||
and unbounded following)
|
||||
order by f.modified_at desc
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue