Basic backend integration for page history fetching.

This commit is contained in:
Andrey Antukh 2016-03-24 12:43:14 +02:00
parent 6b495c1656
commit e97e4cbb5a
5 changed files with 100 additions and 65 deletions

View file

@ -164,3 +164,49 @@
(defn delete-page (defn delete-page
[id] [id]
(DeletePage. id)) (DeletePage. id))
;; --- Page History Fetched
(defrecord PageHistoryFetched [history]
rs/UpdateEvent
(-apply-update [_ state]
(-> state
(assoc-in [:workspace :history :items] history)
(assoc-in [:workspace :history :selected] nil))))
;; --- Fetch Page History
(defrecord FetchPageHistory [id]
rs/WatchEvent
(-apply-watch [_ state s]
(println "FetchPageHistory" id)
(letfn [(on-success [{history :payload}]
(->PageHistoryFetched history))
(on-failure [e]
(uum/error (tr "errors.fetch-page-history"))
(rx/empty))]
(->> (rp/do :fetch/page-history {:page id})
(rx/map on-success)
(rx/catch on-failure))))
rs/EffectEvent
(-apply-effect [_ state]
))
(defn fetch-page-history
[id]
(FetchPageHistory. id))
;; --- Clean Page History
(defrecord CleanPageHistory []
rs/UpdateEvent
(-apply-update [_ state]
(println "CleanPageHistory")
(-> state
(assoc-in [:workspace :history :items] nil)
(assoc-in [:workspace :history :selected] nil))))
(defn clean-page-history
[]
(CleanPageHistory.))

View file

@ -23,6 +23,11 @@
(let [url (str url "/projects/" project "/pages")] (let [url (str url "/projects/" project "/pages")]
(send! {:method :get :url url}))) (send! {:method :get :url url})))
(defmethod -do :fetch/page-history
[type {:keys [page] :as params}]
(let [url (str url "/pages/" page "/history")]
(send! {:method :get :url url})))
(defmethod -do :delete/page (defmethod -do :delete/page
[_ id] [_ id]
(let [url (str url "/pages/" id)] (let [url (str url "/pages/" id)]

View file

@ -17,7 +17,7 @@
[uxbox.ui.workspace.sidebar.options :refer (options-toolbox)] [uxbox.ui.workspace.sidebar.options :refer (options-toolbox)]
[uxbox.ui.workspace.sidebar.layers :refer (layers-toolbox)] [uxbox.ui.workspace.sidebar.layers :refer (layers-toolbox)]
[uxbox.ui.workspace.sidebar.sitemap :refer (sitemap-toolbox)] [uxbox.ui.workspace.sidebar.sitemap :refer (sitemap-toolbox)]
[uxbox.ui.workspace.sidebar.document-history :refer (document-history-toolbox)] [uxbox.ui.workspace.sidebar.history :refer (history-toolbox)]
[uxbox.ui.workspace.sidebar.icons :refer (icons-toolbox)] [uxbox.ui.workspace.sidebar.icons :refer (icons-toolbox)]
[uxbox.ui.workspace.sidebar.drawtools :refer (draw-toolbox)])) [uxbox.ui.workspace.sidebar.drawtools :refer (draw-toolbox)]))
@ -34,7 +34,7 @@
(when (contains? flags :sitemap) (when (contains? flags :sitemap)
(sitemap-toolbox)) (sitemap-toolbox))
(when (contains? flags :document-history) (when (contains? flags :document-history)
(document-history-toolbox)) (history-toolbox))
(when (contains? flags :layers) (when (contains? flags :layers)
(layers-toolbox))]]))) (layers-toolbox))]])))

View file

