Browse Source

show help text about how to get started in the web interface

Alan Shreve 12 years ago
parent
commit
0e5e369f1a
3 changed files with 51 additions and 8 deletions
  1. 6 2
      assets/ngrok.js
  2. 11 3
      assets/page.html
  3. 34 3
      src/ngrok/client/views/web/http.go

+ 6 - 2
assets/ngrok.js

@@ -98,7 +98,10 @@ ngrok.directive({
 
                 if (!$scope.hasError && !!transform) {
                     try {
-                    body.Text = vkbeautify[transform](body.Text);
+                        // vkbeautify does poorly at formatting html
+                        if (body.ContentType != "text/html") {
+                            body.Text = vkbeautify[transform](body.Text);
+                        }
                     } catch (e) {
                     }
                 }
@@ -148,7 +151,8 @@ ngrok.directive({
 
 ngrok.controller({
     "HttpTxns": function($scope) {
-        $scope.txns = window.txns;
+        $scope.publicUrl = window.data.UiState.Url;
+        $scope.txns = window.data.Txns;
 
         if (!!window.WebSocket) {
             var ws = new WebSocket("ws://localhost:4040/_ws");

+ 11 - 3
assets/page.html

@@ -10,7 +10,7 @@
         <script>hljs.initHighlightingOnLoad();</script>
         <script src="/static/ngrok.js"></script>
         <script type="text/javascript">
-            window.txns = JSON.parse({% . %});
+            window.data = JSON.parse({% . %});
         </script>
         <style type="text/css">
             body { margin-top: 50px; }
@@ -20,7 +20,7 @@
     </head>
 
     <body ng-app="ngrok">
-        <div class="container">
+        <div class="container" ng-controller="HttpTxns">
             <div class="navbar navbar-inverse navbar-fixed-top">
                 <div class="navbar-inner">
                     <div class="container">
@@ -33,7 +33,15 @@
                     </div>
                 </div>
             </div>
-            <ul class="history unstyled" ng-controller="HttpTxns">
+            <div ng-show="txns.length==0" class="row">
+                <div class="span6 offset3">
+                    <div class="well" style="padding: 20px 50px;">
+                        <h4>No requests to display yet</h4>
+                        <p class="lead">Make a request to <a target="_blank" href="{{ publicUrl }}">{{ publicUrl }}</a> to get started!</p>
+                    </div>
+                </div>
+            </div>
+            <ul class="history unstyled">
                 <li ng-repeat="txn in txns">
                     <div class="row">
 

+ 34 - 3
src/ngrok/client/views/web/http.go

@@ -52,19 +52,33 @@ type WebHttpView struct {
 	webview      *WebView
 	ctl          *ui.Controller
 	httpProto    *proto.Http
+	updates      chan interface{}
+	state        chan SerializedUiState
 	HttpRequests *util.Ring
 	idToTxn      map[string]*SerializedTxn
 }
 
+type SerializedUiState struct {
+	Url string
+}
+
+type SerializedPayload struct {
+	Txns    []interface{}
+	UiState SerializedUiState
+}
+
 func NewWebHttpView(wv *WebView, ctl *ui.Controller, proto *proto.Http) *WebHttpView {
 	w := &WebHttpView{
 		webview:      wv,
 		ctl:          ctl,
 		httpProto:    proto,
 		idToTxn:      make(map[string]*SerializedTxn),
+		updates:      ctl.Updates.Reg(),
+		state:        make(chan SerializedUiState),
 		HttpRequests: util.NewRing(20),
 	}
-	go w.update()
+	go w.updateHttp()
+	go w.updateUiState()
 	w.register()
 	return w
 }
@@ -121,7 +135,7 @@ func makeBody(h http.Header, body []byte) SerializedBody {
 	return b
 }
 
-func (whv *WebHttpView) update() {
+func (whv *WebHttpView) updateHttp() {
 	// open channels for incoming http state changes
 	// and broadbasts
 	txnUpdates := whv.httpProto.Txns.Reg()
@@ -188,6 +202,18 @@ func (whv *WebHttpView) update() {
 	}
 }
 
+func (v *WebHttpView) updateUiState() {
+	var s SerializedUiState
+	for {
+		select {
+		case obj := <-v.updates:
+			uiState := obj.(ui.State)
+			s.Url = uiState.GetPublicUrl()
+		case v.state <- s:
+		}
+	}
+}
+
 func (h *WebHttpView) register() {
 	http.HandleFunc("/http/in/replay", func(w http.ResponseWriter, r *http.Request) {
 		r.ParseForm()
@@ -208,7 +234,12 @@ func (h *WebHttpView) register() {
 	http.HandleFunc("/http/in", func(w http.ResponseWriter, r *http.Request) {
 		tmpl := template.Must(template.New("page.html").Delims("{%", "%}").Parse(string(static.PageHtml())))
 
-		payload, err := json.Marshal(h.HttpRequests.Slice())
+		payloadData := SerializedPayload{
+			Txns:    h.HttpRequests.Slice(),
+			UiState: <-h.state,
+		}
+
+		payload, err := json.Marshal(payloadData)
 		if err != nil {
 			panic(err)
 		}