From 39fd9dd2c8156c9a9f9abc23e6f5398770e44f5d Mon Sep 17 00:00:00 2001
From: Christian Pointner
Date: Sat, 23 Jul 2016 03:46:32 +0200
Subject: some cleanup and imrpovments (mainly in the javasctipt test sites
diff --git a/src/rhimportd/ctrlWeb.go b/src/rhimportd/ctrlWeb.go
deleted file mode 100644
index bd3d776..0000000
--- a/src/rhimportd/ctrlWeb.go
+++ /dev/null
@@ -1,58 +0,0 @@
-//
-// rhimportd
-//
-// The Radio Helsinki Rivendell Import Daemon
-//
-//
-// Copyright (C) 2015-2016 Christian Pointner
-//
-// This file is part of rhimportd.
-//
-// rhimportd is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// any later version.
-//
-// rhimportd is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with rhimportd. If not, see .
-//
-
-package main
-
-import (
- "code.helsinki.at/rhrd-go/rddb"
- "code.helsinki.at/rhrd-go/rhimport"
- "net/http"
- _ "net/http/pprof"
- "time"
-)
-
-type webHandler struct {
- *rhimport.Config
- *rddb.DBChan
- *rhimport.SessionStoreChan
- trusted bool
- H func(*rhimport.Config, *rddb.DBChan, *rhimport.SessionStoreChan, bool, http.ResponseWriter, *http.Request)
-}
-
-func (self webHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
- self.H(self.Config, self.DBChan, self.SessionStoreChan, self.trusted, w, r)
-}
-
-func StartControlWeb(addr, staticDir string, conf *rhimport.Config, db *rddb.DBChan, sessions *rhimport.SessionStoreChan) {
- http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir(staticDir))))
-
- // http.Handle("/trusted/simple", webHandler{conf, db, sessions, true, webSimpleHandler})
- http.Handle("/public/simple", webHandler{conf, db, sessions, false, webSimpleHandler})
- http.Handle("/public/socket", webHandler{conf, db, sessions, false, webSocketHandler})
- http.Handle("/public/upload", webHandler{conf, db, sessions, false, webUploadHandler})
-
- rhl.Println("web-ctrl: listening on", addr)
- server := &http.Server{Addr: addr, ReadTimeout: 2 * time.Hour, WriteTimeout: 2 * time.Hour}
- server.ListenAndServe()
-}
diff --git a/src/rhimportd/main.go b/src/rhimportd/main.go
index e94476c..72785c0 100644
--- a/src/rhimportd/main.go
+++ b/src/rhimportd/main.go
@@ -141,9 +141,9 @@ func main() {
wg.Add(1)
go func() {
defer wg.Done()
- rhl.Println("starting web-ctrl")
- StartControlWeb(webAddr.Get().(string), webStaticDir.Get().(string), conf, db.GetInterface(), sessions.GetInterface())
- rhl.Println("web-ctrl finished")
+ rhl.Println("starting web-router")
+ StartWebRouter(webAddr.Get().(string), webStaticDir.Get().(string), conf, db.GetInterface(), sessions.GetInterface())
+ rhl.Println("web-router finished")
}()
}
diff --git a/src/rhimportd/routeWeb.go b/src/rhimportd/routeWeb.go
new file mode 100644
index 0000000..22db1d7
--- /dev/null
+++ b/src/rhimportd/routeWeb.go
@@ -0,0 +1,58 @@
+//
+// rhimportd
+//
+// The Radio Helsinki Rivendell Import Daemon
+//
+//
+// Copyright (C) 2015-2016 Christian Pointner
+//
+// This file is part of rhimportd.
+//
+// rhimportd is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// any later version.
+//
+// rhimportd is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with rhimportd. If not, see .
+//
+
+package main
+
+import (
+ "code.helsinki.at/rhrd-go/rddb"
+ "code.helsinki.at/rhrd-go/rhimport"
+ "net/http"
+ _ "net/http/pprof"
+ "time"
+)
+
+type webHandler struct {
+ *rhimport.Config
+ *rddb.DBChan
+ *rhimport.SessionStoreChan
+ trusted bool
+ H func(*rhimport.Config, *rddb.DBChan, *rhimport.SessionStoreChan, bool, http.ResponseWriter, *http.Request)
+}
+
+func (self webHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
+ self.H(self.Config, self.DBChan, self.SessionStoreChan, self.trusted, w, r)
+}
+
+func StartWebRouter(addr, staticDir string, conf *rhimport.Config, db *rddb.DBChan, sessions *rhimport.SessionStoreChan) {
+ http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir(staticDir))))
+
+ // http.Handle("/trusted/simple", webHandler{conf, db, sessions, true, webSimpleHandler})
+ http.Handle("/public/simple", webHandler{conf, db, sessions, false, webSimpleHandler})
+ http.Handle("/public/socket", webHandler{conf, db, sessions, false, webSocketHandler})
+ http.Handle("/public/upload", webHandler{conf, db, sessions, false, webUploadHandler})
+
+ rhl.Println("web-router: listening on", addr)
+ server := &http.Server{Addr: addr, ReadTimeout: 2 * time.Hour, WriteTimeout: 2 * time.Hour}
+ server.ListenAndServe()
+}
diff --git a/src/rhimportd/uploadWeb.go b/src/rhimportd/uploadWeb.go
index 7d1f460..84605e6 100644
--- a/src/rhimportd/uploadWeb.go
+++ b/src/rhimportd/uploadWeb.go
@@ -100,7 +100,7 @@ func webUploadParseForm(r *http.Request) (username, sessionid, srcfile string, s
func webUploadHandler(conf *rhimport.Config, db *rddb.DBChan, sessions *rhimport.SessionStoreChan, trusted bool, w http.ResponseWriter, r *http.Request) {
if r.Method == "GET" {
- http.Redirect(w, r, "/static/upload-form.html", http.StatusTemporaryRedirect)
+ http.Redirect(w, r, "/static/upload.html", http.StatusTemporaryRedirect)
return
}
diff --git a/web-static/socket.html b/web-static/socket.html
index 9b118ac..9781e81 100644
--- a/web-static/socket.html
+++ b/web-static/socket.html
@@ -17,6 +17,19 @@
margin-bottom: 1em;
}
+ #progress {
+ background-color: white;
+ border: 1px solid;
+ padding: 1em;
+ font-family: monospace;
+ margin-top: 2em;
+ margin-bottom: 0em;
+ }
+
+ #progress span.caption {
+ font-weight: bold;
+ }
+
td {
text-align: right;
}
@@ -60,6 +73,9 @@
$('#sessionid').val(msg.ID);
buttonsRunning();
break;
+ case "progress":
+ repaintProgress(msg.PROGRESS_STEP_NAME, msg.PROGRESS, msg.TITLE, msg.CART_NUMBER, msg.CUT_NUMBER);
+ break;
case "done":
case "error":
this.sock.close();
@@ -110,23 +126,32 @@
}
function buttonsIdle() {
- $('#buttonrun').removeAttr('disabled')
- $('#buttonreconnect').removeAttr('disabled')
- $('#buttondetach').attr('disabled','disabled')
- $('#buttoncancel').attr('disabled','disabled')
+ $('#buttonrun').removeAttr('disabled');
+ $('#buttonreconnect').removeAttr('disabled');
+ $('#buttondetach').attr('disabled','disabled');
+ $('#buttoncancel').attr('disabled','disabled');
}
function buttonsRunning() {
- $('#buttonrun').attr('disabled','disabled')
- $('#buttonreconnect').attr('disabled','disabled')
- $('#buttondetach').removeAttr('disabled')
- $('#buttoncancel').removeAttr('disabled')
+ $('#buttonrun').attr('disabled','disabled');
+ $('#buttonreconnect').attr('disabled','disabled');
+ $('#buttondetach').removeAttr('disabled');
+ $('#buttoncancel').removeAttr('disabled');
+ }
+
+ function repaintProgress(step, value, title, cart, cut) {
+ $('#progress_step').text("'" + step + "'");
+ $('#progress_value').text(Math.round(value*100)/100 + "%");
+ $('#progress_title').text("'" + title + "'");
+ $('#progress_cart').text(cart);
+ $('#progress_cut').text(cut);
}
function init() {
$('#sessionid').val("");
buttonsIdle();
- $('#buttonlist').removeAttr('disabled','disabled')
+ repaintProgress("", 0, "", 0, 0);
+ $('#buttonlist').removeAttr('disabled','disabled');
}
@@ -154,6 +179,14 @@
+