Skip to content

Commit 154cc1b

Browse files
committed
Web: base management panel, refactoring
1 parent 42db6ff commit 154cc1b

File tree

18 files changed

+237
-33
lines changed

18 files changed

+237
-33
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ playground.iml
1414
/data/
1515
resources/public/js/playground.js
1616
resources/public/js/site.js
17+
resources/public/js/admin.js
1718
resources/public/js/codemirror.min.js
1819
resources/public/js/clipboard-splitter-sortable.min.js
1920
resources/public/css/editor.css
2021
resources/public/css/main.css
22+
resources/public/css/admin.css
2123
src-css/.sass-cache
2224
.sass-cache
2325
resources/public/chartopedia/images

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
language: clojure
22
script:
33
- lein sass4clj once
4-
- lein cljsbuild once prod prod-site
4+
- lein cljsbuild once prod prod-site prod-admin
55
- lein minify-assets
66
- lein uberjar
77
sudo: false

project.clj

+21-7
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
[reagent "0.8.0"]
7373
[re-frame "0.10.5"]
7474
[re-com "2.1.0"]
75+
[rum "0.11.2"]
7576
[alandipert/storage-atom "2.0.1"]
7677
; [cljs-http "0.1.42"]
7778
[cljs-ajax "0.7.3"]
@@ -113,6 +114,7 @@
113114
:target "resources/public/js/clipboard-splitter-sortable.min.js"}]]
114115
:profiles {:dev {:jvm-opts ["-Dlocal=true"]
115116
:dependencies [[re-frisk "0.5.4"]]}}
117+
116118
:cljsbuild {:builds [
117119
;; editor
118120
{:id "dev"
@@ -123,16 +125,13 @@
123125
:preloads [re-frisk.preload]}}
124126
{:id "prod"
125127
:source-paths ["src-cljs" "src-cljc"]
126-
:compiler {
127-
;:output-dir "resources/public/js"
128-
:output-to "resources/public/js/playground.js"
128+
:compiler {:output-to "resources/public/js/playground.js"
129129
:optimizations :advanced
130130
:pretty-print false
131131
:pseudo-names false
132132
:externs ["codemirror_externs.js"]
133-
:closure-defines {"goog.DEBUG" false}
134-
;:source-map "resources/public/js/playground.js.map"
135-
}}
133+
:closure-defines {"goog.DEBUG" false}}}
134+
136135
;; site
137136
{:id "dev-site"
138137
:source-paths ["src-site-cljs" "src-cljc"]
@@ -145,4 +144,19 @@
145144
:optimizations :advanced
146145
:pretty-print false
147146
:pseudo-names false
148-
:closure-defines {"goog.DEBUG" false}}}]})
147+
:closure-defines {"goog.DEBUG" false}}}
148+
149+
;; admin panel
150+
{:id "dev-admin"
151+
:source-paths ["src-admin-cljs" "src-site-cljs" "src-cljc"]
152+
:compiler {:output-to "resources/public/js/admin.js"
153+
:optimizations :whitespace
154+
:pretty-print true}}
155+
{:id "prod-admin"
156+
:source-paths ["src-admin-cljs" "src-site-cljs" "src-cljc"]
157+
:compiler {:output-to "resources/public/js/admin.js"
158+
:optimizations :advanced
159+
:pretty-print false
160+
:pseudo-names false
161+
:closure-defines {"goog.DEBUG" false}}}
162+
]})
+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
(ns playground.admin.core
2+
(:require [rum.core :as rum]
3+
[cognitect.transit :as t]
4+
[playground.utils.utils :as utils]
5+
[ajax.core :refer [GET POST]]))
6+
7+
8+
(enable-console-print!)
9+
10+
11+
(def state (atom {:projects []
12+
:project nil
13+
:versions []
14+
:version nil}))
15+
16+
17+
(defn get-project-by-name [project-name]
18+
(first (filter #(= project-name (:name %)) (:projects @state))))
19+
20+
21+
(defn update-versions []
22+
(POST "/_admin_/versions"
23+
{:params {:project-id (-> @state :project :id)}
24+
:handler #(swap! state assoc :versions %)
25+
:error-handler #(println %)}))
26+
27+
28+
(defn change-project [project]
29+
(println "change-project:" project)
30+
(swap! state assoc :project (get-project-by-name project))
31+
(update-versions))
32+
33+
34+
(defn change-version [version]
35+
36+
)
37+
38+
39+
(rum/defc project-select < rum/reactive []
40+
[:div
41+
[:h5 "Version management panel"]
42+
[:form
43+
[:div.form-group
44+
[:label {:for "project-select"} "Select project"]
45+
[:br]
46+
[:select.custom-select#project-select {:on-change #(change-project (-> % .-target .-value))}
47+
(for [repo (:projects (rum/react state))]
48+
[:option {:key (:name repo)
49+
:value (:name repo)} (:name repo)])]
50+
[:a.btn.btn-success {:role "button"
51+
:href (str "/" (:name (:project (rum/react state))) "/_update_")} "Update versions"] ]
52+
53+
[:label {:for "version-select"} "Select version"]
54+
[:br]
55+
[:select.custom-select#version-select {:on-change #(change-version (-> % .-target .-value))}
56+
(for [version (:versions (rum/react state))]
57+
[:option {:key (:name version)
58+
:value (:name version)} (:name version)])]
59+
[:button.btn.btn-danger "Delete"]
60+
[:button.btn.btn-primary "Rebuild"]
61+
62+
[:br]
63+
[:div.alert.alert-primary
64+
"This action is used to update AnyChart develop versions in PG editor."
65+
[:br]
66+
[:a.btn.btn-success {:role "button"
67+
:href "/_update_anychart_versions_"} "Update AnyChart versions"]]
68+
[:a.btn.btn-link {:role "button"
69+
:href "/tags/index"} "Show tags stat" ]
70+
71+
]
72+
])
73+
74+
75+
(rum/defc main-comp []
76+
[:div "asdf"])
77+
78+
79+
(defn ^:export init [data]
80+
(let [data (t/read (t/reader :json) data)
81+
repos (:repos data)]
82+
(reset! state {:projects (:repos data)
83+
:project (first repos)})
84+
(update-versions)
85+
(println data)
86+
(rum/mount (project-select)
87+
(.getElementById js/document "main-container"))))

src-cljs/playground/core.cljs

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
[re-frame.core :as rf]
44
[playground.subs]
55
[playground.events]
6-
[playground.utils :as utils]
76
[playground.views :as views]
87
[playground.js]
98
[cognitect.transit :as t]

src-cljs/playground/editors/events.cljs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
(ns playground.editors.events
22
(:require [re-frame.core :as rf]
33
[playground.editors.js :as editors-js]
4-
[playground.utils :as js-utils]
54
[playground.utils.utils :as utils]
65
[ajax.core :refer [GET POST]]))
76

@@ -133,7 +132,7 @@
133132
(rf/reg-event-db
134133
:data-error
135134
(fn [db [_ error]]
136-
(js-utils/log "Data error!" error)
135+
(println "Data error!" error)
137136
(js/alert "Data error!")
138137
db))
139138

src-cljs/playground/editors/js.cljs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
(ns playground.editors.js
2-
(:require [re-frame.core :as rf]
3-
[playground.utils :as utils]))
2+
(:require [re-frame.core :as rf]))
43

54

65
(defn create-editor [type value mode]

src-cljs/playground/events.cljs

+5-7
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@
22
(:require-macros [hiccups.core :as h])
33
(:require [reagent.core :as reagent :refer [atom]]
44
[re-frame.core :as rf]
5-
[playground.utils :as js-utils]
65
[ajax.core :refer [GET POST]]
76
;[accountant.core :as accountant]
87
[playground.editors.js :as editors-js]
98
[playground.utils.utils :as common-utils]
109
[alandipert.storage-atom :refer [local-storage]]
1110
[playground.views.iframe :as iframe-view]
1211
[hiccups.runtime :as hiccupsrt]
13-
[playground.utils.utils :as utils]
1412
[playground.settings-window.javascript-tab.version-detect :as version-detect]
1513
[playground.settings-window.javascript-tab.events :refer [detect-version-interceptor]]))
1614

@@ -34,7 +32,7 @@
3432
; (swap! ls assoc :hidden-types [])
3533
; (utils/log (clj->js @ls))
3634
(when-not (-> data :sample :version-id)
37-
(.replaceState (.-history js/window) nil nil (utils/sample-url-with-version (:sample data))))
35+
(.replaceState (.-history js/window) nil nil (common-utils/sample-url-with-version (:sample data))))
3836
(let [view (or (:view data) (:view @ls) :right)]
3937
{:db {:editors {:editors-height (editors-js/editors-height)
4038
:view view
@@ -158,7 +156,7 @@
158156
(rf/reg-event-db
159157
:save-error
160158
(fn [db [_ error]]
161-
(js-utils/log "Save error!" error)
159+
(println "Save error!" error)
162160
(js/alert "Save error!")
163161
db))
164162

@@ -169,7 +167,7 @@
169167
(rf/reg-event-db
170168
:fork
171169
(fn [db _]
172-
(js-utils/log "Fork")
170+
(println "Fork")
173171
(when (= :standalone (-> db :editors :view))
174172
(rf/dispatch [:view/editor]))
175173
(POST "/fork"
@@ -199,7 +197,7 @@
199197
(rf/reg-event-db
200198
:fork-error
201199
(fn [db [_ error]]
202-
(js-utils/log "Fork error!" error)
200+
(println "Fork error!" error)
203201
(js/alert "Fork error!")
204202
db))
205203

@@ -225,7 +223,7 @@
225223
(rf/reg-event-db
226224
:search-hints-request-error
227225
(fn [db [_ error]]
228-
(js-utils/log "Search hints request error" error)
226+
(println "Search hints request error" error)
229227
db))
230228

231229

src-cljs/playground/export_window/events.cljs

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
(:require-macros [hiccups.core :as h])
33
(:require [re-frame.core :as rf]
44
[playground.utils.utils :as common-utils]
5-
[playground.utils :as utils]
65
[playground.views.iframe :as iframe-view]
76
[hiccups.runtime :as hiccupsrt]
87
[clojure.string :as string]))

src-cljs/playground/export_window/views.cljs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
(ns playground.export-window.views
22
(:require [re-frame.core :as rf]
3-
[playground.utils :as utils]
43
[reagent.core :as reagent]))
54

65
(defn embed-editor []

src-cljs/playground/subs.cljs

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
[re-frame.core :as rf]
44
[clojure.string :as string]
55
[playground.utils.utils :as common-utils]
6-
[playground.web.auth-base :as auth-base]
7-
[playground.utils.utils :as utils]))
6+
[playground.web.auth-base :as auth-base]))
87

98

109
(defn- makrup-type->str [type]

src-cljs/playground/tips/events.cljs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
(ns playground.tips.events
22
(:require [re-frame.core :as rf]
3-
[playground.utils :as utils]
43
[playground.tips.tips-data :as tips-data]))
54

65

src-cljs/playground/utils.cljs

-7
This file was deleted.

src-cljs/playground/views.cljs

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
[playground.tips.views :as tips]
88
[playground.sidemenu.views :as sidemenu]
99
[playground.search.views :as search]
10-
[playground.utils :as utils]
1110
[playground.utils.utils :as utils-main]
1211
[playground.data.consts :as consts]
1312
[playground.modal-window.views :as modal-view]))

src-css/scss/admin.scss

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
body {
2+
3+
#main-container{
4+
widtH: 500px;
5+
6+
select {
7+
width: 200px;
8+
}
9+
10+
select, a, button {
11+
margin-right: 10px;
12+
}
13+
}
14+
}

0 commit comments

Comments
 (0)