r2995 - in branches/ng-jtimer/src/main: java/org/chorem/jtimer/entities java/org/chorem/jtimer/storage java/org/chorem/jtimer/web webapp/js
Author: obruce Date: 2014-06-05 18:19:13 +0200 (Thu, 05 Jun 2014) New Revision: 2995 Url: http://forge.chorem.org/projects/jtimer/repository/revisions/2995 Log: Ajout synchro serveur-serveur Changement removed de timertime Synchro a verifier Added: branches/ng-jtimer/src/main/java/org/chorem/jtimer/entities/Pair.java Modified: branches/ng-jtimer/src/main/java/org/chorem/jtimer/entities/TimerTime.java branches/ng-jtimer/src/main/java/org/chorem/jtimer/entities/TodoList.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/TiersServerResource.java branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TimeResource.java branches/ng-jtimer/src/main/webapp/js/controllers.js Added: branches/ng-jtimer/src/main/java/org/chorem/jtimer/entities/Pair.java =================================================================== --- branches/ng-jtimer/src/main/java/org/chorem/jtimer/entities/Pair.java (rev 0) +++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/entities/Pair.java 2014-06-05 16:19:13 UTC (rev 2995) @@ -0,0 +1,46 @@ +package org.chorem.jtimer.entities; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * Created by olivia on 05/06/14. + * <p/> + * Project name : jtimer + * <p/> + * Package name : org.chorem.jtimer.entities + * + * Cette classe represente un duo d'element type cle/valeur + * @param <K> la cle + * @param <V> la valeur + */ +public class Pair<K,V>{ + + protected static final Log log = LogFactory.getLog(Pair.class); + + private K key; //la clef de la pair + private V value; //la valeur de la pair + + public Pair(K key, V value){ + this.key = key; + this.value = value; + + log.info(this.key.toString() + this.value.toString()); + } + + public V getValue() { + return value; + } + + public void setValue(V value) { + this.value = value; + } + + public K getKey() { + return key; + } + + public void setKey(K key) { + this.key = key; + } +} Modified: branches/ng-jtimer/src/main/java/org/chorem/jtimer/entities/TimerTime.java =================================================================== --- branches/ng-jtimer/src/main/java/org/chorem/jtimer/entities/TimerTime.java 2014-06-04 14:21:46 UTC (rev 2994) +++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/entities/TimerTime.java 2014-06-05 16:19:13 UTC (rev 2995) @@ -29,12 +29,12 @@ /** Time Elapsed in the period */ protected long time; - /** */ - protected boolean isremoved; + /** Specifies if the time has been removed */ + protected long removed; public TimerTime() { - isremoved = false; + removed = 0; } /** @@ -49,7 +49,7 @@ this.time = time; this.creationDate = creationDate; this.modificationDate = creationDate; - this.isremoved=false; + this.removed=0; } @@ -104,11 +104,11 @@ '}'; } - public void setRemoved(boolean removed) { - this.isremoved = removed; + public void setRemoved(long removed) { + this.removed = removed; } - public boolean getRemoved() { - return isremoved; + public long getRemoved() { + return removed; } } Modified: branches/ng-jtimer/src/main/java/org/chorem/jtimer/entities/TodoList.java =================================================================== --- branches/ng-jtimer/src/main/java/org/chorem/jtimer/entities/TodoList.java 2014-06-04 14:21:46 UTC (rev 2994) +++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/entities/TodoList.java 2014-06-05 16:19:13 UTC (rev 2995) @@ -21,10 +21,10 @@ protected Queue<String> deletedTasks; /** {Arraylist of times} stockage des temps crees avant synchro */ - protected Queue<String> createdTimes; + protected Queue<Pair<String,String>> createdTimes; /** {Arraylist of times} stockage des temps mis à jour avant synchro */ - protected Queue<String> updatedTimes; + protected Queue<Pair<String,String>> updatedTimes; /** {Arraylist of long} stockage des identifiants temps supprimees avant synchro */ protected Queue<String> deletedTimes; @@ -71,11 +71,11 @@ deletedTasks.add(taskId); } - public void pushCreatedTime(String time) { + public void pushCreatedTime(Pair<String,String> time) { createdTimes.add(time); } - public void pushUpdatedTime(String time) { + public void pushUpdatedTime(Pair<String,String> time) { updatedTimes.add(time); } @@ -113,47 +113,24 @@ return createdTasks; } - public void setCreatedTasks(Queue<String> createdTasks) { - this.createdTasks = createdTasks; - } - public Queue<String> getUpdatedTasks() { return updatedTasks; } - public void setUpdatedTasks(Queue<String> updatedTasks) { - this.updatedTasks = updatedTasks; - } - public Queue<String> getDeletedTasks() { return deletedTasks; } - public void setDeletedTasks(Queue<String> deletedTasks) { - this.deletedTasks = deletedTasks; - } - - public Queue<String> getCreatedTimes() { + public Queue<Pair<String, String>> getCreatedTimes() { return createdTimes; } - public void setCreatedTimes(Queue<String> createdTimes) { - this.createdTimes = createdTimes; - } - - public Queue<String> getUpdatedTimes() { + public Queue<Pair<String, String>> getUpdatedTimes() { return updatedTimes; } - public void setUpdatedTimes(Queue<String> updatedTimes) { - this.updatedTimes = updatedTimes; - } - public Queue<String> getDeletedTimes() { return deletedTimes; } - public void setDeletedTimes(Queue<String> deletedTimes) { - this.deletedTimes = deletedTimes; - } } 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-06-04 14:21:46 UTC (rev 2994) +++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/storage/Storage.java 2014-06-05 16:19:13 UTC (rev 2995) @@ -152,7 +152,7 @@ " modificationDate LONG, " + " hidden BOOLEAN," + " note TEXT," + - "removed LONG," + + " removed LONG," + " PRIMARY KEY (taskId))"); statement.executeUpdate("CREATE TABLE " + TABLE_TIME + "(taskid VARCHAR(255) NOT NULL," + @@ -160,7 +160,7 @@ " uuid varchar(255) unique," + " duration LONG," + " modificationDate LONG," + - " removed BOOLEAN," + + " removed LONG," + " PRIMARY KEY (taskid, date, uuid)," + " FOREIGN KEY (taskid)" + " REFERENCES " + TABLE_TASK +"(taskId)" + @@ -308,7 +308,7 @@ statement.setLong(1, t.getCreationDate().getTime()); statement.setLong(2, t.getTime()); statement.setLong(3, t.getModificationDate().getTime()); //modificationDate - statement.setBoolean(4, t.getRemoved()); + statement.setLong(4, t.getRemoved()); statement.setString(5, t.getTimeId() ); statement.executeUpdate(); } catch (SQLException ex) { @@ -386,7 +386,7 @@ statement.setString(3, time.getTimeId()); statement.setLong(4, time.getTime()); statement.setLong(5, time.getModificationDate().getTime()); - statement.setBoolean(6, time.getRemoved()); + statement.setLong(6, time.getRemoved()); statement.executeUpdate(); } catch (SQLException ex) { throw new StorageException("Can't add task time", ex); @@ -428,7 +428,7 @@ time.setTime(rs.getLong("duration")); time.setCreationDate(new java.util.Date(rs.getLong("date"))); time.setModificationDate(new java.util.Date(rs.getLong("modificationDate"))); - time.setRemoved(rs.getBoolean("removed")); + time.setRemoved(rs.getLong("removed")); times.add(time); @@ -465,7 +465,7 @@ time.setTime(rs.getLong("duration")); time.setCreationDate(new java.util.Date(rs.getLong("date"))); time.setModificationDate(new java.util.Date(rs.getLong("modificationDate"))); - time.setRemoved(rs.getBoolean("removed")); + time.setRemoved(rs.getLong("removed")); times.add(time); } @@ -530,7 +530,7 @@ PreparedStatement statement = null; try { statement = connection.prepareStatement("UPDATE " + - TABLE_TIME + " SET removed = 1, modificationDate =" +time + + TABLE_TIME + " SET removed = "+time+", modificationDate =" +time + " WHERE uuid = ?"); statement.setString(1, timeId); @@ -552,7 +552,7 @@ PreparedStatement statement = null; try { statement = connection.prepareStatement("UPDATE " + - TABLE_TASK + " SET removed = 1, modificationDate =" +time + + TABLE_TASK + " SET removed = "+time+", modificationDate =" +time + " WHERE taskId = '"+taskId +"'"); 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-06-04 14:21:46 UTC (rev 2994) +++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/RestApplication.java 2014-06-05 16:19:13 UTC (rev 2995) @@ -1,12 +1,8 @@ package org.chorem.jtimer.web; -import java.util.Date; -import java.util.Timer; -import java.util.UUID; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.chorem.jtimer.entities.TimerTask; +import org.chorem.jtimer.entities.Pair; import org.chorem.jtimer.entities.TodoList; import org.chorem.jtimer.storage.Storage; import org.restlet.Application; @@ -14,59 +10,27 @@ import org.restlet.Restlet; import org.restlet.routing.Router; +import java.util.Date; +import java.util.Iterator; +import java.util.Timer; + public class RestApplication extends Application { + /** Timer qui va se lancer toutes les x minutes */ protected Timer timer = new Timer(); + + /** Resource qui va pousser les elements vers d'autres serveurs */ protected TiersServerResource tiers = new TiersServerResource(); protected static final Log log = LogFactory.getLog(RestApplication.class); - protected boolean connected = true; + /** Determine si la connexion est établie */ //TODO obruce 05/06/2014 to change when configuration available + protected boolean connected = false; + + /** Todolist instance */ protected TodoList todoList; - - protected class TodoTask extends java.util.TimerTask{ - @Override - public void run() { - log.info("Passage dans le run"); - - if(connected){ - - if(!todoList.getCreatedTasks().isEmpty()) { - //Les taches crees - log.info("Des taches creer à envoyer"); - for (String task : todoList.getCreatedTasks()) { - if (tiers.postTask(task)) { - todoList.removeCreatedTask(); - } - } - } - - if(!todoList.getUpdatedTasks().isEmpty() ){ - log.info("Des taches avec update à envoyer"); - for (String task : todoList.getUpdatedTasks()){ - if(tiers.updateTask(task)){ - log.info("update fait"); - todoList.removeUpdatedTask(); - } - } - } - - if(!todoList.getDeletedTasks().isEmpty()){ - log.info("Des taches avec update à envoyer"); - for (String task : todoList.getDeletedTasks()){ - if(tiers.deleteTask(task)){ - log.info("update fait"); - todoList.removeUpdatedTask(); - } - } - } - - } - } - }; - /** * Creates a root Restlet that will receive all incoming calls. */ @@ -88,42 +52,113 @@ return router; } + /** + * Initialise le context de l'application REST + * @param context + */ protected void initContext(Context context) { //Initialisation du storage Storage storage = new Storage(); if (storage.getTasksCount() == 0) { - TimerTask jTimerProject = new TimerTask( "jTimer"); - TimerTask jTimerTask1 = new TimerTask( "WebService"); - TimerTask jTimerTask2 = new TimerTask( "WebService2"); - jTimerTask1.setParent(jTimerProject.getTaskId()); - jTimerTask2.setParent(jTimerProject.getTaskId()); - 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(), 1000000); - storage.addTaskTime(jTimerTask2, new Date(), UUID.randomUUID().toString(), 45); - - storage.addTask(new TimerTask( "Chorem")); - storage.addTask(new TimerTask( "Wikitty")); - storage.addTask(new TimerTask( "Nuiton-js")); - storage.addTask(new TimerTask( "Angular")); - storage.addTask(new TimerTask( "Isis-Fish")); } context.getAttributes().put(Storage.class.getName(), storage); //Initialisation du timer - timer.schedule(new TodoTask(), new Date(), (long) 30000); + timer.schedule(new TodoTask(), new Date(), (long) 10000); //TODO obruce change timer time todoList = TodoList.getInstance(); } + /** + * Classe representant la tache a effectuer pendant le timer + * + * Methode run: qui se lance toutes les x minutes + */ + protected class TodoTask extends java.util.TimerTask{ + @Override + public void run() { + log.info("Passage dans le run"); + if(connected){ + if(!todoList.getCreatedTasks().isEmpty()) { + //Les taches crees + log.info("Des taches creer à envoyer"); + Iterator iter = todoList.getCreatedTasks().iterator(); + while(iter.hasNext()) { + if (tiers.postTask((String) iter.next())) { + iter.remove(); + } + } + + } + + if(!todoList.getUpdatedTasks().isEmpty() ){ + log.info("Des taches avec update à envoyer"); + + Iterator iter = todoList.getUpdatedTasks().iterator(); + while(iter.hasNext()) { + if (tiers.updateTask((String) iter.next())) { + iter.remove(); + } + } + } + + if(!todoList.getDeletedTasks().isEmpty()){ + log.info("Des taches supprimée à envoyer"); + + Iterator iter = todoList.getDeletedTasks().iterator(); + while(iter.hasNext()) { + if (tiers.deleteTask((String) iter.next())) { + iter.remove(); + } + } + } + + if(!todoList.getCreatedTimes().isEmpty()) { + + log.info("Des temps creer à envoyer"); + + Iterator iter = todoList.getCreatedTimes().iterator(); + while(iter.hasNext()) { + if (tiers.postTime((Pair) iter.next())) { + iter.remove(); + } + } + + } + + if(!todoList.getUpdatedTimes().isEmpty() ){ + log.info("Des temps avec update à envoyer"); + + Iterator iter = todoList.getUpdatedTimes().iterator(); + while(iter.hasNext()) { + if (tiers.updateTime((Pair) iter.next())) { + iter.remove(); + } + } + + } + + if(!todoList.getDeletedTimes().isEmpty()){ + log.info("Des temps supprimé à envoyer"); + + Iterator iter = todoList.getDeletedTimes().iterator(); + while(iter.hasNext()) { + if (tiers.deleteTime((String) iter.next())) { + iter.remove(); + } + } + } + + } + } + }; + + } \ No newline at end of file Modified: branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TiersServerResource.java =================================================================== --- branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TiersServerResource.java 2014-06-04 14:21:46 UTC (rev 2994) +++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TiersServerResource.java 2014-06-05 16:19:13 UTC (rev 2995) @@ -10,7 +10,7 @@ import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; -import org.restlet.resource.ServerResource; +import org.chorem.jtimer.entities.Pair; /** * Created by olivia on 03/06/14. @@ -21,11 +21,13 @@ * * */ -public class TiersServerResource extends ServerResource { +public class TiersServerResource{ protected static final Log log = LogFactory.getLog(TiersServerResource.class); protected static final String dispatch = "?dispatch=false"; //TODO 04/06/14 obruce : remove this parameter when config will be available + protected static final String path = "http://localhost:8080/rest/tasks/"; //TODO 04/06/14 obruce : remove this parameter when config will be available + /** * Ctr */ @@ -43,7 +45,7 @@ boolean success = false; CloseableHttpClient httpclient = HttpClients.createDefault(); - HttpPost httpPost = new HttpPost("http://localhost:8080/rest/tasks/task"+dispatch); + HttpPost httpPost = new HttpPost(path+ "task"+dispatch); StringEntity myEntity = new StringEntity(t,ContentType.create("application/json", "UTF-8")); @@ -77,7 +79,7 @@ boolean success = false; CloseableHttpClient httpclient = HttpClients.createDefault(); - HttpPut httpPut = new HttpPut("http://localhost:8080/rest/tasks/task"+dispatch); + HttpPut httpPut = new HttpPut(path+"task"+dispatch); StringEntity myEntity = new StringEntity(task,ContentType.create("application/json", "UTF-8")); @@ -111,7 +113,7 @@ boolean success = false; CloseableHttpClient httpclient = HttpClients.createDefault(); - HttpDelete httpDelete = new HttpDelete("http://localhost:8080/rest/tasks/task/"+taskId +dispatch); + HttpDelete httpDelete = new HttpDelete(path+"task/"+taskId +dispatch); try{ CloseableHttpResponse response2 = httpclient.execute(httpDelete); @@ -132,4 +134,95 @@ } + public boolean postTime(Pair<String, String> time) { + + boolean success = false; + + CloseableHttpClient httpclient = HttpClients.createDefault(); + HttpPost httpPost = new HttpPost(path+ "time/"+ time.getKey()+dispatch); + + StringEntity myEntity = new StringEntity(time.getValue(),ContentType.create("application/json", "UTF-8")); + + //On ajoute l'entite + httpPost.setEntity(myEntity); + + try{ + CloseableHttpResponse response2 = httpclient.execute(httpPost); + log.info(" Reponse du server 2 : " +response2.getStatusLine()); + + //On ferme la reponse + response2.close(); + + //Mission accompli + success = true; + + }catch(Exception e){ + e.printStackTrace(); + } + + return success; + } + + /** + * Methode qui envoie les mise a jour des temps vers le serveur + * @param time l'objet temps avec la task et la representation du temŝ + * @return boolean of Http success + */ + public boolean updateTime(Pair<String, String> time) { + + boolean success = false; + + CloseableHttpClient httpclient = HttpClients.createDefault(); + HttpPut httpPut = new HttpPut(path+ "time/"+ time.getKey()+dispatch); + + StringEntity myEntity = new StringEntity(time.getValue(),ContentType.create("application/json", "UTF-8")); + + //On ajoute l'entite + httpPut.setEntity(myEntity); + + try{ + CloseableHttpResponse response2 = httpclient.execute(httpPut); + log.info(" Reponse du server 2 : " +response2.getStatusLine()); + + //On ferme la reponse + response2.close(); + + //Mission accompli + success = true; + + }catch(Exception e){ + e.printStackTrace(); + } + + return success; + } + + /** + * Methode qui envoie les temps taggee comme supprimer + * @param time l'objet temps avec la task et la representation du temŝ + * @return boolean of Http success + */ + public boolean deleteTime(String time) { + boolean success = false; + + CloseableHttpClient httpclient = HttpClients.createDefault(); + HttpDelete httpDelete = new HttpDelete(path+ "time/"+ time+dispatch); + + try{ + CloseableHttpResponse response2 = httpclient.execute(httpDelete); + log.info(" Reponse du server 2 : " +response2.getStatusLine()); + + //On ferme la reponse + response2.close(); + + //Mission accompli + success = true; + + }catch(Exception e){ + e.printStackTrace(); + } + + return success; + + } } Modified: branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TimeResource.java =================================================================== --- branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TimeResource.java 2014-06-04 14:21:46 UTC (rev 2994) +++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TimeResource.java 2014-06-05 16:19:13 UTC (rev 2995) @@ -11,7 +11,9 @@ import com.google.gson.JsonSerializer; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.chorem.jtimer.entities.Pair; import org.chorem.jtimer.entities.TimerTime; +import org.chorem.jtimer.entities.TodoList; import org.chorem.jtimer.storage.Storage; import org.restlet.data.MediaType; import org.restlet.representation.Representation; @@ -33,9 +35,16 @@ private static final Log log = LogFactory.getLog(TimeResource.class); + /** Builder for serialisation deserialisation */ private GsonBuilder builder; + /** H2 storage instance */ protected Storage storage; + /** Todolist instance */ + protected TodoList todoList; + /** Specifies if the post should be dispatched */ + protected boolean dispatch; //TODO 04/06/14 obruce : remove this parameter when config will be available + /** * Methode qui initialis la resource * @throws ResourceException @@ -65,6 +74,7 @@ storage = (Storage)getContext().getAttributes().get(Storage.class.getName()); + todoList = TodoList.getInstance(); } /** @@ -100,8 +110,14 @@ */ @Delete public void deleteTime() { + + dispatch = getDispatch(); String timeId = (String)getRequest().getAttributes().get("taskId"); storage.removeTimeWithId(timeId, new Date().getTime()); + + if (dispatch) { + todoList.pushDeletedTime(timeId); + } } /** @@ -111,38 +127,28 @@ @Post("json") public void createTime(Representation representation) throws IOException { - String taskId = (String)getRequest().getAttributes().get("taskId"); + if(representation.isAvailable()) { - Gson gson = builder.create(); - String repr1 = representation.getText(); + dispatch = getDispatch(); + Gson gson = builder.create(); - TimerTime newTime = gson.fromJson(repr1, TimerTime.class); + //On reconstruit l'element avec la representation + String jsonRepr = representation.getText(); + TimerTime newTime = gson.fromJson(jsonRepr, TimerTime.class); - List<TimerTime> list = storage.getTimes(taskId, newTime.getCreationDate().getTime()); + if (log.isInfoEnabled()) { + log.info("La periode suivante est cree : " + newTime.toString()); + } - for(TimerTime oldTime : list){ - long oldStart= oldTime.getCreationDate().getTime(); - long oldEnd = oldStart + oldTime.getTime(); - long newStart =newTime.getCreationDate().getTime(); - long newEnd = newStart + newTime.getTime(); + storage.addTaskTime(newTime); - - if(oldEnd > newStart || newEnd > oldStart){ - //Les temps ne se chevauchent pas - - }else{ - //un temps chevauchent un autre - + if (dispatch) { + String taskId = (String) getRequest().getAttributes().get("taskId"); + Pair p = new Pair<String, String>(taskId, jsonRepr); + log.info(" la pair cree" + p.toString()+ p.getKey().toString()+p.getValue().toString()); + todoList.pushCreatedTime(p); } - } - - if (log.isInfoEnabled()) { - log.info("La periode suivante est cree : " + newTime.toString()); - } - - storage.addTaskTime(newTime); - } /** @@ -152,16 +158,47 @@ @Put("json") public void updateTime(Representation representation) throws IOException{ - Gson gson = builder.create(); - String repr1 = representation.getText(); - TimerTime t = gson.fromJson(repr1, TimerTime.class); + if(representation.isAvailable()) { - storage.modifyTime(t); + dispatch = getDispatch(); + + Gson gson = builder.create(); + String jsonRepr = representation.getText(); + TimerTime t = gson.fromJson(jsonRepr, TimerTime.class); + + storage.modifyTime(t); + + if (dispatch) { + String taskId = (String) getRequest().getAttributes().get("taskId"); + todoList.pushUpdatedTime(new Pair<String, String>(taskId, jsonRepr)); + } + } + } + /** + * Called when option requests are catched + * Needed to avoid cross origin + */ @Options public void timeOptions() { + //do nothing + } + /** + * Recupere la valeur de dispatch dans l'url + * TODO 04/06/14 obruce : remove this method when config will be available + * @return + */ + private boolean getDispatch() { + boolean res; + try { + res = Boolean.valueOf(getQuery().getValues("dispatch")); + } catch (Exception e) { + e.printStackTrace(); + res = true; + } + return res; } } Modified: branches/ng-jtimer/src/main/webapp/js/controllers.js =================================================================== --- branches/ng-jtimer/src/main/webapp/js/controllers.js 2014-06-04 14:21:46 UTC (rev 2994) +++ branches/ng-jtimer/src/main/webapp/js/controllers.js 2014-06-05 16:19:13 UTC (rev 2995) @@ -288,7 +288,7 @@ var editedTime = getObjectInArrayWithId($scope.data.times[item.taskId],item.timeId); if(editedTime){ - if(!item.isremoved){ + if(item.removed == 0){ console.log("Temps existe donc remplacé"); //Le temps existe editedTime.time = item.time; @@ -297,9 +297,12 @@ //TODO obruce 2/6/14 verfication chevauchement temps save(); + }else{ + //TODO supprimer si existant mais removed + suppressObjectInArrayWithId($scope.data.times[item.taskId],item.timeId); } - }else if(!item.isremoved){ + }else if(item.removed == 0){ 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] = []} @@ -359,6 +362,21 @@ return res; } + + //Recuperer un element dans un array avec son id + var suppressObjectInArrayWithId= function(array, timeid,taskid){ + var res=0; + angular.forEach(array, function(time){ + if(time.timeId == timeid){ + array.splice(res,1); + + } + res++; + }); + return res; + } + + /** * Methode qui retourne l'existence d'un element dans un array */ @@ -419,7 +437,7 @@ //On change la date au dernier acces time["modificationDate"]=$scope.timeAccess; - serverTimeAccess.create({taskId: task} , angular.toJson(time), + serverTimeAccess.create({taskId: task,dispatch:true} , angular.toJson(time), function(){ console.log("persist time success" + task); $scope.todo.stockedNewTimes[task].shift(); @@ -436,7 +454,7 @@ time["modificationDate"]=$scope.timeAccess; - serverTimeAccess.update({taskId: task}, angular.toJson(time), + serverTimeAccess.update({taskId: task,dispatch:true}, angular.toJson(time), function(){ console.log("update time success" + task); $scope.todo.stockedEditedTimes[task].shift(); @@ -450,7 +468,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.deleteTime({taskId: time}, + serverTimeAccess.deleteTime({taskId: time,dispatch:true}, function(){ console.log("delete time success" + task); $scope.todo.stockedDeletedTimes[task].shift(); @@ -866,10 +884,6 @@ } }); - modalInstance.result.finally(function() { - console.log("finally"); - }); - } /** @@ -968,9 +982,6 @@ $modalInstance.dismiss('cancel'); }; - $scope.$on('$destroy', function() { - console.log('Modal scope should be destroyed.'); - }); }; function DatePickerCtrl($scope){
participants (1)
-
obruce@users.chorem.org