Author: obruce Date: 2014-08-14 16:43:54 +0200 (Thu, 14 Aug 2014) New Revision: 3028 Url: http://forge.chorem.org/projects/jtimer/repository/revisions/3028 Log: Ajout d'une page de settings et de l'import partiel ?\195?\160 l'ui Changement des alertes Added: branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/ImportResource.java branches/ng-jtimer/src/main/webapp/partials/settings.html Modified: branches/ng-jtimer/src/main/java/org/chorem/jtimer/io/DataHandler.java branches/ng-jtimer/src/main/java/org/chorem/jtimer/io/GTimerDataLoader.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/java/org/chorem/jtimer/web/TaskResource.java branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TasksResource.java branches/ng-jtimer/src/main/resources/jtimer-default.properties 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/js/service.js branches/ng-jtimer/src/main/webapp/partials/alertModal.html branches/ng-jtimer/src/main/webapp/partials/tasks.html Modified: branches/ng-jtimer/src/main/java/org/chorem/jtimer/io/DataHandler.java =================================================================== --- branches/ng-jtimer/src/main/java/org/chorem/jtimer/io/DataHandler.java 2014-08-08 15:02:24 UTC (rev 3027) +++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/io/DataHandler.java 2014-08-14 14:43:54 UTC (rev 3028) @@ -46,6 +46,17 @@ this.storage = storage; } + /** + * Methode qui va effectuer l'importation + */ + public void migrateData(String data){ + DATA_PATH = data; + migrateData(); + } + + /** + * Methode qui va effectuer l'importation + */ public void migrateData(){ Collection oldData; Collection res = new HashSet(); @@ -60,15 +71,20 @@ OldTimerTask old = (OldTimerTask)iter.next(); reccursiveMigrate(old,""); - - log.info(old.toString()); } } + /** + * Methode qui va transformer les anciens objets gtimer en objet webtimer et va les pousser dans la base + * Reccursive qui va passer sur chaque noeud + * @param old l'ancien objet + * @param father le pere de l'objet + */ protected void reccursiveMigrate( OldTimerTask old, String father){ // On reconstruit ce qu'on peut de notre objet TimerTask task = new TimerTask(old,father); + //Persist la task storage.addTask(task); @@ -90,8 +106,14 @@ OldTimerAlert oldAlert = (OldTimerAlert)iter2.next(); + String type = ""; + if(oldAlert.getType() == OldTimerAlert.Type.REACH_DAILY_TIME){ + type= "Total_Day_Time"; + }else{ + type= "Total_Time"; + } - TimerAlarm alarm = new TimerAlarm(task.getTaskId(), task.getName()+index, oldAlert.getType().toString(), oldAlert.getDuration()); + TimerAlarm alarm = new TimerAlarm(task.getTaskId(), task.getName()+index, type, oldAlert.getDuration()); storage.addTaskAlarm(alarm); index++; Modified: branches/ng-jtimer/src/main/java/org/chorem/jtimer/io/GTimerDataLoader.java =================================================================== --- branches/ng-jtimer/src/main/java/org/chorem/jtimer/io/GTimerDataLoader.java 2014-08-08 15:02:24 UTC (rev 3027) +++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/io/GTimerDataLoader.java 2014-08-14 14:43:54 UTC (rev 3028) @@ -443,10 +443,12 @@ alertTaskFile)); // skip first line : "format: 1.2" + alertIn.readLine(); + String line; while ((line = alertIn.readLine()) != null) { - line = line.trim(); + line = line.trim(); //trime start and end whitespace if (!line.isEmpty()) { String alertType = line.substring(0, line.indexOf(' ')); String alertDuration = line.substring( 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-08-08 15:02:24 UTC (rev 3027) +++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/storage/Storage.java 2014-08-14 14:43:54 UTC (rev 3028) @@ -40,9 +40,6 @@ private static final Log log = LogFactory.getLog(Storage.class); - protected static final String TABLE_TASK = "task"; - protected static final String TABLE_TIME = "tasktime"; - protected static final String TABLE_ALARM = "taskalarm"; protected String TABLE_VERSION; protected String STORAGE_PATH; @@ -118,7 +115,7 @@ protected void closeConnection(Connection conn) throws SQLException { if (conn != null) { conn.close(); - conn = null; + } } @@ -198,33 +195,6 @@ return result; } - /** Query **/ - - /** - * Find all project. (task with no parent, parent = 0). - * - * @return all projects - */ - public int getTasksCount() { - int result = 0; - PreparedStatement statement = null; - try { - statement = getConnection().prepareStatement(config.getStorageQuerySelectCountTask()); - - ResultSet rs = statement.executeQuery(); - if (rs.next()) { - result = rs.getInt(1); - } - } catch (SQLException ex) { - throw new StorageException("Can't get task count", ex); - } finally { - closeStatement(statement); - } - return result; - } - - - /* Insert */ /** @@ -282,38 +252,10 @@ } finally { closeStatement(statement); } - log.info("insert done"); } - /** * Ajoute une periode pour une tache - * @param task la tache qui va recevoir un temps - * @param date la date de creation - * @param uuid l'identifiant du temps - * @param duration le duree de la periode - */ - public void addTaskTime(TimerTask task, Date date, String uuid, long duration) { - PreparedStatement statement = null; - try { - statement = getConnection().prepareStatement(config.getStorageQueryInsertTime()); - - statement.setString(1, task.getTaskId()); - statement.setObject(2, new Date()); - statement.setString(3, uuid); - statement.setLong(4, duration); - statement.setObject(5, new Date()); - statement.setBoolean(6, false); - statement.executeUpdate(); - } catch (SQLException ex) { - throw new StorageException("Can't add task time", ex); - } finally { - closeStatement(statement); - } - } - - /** - * Ajoute une periode pour une tache * @param time le timertime a ajouter */ public void addTaskTime(TimerTime time) { Added: branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/ImportResource.java =================================================================== --- branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/ImportResource.java (rev 0) +++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/ImportResource.java 2014-08-14 14:43:54 UTC (rev 3028) @@ -0,0 +1,36 @@ +package org.chorem.jtimer.web; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.jtimer.io.DataHandler; +import org.restlet.representation.Representation; +import org.restlet.resource.Post; + +import java.io.IOException; + +/** + * Created by olivia on 11/08/14. + * <p/> + * Project name : jtimer + * <p/> + * Package name : org.chorem.jtimer.web + */ +public class ImportResource extends AbstractResource{ + + private static final Log log = LogFactory.getLog(ImportResource.class); + + /** + * Methode qui cree une periode + * suite d'une requête de type POST + */ + @Post("json") + public void importTasks(Representation representation) throws IOException { + + if(representation.isAvailable()) { + DataHandler g = new DataHandler(storage); + g.migrateData(); + //g.migrateData(representation.getText()); + } + } + +} 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-08-08 15:02:24 UTC (rev 3027) +++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/RestApplication.java 2014-08-14 14:43:54 UTC (rev 3028) @@ -5,7 +5,6 @@ import org.apache.commons.logging.LogFactory; import org.chorem.jtimer.config.JtimerConfig; import org.chorem.jtimer.entities.TodoList; -import org.chorem.jtimer.io.DataHandler; import org.chorem.jtimer.storage.Storage; import org.restlet.Application; import org.restlet.Context; @@ -60,6 +59,7 @@ router.attach("/report", ReportResource.class); router.attach("/tasks/alarm", AlarmsResource.class); router.attach("/tasks/alarm/{taskId}", AlarmResource.class); + router.attach("/import", ImportResource.class); @@ -79,10 +79,6 @@ Storage storage = new Storage(jtimerConf); context.getAttributes().put(Storage.class.getName(), storage); - DataHandler g = new DataHandler(storage); - g.migrateData(); - - //initialisation de la todoList todoList = TodoList.getInstance(); Modified: branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TaskResource.java =================================================================== --- branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TaskResource.java 2014-08-08 15:02:24 UTC (rev 3027) +++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TaskResource.java 2014-08-14 14:43:54 UTC (rev 3028) @@ -4,7 +4,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.jtimer.entities.TodoList; -import org.chorem.jtimer.storage.Storage; import org.restlet.data.MediaType; import org.restlet.representation.Representation; import org.restlet.representation.StringRepresentation; @@ -19,7 +18,6 @@ private static final Log log = LogFactory.getLog(TaskResource.class); - protected Storage storage; protected TodoList todoList; /** @@ -28,9 +26,7 @@ */ @Override protected void doInit() throws ResourceException { - - storage = (Storage)getContext().getAttributes().get(Storage.class.getName()); - + super.doInit(); //On recupere la todoList courante todoList = TodoList.getInstance(); @@ -73,7 +69,7 @@ /** * Recupere la valeur de dispatch dans l'url * TODO 04/06/14 obruce : remove this method when config will be available - * @return + * @return if need to be dispatched */ private boolean getDispatch() { boolean res; 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-08-08 15:02:24 UTC (rev 3027) +++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TasksResource.java 2014-08-14 14:43:54 UTC (rev 3028) @@ -1,20 +1,11 @@ package org.chorem.jtimer.web; import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonParseException; -import com.google.gson.JsonPrimitive; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.jtimer.entities.TimerTask; import org.chorem.jtimer.entities.TodoList; -import org.chorem.jtimer.storage.Storage; import org.restlet.data.MediaType; import org.restlet.representation.Representation; import org.restlet.representation.StringRepresentation; @@ -24,16 +15,12 @@ import org.restlet.resource.ResourceException; import java.io.IOException; -import java.lang.reflect.Type; import java.util.ArrayList; -import java.util.Date; public class TasksResource extends AbstractResource { private static final Log log = LogFactory.getLog(TasksResource.class); - protected Storage storage; - protected GsonBuilder builder; protected TodoList todoList; protected boolean dispatch; //TODO 04/06/14 obruce : remove this parameter when config will be available @@ -45,25 +32,9 @@ */ @Override protected void doInit() throws ResourceException { - storage = (Storage) getContext().getAttributes().get(Storage.class.getName()); - // Register an adapter to manage the date types as long values - builder = new GsonBuilder(); - builder.registerTypeAdapter(Date.class, new JsonDeserializer<Date>() { + super.doInit(); - public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { - return new Date(json.getAsJsonPrimitive().getAsLong()); - } - - }); - - builder.registerTypeAdapter(Date.class, new JsonSerializer<Date>() { - @Override - public JsonElement serialize(Date date, Type type, JsonSerializationContext jsonSerializationContext) { - return new JsonPrimitive(date.getTime()); - } - }); - //On recupere la todoList courante todoList = TodoList.getInstance(); Modified: branches/ng-jtimer/src/main/resources/jtimer-default.properties =================================================================== --- branches/ng-jtimer/src/main/resources/jtimer-default.properties 2014-08-08 15:02:24 UTC (rev 3027) +++ branches/ng-jtimer/src/main/resources/jtimer-default.properties 2014-08-14 14:43:54 UTC (rev 3028) @@ -2,7 +2,7 @@ # jTimer default properties ### # jTimer storage path -jtimer.storage.path=/home/olivia/Bureau/jtimer/jtimer/BDDImport2 +jtimer.storage.path=/home/olivia/Bureau/jtimer/jtimer/BDD2 ### # SQL properties ### Modified: branches/ng-jtimer/src/main/webapp/js/app.js =================================================================== --- branches/ng-jtimer/src/main/webapp/js/app.js 2014-08-08 15:02:24 UTC (rev 3027) +++ branches/ng-jtimer/src/main/webapp/js/app.js 2014-08-14 14:43:54 UTC (rev 3028) @@ -306,12 +306,14 @@ /** * Module de webtimer **/ -angular.module('webtimer', ['webtimerFilters', 'ngRoute', 'ngAnimate', 'ui.bootstrap','serverAccessService', 'serverTimeService','serverReportService', 'serverAlarmService' ]) +angular.module('webtimer', ['webtimerFilters', 'ngRoute', 'ngAnimate', 'ui.bootstrap', 'settingsService', + 'serverAccessService', 'serverTimeService','serverReportService', 'serverAlarmService','importModule' ]) .config(['$routeProvider', function($routeProvider) { $routeProvider. when('/tasks', {templateUrl: 'partials/tasks.html', controller: TasksCtrl}). when('/about', {templateUrl: 'partials/about.html'}). when('/contact', {templateUrl: 'partials/contact.html'}). + when('/settings', {templateUrl: 'partials/settings.html', controller: SettingsCtrl}). otherwise({redirectTo: '/tasks'}); }]) .config(function (datepickerConfig, datepickerPopupConfig) { Modified: branches/ng-jtimer/src/main/webapp/js/controllers.js =================================================================== --- branches/ng-jtimer/src/main/webapp/js/controllers.js 2014-08-08 15:02:24 UTC (rev 3027) +++ branches/ng-jtimer/src/main/webapp/js/controllers.js 2014-08-14 14:43:54 UTC (rev 3028) @@ -1,4 +1,4 @@ -function TasksCtrl($scope, $interval, $timeout, $q, serverTaskAccess, serverTimeAccess, serverAlarmAccess, serverReportAccess, $localStorage, $window, $document, $modal, wtWebsocket, jTimerWebsocket) { +function TasksCtrl($scope, $interval, $timeout, $q, settings, serverTaskAccess, serverTimeAccess, serverAlarmAccess, serverReportAccess, $localStorage, $window, $document, $modal, wtWebsocket, jTimerWebsocket) { // {Boolean} vrai si on est online $scope.online = $window.navigator.onLine; @@ -33,19 +33,19 @@ $scope.currentTaskDate = null; // {String} le filtre d'affichage des noeuds (permet la recherche d'un noeud) $scope.query = ""; - // {boolean} boolean qui permet de force le depliage complet de l'arbre s'il est vrai - $scope.forceExpanded = false; + // {boolean} boolean qui permet de force le depliage complet de l'arbre s'il est vrai + $scope.forceExpanded = settings.forceExpanded; // {boolean} boolean qui indique si la colonne NAME doit etre affichee - $scope.showName = true; + $scope.showName = settings.showName; // {boolean} boolean qui indique si la colonne TODAY doit etre affichee - $scope.showToday = true; + $scope.showToday = settings.showToday; // {boolean} boolean qui indique si la colonne TOTAL doit etre affichee - $scope.showGlobal = true; + $scope.showGlobal = settings.showGlobal; // {boolean} boolean qui indique si la colonne TAGS doit etre affichee - $scope.showTags = true; + $scope.showTags = settings.showTags; // {boolean} boolean qui indique si les taches masquees doivent etre affichees - $scope.showHidden = false; + $scope.showHidden = settings.showHidden; // {boolean} etat du client local (le serveur websocket) $scope.webSocketClientOnline = false; @@ -65,6 +65,10 @@ } }; + /** + * Notify the user with a html5 notification + * @param msg the message to display + */ var notifyUser=function (msg) { // Let's check if the browser supports notifications @@ -75,7 +79,7 @@ var notification = new Notification( "Notification", { body: msg, - icon: "" + icon: "http://media.maginea.com/ld/products/00/00/66/29/LD0000662925_1.jpg" }); @@ -90,7 +94,7 @@ var notification = new Notification( "Notification", { body: msg, - icon: "" + icon: "http://media.maginea.com/ld/products/00/00/66/29/LD0000662925_1.jpg" }); } }); @@ -142,7 +146,20 @@ $scope.online = true; }, false); + /** + * Methode qui parcours l'arbre pour vérifier si le noeud a un fils actif + * @param le noeud dont on va verifier les fils + */ + $scope.hasActivSon = function(node){ + res = false; + angular.forEach(node.children, function(child){ + res = res || (child.task == $scope.currentTask) || $scope.hasActivSon(child); + }); + + return res; + }; + /** * Force la sauvegarde des datas * @returns {undefined}cd @@ -178,65 +195,54 @@ * Methode qui se lance toutes les minutes pour verifier les alamres des taches */ var checkAlarms = function(delay) { + + launchDate = Date.now(); + $interval(function() { if ($scope.currentTask) { - checkRecurseParent($scope.currentTask); + checkRecurseParent($scope.currentTask, launchDate); } - + delay = 0; }, 60000-delay); }; /** - * + * Methode qui va recursivement aller modifier les alarmes des membres d'une même branche * @param :task la tache */ - var checkRecurseParent = function(task){ + var checkRecurseParent = function(task, date){ - var alarms= task.alarms; - var index=0; + var alarms = task.alarms; + var index = 0; var parent = $scope.data.tasks[task.parent]; angular.forEach(alarms, function(alarm){ + alarm.launchDate = date; - if(!alarm.type=="Total_Time" && !alarm.isToday()){ + // Si l'alarme date d'un autre jour et qu'elle est periodique + if(!alarm.type == "Total_Time" && !alarm.isToday()){ alarm.setToday(); - alarm.remainingHour = alarm.limitHour; - alarm.remainingMin = alarm.limitMin; + alarm.remainingTime = alarm.duration; } - if(alarm.remainingMin > 0){ - alarm.remainingMin -=1; - }else if(alarm.remainingMin == 0){ - alarm.remainingMin = 59; - alarm.remainingHour -=1; - } + /* console.log(date); + console.log(date + alarm.remainingTime); + console.log(Date.now()); + console.log(date + alarm.remainingTime < Date.now());*/ - var limit = alarm.limitHour*60 + alarm.limitMin; - var remaining = alarm.remainingHour*60 + alarm.remainingMin; - - var res = ((limit-remaining)/limit)*100; - - if(res == 50 ){ - //$scope.currentTaskAlarmState="alarmOk"; - notifyUser("You've already spend half of the time on the task"); - }else if(res == 80){ - //$scope.currentTaskAlarmState="alarmInter"; - notifyUser("You only got 20% of your time"); - } - - - if(alarm.remainingHour == 0 && alarm.remainingMin == 0){ - //console.log("Alarme lancée " +alarm.name +" de type "+ alarm.type + " par " + task.name ); + if((alarm.remainingTime != -1) && (date + alarm.remainingTime < Date.now())){ + //L'alarme a atteint son but if(alarm.type=="Total_Time"){ alarms.splice(index,1); + }else{ + alarm.remainingTime = -1; } - notifyUser("Alarms : "+ alarm.name +" end!"); - + notifyUser("Hey, "+ alarm.name +" has ended!"); } index+=1; }); @@ -253,7 +259,9 @@ */ var timer = function() { $interval(function() { + //On pousse les majs pushTodoListToServ(); + //On update les changements eventuels de la base updateTasksFromServ(); updateTimesFromServer(); }, interval); @@ -263,61 +271,16 @@ timer(); /** - * Récupère les nouveaux elements du serveur et les ajoute a l'arbre pour l'affichage - * - */ - var initTasksFromServ = function(){ - - serverTaskAccess.query({date : 0}, function (response) { - - angular.forEach(response, function (item) { - //console.log(response); - if((!(item.taskId in $scope.data.tasks)) && item.removed == 0){ - - console.log( "Un element non present " + item.name + item.modificationDate); - var newTask = new Task( item.name, item.taskId, item.parent, item.tags,item.description); - - if(item.parent == "" ){ - - //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)); - } - - }else{ - //Un noeud avec un parent est ajoute à l'arbre de son parent - $scope.data.tasks[newTask.taskId] = newTask; - save(); - } - save(); - } - - }); - - console.log("Task initialisé"); - //On change la date de dernier acces - $scope.taskAccess = Date.now(); - $scope.todo.lastTaskAccess= $scope.taskAccess; - - - save(); - }); - - updateTimesFromServer(); - }; - - - - /** * Methode qui va chercher les mise à jour sur les taches * */ var updateTasksFromServ = function(){ - serverTaskAccess.query({date : ($scope.taskAccess-delayAccess)}, function (response) { + //On revupere la promesse des taches ayant une date de modification > date + var prom = serverTaskAccess.query({date : ($scope.taskAccess-delayAccess)}).$promise; + prom.then(function (response) { + angular.forEach(response, function (item) { //La tache existe @@ -365,17 +328,17 @@ save(); } - //Les temps sont recuperes du serveur - getTimesFromServerWithTask(newTask); + //Les alarmes + getAlarmsFromServerWithTask(newTask); save(); } - - getAlarmsFromServerWithTask(newTask); } }); }); + + //On change la date de dernier acces $scope.taskAccess = Date.now(); $scope.todo.lastTaskAccess= $scope.taskAccess; @@ -388,8 +351,10 @@ */ var updateTimesFromServer = function(){ - serverTimeAccess.query({date : $scope.timeAccess-delayAccess}, function (response) { + var prom = serverTimeAccess.query({date : $scope.timeAccess-delayAccess}).$promise; + prom.then(function (response) { + angular.forEach(response, function (item) { var editedTime = getTimeInArrayWithId($scope.data.times[item.taskId],item.timeId); @@ -519,12 +484,14 @@ return res; } - serverAlarmAccess.query({taskId : task.taskId, date : $scope.timeAccess}, function (response) { + var prom = serverAlarmAccess.query({taskId : task.taskId, date : $scope.timeAccess}).$promise; + prom.then(function (response) { + angular.forEach(response, function (item) { if(getAlarmInArrayWithId(task.alarms, item.alarmId) == undefined && !item.removed){ - //On cree le tasktime + //On cree le taskalarm taskAlarm = new TaskAlarm(task, item.alarmId, item.name, item.type, item.modificationDate); //TODO task.alarms.push(taskAlarm); save(); @@ -717,6 +684,51 @@ }); }; + var deleteTaskAndKeepTime = function(node,father){ + + //On parcours jusqu'en bas + angular.forEach(node.children, function(child){ + deleteTaskAndKeepTime(child, father); + }); + + //On supprime la tache du serveur + var prom = serverTaskAccess.deleteTask({taskId: node.task.taskId, dispatch:true}).$promise; + prom.then(console.log("delete success" + node.task.taskId), + function(){ + console.log("fail"); + $scope.todo.stockedDeletedTasks.push(node.task.taskId); + + }); + + if(!$scope.data.times[father]){ + $scope.data.times[father]=[]; + } + + //On recree les temps du fils pour le pere + angular.forEach($scope.data.times[node.task.taskId], function(time){ + time.taskId = father; + time.timeId = generateUUID(); + + $scope.data.times[father].push(time); + promT = serverTimeAccess.create({taskId: father,dispatch:true} , angular.toJson(time)).$promise; + + promT.then(console.log("create time success" + node.task.taskId), + function(){ + console.log("fail"); + if(!$scope.todo.stockedNewTimes[node.task.taskId]){$scope.todo.stockedNewTimes[node.task.taskId] = []} + $scope.todo.stockedNewTimes[node.task.taskId].push(time); + + }); + }); + + //suppression de la tache + node.task.remove(); + node.remove(); + delete $scope.data.times[node.task.taskId]; + delete $scope.data.tasks[node.task.taskId]; + }; + + /** * Supprime une tache (et ces sous taches recursivement) * @param {type} task @@ -752,60 +764,9 @@ }); }; - /** - * methode pour faire la suppression recursivement - * en gardant le temps de la tache et de ses parents dans le parent de la tache - */ - var removeTaskRecurseKeepTime = function(tasks, father) { + // mark all task as removed + removeRecurse([node.task]); - console.log("coucou1"); - - angular.forEach(tasks, function(task) { - - var children = $scope.getChildren(task); - removeTaskRecurseKeepTime(children,father); - - task.remove(); - - delete $scope.data.tasks[task.taskId]; - - if($scope.data.times[task.taskId]){ - if(!$scope.data.times[father]){ - $scope.data.times[father]=[]; - } - - // On attache les temps à la tache principal - $scope.data.times[father]=$scope.data.times[father].concat($scope.data.times[task.taskId]); - - //TODO persistance - } - - // On supprime les temps associes à la tache - $scope.data.times[task.taskId] = []; - - console.log("coucou2"); - - serverTaskAccess.deleteTask({taskId: task.taskId, dispatch:true}, function(){ - console.log("delete success" + task.taskId); - }, - function(){ - console.log("fail"); - $scope.todo.stockedDeletedTasks.push(task.taskId); - - }); - - node.remove(); - save(); - }); - }; - - if(method = 1){ - // mark all task as removed - removeRecurse([node.task]); - }else{ - removeTaskRecurseKeepTime([node.task], node.task.taskId); - } - // remove node in tree node.remove(); save(); @@ -994,11 +955,26 @@ $scope.currentTask = task; $scope.currentTaskDate = now; + //A voir pour mettre enlever quelques secondes en trop checkAlarms(0); } else { $interval.cancel(checkAlarms); + var changeRemainingRecurse=function(task){ + var parent = $scope.data.tasks[task.taskId]; + + angular.forEach(task.alarms, function(alarm){ + alarm.remainingTime = alarm.launchDate + alarm.remainingTime - Date.now(); + console.log(" il reste "+alarm.remainingTime); + }); + + if(parent){ + changeRemainingRecurse(parent); + } + } + + $scope.currentTask = null; $scope.currentTaskDate = null; } @@ -1171,7 +1147,7 @@ $scope.removeTask(node, 1); }else if(elem == 2){ // Suppression taches mais temps reportees au parent - $scope.removeTask(node,2); + deleteTaskAndKeepTime(node, node.parent.task.taskId); }else{ // Masque de la tache $scope.hideTaskRecurse([node.task],true); @@ -1199,14 +1175,13 @@ */ var initControllerWithServ = function(){ //Si en ligne on envoie les donnees - if ( $scope.online) { - updateTasksFromServ(); - updateTimesFromServer(); - pushTodoListToServ(); - initTasksFromServ(); - } + updateTasksFromServ(); + updateTimesFromServer(); + pushTodoListToServ(); + + } //force the first server connection @@ -1290,10 +1265,15 @@ }; } +/** + * Controller de la page de l'alarme + * + */ function AlertModalInstanceCtrl($scope,serverAlarmAccess){ + task = $scope.task; - totaltime = $scope.totaltime; - todaytime = $scope.todaytime; + totaltime = $scope.totaltime; //le temps total + todaytime = $scope.todaytime; //le temps total pour la journee $scope.alarm={name : "" , type : "Type"}; @@ -1305,6 +1285,7 @@ return ((ms / (1000*60)) % 60); } + //pour l'affichage $scope.valMinHour=function(){ var res; if($scope.alarm.type=="Total_Time"){ @@ -1323,36 +1304,39 @@ } return res; } - + //On affiche le temps minimal dans l'input $scope.alarm.hour = $scope.valMinHour(); $scope.alarm.min = $scope.valMinMin(); - $scope.name = task.name; + //La liste de d'alarmes a afficher ng repeat $scope.alarms = task.alarms; - - + /** + * Fait le calcul de progression + * + */ $scope.dynamicProgressBar = function(alarm){ var res = 0; - var limit = alarm.limitHour*60 + alarm.limitMin; - var remaining = alarm.remainingHour*60 + alarm.remainingMin; + var limit = alarm.duration; + var remaining = alarm.remainingTime; res = ((limit-remaining)/limit)*100; return res; }; + //On place le bon temps selon le type $scope.dropdownType1= function(){ $scope.alarm.type = "Total_Day_Time"; - $scope.alarm.hour = $scope.valMinHour(); - $scope.alarm.min = $scope.valMinMin(); + $scope.alarm.hour = $scope.valMinHour(); + $scope.alarm.min = $scope.valMinMin(); } $scope.dropdownType2 = function(){ $scope.alarm.type = "Total_Time"; - $scope.alarm.hour = $scope.valMinHour(); - $scope.alarm.min = $scope.valMinMin(); + $scope.alarm.hour = $scope.valMinHour(); + $scope.alarm.min = $scope.valMinMin(); } /** @@ -1368,48 +1352,32 @@ * Methode qui sauve l'alarme */ $scope.saveAlarm = function(){ + if($scope.alarm.name== "" || $scope.alarm.type=="Type" ){ }else{ var min=$scope.alarm.min; var hour=$scope.alarm.hour; - if($scope.alarm.type=="Total_Time"){ - var prevHour = parseInt(msToHour(totaltime)); - var prevMin = parseInt(msToMin(totaltime)); + var scopetime = min*60*1000 + hour*60*60*1000 ; + var remaining = scopetime; - hour-=prevHour; - - if(min - prevMin<0){ - min = 59 +(min-prevMin); - hour -=1; - }else{ - min =min - prevMin; - } - + //SI c'est un temps total + if($scope.alarm.type=="Total_Time"){ + remaining = scopetime-totaltime; }else{ - var prevHour = parseInt(msToHour(todaytime)); - var prevMin = parseInt(msToMin(todaytime)); - - hour-=prevHour; - - if(min - prevMin<0){ - min = 59 +(min-prevMin); - hour -=1; - }else{ - min =min - prevMin; - } + remaining = scopetime-todaytime; } if($scope.alarm.hour > 0 || $scope.alarm.min> 0 ){ - var al = new TaskAlarm(task,undefined , - $scope.alarm.name, - $scope.alarm.type, - $scope.alarm.hour, - $scope.alarm.min, - hour, - min); + var al = new TaskAlarm(task, //taskid + undefined , //alarmid + $scope.alarm.name, //name + $scope.alarm.type, //type + scopetime, //duration + remaining //remaining + ); //repeat $scope.alarms.push(al); @@ -1656,7 +1624,6 @@ }else{ - console.log(data); $scope.periodTaskData={}; angular.forEach(data, function(array,period){ @@ -2078,8 +2045,26 @@ }; +function SettingsCtrl($scope, settings, importService){ + $scope.settings=settings; + $scope.done = false; + $scope.import = function(path){ + if(path){ + importService.import({}, angular.toJson($scope.path)); + $scope.done = true; + } + }; + $scope.edit=function(){ + $scope.done= false; + }; + +} + + + + Modified: branches/ng-jtimer/src/main/webapp/js/entities.js =================================================================== --- branches/ng-jtimer/src/main/webapp/js/entities.js 2014-08-08 15:02:24 UTC (rev 3027) +++ branches/ng-jtimer/src/main/webapp/js/entities.js 2014-08-14 14:43:54 UTC (rev 3028) @@ -282,7 +282,6 @@ TreeNode.prototype.remove = function() { if (this.parent) { - var brothers = this.parent.children; var match = brothers.indexOf(this); @@ -508,7 +507,6 @@ }else{ this.time = time; } - }; /** @@ -565,7 +563,7 @@ * @param {Task} task la tache liee * @returns {TaskAlarm} */ -var TaskAlarm = function (task,id, name, type, limitHour,limitMin, remainingHour, remainingMin,repeatF) { +var TaskAlarm = function (task,id, name, type, duration, remaining,repeatF) { this.taskId = task && task.taskId; if(id == undefined){ @@ -579,10 +577,9 @@ this.date = today(); - this.limitHour = limitHour; - this.limitMin = limitMin; - this.remainingHour = remainingHour; - this.remainingMin = remainingMin; + this.launchDate = null; + this.duration = duration; + this.remainingTime = remaining; this.modificationDate = Date.now(); Modified: branches/ng-jtimer/src/main/webapp/js/service.js =================================================================== --- branches/ng-jtimer/src/main/webapp/js/service.js 2014-08-08 15:02:24 UTC (rev 3027) +++ branches/ng-jtimer/src/main/webapp/js/service.js 2014-08-14 14:43:54 UTC (rev 3028) @@ -68,4 +68,36 @@ } ); } -); \ No newline at end of file +); + +/** + * Service qui permet d'enclancher l'import des anciennes taches + */ +angular.module("importModule", ["ngResource"]) +.factory("importService", function ( $resource) { + // Encapsule l'acces au server + return $resource("/rest/import",{}, + { + import: { method: 'POST' }, + } + ); + } +); + + +/** + * Service qui garde les settings + */ +angular.module('settingsService', []).factory("settings", function(){ + var settings= { + forceExpanded : false, + showName : true, + showToday : true, + showGlobal : true, + showTags : true, + showHidden : false, + showAlarms : false, // not yet available + }; + + return settings; +}); \ No newline at end of file Modified: branches/ng-jtimer/src/main/webapp/partials/alertModal.html =================================================================== --- branches/ng-jtimer/src/main/webapp/partials/alertModal.html 2014-08-08 15:02:24 UTC (rev 3027) +++ branches/ng-jtimer/src/main/webapp/partials/alertModal.html 2014-08-14 14:43:54 UTC (rev 3028) @@ -12,28 +12,25 @@ </thead> <div class="tbody"> - <!-- <div ng-bind-html="toHTML(htmlReport)"></div> - $scope.toHTML = function (data) { - return $sce.trustAsHtml(data); - --> - <!--Portion d'ajout --> <tr ng-repeat="(index,alarm) in alarms"> <td><i class="glyphicon glyphicon-minus-sign" ng-click="removeAlarm(index,alarm)"></i></td> <td >{{alarm.name}}</td> <td>{{alarm.type}}</td> - <td>{{alarm.limitHour}}h: {{alarm.limitMin}}min</td> + <td>{{alarm.duration|time}}</td> <td> <progressbar value="dynamicProgressBar(alarm)"></progressbar> </td> + <td></td> </tr> <tr> <th>New:</th> </tr> <tr> - <td><i class="glyphicon glyphicon-floppy-disk" ng-click="saveAlarm()"></i></td> + <td></td> + <td><input class='input-sm small_input' ng-model="alarm.name" placeholder="New Alert"> <i class="glyphicon glyphicon-edit color_red" ng-show="alarm.name==''"> </i> <i class="glyphicon glyphicon-check color_green" ng-show="alarm.name!=''"> </i></td> @@ -66,14 +63,8 @@ </td> <td></td> + <td><i class="glyphicon glyphicon-floppy-disk" ng-click="saveAlarm()"></i></td> </tr> </div> </table> - -<!-- -<div class="modal-footer"> - <button class="btn btn-default btn-sm" ng-click="cancel()">Cancel</button> - <button class="btn btn-default btn-sm" ng-click="close()">Close</button> -</div> ---> \ No newline at end of file Added: branches/ng-jtimer/src/main/webapp/partials/settings.html =================================================================== --- branches/ng-jtimer/src/main/webapp/partials/settings.html (rev 0) +++ branches/ng-jtimer/src/main/webapp/partials/settings.html 2014-08-14 14:43:54 UTC (rev 3028) @@ -0,0 +1,38 @@ +<div id="header"> + <a href='#/tasks' class='glyphicon glyphicon-arrow-left'>Home</a> +</div> + +<h4>Interface Settings</h4> + +<b>Task tree:</b> +<ul> + + <li><input type='checkbox' ng-model= 'settings.forceExpanded'/> Keep tree opened</li> +</ul> +<b>Columns:</b> +<ul> + <li><input type='checkbox' ng-model= 'settings.showName'/> Task name</li> + <li><input type='checkbox' ng-model= 'settings.showToday'/> Today time</li> + <li><input type='checkbox' ng-model= 'settings.showGlobal'/> Total time</li> + <li><input type='checkbox' ng-model= 'settings.showTags'/> Tags</li> + <li><input type='checkbox' ng-model= 'settings.showAlarms'/> Alarms</li> + <li><input type='checkbox' ng-model= 'settings.showHidden'/> Hidden tasks</li> +</ul> + +<h4>Import gtimer data (zip):</h4> +<b>Specify your file path:</b><br/> +<form ng-submit="import(path)" ng-show="!done"> + <p> + <!--<input type="file" name="datafile" accept=".zip" size="40"> --> + <input type="text" ng-model='path'/> + <input ng-if="path" type="submit" id="submit" value="Submit" /> + </p> +</form> +<div ng-click="edit()" ng-show="done"> + {{path}} +</div> + +<!-- Footer --> +<div id="footer"> + <span class="center"><i class="fa fa-html5"></i> <a>WebTimer</a></span> +</div> \ No newline at end of file Modified: branches/ng-jtimer/src/main/webapp/partials/tasks.html =================================================================== --- branches/ng-jtimer/src/main/webapp/partials/tasks.html 2014-08-08 15:02:24 UTC (rev 3027) +++ branches/ng-jtimer/src/main/webapp/partials/tasks.html 2014-08-14 14:43:54 UTC (rev 3028) @@ -11,17 +11,10 @@ <!--Header partie droite--> <span class="right"> <i class="glyphicon glyphicon-stop color_red" ng-show="currentTask" ng-click="timeTask(currentTask)">Stop </i> - <i class="glyphicon glyphicon-cog" ng-click="reportPopup()">Report </i> - - <a class="glyphicon glyphicon-plus-sign" ng-click="showMenu = !showMenu"></a> - <ul class="dropdown-menu" ng-class="{'menu-show': showMenu}"> - <li>Keep Tree opened <input type='checkbox' ng-model="forceExpanded"></li> - <li>Name <input type='checkbox' ng-model='showName'/></li> - <li>Today <input type='checkbox' ng-model='showToday'/></li> - <li>Total <input type='checkbox' ng-model='showGlobal'/></li> - <li>Tags <input type='checkbox' ng-model='showTags'/></li> - <li>Hidden Tasks <input type='checkbox' ng-model='showHidden'/></li> - </ul> + <i popover-placement="left" popover="Report " popover-trigger="mouseenter" + class="glyphicon glyphicon-cog" ng-click="reportPopup()"></i> + <a popover-placement="left" popover="Settings" popover-trigger="mouseenter" href="#/settings" + class="glyphicon glyphicon-list-alt" ></a> <i class="glyphicon glyphicon-cloud" ng-class="{online: online, offline: !online}"></i> </span> </div> @@ -41,7 +34,7 @@ <!-- Footer --> <div id="footer"> <span class="left">{{currentDate()}}</span> - <span class="center"><i class="fa fa-html5 color_red"></i> <a>WebTimer</a></span> + <span class="center"><i class="fa fa-html5"></i> WebTimer</span> <span class="right">{{tree.getTime().today |time}} | {{tree.getTime().global | time}}</span> </div> @@ -76,7 +69,7 @@ <i style="font-size:10px" class="glyphicon glyphicon-ban-circle" ng-show="$state=='empty'"></i> <i style="font-size:10px" class="glyphicon glyphicon-chevron-right" ng-click="$toggleState()" ng-show="$state=='close'"></i> <i style="font-size:10px" class="glyphicon glyphicon-chevron-down" ng-click="$toggleState()" ng-show="$state=='open'"></i> - <img src="partials/loading_timer.gif" height="20" width="20" ng-show="currentTask == $node.task"> + <img src="partials/loading_timer.gif" height="20" width="20" ng-show=" (hasActivSon($node) && $state=='close') || currentTask == $node.task"> </span>