Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
workspace
wtmp begins Sat Oct 24 15:30  indicators with intervalic self-updates
  • Loading branch information
andrew committed Jun 14, 2016
1 parent adcc10c commit b3a4236
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/cljs/ulysses/db.cljs
Expand Up @@ -92,6 +92,9 @@
; user workspace-faculty hover (id)
:builder-workspace-faculty-hover nil

; builder workspaces saved timestamps {workspace-id => timestamp}
:builder-workspaces-saved-timestamps {}

;; -------------------------------------------------------------------------
;; interface
;; -------------------------------------------------------------------------
Expand Down
12 changes: 11 additions & 1 deletion src/cljs/ulysses/handlers.cljs
Expand Up @@ -3,6 +3,7 @@
[clojure.set :as set]
[ulysses.config :as config]
[ulysses.db :as db]
[ulysses.lib.moment :as m]
[ulysses.utils :refer [document-size
window-size
valid-request-id?
Expand Down Expand Up @@ -242,7 +243,7 @@

(register-handler
:workspace-receive
(fn [db [_ response dont-switch?]]
(fn [db [_ response dont-switch? is-after-save?]]
(let [wbb (-> response
(hyphenate-keys)
(select-keys [:id :name
Expand All @@ -260,6 +261,8 @@
valid-filters? (-> wbb :filters validate-builder-filters)]
(if-not valid-filters? db
(do
(when is-after-save?
(dispatch [:workspace-saved (:id wbb)]))
(when-not dont-switch?
(dispatch [:workspace-switch (:id wbb)]))
(update db :workspaces
Expand All @@ -270,6 +273,13 @@
:workspace-save
debounce-request-workspace-save)

(register-handler
:workspace-saved
(fn [db [_ workspace-id]]
(update db :builder-workspaces-saved-timestamps
(fn [ts]
(assoc ts workspace-id (m/moment))))))

(register-handler
:workspace-new-blank
(fn [db _]
Expand Down
24 changes: 22 additions & 2 deletions src/cljs/ulysses/pages/builder.cljs
Expand Up @@ -12,6 +12,7 @@
[ulysses.components.word-cloud :refer [word-cloud]]
[ulysses.utils :refer [map-subels map-lookup str->int classes-attr]]
[ulysses.lib.packer :as packer]
[ulysses.lib.moment :as m]
[reagent.core :as r]
[clojure.string :as string]
[cljs.pprint :as pprint]
Expand Down Expand Up @@ -165,6 +166,21 @@
[hink #(dispatch [:workspace-new-duplicate]) btn-attrs "Duplicate"]]]
[workspace-header-tabs workspaces workspace-current]]))

(defn workspace-last-saved [workspace-current workspaces-saved-timestamps]
(let [n-updates (r/atom 0)]
(fn [workspace-current workspaces-saved-timestamps]
(let [_ @n-updates]) ; subscribe; not used
(when-let [timestamp (get workspaces-saved-timestamps (:id workspace-current))]
(when (m/is-valid timestamp)
; set timeout for next self-update
(js/setTimeout
(fn []
(swap! n-updates inc))
(* 2 1000))
[:span.workspace-last-saved
"last saved "
(m/from-now timestamp)])))))

(defn workspace-rename [workspace-current]
(let [new-name (r/atom (str))]
(fn [workspace-current]
Expand Down Expand Up @@ -203,9 +219,10 @@
(classes-attr :btn :btn-sm :btn-danger)
"Delete"])

(defn workspace-footer [workspace-current]
(defn workspace-footer [workspace-current workspaces-saved-timestamps]
(when workspace-current
[:div.workspace-footer
[workspace-last-saved workspace-current workspaces-saved-timestamps]
[workspace-rename workspace-current]
[workspace-delete workspace-current]
[workspace-save]]))
Expand Down Expand Up @@ -241,6 +258,7 @@
[op
faculties faculty-titles faculties-pool
workspaces workspace-current workspace-faculty-hover
workspaces-saved-timestamps
filters]
[:div.builder-panel
[sidebar faculty-titles filters]
Expand All @@ -249,7 +267,7 @@
[:div.inner
[workspace-header workspaces workspace-current]
[workspace (map-lookup faculties (or (:faculties workspace-current) []))]
[workspace-footer workspace-current]]
[workspace-footer workspace-current workspaces-saved-timestamps]]
[:div.inner
[:h3 "Word Cloud"]
(when workspace-faculty-hover
Expand Down Expand Up @@ -288,6 +306,7 @@
workspaces (subscribe [:workspaces-current])
workspace (subscribe [:builder-workspace])
workspace-faculty-hover (subscribe [:builder-workspace-faculty-hover])
workspaces-saved-timestamps (subscribe [:builder-workspaces-saved-timestamps])

filters (subscribe [:builder-filters])

Expand Down Expand Up @@ -333,6 +352,7 @@
@workspaces
@workspace
@workspace-faculty-hover
@workspaces-saved-timestamps

@filters]]
[loading-or-no-results
Expand Down
5 changes: 5 additions & 0 deletions src/cljs/ulysses/subs.cljs
Expand Up @@ -159,6 +159,11 @@
(when builder-workspace-faculty-hover
(get faculties builder-workspace-faculty-hover))))))

(register-sub
:builder-workspaces-saved-timestamps
(fn [db _]
(reaction (-> @db :builder-workspaces-saved-timestamps))))

;; ----------------------------------------------------------------------------
;; interface
;; ----------------------------------------------------------------------------
Expand Down
4 changes: 3 additions & 1 deletion src/cljs/ulysses/utils.cljs
Expand Up @@ -547,7 +547,9 @@
:method :put
:params {:faculties (clj->json (or (:faculties current) []))
:filters (clj->json (:builder-filters db))}
:handler #(dispatch [:workspace-receive %]))
:handler
(fn [response]
(dispatch [:workspace-receive response nil true])))
db))))

(defn debounce-request-workspace-save
Expand Down
9 changes: 9 additions & 0 deletions src/sass/components/_builder-panel.scss
Expand Up @@ -64,4 +64,13 @@
margin-right: 0;
}
}

.workspace-last-saved {
color: $gray-light;
display: inline-block;
font-style: italic;
padding-right: 15px;
padding-top: 12px;
vertical-align: middle;
}
}
11 changes: 10 additions & 1 deletion test/cljs/ulysses/utils_test.cljs
Expand Up @@ -338,7 +338,16 @@
:success :nih
nil :not-found))

; missing: update-db-pagination
(deftest update-db-pagination
(are [x db response] (= x (utils/update-db-pagination db response))
;; test 1
{:page-current 2 :page-last 3}
{:page-current 1 :page-last 1}
{:current_page 2 :last_page 3}
;; test 2
{:foo :bar :page-current 1 :page-last 3}
{:foo :bar :page-current 1 :page-last 1}
{:foo :asdf :current_page 1 :last_page 3}))

; missing: faculties-pool-params

Expand Down

0 comments on commit b3a4236

Please sign in to comment.