event necessary in client annotation
authorcavaliet
Fri, 17 Oct 2014 13:51:39 +0200
changeset 34 dc21d793b5d4
parent 32 dc1c745850d8
child 35 139737335c8a
event necessary in client annotation
client/app/app.js
--- a/client/app/app.js	Thu Oct 16 21:51:48 2014 +0200
+++ b/client/app/app.js	Fri Oct 17 13:51:39 2014 +0200
@@ -15,7 +15,7 @@
             $logProvider.debugEnabled(true);
         })
         .service('dataApi', function($resource, context) {
-            console.log('dataApi',$resource, context);
+            //console.log('dataApi',$resource, context);
             this.dataResource = $resource(context.urls.dataUrl);
         })
         .service('dataModel', function(dataApi) {
@@ -23,8 +23,15 @@
             this.data = dataApi.dataResource.get();
         })
         .controller('homeCtrl', function($scope, $location, dataModel, context, $interval){
+            
+            function getURLParameter(name) {
+                return decodeURI(
+                    (new RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]
+                );
+            }
+            
             //console.log('homeCtrl 1', $scope, $location, context);
-            console.log('homeCtrl 2', context);
+            //console.log('homeCtrl 2', context);
             $scope.data = dataModel.data;
 
             dataModel.data.$promise.then(function(data) {
@@ -84,7 +91,15 @@
             } else {
                 wsuri = 'ws://' + window.location.hostname + ':8090/annot';
             }
-            wsuri = wsuri + '?event=test';
+            var eventCode = $location.search().event;
+            if(typeof eventCode==='undefined' || eventCode===''){
+                eventCode = getURLParameter('event');
+                if(typeof eventCode==='undefined' || eventCode===''){
+                    alert('le code de l\'événement doit être indiqué dans l\'url selon "?event=CODE_EVENEMENT".');
+                    return;
+                }
+            }
+            wsuri = wsuri + '?event=' + eventCode;
 
             if ('WebSocket' in window) {
                 sock = new WebSocket(wsuri);
@@ -114,11 +129,11 @@
 
                 sock.onmessage = function(e) {
                     if(context.logging){
-                        console.log('Got message: ', e.data);
+                        log('Got message: ', e.data);
                     }
                     //var data_json = JSON.parse(e.data);
                     //showAlert('Annotation bien reçue.', true);
-                    console.log('2 message', $scope.annotPile.length);
+                    //console.log('2 message', $scope.annotPile.length);
                     if($scope.annotPile.length>0){
                         var c = $scope.annotPile.shift();
                         //console.log('3 message', c);
@@ -188,7 +203,7 @@
                 }
                 else{
                     // Send query
-                    console.log('send ntm', c);
+                    //console.log('send ntm', c);
                     $scope.sendAnnotation(label, code, c);
                 }
             };