@ -5,7 +5,7 @@
;; Copyright (c) 2015-2016 Andrey Antukh <niwi@niwi.nz> ;; Copyright (c) 2015-2016 Andrey Antukh <niwi@niwi.nz>
;; Copyright (c) 2015-2016 Juan de la Cruz <delacruzgarciajuan@gmail.com> ;; Copyright (c) 2015-2016 Juan de la Cruz <delacruzgarciajuan@gmail.com>
(ns uxbox.ui.workspace.sidebar.document-history (ns uxbox.ui.workspace.sidebar.history
(:require [sablono.core :as html :refer-macros [html]] (:require [sablono.core :as html :refer-macros [html]]
[rum.core :as rum] [rum.core :as rum]
[lentes.core :as l] [lentes.core :as l]
@ -15,21 +15,51 @@
[uxbox.state :as st] [uxbox.state :as st]
[uxbox.shapes :as shapes] [uxbox.shapes :as shapes]
[uxbox.library :as library] [uxbox.library :as library]
[uxbox.util.datetime :as dt]
[uxbox.util.data :refer (read-string)] [uxbox.util.data :refer (read-string)]
[uxbox.data.workspace :as dw] [uxbox.data.workspace :as dw]
[uxbox.data.pages :as dpg]
[uxbox.ui.workspace.base :as wb] [uxbox.ui.workspace.base :as wb]
[uxbox.ui.icons :as i] [uxbox.ui.icons :as i]
[uxbox.ui.mixins :as mx] [uxbox.ui.mixins :as mx]
[uxbox.util.dom :as dom])) [uxbox.util.dom :as dom]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Lenses
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(def ^:const history-l
(as-> (l/in [:workspace :history]) $
(l/focus-atom $ st/state)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Component ;; Component
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn document-history-toolbox-render (defn- history-toolbox-will-mount
[own] [own]
(let [workspace (rum/react wb/workspace-l) (let [page @wb/page-l]
local (:rum/local own) (rs/emit! (dpg/fetch-page-history (:id page)))
(add-watch wb/page-l ::key (fn [_ _ ov nv]
(when (> (:version nv) (:version ov))
(rs/emit! (dpg/fetch-page-history (:id nv))))))
own))
(defn- history-toolbox-will-unmount
[own]
(rs/emit! (dpg/clean-page-history))
(remove-watch wb/page-l ::key)
own)
(defn- history-toolbox-transfer-state
[oldown own]
own)
(defn history-toolbox-render
[own]
(let [local (:rum/local own)
page (rum/react wb/page-l)
history (rum/react history-l)
section (:section @local :main) section (:section @local :main)
close #(rs/emit! (dw/toggle-flag :document-history)) close #(rs/emit! (dw/toggle-flag :document-history))
main? (= section :main) main? (= section :main)
@ -63,65 +93,19 @@
[:ul.history-content [:ul.history-content
[:li.current [:li.current
[:div.pin-icon i/pin] [:div.pin-icon i/pin]
[:span "Current version"]] [:span (str "Version " (:version page) " (current)")]]
[:li (for [item (:items history)]
[:div.pin-icon i/pin] [:li {:key (str (:id item))}
[:span "Version 02/02/2016 12:33h"]] [:div.pin-icon i/pin]
[:li [:span (str "Version " (:version item)
[:div.pin-icon i/pin] " (" (dt/timeago (:created-at item)) ")")]])
[:span "Version 02/02/2016 12:33h"]] ])]])))
[:li
[:div.pin-icon i/pin]
[:span "Version 02/02/2016 12:33h"]]
[:li
[:div.pin-icon i/pin]
[:span "Version 02/02/2016 12:33h"]]
[:li
[:div.pin-icon i/pin]
[:span "Version 02/02/2016 12:33h"]]
[:li
[:div.pin-icon i/pin]
[:span "Version 02/02/2016 12:33h"]]
[:li
[:div.pin-icon i/pin]
[:span "Version 02/02/2016 12:33h"]]
[:li
[:div.pin-icon i/pin]
[:span "Version 02/02/2016 12:33h"]]
[:li
[:div.pin-icon i/pin]
[:span "Version 02/02/2016 12:33h"]]
[:li
[:div.pin-icon i/pin]
[:span "Version 02/02/2016 12:33h"]]
[:li
[:div.pin-icon i/pin]
[:span "Version 02/02/2016 12:33h"]]
[:li
[:div.pin-icon i/pin]
[:span "Version 02/02/2016 12:33h"]]
[:li
[:div.pin-icon i/pin]
[:span "Version 02/02/2016 12:33h"]]
[:li
[:div.pin-icon i/pin]
[:span "Version 02/02/2016 12:33h"]]
[:li
[:div.pin-icon i/pin]
[:span "Version 02/02/2016 12:33h"]]
[:li
[:div.pin-icon i/pin]
[:span "Version 02/02/2016 12:33h"]]
[:li
[:div.pin-icon i/pin]
[:span "Version 02/02/2016 12:33h"]]
[:li
[:div.pin-icon i/pin]
[:span "Version 02/02/2016 12:33h"]]])]])))
(def ^:static history-toolbox
(def ^:static document-history-toolbox
(mx/component (mx/component
{:render document-history-toolbox-render {:render history-toolbox-render
:name "document-history-toolbox" :name "document-history-toolbox"
:will-mount history-toolbox-will-mount
:will-unmount history-toolbox-will-unmount
:transfer-state history-toolbox-transfer-state
:mixins [mx/static rum/reactive (mx/local)]})) :mixins [mx/static rum/reactive (mx/local)]}))

View file

@ -33,7 +33,7 @@
;; Lenses ;; Lenses
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(def ^:static pages-l (def ^:const pages-l
(letfn [(getter [state] (letfn [(getter [state]
(let [project (get-in state [:workspace :project])] (let [project (get-in state [:workspace :project])]
(stpr/project-pages state project)))] (stpr/project-pages state project)))]