Jtimer-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
May 2014
- 3 participants
- 31 discussions
r2972 - in branches/ng-jtimer/src/main: java/org/chorem/jtimer/entities java/org/chorem/jtimer/storage java/org/chorem/jtimer/web webapp/js webapp/partials
by obruce@users.chorem.org 12 May '14
by obruce@users.chorem.org 12 May '14
12 May '14
Author: obruce
Date: 2014-05-12 18:17:30 +0200 (Mon, 12 May 2014)
New Revision: 2972
Url: http://forge.chorem.org/projects/jtimer/repository/revisions/2972
Log:
Storage: correction delete cascade, Serveur: correction des dates, UI: ajout module modification des temps
Added:
branches/ng-jtimer/src/main/webapp/partials/timeModal.html
Modified:
branches/ng-jtimer/src/main/java/org/chorem/jtimer/entities/TimerTask.java
branches/ng-jtimer/src/main/java/org/chorem/jtimer/storage/Storage.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/java/org/chorem/jtimer/web/TimeResource.java
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/entities/TimerTask.java
===================================================================
--- branches/ng-jtimer/src/main/java/org/chorem/jtimer/entities/TimerTask.java 2014-05-07 16:02:47 UTC (rev 2971)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/entities/TimerTask.java 2014-05-12 16:17:30 UTC (rev 2972)
@@ -86,9 +86,26 @@
this.name = name;
this.taskId = UUID.randomUUID().toString();
this.parent = "";
+ this.creationDate= new Date();
}
/**
+ * Constructor with name.
+ *
+ * @param name task name
+ */
+ public TimerTask(long number, String name, long datetime) {
+ this();
+ this.number = number;
+ this.name = name;
+ this.taskId = UUID.randomUUID().toString();
+ this.parent = "";
+ this.creationDate= new Date(datetime);
+ }
+
+
+
+ /**
* Get task number.
*
* @return the number
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-07 16:02:47 UTC (rev 2971)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/storage/Storage.java 2014-05-12 16:17:30 UTC (rev 2972)
@@ -152,12 +152,12 @@
" note TEXT," +
" PRIMARY KEY (id, taskId))");
statement.executeUpdate("CREATE TABLE " + TABLE_TIME +
- "(taskid LONG NOT NULL REFERENCES " + TABLE_TASK + "(id)," +
+ "(taskid LONG NOT NULL," +
" date DATE," +
" uuid varchar(255) unique," +
" duration LONG," +
- " PRIMARY KEY (taskid, date, uuid)" +
- ", FOREIGN KEY (taskid)" +
+ " PRIMARY KEY (taskid, date, uuid)," +
+ " FOREIGN KEY (taskid)" +
" REFERENCES " + TABLE_TASK +"(id)" +
" ON DELETE CASCADE" +
")");
@@ -280,18 +280,18 @@
PreparedStatement statement = null;
try {
statement = connection.prepareStatement("UPDATE " +
- TABLE_TASK + " SET name=?, parent=?, taskId=?, hidden=?, note=?" +
- " WHERE id = ?");
- statement.setString(1, task.getName());
+ TABLE_TASK + " SET name=?, parent=?, hidden=?, note=?" +
+ " WHERE taskId = ?");
+ statement.setString(1, task.getName()); //name
if (task.getParent() == "") {
- statement.setString(2, "");
+ statement.setString(2, ""); //parent
} else {
- statement.setString(2, task.getParent());
+ statement.setString(2, task.getParent()); //parent
}
- statement.setString(3, task.getTaskId());
- statement.setBoolean(4, task.isClosed());
- statement.setString(5, null /*project.getNote()*/);
- statement.setLong(6, task.getNumber());
+
+ statement.setBoolean(3, task.isClosed()); //hidden
+ statement.setString(4, null /*project.getNote()*/);//note
+ statement.setString(5, task.getTaskId()); //taskId
statement.executeUpdate();
} catch (SQLException ex) {
throw new StorageException("Can't modify task", ex);
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-05-07 16:02:47 UTC (rev 2971)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TaskResource.java 2014-05-12 16:17:30 UTC (rev 2972)
@@ -14,11 +14,21 @@
protected Storage storage;
+ /**
+ * Methode qui initialis la resource
+ * @throws ResourceException
+ */
@Override
protected void doInit() throws ResourceException {
storage = (Storage)getContext().getAttributes().get(Storage.class.getName());
}
+ /**
+ * Methode qui retourne la représentation d'une tache
+ * suite d'une requête de type GET
+ *
+ * @return une representation de la tache
+ */
@Get("json")
public Representation getTask() {
String taskId = (String)getRequest().getAttributes().get("taskId");
@@ -27,6 +37,11 @@
return new StringRepresentation( json , MediaType.APPLICATION_JSON);
}
+ /**
+ * Methode qui supprime un element de la base
+ * suite d'une requête de type DELETE
+ *
+ */
@Delete
public void deleteTask() {
@@ -34,10 +49,7 @@
storage.deleteTaskWithId(taskId);
}
- @Put("json")
- public void updateTask(){
- }
}
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-05-07 16:02:47 UTC (rev 2971)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TasksResource.java 2014-05-12 16:17:30 UTC (rev 2972)
@@ -23,7 +23,10 @@
private final static Logger LOGGER = Logger.getLogger(TasksResource.class.getName());
private GsonBuilder builder;
-
+ /**
+ * Methode qui initialis la resource
+ * @throws ResourceException
+ */
@Override
protected void doInit() throws ResourceException {
storage = (Storage)getContext().getAttributes().get(Storage.class.getName());
@@ -37,6 +40,11 @@
});
}
+ /**
+ * Methode qui retourne la representation de la liste de toutes les taches
+ * Suite a une requete de type GET
+ * @return
+ */
@Get("json")
public Representation getTasks() {
Gson gson = new Gson();
@@ -59,6 +67,10 @@
return new StringRepresentation(json, MediaType.APPLICATION_JSON);
}
+ /**
+ * Methode qui cree une tache
+ * suite d'une requête de type POST
+ */
@Post("json")
public void createTask(Representation representation) throws IOException {
@@ -67,12 +79,21 @@
TimerTask t = gson.fromJson(repr1, TimerTask.class);
LOGGER.log(Level.INFO,"repr1");
- //List<TimerTask> timerTasks = gson.fromJson(repr1, List.class);
-
- /*for(TimerTask t : timerTasks){
- storage.addTask(t);
- }*/
storage.addTask(t);
}
+ /**
+ * Methode qui met à jour une tache
+ * suite d'une requête de type PUT
+ */
+ @Put("json")
+ public void updateTask(Representation representation) throws IOException{
+
+ Gson gson = builder.create();
+ String repr1 = representation.getText();
+ TimerTask t = gson.fromJson(repr1, TimerTask.class);
+
+ storage.modifyTask(t);
+ }
+
}
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-07 16:02:47 UTC (rev 2971)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TimeResource.java 2014-05-12 16:17:30 UTC (rev 2972)
@@ -19,32 +19,56 @@
public class TimeResource extends ServerResource {
private GsonBuilder builder;
+
protected Storage storage;
private final static Logger LOGGER = Logger.getLogger(TasksResource.class.getName());
+ /**
+ * Methode qui initialis la resource
+ * @throws ResourceException
+ */
@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());
}
+ /**
+ * Methode qui retourne la représentation d'une liste de periode
+ * suite d'une requête de type GET
+ *
+ * @return la representation de la liste
+ */
@Get("json")
public Representation getTask() {
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);
}
+ /**
+ * Methode qui supprime un element de la base
+ * suite d'une requête de type DELETE
+ *
+ */
@Delete
public void deleteTask() {
@@ -52,12 +76,16 @@
storage.deleteTimeWithId(timeId);
}
+ /**
+ * Methode qui cree une periode
+ * suite d'une requête de type POST
+ */
@Post("json")
public void createTask(Representation representation) throws IOException {
String timeId = (String)getRequest().getAttributes().get("taskId");
long number = storage.getTaskNumber(timeId);
- Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX").create();
+ Gson gson = builder.create();
String repr1 = representation.getText();
TimerTime t = gson.fromJson(repr1, TimerTime.class);
Modified: branches/ng-jtimer/src/main/webapp/js/controllers.js
===================================================================
--- branches/ng-jtimer/src/main/webapp/js/controllers.js 2014-05-07 16:02:47 UTC (rev 2971)
+++ branches/ng-jtimer/src/main/webapp/js/controllers.js 2014-05-12 16:17:30 UTC (rev 2972)
@@ -44,11 +44,11 @@
$scope.webSocketClientIdle = false;
-
- //obruce :Creation de files de temps, de taches
// {Array of TaskID} la file de tache attendant la synchronisation avec le serveur
+ var stockedDeletedTasks = [];
+ // {Array of Task}
var stockedNewTasks = [];
- var stockedDeletedTasks = [];
+ var stockedEditedTasks = [];
// {key: taskId, value: Array of TaskTime} la file de temps des taches attendant la synchronisation avec le serveur
var stockedNewTimes = {};
@@ -131,7 +131,7 @@
if ($scope.tree) {
$scope.tree.addChild($scope.createTreeNode(newTask));
}
- console.log("Import projet " + newTask.name);
+
}else{
//Un noeud avec un parent est ajoute à l'arbre de son parent
$scope.data.tasks[newTask.taskId] = newTask;
@@ -139,9 +139,6 @@
//Les temps sont recuperes du serveur
getTimesFromServer(newTask);
- console.log(newTask);
- console.log("Import task "+ newTask.name);
- console.log($scope.data.times[newTask.taskId])
save();
}
}
@@ -154,7 +151,7 @@
var getTimesFromServer = function(task){
if(!$scope.data.times[task.taskId]){$scope.data.times[task.taskId] = []}
- //On va chercher les temps pour une tacheeditTask
+
serverTimeAccess.query({taskId : task.taskId}, function (response) {
angular.forEach(response, function (item) {
@@ -192,6 +189,17 @@
console.log("fail");
});
});
+ //On ajoute au serveur les taches stockees pour l'ajout
+ angular.forEach(stockedEditedTasks, function(task){
+ serverTaskAccess.update(angular.toJson(task),
+ function(){
+ console.log("update task success" + task);
+ stockedEditedTasks.shift();
+ },
+ function(){
+ console.log("fail");
+ });
+ });
//On ajoute les nouveaux temps au serveur
angular.forEach(stockedNewTimes, function(times,task){
@@ -208,6 +216,8 @@
});
}
+
+
/**
* Timer qui met les temps a jour toutes les secondes si une tache est
* active
@@ -228,25 +238,31 @@
refresh();
/**
- * Timer qui fait une demande d'envoie de maj toutes les minutes
+ * Timer qui joue des actions sur un interval donné
* @returns {promise}
*/
var timer = function() {
$interval(function() {
- //Si en ligne on envoie les donnees
- if ( $scope.online == true) {
+ actionToServ();
+ }, 30000); //TODO: for now 10s but for real put at least 2h: 200000000
+ };
+ timer();
- pushChangesToServ();
- getTasksFromServ();
+ /**
+ *Méthode qui lance les actions à faires sur le serveur
+ */
+ var actionToServ = function(){
+ //Si en ligne on envoie les donnees
+ if ( $scope.online == true) {
- //On change la date de dernier acces
- $scope.acces = moment().format("DD-MM-YYYY H:mm:ss a");
+ pushChangesToServ();
+ getTasksFromServ();
- }
+ //On change la date de dernier acces
+ $scope.acces = moment().format("DD-MM-YYYY H:mm:ss a");
+ }
- }, 30000); //TODO: for now 10s but for real put at least 2h: 200000000
- };
- timer();
+ }
/**
* Ajoute une tache root
@@ -408,7 +424,7 @@
$scope.data.times[task.taskId]= times;
}
- var maxDate = new Date(0,0,0,0,0);
+ var maxDate = new Date(0,0,0,0,0).getTime();
var result;
angular.forEach(times, function (t) {
@@ -444,7 +460,9 @@
*/
$scope.saveTask = function(node) {
node.edit = null;
+ stockedEditedTasks.push(node.task);
save();
+ console.log(stockedEditedTasks);
};
/**
@@ -547,9 +565,27 @@
$scope.webSocketClientIdle = false;
};
+ $scope.popup = function (node){
+
+ var modalInstance = $modal.open({
+ templateUrl: 'partials/timeModal.html',
+ controller: ModalInstanceCtrl,
+ resolve: {
+ taskTimes : function(){
+ return $scope.data.times[node.task.taskId];
+ }
+ }
+ });
+
+ modalInstance.result.then(function (item) {
+ console.log(item);
+ }, function () {
+ //Dismiss
+ });
+ }
+
//force the first server connection
- pushChangesToServ();
- getTasksFromServ();
+ actionToServ();
// force the first tree creation
$scope.createTree();
@@ -572,3 +608,64 @@
};
}
+
+
+
+var ModalInstanceCtrl = function ($scope, $modalInstance, taskTimes) {
+
+ // Les temps de la tache
+ $scope.times = taskTimes;
+
+ //La tache courante
+ $scope.currentTask = 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";
+
+ //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.getStopTime = function(item){return item.time;}
+
+ //Pour le timePicker
+ $scope.select = function(item){
+ $scope.currentTask = item;
+ $scope.aTime = new Date($scope.currentTask.creationDate);
+ }
+
+
+ $scope.changeTime = function(item){
+
+ }
+
+ $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 );
+ }
+
+ $scope.ok = function () {
+ $modalInstance.close();
+ };
+
+ $scope.cancel = function () {
+ $modalInstance.dismiss('cancel');
+ };
+};
+
Modified: branches/ng-jtimer/src/main/webapp/js/entities.js
===================================================================
--- branches/ng-jtimer/src/main/webapp/js/entities.js 2014-05-07 16:02:47 UTC (rev 2971)
+++ branches/ng-jtimer/src/main/webapp/js/entities.js 2014-05-12 16:17:30 UTC (rev 2972)
@@ -256,6 +256,14 @@
};
/**
+ * Determine si le global time est vide
+ * @returns {GlobalTime} this
+ */
+GlobalTime.prototype.estVide = function() {
+ return (this.global) == 0;
+};
+
+/**
* Ajoute les temps d'un tableau de TaskTime au temps global et a today si
* la TaskTime est pour today
* @param {Array of TaskTime} taskTimes
@@ -360,9 +368,10 @@
}
if(date == undefined){
- this.creationDate = new Date();
+ this.creationDate = Date.now();
}else{
- this.creationDate = new Date(date);
+ this.creationDate = date;
+
}
if(time == undefined){
@@ -401,7 +410,29 @@
return this;
};
+
/**
+ * change la date de début
+ * @param {Long} d la date en ms
+ * @returns {TaskTime} this
+ */
+TaskTime.prototype.changeCreationDate = function(d) {
+ this.creationDate = d;
+ return this;
+};
+
+/**
+ * change la duree de la periode
+ * @param {Long} d la date en ms
+ * @returns {TaskTime} this
+ */
+TaskTime.prototype.changeDuration = function(d) {
+ this.time = d;
+ return this;
+};
+
+
+/**
* Represente une note pour une tache
* @param {Task} task
* @returns {TaskNote}
Modified: branches/ng-jtimer/src/main/webapp/partials/tasks.html
===================================================================
--- branches/ng-jtimer/src/main/webapp/partials/tasks.html 2014-05-07 16:02:47 UTC (rev 2971)
+++ branches/ng-jtimer/src/main/webapp/partials/tasks.html 2014-05-12 16:17:30 UTC (rev 2972)
@@ -50,8 +50,7 @@
<div class="tr" ng-class="{'current-row' : ($node.task === currentTask), 'selected-row' : ($node.task === selectedTask)}"
ng-click="setSelectedTask($node.task)"
- ng-dblclick="timeTask($node.task)"
- ng-keydown="keyPressed($event)">
+ ng-keydown="keyPressed($event)"><!--ng-dblclick="timeTask($node.task)"-->
<div class="td" ng-show="showName">
<span class="spacer level{{$level}}"></span>
@@ -63,7 +62,7 @@
<!--Project name visible and editable -->
<form ng-submit="saveTask($node)" ng-show="$node.edit == 'name'">
- <input ng-model="$node.task.name">
+ <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>
@@ -73,9 +72,16 @@
<i class="glyphicon" ng-class="{'glyphicon-play' : ($node.task != currentTask), 'glyphicon-stop' : ($node.task == currentTask)}"></i>
</a>
<a class="btn btn-default btn-xs" href="" ng-click="addSubTask($node)"><i class="glyphicon glyphicon-plus"></i></a>
- <a class="btn btn-default btn-xs" href="" ng-really-message="La suppression de cette tâche nécessite une confirmation. " ng-really-click="removeTask($node)" ng-show="$node.task != currentTask">
+ <a class="btn btn-default btn-xs" href=""
+ ng-really-message="La suppression de cette tâche nécessite une confirmation. "
+ ng-really-click="removeTask($node)" ng-show="$node.task != currentTask">
<i class="glyphicon glyphicon-minus"></i>
</a>
+
+ <a class="btn btn-default btn-xs" href="" ng-click="popup($node)" ng-show="!$node.getTime().estVide()"><i class="glyphicon glyphicon-pencil" ></i></a>
+
+
+
</span>
</div>
Added: branches/ng-jtimer/src/main/webapp/partials/timeModal.html
===================================================================
--- branches/ng-jtimer/src/main/webapp/partials/timeModal.html (rev 0)
+++ branches/ng-jtimer/src/main/webapp/partials/timeModal.html 2014-05-12 16:17:30 UTC (rev 2972)
@@ -0,0 +1,46 @@
+<div>
+ <h3> Modifier la tâche.</h3>
+
+ <ul>
+ <li ng-repeat="item in times" >
+
+ <span ng-click="select(item)">
+ Date de création : {{getStartTime(item)}} - Durée : {{getStopTime(item)| time}}
+ </span>
+
+ <!-- Timepicker -->
+ <div ng-show = "currentTask == item">
+ <hr>
+
+ <!-- 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>
+
+ </ul>
+ </div>
+
+ <timepicker
+ ng-model="$parent.$parent.aTime" ng-change="changeTime()" hour-step="hstep" minute-step="mstep" show-meridian="ismeridian">
+ </timepicker>
+ </div>
+ </li>
+
+ </ul>
+
+
+
+
+ <div class="modal-footer">
+ <button class="btn btn-primary" ng-click="ok()">OK</button>
+ <button class="btn btn-warning" ng-click="cancel()">Cancel</button>
+ </div>
+
+
+
+</div>
+
1
0
07 May '14
Author: echatellier
Date: 2014-05-07 18:02:47 +0200 (Wed, 07 May 2014)
New Revision: 2971
Url: http://forge.chorem.org/projects/jtimer/repository/revisions/2971
Log:
Fix icon
Modified:
branches/ng-jtimer/src/main/webapp/partials/tasks.html
Modified: branches/ng-jtimer/src/main/webapp/partials/tasks.html
===================================================================
--- branches/ng-jtimer/src/main/webapp/partials/tasks.html 2014-05-07 15:32:09 UTC (rev 2970)
+++ branches/ng-jtimer/src/main/webapp/partials/tasks.html 2014-05-07 16:02:47 UTC (rev 2971)
@@ -29,7 +29,7 @@
</div>
<div id="footer">
<span class="left">{{currentDate()}}</span>
- <span class="center"><i class="icon-html5"></i> <a href="#">WebTimer</a></span>
+ <span class="center"><i class="fa fa-html5"></i> <a href="#">WebTimer</a></span>
<!--<span class="right">{{tree.getTime().today |time}} | {{tree.getTime().global | time}}</span>-->
<span class="right">Dernier accès serveur: {{acces}}</span>
</div>
1
0
Author: echatellier
Date: 2014-05-07 17:32:09 +0200 (Wed, 07 May 2014)
New Revision: 2970
Url: http://forge.chorem.org/projects/jtimer/repository/revisions/2970
Log:
Update angularjs
Modified:
branches/ng-jtimer/pom.xml
Modified: branches/ng-jtimer/pom.xml
===================================================================
--- branches/ng-jtimer/pom.xml 2014-05-07 15:19:53 UTC (rev 2969)
+++ branches/ng-jtimer/pom.xml 2014-05-07 15:32:09 UTC (rev 2970)
@@ -48,7 +48,7 @@
<dependency>
<groupId>org.nuiton.js</groupId>
<artifactId>nuiton-js-angularjs</artifactId>
- <version>1.2.16-1</version>
+ <version>1.3.0-beta.7-1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.nuiton.js</groupId>
1
0
r2969 - in branches/ng-jtimer: . src/main/config src/main/webapp src/main/webapp/js src/main/webapp/partials
by echatellier@users.chorem.org 07 May '14
by echatellier@users.chorem.org 07 May '14
07 May '14
Author: echatellier
Date: 2014-05-07 17:19:53 +0200 (Wed, 07 May 2014)
New Revision: 2969
Url: http://forge.chorem.org/projects/jtimer/repository/revisions/2969
Log:
Update libs (bootstrap, angular-ui-bootstrap, momentjs)
Modified:
branches/ng-jtimer/pom.xml
branches/ng-jtimer/src/main/config/wro.xml
branches/ng-jtimer/src/main/webapp/index.html
branches/ng-jtimer/src/main/webapp/js/controllers.js
branches/ng-jtimer/src/main/webapp/partials/tasks.html
Modified: branches/ng-jtimer/pom.xml
===================================================================
--- branches/ng-jtimer/pom.xml 2014-05-07 14:40:24 UTC (rev 2968)
+++ branches/ng-jtimer/pom.xml 2014-05-07 15:19:53 UTC (rev 2969)
@@ -48,27 +48,32 @@
<dependency>
<groupId>org.nuiton.js</groupId>
<artifactId>nuiton-js-angularjs</artifactId>
- <version>1.3.0-beta.4-1</version>
+ <version>1.2.16-1</version>
</dependency>
<dependency>
<groupId>org.nuiton.js</groupId>
+ <artifactId>nuiton-js-angular-ui-bootstrap</artifactId>
+ <version>0.11.0-1-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.nuiton.js</groupId>
<artifactId>nuiton-js-jquery</artifactId>
- <version>2.1.0-1</version>
+ <version>1.11.1-1</version>
</dependency>
<dependency>
<groupId>org.nuiton.js</groupId>
<artifactId>nuiton-js-bootstrap</artifactId>
- <version>2.3.2-1</version>
+ <version>3.1.1-1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.nuiton.js</groupId>
<artifactId>nuiton-js-moment</artifactId>
- <version>2.1.0-1-SNAPSHOT</version>
+ <version>2.6.0-1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.nuiton.js</groupId>
<artifactId>nuiton-js-font-awesome</artifactId>
- <version>3.2.1-1-SNAPSHOT</version>
+ <version>4.0.3-1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>ro.isdc.wro4j</groupId>
Modified: branches/ng-jtimer/src/main/config/wro.xml
===================================================================
--- branches/ng-jtimer/src/main/config/wro.xml 2014-05-07 14:40:24 UTC (rev 2968)
+++ branches/ng-jtimer/src/main/config/wro.xml 2014-05-07 15:19:53 UTC (rev 2969)
@@ -5,6 +5,7 @@
<group-ref>angular-route</group-ref>
<group-ref>angular-resource</group-ref>
<group-ref>angular-animate</group-ref>
+ <group-ref>angular-ui-bootstrap</group-ref>
<group-ref>bootstrap</group-ref>
<group-ref>font-awesome</group-ref>
<group-ref>moment</group-ref>
Modified: branches/ng-jtimer/src/main/webapp/index.html
===================================================================
--- branches/ng-jtimer/src/main/webapp/index.html 2014-05-07 14:40:24 UTC (rev 2968)
+++ branches/ng-jtimer/src/main/webapp/index.html 2014-05-07 15:19:53 UTC (rev 2969)
@@ -9,8 +9,6 @@
<link rel="stylesheet" href="css/jtimer.css">
<script src="js/jtimer.js"></script>
- <script src="http://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.6.0.js"></script>
-
<link rel="stylesheet" href="css/app.css">
<script src="js/app.js"></script>
<script src="js/controllers.js"></script>
Modified: branches/ng-jtimer/src/main/webapp/js/controllers.js
===================================================================
--- branches/ng-jtimer/src/main/webapp/js/controllers.js 2014-05-07 14:40:24 UTC (rev 2968)
+++ branches/ng-jtimer/src/main/webapp/js/controllers.js 2014-05-07 15:19:53 UTC (rev 2969)
@@ -523,11 +523,7 @@
wtWebsocket.send(JSON.stringify({idleStatus:true}));
var modalInstance = $modal.open({
templateUrl: 'idleModalTemplate.html',
- windowClass: 'idleModal',
- controller: IdleModalCtrl,
- backdropFade: true,
- dialogFade: true,
- keyboard: false // for cancel to not work
+ controller: IdleModalCtrl
});
modalInstance.result.then($scope.restartFromIdleness);
};
Modified: branches/ng-jtimer/src/main/webapp/partials/tasks.html
===================================================================
--- branches/ng-jtimer/src/main/webapp/partials/tasks.html 2014-05-07 14:40:24 UTC (rev 2968)
+++ branches/ng-jtimer/src/main/webapp/partials/tasks.html 2014-05-07 15:19:53 UTC (rev 2969)
@@ -1,15 +1,15 @@
<div id="header">
<!--Header partie gauche -->
- <span class='left'>
- <input class='search-query input-small' ng-model="query" placeholder="Search">
+ <span class='left form-inline'>
+ <input class='search-query form-group form-control input-sm' ng-model="query" placeholder="Search">
<form ng-submit="addTask()">
- <input class='search-query input-small' ng-model="name" placeholder="New Task">
+ <input class='search-query form-group form-group form-control input-sm' ng-model="name" placeholder="New Task">
</form>
</span>
<!--Header partie droite -->
<span class="right">
- <a class="icon-plus-sign" ng-click="showMenu = !showMenu">
- <b class="caret"></b>
+ <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>
@@ -18,7 +18,7 @@
<li>Total <input type='checkbox' ng-model='showGlobal'/></li>
<li>Tags <input type='checkbox' ng-model='showTags'/></li>
</ul>
- <i class="icon-cloud" ng-class="{online: online, offline: !online}"></i>
+ <i class="glyphicon glyphicon-cloud" ng-class="{online: online, offline: !online}"></i>
</span>
</div>
<div id="alerts">
@@ -57,9 +57,9 @@
<span class="spacer level{{$level}}"></span>
<!--Task state icon-->
- <i class="icon-ban-circle" ng-show="$state=='empty'"></i>
- <i class="icon-plus-sign" ng-click="$toggleState()" ng-show="$state=='close'"></i>
- <i class="icon-minus-sign" ng-click="$toggleState()" ng-show="$state=='open'"></i>
+ <i class="glyphicon glyphicon-ban-circle" ng-show="$state=='empty'"></i>
+ <i class="glyphicon glyphicon-plus-sign" ng-click="$toggleState()" ng-show="$state=='close'"></i>
+ <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'">
@@ -69,12 +69,12 @@
<!-- Action button, add,remove activate task -->
<span class="btn-group action">
- <a class="btn btn-mini" href="" ng-click="timeTask($node.task)" ng-show="$level > 1">
- <i ng-class="{'icon-play' : ($node.task != currentTask), 'icon-stop' : ($node.task == currentTask)}"></i>
+ <a class="btn btn-default btn-xs" href="" ng-click="timeTask($node.task)" ng-show="$level > 1">
+ <i class="glyphicon" ng-class="{'glyphicon-play' : ($node.task != currentTask), 'glyphicon-stop' : ($node.task == currentTask)}"></i>
</a>
- <a class="btn btn-mini" href="" ng-click="addSubTask($node)"><i class="icon-plus"></i></a>
- <a class="btn btn-mini" href="" ng-really-message="La suppression de cette tâche nécessite une confirmation. " ng-really-click="removeTask($node)" ng-show="$node.task != currentTask">
- <i class="icon-minus"></i>
+ <a class="btn btn-default btn-xs" href="" ng-click="addSubTask($node)"><i class="glyphicon glyphicon-plus"></i></a>
+ <a class="btn btn-default btn-xs" href="" ng-really-message="La suppression de cette tâche nécessite une confirmation. " ng-really-click="removeTask($node)" ng-show="$node.task != currentTask">
+ <i class="glyphicon glyphicon-minus"></i>
</a>
</span>
</div>
@@ -92,7 +92,7 @@
<!-- Tag of the task -->
<div class="td tags" ng-show="showTags" ng-click="editTask($node, 'tags')">
<form ng-submit="saveTask($node)" ng-show="$node.edit == 'tags'">
- <input ng-model="$node.task.tags" ng-list>
+ <input class="form-control input-sm" ng-model="$node.task.tags" ng-list>
</form>
<span class="label label-info" ng-repeat="tag in $node.task.tags" style="margin-right: 10px;" ng-show="$node.edit != 'tags'">
@@ -112,15 +112,15 @@
<!-- Affichage pour l'inactivité -->
<script type="text/ng-template" id="idleModalTemplate.html">
<div class="modal-header">
- <h3>Inactivité détectée</h3>
+ <h3 class="modal-title">Inactivité détectée</h3>
</div>
<div class="modal-body">
Vous êtes inactif depuis 42 minutes.
Choisissez une option pour reprendre ou arrêter la tâche.
</div>
<div class="modal-footer">
- <button class="btn btn-primary icon-remove-circle" ng-click="close('stop')"> Arrêter</button>
- <button class="btn btn-primary icon-arrow-right" ng-click="close('continue')"> Continuer</button>
- <button class="btn btn-primary icon-ok-circle" ng-click="close('resume')"> Reprendre</button>
+ <button class="btn btn-primary glyphicon glyphicon-remove-circle" ng-click="close('stop')"> Arrêter</button>
+ <button class="btn btn-primary glyphicon glyphicon-arrow-right" ng-click="close('continue')"> Continuer</button>
+ <button class="btn btn-primary glyphicon glyphicon-ok-circle" ng-click="close('resume')"> Reprendre</button>
</div>
</script>
1
0
Author: echatellier
Date: 2014-05-07 16:40:24 +0200 (Wed, 07 May 2014)
New Revision: 2968
Url: http://forge.chorem.org/projects/jtimer/repository/revisions/2968
Log:
Add google notranslate meta
Modified:
branches/ng-jtimer/src/main/webapp/index.html
Modified: branches/ng-jtimer/src/main/webapp/index.html
===================================================================
--- branches/ng-jtimer/src/main/webapp/index.html 2014-05-07 14:11:25 UTC (rev 2967)
+++ branches/ng-jtimer/src/main/webapp/index.html 2014-05-07 14:40:24 UTC (rev 2968)
@@ -3,6 +3,7 @@
<head>
<title>jTimer</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+ <meta name="google" content="notranslate" />
<link rel="stylesheet" href="css/jtimer.css">
1
0
r2967 - branches/ng-jtimer/src/main/java/org/chorem/jtimer/entities
by obruce@users.chorem.org 07 May '14
by obruce@users.chorem.org 07 May '14
07 May '14
Author: obruce
Date: 2014-05-07 16:11:25 +0200 (Wed, 07 May 2014)
New Revision: 2967
Url: http://forge.chorem.org/projects/jtimer/repository/revisions/2967
Log:
Ajout de timertime
Added:
branches/ng-jtimer/src/main/java/org/chorem/jtimer/entities/TimerTime.java
Added: branches/ng-jtimer/src/main/java/org/chorem/jtimer/entities/TimerTime.java
===================================================================
--- branches/ng-jtimer/src/main/java/org/chorem/jtimer/entities/TimerTime.java (rev 0)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/entities/TimerTime.java 2014-05-07 14:11:25 UTC (rev 2967)
@@ -0,0 +1,90 @@
+package org.chorem.jtimer.entities;
+
+import java.io.Serializable;
+import java.util.Date;
+import java.util.UUID;
+
+/**
+ *
+ * jTimer TimerTime
+ *
+ * This class represents
+ *
+ * Created by olivia on 05/05/14.
+ */
+public class TimerTime implements Serializable {
+
+ /** Task identifier it refers to */
+ protected String taskId;
+
+ /** Task identifier*/
+ protected String timeId;
+
+ /** Creation Date*/
+ protected Date creationDate;
+
+ /** Time Elapsed in the period */
+ protected long time;
+
+
+ public TimerTime() {
+ }
+
+ /**
+ * Constructor
+ * @param taskId
+ * @param time
+ * @param creationDate
+ */
+ public TimerTime( String taskId, long time, Date creationDate) {
+ this.timeId = UUID.randomUUID().toString();
+ this.taskId = taskId;
+ this.time = time;
+ this.creationDate = creationDate;
+ }
+
+
+
+
+ public String getTaskId() {
+ return taskId;
+ }
+
+ public void setTaskId(String taskId) {
+ this.taskId = taskId;
+ }
+
+ public String getTimeId() {
+ return timeId;
+ }
+
+ public void setTimeId(String timeId) {
+ this.timeId = timeId;
+ }
+
+ public Date getCreationDate() {
+ return creationDate;
+ }
+
+ public void setCreationDate(Date creationDate) {
+ this.creationDate = creationDate;
+ }
+
+ public long getTime() {
+ return time;
+ }
+
+ public void setTime(long time) {
+ this.time = time;
+ }
+
+ @Override
+ public String toString() {
+ return "TimerTime{" +
+ ", taskId='" + taskId + '\'' +
+ ", timeId='" + timeId + '\'' +
+ ", creationDate=" + creationDate +
+ ", time=" + time +
+ '}';
+ }
+}
1
0
r2966 - in branches/ng-jtimer/src/main: java/org/chorem/jtimer/web webapp/js
by obruce@users.chorem.org 07 May '14
by obruce@users.chorem.org 07 May '14
07 May '14
Author: obruce
Date: 2014-05-07 16:07:58 +0200 (Wed, 07 May 2014)
New Revision: 2966
Url: http://forge.chorem.org/projects/jtimer/repository/revisions/2966
Log:
Correction base ajout delete cascade
Modified:
branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TaskResource.java
branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TimeResource.java
branches/ng-jtimer/src/main/webapp/js/controllers.js
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-05-07 09:53:17 UTC (rev 2965)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TaskResource.java 2014-05-07 14:07:58 UTC (rev 2966)
@@ -34,5 +34,10 @@
storage.deleteTaskWithId(taskId);
}
+ @Put("json")
+ public void updateTask(){
+ }
+
+
}
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-07 09:53:17 UTC (rev 2965)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TimeResource.java 2014-05-07 14:07:58 UTC (rev 2966)
@@ -62,7 +62,7 @@
TimerTime t = gson.fromJson(repr1, TimerTime.class);
- storage.addTaskTime(t,3);
+ storage.addTaskTime(t,number);
}
Modified: branches/ng-jtimer/src/main/webapp/js/controllers.js
===================================================================
--- branches/ng-jtimer/src/main/webapp/js/controllers.js 2014-05-07 09:53:17 UTC (rev 2965)
+++ branches/ng-jtimer/src/main/webapp/js/controllers.js 2014-05-07 14:07:58 UTC (rev 2966)
@@ -154,7 +154,7 @@
var getTimesFromServer = function(task){
if(!$scope.data.times[task.taskId]){$scope.data.times[task.taskId] = []}
-
+ //On va chercher les temps pour une tacheeditTask
serverTimeAccess.query({taskId : task.taskId}, function (response) {
angular.forEach(response, function (item) {
@@ -170,28 +170,42 @@
}
var pushChangesToServ= function(){
-
+ //On supprime de la base les taches sotckees pour suppression
angular.forEach(stockedDeletedTasks, function(task){
- serverTaskAccess.delete({taskId: task});
- console.log("delete "+ task.name);
+ serverTaskAccess.delete({taskId: task},
+ function(){
+ console.log("delete success" + task);
+ stockedDeletedTasks.shift();
+ },
+ function(){
+ console.log("fail");
+ });
});
+ //On ajoute au serveur les taches stockees pour l'ajout
angular.forEach(stockedNewTasks, function(task){
- serverTaskAccess.create(angular.toJson(task));
- console.log("ajout new task to serv "+ task.name);
+ serverTaskAccess.create(angular.toJson(task),
+ function(){
+ console.log("persist task success" + task);
+ stockedNewTasks.shift();
+ },
+ function(){
+ console.log("fail");
+ });
});
+
+ //On ajoute les nouveaux temps au serveur
angular.forEach(stockedNewTimes, function(times,task){
angular.forEach(times, function(time){
- serverTimeAccess.create({taskId: task} , angular.toJson(time));
- });
-
- console.log(times);
- //serverTimeAccess.create({taskId: task} , angular.toJson(times));
- console.log("ajout new time to serv ");
+ serverTimeAccess.create({taskId: task} , angular.toJson(time),
+ function(){
+ console.log("persist time success" + task);
+ stockedNewTimes[task].shift();
+ },
+ function(){
+ console.log("fail");
+ });
+ });
});
- //TODO comportement de file avec shift
- stockedDeletedTasks = [];
- stockedNewTasks = [];
- stockedNewTimes ={};
}
/**
@@ -378,36 +392,7 @@
return result;
};
- /**
- * Retourne l'objet TaskTime d'aujourd'hui pour la tache demandee
- * Si cet objet n'existait pas, il est cree et ajouter a la liste
- * des objets temps existant
- * @param {type} task
- * @returns {nodes}
- $scope.getTodayTaskTime = function(task) {
- var times = $scope.data.times[task.taskId];
-
- if (!times) {
- times = [];
- $scope.data.times[task.taskId]= times;
- }
-
- var result;
- angular.forEach(times, function (t) {
- if (!result && t.isToday()) {
- result = t;
- }
- });
-
- if (!result) {
- result = new TaskTime(task);
- times.push(result);
- }
-
- return result;
- };*/
-
/**
* Retourne l'objet TaskTime d'aujourd'hui pour la tache demandee
* Si cet objet n'existait pas, il est cree et ajouter a la liste
@@ -422,7 +407,6 @@
times = [];
$scope.data.times[task.taskId]= times;
}
- if(!stockedNewTimes[task.taskId]){stockedNewTimes[task.taskId]=[];}
var maxDate = new Date(0,0,0,0,0);
var result;
@@ -439,7 +423,6 @@
if (!result) {
result = new TaskTime(task);
times.push(result);
- stockedNewTimes[task.taskId].push(result);
}
return result;
@@ -476,17 +459,18 @@
if ($scope.currentTask) {
var taskTime = $scope.getRecentTaskTime($scope.currentTask);
taskTime.addTime(now - $scope.currentTaskDate);
+
+ if(!stockedNewTimes[task.taskId]){stockedNewTimes[task.taskId]=[];}
+ stockedNewTimes[task.taskId].push(taskTime);
}
//si ce n'est la la tache courante actuel
if ($scope.currentTask !== task) {
- //On ajoute un nouveau timeTask dans la liste des times
+ //On ajoute un nouveau timeTask dans la liste des times
if (!$scope.data.times[task.taskId]) {$scope.data.times[task.taskId]= [];}
- if(!stockedNewTimes[task.taskId]){stockedNewTimes[task.taskId]=[];}
var temp =new TaskTime(task);
$scope.data.times[task.taskId].push(temp);
- stockedNewTimes[task.taskId].push(temp);
//On change la task courante
$scope.currentTask = task;
1
0
r2965 - in branches/ng-jtimer/src/main: java/org/chorem/jtimer/storage webapp/js
by obruce@users.chorem.org 07 May '14
by obruce@users.chorem.org 07 May '14
07 May '14
Author: obruce
Date: 2014-05-07 11:53:17 +0200 (Wed, 07 May 2014)
New Revision: 2965
Url: http://forge.chorem.org/projects/jtimer/repository/revisions/2965
Log:
Correction base ajout delete cascade
Modified:
branches/ng-jtimer/src/main/java/org/chorem/jtimer/storage/Storage.java
branches/ng-jtimer/src/main/webapp/js/service.js
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-06 15:21:10 UTC (rev 2964)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/storage/Storage.java 2014-05-07 09:53:17 UTC (rev 2965)
@@ -144,7 +144,7 @@
statement.executeUpdate("CREATE TABLE " + TABLE_VERSION +
"(version VARCHAR(10))");
statement.executeUpdate("CREATE TABLE " + TABLE_TASK +
- "(id LONG NOT NULL UNIQUE AUTO_INCREMENT," +
+ "(id LONG NOT NULL AUTO_INCREMENT," +
" taskId VARCHAR(255) NOT NULL UNIQUE," +
" name VARCHAR(255) NOT NULL," +
" parent VARCHAR(255)," +
@@ -156,7 +156,11 @@
" date DATE," +
" uuid varchar(255) unique," +
" duration LONG," +
- " PRIMARY KEY (taskid, date, uuid))");
+ " PRIMARY KEY (taskid, date, uuid)" +
+ ", FOREIGN KEY (taskid)" +
+ " REFERENCES " + TABLE_TASK +"(id)" +
+ " ON DELETE CASCADE" +
+ ")");
} catch (SQLException ex) {
throw new StorageException("Can't create schema", ex);
} finally {
Modified: branches/ng-jtimer/src/main/webapp/js/service.js
===================================================================
--- branches/ng-jtimer/src/main/webapp/js/service.js 2014-05-06 15:21:10 UTC (rev 2964)
+++ branches/ng-jtimer/src/main/webapp/js/service.js 2014-05-07 09:53:17 UTC (rev 2965)
@@ -20,10 +20,9 @@
// Encapsule l'acces au server
return $resource("rest/tasks/:taskId/time",{},
{
- query : {method:'GET', isArray:true},
+ query : {method:'GET', isArray:true},
get : {method: 'GET', isArray: false},
update: {method: "PUT"},
- delete: { method: 'DELETE' },
create: { method: 'POST' }
1
0
r2964 - in branches/ng-jtimer/src/main: java/org/chorem/jtimer/storage java/org/chorem/jtimer/web webapp/js
by obruce@users.chorem.org 06 May '14
by obruce@users.chorem.org 06 May '14
06 May '14
Author: obruce
Date: 2014-05-06 17:21:10 +0200 (Tue, 06 May 2014)
New Revision: 2964
Url: http://forge.chorem.org/projects/jtimer/repository/revisions/2964
Log:
Ajout de push et pull task et time
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/js/controllers.js
branches/ng-jtimer/src/main/webapp/js/entities.js
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-06 07:45:40 UTC (rev 2963)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/storage/Storage.java 2014-05-06 15:21:10 UTC (rev 2964)
@@ -144,8 +144,8 @@
statement.executeUpdate("CREATE TABLE " + TABLE_VERSION +
"(version VARCHAR(10))");
statement.executeUpdate("CREATE TABLE " + TABLE_TASK +
- "(id LONG NOT NULL AUTO_INCREMENT," +
- " taskId VARCHAR(255) NOT NULL," +
+ "(id LONG NOT NULL UNIQUE AUTO_INCREMENT," +
+ " taskId VARCHAR(255) NOT NULL UNIQUE," +
" name VARCHAR(255) NOT NULL," +
" parent VARCHAR(255)," +
" hidden BOOLEAN," +
@@ -296,6 +296,25 @@
}
}
+ public long getTaskNumber(String id) {
+ PreparedStatement statement = null;
+ long result= 0;
+ try {
+ statement = connection.prepareStatement("SELECT id FROM " +TABLE_TASK +
+ " WHERE taskId = '" + id+"'");
+
+ ResultSet rs = statement.executeQuery();
+ while (rs.next()) {
+ result = rs.getLong(1);
+ }
+ } catch (SQLException ex) {
+ throw new StorageException("Read error", ex);
+ } finally {
+ closeStatement(statement);
+ }
+ return result;
+ }
+
public void addTaskTime(TimerTask task, Date date, String uuid, long duration) {
PreparedStatement statement = null;
try {
@@ -315,38 +334,33 @@
}
}
- public void deleteTask(TimerTask task) {
+ public void addTaskTime(TimerTime time, long number) {
PreparedStatement statement = null;
try {
- statement = connection.prepareStatement("DELETE FROM " +
- TABLE_TASK + " WHERE id = ?");
- statement.setLong(1, task.getNumber());
+ statement = connection.prepareStatement("INSERT INTO " + TABLE_TIME +
+ "(taskid, date, uuid, duration)" +
+ " VALUES(?, ?, ?, ?)");
+
+ statement.setLong(1, number);
+ statement.setDate(2, new java.sql.Date(time.getCreationDate().getTime()));
+ statement.setString(3, time.getTimeId());
+ statement.setLong(4, time.getTime());
statement.executeUpdate();
} catch (SQLException ex) {
- throw new StorageException("Can't delete project", ex);
+ throw new StorageException("Can't add task time", ex);
} finally {
closeStatement(statement);
}
}
+
+
+
public void setAnnotation(TimerTask task, Date date, String annotation) {
}
- public void deleteTaskWithId(String taskId) {
- PreparedStatement statement = null;
- try {
- statement = connection.prepareStatement("DELETE FROM " +
- TABLE_TASK + " WHERE taskId = ?");
- statement.setString(1, taskId);
- statement.executeUpdate();
- } catch (SQLException ex) {
- throw new StorageException("Can't delete project", ex);
- } finally {
- closeStatement(statement);
- }
- }
/**
@@ -379,4 +393,60 @@
}
return times;
}
+
+
+ /** Suppression de tuple **/
+
+ /**
+ * Methode qui va supprimer un timertime a l'aide de son identifiant
+ * @param timeId
+ */
+ public void deleteTimeWithId(String timeId) {
+ PreparedStatement statement = null;
+ try {
+ statement = connection.prepareStatement("DELETE FROM " +
+ TABLE_TIME + " WHERE uuid = ?");
+ statement.setString(1, timeId);
+ statement.executeUpdate();
+ } catch (SQLException ex) {
+ throw new StorageException("Can't delete time", ex);
+ } finally {
+ closeStatement(statement);
+ }
+
+ }
+
+ /**
+ * Methode qui va supprimer un timertime a l'aide de son identifiant
+ * @param taskId
+ */
+ public void deleteTaskWithId(String taskId) {
+ PreparedStatement statement = null;
+ try {
+ statement = connection.prepareStatement("DELETE FROM " +
+ TABLE_TASK + " WHERE taskId = ?");
+ statement.setString(1, taskId);
+ statement.executeUpdate();
+ } catch (SQLException ex) {
+ throw new StorageException("Can't delete project", ex);
+ } finally {
+ closeStatement(statement);
+ }
+
+ }
+
+ public void deleteTask(TimerTask task) {
+ PreparedStatement statement = null;
+ try {
+ statement = connection.prepareStatement("DELETE FROM " +
+ TABLE_TASK + " WHERE id = ?");
+ statement.setLong(1, task.getNumber());
+ statement.executeUpdate();
+ } catch (SQLException ex) {
+ throw new StorageException("Can't delete project", ex);
+ } finally {
+ closeStatement(statement);
+ }
+ }
+
}
\ No newline at end of file
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-06 07:45:40 UTC (rev 2963)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TimeResource.java 2014-05-06 15:21:10 UTC (rev 2964)
@@ -1,22 +1,37 @@
package org.chorem.jtimer.web;
-import com.google.gson.Gson;
+import com.google.gson.*;
+import org.chorem.jtimer.entities.TimerTask;
import org.chorem.jtimer.entities.TimerTime;
import org.chorem.jtimer.storage.Storage;
import org.restlet.data.MediaType;
import org.restlet.representation.Representation;
import org.restlet.representation.StringRepresentation;
-import org.restlet.resource.Get;
-import org.restlet.resource.ResourceException;
-import org.restlet.resource.ServerResource;
+import org.restlet.resource.*;
+import java.io.IOException;
+import java.lang.reflect.Type;
+import java.util.Date;
import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
public class TimeResource extends ServerResource {
+
+ private GsonBuilder builder;
protected Storage storage;
+ private final static Logger LOGGER = Logger.getLogger(TasksResource.class.getName());
@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());
+ }
+ });
+
storage = (Storage)getContext().getAttributes().get(Storage.class.getName());
}
@@ -29,4 +44,26 @@
String json = gson.toJson(timerTimes);
return new StringRepresentation(json, MediaType.APPLICATION_JSON);
}
+
+ @Delete
+ public void deleteTask() {
+
+ String timeId = (String)getRequest().getAttributes().get("taskId");
+ storage.deleteTimeWithId(timeId);
+ }
+
+ @Post("json")
+ public void createTask(Representation representation) throws IOException {
+ String timeId = (String)getRequest().getAttributes().get("taskId");
+ long number = storage.getTaskNumber(timeId);
+
+ Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX").create();
+ String repr1 = representation.getText();
+
+ TimerTime t = gson.fromJson(repr1, TimerTime.class);
+
+ storage.addTaskTime(t,3);
+ }
+
+
}
Modified: branches/ng-jtimer/src/main/webapp/js/controllers.js
===================================================================
--- branches/ng-jtimer/src/main/webapp/js/controllers.js 2014-05-06 07:45:40 UTC (rev 2963)
+++ branches/ng-jtimer/src/main/webapp/js/controllers.js 2014-05-06 15:21:10 UTC (rev 2964)
@@ -49,8 +49,8 @@
// {Array of TaskID} la file de tache attendant la synchronisation avec le serveur
var stockedNewTasks = [];
var stockedDeletedTasks = [];
- // {Array of TaskID} la file de temps des taches attendant la synchronisation avec le serveur
- var stockedNewTimes = [];
+ // {key: taskId, value: Array of TaskTime} la file de temps des taches attendant la synchronisation avec le serveur
+ var stockedNewTimes = {};
/**
* Met a jour la tache selectionne, si la tache selectionnee est la courante
@@ -113,7 +113,7 @@
/**
* Récupère les nouveaux elements du serveur et les ajoute a l'arbre pour l'affichage
*/
- var getChangesFromServ = function(){
+ var getTasksFromServ = function(){
serverTaskAccess.query(function (response) {
angular.forEach(response, function (item) {
@@ -136,13 +136,9 @@
//Un noeud avec un parent est ajoute à l'arbre de son parent
$scope.data.tasks[newTask.taskId] = newTask;
+ //Les temps sont recuperes du serveur
getTimesFromServer(newTask);
- //On ajoute le temps du jour et global sur ce noeud
- //$scope.getRecentTaskTime($scope.data.tasks[newTask.taskId]).addTime(item.todayTime);
- //var global = new GlobalTime(newTask).addTime(parseInt(item.totalTime));
- //$scope.data.globalTimes[newTask.taskId] = global;
-
console.log(newTask);
console.log("Import task "+ newTask.name);
console.log($scope.data.times[newTask.taskId])
@@ -166,9 +162,11 @@
//On cree le tasktime
taskTime = new TaskTime(task, item.timeId, item.creationDate, item.time);
$scope.data.times[task.taskId].push(taskTime);
+ save();
}
});
});
+
}
var pushChangesToServ= function(){
@@ -181,8 +179,19 @@
serverTaskAccess.create(angular.toJson(task));
console.log("ajout new task to serv "+ task.name);
});
+ angular.forEach(stockedNewTimes, function(times,task){
+ angular.forEach(times, function(time){
+ serverTimeAccess.create({taskId: task} , angular.toJson(time));
+ });
+
+ console.log(times);
+ //serverTimeAccess.create({taskId: task} , angular.toJson(times));
+ console.log("ajout new time to serv ");
+ });
+ //TODO comportement de file avec shift
stockedDeletedTasks = [];
stockedNewTasks = [];
+ stockedNewTimes ={};
}
/**
@@ -214,11 +223,11 @@
if ( $scope.online == true) {
pushChangesToServ();
- getChangesFromServ();
+ getTasksFromServ();
//On change la date de dernier acces
$scope.acces = moment().format("DD-MM-YYYY H:mm:ss a");
- console.log($scope.data.times);
+
}
}, 30000); //TODO: for now 10s but for real put at least 2h: 200000000
@@ -258,7 +267,6 @@
node.$$open = true;
save();
node.addChild($scope.createTreeNode(newTask));
- console.log($scope.data.times[newTask.taskId]);
};
/**
@@ -276,6 +284,7 @@
delete $scope.data.times[task.taskId];
stockedDeletedTasks.push(task.taskId);
+ delete stockedNewTimes[task.taskId];
var children = $scope.getChildren(task);
removeRecurse(children);
@@ -413,14 +422,15 @@
times = [];
$scope.data.times[task.taskId]= times;
}
+ if(!stockedNewTimes[task.taskId]){stockedNewTimes[task.taskId]=[];}
var maxDate = new Date(0,0,0,0,0);
var result;
angular.forEach(times, function (t) {
if (t.isToday() ) {
- if(maxDate < t.creationTime){
- maxDate = t.creationTime;
+ if(maxDate < t.creationDate){
+ maxDate = t.creationDate;
result = t;
}
}
@@ -429,6 +439,7 @@
if (!result) {
result = new TaskTime(task);
times.push(result);
+ stockedNewTimes[task.taskId].push(result);
}
return result;
@@ -469,13 +480,14 @@
//si ce n'est la la tache courante actuel
if ($scope.currentTask !== task) {
//On ajoute un nouveau timeTask dans la liste des times
- var times = $scope.data.times[task.taskId];
- if (!times) {
- times = [];
- $scope.data.times[task.taskId]= times;
- }
- times.push(new TaskTime(task));
+ if (!$scope.data.times[task.taskId]) {$scope.data.times[task.taskId]= [];}
+ if(!stockedNewTimes[task.taskId]){stockedNewTimes[task.taskId]=[];}
+
+ var temp =new TaskTime(task);
+ $scope.data.times[task.taskId].push(temp);
+ stockedNewTimes[task.taskId].push(temp);
+
//On change la task courante
$scope.currentTask = task;
$scope.currentTaskDate = now;
@@ -485,7 +497,6 @@
$scope.currentTask = null;
$scope.currentTaskDate = null;
}
- console.log($scope.data.times[task.taskId]);
save();
};
@@ -558,7 +569,7 @@
//force the first server connection
pushChangesToServ();
- getChangesFromServ();
+ getTasksFromServ();
// force the first tree creation
$scope.createTree();
Modified: branches/ng-jtimer/src/main/webapp/js/entities.js
===================================================================
--- branches/ng-jtimer/src/main/webapp/js/entities.js 2014-05-06 07:45:40 UTC (rev 2963)
+++ branches/ng-jtimer/src/main/webapp/js/entities.js 2014-05-06 15:21:10 UTC (rev 2964)
@@ -360,9 +360,9 @@
}
if(date == undefined){
- this.creationTime = new Date();
+ this.creationDate = new Date();
}else{
- this.creationTime = new Date(date);
+ this.creationDate = new Date(date);
}
if(time == undefined){
@@ -378,7 +378,7 @@
* @returns {Boolean}
*/
TaskTime.prototype.isToday = function() {
- var result = new Date(this.creationTime).sameDay(new Date());
+ var result = new Date(this.creationDate).sameDay(new Date());
return result;
};
1
0
r2963 - in branches/ng-jtimer/src/main: java/org/chorem/jtimer/entities java/org/chorem/jtimer/storage java/org/chorem/jtimer/web webapp/js
by obruce@users.chorem.org 06 May '14
by obruce@users.chorem.org 06 May '14
06 May '14
Author: obruce
Date: 2014-05-06 09:45:40 +0200 (Tue, 06 May 2014)
New Revision: 2963
Url: http://forge.chorem.org/projects/jtimer/repository/revisions/2963
Log:
Ajout des p?\195?\169riodes entities/TimeResource, ajout uuid pour les taches, ajout service rest pour les temps
Modified:
branches/ng-jtimer/src/main/java/org/chorem/jtimer/entities/TimerTask.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/java/org/chorem/jtimer/web/TimeResource.java
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
Modified: branches/ng-jtimer/src/main/java/org/chorem/jtimer/entities/TimerTask.java
===================================================================
--- branches/ng-jtimer/src/main/java/org/chorem/jtimer/entities/TimerTask.java 2014-05-02 09:57:35 UTC (rev 2962)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/entities/TimerTask.java 2014-05-06 07:45:40 UTC (rev 2963)
@@ -27,13 +27,14 @@
import java.io.Serializable;
import java.util.Date;
+import java.util.UUID;
/**
* Represents a task.
- *
+ *
* @author chatellier
* @version $Revision$
- *
+ *
* Last update : $Date$
* By : $Author$
*/
@@ -45,8 +46,11 @@
/** Task number. */
protected long number;
+ /** Task uuid */
+ protected String taskId;
+
/** Parent task number. */
- protected long parent;
+ protected String parent;
/** Task name. */
protected String name;
@@ -73,13 +77,15 @@
/**
* Constructor with name.
- *
+ *
* @param name task name
*/
public TimerTask(long number, String name) {
this();
this.number = number;
this.name = name;
+ this.taskId = UUID.randomUUID().toString();
+ this.parent = "";
}
/**
@@ -100,17 +106,41 @@
this.number = number;
}
- public long getParent() {
+ /**
+ * Get task uuid
+ * @return the task uuid
+ */
+ public void setTaskId(String taskuuid) {
+ taskId = taskuuid;
+ }
+
+ /**
+ * Get task uuid
+ * @return the task uuid
+ */
+ public String getTaskId() {
+ return taskId;
+ }
+
+ /**
+ * Get task parent
+ * @return the parent
+ */
+ public String getParent() {
return parent;
}
- public void setParent(long parent) {
+ /**
+ * Set task parent
+ * @param parent the parent to set
+ */
+ public void setParent(String parent) {
this.parent = parent;
}
/**
* Get task name.
- *
+ *
* @return the name
*/
public String getName() {
@@ -119,7 +149,7 @@
/**
* Set task name.
- *
+ *
* @param name the name to set
*/
public void setName(String name) {
@@ -128,7 +158,7 @@
/**
* Get task creation date.
- *
+ *
* @return task creation date
*/
public Date getCreationDate() {
@@ -137,7 +167,7 @@
/**
* Set task creation date.
- *
+ *
* @param creationDate creation date
*/
public void setCreationDate(Date creationDate) {
@@ -146,7 +176,7 @@
/**
* Get closed task state.
- *
+ *
* @return <tt>true</tt> if task is closed
*/
public boolean isClosed() {
@@ -155,7 +185,7 @@
/**
* Set closed.
- *
+ *
* @param closed closed
*/
public void setClosed(boolean closed) {
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-02 09:57:35 UTC (rev 2962)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/storage/Storage.java 2014-05-06 07:45:40 UTC (rev 2963)
@@ -13,17 +13,18 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.chorem.jtimer.entities.TimerTask;
+import org.chorem.jtimer.entities.TimerTime;
/**
* Implementation du stockage des taches en base de données basée sur h2.
- *
+ *
* Le schema est composé des tables:
* <ul>
* <li>Task
* <li>TaskTime
* <li>Version (contenant la version du schema en cas de migration)</li>
* </ul>
- *
+ *
* @author echatellier
*/
public class Storage {
@@ -80,7 +81,7 @@
log.info("Creating new database schema");
}
createSchema(conn);
-
+
// set new version in schema
Statement statement = conn.createStatement();
statement.executeUpdate("INSERT INTO VERSION VALUES('2.0')");
@@ -107,7 +108,7 @@
/**
* Test if table "version" exists in database list.
- *
+ *
* @param conn sql connection
* @return schema exists
*/
@@ -143,11 +144,13 @@
statement.executeUpdate("CREATE TABLE " + TABLE_VERSION +
"(version VARCHAR(10))");
statement.executeUpdate("CREATE TABLE " + TABLE_TASK +
- "(id LONG NOT NULL AUTO_INCREMENT PRIMARY KEY," +
+ "(id LONG NOT NULL AUTO_INCREMENT," +
+ " taskId VARCHAR(255) NOT NULL," +
" name VARCHAR(255) NOT NULL," +
- " parent LONG DEFAULT 0," +
+ " parent VARCHAR(255)," +
" hidden BOOLEAN," +
- " note TEXT)");
+ " note TEXT," +
+ " PRIMARY KEY (id, taskId))");
statement.executeUpdate("CREATE TABLE " + TABLE_TIME +
"(taskid LONG NOT NULL REFERENCES " + TABLE_TASK + "(id)," +
" date DATE," +
@@ -159,14 +162,14 @@
} finally {
closeStatement(statement);
}
-
+
}
/** Query **/
/**
* Find all project. (task with no parent, parent = 0).
- *
+ *
* @return all projects
*/
public int getTasksCount() {
@@ -195,7 +198,7 @@
PreparedStatement statement = null;
PreparedStatement statement2 = null;
try {
- statement = connection.prepareStatement("SELECT TA.*, sum(TI.duration) AS totalduration FROM " +
+ statement = connection.prepareStatement("SELECT TA.*, MIN(TI.date) as modifdate, sum(TI.duration) AS totalduration FROM " +
TABLE_TASK + " TA, " + TABLE_TIME + " TI" +
" WHERE TA.id = TI.taskid" +
" GROUP BY TA.id");
@@ -203,13 +206,15 @@
while (rs.next()) {
TimerTask task = new TimerTask();
task.setNumber(rs.getInt("id"));
+ task.setTaskId(rs.getString("taskId"));
task.setName(rs.getString("name"));
- task.setParent(rs.getLong("parent"));
+ task.setParent(rs.getString("parent"));
task.setTodayTime(0);
+ task.setCreationDate(new java.util.Date(rs.getDate("modifdate").getTime()));
task.setTotalTime(rs.getLong("totalduration"));
tasks.add(task);
}
-
+
// not timed tasks
statement2 = connection.prepareStatement("SELECT * FROM " + TABLE_TASK +
" WHERE id not in (SELECT taskid FROM " + TABLE_TIME + ")");
@@ -218,7 +223,9 @@
TimerTask task = new TimerTask();
task.setNumber(rs.getInt("id"));
task.setName(rs.getString("name"));
- task.setParent(rs.getLong("parent"));
+ task.setTaskId(rs.getString("taskId"));
+ task.setParent(rs.getString("parent"));
+ task.setCreationDate(new Date());
task.setTodayTime(0);
task.setTotalTime(0);
tasks.add(task);
@@ -240,12 +247,17 @@
PreparedStatement statement = null;
try {
statement = connection.prepareStatement("INSERT INTO " +
- TABLE_TASK + "(name, parent, hidden, note)" +
- " VALUES (?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS);
+ TABLE_TASK + "(name, parent, taskId, hidden, note)" +
+ " VALUES (?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS);
statement.setString(1, task.getName());
- statement.setLong(2, task.getParent());
- statement.setBoolean(3, task.isClosed());
- statement.setString(4, null /*project.getNote()*/);
+ if (task.getParent() == "" || task.getParent() == "0" ) {
+ statement.setString(2, "");
+ } else {
+ statement.setString(2, task.getParent());
+ }
+ statement.setString(3, task.getTaskId());
+ statement.setBoolean(4, task.isClosed());
+ statement.setString(5, null /*project.getNote()*/);
statement.executeUpdate();
// get generated id
@@ -264,17 +276,18 @@
PreparedStatement statement = null;
try {
statement = connection.prepareStatement("UPDATE " +
- TABLE_TASK + " SET name=?, parent=?, hidden=?, note=?" +
+ TABLE_TASK + " SET name=?, parent=?, taskId=?, hidden=?, note=?" +
" WHERE id = ?");
statement.setString(1, task.getName());
- if (task.getParent() > 0) {
- statement.setLong(2, 0);
+ if (task.getParent() == "") {
+ statement.setString(2, "");
} else {
- statement.setLong(2, task.getParent());
+ statement.setString(2, task.getParent());
}
- statement.setBoolean(3, task.isClosed());
- statement.setString(4, null /*project.getNote()*/);
- statement.setLong(5, task.getNumber());
+ statement.setString(3, task.getTaskId());
+ statement.setBoolean(4, task.isClosed());
+ statement.setString(5, null /*project.getNote()*/);
+ statement.setLong(6, task.getNumber());
statement.executeUpdate();
} catch (SQLException ex) {
throw new StorageException("Can't modify task", ex);
@@ -317,6 +330,53 @@
}
public void setAnnotation(TimerTask task, Date date, String annotation) {
-
+
}
+
+ public void deleteTaskWithId(String taskId) {
+ PreparedStatement statement = null;
+ try {
+ statement = connection.prepareStatement("DELETE FROM " +
+ TABLE_TASK + " WHERE taskId = ?");
+ statement.setString(1, taskId);
+ statement.executeUpdate();
+ } catch (SQLException ex) {
+ throw new StorageException("Can't delete project", ex);
+ } finally {
+ closeStatement(statement);
+ }
+
+ }
+
+
+ /**
+ * Query that returns every tasks
+ * @return tasks arraylist of tasks
+ */
+ public List<TimerTime> getTimes(String taskid) {
+
+ List<TimerTime> times = new ArrayList<>();
+ PreparedStatement statement = null;
+ try {
+ statement = connection.prepareStatement("SELECT TI.* FROM " +
+ TABLE_TASK + " TA, "+ TABLE_TIME + " TI" +
+ " WHERE TA.id = TI.taskid AND TA.taskId = '" +taskid +"' ");
+ ResultSet rs = statement.executeQuery();
+ while (rs.next()) {
+ TimerTime time = new TimerTime();
+ time.setTaskId(taskid);
+ time.setTimeId(rs.getString("uuid"));
+ time.setTime(rs.getLong("duration"));
+ time.setCreationDate(new java.util.Date(rs.getDate("date").getTime()));
+
+ times.add(time);
+
+ }
+ } catch (SQLException ex) {
+ throw new StorageException("Can't get time", ex);
+ } finally {
+ closeStatement(statement);
+ }
+ return times;
+ }
}
\ No newline at end of file
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-05-02 09:57:35 UTC (rev 2962)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/RestApplication.java 2014-05-06 07:45:40 UTC (rev 2963)
@@ -5,13 +5,12 @@
import org.chorem.jtimer.entities.TimerTask;
import org.chorem.jtimer.storage.Storage;
-import org.restlet.Application;
-import org.restlet.Context;
-import org.restlet.Restlet;
+import org.restlet.*;
import org.restlet.routing.Router;
public class RestApplication extends Application {
+
/**
* Creates a root Restlet that will receive all incoming calls.
*/
@@ -25,8 +24,8 @@
// Defines only one route
router.attach("/tasks", TasksResource.class);
- //router.attach("/tasks/{taskId}", TaskResource.class);
- //router.attach("/tasks/{taskId}/time", TimeResource.class);
+ router.attach("/tasks/{taskId}", TaskResource.class);
+ router.attach("/tasks/{taskId}/time", TimeResource.class);
return router;
}
@@ -39,8 +38,8 @@
TimerTask jTimerProject = new TimerTask(1, "jTimer");
TimerTask jTimerTask1 = new TimerTask(2, "WebService");
TimerTask jTimerTask2 = new TimerTask(8, "WebService2");
- jTimerTask1.setParent(jTimerProject.getNumber());
- jTimerTask2.setParent(jTimerProject.getNumber());
+ jTimerTask1.setParent(jTimerProject.getTaskId());
+ jTimerTask2.setParent(jTimerProject.getTaskId());
storage.addTask(jTimerProject);
storage.addTask(jTimerTask1);
storage.addTask(jTimerTask2);
@@ -58,4 +57,8 @@
context.getAttributes().put(Storage.class.getName(), storage);
}
+
+
+
+
}
\ No newline at end of file
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-05-02 09:57:35 UTC (rev 2962)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TaskResource.java 2014-05-06 07:45:40 UTC (rev 2963)
@@ -5,10 +5,11 @@
import org.restlet.data.MediaType;
import org.restlet.representation.Representation;
import org.restlet.representation.StringRepresentation;
-import org.restlet.resource.Get;
-import org.restlet.resource.ResourceException;
-import org.restlet.resource.ServerResource;
+import org.restlet.resource.*;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
public class TaskResource extends ServerResource {
protected Storage storage;
@@ -22,7 +23,16 @@
public Representation getTask() {
String taskId = (String)getRequest().getAttributes().get("taskId");
Gson gson = new Gson();
- String json = gson.toJson(storage.getTask(Long.valueOf(taskId).longValue()));
+ String json = gson.toJson(Long.valueOf(taskId).longValue());
return new StringRepresentation( json , MediaType.APPLICATION_JSON);
}
+
+ @Delete
+ public void deleteTask() {
+
+ String taskId = (String)getRequest().getAttributes().get("taskId");
+ storage.deleteTaskWithId(taskId);
+ }
+
+
}
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-05-02 09:57:35 UTC (rev 2962)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TasksResource.java 2014-05-06 07:45:40 UTC (rev 2963)
@@ -1,25 +1,40 @@
package org.chorem.jtimer.web;
+import com.google.gson.*;
import org.chorem.jtimer.entities.TimerTask;
import org.chorem.jtimer.storage.Storage;
+import org.eclipse.jetty.util.log.Log;
import org.restlet.data.MediaType;
import org.restlet.representation.Representation;
import org.restlet.representation.StringRepresentation;
-import org.restlet.resource.Get;
-import org.restlet.resource.ResourceException;
-import org.restlet.resource.ServerResource;
+import org.restlet.resource.*;
-import com.google.gson.Gson;
+import java.io.IOException;
+import java.lang.reflect.Type;
+import java.util.Date;
import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
public class TasksResource extends ServerResource {
protected Storage storage;
+ private final static Logger LOGGER = Logger.getLogger(TasksResource.class.getName());
+ private GsonBuilder builder;
+
@Override
protected void doInit() throws ResourceException {
storage = (Storage)getContext().getAttributes().get(Storage.class.getName());
+
+ builder = new GsonBuilder();
+ // Register an adapter to manage the date types as long values
+ builder.registerTypeAdapter(Date.class, new JsonDeserializer<Date>() {
+ public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
+ return new Date(json.getAsJsonPrimitive().getAsLong());
+ }
+ });
}
@Get("json")
@@ -31,7 +46,7 @@
int tabSize = timerTasks.size();
for(int i =0; i <= tabSize;i++){
TimerTask task = timerTasks.get(i);
- if(task.getParent() == 0){
+ if(task.getParent() == ""){
timerTasks.add(task);
timerTasks.remove(i);
i--;
@@ -43,4 +58,21 @@
String json = gson.toJson(timerTasks);
return new StringRepresentation(json, MediaType.APPLICATION_JSON);
}
+
+ @Post("json")
+ public void createTask(Representation representation) throws IOException {
+
+ Gson gson = builder.create();
+ String repr1 = representation.getText();
+ TimerTask t = gson.fromJson(repr1, TimerTask.class);
+ LOGGER.log(Level.INFO,"repr1");
+
+ //List<TimerTask> timerTasks = gson.fromJson(repr1, List.class);
+
+ /*for(TimerTask t : timerTasks){
+ storage.addTask(t);
+ }*/
+ storage.addTask(t);
+ }
+
}
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-02 09:57:35 UTC (rev 2962)
+++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/TimeResource.java 2014-05-06 07:45:40 UTC (rev 2963)
@@ -1,6 +1,7 @@
package org.chorem.jtimer.web;
import com.google.gson.Gson;
+import org.chorem.jtimer.entities.TimerTime;
import org.chorem.jtimer.storage.Storage;
import org.restlet.data.MediaType;
import org.restlet.representation.Representation;
@@ -9,6 +10,8 @@
import org.restlet.resource.ResourceException;
import org.restlet.resource.ServerResource;
+import java.util.List;
+
public class TimeResource extends ServerResource {
protected Storage storage;
@@ -20,8 +23,10 @@
@Get("json")
public Representation getTask() {
String taskId = (String)getRequest().getAttributes().get("taskId");
+ List<TimerTime> timerTimes = storage.getTimes(taskId);
+
Gson gson = new Gson();
- String jsonTime = gson.toJson(storage.getTask(Long.valueOf(taskId).longValue()).getTodayTime());
- return new StringRepresentation("Today time : " + jsonTime , MediaType.APPLICATION_JSON);
+ String json = gson.toJson(timerTimes);
+ return new StringRepresentation(json, MediaType.APPLICATION_JSON);
}
}
Modified: branches/ng-jtimer/src/main/webapp/js/app.js
===================================================================
--- branches/ng-jtimer/src/main/webapp/js/app.js 2014-05-02 09:57:35 UTC (rev 2962)
+++ branches/ng-jtimer/src/main/webapp/js/app.js 2014-05-06 07:45:40 UTC (rev 2963)
@@ -247,7 +247,7 @@
/**
* Module de webtimer
**/
-angular.module('webtimer', ['webtimerFilters', 'ngRoute', 'ngAnimate', 'ui.bootstrap','serverAccessService'])
+angular.module('webtimer', ['webtimerFilters', 'ngRoute', 'ngAnimate', 'ui.bootstrap','serverAccessService', 'serverTimeService' ])
.config(['$routeProvider', function($routeProvider) {
$routeProvider.
when('/tasks', {templateUrl: 'partials/tasks.html', controller: TasksCtrl}).
Modified: branches/ng-jtimer/src/main/webapp/js/controllers.js
===================================================================
--- branches/ng-jtimer/src/main/webapp/js/controllers.js 2014-05-02 09:57:35 UTC (rev 2962)
+++ branches/ng-jtimer/src/main/webapp/js/controllers.js 2014-05-06 07:45:40 UTC (rev 2963)
@@ -1,4 +1,4 @@
-function TasksCtrl($scope, $interval, $timeout, $q, serverAccess, $localStorage, $window, $document, $modal, wtWebsocket) {
+function TasksCtrl($scope, $interval, $timeout, $q, serverTaskAccess, serverTimeAccess, $localStorage, $window, $document, $modal, wtWebsocket) {
// {Boolean} vrai si on est online
$scope.online = $window.navigator.onLine;
@@ -47,9 +47,10 @@
//obruce :Creation de files de temps, de taches
// {Array of TaskID} la file de tache attendant la synchronisation avec le serveur
- $scope.stockedNewTasks = [];
+ var stockedNewTasks = [];
+ var stockedDeletedTasks = [];
// {Array of TaskID} la file de temps des taches attendant la synchronisation avec le serveur
- $scope.stockedNewTimes = [];
+ var stockedNewTimes = [];
/**
* Met a jour la tache selectionne, si la tache selectionnee est la courante
@@ -74,7 +75,7 @@
///console.log(e);
// i = 73; d = 68; F2 = 113
if ($scope.selectedTask) {
- var taskTime = $scope.getTodayTaskTime($scope.selectedTask);
+ var taskTime = $scope.getRecentTaskTime($scope.selectedTask);
if (e.keyCode === 113) {
// edit task, time, note
} else if (e.keyCode === 73 && e.ctrlKey && e.shiftKey) {
@@ -114,33 +115,37 @@
*/
var getChangesFromServ = function(){
- serverAccess.query(function (response) {
+ serverTaskAccess.query(function (response) {
angular.forEach(response, function (item) {
//On verife si l'element n'est pas deja present
- if(!(item.number in $scope.data.tasks)){
- var newTask = new Task( item.name, item.number,item.parent);
+ if(!(item.taskId in $scope.data.tasks)){
- if(item.parent == 0){
+ var newTask = new Task( item.name, item.taskId, item.parent);
+ 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));
}
-
+ console.log("Import projet " + newTask.name);
}else{
-
//Un noeud avec un parent est ajoute à l'arbre de son parent
$scope.data.tasks[newTask.taskId] = newTask;
+ getTimesFromServer(newTask);
//On ajoute le temps du jour et global sur ce noeud
- $scope.getTodayTaskTime($scope.data.tasks[newTask.taskId]).addTime(item.todayTime);
+ //$scope.getRecentTaskTime($scope.data.tasks[newTask.taskId]).addTime(item.todayTime);
- var global = new GlobalTime(newTask).addTime(parseInt(item.totalTime));
- $scope.data.globalTimes[newTask.taskId] = global;
+ //var global = new GlobalTime(newTask).addTime(parseInt(item.totalTime));
+ //$scope.data.globalTimes[newTask.taskId] = global;
+ console.log(newTask);
+ console.log("Import task "+ newTask.name);
+ console.log($scope.data.times[newTask.taskId])
save();
}
}
@@ -150,7 +155,36 @@
};
+ var getTimesFromServer = function(task){
+ if(!$scope.data.times[task.taskId]){$scope.data.times[task.taskId] = []}
+
+ serverTimeAccess.query({taskId : task.taskId}, function (response) {
+ angular.forEach(response, function (item) {
+
+ if(!(item.timeId in $scope.data.times[task.taskId])){
+ //On cree le tasktime
+ taskTime = new TaskTime(task, item.timeId, item.creationDate, item.time);
+ $scope.data.times[task.taskId].push(taskTime);
+ }
+ });
+ });
+ }
+
+ var pushChangesToServ= function(){
+
+ angular.forEach(stockedDeletedTasks, function(task){
+ serverTaskAccess.delete({taskId: task});
+ console.log("delete "+ task.name);
+ });
+ angular.forEach(stockedNewTasks, function(task){
+ serverTaskAccess.create(angular.toJson(task));
+ console.log("ajout new task to serv "+ task.name);
+ });
+ stockedDeletedTasks = [];
+ stockedNewTasks = [];
+ }
+
/**
* Timer qui met les temps a jour toutes les secondes si une tache est
* active
@@ -179,9 +213,12 @@
//Si en ligne on envoie les donnees
if ( $scope.online == true) {
+ pushChangesToServ();
getChangesFromServ();
+
//On change la date de dernier acces
$scope.acces = moment().format("DD-MM-YYYY H:mm:ss a");
+ console.log($scope.data.times);
}
}, 30000); //TODO: for now 10s but for real put at least 2h: 200000000
@@ -192,17 +229,18 @@
* Ajoute une tache root
*/
$scope.addTask = function() {
- var newTask = new Task($scope.name,undefined,0);
+ var newTask = new Task($scope.name);
$scope.data.tasks[newTask.taskId] = newTask;
//On ajoute à la file de synchro
- $scope.stockedNewTasks.push(newTask);
+ stockedNewTasks.push(newTask);
$scope.name = "";
save();
if ($scope.tree) {
$scope.tree.addChild($scope.createTreeNode(newTask));
}
+
};
/**
@@ -215,11 +253,12 @@
$scope.data.tasks[newTask.taskId] = newTask;
//On ajoute à la file de synchro
- $scope.stockedNewTasks.push(newTask);
+ stockedNewTasks.push(newTask);
node.$$open = true;
save();
node.addChild($scope.createTreeNode(newTask));
+ console.log($scope.data.times[newTask.taskId]);
};
/**
@@ -236,9 +275,12 @@
delete $scope.data.tasks[task.taskId];
delete $scope.data.times[task.taskId];
+ stockedDeletedTasks.push(task.taskId);
+
var children = $scope.getChildren(task);
removeRecurse(children);
});
+ save();
};
// mark all task as removed
removeRecurse([node.task]);
@@ -333,7 +375,7 @@
* des objets temps existant
* @param {type} task
* @returns {nodes}
- */
+
$scope.getTodayTaskTime = function(task) {
var times = $scope.data.times[task.taskId];
@@ -355,7 +397,7 @@
}
return result;
- };
+ };*/
/**
* Retourne l'objet TaskTime d'aujourd'hui pour la tache demandee
@@ -376,9 +418,9 @@
var result;
angular.forEach(times, function (t) {
- if (t.isToday()) {
- if(maxDate < new Date(t.date)){
- maxDate = new Date(t.date);
+ if (t.isToday() ) {
+ if(maxDate < t.creationTime){
+ maxDate = t.creationTime;
result = t;
}
}
@@ -437,11 +479,13 @@
//On change la task courante
$scope.currentTask = task;
$scope.currentTaskDate = now;
+
} else {
+
$scope.currentTask = null;
$scope.currentTaskDate = null;
}
-
+ console.log($scope.data.times[task.taskId]);
save();
};
@@ -513,6 +557,7 @@
};
//force the first server connection
+ pushChangesToServ();
getChangesFromServ();
// force the first tree creation
Modified: branches/ng-jtimer/src/main/webapp/js/entities.js
===================================================================
--- branches/ng-jtimer/src/main/webapp/js/entities.js 2014-05-02 09:57:35 UTC (rev 2962)
+++ branches/ng-jtimer/src/main/webapp/js/entities.js 2014-05-06 07:45:40 UTC (rev 2963)
@@ -64,7 +64,6 @@
// la version des donnees
this.dataVersion = 1;
- //this.tasks = []; // Array of Task
this.tasks = {}; // key: taskId, value: Task
this.globalTimes = {}; // key: taskId, value: GlobalTime
this.times = {}; // key: taskId, value: Array of TaskTime
@@ -291,9 +290,9 @@
this.removed = 0;
if(parentTaskId == undefined){
- this.parentTaskId = 0;
+ this.parent = "";
}else{
- this.parentTaskId = parentTaskId;
+ this.parent = parentTaskId;
}
this.name = name;
@@ -333,7 +332,7 @@
* @returns {Boolean}
*/
Task.prototype.isParentOf = function(subtask) {
- var result = subtask.parentTaskId === this.taskId;
+ var result = subtask.parent === this.taskId;
return result;
};
@@ -342,7 +341,7 @@
* @returns {unresolved}
*/
Task.prototype.isRoot = function() {
- var result = !this.parentTaskId;
+ var result = !this.parent;
return result;
};
@@ -351,15 +350,27 @@
* @param {Task} task
* @returns {TaskTime}
*/
-var TaskTime = function (task) {
+var TaskTime = function (task, id, date,time) {
this.taskId = task && task.taskId;
- this.timeId = generateUUID();
+ if(id == undefined){
+ this.timeId = generateUUID();
+ }else{
+ this.timeId = id;
+ }
- this.date = today();
- //this.date = Date.now();
+ if(date == undefined){
+ this.creationTime = new Date();
+ }else{
+ this.creationTime = new Date(date);
+ }
- this.time = 0;
+ if(time == undefined){
+ this.time = 0;
+ }else{
+ this.time = time;
+ }
+
};
/**
@@ -367,10 +378,16 @@
* @returns {Boolean}
*/
TaskTime.prototype.isToday = function() {
- var result = this.date === today();
+ var result = new Date(this.creationTime).sameDay(new Date());
return result;
};
+Date.prototype.sameDay = function(d) {
+ return this.getFullYear() === d.getFullYear()
+ && this.getDate() === d.getDate()
+ && this.getMonth() === d.getMonth();
+}
+
/**
* ajoute du temps
* @param {Number} t
Modified: branches/ng-jtimer/src/main/webapp/js/service.js
===================================================================
--- branches/ng-jtimer/src/main/webapp/js/service.js 2014-05-02 09:57:35 UTC (rev 2962)
+++ branches/ng-jtimer/src/main/webapp/js/service.js 2014-05-06 07:45:40 UTC (rev 2963)
@@ -1,18 +1,33 @@
angular.module("serverAccessService", ["ngResource"])
-.factory("serverAccess", function ( $resource) {
- //TODO: obruce implémenter accès server
+.factory("serverTaskAccess", function ( $resource) {
// Encapsule l'acces au server
- return $resource("rest/tasks/:Id",{Id: "@Id" },
+ return $resource("rest/tasks/:taskId",{},
{
query : {method:'GET', isArray:true},
- get : {
- method: 'GET',
+ get : {method: 'GET',isArray: false},
+ update: {method: "PUT"},
+ delete: { method: 'DELETE' },
+ create: { method: 'POST' }
- isArray: false
- },
- update: {method: "PUT"}
}
);
}
);
+
+angular.module("serverTimeService", ["ngResource"])
+.factory("serverTimeAccess", function ( $resource) {
+ // Encapsule l'acces au server
+ return $resource("rest/tasks/:taskId/time",{},
+ {
+ query : {method:'GET', isArray:true},
+ get : {method: 'GET', isArray: false},
+ update: {method: "PUT"},
+ delete: { method: 'DELETE' },
+ create: { method: 'POST' }
+
+
+ }
+ );
+ }
+);
1
0