From 5b0fdb260c89ccd06ecc4b869d9f917358aa7452 Mon Sep 17 00:00:00 2001 From: Shengzhe Yao Date: Mon, 2 Feb 2015 21:22:39 -0800 Subject: [PATCH] Move schema editor to templates --- go/cmd/vtctld/explorer.go | 2 +- go/cmd/vtctld/template.go | 2 +- .../{schema_editor => templates}/app.js | 12 ++++----- .../{schema_editor => templates}/curschema.js | 0 .../editor/class/class.html | 2 +- .../editor/class/class.js | 0 .../editor/classes.html | 2 +- .../editor/keyspace.html | 14 +++++----- .../editor/keyspace.js | 0 .../editor/sidebar.html | 6 ++--- .../editor/sidebar.js | 0 .../editor/tables.html | 0 .../editor/unsharded_tables.html | 0 .../editor/vindexes.html | 0 .../{schema_editor => templates}/index.html | 27 ++++++++++--------- .../load/load.html | 4 +-- .../{schema_editor => templates}/load/load.js | 0 .../submit/submit.html | 4 +-- .../submit/submit.js | 0 .../vindex_info.js | 0 go/cmd/vtctld/vtctld.go | 14 +++++----- test/utils.py | 1 - 22 files changed, 47 insertions(+), 43 deletions(-) rename go/cmd/vtctld/{schema_editor => templates}/app.js (78%) rename go/cmd/vtctld/{schema_editor => templates}/curschema.js (100%) rename go/cmd/vtctld/{schema_editor => templates}/editor/class/class.html (97%) rename go/cmd/vtctld/{schema_editor => templates}/editor/class/class.js (100%) rename go/cmd/vtctld/{schema_editor => templates}/editor/classes.html (99%) rename go/cmd/vtctld/{schema_editor => templates}/editor/keyspace.html (72%) rename go/cmd/vtctld/{schema_editor => templates}/editor/keyspace.js (100%) rename go/cmd/vtctld/{schema_editor => templates}/editor/sidebar.html (89%) rename go/cmd/vtctld/{schema_editor => templates}/editor/sidebar.js (100%) rename go/cmd/vtctld/{schema_editor => templates}/editor/tables.html (100%) rename go/cmd/vtctld/{schema_editor => templates}/editor/unsharded_tables.html (100%) rename go/cmd/vtctld/{schema_editor => templates}/editor/vindexes.html (100%) rename go/cmd/vtctld/{schema_editor => templates}/index.html (67%) rename go/cmd/vtctld/{schema_editor => templates}/load/load.html (90%) rename go/cmd/vtctld/{schema_editor => templates}/load/load.js (100%) rename go/cmd/vtctld/{schema_editor => templates}/submit/submit.html (92%) rename go/cmd/vtctld/{schema_editor => templates}/submit/submit.js (100%) rename go/cmd/vtctld/{schema_editor => templates}/vindex_info.js (100%) diff --git a/go/cmd/vtctld/explorer.go b/go/cmd/vtctld/explorer.go index 91c7044cd5..0e4e7280db 100644 --- a/go/cmd/vtctld/explorer.go +++ b/go/cmd/vtctld/explorer.go @@ -73,7 +73,7 @@ func HandleExplorer(name, url, templateName string, exp Explorer) { explorer = exp explorerName = name - + indexContent.ToplevelLinks[name+" Explorer"] = url http.HandleFunc(url, func(w http.ResponseWriter, r *http.Request) { if err := r.ParseForm(); err != nil { httpError(w, "cannot parse form: %s", err) diff --git a/go/cmd/vtctld/template.go b/go/cmd/vtctld/template.go index 48ea4e5fe6..8a862de533 100644 --- a/go/cmd/vtctld/template.go +++ b/go/cmd/vtctld/template.go @@ -143,7 +143,7 @@ type TemplateLoader struct { } func (loader *TemplateLoader) compile() (*template.Template, error) { - return template.New("main").Funcs(FuncMap).ParseGlob(path.Join(loader.Directory, "[a-z]*")) + return template.New("main").Funcs(FuncMap).ParseGlob(path.Join(loader.Directory, "[a-z]*.html")) } func (loader *TemplateLoader) makeErrorTemplate(errorMessage string) *template.Template { diff --git a/go/cmd/vtctld/schema_editor/app.js b/go/cmd/vtctld/templates/app.js similarity index 78% rename from go/cmd/vtctld/schema_editor/app.js rename to go/cmd/vtctld/templates/app.js index 8fddb838db..266b3587e9 100644 --- a/go/cmd/vtctld/schema_editor/app.js +++ b/go/cmd/vtctld/templates/app.js @@ -15,24 +15,24 @@ angular.module('app', ['ngRoute']) .controller('SubmitController', SubmitController) .config(['$routeProvider', function($routeProvider) { $routeProvider - .when('/',{ - templateUrl: "editor/keyspace.html", + .when('/editor',{ + templateUrl: "/content/editor/keyspace.html", controller: "KeyspaceController" }) .when('/editor/:keyspaceName',{ - templateUrl: "editor/keyspace.html", + templateUrl: "/content/editor/keyspace.html", controller: "KeyspaceController" }) .when('/editor/:keyspaceName/class/:className',{ - templateUrl: "editor/class/class.html", + templateUrl: "/content/editor/class/class.html", controller: "ClassController" }) .when('/load',{ - templateUrl: "load/load.html", + templateUrl: "/content/load/load.html", controller: "LoadController" }) .when('/submit',{ - templateUrl: "submit/submit.html", + templateUrl: "/content/submit/submit.html", controller: "SubmitController" }) .otherwise({redirectTo: '/'}); diff --git a/go/cmd/vtctld/schema_editor/curschema.js b/go/cmd/vtctld/templates/curschema.js similarity index 100% rename from go/cmd/vtctld/schema_editor/curschema.js rename to go/cmd/vtctld/templates/curschema.js diff --git a/go/cmd/vtctld/schema_editor/editor/class/class.html b/go/cmd/vtctld/templates/editor/class/class.html similarity index 97% rename from go/cmd/vtctld/schema_editor/editor/class/class.html rename to go/cmd/vtctld/templates/editor/class/class.html index 2d797ba4fe..17ac52a351 100644 --- a/go/cmd/vtctld/schema_editor/editor/class/class.html +++ b/go/cmd/vtctld/templates/editor/class/class.html @@ -1,6 +1,6 @@
-
+

Class: diff --git a/go/cmd/vtctld/schema_editor/editor/class/class.js b/go/cmd/vtctld/templates/editor/class/class.js similarity index 100% rename from go/cmd/vtctld/schema_editor/editor/class/class.js rename to go/cmd/vtctld/templates/editor/class/class.js diff --git a/go/cmd/vtctld/schema_editor/editor/classes.html b/go/cmd/vtctld/templates/editor/classes.html similarity index 99% rename from go/cmd/vtctld/schema_editor/editor/classes.html rename to go/cmd/vtctld/templates/editor/classes.html index c67758c130..cb2bad8c37 100644 --- a/go/cmd/vtctld/schema_editor/editor/classes.html +++ b/go/cmd/vtctld/templates/editor/classes.html @@ -57,4 +57,4 @@ -

\ No newline at end of file +
diff --git a/go/cmd/vtctld/schema_editor/editor/keyspace.html b/go/cmd/vtctld/templates/editor/keyspace.html similarity index 72% rename from go/cmd/vtctld/schema_editor/editor/keyspace.html rename to go/cmd/vtctld/templates/editor/keyspace.html index 363167025e..fb9d990c3f 100644 --- a/go/cmd/vtctld/schema_editor/editor/keyspace.html +++ b/go/cmd/vtctld/templates/editor/keyspace.html @@ -1,7 +1,7 @@
-
-
+
+

Keyspace: {{keyspaceName}}

-
\ No newline at end of file +
diff --git a/go/cmd/vtctld/schema_editor/editor/keyspace.js b/go/cmd/vtctld/templates/editor/keyspace.js similarity index 100% rename from go/cmd/vtctld/schema_editor/editor/keyspace.js rename to go/cmd/vtctld/templates/editor/keyspace.js diff --git a/go/cmd/vtctld/schema_editor/editor/sidebar.html b/go/cmd/vtctld/templates/editor/sidebar.html similarity index 89% rename from go/cmd/vtctld/schema_editor/editor/sidebar.html rename to go/cmd/vtctld/templates/editor/sidebar.html index b9a215fc20..8f9cd36be4 100644 --- a/go/cmd/vtctld/schema_editor/editor/sidebar.html +++ b/go/cmd/vtctld/templates/editor/sidebar.html @@ -3,9 +3,9 @@
Commands
diff --git a/go/cmd/vtctld/schema_editor/editor/sidebar.js b/go/cmd/vtctld/templates/editor/sidebar.js similarity index 100% rename from go/cmd/vtctld/schema_editor/editor/sidebar.js rename to go/cmd/vtctld/templates/editor/sidebar.js diff --git a/go/cmd/vtctld/schema_editor/editor/tables.html b/go/cmd/vtctld/templates/editor/tables.html similarity index 100% rename from go/cmd/vtctld/schema_editor/editor/tables.html rename to go/cmd/vtctld/templates/editor/tables.html diff --git a/go/cmd/vtctld/schema_editor/editor/unsharded_tables.html b/go/cmd/vtctld/templates/editor/unsharded_tables.html similarity index 100% rename from go/cmd/vtctld/schema_editor/editor/unsharded_tables.html rename to go/cmd/vtctld/templates/editor/unsharded_tables.html diff --git a/go/cmd/vtctld/schema_editor/editor/vindexes.html b/go/cmd/vtctld/templates/editor/vindexes.html similarity index 100% rename from go/cmd/vtctld/schema_editor/editor/vindexes.html rename to go/cmd/vtctld/templates/editor/vindexes.html diff --git a/go/cmd/vtctld/schema_editor/index.html b/go/cmd/vtctld/templates/index.html similarity index 67% rename from go/cmd/vtctld/schema_editor/index.html rename to go/cmd/vtctld/templates/index.html index 25c53c47e8..24a8a06ce4 100644 --- a/go/cmd/vtctld/schema_editor/index.html +++ b/go/cmd/vtctld/templates/index.html @@ -9,7 +9,7 @@ license that can be found in the LICENSE file. - + VTGate schema editor @@ -23,10 +23,13 @@ license that can be found in the LICENSE file.
@@ -51,28 +54,28 @@ license that can be found in the LICENSE file. type="text/javascript"> - - - - - - - - diff --git a/go/cmd/vtctld/schema_editor/load/load.html b/go/cmd/vtctld/templates/load/load.html similarity index 90% rename from go/cmd/vtctld/schema_editor/load/load.html rename to go/cmd/vtctld/templates/load/load.html index b65b591be4..94f8ad5f19 100644 --- a/go/cmd/vtctld/schema_editor/load/load.html +++ b/go/cmd/vtctld/templates/load/load.html @@ -1,6 +1,6 @@
-
+
@@ -18,4 +18,4 @@
{{loadedJSON}}
-
\ No newline at end of file + diff --git a/go/cmd/vtctld/schema_editor/load/load.js b/go/cmd/vtctld/templates/load/load.js similarity index 100% rename from go/cmd/vtctld/schema_editor/load/load.js rename to go/cmd/vtctld/templates/load/load.js diff --git a/go/cmd/vtctld/schema_editor/submit/submit.html b/go/cmd/vtctld/templates/submit/submit.html similarity index 92% rename from go/cmd/vtctld/schema_editor/submit/submit.html rename to go/cmd/vtctld/templates/submit/submit.html index 62b94a3d68..c81a7c2f33 100644 --- a/go/cmd/vtctld/schema_editor/submit/submit.html +++ b/go/cmd/vtctld/templates/submit/submit.html @@ -1,6 +1,6 @@
-
+
@@ -26,4 +26,4 @@
{{keyspacesJSON}}
-
\ No newline at end of file + diff --git a/go/cmd/vtctld/schema_editor/submit/submit.js b/go/cmd/vtctld/templates/submit/submit.js similarity index 100% rename from go/cmd/vtctld/schema_editor/submit/submit.js rename to go/cmd/vtctld/templates/submit/submit.js diff --git a/go/cmd/vtctld/schema_editor/vindex_info.js b/go/cmd/vtctld/templates/vindex_info.js similarity index 100% rename from go/cmd/vtctld/schema_editor/vindex_info.js rename to go/cmd/vtctld/templates/vindex_info.js diff --git a/go/cmd/vtctld/vtctld.go b/go/cmd/vtctld/vtctld.go index 51b846c0ed..8e8035810b 100644 --- a/go/cmd/vtctld/vtctld.go +++ b/go/cmd/vtctld/vtctld.go @@ -18,9 +18,8 @@ import ( ) var ( - templateDir = flag.String("templates", "", "directory containing templates") - debug = flag.Bool("debug", false, "recompile templates for every request") - schemaEditorDir = flag.String("schema-editor-dir", "", "directory containing schema_editor/") + templateDir = flag.String("templates", "", "directory containing templates") + debug = flag.Bool("debug", false, "recompile templates for every request") ) func init() { @@ -48,6 +47,9 @@ type IndexContent struct { // used at runtime by plug-ins var templateLoader *TemplateLoader var actionRepo *ActionRepository +var indexContent = IndexContent{ + ToplevelLinks: map[string]string{}, +} var ts topo.Server @@ -265,12 +267,12 @@ func main() { // vschema editor http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { - http.ServeFile(w, r, *schemaEditorDir+"/schema_editor/index.html") + templateLoader.ServeTemplate("index.html", indexContent, w, r) }) // vschema editor - http.HandleFunc("/schema_editor/", func(w http.ResponseWriter, r *http.Request) { - http.ServeFile(w, r, *schemaEditorDir+r.URL.Path) + http.HandleFunc("/content/", func(w http.ResponseWriter, r *http.Request) { + http.ServeFile(w, r, *templateDir+r.URL.Path[8:]) }) // vschema viewer diff --git a/test/utils.py b/test/utils.py index 3f38eac182..c16cd4f2f1 100644 --- a/test/utils.py +++ b/test/utils.py @@ -695,7 +695,6 @@ class Vtctld(object): args = environment.binary_args('vtctld') + [ '-debug', '-templates', environment.vttop + '/go/cmd/vtctld/templates', - '-schema-editor-dir', environment.vttop + '/go/cmd/vtctld', '-log_dir', environment.vtlogroot, '-port', str(self.port), ] + \