r2960 - in branches/ng-jtimer/src/main: config java/org/chorem/jtimer/storage java/org/chorem/jtimer/web webapp webapp/js webapp/partials
Author: obruce Date: 2014-04-28 18:05:41 +0200 (Mon, 28 Apr 2014) New Revision: 2960 Url: http://forge.chorem.org/projects/jtimer/repository/revisions/2960 Log: TasksResource ordonne element dans le JSON Service.js acces au serveur entities controller : changement de de webtimerdata + ajout query du serveur + construction de l'arbre Added: branches/ng-jtimer/src/main/webapp/js/service.js Modified: branches/ng-jtimer/src/main/config/wro.xml branches/ng-jtimer/src/main/java/org/chorem/jtimer/storage/Storage.java branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TasksResource.java branches/ng-jtimer/src/main/webapp/index.html 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 branches/ng-jtimer/src/main/webapp/webtimer.appcache Modified: branches/ng-jtimer/src/main/config/wro.xml =================================================================== --- branches/ng-jtimer/src/main/config/wro.xml 2014-04-23 14:43:13 UTC (rev 2959) +++ branches/ng-jtimer/src/main/config/wro.xml 2014-04-28 16:05:41 UTC (rev 2960) @@ -3,6 +3,7 @@ <group-ref>jquery</group-ref> <group-ref>angular</group-ref> <group-ref>angular-route</group-ref> + <group-ref>angular-resource</group-ref> <group-ref>angular-animate</group-ref> <group-ref>bootstrap</group-ref> <group-ref>font-awesome</group-ref> 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-23 14:43:13 UTC (rev 2959) +++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/storage/Storage.java 2014-04-28 16:05:41 UTC (rev 2960) @@ -237,17 +237,17 @@ * @param taskId the task id * @return a task */ - public TimerTask getTask(long taskId) { + public TimerTask getTask(long taskId) { //FIXME: obruce ne gère pas les taches routes TimerTask task = new TimerTask(); PreparedStatement statement = null; - PreparedStatement statement2 = null; try { statement = connection.prepareStatement("SELECT TA.*, TI.duration AS totalduration FROM " + - TABLE_TASK + " TA, " + TABLE_TIME + " TI" + + TABLE_TASK + " TA, " + TABLE_TIME + " TI " + " WHERE TA.id = TI.taskid " + - "AND TA.id = " + taskId +" " + "AND TA.id = " + taskId ); + ResultSet rs = statement.executeQuery(); while (rs.next()) { 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-23 14:43:13 UTC (rev 2959) +++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TasksResource.java 2014-04-28 16:05:41 UTC (rev 2960) @@ -1,5 +1,6 @@ package org.chorem.jtimer.web; +import org.chorem.jtimer.entities.TimerTask; import org.chorem.jtimer.storage.Storage; import org.restlet.data.MediaType; import org.restlet.representation.Representation; @@ -10,6 +11,8 @@ import com.google.gson.Gson; +import java.util.List; + public class TasksResource extends ServerResource { protected Storage storage; @@ -22,7 +25,22 @@ @Get("json") public Representation getTasks() { Gson gson = new Gson(); - String json = gson.toJson(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--; + } + + } + + String json = gson.toJson(lesTasks); return new StringRepresentation(json, MediaType.APPLICATION_JSON); } } Modified: branches/ng-jtimer/src/main/webapp/index.html =================================================================== --- branches/ng-jtimer/src/main/webapp/index.html 2014-04-23 14:43:13 UTC (rev 2959) +++ branches/ng-jtimer/src/main/webapp/index.html 2014-04-28 16:05:41 UTC (rev 2960) @@ -3,8 +3,8 @@ <head> <title>jTimer</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> - - + + <link rel="stylesheet" href="css/jtimer.css"> <script src="js/jtimer.js"></script> @@ -15,8 +15,9 @@ <script src="js/controllers.js"></script> <script src="js/filters.js"></script> <script src="js/entities.js"></script> - - + <script src="js/service.js"></script> + + </head> <body> Modified: branches/ng-jtimer/src/main/webapp/js/app.js =================================================================== --- branches/ng-jtimer/src/main/webapp/js/app.js 2014-04-23 14:43:13 UTC (rev 2959) +++ branches/ng-jtimer/src/main/webapp/js/app.js 2014-04-28 16:05:41 UTC (rev 2960) @@ -200,6 +200,9 @@ }; }]; +/** + * Pour le websocket + */ var wtWebSocketService = [function() { var service = {}; @@ -240,7 +243,11 @@ }]; -angular.module('webtimer', ['webtimerFilters', 'ngRoute', 'ngAnimate', 'ui.bootstrap']) + +/** + * Module de webtimer + **/ +angular.module('webtimer', ['webtimerFilters', 'ngRoute', 'ngAnimate', 'ui.bootstrap','serverAccessService']) .config(['$routeProvider', function($routeProvider) { $routeProvider. when('/tasks', {templateUrl: 'partials/tasks.html', controller: TasksCtrl}). Modified: branches/ng-jtimer/src/main/webapp/js/controllers.js =================================================================== --- branches/ng-jtimer/src/main/webapp/js/controllers.js 2014-04-23 14:43:13 UTC (rev 2959) +++ branches/ng-jtimer/src/main/webapp/js/controllers.js 2014-04-28 16:05:41 UTC (rev 2960) @@ -1,12 +1,13 @@ -function TasksCtrl($scope, $timeout, $localStorage, $window, $document, $modal, wtWebsocket) { +function TasksCtrl($scope, $interval, $timeout, $q, serverAccess, $localStorage, $window, $document, $modal, wtWebsocket) { - /** - * {Boolean} vrai si on est online - */ + // {Boolean} vrai si on est online $scope.online = $window.navigator.onLine; - // {WebTimerData} toutes les donnees $scope.data = $localStorage.get("data"); + + // {Date} last update to server + $scope.acces = new Date(); + // {TreeNode} l'arbre regenere automatiquement lorsque les donnees changent $scope.tree; // {Array of Function} les listeners qui surveille l'ajout de nouveau temps, et qui les ajoutes dans l'arbre @@ -35,9 +36,17 @@ // {boolean} etat du client local (le serveur websocket) $scope.webSocketClientOnline = false; - // {boolean} boolean qui indique si une inactivité a été détectée + // {boolean} boolean qui indique si une inactivite a ete detectee $scope.webSocketClientIdle = false; + + + //TODO obruce :Creation de files de temps, de taches + // {Array of Task} 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 = {}; + /** * Met a jour la tache selectionne, si la tache selectionnee est la courante * alors on met la selection a null @@ -87,16 +96,61 @@ $scope.online = true; }, false); + /** * Force la sauvegarde des datas - * @returns {undefined} + * @returns {undefined}cd */ var save = function() { $localStorage.set("data", $scope.data); }; /** - * Timer qui mais les temps a jour toutes les secondes si une tache est + * Pousse les changements pour que le serveur les stocks + * Nouvelles taches + * nouveaux temps + */ + var getChangesFromServ = function(){ + + serverAccess.query(function (response) { + angular.forEach(response, function (item) { + //On verife si l'element n'est pas deja present + if(!(item.number in $scope.data.tasks)){ + + 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; + + if ($scope.tree) { + $scope.tree.addChild($scope.createTreeNode(newTask)); + } + + }else{ + + //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)); + + } + } + + }); + }); + console.log("Fin de getChanges from serv"); + console.log($scope.data.tasks); + //save(); + }; + + + /** + * Timer qui met les temps a jour toutes les secondes si une tache est * active * @returns {undefined} */ @@ -115,11 +169,33 @@ refresh(); /** + * Timer qui fait une demande d'envoie de maj toutes les minutes + * @returns {promise} + */ + var timer = function() { + $interval(function() { + //Si en ligne on envoie les donnees + if ( $scope.online == true) { + + getChangesFromServ(); + + //console.log(new Date()); + $scope.acces = new Date(); + } + + }, 100000); //TODO: for now 10s but for real put at least 2h: 200000000 + }; + timer(); + + /** * Ajoute une tache root */ $scope.addTask = function() { - var newTask = new Task($scope.name); - $scope.data.tasks.push(newTask); + var newTask = new Task($scope.name,undefined,0); + $scope.data.tasks[newTask.taskId] = newTask; + + //On ajoute à la file de synchro + $scope.stockedNewTasks.push(newTask); $scope.name = ""; save(); if ($scope.tree) { @@ -133,8 +209,12 @@ */ $scope.addSubTask = function(node) { var task = node.task; - var newTask = new Task("New task", task.taskId); - $scope.data.tasks.push(newTask); + var newTask = new Task("New task", undefined,task.taskId); + $scope.data.tasks[newTask.taskId] = newTask; + + //On ajoute à la file de synchro + $scope.stockedNewTasks.push(newTask); + node.$$open = true; save(); node.addChild($scope.createTreeNode(newTask)); @@ -149,6 +229,11 @@ var removeRecurse = function(tasks) { angular.forEach(tasks, function(task) { task.remove(); + + // On supprime les temps associes à la tache + delete $scope.data.tasks[task.taskId]; + delete $scope.data.times[task.taskId]; + var children = $scope.getChildren(task); removeRecurse(children); }); @@ -186,7 +271,7 @@ * Retourne la liste des enfants non supprime d'un noeud. Les sous taches * retourne peuvent etre modifiee via encapsulationFuntion si elle existe * @param {Task} task la tache dont on recherche les enfants - * @param {Funciton} encapsulationFuntion une methode appelee pour chaque enfant, + * @param {Function} encapsulationFuntion une methode appelee pour chaque enfant, * qui peut retourner un autre objet que l'enfant * @returns {Array of Task or other if encapsulationFuntion used} */ @@ -201,7 +286,6 @@ result.push(node); } }); - return result; }; @@ -250,9 +334,13 @@ */ $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; @@ -265,6 +353,8 @@ if (!result) { result = new TaskTime(task); times.push(result); + stocktimes.push(result); + } return result; @@ -299,6 +389,7 @@ if ($scope.currentTask) { var taskTime = $scope.getTodayTaskTime($scope.currentTask); taskTime.addTime(now - $scope.currentTaskDate); + } if ($scope.currentTask !== task) { @@ -378,14 +469,19 @@ $scope.webSocketClientIdle = false; }; + // force the first tree creation $scope.createTree(); + //force the first server connection + getChangesFromServ(); + // connect to webscocket server (go client) wtWebsocket.connect(); + } /** - * Controller de pour la modal d'inactivité. + * Controller de pour la modal d'inactivite. * * @param $scope * @param $modalInstance @@ -394,4 +490,5 @@ $scope.close = function(restartOption) { $modalInstance.close(restartOption); }; -} \ No newline at end of file +} + Modified: branches/ng-jtimer/src/main/webapp/js/entities.js =================================================================== --- branches/ng-jtimer/src/main/webapp/js/entities.js 2014-04-23 14:43:13 UTC (rev 2959) +++ branches/ng-jtimer/src/main/webapp/js/entities.js 2014-04-28 16:05:41 UTC (rev 2960) @@ -64,10 +64,11 @@ // la version des donnees this.dataVersion = 1; - this.tasks = []; // Array of Task + //this.tasks = []; // Array of Task + this.tasks = {}; // key: taskId, value: Task this.globalTimes = {}; // key: taskId, value: GlobalTime - this.times = {}; // key: taskId, value: Array of TaskTime - this.notes = {}; // key: taskId, value: Array of TaskNote + this.times = {}; // key: taskId, value: Array of TaskTime + this.notes = {}; // key: taskId, value: Array of TaskNote }; /** @@ -105,9 +106,11 @@ json = this.migrate(json.dataVersion, this.dataVersion, json); } if (json) { - angular.forEach(json.tasks, function (t) { + + angular.forEach(json.tasks, function (t, k) { t = jQuery.extend(new Task(), t); - this.tasks.push(t); + //this.tasks.push(t); + this.tasks[k] = t; }, this); angular.forEach(json.globalTimes, function (t, k) { @@ -264,18 +267,31 @@ * @param {type} parentTaskId l'identifiant de la tache parente * @returns {Task} */ -var Task = function (name, parentTaskId) { - this.taskId = generateUUID(); +var Task = function (name,taskId, parentTaskId) { + + if(taskId == undefined){ + this.taskId =generateUUID(); + }else{ + this.taskId = taskId; + } + this.creationDate = Date.now(); this.modificationDate = this.creationDate; this.removed = 0; - this.parentTaskId = parentTaskId; + + if(parentTaskId == undefined){ + this.parentTaskId = 0; + }else{ + this.parentTaskId = parentTaskId; + } + this.name = name; this.description = ""; this.tags = []; this.syncOptions = {}; }; + /** * Marque la tache comme supprimee * @returns {undefined} Added: branches/ng-jtimer/src/main/webapp/js/service.js =================================================================== --- branches/ng-jtimer/src/main/webapp/js/service.js (rev 0) +++ branches/ng-jtimer/src/main/webapp/js/service.js 2014-04-28 16:05:41 UTC (rev 2960) @@ -0,0 +1,18 @@ +angular.module("serverAccessService", ["ngResource"]) +.factory("serverAccess", function ( $resource) { + //TODO: obruce implémenter accès server + // Encapsule l'acces au server + return $resource("rest/tasks/:Id",{Id: "@Id" }, + { + query : {method:'GET', isArray:true}, + get : { + method: 'GET', + + isArray: false + }, + update: {method: "PUT"} + + } + ); + } +); Modified: branches/ng-jtimer/src/main/webapp/partials/tasks.html =================================================================== --- branches/ng-jtimer/src/main/webapp/partials/tasks.html 2014-04-23 14:43:13 UTC (rev 2959) +++ branches/ng-jtimer/src/main/webapp/partials/tasks.html 2014-04-28 16:05:41 UTC (rev 2960) @@ -30,7 +30,8 @@ <div id="footer"> <span class="left">{{currentDate()}}</span> <span class="center"><i class="icon-html5"></i> <a href="#">WebTimer</a></span> - <span class="right">{{tree.getTime().today |time}} | {{tree.getTime().global | time}}</span> + <!--<span class="right">{{tree.getTime().today |time}} | {{tree.getTime().global | time}}</span>--> + <span class="right">Dernier accès serveur: {{acces}}</span> </div> <div> Modified: branches/ng-jtimer/src/main/webapp/webtimer.appcache =================================================================== --- branches/ng-jtimer/src/main/webapp/webtimer.appcache 2014-04-23 14:43:13 UTC (rev 2959) +++ branches/ng-jtimer/src/main/webapp/webtimer.appcache 2014-04-28 16:05:41 UTC (rev 2960) @@ -13,6 +13,7 @@ js/entities.js js/filters.js js/jtimer.js +js/service.js NETWORK: http://localhost:33678/*
participants (1)
-
obruce@users.chorem.org