annot-server/static/js/app.js
changeset 107 6d41506f9482
parent 84 d7c5bffdd2d8
child 109 8546e2181a73
equal deleted inserted replaced
106:9b20ddf1fc70 107:6d41506f9482
    31 
    31 
    32             function getURLParameter(name) {
    32             function getURLParameter(name) {
    33                 return decodeURI(
    33                 return decodeURI(
    34                     (new RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]
    34                     (new RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]
    35                 );
    35                 );
       
    36             }
       
    37 
       
    38             function parseColor(input) {
       
    39                 var m = input.match(/^rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$/i);
       
    40                 if( m) return [m[1],m[2],m[3]];
       
    41                 else throw new Error("Colour "+input+" could not be parsed.");
       
    42             }
       
    43 
       
    44             function rgbToHex(r, g, b) {
       
    45                 return "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);
    36             }
    46             }
    37 
    47 
    38             $scope.data = dataModel.data;
    48             $scope.data = dataModel.data;
    39 
    49 
    40             var process_categories = function(data) {
    50             var process_categories = function(data) {
    48                             for(var j=0;j<nbSubCat;j++){
    58                             for(var j=0;j<nbSubCat;j++){
    49                                 cats.push(data.categories[i].subcategories[j].label);
    59                                 cats.push(data.categories[i].subcategories[j].label);
    50                             }
    60                             }
    51                         }
    61                         }
    52                     }
    62                     }
    53                     $scope.allCatLabels = cats;
    63                     if(typeof data.autocomplete === 'undefined' || data.autocomplete.length === 0) {
       
    64                         $scope.allCatLabels = cats;
       
    65                     }
       
    66                     else {
       
    67                         $scope.allCatLabels = data.autocomplete;
       
    68                     }
    54                 }
    69                 }
    55             };
    70             };
    56 
    71 
    57             if (typeof dataModel.data.$promise !== 'undefined') {
    72             if (typeof dataModel.data.$promise !== 'undefined') {
    58                 dataModel.data.$promise.then(process_categories);
    73                 dataModel.data.$promise.then(process_categories);
    99             if (window.location.protocol === 'file:') {
   114             if (window.location.protocol === 'file:') {
   100                 wsuri = 'ws://127.0.0.1:8090/annot';
   115                 wsuri = 'ws://127.0.0.1:8090/annot';
   101             } else {
   116             } else {
   102                 wsuri = 'ws://' + window.location.hostname + ':8090/annot';
   117                 wsuri = 'ws://' + window.location.hostname + ':8090/annot';
   103             }
   118             }
   104             
   119 
   105             var eventCode = context.event_code;
   120             var eventCode = context.event_code;
   106             if(typeof eventCode==='undefined' || eventCode===''){
   121             if(typeof eventCode==='undefined' || eventCode===''){
   107                 eventCode = $location.search().event;
   122                 eventCode = $location.search().event;
   108                 if(typeof eventCode==='undefined' || eventCode===''){
   123                 if(typeof eventCode==='undefined' || eventCode===''){
   109                     eventCode = getURLParameter('event');
   124                     eventCode = getURLParameter('event');
   171                         }
   186                         }
   172                     }
   187                     }
   173                 };
   188                 };
   174             }
   189             }
   175 
   190 
   176             $scope.sendAnnotation = function(label, code, c){
   191             $scope.sendFreeAnnotation = function(label, text) {
       
   192                 $scope.sendAnnotation(label, window.S(label).slugify().s, label, text, $scope.data.defaultColor || "#536991");
       
   193             };
       
   194 
       
   195             $scope.sendAnnotation = function(label, code, freeLabel, freetext, color, c){
       
   196 
   177                 if($scope.username==='' || typeof $scope.username==='undefined'){
   197                 if($scope.username==='' || typeof $scope.username==='undefined'){
   178                     showAlert('Vous devez indiquer un nom d\'utilisateur.', false);
   198                     showAlert('Vous devez indiquer un nom d\'utilisateur.', false);
   179                     return;
   199                     return;
   180                 }
   200                 }
   181                 if(label==='' || typeof label==='undefined'){
   201                 if(label==='' || typeof label==='undefined'){
   185                 // Send query
   205                 // Send query
   186                 if (sock) {
   206                 if (sock) {
   187                     if(typeof code==='undefined' || code===''){
   207                     if(typeof code==='undefined' || code===''){
   188                         code = window.S(label).slugify().s;
   208                         code = window.S(label).slugify().s;
   189                     }
   209                     }
       
   210 
       
   211                     var hexc;
       
   212                     if(color.substring(0, 4) === 'rgb(') {
       
   213                         var rgbc = parseColor(color);
       
   214                         hexc = rgbToHex(rgbc[0],rgbc[1], rgbc[2]);
       
   215                     }
       
   216                     else {
       
   217                         hexc = color;
       
   218                     }
       
   219 
       
   220 
   190                     var new_annot = {
   221                     var new_annot = {
   191                             category: {code: code, label: label},
   222                             category: {code: code, label: label},
       
   223                             text: freetext,
       
   224                             color: hexc,
   192                             user : $scope.username
   225                             user : $scope.username
   193                     };
   226                     };
   194                     sock.send(JSON.stringify(new_annot));
   227                     sock.send(JSON.stringify(new_annot));
   195                     if(context.logging===true){
   228                     if(context.logging===true){
   196                         log('Sent: ' + JSON.stringify(new_annot));
   229                         log('Sent: ' + JSON.stringify(new_annot));
   199                         $scope.annotPile.push(false);
   232                         $scope.annotPile.push(false);
   200                     }
   233                     }
   201                     else{
   234                     else{
   202                         $scope.annotPile.push(c);
   235                         $scope.annotPile.push(c);
   203                     }
   236                     }
       
   237                     $scope.catText = "";
       
   238                     $scope.catLabel = "";
   204                 } else {
   239                 } else {
   205                     showAlert('La socket ne fonctionne pas.', false);
   240                     showAlert('La socket ne fonctionne pas.', false);
   206                     if(context.logging===true){
   241                     if(context.logging===true){
   207                         log('Not connected.');
   242                         log('Not connected.');
   208                     }
   243                     }
   209                 }
   244                 }
   210             };
   245             };
   211 
   246 
   212             // Interface management
   247             // Interface management
   213             $scope.selectLevel = function(label, code, c){
   248             $scope.selectLevel = function(label, code, freelabel, freetext, color, c){
   214                 if(typeof c==='undefined'){
   249                 if(typeof c==='undefined'){
   215                     $scope.returnVisStyle = {visibility:'hidden'};
   250                     $scope.returnVisStyle = {visibility:'hidden'};
   216                     $scope.selectedlevel = false;
   251                     $scope.selectedlevel = false;
   217                     return;
   252                     return;
   218                 }
   253                 }
   221                     $scope.returnVisStyle = {visibility:'show'};
   256                     $scope.returnVisStyle = {visibility:'show'};
   222                 }
   257                 }
   223                 else{
   258                 else{
   224                     // Send query
   259                     // Send query
   225                     //console.log('send ntm', c);
   260                     //console.log('send ntm', c);
   226                     $scope.sendAnnotation(label, code, c);
   261                     $scope.sendAnnotation(label, code, freelabel, freetext, color, c);
   227                 }
   262                 }
   228             };
   263             };
   229 
   264 
   230         });
   265         });
   231 
   266