r2992 - in branches/ng-jtimer/src/main: java/org/chorem/jtimer/storage webapp/js webapp/partials
Author: obruce Date: 2014-05-28 11:38:19 +0200 (Wed, 28 May 2014) New Revision: 2992 Url: http://forge.chorem.org/projects/jtimer/repository/revisions/2992 Log: correction du timeModal et du storage Modified: branches/ng-jtimer/src/main/java/org/chorem/jtimer/storage/Storage.java branches/ng-jtimer/src/main/webapp/js/controllers.js branches/ng-jtimer/src/main/webapp/js/service.js branches/ng-jtimer/src/main/webapp/partials/tasks.html branches/ng-jtimer/src/main/webapp/partials/timeModal.html Modified: branches/ng-jtimer/src/main/java/org/chorem/jtimer/storage/Storage.java =================================================================== --- branches/ng-jtimer/src/main/java/org/chorem/jtimer/storage/Storage.java 2014-05-28 08:05:18 UTC (rev 2991) +++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/storage/Storage.java 2014-05-28 09:38:19 UTC (rev 2992) @@ -295,9 +295,10 @@ statement.setBoolean(3, task.isClosed()); //hidden statement.setString(4, null /*project.getNote()*/);//note statement.setLong(5, task.getModificationDate().getTime()); //modificationDate - statement.setString(6, task.getTaskId()); //taskId - statement.setBoolean(7,task.getRemoved()); + statement.setBoolean(6,task.getRemoved()); + statement.setString(7, task.getTaskId()); //taskId + statement.executeUpdate(); } catch (SQLException ex) { throw new StorageException("Can't modify task", ex); @@ -315,8 +316,8 @@ statement.setLong(1, t.getCreationDate().getTime()); statement.setLong(2, t.getTime()); statement.setLong(3, t.getModificationDate().getTime()); //modificationDate - statement.setString(4, t.getTimeId() ); - statement.setBoolean(5, t.getRemoved()); + statement.setBoolean(4, t.getRemoved()); + statement.setString(5, t.getTimeId() ); statement.executeUpdate(); } catch (SQLException ex) { throw new StorageException("Can't modify time", ex); Modified: branches/ng-jtimer/src/main/webapp/js/controllers.js =================================================================== --- branches/ng-jtimer/src/main/webapp/js/controllers.js 2014-05-28 08:05:18 UTC (rev 2991) +++ branches/ng-jtimer/src/main/webapp/js/controllers.js 2014-05-28 09:38:19 UTC (rev 2992) @@ -13,7 +13,7 @@ $scope.timeAccess = $scope.todo.lastTimeAccess; //interval de conec - var interval = 20000; //TODO: obruce 05-05-14 decider d'un intervalle interessant + var interval = 30000; //TODO: obruce 05-05-14 decider d'un intervalle interessant // periode de delais = 3 periode +1msec var delayAccess = 2 * interval +1; @@ -119,7 +119,42 @@ $localStorage.setTodo("todo", $scope.todo); }; + + /** + * Timer qui met les temps a jour toutes les secondes si une tache est + * active + * @returns {undefined} + */ + var refresh = function() { + $timeout(function() { + if ($scope.currentTask) { + var now = Date.now(); + var taskTime = $scope.getRecentTaskTime($scope.currentTask); + taskTime.addTime(now - $scope.currentTaskDate); + $scope.currentTaskDate = now; + save(); + } + + refresh(); + }, 1000); + }; + refresh(); + + /** + * Timer qui joue des actions sur un interval donné + * @returns {promise} + */ + var timer = function() { + $interval(function() { + pushTodoListToServ(); + updateTasksFromServ(); + updateTimesFromServer(); + }, interval); + }; + timer(); + + /** * Récupère les nouveaux elements du serveur et les ajoute a l'arbre pour l'affichage * */ @@ -157,7 +192,7 @@ }); - console.log("Je suis dans le get tasks"); + console.log("Task initialisé"); //On change la date de dernier acces $scope.taskAccess = Date.now(); $scope.todo.lastTaskAccess= $scope.taskAccess; @@ -184,8 +219,7 @@ //La tache existe if(item.taskId in $scope.data.tasks){ - console.log("Tache existe"); - //console.log(item); + console.log("Tache existe"+item); //On cherche le node et on le met à jour var tmp = $scope.tree.getNode(item.taskId); @@ -200,8 +234,7 @@ }else if(!item.isremoved){ - console.log("Nouvelle tache"); - console.log(item); + console.log("Nouvelle tache" +item); var newTask = new Task( item.name, item.taskId, item.parent); @@ -249,30 +282,29 @@ serverTimeAccess.query({date : $scope.timeAccess-delayAccess}, function (response) { angular.forEach(response, function (item) { - //le temps n'existe pas - console.log("Changement d'une periode"); - console.log(item); var editedTime = getObjectInArrayWithId($scope.data.times[item.taskId],item.timeId); - if(editedTime == undefined){ + if(editedTime){ + if(!item.isremoved){ + console.log("Temps existe donc remplacé"); + //Le temps existe + var editedTime = getObjectInArrayWithId($scope.data.times[item.taskId],item.timeId); + editedTime.time = item.time; + editedTime.creationDate = item.creationDate; - console.log("le temps n'existe pas"); - if(!$scope.data.times[item.taskId]){$scope.data.times[item.taskId] = []} + save(); + } - taskTime = new TaskTime($scope.data.tasks[item.taskId], item.timeId, item.creationDate, item.time); - $scope.data.times[item.taskId].push(taskTime); + }else if(!item.isremoved){ + console.log("le temps n'existe pas"); + //init de l'array des temps de la tache + if(!$scope.data.times[item.taskId]){$scope.data.times[item.taskId] = []} - save(); + taskTime = new TaskTime($scope.data.tasks[item.taskId], item.timeId, item.creationDate, item.time); + $scope.data.times[item.taskId].push(taskTime); - }else{ - console.log("Temps existe donc remplacé"); - //Le temps existe - var editedTime = getObjectInArrayWithId($scope.data.times[item.taskId],item.timeId); - editedTime.time = item.time; - editedTime.creationDate = item.creationDate; - - save(); + save(); } //On change la date de dernier acces @@ -300,13 +332,13 @@ */ var getTimesFromServerWithTask = function(task){ - if(!$scope.data.times[task.taskId]){$scope.data.times[task.taskId] = []} - serverTimeAccess.query({taskId : task.taskId, date : $scope.timeAccess}, function (response) { angular.forEach(response, function (item) { - if(!(existInObject($scope.data.times,item.timeId,task.taskId)) && !(existInObject($scope.todo.stockedDeletedTimes, item.timeId, task.taskId))){ + if(!$scope.data.times[task.taskId]){$scope.data.times[task.taskId] = []} + + if(!(existInObject($scope.data.times,item.timeId,task.taskId)) && !(existInObject($scope.todo.stockedDeletedTimes, item.timeId, task.taskId)) && !item.isremoved){ //On cree le tasktime taskTime = new TaskTime(task, item.timeId, item.creationDate, item.time); $scope.data.times[task.taskId].push(taskTime); @@ -324,7 +356,7 @@ * Methode qui retourne l'existence d'un element dans un array */ var existInObject = function(object, item, pos){ - return (object[pos]) && (item in object[pos]); + return (object[pos]) && (item in object[pos]); }; /** @@ -335,7 +367,7 @@ //On supprime de la base les taches sotckees pour suppression angular.forEach($scope.todo.stockedDeletedTasks, function(task){ - serverTaskAccess.delete({taskId: task}, + serverTaskAccess.deleteTask({taskId: task}, function(){ console.log("delete success" + task); $scope.todo.stockedDeletedTasks.shift(); @@ -384,7 +416,6 @@ function(){ console.log("persist time success" + task); $scope.todo.stockedNewTimes[task].shift(); - console.log($scope.todo.stockedNewTimes[task]); }, function(){ console.log("fail"); @@ -412,7 +443,7 @@ //On supprime de la base les taches sotckees pour suppression angular.forEach($scope.todo.stockedDeletedTimes, function(times,task){ angular.forEach(times, function(time){ - serverTimeAccess.delete({taskId: time}, + serverTimeAccess.deleteTime({taskId: time}, function(){ console.log("delete time success" + task); $scope.todo.stockedDeletedTimes[task].shift(); @@ -429,41 +460,6 @@ /** - * Timer qui met les temps a jour toutes les secondes si une tache est - * active - * @returns {undefined} - */ - var refresh = function() { - $timeout(function() { - if ($scope.currentTask) { - var now = Date.now(); - var taskTime = $scope.getRecentTaskTime($scope.currentTask); - taskTime.addTime(now - $scope.currentTaskDate); - $scope.currentTaskDate = now; - save(); - } - refresh(); - }, 1000); - }; - refresh(); - - /** - * Timer qui joue des actions sur un interval donné - * @returns {promise} - */ - var timer = function() { - $interval(function() { - - pushTodoListToServ(); - updateTasksFromServ(); - updateTimesFromServer(); - - - }, interval); - }; - timer(); - - /** * Ajoute une tache root */ $scope.addTask = function() { @@ -532,7 +528,7 @@ delete $scope.todo.stockedNewTimes[task.taskId]; - serverTaskAccess.delete({taskId: task.taskId}, function(){ + serverTaskAccess.deleteTask({taskId: task.taskId}, function(){ console.log("delete success" + task.taskId); }, function(){ @@ -728,6 +724,7 @@ $scope.currentTask = null; $scope.currentTaskDate = null; } + save(); }; @@ -797,13 +794,17 @@ $scope.popup = function (node){ //Task identifier var id = node.task.taskId; + var data; var modalInstance = $modal.open({ templateUrl: 'partials/timeModal.html', controller: ModalInstanceCtrl, resolve: { - taskTimes : function(){ - return $scope.data.times[id]; + taskTimes : function () { + return angular.copy($scope.data); + }, + indent : function () { + return id; } } @@ -814,6 +815,7 @@ if(item.index != -1){ if(item.action=='Modification'){ //On met la valeur à jour + $scope.data.times[id][item.index].changeCreationDate(item.creationDate); $scope.data.times[id][item.index].changeDuration(item.time); @@ -840,17 +842,27 @@ } if(item.action == 'Suppression'){ - - if(!$scope.todo.stockedDeletedTimes[id]){$scope.todo.stockedDeletedTimes[id] = []}; + // init de l'objet + if(!$scope.todo.stockedDeletedTimes[id]){ + $scope.todo.stockedDeletedTimes[id] = [] + }; + //on pousse l'objet à supprimer $scope.todo.stockedDeletedTimes[id].push($scope.data.times[id][item.index].timeId); $scope.data.times[id].splice(item.index,1); - console.log( $scope.data.times[id]); + if($scope.data.times[id]==[]){ + delete $scope.data.times[id]; + } save(); } - + data = $scope.data.times; } }); + + modalInstance.result.finally(function() { + console.log("finally"); + }); + } /** @@ -894,13 +906,10 @@ } +function ModalInstanceCtrl($scope, $modalInstance, taskTimes,indent) { - -var ModalInstanceCtrl = function ($scope, $modalInstance, taskTimes) { - - // Les temps de la tache - $scope.times = taskTimes; + $scope.times = taskTimes.times[indent]; $scope.dateobj={aTime : new Date(), date : new Date(),}; //L'objet retourner @@ -913,8 +922,12 @@ $scope.activTime = null; //Choix d'action - $scope.periodAction1 =function(){$scope.obj.action = "Ajout"; $scope.act}; - $scope.periodAction2 = function(){$scope.obj.action = "Modification";}; + $scope.periodAction1 = function(){ + $scope.obj.action = "Ajout"; + }; + $scope.periodAction2 = function(){ + $scope.obj.action = "Modification"; + }; $scope.periodAction3 = function(){$scope.obj.action = "Suppression";}; //Pour l'affichage @@ -947,9 +960,13 @@ $scope.cancel = function () { $modalInstance.dismiss('cancel'); }; + + $scope.$on('$destroy', function() { + console.log('Modal scope should be destroyed.'); + }); }; -var datePickerCtrl = function($scope){ +function DatePickerCtrl($scope){ $scope.dateMaxPicker= new Date(); @@ -971,7 +988,7 @@ -var radioTimeCtrl = function ($scope){ +function RadioTimeCtrl($scope){ //Activated button radio $scope.radioModel = 'Left'; @@ -980,8 +997,6 @@ $scope.hstep = 1; $scope.mstep = 1; - $scope.obj.index= null; - /* * Méthode déclancher quand l'heure change dans le timepicker * Change l'objet du controller principal @@ -1011,9 +1026,6 @@ //Empeche de depasser 23:59 $scope.dateobj.aTime = maxDate; $scope.obj.time = maxDate.getTime() - $scope.obj.creationDate; - console.log($scope.obj.time); - console.log(maxDate); - } } } @@ -1026,7 +1038,9 @@ $scope.dateobj.aTime = new Date($scope.obj.creationDate + $scope.obj.time); } } -}; +} + + Modified: branches/ng-jtimer/src/main/webapp/js/service.js =================================================================== --- branches/ng-jtimer/src/main/webapp/js/service.js 2014-05-28 08:05:18 UTC (rev 2991) +++ branches/ng-jtimer/src/main/webapp/js/service.js 2014-05-28 09:38:19 UTC (rev 2992) @@ -6,7 +6,7 @@ query : {method:'GET', isArray:true}, get : {method: 'GET',isArray: false}, update: {method: "PUT"}, - delete: { method: 'DELETE' }, + deleteTask: { method: 'DELETE' }, create: { method: 'POST' } @@ -23,7 +23,8 @@ query : {method:'GET', isArray:true}, get : {method: 'GET', isArray: false}, update: {method: "PUT"}, - create: { method: 'POST' } + create: { method: 'POST' }, + deleteTime: { method: 'DELETE' } } Modified: branches/ng-jtimer/src/main/webapp/partials/tasks.html =================================================================== --- branches/ng-jtimer/src/main/webapp/partials/tasks.html 2014-05-28 08:05:18 UTC (rev 2991) +++ branches/ng-jtimer/src/main/webapp/partials/tasks.html 2014-05-28 09:38:19 UTC (rev 2992) @@ -27,15 +27,15 @@ <!-- Websocket information --> <div id="alerts"> <div class="alert alert-warning" ng-if="!webSocketClientOnline"> - <span class="glyphicon glyphicon-warning-sign"></span> Impossible de contacter le client local pour la gestion de l'inactivité. - <a href="#" target="_blank">Télécharger le client local</a>. + <span class="icon-warning-sign"></span> Impossible de contacter le client local pour la gestion de l'inactivité. + <a target="_blank">Télécharger le client local</a>. </div> </div> <!-- Footer --> <div id="footer"> <span class="left">{{currentDate()}}</span> - <span class="center"><i class="fa fa-html5"></i> <a href="#">WebTimer</a></span> + <span class="center"><i class="fa fa-html5"></i> <a>WebTimer</a></span> <!--<span class="right">{{tree.getTime().today |time}} | {{tree.getTime().global | time}}</span>--> <span class="right">Dernière mise à jour: {{getLastMajDate()}}</span> </div> @@ -76,17 +76,17 @@ <!-- Action button, add,remove activate task --> <span class="btn-group action"> - <a class="btn btn-default btn-xs" href="" ng-click="timeTask($node.task)" ng-show="$level > 1"> + <a class="btn btn-default btn-xs" ng-click="timeTask($node.task)" ng-show="$level > 1"> <i class="glyphicon" ng-class="{'glyphicon-play' : ($node.task != currentTask), 'glyphicon-stop' : ($node.task == currentTask)}"></i> </a> - <a class="btn btn-default btn-xs" href="" ng-click="addSubTask($node)"><i class="glyphicon glyphicon-plus"></i></a> - <a class="btn btn-default btn-xs" href="" + <a class="btn btn-default btn-xs" ng-click="addSubTask($node)"><i class="glyphicon glyphicon-plus"></i></a> + <a class="btn btn-default btn-xs" ng-really-message="La suppression de cette tâche nécessite une confirmation. " ng-really-click="removeTask($node)" ng-show="$node.task != currentTask"> <i class="glyphicon glyphicon-minus"></i> </a> - <a class="btn btn-default btn-xs" href="" ng-click="popup($node)" + <a class="btn btn-default btn-xs" ng-click="popup($node)" ng-show="!$node.task.isRoot() "> <i class="glyphicon glyphicon-pencil" ></i> </a> Modified: branches/ng-jtimer/src/main/webapp/partials/timeModal.html =================================================================== --- branches/ng-jtimer/src/main/webapp/partials/timeModal.html 2014-05-28 08:05:18 UTC (rev 2991) +++ branches/ng-jtimer/src/main/webapp/partials/timeModal.html 2014-05-28 09:38:19 UTC (rev 2992) @@ -6,9 +6,9 @@ Action à faire sur la tâche: <span class="caret"></span> </button> <ul class="dropdown-menu" role="menu"> - <li><a href="#" ng-click="periodAction1()">Ajouter une periode</a></li> - <li><a href="#" ng-click="periodAction2()">Modifier une periode</a></li> - <li><a href="#" ng-click="periodAction3()">Supprimer une periode</a></li> + <li><a ng-click="periodAction1()">Ajouter une periode</a></li> + <li><a ng-click="periodAction2()">Modifier une periode</a></li> + <li><a ng-click="periodAction3()">Supprimer une periode</a></li> </ul> </div> @@ -24,7 +24,7 @@ <li ng-repeat="(index,item) in times" > - <a href="#" ng-click="select(item, index)"> + <a ng-click="select(item, index)"> Début : {{getStartTime(item)}} - Durée : {{getStopTime(item)| time}} </a> @@ -38,11 +38,11 @@ <hr/> <div class ="timepick"> - <div ng-controller="datePickerCtrl" style="display:inline-block; min-height:290px;"> + <div ng-controller="DatePickerCtrl" style="display:inline-block; min-height:290px;"> <datepicker ng-model="dateobj.date" ng-change="changeDayDate()" min-date="minDate" max-date="dateMaxPicker" show-weeks="true" class="well well-sm"></datepicker> </div> - <div class = "timepick" ng-controller="radioTimeCtrl"> + <div class = "timepick" ng-controller="RadioTimeCtrl"> <div> <div class="btn-group"> <label class="btn btn-primary" ng-model="radioModel" ng-change="changeFonc()" btn-radio="'Left'">Début de période </label> @@ -68,7 +68,7 @@ <alert type="danger" >Choisir une période :</alert> - <div class = "timepick" ng-controller="radioTimeCtrl"> + <div class = "timepick" ng-controller="RadioTimeCtrl"> <br/>
participants (1)
-
obruce@users.chorem.org