Skip to content

Commit

Permalink
multiple workspaces; workspace persistence (big commit)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew committed Jun 5, 2016
1 parent dff6b07 commit 9454c4c
Show file tree
Hide file tree
Showing 8 changed files with 325 additions and 76 deletions.
16 changes: 16 additions & 0 deletions src/cljs/ulysses/components/basic.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,22 @@
[:div.tooltip-arrow]
[:div.tooltip-inner text]])

(defn tab
[name on-click is-active]
[:li.nav-item
[hink
on-click
(classes-attr :nav-link {:active is-active})
name]])

(defn tabs
[ts]
[:ul.nav.nav-tabs
(map-subels
(fn [{:keys [name on-click is-active]}]
[tab name on-click is-active])
ts)])

;; ----------------------------------------------------------------------------
;; css transition group
;; ----------------------------------------------------------------------------
Expand Down
27 changes: 22 additions & 5 deletions src/cljs/ulysses/db.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,15 @@
; grant ops (bare-bones, for listings)
:grant-ops []

; faculties (extended, with keywords)
; workspaces (bare-bones)
:workspaces [{:id 1 :name "a" :grant-op-id 1}
{:id 2 :name "b" :grant-op-id 1}
{:id 3 :name "c" :grant-op-id 1}]

; faculties (extended, with keywords) [builder]
:faculties {}

; faculty titles
; faculty titles [builder]
:faculty-titles []

;; builder ----
Expand All @@ -50,8 +55,15 @@
; builder: current faculty pool results given filters (with metrics)
:builder-faculties-pool []

; builder: current faculty workspace (list of ids)
:builder-faculties-workspace []
; builder: current workspace (bare-bones)
:builder-workspace nil

; builder: current workspace faculties (list of ids)
:builder-workspace-faculties []

; builder: until back-end persistence, just store faculty-workspace
; relationships as "join rows", ex. {:faculty-id 3 :workspace-id 4}
:TMP-builder-faculty-workspaces []

;; -------------------------------------------------------------------------
;; user data
Expand All @@ -76,4 +88,9 @@
:faculty-years-uconn 0}

; user workspace-faculty hover (id)
:builder-faculties-workspace-hover nil})
:builder-workspace-faculty-hover nil})

(defn refresh-keys
"given a db, set the given keys to their original state"
[db keys]
(merge db (select-keys default-db keys)))
170 changes: 141 additions & 29 deletions src/cljs/ulysses/handlers.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
parse-int-id
str->int
to-id-map
find-by-id
remove-by-id
merge-by-id
new-id
scroll-to
request
faculties-pool-params
Expand Down Expand Up @@ -101,7 +105,7 @@
(request db
[:funding grant-op-id]
:handler #(dispatch [:receive-builder-grant-op %])
:error-handler #(dispatch [:nil-builder-grant-op])))
:error-handler #(dispatch [:nil-builder])))
db))

(register-handler
Expand All @@ -112,11 +116,6 @@
:nih_rfa
clean-incoming-grant-op))))

(register-handler
:nil-builder-grant-op
(fn [db _]
(assoc db :builder-grant-op nil)))

; faculties pool ----

(register-handler
Expand All @@ -139,11 +138,6 @@
(assoc db :builder-faculties-pool
response))))

(register-handler
:nil-faculties-pool
(fn [db _]
(assoc db :builder-faculties-pool [])))

; grant ops ----

