Author: obruce Date: 2014-06-25 18:08:07 +0200 (Wed, 25 Jun 2014) New Revision: 3007 Url: http://forge.chorem.org/projects/jtimer/repository/revisions/3007 Log: construction arbre serveur +json du rapport + d?\195?\169but pr?\195?\169sentation rapport dans l'interface Added: branches/ng-jtimer/src/main/webapp/partials/reportNestedTask.html Modified: branches/ng-jtimer/src/main/java/org/chorem/jtimer/storage/Storage.java branches/ng-jtimer/src/main/java/org/chorem/jtimer/utils/MustacheHandler.java branches/ng-jtimer/src/main/java/org/chorem/jtimer/utils/MustacheReport.java branches/ng-jtimer/src/main/java/org/chorem/jtimer/utils/ReportTask.java branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/ReportResource.java branches/ng-jtimer/src/main/resources/jtimer-default.properties branches/ng-jtimer/src/main/webapp/js/controllers.js branches/ng-jtimer/src/main/webapp/js/service.js branches/ng-jtimer/src/main/webapp/partials/reportModal.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-24 13:20:34 UTC (rev 3006) +++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/storage/Storage.java 2014-06-25 16:08:07 UTC (rev 3007) @@ -15,6 +15,7 @@ import java.sql.Statement; import java.util.ArrayList; import java.util.Date; +import java.util.HashMap; import java.util.List; /** @@ -433,9 +434,9 @@ return times; } - public List getReportByProject(Long startDate, Long endDate){ + public HashMap getReportByProject(Long startDate, Long endDate){ - List list = new ArrayList<ReportTask>(); + HashMap map = new HashMap(); PreparedStatement statement = null; PreparedStatement statement2 = null; try{ @@ -446,8 +447,17 @@ ResultSet rs = statement.executeQuery(); while(rs.next()){ - list.add(new ReportTask(rs.getString("task"),rs.getString("taskid"), - rs.getString("parent") , rs.getLong("totalduration"), rs.getLong("creationDate"))); + ReportTask task = new ReportTask(rs.getString("name"), + rs.getString("taskId"), + rs.getString("parent"), + rs.getLong("totalduration")); + + ArrayList tmp = new ArrayList(); + if(map.containsKey(rs.getString("parent"))){ + tmp = (ArrayList) map.get(rs.getString("parent")); + } + tmp.add(task); + map.put(rs.getString("parent"), tmp); } // not timed tasks @@ -455,8 +465,17 @@ rs = statement2.executeQuery(); while(rs.next()){ - list.add(new ReportTask(rs.getString("name"), rs.getString("taskId"), - rs.getString("parent"), (long) 0, rs.getLong("creationDate"))); + ReportTask task = new ReportTask(rs.getString("name"), + rs.getString("taskId"), + rs.getString("parent"), + (long) 0); + + ArrayList tmp = new ArrayList(); + if(map.containsKey(rs.getString("parent"))){ + tmp = (ArrayList) map.get(rs.getString("parent")); + } + tmp.add(task); + map.put(rs.getString("parent"), tmp); } }catch(SQLException ex) { @@ -466,7 +485,7 @@ closeStatement(statement2); } - return list; + return map; } Modified: branches/ng-jtimer/src/main/java/org/chorem/jtimer/utils/MustacheHandler.java =================================================================== --- branches/ng-jtimer/src/main/java/org/chorem/jtimer/utils/MustacheHandler.java 2014-06-24 13:20:34 UTC (rev 3006) +++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/utils/MustacheHandler.java 2014-06-25 16:08:07 UTC (rev 3007) @@ -19,6 +19,8 @@ protected static final Log log = LogFactory.getLog(MustacheReport.class); + protected ArrayList reprArray; + List<ReportTask> tasks; List tasks() { @@ -68,9 +70,11 @@ /** * Constructeur * @param mustacheList la liste des taches + * @param reprArray */ - public MustacheHandler(List<ReportTask> mustacheList){ + public MustacheHandler(List mustacheList, ArrayList reprArray){ this.tasks = mustacheList; + this.reprArray = reprArray; log.debug(mustacheList); } Modified: branches/ng-jtimer/src/main/java/org/chorem/jtimer/utils/MustacheReport.java =================================================================== --- branches/ng-jtimer/src/main/java/org/chorem/jtimer/utils/MustacheReport.java 2014-06-24 13:20:34 UTC (rev 3006) +++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/utils/MustacheReport.java 2014-06-25 16:08:07 UTC (rev 3007) @@ -10,6 +10,7 @@ import java.io.IOException; import java.io.StringWriter; +import java.util.ArrayList; import java.util.List; /** @@ -41,7 +42,7 @@ * Methode qui cree une moustache * @throws IOException */ - public String createByProjectMustache(String type, long start, long end) throws IOException { + public String createByProjectMustache(String type, long start, long end, ArrayList reprArray) throws IOException { log.info("create a Mustache by project"); MustacheFactory mf = new DefaultMustacheFactory(); @@ -49,10 +50,10 @@ //On recupere les taches - mustacheList = storage.getReportByProject(start, end); + //mustacheList = storage.getReportByProject(start, end); StringWriter sw = new StringWriter(); - mustache.execute(sw, new MustacheHandler(mustacheList)).flush(); + mustache.execute(sw, new MustacheHandler(mustacheList,reprArray)).flush(); return sw.toString(); } @@ -63,9 +64,6 @@ MustacheFactory mf = new DefaultMustacheFactory(); Mustache mustache = mf.compile("ByWeek_template.mustache"); - - storage.getReportByWeek(start, end); - StringWriter sw = new StringWriter(); //mustache.execute(sw, MustacheHandler.getByWeekReport()); Modified: branches/ng-jtimer/src/main/java/org/chorem/jtimer/utils/ReportTask.java =================================================================== --- branches/ng-jtimer/src/main/java/org/chorem/jtimer/utils/ReportTask.java 2014-06-24 13:20:34 UTC (rev 3006) +++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/utils/ReportTask.java 2014-06-25 16:08:07 UTC (rev 3007) @@ -1,10 +1,6 @@ package org.chorem.jtimer.utils; -import org.chorem.jtimer.utils.Resource.ReportTime; - import java.util.ArrayList; -import java.util.Date; -import java.util.List; /** * Created by olivia on 16/06/14. @@ -19,10 +15,10 @@ protected String name; protected String taskId; protected String parent; - protected ReportTime time; - protected List subtasks; + protected long time; + protected boolean isReported; - protected Date creationDate; + protected ArrayList subtasks; /** * Constructeur @@ -31,12 +27,12 @@ * @param parent l'identifiant du parent * @param time le temps */ - public ReportTask(String name, String taskId, String parent, long time,long date){ - this.creationDate = new Date(date); + public ReportTask(String name, String taskId, String parent, long time){ this.taskId = taskId; this.name = name; this.parent = parent; - this.time = new ReportTime(time); + this.time = time; + this.isReported = false; this.subtasks = new ArrayList(); } @@ -44,7 +40,7 @@ /** Ajout */ public void addChild(ReportTask t){ this.subtasks.add(t); - this.time.addTime(t.getTime()); + this.time+= t.getTime(); } /**Getter */ @@ -61,10 +57,18 @@ return parent; } - public ReportTime getTime() { + public long getTime() { return time; } + public boolean isReported() { + return isReported; + } + + public void setReported(boolean isReported) { + this.isReported = isReported; + } + @Override public String toString() { return "ReportTask{" + @@ -72,7 +76,7 @@ ", taskId='" + taskId + '\'' + ", parent='" + parent + '\'' + ", time=" + time + - ", subtasks=" + subtasks + + ", subtasks=" + subtasks.toString() + '}'; } } Modified: branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/ReportResource.java =================================================================== --- branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/ReportResource.java 2014-06-24 13:20:34 UTC (rev 3006) +++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/ReportResource.java 2014-06-25 16:08:07 UTC (rev 3007) @@ -1,14 +1,19 @@ package org.chorem.jtimer.web; +import com.google.gson.Gson; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.chorem.jtimer.utils.MustacheReport; +import org.chorem.jtimer.storage.Storage; +import org.chorem.jtimer.utils.ReportTask; import org.restlet.data.MediaType; import org.restlet.representation.Representation; import org.restlet.representation.StringRepresentation; -import org.restlet.resource.Get; +import org.restlet.resource.Post; +import org.restlet.resource.ResourceException; import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; /** * Created by olivia on 11/06/14. @@ -21,17 +26,29 @@ protected static final Log log = LogFactory.getLog(ReportResource.class); + protected Storage storage; + + @Override + protected void doInit() throws ResourceException { + storage = (Storage) getContext().getAttributes().get(Storage.class.getName()); + } /** * Methode qui retourne la representation du rapport * Suite a une requete de type GET * * @return representation du rapport */ - @Get - public Representation getReport() throws IOException { + @Post("json") + public Representation getReport(Representation representation) throws IOException { + ArrayList toReport = new ArrayList(); + if(representation.isAvailable()) { + String repr1 = representation.getText(); + Gson gson =new Gson(); + toReport = gson.fromJson(repr1, ArrayList.class); + } + String type ="BY_PROJECT"; - String res=""; long startDate = (long) 0; long endDate = Long.MAX_VALUE; @@ -52,13 +69,49 @@ } - MustacheReport report = new MustacheReport(getContext()); + //MustacheReport report = new MustacheReport(getContext()); + //res = report.createByProjectMustache(type, startDate, endDate,reprArray); + Gson gson = new Gson(); + HashMap storedTask = storage.getReportByProject(startDate, endDate); + ArrayList res = new ArrayList(); - res = report.createByProjectMustache(type, startDate, endDate); - log.info("Ce qui est produit " + res); + //On recree l'arbre + for(ReportTask rt: (ArrayList<ReportTask>)storedTask.get("")){ + reccursivSortTask(storedTask, rt, res ); + } + //On enleve les éléments non voulus - return new StringRepresentation(res, MediaType.TEXT_HTML); + + + String json = gson.toJson(res, ArrayList.class); + + return new StringRepresentation(json, MediaType.TEXT_HTML); } -} \ No newline at end of file + + /** + * Method that sorts in a array a mapped tree + * @param map the map to sort + * @param rt the current task + * @param res the tree array + */ + private void reccursivSortTask(HashMap map, ReportTask rt, ArrayList res ){ + + if(map.containsKey(rt.getTaskId())) { + for (ReportTask child : (ArrayList<ReportTask>) map.get(rt.getTaskId())) { + reccursivSortTask(map, child, res); + + if(child.getTime() != (long) 0){ + rt.addChild(child); + } + + } + } + + if(rt.getParent() == "" && rt.getTime() != 0){ + res.add(rt); + } + } +} + Modified: branches/ng-jtimer/src/main/resources/jtimer-default.properties =================================================================== --- branches/ng-jtimer/src/main/resources/jtimer-default.properties 2014-06-24 13:20:34 UTC (rev 3006) +++ branches/ng-jtimer/src/main/resources/jtimer-default.properties 2014-06-25 16:08:07 UTC (rev 3007) @@ -65,17 +65,17 @@ WHERE TA.taskId = TI.taskid \ AND TA.removed > 0 \ GROUP BY TA.taskId -jtimer.storage.select.report.timedtasks=SELECT TA.taskId AS taskid, TA.name AS task, TA.parent AS parent, \ - TA.creationDate AS creationDate, sum(TI.duration) AS totalduration \ +jtimer.storage.select.report.timedtasks=SELECT TA.* , sum(TI.duration) AS totalduration \ FROM task TA, tasktime TI \ WHERE TA.taskId = TI.taskid \ AND TA.creationDate > ? \ AND TA.creationDate < ? \ + AND TA.removed = 0 \ GROUP BY TA.taskId \ ORDER BY TA.creationDate DESC jtimer.storage.select.report.roottasks=SELECT * \ FROM task \ - WHERE (taskId not in (SELECT taskid FROM tasktime) AND parent = '' ) + WHERE (taskId not in (SELECT taskid FROM tasktime) AND removed = 0 ) ### #DELETE jtimer.storage.delete.time.withid=DELETE FROM tasktime WHERE uuid = ? Modified: branches/ng-jtimer/src/main/webapp/js/controllers.js =================================================================== --- branches/ng-jtimer/src/main/webapp/js/controllers.js 2014-06-24 13:20:34 UTC (rev 3006) +++ branches/ng-jtimer/src/main/webapp/js/controllers.js 2014-06-25 16:08:07 UTC (rev 3007) @@ -1,4 +1,4 @@ -function TasksCtrl($scope, $interval, $timeout, $q, serverTaskAccess, serverTimeAccess, $localStorage, $window, $document, $modal, wtWebsocket, jTimerWebsocket) { +function TasksCtrl($scope, $interval, $timeout, $q, serverTaskAccess, serverTimeAccess, serverReportAccess, $localStorage, $window, $document, $modal, wtWebsocket, jTimerWebsocket) { // {Boolean} vrai si on est online $scope.online = $window.navigator.onLine; @@ -764,8 +764,6 @@ return moment().format("HH:mm DD/MM/YYYY"); }; - console.log(jTimerWebsocket); - jTimerWebsocket.subscribe({ message: function(data) { //var jsData = JSON.parse(data); @@ -960,7 +958,7 @@ }; } -function ReportModalInstanceCtrl($scope, $modalInstance,$http, $sce, tree){ +function ReportModalInstanceCtrl($scope, $modalInstance,$http, $sce, serverReportAccess, tree){ $scope.tree = tree; @@ -986,24 +984,79 @@ var deb =($scope.obj.startDate).getTime(); var end =($scope.obj.endDate).getTime(); - //TODO obruce envoyer les taches à reporter - $http({method: "GET", url: "/rest/report", - params:{start_Date : deb, end_Date : end}}) + toReportTask = []; + $scope.reportedTask = []; + + var recurseGenerateChildReport = function(child){ + + angular.forEach(child.children, function(childnode){recurseGenerateChildReport(childnode)}); + if(child.task.isReported){ + toReportTask.push(child.task.taskId); + } + } + + angular.forEach(tree.children, function(child){recurseGenerateChildReport(child)}); + + $http({method: "POST", url: "/rest/report", + params:{start_Date : deb, end_Date : end}, data : angular.toJson(toReportTask)}) .success(function(data){ - $scope.htmlReport = data;// data should be text string here (only if the server response is text/plain) + + $scope.htmlReport = data; + angular.forEach(data, function(d){ + console.log(d); + $scope.reportedTask.push({name : d.name, time : d.time}) + }) } ); } - + /** + * Methode qui check les box du parent jusqu'aux enfants + * @param node le noeud concerné + */ $scope.setChildrenCheckbox = function(node){ - angular.forEach(node.children, function(child) { + var recurseReportChild = function(child){ + + angular.forEach(child.children, function(childnode){ + recurseReportChild(childnode) + }); child.task.isReported = node.task.isReported; + } + + angular.forEach(node.children, function(child){ + recurseReportChild(child) }); } - //TODO obruce faire un check et uncheck all + /**Check all checkbox*/ + $scope.checkAll= function(){ + angular.forEach(tree.children, function(child){ + recurseChildEncapsulated(child,encapFonc(child, true)) + }); + }; + + /**Uncheck all checkbox*/ + $scope.uncheckAll= function(){ + angular.forEach(tree.children, function(child){ + recurseChildEncapsulated(child,encapFonc(child, false)) + }); + }; + + /** + * Reccursion sur l'arbre + */ + var recurseChildEncapsulated = function(child, encapsulated){ + angular.forEach(child.children, function(childnode){ + recurseChildEncapsulated(childnode, encapFonc(child, true)) + }); + } + + /**Fonction encapsule*/ + var encapFonc = function(child, bool){ + child.task.isReported= bool; + } + $scope.close = function() { $modalInstance.close(); }; Modified: branches/ng-jtimer/src/main/webapp/js/service.js =================================================================== --- branches/ng-jtimer/src/main/webapp/js/service.js 2014-06-24 13:20:34 UTC (rev 3006) +++ branches/ng-jtimer/src/main/webapp/js/service.js 2014-06-25 16:08:07 UTC (rev 3007) @@ -37,7 +37,7 @@ // Encapsule l'acces au server return $resource("/rest/report",{}, { - get : {method: 'GET', isArray: false}, + getReport : {method: 'POST'}, } ); } Modified: branches/ng-jtimer/src/main/webapp/partials/reportModal.html =================================================================== --- branches/ng-jtimer/src/main/webapp/partials/reportModal.html 2014-06-24 13:20:34 UTC (rev 3006) +++ branches/ng-jtimer/src/main/webapp/partials/reportModal.html 2014-06-25 16:08:07 UTC (rev 3007) @@ -67,6 +67,9 @@ </div> </div> + + <button class="btn btn-primary" ng-click="checkAll()">Check All</button> + <button class="btn btn-primary" ng-click="uncheckAll()">Unckeck All</button> </div> </div> @@ -75,7 +78,14 @@ <alert type="info" > <span> - <div ng-bind-html="toHTML(htmlReport)"></div> + <h4>Projet :</h4> + <div ng-repeat="task in reportedTask"> + {{task.name}} : {{task.time|time}} + <div ng-repeat="subtask in task.subtasks" ng-include="reportNestedTask.html"> + {{subtask.name}} : {{subtask.time|time}} + </div> + + </div> </span> </alert> @@ -86,7 +96,6 @@ - <div class="modal-footer"> <button class="btn btn-primary" ng-click="generateReport()">Générer</button> <button class="btn btn-primary" ng-click="close()">Fermer</button> Added: branches/ng-jtimer/src/main/webapp/partials/reportNestedTask.html =================================================================== --- branches/ng-jtimer/src/main/webapp/partials/reportNestedTask.html (rev 0) +++ branches/ng-jtimer/src/main/webapp/partials/reportNestedTask.html 2014-06-25 16:08:07 UTC (rev 3007) @@ -0,0 +1,5 @@ +<div ng-repeat="task in subtasks"> + {{task.name}} : {{task.time|time}} + <div ng-repeat="subtask in subtasks" ng-include="reportNestedTask.html"></div> + +</div> \ No newline at end of file