Author: obruce Date: 2014-07-03 16:39:22 +0200 (Thu, 03 Jul 2014) New Revision: 3011 Url: http://forge.chorem.org/projects/jtimer/repository/revisions/3011 Log: controller, alarmpartial : changement Modified: branches/ng-jtimer/src/main/webapp/js/controllers.js branches/ng-jtimer/src/main/webapp/partials/alertModal.html Modified: branches/ng-jtimer/src/main/webapp/js/controllers.js =================================================================== --- branches/ng-jtimer/src/main/webapp/js/controllers.js 2014-07-03 13:12:30 UTC (rev 3010) +++ branches/ng-jtimer/src/main/webapp/js/controllers.js 2014-07-03 14:39:22 UTC (rev 3011) @@ -379,33 +379,6 @@ } - /** - * Methode qui recupere les temps pour une tache - */ - var getTimesFromServerWithTask = function(task){ - - serverTimeAccess.query({taskId : task.taskId, date : $scope.timeAccess}, function (response) { - - angular.forEach(response, function (item) { - - if(!$scope.data.times[task.taskId]){$scope.data.times[task.taskId] = []} - - if(!(existInObject($scope.data.times,item.timeId,task.taskId)) && !(existInObject($scope.todo.stockedDeletedTimes, item.timeId, task.taskId)) && !item.isremoved){ - //On cree le tasktime - taskTime = new TaskTime(task, item.timeId, item.creationDate, item.time); - $scope.data.times[task.taskId].push(taskTime); - save(); - //TODO obruce 2/6/14 verfication chevauchement temps - } - }); - //On change la date de dernier acces - $scope.timeAccess = new Date().getTime(); - $scope.todo.lastTimeAccess= $scope.timeAccess; - save(); - }); - } - - //Recuperer un element dans un array avec son id var getObjectInArrayWithId= function(array, id){ var res; @@ -431,7 +404,33 @@ return res; } + /** + * Methode qui recupere les alarmes pour une tache + */ + var getAlarmsFromServerWithTask = function(task){ + serverAlarmAccess.query({taskId : task.taskId, date : $scope.timeAccess}, function (response) { + + angular.forEach(response, function (item) { + + if(!$scope.data.times[task.taskId]){$scope.data.times[task.taskId] = []} + + if(!(existInObject($scope.data.times,item.timeId,task.taskId)) && !(existInObject($scope.todo.stockedDeletedTimes, item.timeId, task.taskId)) && !item.isremoved){ + //On cree le tasktime + taskTime = new TaskTime(task, item.timeId, item.creationDate, item.time); + $scope.data.times[task.taskId].push(taskTime); + save(); + //TODO obruce 2/6/14 verfication chevauchement temps + } + }); + //On change la date de dernier acces + $scope.timeAccess = new Date().getTime(); + $scope.todo.lastTimeAccess= $scope.timeAccess; + save(); + }); + } + + /** * Methode qui retourne l'existence d'un element dans un array */ @@ -780,7 +779,7 @@ task : function(){ return node.task; }, - time : function(){ + totaltime : function(){ var res=0; @@ -800,6 +799,28 @@ console.log(res); return res; + }, + todaytime : function(){ + var res=0; + + var recChildren = function(noeud){ + angular.forEach($scope.data.times[noeud.task.taskId], function(t){ + if(t.isToday()){ + res+=t.time; + } + }); + + if(noeud.children){ + angular.forEach(noeud.children, function(child){ + recChildren(child); + }); + } + + } + recChildren(node); + + console.log(res); + return res; } } }); @@ -1045,8 +1066,12 @@ }; } -function AlertModalInstanceCtrl($scope, $modalInstance, serverAlarmAccess, task, time){ +function AlertModalInstanceCtrl($scope, $modalInstance, serverAlarmAccess, task, totaltime, todaytime){ + console.log(totaltime +" " +todaytime) + + $scope.alarm={name : "" , type : "Type"}; + var msToHour=function(ms){ return ((ms / (1000*60*60)) % 24); } @@ -1056,20 +1081,33 @@ } $scope.valMinHour=function(){ - return parseInt(msToHour(time)); + var res; + if($scope.alarm.type=="Total_Time"){ + res = parseInt(msToHour(totaltime)); + }else{ + res = parseInt(msToHour(todaytime)); + } + return res; } $scope.valMinMin=function(){ - return parseInt(msToMin(time)); + var res; + if($scope.alarm.type=="Total_Time"){ + res = parseInt(msToMin(totaltime)); + }else{ + res = parseInt(msToMin(todaytime)); + } + return res; } - $scope.alarm={name : "" , type : "Type", hour : $scope.valMinHour(), min : $scope.valMinMin()}; + $scope.alarm.hour = $scope.valMinHour(); + $scope.alarm.min = $scope.valMinMin(); $scope.name = task.name; $scope.alarms = task.alarms; - $scope.dynamic = function(alarm){ + $scope.dynamicProgressBar = function(alarm){ var res = 0; var limit = alarm.limitHour*60 + alarm.limitMin; @@ -1082,10 +1120,14 @@ $scope.dropdownType1= function(){ $scope.alarm.type = "Total_Day_Time"; + $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(); } /** @@ -1102,16 +1144,15 @@ if($scope.alarm.name== "" || $scope.alarm.type=="Type" ){ }else{ - console.log("save " +time); - minusPreviousTime(time, $scope.alarm.hour, $scope.alarm.min); + if($scope.alarm.type=="Total_Time"){ + minusPreviousTime(totaltime, $scope.alarm.hour, $scope.alarm.min); + }else{ + minusPreviousTime(todaytime, $scope.alarm.hour, $scope.alarm.min); + } - console.log("apres minus " +$scope.alarm.hour + " "+$scope.alarm.min); - if($scope.alarm.hour > 0 || $scope.alarm.min> 0 ){ - console.log($scope.alarm.hour + " "+$scope.alarm.min); - var al = new TaskAlarm(task,undefined , $scope.alarm.name, $scope.alarm.type, @@ -1131,7 +1172,6 @@ //On remet les elements affiches a la valeur par defaut $scope.alarm.name= ""; $scope.alarm.type="Type"; - //$scope.alarm.date= new Date(); $scope.alarm.hour = 0; $scope.alarm.min = 0; } Modified: branches/ng-jtimer/src/main/webapp/partials/alertModal.html =================================================================== --- branches/ng-jtimer/src/main/webapp/partials/alertModal.html 2014-07-03 13:12:30 UTC (rev 3010) +++ branches/ng-jtimer/src/main/webapp/partials/alertModal.html 2014-07-03 14:39:22 UTC (rev 3011) @@ -22,47 +22,46 @@ <!--Portion d'ajout --> <tr ng-repeat="(index,alarm) in alarms"> - <th><i class="glyphicon glyphicon-minus-sign" ng-click="removeAlert(index,alarm)"></i></th> + <td><i class="glyphicon glyphicon-minus-sign" ng-click="removeAlert(index,alarm)"></i></td> - <th>{{alarm.name}}</th> - <th>{{alarm.type}}</th> - <th>{{alarm.limitHour}}h: {{alarm.limitMin}}min</th> - <th> - <progressbar value="dynamic(alarm)"></progressbar> - </th> - <th></th> + <td >{{alarm.name}}</td> + <td>{{alarm.type}}</td> + <td>{{alarm.limitHour}}h: {{alarm.limitMin}}min</td> + <td> + <progressbar value="dynamicProgressBar(alarm)"></progressbar> + </td> </tr> <tr> - - <th>Nouveau:</th> + <th>New:</th> </tr> - <tr> - - <th></th> - <th><input class='input-sm small_input' ng-model="alarm.name" placeholder="New Alert"> + <td><i class="glyphicon glyphicon-floppy-disk" ng-click="saveAlarm()"></i></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></th> - <th> + <i class="glyphicon glyphicon-check color_green" ng-show="alarm.name!=''"> </i></td> + <td> <div class="btn-group" dropdown is-open="status.isopen"> <button type="button" class="btn btn-primary dropdown-toggle"> {{alarm.type}} <span class="caret"></span> </button> <ul class="dropdown-menu" role="menu"> - <li ng-click="dropdownType1()">Total_Time_In_a_Day</li> + <li ng-click="dropdownType1()">Total_Day_Time</li> <li ng-click="dropdownType2()">Total_Time</li> </ul> </div> <i class="glyphicon glyphicon-edit color_red" ng-show="alarm.type=='Type'"> </i> <i class="glyphicon glyphicon-check color_green"ng-show="alarm.type!='Type'"> </i> - </th> - <th> + </td> + <td> <!--<timepicker ng-model="alarm.date" ng-change="changed()" hour-step="1" minute-step="1" show-meridian="ismeridian"> </timepicker>--> - <div ng-if="alarm.type!='Total_Time'"> + <div ng-if="alarm.type=='Type'"> + </div> + + <div ng-if="alarm.type=='Total_Day_Time'"> <input type="number" step="1" min="{{valMinHour()}}" max="23" ng-model="alarm.hour">h: <input type="number" step="1" min="{{valMinMin()}}" max="59" ng-model="alarm.min">m </div> @@ -72,9 +71,8 @@ <input class="xsmall_input" type="number" step="1" min="{{valMinMin()}}" max="59" ng-model="alarm.min">m </div> - </th> - <th></th> - <th><i class="glyphicon glyphicon-ok green" ng-click="saveAlarm()"></i></th> + </td> + <td></td> </tr> </div>