Author: obruce Date: 2014-04-30 11:49:43 +0200 (Wed, 30 Apr 2014) New Revision: 2961 Url: http://forge.chorem.org/projects/jtimer/repository/revisions/2961 Log: controller: Correction des erreurs + ajout du temps tasks.html et app.js: ajout d'un message ?\195?\160 la suppression entities: changement dans globaltime Modified: 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/java/org/chorem/jtimer/web/TasksResource.java branches/ng-jtimer/src/main/webapp/js/app.js 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/storage/Storage.java =================================================================== --- branches/ng-jtimer/src/main/java/org/chorem/jtimer/storage/Storage.java 2014-04-28 16:05:41 UTC (rev 2960) +++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/storage/Storage.java 2014-04-30 09:49:43 UTC (rev 2961) @@ -195,7 +195,7 @@ PreparedStatement statement = null; PreparedStatement statement2 = null; try { - statement = connection.prepareStatement("SELECT TA.*, sum(TI.duration) AS totalduration FROM " + + statement = connection.prepareStatement("SELECT TA.*, MIN(TI.date) as modifdate, sum(TI.duration) AS totalduration FROM " + TABLE_TASK + " TA, " + TABLE_TIME + " TI" + " WHERE TA.id = TI.taskid" + " GROUP BY TA.id"); @@ -206,6 +206,7 @@ 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); } @@ -219,6 +220,7 @@ 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); @@ -232,94 +234,8 @@ return tasks; } - /** - * Gets a task by its ID - * @param taskId the task id - * @return a task - */ - public TimerTask getTask(long taskId) { //FIXME: obruce ne gère pas les taches routes - TimerTask task = new TimerTask(); - PreparedStatement statement = null; - try { - statement = connection.prepareStatement("SELECT TA.*, TI.duration AS totalduration FROM " + - TABLE_TASK + " TA, " + TABLE_TIME + " TI " + - " WHERE TA.id = TI.taskid " + - "AND TA.id = " + taskId - ); - ResultSet rs = statement.executeQuery(); - while (rs.next()) { - - task.setNumber(rs.getInt("id")); - task.setName(rs.getString("name")); - task.setParent(rs.getLong("parent")); - task.setTodayTime(0); - task.setTotalTime(rs.getLong("totalduration")); - } - - } catch (SQLException ex) { - throw new StorageException("Can't get task", ex); - } finally { - closeStatement(statement); - } - return task; - } - - /** - * Gets a task by its ID - * - * @return a task - */ - public List<TimerTask> getRecentTasks() { - - List<TimerTask> tasks = new ArrayList<>(); - PreparedStatement statement = null; - PreparedStatement statement2 = null; - try { - statement = connection.prepareStatement("SELECT TA.*, sum(TI.duration) AS totalduration, Max(TI.date) AS lastDate FROM " + - TABLE_TASK + " TA, " + TABLE_TIME + " TI" + - " WHERE TA.id = TI.taskid and TI.date < DATE '1995-12-31'" + - " GROUP BY TA.id"); - - ResultSet rs = statement.executeQuery(); - while (rs.next()) { - TimerTask task = new TimerTask(); - task.setNumber(rs.getInt("id")); - task.setName(rs.getString("name")); - task.setParent(rs.getLong("parent")); - - task.setTodayTime(0); - task.setTotalTime(rs.getLong("totalduration")); - tasks.add(task); - } - - // not timed tasks - statement2 = connection.prepareStatement("SELECT * FROM " + TABLE_TASK + - " WHERE id not in (SELECT taskid FROM " + TABLE_TIME + ")"); - rs = statement2.executeQuery(); - while (rs.next()) { - TimerTask task = new TimerTask(); - task.setNumber(rs.getInt("id")); - task.setName(rs.getString("name")); - task.setParent(rs.getLong("parent")); - task.setTodayTime(0); - task.setTotalTime(0); - tasks.add(task); - } - - } catch (SQLException ex) { - throw new StorageException("Can't get task", ex); - } finally { - closeStatement(statement); - closeStatement(statement2); - } - return tasks; - } - - - - /* Insert, Update, Delete */ public void addTask(TimerTask 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-28 16:05:41 UTC (rev 2960) +++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/RestApplication.java 2014-04-30 09:49:43 UTC (rev 2961) @@ -25,8 +25,8 @@ // Defines only one route router.attach("/tasks", TasksResource.class); - router.attach("/tasks/{taskId}", TaskResource.class); - router.attach("/tasks/{taskId}/time", TimeResource.class); + //router.attach("/tasks/{taskId}", TaskResource.class); + //router.attach("/tasks/{taskId}/time", TimeResource.class); return router; } @@ -38,11 +38,16 @@ TimerTask jTimerProject = new TimerTask(1, "jTimer"); TimerTask jTimerTask1 = new TimerTask(2, "WebService"); + TimerTask jTimerTask2 = new TimerTask(8, "WebService2"); jTimerTask1.setParent(jTimerProject.getNumber()); + jTimerTask2.setParent(jTimerProject.getNumber()); storage.addTask(jTimerProject); storage.addTask(jTimerTask1); + storage.addTask(jTimerTask2); + storage.addTaskTime(jTimerTask1, new Date(), UUID.randomUUID().toString(), 4567); - storage.addTaskTime(jTimerTask1, new Date(), UUID.randomUUID().toString(), 20); + storage.addTaskTime(jTimerTask2, new Date(), UUID.randomUUID().toString(), 45); + storage.addTask(new TimerTask(3, "Chorem")); storage.addTask(new TimerTask(4, "Wikitty")); storage.addTask(new TimerTask(5, "Nuiton-js")); Modified: branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TasksResource.java =================================================================== --- branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TasksResource.java 2014-04-28 16:05:41 UTC (rev 2960) +++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TasksResource.java 2014-04-30 09:49:43 UTC (rev 2961) @@ -25,22 +25,22 @@ @Get("json") public Representation getTasks() { Gson gson = new Gson(); + List<TimerTask> timerTasks = storage.getTasks(); - //On ordonne les donnees, tache fille placee en fin - - List<TimerTask> lesTasks = storage.getTasks(); - int taille = lesTasks.size(); - for(int i =0; i <= taille;i++){ - TimerTask task = lesTasks.get(i); - if(task.getParent() != 0){ - lesTasks.add(task); - lesTasks.remove(i); - taille--; + //On ordonne les donnees, tache fille placee en début + int tabSize = timerTasks.size(); + for(int i =0; i <= tabSize;i++){ + TimerTask task = timerTasks.get(i); + if(task.getParent() == 0){ + timerTasks.add(task); + timerTasks.remove(i); + i--; + tabSize--; } } - String json = gson.toJson(lesTasks); + String json = gson.toJson(timerTasks); return new StringRepresentation(json, MediaType.APPLICATION_JSON); } } Modified: branches/ng-jtimer/src/main/webapp/js/app.js =================================================================== --- branches/ng-jtimer/src/main/webapp/js/app.js 2014-04-28 16:05:41 UTC (rev 2960) +++ branches/ng-jtimer/src/main/webapp/js/app.js 2014-04-30 09:49:43 UTC (rev 2961) @@ -280,3 +280,22 @@ .directive('wtTreeRepeat', wtTreeRepeatDirective) .service('wtWebsocket', wtWebSocketService); + + +/** +* Cette directive permet de confirmer/ infirmer une action. +* Usage: Ajouter attributs: ng-really-message="Êtes vous d'accord?" ng-really-click="takeAction()" +*/ +angular.module('webtimer').directive('ngReallyClick', [function() { + return { + restrict: 'A', + link: function(scope, element, attrs) { + element.bind('click', function() { + var message = attrs.ngReallyMessage; + if (message && confirm(message)) { + scope.$apply(attrs.ngReallyClick); + } + }); + } + } +}]); \ No newline at end of file Modified: branches/ng-jtimer/src/main/webapp/js/controllers.js =================================================================== --- branches/ng-jtimer/src/main/webapp/js/controllers.js 2014-04-28 16:05:41 UTC (rev 2960) +++ branches/ng-jtimer/src/main/webapp/js/controllers.js 2014-04-30 09:49:43 UTC (rev 2961) @@ -41,11 +41,11 @@ - //TODO obruce :Creation de files de temps, de taches - // {Array of Task} la file de tache attendant la synchronisation avec le serveur + //obruce :Creation de files de temps, de taches + // {Array of TaskID} la file de tache attendant la synchronisation avec le serveur $scope.stockedNewTasks = []; - // {Array of Time} la file de temps des taches attendant la synchronisation avec le serveur - $scope.stockedNewTimes = {}; + // {Array of TaskID} la file de temps des taches attendant la synchronisation avec le serveur + $scope.stockedNewTimes = []; /** * Met a jour la tache selectionne, si la tache selectionnee est la courante @@ -106,9 +106,7 @@ }; /** - * Pousse les changements pour que le serveur les stocks - * Nouvelles taches - * nouveaux temps + * Récupère les nouveaux elements du serveur et les ajoute a l'arbre pour l'affichage */ var getChangesFromServ = function(){ @@ -120,9 +118,10 @@ var newTask = new Task( item.name, item.number,item.parent); if(item.parent == 0){ + //Un noeud sans parent est ajouter à l'arbre du scope $scope.data.tasks[newTask.taskId] = newTask; - + save(); if ($scope.tree) { $scope.tree.addChild($scope.createTreeNode(newTask)); } @@ -131,18 +130,30 @@ //Un noeud avec un parent est ajoute à l'arbre de son parent $scope.data.tasks[newTask.taskId] = newTask; - //Le node parent - var node = $scope.createTreeNode( $scope.data.tasks[newTask.parentTaskId]); - node.$$open = true; - save(); - node.addChild($scope.createTreeNode(newTask)); + //On ajoute le temps sur ce noeud + console.log("Ici"); + //console.log($scope.data.times[newTask.TaskId]); + $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(); } } }); }); + + 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(); @@ -183,7 +194,7 @@ $scope.acces = new Date(); } - }, 100000); //TODO: for now 10s but for real put at least 2h: 200000000 + }, 30000); //TODO: for now 10s but for real put at least 2h: 200000000 }; timer(); @@ -196,6 +207,7 @@ //On ajoute à la file de synchro $scope.stockedNewTasks.push(newTask); + $scope.name = ""; save(); if ($scope.tree) { @@ -334,13 +346,10 @@ */ $scope.getTodayTaskTime = function(task) { var times = $scope.data.times[task.taskId]; - var stocktimes = $scope.stockedNewTimes[task.taskId]; if (!times) { times = []; - stocktimes =[]; $scope.data.times[task.taskId]= times; - $scope.stockedNewTimes[task.taskId]=stocktimes; } var result; @@ -353,8 +362,6 @@ if (!result) { result = new TaskTime(task); times.push(result); - stocktimes.push(result); - } return result; @@ -469,12 +476,13 @@ $scope.webSocketClientIdle = false; }; + //force the first server connection + getChangesFromServ(); // force the first tree creation $scope.createTree(); - //force the first server connection - getChangesFromServ(); + // connect to webscocket server (go client) wtWebsocket.connect(); Modified: branches/ng-jtimer/src/main/webapp/js/entities.js =================================================================== --- branches/ng-jtimer/src/main/webapp/js/entities.js 2014-04-28 16:05:41 UTC (rev 2960) +++ branches/ng-jtimer/src/main/webapp/js/entities.js 2014-04-30 09:49:43 UTC (rev 2961) @@ -198,7 +198,7 @@ }; /** - * Retourne le temps consolide pour ce noeud (temps glocal + locaux + enfant) + * Retourne le temps consolide pour ce noeud (temps global + locaux + enfant) * @returns {GlobalTime} */ TreeNode.prototype.getTime = function() { @@ -246,6 +246,17 @@ }; /** + * Ajoute le temps recupere d'une variable + * @param {number} globalTime + * @param {number} todayTime + * @returns {GlobalTime} this + */ +GlobalTime.prototype.addTime = function(globalTime) { + this.global += globalTime; + return this; +}; + +/** * Ajoute les temps d'un tableau de TaskTime au temps global et a today si * la TaskTime est pour today * @param {Array of TaskTime} taskTimes @@ -332,10 +343,16 @@ * @param {Task} task * @returns {TaskTime} */ -var TaskTime = function (task) { +var TaskTime = function (task,date) { this.taskId = task && task.taskId; this.timeId = generateUUID(); - this.date = today(); + + if(!date){ + this.date = today(); + }else{ + this.date = date + } + this.time = 0; }; Modified: branches/ng-jtimer/src/main/webapp/partials/tasks.html =================================================================== --- branches/ng-jtimer/src/main/webapp/partials/tasks.html 2014-04-28 16:05:41 UTC (rev 2960) +++ branches/ng-jtimer/src/main/webapp/partials/tasks.html 2014-04-30 09:49:43 UTC (rev 2961) @@ -73,7 +73,7 @@ <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> - <a class="btn btn-mini" href="" ng-click="removeTask($node)" ng-show="$node.task != currentTask"> + <a class="btn btn-mini" href="" 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="icon-minus"></i> </a> </span> @@ -85,7 +85,9 @@ </div> <!-- Global time of the task --> - <div class="td global" ng-show="showGlobal">{{$node.getTime().global | time}}</div> + <div class="td global" ng-show="showGlobal"> + {{$node.getTime().global | time}} + </div> <!-- Tag of the task --> <div class="td tags" ng-show="showTags" ng-click="editTask($node, 'tags')">