Author: obruce Date: 2014-07-01 17:47:05 +0200 (Tue, 01 Jul 2014) New Revision: 3009 Url: http://forge.chorem.org/projects/jtimer/repository/revisions/3009 Log: interface alarm Added: branches/ng-jtimer/src/main/webapp/partials/alertModal.html Modified: branches/ng-jtimer/src/main/java/org/chorem/jtimer/storage/Storage.java branches/ng-jtimer/src/main/resources/jtimer-default.properties branches/ng-jtimer/src/main/webapp/css/app.css 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 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-27 09:46:09 UTC (rev 3008) +++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/storage/Storage.java 2014-07-01 15:47:05 UTC (rev 3009) @@ -36,7 +36,7 @@ protected static final String TABLE_TASK = "task"; protected static final String TABLE_TIME = "tasktime"; - protected static final String TABLE_VERSION = "version"; + protected String TABLE_VERSION; protected String STORAGE_PATH; protected JtimerConfig config; @@ -47,6 +47,7 @@ this.config = conf; this.STORAGE_PATH = config.getStoragePath(); + this.TABLE_VERSION = config.getStorageTableVersion(); try { if (log.isDebugEnabled()) { Modified: branches/ng-jtimer/src/main/resources/jtimer-default.properties =================================================================== --- branches/ng-jtimer/src/main/resources/jtimer-default.properties 2014-06-27 09:46:09 UTC (rev 3008) +++ branches/ng-jtimer/src/main/resources/jtimer-default.properties 2014-07-01 15:47:05 UTC (rev 3009) @@ -10,6 +10,7 @@ jtimer.storage.table.task=task jtimer.storage.table.time=tasktime jtimer.storage.table.version=version +jtimer.storage.table.alert=taskalert ### #CREATE SCHEMA jtimer.storage.create.table.version=CREATE TABLE version (version VARCHAR(10)) @@ -34,6 +35,14 @@ FOREIGN KEY (taskid) \ REFERENCES task (taskId) \ ON DELETE CASCADE) +jtimer.storage.create.alert=CREATE TABLE taskalert \ + (taskid VARCHAR(255) NOT NULL, \ + name VARCHAR(255) NOT NULL, \ + type VARCHAR(255) NOT NULL, \ + limitDate LONG, \ + modificationDate LONG, \ + repeatFrequence VARCHAR(255), \ + PRIMARY KEY (taskId, name)) #### #INSERT jtimer.storage.insert.version.number=INSERT INTO VERSION VALUES('2.0') Modified: branches/ng-jtimer/src/main/webapp/css/app.css =================================================================== --- branches/ng-jtimer/src/main/webapp/css/app.css 2014-06-27 09:46:09 UTC (rev 3008) +++ branches/ng-jtimer/src/main/webapp/css/app.css 2014-07-01 15:47:05 UTC (rev 3009) @@ -262,6 +262,10 @@ margin : auto; } +.xsmall_input{ + width : 50px; +} + .small_input{ width : 100px; } Modified: branches/ng-jtimer/src/main/webapp/js/controllers.js =================================================================== --- branches/ng-jtimer/src/main/webapp/js/controllers.js 2014-06-27 09:46:09 UTC (rev 3008) +++ branches/ng-jtimer/src/main/webapp/js/controllers.js 2014-07-01 15:47:05 UTC (rev 3009) @@ -142,6 +142,64 @@ refresh(); /** + * Methode qui se lance toutes les minutes pour verifier les alamres des taches + */ + var checkAlarms = function() { + $timeout(function() { + + if ($scope.currentTask) { + + checkRecurseParent($scope.currentTask); + } + + checkAlarms(); + }, 60000); + }; + checkAlarms(); + + /** + * + * @param :task la tache + */ + var checkRecurseParent = function(task){ + + var alarms= task.alarms; + var index=0; + var parent = $scope.data.tasks[task.parent]; + + angular.forEach(alarms, function(alarm){ + + + if(!alarm.type=="Total_Time" && !alarm.isToday()){ + alarm.setToday(); + alarm.passedHour = alarm.limitHour; + alarm.passedMin = alarm.limitMin; + } + + if(alarm.passedMin > 0){ + alarm.passedMin -=1; + }else if(alarm.passedMin == 0){ + alarm.passedMin = 59; + alarm.passedHour -=1; + } + + if(alarm.passedHour == 0 && alarm.passedMin == 0){ + //console.log("Alarme lancée " +alarm.name +" de type "+ alarm.type + " par " + task.name ); + if(alarm.type=="Total_Time"){ + alarms.splice(index,1); + } + alert('Alarme déclenchée, '+alarm.name + ' ce message va s\'auto détruire!\n'); + } + index+=1; + }); + + + if(task.parent != ""){ + checkRecurseParent(parent); + } + }; + + /** * Timer qui joue des actions sur un interval donné * @returns {promise} */ @@ -246,7 +304,6 @@ } }else{ - //Un noeud avec un parent est ajoute à l'arbre de son parent //On ajoute le node à l'arbre if ($scope.tree.getNode(item.parent)) { @@ -714,10 +771,22 @@ }; /** Methode qui va tenter d'envoyer la tâche vers le serveur */ - $scope.persistToServ = function(task){ + $scope.alarmPopup = function(task){ - }; + var modalInstance = $modal.open({ + templateUrl: 'partials/alertModal.html', + controller: AlertModalInstanceCtrl, + resolve: { + task : function(){ + return task; + } + } + }); + modalInstance.result.then(function (item) { + }); + } + /** * Active/desactive le comptage de temps pour une tache * @param {type} task @@ -913,9 +982,6 @@ } } }); - - modalInstance.result.then(function (item) { - }); } /** @@ -958,6 +1024,66 @@ }; } +function AlertModalInstanceCtrl($scope, $modalInstance, task){ + + $scope.alarm={name : "" , type : "Type", hour : 0, min : 0}; + + $scope.name = task.name; + $scope.alarms = task.alarms; + + + $scope.dynamic = function(alarm){ + var res = 0; + + var limit = alarm.limitHour*60 + alarm.limitMin; + var passed = alarm.passedHour*60 + alarm.passedMin; + + res = ((limit-passed)/limit)*100; + + return res; + }; + + $scope.dropdownType1= function(){ + $scope.alarm.type = "Total_Day_Time"; + } + + $scope.dropdownType2 = function(){ + $scope.alarm.type = "Total_Time"; + } + + /** + * Methode qui supprime un element du tableau d'alerte + */ + $scope.removeAlert = function(index,a){ + $scope.alarms.splice(index, 1); + } + + /** + * Methode qui sauve l'alarme + */ + $scope.saveAlarm = function(){ + if($scope.alarm.name== "" || $scope.alarm.type=="Type"){ + + + + }else{ + $scope.alarms.push(new TaskAlarm(task, $scope.alarm.name, $scope.alarm.type, $scope.alarm.hour, $scope.alarm.min)); + + $scope.alarm.name= ""; + $scope.alarm.type="Type"; + //$scope.alarm.date= new Date(); + $scope.alarm.hour = 0; + $scope.alarm.min = 0; + } + } + + $scope.close = function() { + + $modalInstance.close(); + }; +} + + function ReportModalInstanceCtrl($scope, $modalInstance,$http, $sce, serverReportAccess, tree){ $scope.tree = tree; @@ -976,6 +1102,10 @@ return $sce.trustAsHtml(data); } + /** + * Methode de generation du rapport + * + */ $scope.generateReport= function(){ $scope.obj.startDate.setHours(0,0,0,0); Modified: branches/ng-jtimer/src/main/webapp/js/entities.js =================================================================== --- branches/ng-jtimer/src/main/webapp/js/entities.js 2014-06-27 09:46:09 UTC (rev 3008) +++ branches/ng-jtimer/src/main/webapp/js/entities.js 2014-07-01 15:47:05 UTC (rev 3009) @@ -403,6 +403,7 @@ this.name = name; this.description = ""; this.isReported = true; + this.alarms=[]; this.tags = []; this.syncOptions = {}; }; @@ -521,7 +522,37 @@ return this; }; +/** + * Permet de conserver une alarme + * @param {Task} task la tache liee + * @returns {TaskAlarm} + */ +var TaskAlarm = function (task, name, type, limitHour,limitMin, repeatF) { + this.taskId = task && task.taskId; + this.name = name; + this.type = type; + this.date = today(); + + this.limitHour = limitHour; + this.limitMin = limitMin; + this.passedHour = limitHour; + this.passedMin = limitMin; + + this.Frequence = repeatF; + +}; + +TaskAlarm.prototype.isToday = function() { + var result = this.date === today(); + return result; +}; + +TaskAlarm.prototype.setToday = function() { + this.date=today(); +}; + + /** * Represente une note pour une tache * @param {Task} task Added: branches/ng-jtimer/src/main/webapp/partials/alertModal.html =================================================================== --- branches/ng-jtimer/src/main/webapp/partials/alertModal.html (rev 0) +++ branches/ng-jtimer/src/main/webapp/partials/alertModal.html 2014-07-01 15:47:05 UTC (rev 3009) @@ -0,0 +1,82 @@ +<h3>Les alarmes pour {{name}} :</h3> + +<hr/> + +<table class='table'> + <thead> + <tr> + <th></th> + <th>Name</th> + <th>Type</th> + <th>Limit time</th> + <th>Progress</th> + <th></th> + </tr> + </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"> + <th><i class="glyphicon glyphicon-minus-sign" ng-click="removeAlert(index,alarm)"></i></th> + + <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> + </tr> + + + <tr> + <th></th> + <th><input class='input-sm small_input' ng-model="alarm.name" placeholder="New Alert"> + <i class="glyphicon glyphicon-edit" ng-show="alarm.name==''"> </i> + <i class="glyphicon glyphicon-check" ng-show="alarm.name!=''"> </i></th> + <th> + <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="dropdownType2()">Total_Time</li> + </ul> + </div> + <i class="glyphicon glyphicon-edit" ng-show="alarm.type=='Type'"> </i> + <i class="glyphicon glyphicon-check" ng-show="alarm.type!='Type'"> </i> + </th> + <th> + <!--<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'"> + <input type="number" step="1" min="0" max="23" ng-model="alarm.hour">h: + <input type="number" step="1" min="0" max="59" ng-model="alarm.min">m + </div> + + <div ng-if="alarm.type=='Total_Time'"> + <input class="xsmall_input" type="number" step="1" min="0" max="" ng-model="alarm.hour">h: + <input class="xsmall_input" type="number" step="1" min="0" max="" ng-model="alarm.min">m + </div> + + </th> + <th></th> + <th><i class="glyphicon glyphicon-ok" ng-click="saveAlarm()"></i></th> + </tr> + </div> + +</table> + + +<div class="modal-footer"> + <button class="btn btn-primary" ng-click="cancel()">Cancel</button> + <button class="btn btn-primary" ng-click="close()">Close</button> +</div> Modified: branches/ng-jtimer/src/main/webapp/partials/tasks.html =================================================================== --- branches/ng-jtimer/src/main/webapp/partials/tasks.html 2014-06-27 09:46:09 UTC (rev 3008) +++ branches/ng-jtimer/src/main/webapp/partials/tasks.html 2014-07-01 15:47:05 UTC (rev 3009) @@ -37,7 +37,7 @@ <span class="left">{{currentDate()}}</span> <span class="center"><i class="fa fa-html5"></i> <a>WebTimer</a></span> <!--<span class="right">{{tree.getTime().today |time}} | {{tree.getTime().global | time}}</span>--> - <span class="right">Dernière mise à jour: {{getLastMajDate()}}</span> + <span class="right">Last update : {{getLastMajDate()}}</span> </div> @@ -69,11 +69,12 @@ <i class="glyphicon glyphicon-minus-sign" ng-click="$toggleState()" ng-show="$state=='open'"></i> <!--Project name visible and editable --> - <form ng-submit="saveTask($node)" ng-show="$node.edit == 'name'"> + <form ng-submit="saveTask($node)" ng-show="$node.edit == 'name'" ng-blur="$node.edit == ''"> <input ng-model="$node.task.name" ng-blur="$node.edit == ''" > </form> <span ng-click="editTask($node, 'name')" ng-show="$node.edit != 'name'">{{$node.task.name}} </span> + <!-- Action button, add,remove activate task --> <span class="btn-group action"> <a class="btn btn-default btn-xs" ng-click="timeTask($node.task)" ng-show="$level > 1"> @@ -90,8 +91,8 @@ ng-show="!$node.task.isRoot() "> <i class="glyphicon glyphicon-pencil" ></i> </a> - <a class="btn btn-default btn-xs" ng-click="persistToServ($node.task)"> - <i class="glyphicon glyphicon-floppy-disk" ></i> + <a class="btn btn-default btn-xs" ng-click="alarmPopup($node.task)"> + <i class="glyphicon glyphicon-bell" ></i> </a> </span> </div>