diff -r bd2f2c3f205c -r dd414da0f0bb client/annot-client/app/app.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/client/annot-client/app/app.js Thu Jan 08 19:15:59 2015 +0100 @@ -0,0 +1,232 @@ +(function(){ + 'use strict'; + + angular.module('mons', [ 'ngResource', 'ngRoute', 'autocomplete' ]) + .config(function($routeProvider) { + $routeProvider. + when('/', { + controller: 'homeCtrl' + }). + otherwise({ + redirectTo: '/' + }); + }) + .config(function($logProvider){ + $logProvider.debugEnabled(true); + }) + .service('dataApi', function($resource, context) { + //console.log('dataApi',$resource, context); + this.dataResource = $resource(context.urls.dataUrl); + }) + .service('dataModel', function(dataApi, context) { + //console.log('dataModel',this,dataApi); + if(typeof context.categories_json !== 'undefined' && context.categories_json) { + this.data = JSON.parse(context.categories_json); + } + else { + 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] + ); + } + + $scope.data = dataModel.data; + + var process_categories = function(data) { + if(typeof data.categories!=='undefined' && data.categories.length>0){ + var cats = []; + var nbCat = data.categories.length; + for(var i=0;i0){ + var nbSubCat = data.categories[i].subcategories.length; + for(var j=0;j0){ + var c = $scope.annotPile.shift(); + //console.log('3 message', c); + //console.log('2',data_json.status,data_json.status==='OK'); + var ok = data_json.status==='OK'; + var i; + if(c===false){ + //showAlert('Annotation envoyée.', true); + $scope.sendBtnSuccess = ok; + $scope.sendBtnError = !ok; + i = $interval(function(){ $interval.cancel(i); $scope.sendBtnSuccess = false; $scope.sendBtnError = false; }, 2000, 1); + } + else{ + c.sendSuccess = ok; + c.sendError = !ok; + i = $interval(function(){ $interval.cancel(i); c.sendSuccess = false; c.sendError = false; }, 2000, 1); + } + if(!$scope.$$phase) { + $scope.$apply(); + } + } + }; + } + + $scope.sendAnnotation = function(label, code, c){ + if($scope.username==='' || typeof $scope.username==='undefined'){ + showAlert('Vous devez indiquer un nom d\'utilisateur.', false); + return; + } + if(label==='' || typeof label==='undefined'){ + showAlert('Vous devez indiquer un nom de catégorie.', false); + return; + } + // Send query + if (sock) { + if(typeof code==='undefined' || code===''){ + code = window.S(label).slugify().s; + } + var new_annot = { + category: {code: code, label: label}, + user : $scope.username + }; + sock.send(JSON.stringify(new_annot)); + if(context.logging===true){ + log('Sent: ' + JSON.stringify(new_annot)); + } + if(typeof c==='undefined'){ + $scope.annotPile.push(false); + } + else{ + $scope.annotPile.push(c); + } + } else { + showAlert('La socket ne fonctionne pas.', false); + if(context.logging===true){ + log('Not connected.'); + } + } + }; + + // Interface management + $scope.selectLevel = function(label, code, c){ + if(typeof c==='undefined'){ + $scope.returnVisStyle = {visibility:'hidden'}; + $scope.selectedlevel = false; + return; + } + if(typeof c.subcategories!=='undefined' && c.subcategories.length>0){ + $scope.selectedlevel = c.subcategories; + $scope.returnVisStyle = {visibility:'show'}; + } + else{ + // Send query + //console.log('send ntm', c); + $scope.sendAnnotation(label, code, c); + } + }; + + }); + +})();