Author: obruce Date: 2014-05-02 11:57:35 +0200 (Fri, 02 May 2014) New Revision: 2962 Url: http://forge.chorem.org/projects/jtimer/repository/revisions/2962 Log: controller: Ajout des p?\195?\169riodes dans le controller. bdd: changement g?\195?\169r?\195?\169 avec la base existante ui: timer les taches projets enlev?\195?\169s Modified: branches/ng-jtimer/src/main/java/org/chorem/jtimer/entities/TimerTask.java branches/ng-jtimer/src/main/java/org/chorem/jtimer/storage/Storage.java branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/RestApplication.java branches/ng-jtimer/src/main/webapp/js/controllers.js branches/ng-jtimer/src/main/webapp/js/entities.js branches/ng-jtimer/src/main/webapp/partials/tasks.html Modified: branches/ng-jtimer/src/main/java/org/chorem/jtimer/entities/TimerTask.java =================================================================== --- branches/ng-jtimer/src/main/java/org/chorem/jtimer/entities/TimerTask.java 2014-04-30 09:49:43 UTC (rev 2961) +++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/entities/TimerTask.java 2014-05-02 09:57:35 UTC (rev 2962) @@ -84,7 +84,7 @@ /** * Get task number. - * + * * @return the number */ public long getNumber() { @@ -93,7 +93,7 @@ /** * Set task number. - * + * * @param number the number to set */ public void setNumber(long number) { 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-04-30 09:49:43 UTC (rev 2961) +++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/storage/Storage.java 2014-05-02 09:57:35 UTC (rev 2962) @@ -195,7 +195,7 @@ PreparedStatement statement = null; PreparedStatement statement2 = null; try { - statement = connection.prepareStatement("SELECT TA.*, MIN(TI.date) as modifdate, sum(TI.duration) AS totalduration FROM " + + statement = connection.prepareStatement("SELECT TA.*, sum(TI.duration) AS totalduration FROM " + TABLE_TASK + " TA, " + TABLE_TIME + " TI" + " WHERE TA.id = TI.taskid" + " GROUP BY TA.id"); @@ -206,7 +206,6 @@ task.setName(rs.getString("name")); task.setParent(rs.getLong("parent")); task.setTodayTime(0); - task.setCreationDate(new java.util.Date(rs.getDate("modifdate").getTime())); task.setTotalTime(rs.getLong("totalduration")); tasks.add(task); } @@ -220,7 +219,6 @@ task.setNumber(rs.getInt("id")); task.setName(rs.getString("name")); task.setParent(rs.getLong("parent")); - task.setCreationDate(new Date()); task.setTodayTime(0); task.setTotalTime(0); tasks.add(task); Modified: branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/RestApplication.java =================================================================== --- branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/RestApplication.java 2014-04-30 09:49:43 UTC (rev 2961) +++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/RestApplication.java 2014-05-02 09:57:35 UTC (rev 2962) @@ -46,6 +46,7 @@ storage.addTask(jTimerTask2); storage.addTaskTime(jTimerTask1, new Date(), UUID.randomUUID().toString(), 4567); + storage.addTaskTime(jTimerTask1, new Date(), UUID.randomUUID().toString(), 1000000); storage.addTaskTime(jTimerTask2, new Date(), UUID.randomUUID().toString(), 45); storage.addTask(new TimerTask(3, "Chorem")); Modified: branches/ng-jtimer/src/main/webapp/js/controllers.js =================================================================== --- branches/ng-jtimer/src/main/webapp/js/controllers.js 2014-04-30 09:49:43 UTC (rev 2961) +++ branches/ng-jtimer/src/main/webapp/js/controllers.js 2014-05-02 09:57:35 UTC (rev 2962) @@ -6,7 +6,7 @@ $scope.data = $localStorage.get("data"); // {Date} last update to server - $scope.acces = new Date(); + $scope.acces = moment().format("DD-MM-YYYY H:mm:ss"); // {TreeNode} l'arbre regenere automatiquement lorsque les donnees changent $scope.tree; @@ -18,6 +18,10 @@ $scope.selectedTask = null; // {Task} la tache en cours de timing $scope.currentTask = null; + + // {Array of TaskId} la tache en cours de timing + $scope.activeTask = []; + // {Date in millis} le temps pour la tache en cours de timing $scope.currentTaskDate = null; // {String} le filtre d'affichage des noeuds (permet la recherche d'un noeud) @@ -67,7 +71,7 @@ * @returns {undefined} */ $document[0].onkeydown = function(e){ - console.log(e); + ///console.log(e); // i = 73; d = 68; F2 = 113 if ($scope.selectedTask) { var taskTime = $scope.getTodayTaskTime($scope.selectedTask); @@ -131,14 +135,10 @@ //Un noeud avec un parent est ajoute à l'arbre de son parent $scope.data.tasks[newTask.taskId] = newTask; - //On ajoute le temps sur ce noeud - console.log("Ici"); - //console.log($scope.data.times[newTask.TaskId]); + //On ajoute le temps du jour et global sur ce noeud $scope.getTodayTaskTime($scope.data.tasks[newTask.taskId]).addTime(item.todayTime); var global = new GlobalTime(newTask).addTime(parseInt(item.totalTime)); - console.log(item.totalTime); - console.log(global); $scope.data.globalTimes[newTask.taskId] = global; save(); @@ -148,15 +148,6 @@ }); }); - console.log("temps globaux "); - console.log($scope.data.globalTimes); - - console.log("temps par jour"); - console.log($scope.data.times); - - console.log("Fin de getChanges from serv"); - console.log($scope.data.tasks); - //save(); }; @@ -169,7 +160,7 @@ $timeout(function() { if ($scope.currentTask) { var now = Date.now(); - var taskTime = $scope.getTodayTaskTime($scope.currentTask); + var taskTime = $scope.getRecentTaskTime($scope.currentTask); taskTime.addTime(now - $scope.currentTaskDate); $scope.currentTaskDate = now; save(); @@ -189,9 +180,8 @@ if ( $scope.online == true) { getChangesFromServ(); - - //console.log(new Date()); - $scope.acces = new Date(); + //On change la date de dernier acces + $scope.acces = moment().format("DD-MM-YYYY H:mm:ss a"); } }, 30000); //TODO: for now 10s but for real put at least 2h: 200000000 @@ -368,6 +358,41 @@ }; /** + * Retourne l'objet TaskTime d'aujourd'hui pour la tache demandee + * Si cet objet n'existait pas, il est cree et ajouter a la liste + * des objets temps existant + * @param {type} task + * @returns {nodes} + */ + $scope.getRecentTaskTime = function(task) { + var times = $scope.data.times[task.taskId]; + + if (!times) { + times = []; + $scope.data.times[task.taskId]= times; + } + + var maxDate = new Date(0,0,0,0,0); + var result; + + angular.forEach(times, function (t) { + if (t.isToday()) { + if(maxDate < new Date(t.date)){ + maxDate = new Date(t.date); + result = t; + } + } + }); + + if (!result) { + result = new TaskTime(task); + times.push(result); + } + + return result; + }; + + /** * Lance l'edition du nom d'une tache * @param {TreeNode} node * @param {String} type le type d'action @@ -392,20 +417,31 @@ * @param {type} element */ $scope.timeTask = function(task, element) { - var now = Date.now(); + var now = Date.now(); //ms since 1970 + + //Si une tache est en cours de timing if ($scope.currentTask) { - var taskTime = $scope.getTodayTaskTime($scope.currentTask); + var taskTime = $scope.getRecentTaskTime($scope.currentTask); taskTime.addTime(now - $scope.currentTaskDate); - } - + //si ce n'est la la tache courante actuel if ($scope.currentTask !== task) { + //On ajoute un nouveau timeTask dans la liste des times + var times = $scope.data.times[task.taskId]; + if (!times) { + times = []; + $scope.data.times[task.taskId]= times; + } + times.push(new TaskTime(task)); + + //On change la task courante $scope.currentTask = task; $scope.currentTaskDate = now; } else { $scope.currentTask = null; $scope.currentTaskDate = null; } + save(); }; Modified: branches/ng-jtimer/src/main/webapp/js/entities.js =================================================================== --- branches/ng-jtimer/src/main/webapp/js/entities.js 2014-04-30 09:49:43 UTC (rev 2961) +++ branches/ng-jtimer/src/main/webapp/js/entities.js 2014-05-02 09:57:35 UTC (rev 2962) @@ -304,6 +304,14 @@ /** + * Change la date de derniere modification + * @returns {undefined} + */ +Task.prototype.setModificationDate = function() { + this.modificationDate = Date.now(); +}; + +/** * Marque la tache comme supprimee * @returns {undefined} */ @@ -343,16 +351,14 @@ * @param {Task} task * @returns {TaskTime} */ -var TaskTime = function (task,date) { +var TaskTime = function (task) { this.taskId = task && task.taskId; this.timeId = generateUUID(); - if(!date){ - this.date = today(); - }else{ - this.date = date - } + this.date = today(); + //this.date = Date.now(); + this.time = 0; }; Modified: branches/ng-jtimer/src/main/webapp/partials/tasks.html =================================================================== --- branches/ng-jtimer/src/main/webapp/partials/tasks.html 2014-04-30 09:49:43 UTC (rev 2961) +++ branches/ng-jtimer/src/main/webapp/partials/tasks.html 2014-05-02 09:57:35 UTC (rev 2962) @@ -69,7 +69,7 @@ <!-- Action button, add,remove activate task --> <span class="btn-group action"> - <a class="btn btn-mini" href="" ng-click="timeTask($node.task)"> + <a class="btn btn-mini" href="" ng-click="timeTask($node.task)" ng-show="$level > 1"> <i ng-class="{'icon-play' : ($node.task != currentTask), 'icon-stop' : ($node.task == currentTask)}"></i> </a> <a class="btn btn-mini" href="" ng-click="addSubTask($node)"><i class="icon-plus"></i></a>