2016-03-01 20:18:42 +02:00
|
|
|
;; 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/.
|
|
|
|
;;
|
|
|
|
;; Copyright (c) 2015-2016 Andrey Antukh <niwi@niwi.nz>
|
|
|
|
;; Copyright (c) 2015-2016 Juan de la Cruz <delacruzgarciajuan@gmail.com>
|
|
|
|
|
2015-06-18 19:35:50 +02:00
|
|
|
(ns uxbox.ui
|
2015-12-14 10:48:50 +02:00
|
|
|
(:require [sablono.core :as html :refer-macros [html]]
|
2016-02-24 17:23:03 +02:00
|
|
|
[promesa.core :as p]
|
2015-12-17 12:51:36 +02:00
|
|
|
[goog.dom :as gdom]
|
2015-12-14 10:48:50 +02:00
|
|
|
[rum.core :as rum]
|
2016-02-27 11:27:28 +02:00
|
|
|
[lentes.core :as l]
|
2015-06-18 19:35:50 +02:00
|
|
|
[uxbox.state :as s]
|
2016-02-24 17:23:03 +02:00
|
|
|
[uxbox.router :as r]
|
2015-12-14 20:31:21 +02:00
|
|
|
[uxbox.rstore :as rs]
|
|
|
|
[uxbox.data.projects :as dp]
|
2016-04-02 11:17:51 +03:00
|
|
|
[uxbox.data.users :as udu]
|
2016-02-24 17:23:03 +02:00
|
|
|
[uxbox.ui.lightbox :as ui-lightbox]
|
|
|
|
[uxbox.ui.auth :as ui-auth]
|
|
|
|
[uxbox.ui.dashboard :as ui-dashboard]
|
2016-03-03 20:26:28 +02:00
|
|
|
[uxbox.ui.settings :as ui-settings]
|
2015-12-20 14:41:38 +02:00
|
|
|
[uxbox.ui.workspace :refer (workspace)]
|
2016-01-02 18:03:16 +02:00
|
|
|
[uxbox.ui.mixins :as mx]
|
|
|
|
[uxbox.ui.shapes]))
|
2015-12-17 16:43:58 +02:00
|
|
|
|
2016-02-24 17:23:03 +02:00
|
|
|
(def ^:const auth-data
|
|
|
|
(as-> (l/key :auth) $
|
2015-06-18 19:35:50 +02:00
|
|
|
(l/focus-atom $ s/state)))
|
|
|
|
|
2016-02-24 17:23:03 +02:00
|
|
|
(def ^:const +unrestricted+
|
|
|
|
#{:auth/login})
|
|
|
|
|
|
|
|
(def ^:const restricted?
|
|
|
|
(complement +unrestricted+))
|
|
|
|
|
2015-06-18 19:35:50 +02:00
|
|
|
(defn app-render
|
|
|
|
[own]
|
2016-02-24 17:23:03 +02:00
|
|
|
(let [route (rum/react r/route-l)
|
|
|
|
auth (rum/react auth-data)
|
|
|
|
location (:id route)
|
|
|
|
params (:params route)]
|
|
|
|
(if (and (restricted? location) (not auth))
|
|
|
|
(do (p/schedule 0 #(r/go :auth/login)) nil)
|
|
|
|
(case location
|
|
|
|
:auth/login (ui-auth/login)
|
|
|
|
:dashboard/projects (ui-dashboard/projects-page)
|
|
|
|
:dashboard/elements (ui-dashboard/elements-page)
|
|
|
|
:dashboard/icons (ui-dashboard/icons-page)
|
|
|
|
:dashboard/colors (ui-dashboard/colors-page)
|
2016-03-03 20:26:28 +02:00
|
|
|
:settings/profile (ui-settings/profile-page)
|
|
|
|
:settings/password (ui-settings/password-page)
|
|
|
|
:settings/notifications (ui-settings/notifications-page)
|
2016-02-24 17:23:03 +02:00
|
|
|
:workspace/page (let [projectid (:project-uuid params)
|
|
|
|
pageid (:page-uuid params)]
|
|
|
|
(workspace projectid pageid))
|
|
|
|
nil
|
|
|
|
))))
|
2015-06-18 19:35:50 +02:00
|
|
|
|
2016-03-31 19:14:06 +03:00
|
|
|
(defn app-will-mount
|
|
|
|
[own]
|
2016-04-01 16:55:34 +03:00
|
|
|
(when @auth-data
|
2016-04-02 11:17:51 +03:00
|
|
|
(rs/emit! (udu/fetch-profile)
|
2016-04-01 16:55:34 +03:00
|
|
|
(dp/fetch-projects)))
|
2016-03-31 19:14:06 +03:00
|
|
|
own)
|
|
|
|
|
2015-06-18 19:35:50 +02:00
|
|
|
(def app
|
2016-02-24 17:23:03 +02:00
|
|
|
(mx/component
|
|
|
|
{:render app-render
|
2016-03-31 19:14:06 +03:00
|
|
|
:will-mount app-will-mount
|
2016-02-24 17:23:03 +02:00
|
|
|
:mixins [rum/reactive]
|
|
|
|
:name "app"}))
|
|
|
|
|
2015-12-17 12:51:36 +02:00
|
|
|
(defn init
|
|
|
|
[]
|
2016-01-17 23:32:55 +02:00
|
|
|
(println "ui/init")
|
2015-12-17 12:51:36 +02:00
|
|
|
(let [app-dom (gdom/getElement "app")
|
|
|
|
lb-dom (gdom/getElement "lightbox")]
|
2015-12-17 17:01:52 +02:00
|
|
|
(rum/mount (app) app-dom)
|
2016-02-24 17:23:03 +02:00
|
|
|
(rum/mount (ui-lightbox/lightbox) lb-dom)))
|