mirror of
https://github.com/penpot/penpot.git
synced 2025-05-10 15:06:38 +02:00
🕐 adds recent opened files screen
This commit is contained in:
parent
1ffca33be9
commit
561560ae04
20 changed files with 437 additions and 250 deletions
|
@ -21,6 +21,7 @@
|
|||
(require 'uxbox.services.queries.files)
|
||||
(require 'uxbox.services.queries.pages)
|
||||
(require 'uxbox.services.queries.profile)
|
||||
(require 'uxbox.services.queries.recent-files)
|
||||
;; (require 'uxbox.services.queries.user-attrs)
|
||||
)
|
||||
|
||||
|
|
|
@ -20,7 +20,9 @@
|
|||
|
||||
(def ^:private sql:projects
|
||||
"with projects as (
|
||||
select p.*
|
||||
select p.*,
|
||||
(select count(*) from file as f
|
||||
where f.project_id = p.id and deleted_at is null) as file_count
|
||||
from project as p
|
||||
inner join team_profile_rel as tpr on (tpr.team_id = p.team_id)
|
||||
where tpr.profile_id = $1
|
||||
|
@ -28,7 +30,9 @@
|
|||
tpr.is_owner = true or
|
||||
tpr.can_edit = true)
|
||||
union
|
||||
select p.*
|
||||
select p.*,
|
||||
(select count(*) from file as f
|
||||
where f.project_id = p.id and deleted_at is null)
|
||||
from project as p
|
||||
inner join project_profile_rel as ppr on (ppr.project_id = p.id)
|
||||
where ppr.profile_id = $1
|
||||
|
@ -47,7 +51,10 @@
|
|||
(s/def ::projects-by-team
|
||||
(s/keys :req-un [::profile-id ::team-id]))
|
||||
|
||||
(sq/defquery ::projects-by-team
|
||||
[{:keys [profile-id team-id] :as params}]
|
||||
(defn projects-by-team [profile-id team-id]
|
||||
(db/query db/pool [sql:projects profile-id team-id]))
|
||||
|
||||
(sq/defquery ::projects-by-team
|
||||
[{:keys [profile-id team-id]}]
|
||||
(projects-by-team profile-id team-id))
|
||||
|
||||
|
|
58
backend/src/uxbox/services/queries/recent_files.clj
Normal file
58
backend/src/uxbox/services/queries/recent_files.clj
Normal file
|
@ -0,0 +1,58 @@
|
|||
;; This Source Code Form is subject to the terms of the Mozilla Public
|
||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
;;
|
||||
;; This Source Code Form is "Incompatible With Secondary Licenses", as
|
||||
;; defined by the Mozilla Public License, v. 2.0.
|
||||
;;
|
||||
;; Copyright (c) 2019-2020 Andrey Antukh <niwi@niwi.nz>
|
||||
|
||||
(ns uxbox.services.queries.recent-files
|
||||
(:require
|
||||
[clojure.spec.alpha :as s]
|
||||
[promesa.core :as p]
|
||||
[uxbox.db :as db]
|
||||
[uxbox.common.spec :as us]
|
||||
[uxbox.services.queries :as sq]
|
||||
[uxbox.services.queries.projects :refer [ projects-by-team ]]
|
||||
[uxbox.services.queries.files :refer [ decode-row ]]))
|
||||
|
||||
(def ^:private sql:project_files_recent
|
||||
"select distinct
|
||||
f.*,
|
||||
array_agg(pg.id) over pages_w as pages,
|
||||
first_value(pg.data) over pages_w as data
|
||||
from file as f
|
||||
inner join file_profile_rel as fp_r on (fp_r.file_id = f.id)
|
||||
left join page as pg on (f.id = pg.file_id)
|
||||
where fp_r.profile_id = $1
|
||||
and f.project_id = $2
|
||||
and f.deleted_at is null
|
||||
and pg.deleted_at is null
|
||||
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
|
||||
range between unbounded preceding
|
||||
and unbounded following)
|
||||
order by f.modified_at desc
|
||||
limit 5")
|
||||
|
||||
(defn recent-by-project [profile-id project]
|
||||
(let [project-id (:id project)]
|
||||
(-> (db/query db/pool [sql:project_files_recent profile-id project-id])
|
||||
(p/then (partial mapv decode-row)))))
|
||||
|
||||
(s/def ::team-id ::us/uuid)
|
||||
(s/def ::profile-id ::us/uuid)
|
||||
|
||||
(s/def ::recent-files
|
||||
(s/keys :req-un [::profile-id ::team-id]))
|
||||
|
||||
(sq/defquery ::recent-files
|
||||
[{:keys [profile-id team-id]}]
|
||||
(-> (projects-by-team profile-id team-id)
|
||||
;; Retrieve for each proyect the 5 more recent files
|
||||
(p/then #(p/all (map (partial recent-by-project profile-id) %)))
|
||||
;; Change the structure so it's a map with project-id as keys
|
||||
(p/then #(->> % (flatten) (group-by :project-id)))))
|
Loading…
Add table
Add a link
Reference in a new issue