loggin in annotation client depends on a boolean
authorcavaliet
Thu, 09 Oct 2014 15:22:50 +0200
changeset 6 c53e9b24f93f
parent 5 90a7c431b979
child 7 813fec862542
loggin in annotation client depends on a boolean
client/app/annotationclient.html
client/app/app.js
--- a/client/app/annotationclient.html	Thu Oct 09 14:34:14 2014 +0200
+++ b/client/app/annotationclient.html	Thu Oct 09 15:22:50 2014 +0200
@@ -38,7 +38,7 @@
               <div class="table">
                 <div class="table-cell">
                   <p class="large-cat">ENVOYER</p>
-                  <p class="normal-cat">la catégorie saisie</p>
+                  <p class="normal-cat">la catégorie saisie - {{ myvar }} -</p>
                 </div>
               </div>
           </div>
@@ -71,9 +71,9 @@
       </div>
     </div>
     <footer>
-	  <div class="row">
+	  {% if logging %}<div class="row">
 	    <pre id="log" style="height: 20em; overflow-y: scroll; background-color: #faa; text-align: left;"></pre>
-      </div>
+      </div>{% endif %}
       <div class="row">
         <div class="col-md-12 text-center">
             mons vBeta - ©IRI-2014
@@ -88,6 +88,7 @@
       
     angular.module("mons")
         .value('context', {
+            {% if logging %}logging: true,{% endif %}
             urls: {
                 dataUrl: "{{ pre_static_path }}static/data/categories.json"
             }
--- a/client/app/app.js	Thu Oct 09 14:34:14 2014 +0200
+++ b/client/app/app.js	Thu Oct 09 15:22:50 2014 +0200
@@ -29,7 +29,6 @@
             
             dataModel.data.$promise.then(function(data) {
                 if(typeof data.categories!=='undefined' && data.categories.length>0){
-                    console.log('    JE RENTRE');
                     var cats = [];
                     var nbCat = data.categories.length;
                     for(var i=0;i<nbCat;i++){
@@ -55,10 +54,11 @@
             var ellog = null;
             
             ellog = document.getElementById('log');
-            
             function log(m) {
-                ellog.innerHTML += m + '\n';
-                ellog.scrollTop = ellog.scrollHeight;
+                if(ellog){
+                    ellog.innerHTML += m + '\n';
+                    ellog.scrollTop = ellog.scrollHeight;
+                }
             }
 
             var wsuri;
@@ -74,22 +74,32 @@
             } else if ('MozWebSocket' in window) {
                 sock = new window.MozWebSocket(wsuri);
             } else {
-                log('Browser does not support WebSocket!');
+                if(context.logging===true){
+                    log('Browser does not support WebSocket!');
+                }
                 window.location = 'http://autobahn.ws/unsupportedbrowser';
             }
-            console.log('hi 1', sock);
+            console.log('socket in controller = ', sock);
             if (sock) {
                 sock.onopen = function() {
-                    log('Connected to ' + wsuri);
+                    if(context.logging===true){
+                        log('Connected to ' + wsuri);
+                    }
                 };
 
                 sock.onclose = function(e) {
-                    log('Connection closed (wasClean = ' + e.wasClean + ', code = ' + e.code + ', reason = "' + e.reason + '")');
+                    if(context.logging===true){
+                        log('Connection closed (wasClean = ' + e.wasClean + ', code = ' + e.code + ', reason = ' + e.reason + ')');
+                    }
+                    alert('Communication interrompue : la socket vient de se fermer.');
                     sock = null;
                 };
 
                 sock.onmessage = function(e) {
-                    log('Got message: ' + e.data);
+                    if(context.logging===true){
+                        log('Got message: ' + e.data);
+                    }
+                    alert('Annotation bien reçue.');
                 };
             }
 
@@ -106,14 +116,20 @@
                 if (sock) {
                     var new_annot = {
                             categories : eventCode,
-                            user : 'admin'
+                            user : $scope.username
                     };
                     sock.send(JSON.stringify(new_annot));
-                    log('Sent: ' + JSON.stringify(new_annot));
+                    if(context.logging===true){
+                        log('Sent: ' + JSON.stringify(new_annot));
+                    }
                 } else {
-                    log('Not connected.');
+                    if(context.logging===true){
+                        alert('La socket ne fonctionne pas.');
+                        if(context.logging===true){
+                            log('Not connected.');
+                        }
+                    }
                 }
-                //alert('annotation envoyée ! eventCode = ' + eventCode);
             };
             
             // Interface management