add status to annotation creation. Improve error management for annotation creation
authorymh <ymh.work@gmail.com>
Tue, 14 Oct 2014 08:12:54 +0200
changeset 23 16a1925df2df
parent 22 986ee928a866
child 24 eb1f7b06001f
add status to annotation creation. Improve error management for annotation creation
annot-server/webapp/__init__.py
annot-server/webapp/templates/annot.html
annot-server/webapp/templates/index.html
annot-server/websockets.py
client/app/app.js
--- a/annot-server/webapp/__init__.py	Tue Oct 14 05:07:37 2014 +0200
+++ b/annot-server/webapp/__init__.py	Tue Oct 14 08:12:54 2014 +0200
@@ -17,7 +17,3 @@
 app.config.from_object(config)
 
 import webapp.views
-
-@app.teardown_appcontext
-def shutdown_session(exception=None):
-    database.db_session.remove()
--- a/annot-server/websockets.py	Tue Oct 14 05:07:37 2014 +0200
+++ b/annot-server/websockets.py	Tue Oct 14 08:12:54 2014 +0200
@@ -93,13 +93,17 @@
         }
 
         def error_callback(failure):
-            raise http.HttpException(500,"Error when processing message : %r" % failure)
+            res = params.copy()
+            res['status'] = 'KO'
+            res['failure'] = str(failure)
+            self.sendMessage(json.dumps(res))
 
         def annot_callback(res):
             if 'ts' in res:
                 res['ts'] = res['ts'].isoformat()+'Z'
             if 'uuid' in res:
                 res['uuid'] = str(res['uuid'])
+            res['status'] = 'OK'
             self.sendMessage(json.dumps(res))
 
 
--- a/client/app/app.js	Tue Oct 14 05:07:37 2014 +0200
+++ b/client/app/app.js	Tue Oct 14 08:12:54 2014 +0200
@@ -26,7 +26,7 @@
             //console.log('homeCtrl 1', $scope, $location, context);
             console.log('homeCtrl 2', context);
             $scope.data = dataModel.data;
-            
+
             dataModel.data.$promise.then(function(data) {
                 if(typeof data.categories!=='undefined' && data.categories.length>0){
                     var cats = [];
@@ -43,7 +43,7 @@
                     $scope.allCatLabels = cats;
                 }
             });
-            
+
             $scope.selectedlevel = false;
 
             $scope.currentInterval = false;
@@ -63,13 +63,13 @@
                 $scope.currentInterval = $interval(function(){ $interval.cancel($scope.currentInterval); $scope.showAlertDiv = false; }, 2000, 1);
             }
             $scope.annotPile = [];
-            
-            
+
+
 
             // Socket management
             var sock = null;
             var ellog = null;
-            
+
             ellog = document.getElementById('log');
             function log(m) {
                 if(ellog){
@@ -96,7 +96,7 @@
                 }
                 window.location = 'http://autobahn.ws/unsupportedbrowser';
             }
-            
+
             if (sock) {
                 sock.onopen = function() {
                     if(context.logging===true){
@@ -113,9 +113,10 @@
                 };
 
                 sock.onmessage = function(e) {
-                    if(context.logging===true){
-                        log('Got message: ' + e.data);
+                    if(context.logging){
+                        console.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);
                     if($scope.annotPile.length>0){
@@ -173,7 +174,7 @@
                     }
                 }
             };
-            
+
             // Interface management
             $scope.selectLevel = function(label, code, c){
                 if(typeof c==='undefined'){
@@ -191,7 +192,7 @@
                     $scope.sendAnnotation(label, code, c);
                 }
             };
-            
+
         });
 
 })();