(register-handler
Expand Down Expand Up @@ -196,30 +190,127 @@
;; user data
;; ----------------------------------------------------------------------------

;; working faculties ----
;; workspace management ----

;; NOTE most of the code in this section interfaces with
;; db :workspaces -- eventually, all five handlers
;; should really just be plain http requests so that
;; the back-end handles this stuff

(register-handler
:workspace-new-blank
(fn [db _]
(if-let [op (:builder-grant-op db)]
(let [id (-> db :workspaces new-id)]
(dispatch [:workspace-switch id])
(-> db
(update :workspaces
(fn [ws]
(conj ws
{:id id
:name (str id)
:user-id 1 ; temporary, of course
:grant-op-id (:id op)})))))
db)))

(register-handler
:workspace-new-default
(fn [db _]
(dispatch [:workspace-new-blank])
; TODO
db))

; rename current workspace
(register-handler
:workspace-rename
(fn [db [_ name]]
(if-let [current (:builder-workspace db)]
(-> db
(assoc-in [:builder-workspace :name] name)
(update :workspaces
(fn [ws]
(if-let [f (find-by-id (:id current) ws)]
(->> name
(assoc f :name)
(vector)
(merge-by-id ws)
(vec))
ws))))
db)))

; delete current workspace
(register-handler
:workspace-delete
(fn [db _]
(dispatch [:nil-workspace])
(dispatch [:workspace-switch nil])
(if-let [current (:builder-workspace db)]
(update db :workspaces
(fn [ws]
(vec (remove-by-id (:id current) ws))))
db)))

(register-handler
:workspace-switch
(fn [db [_ workspace-id-maybe]]
(if workspace-id-maybe
(if-let [target (find-by-id workspace-id-maybe (:workspaces db))]
(-> db
(assoc :builder-workspace target)
(assoc :builder-workspace-faculties
; TMP workspace persistence
(->> db
:TMP-builder-faculty-workspaces
(filter #(= workspace-id-maybe (:workspace-id %)))
(map :faculty-id))))
db)
db)))

;; workspace faculties management ----

(register-handler
:add-working-faculty
(fn [db [_ faculty-id]]
(dispatch [:request-faculty faculty-id])
(update db :builder-faculties-workspace
(fn [current]
(-> faculty-id
(cons current)
(distinct))))))
(if-let [current (:builder-workspace db)]
(-> db
(update :builder-workspace-faculties
(fn [fids]
(->> faculty-id
(conj fids)
(distinct))))
(update :TMP-builder-faculty-workspaces
(fn [fws]
(conj fws
{:faculty-id faculty-id
:workspace-id (:id current)}))))
; TODO create new workspace from default,
; then add this new working faculty
db)))

(register-handler
:remove-working-faculty
(fn [db [_ faculty-id]]
;; since the remove button is in the hover area...
(dispatch [:nil-builder-faculties-workspace-hover])
(update db :builder-faculties-workspace
(partial remove #{faculty-id}))))

(register-handler
:nil-faculties-workspace
(fn [db _]
(assoc db :builder-faculties-workspace [])))
(dispatch [:nil-builder-workspace-faculty-hover])
(if-let [current (:builder-workspace db)]
(-> db
(update :builder-workspace-faculties
(fn [fws]
(vec (remove #{faculty-id} fws))))
(update :TMP-builder-faculty-workspaces
(let [current-id (:id current)]
(fn [fws]
(vec
(remove
(fn [fw]
(and
(= faculty-id (:faculty-id %))
(= current-id (:workspace-id %))))
fws))))))
; TODO create new workspace from default,
; then remove this new working faculty
db)))

;; home filters ----

Expand Down Expand Up @@ -265,13 +356,34 @@
;; builder faculty workspace hover ----

(register-handler
:builder-faculties-workspace-hover
:builder-workspace-faculty-hover
(fn [db [_ faculty-id]]
(assoc db :builder-faculties-workspace-hover
(assoc db :builder-workspace-faculty-hover
faculty-id)))

(register-handler
:nil-builder-faculties-workspace-hover
:nil-builder-workspace-faculty-hover
(fn [db _]
(assoc db :builder-faculties-workspace-hover
(assoc db :builder-workspace-faculty-hover
nil)))

;; builder nil

(register-handler
:nil-workspace
(fn [db _]
(db/refresh-keys db
[:builder-workspace
:builder-workspace-faculties
:builder-workspace-faculty-hover])))

(register-handler
:nil-builder
(fn [db _]
(db/refresh-keys db
[:builder-grant-op
:builder-faculties-pool
:builder-workspace
:builder-workspace-faculties
:builder-filters
:builder-workspace-faculty-hover])))
Loading

0 comments on commit 9454c4c

Please sign in to comment.