r2976 - in branches/ng-jtimer/src/main: java/org/chorem/jtimer/storage java/org/chorem/jtimer/web webapp webapp/css webapp/js webapp/partials
Author: obruce Date: 2014-05-14 18:22:39 +0200 (Wed, 14 May 2014) New Revision: 2976 Url: http://forge.chorem.org/projects/jtimer/repository/revisions/2976 Log: controller: modification timeModalCtrl. serveur : correction date Modified: branches/ng-jtimer/src/main/java/org/chorem/jtimer/storage/Storage.java branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TimeResource.java branches/ng-jtimer/src/main/webapp/css/app.css branches/ng-jtimer/src/main/webapp/js/controllers.js branches/ng-jtimer/src/main/webapp/partials/timeModal.html branches/ng-jtimer/src/main/webapp/webtimer.appcache 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-05-14 08:27:44 UTC (rev 2975) +++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/storage/Storage.java 2014-05-14 16:22:39 UTC (rev 2976) @@ -71,7 +71,7 @@ protected Connection getConnection() throws SQLException { - String url = "/tmp/jtimer/jtimer"; + String url = "/home/olivia/Bureau/jtimer/jtimer"; if (log.isInfoEnabled()) { log.info("Opening connection to database : " + url); } @@ -332,7 +332,7 @@ " VALUES(?, ?, ?, ?)"); statement.setLong(1, task.getNumber()); - statement.setLong(2, date.getTime()); //TODO + statement.setLong(2, date.getTime()); statement.setString(3, uuid); statement.setLong(4, duration); statement.executeUpdate(); 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-05-14 08:27:44 UTC (rev 2975) +++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TimeResource.java 2014-05-14 16:22:39 UTC (rev 2976) @@ -18,6 +18,7 @@ public class TimeResource extends ServerResource { + private GsonBuilder builder; protected Storage storage; /** @@ -26,6 +27,27 @@ */ @Override protected void doInit() throws ResourceException { + + //GSON builder to format dates + + builder = new GsonBuilder(); + builder.registerTypeAdapter(Date.class, new JsonDeserializer<Date>() { + + 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()); + } + }); + + storage = (Storage)getContext().getAttributes().get(Storage.class.getName()); } @@ -40,7 +62,7 @@ String taskId = (String)getRequest().getAttributes().get("taskId"); List<TimerTime> timerTimes = storage.getTimes(taskId); - Gson gson = new Gson(); + Gson gson = builder.create(); String json = gson.toJson(timerTimes); return new StringRepresentation(json, MediaType.APPLICATION_JSON); @@ -66,7 +88,7 @@ String timeId = (String)getRequest().getAttributes().get("taskId"); long number = storage.getTaskNumber(timeId); - Gson gson = new Gson(); + Gson gson = builder.create(); String repr1 = representation.getText(); TimerTime t = gson.fromJson(repr1, TimerTime.class); Modified: branches/ng-jtimer/src/main/webapp/css/app.css =================================================================== --- branches/ng-jtimer/src/main/webapp/css/app.css 2014-05-14 08:27:44 UTC (rev 2975) +++ branches/ng-jtimer/src/main/webapp/css/app.css 2014-05-14 16:22:39 UTC (rev 2976) @@ -255,4 +255,9 @@ .idleModal { width: 400px; -} \ No newline at end of file +} + +.timepick{ + width : 50%; + margin : auto; +} Modified: branches/ng-jtimer/src/main/webapp/js/controllers.js =================================================================== --- branches/ng-jtimer/src/main/webapp/js/controllers.js 2014-05-14 08:27:44 UTC (rev 2975) +++ branches/ng-jtimer/src/main/webapp/js/controllers.js 2014-05-14 16:22:39 UTC (rev 2976) @@ -51,6 +51,7 @@ var stockedEditedTasks = []; // {key: taskId, value: Array of TaskTime} la file de temps des taches attendant la synchronisation avec le serveur var stockedNewTimes = {}; + var stockedEditedTimes = {}; /** * Met a jour la tache selectionne, si la tache selectionnee est la courante @@ -462,7 +463,6 @@ node.edit = null; stockedEditedTasks.push(node.task); save(); - console.log(stockedEditedTasks); }; /** @@ -566,27 +566,38 @@ }; $scope.popup = function (node){ + //Task identifier + var id = node.task.taskId; var modalInstance = $modal.open({ templateUrl: 'partials/timeModal.html', controller: ModalInstanceCtrl, resolve: { - taskTimes : function(){ - return $scope.data.times[node.task.taskId]; - } + taskTimes : function(){ + return $scope.data.times[id]; + } } + }); modalInstance.result.then(function (item) { - console.log(item); - }, function () { - //Dismiss + + if(item.index != -1){ + //changement + $scope.data.times[id][item.index].changeCreationDate(item.creationDate); + $scope.data.times[id][item.index].changeDuration(item.time); + + //init + if(!stockedEditedTimes[id]){stockedEditedTimes[id]=[]; } + + stockedEditedTimes[id].push($scope.data.times[id][item.index]); + console.log(stockedEditedTimes); + } }); } //force the first server connection actionToServ(); - // force the first tree creation $scope.createTree(); @@ -613,55 +624,42 @@ var ModalInstanceCtrl = function ($scope, $modalInstance, taskTimes) { + // Les temps de la tache $scope.times = taskTimes; - //La tache courante - $scope.currentTask = null; + //Le time selectionne + $scope.activTime = null; - //Le pas des heures et minutes - $scope.hstep = 1; - $scope.mstep = 1; - $scope.aTime = new Date(); - //La date a modifier - $scope.modifDate= "début"; + //L'objet retourner + $scope.obj={}; + $scope.obj.creationDate=-1; + $scope.obj.time=-1; + $scope.obj.index = -1; - //key:timeId value:Array of time - var stockTime={}; - - //Pour l'affichage - $scope.getStartTime = function(item){ - return moment(item.creationDate).format("DD-MM-YYYY H:mm:ss"); - } - + $scope.getStartTime = function(item){return moment(item.creationDate).format("DD-MM-YYYY H:mm:ss");} $scope.getStopTime = function(item){return item.time;} - //Pour le timePicker - $scope.select = function(item){ - $scope.currentTask = item; - $scope.aTime = new Date($scope.currentTask.creationDate); - } + $scope.getStartObjTime = function(){return moment($scope.obj.creationDate).format("DD-MM-YYYY H:mm:ss");} + $scope.getStopObjTime = function(){return moment($scope.obj.creationDate + $scope.obj.time).format("DD-MM-YYYY H:mm:ss");} + //selectionne un element dans le dropdown + $scope.select = function(item, ind){ + $scope.activTime = item; - $scope.changeTime = function(item){ + //On intialise l'objet a envoyer + $scope.obj.index = ind; + $scope.obj.creationDate=item.creationDate; + $scope.obj.time=item.time; + $scope.aTime = new Date(item.creationDate); } - $scope.dateDebut = function(){ - $scope.modifDate= "début"; - $scope.aTime = new Date($scope.currentTask.creationDate); - - } - - $scope.dateFin = function(){ - $scope.modifDate= "durée"; - $scope.aTime = new Date($scope.currentTask.creationDate + $scope.currentTask.time ); - } - + // Methode a la fermeture $scope.ok = function () { - $modalInstance.close(); + $modalInstance.close($scope.obj); }; $scope.cancel = function () { @@ -669,3 +667,45 @@ }; }; +var radioTimeCtrl = function ($scope){ + + //Activated button radio + $scope.radioModel = 'Left'; + $scope.aTime = new Date($scope.activTime.creationDate); + + //Le pas des heures et minutes + $scope.hstep = 1; + $scope.mstep = 1; + + $scope.changeModel = function(){ + //TODO obruce : ici il faut mettre des contraintes pour pas depasser 24h + //TODO pas depasser dans l'autre sens + if(($scope.radioModel || 'null') == 'Left'){ + + $scope.obj.creationDate = $scope.aTime.getTime(); + console.log($scope.obj.creationDate); + }else{ + + if($scope.aTime.getTime() > $scope.activTime.creationDate){ + var duree = $scope.aTime.getTime() - $scope.activTime.creationDate ; + $scope.obj.time = duree; + }else{ + $scope.aTime = new Date($scope.obj.creationDate ); + duree = 0; + } + console.log($scope.obj.time); + } + } + + //Change l'heure dans le timePicker selon debut/fin + $scope.changeFonc=function(){ + if(($scope.radioModel || 'null') == 'Left'){ + $scope.aTime = new Date($scope.obj.creationDate); + }else{ + $scope.aTime = new Date($scope.obj.creationDate + $scope.activTime.time); + } + } +}; + + + Modified: branches/ng-jtimer/src/main/webapp/partials/timeModal.html =================================================================== --- branches/ng-jtimer/src/main/webapp/partials/timeModal.html 2014-05-14 08:27:44 UTC (rev 2975) +++ branches/ng-jtimer/src/main/webapp/partials/timeModal.html 2014-05-14 16:22:39 UTC (rev 2976) @@ -1,40 +1,57 @@ <div> <h3> Modifier la tâche.</h3> - <ul> - <li ng-repeat="item in times" > + <div class="btn-group" dropdown is-open="status.isopen" ng-show="activTime == null"> + <button type="button" class="btn btn-primary dropdown-toggle"> + Les périodes pour la tâche sélectionnée : <span class="caret"></span> + </button> + <ul class="dropdown-menu" role="menu"> - <span ng-click="select(item)"> - Date de création : {{getStartTime(item)}} - Durée : {{getStopTime(item)| time}} - </span> + <li ng-repeat="(index,item) in times" > - <!-- Timepicker --> - <div ng-show = "currentTask == item"> - <hr> + <span ng-click="select(item, index)"> + Début : {{getStartTime(item)}} - Durée : {{getStopTime(item)| time}} + </span> - <!-- Choix --> - <div class="btn-group" dropdown is-open="status.isopen"> - <button type="button" class="btn btn-primary dropdown-toggle"> - Changer la date de {{modifDate}} de période. <span class="caret"></span> - </button> - <ul class="dropdown-menu" role="menu"> - <li ng-click="dateDebut()"><a href="#">Début de la période</a></li> - <li ng-click="dateFin()"><a href="#">Fin de la période</a></li> + </li> - </ul> + </ul> + </div> + + <div ng-if = "activTime != null"> + <hr/> + <h4>Période : Début : {{getStartTime(activTime)}} - Durée : {{getStopTime(activTime)| time}}</h4> + <alert type="danger" >Choisir une période :</alert> + + <div class = "timepick" ng-controller="radioTimeCtrl"> + <br/> + + + <div> + <div class="btn-group"> + <label class="btn btn-primary" ng-model="radioModel" ng-change="changeFonc()" btn-radio="'Left'">Début de période </label> + <label class="btn btn-primary" ng-model="radioModel" ng-change="changeFonc()" btn-radio="'Right'">Fin de période </label> </div> + </div> + <br/> + + <div class = "timepick"> <timepicker - ng-model="$parent.$parent.aTime" ng-change="changeTime()" hour-step="hstep" minute-step="mstep" show-meridian="ismeridian"> + ng-model="aTime" ng-change="changeModel()" hour-step="hstep" minute-step="mstep" show-meridian="ismeridian"> </timepicker> </div> - </li> + <br/> - </ul> + </div> + <alert type="info" >Début : {{getStartObjTime()}} - Fin : {{getStopObjTime(activTime)}}</alert> + </div> + + <div class="modal-footer"> <button class="btn btn-primary" ng-click="ok()">OK</button> <button class="btn btn-warning" ng-click="cancel()">Cancel</button> Modified: branches/ng-jtimer/src/main/webapp/webtimer.appcache =================================================================== --- branches/ng-jtimer/src/main/webapp/webtimer.appcache 2014-05-14 08:27:44 UTC (rev 2975) +++ branches/ng-jtimer/src/main/webapp/webtimer.appcache 2014-05-14 16:22:39 UTC (rev 2976) @@ -6,6 +6,7 @@ partials/about.html partials/contact.html partials/tasks.html +partials/timeModal.html css/app.css css/jtimer.css js/app.js
participants (1)
-
obruce@users.chorem.org