r3002 - in branches/ng-jtimer/src/main: java/org/chorem/jtimer/storage java/org/chorem/jtimer/utils java/org/chorem/jtimer/web resources webapp/js webapp/partials
Author: obruce Date: 2014-06-17 18:02:11 +0200 (Tue, 17 Jun 2014) New Revision: 3002 Url: http://forge.chorem.org/projects/jtimer/repository/revisions/3002 Log: Ajout mustache par projet avec sous tache Added: branches/ng-jtimer/src/main/java/org/chorem/jtimer/utils/MustacheHandler.java Modified: branches/ng-jtimer/src/main/java/org/chorem/jtimer/storage/Storage.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/ByDay_template.mustache branches/ng-jtimer/src/main/resources/ByProject.mustache branches/ng-jtimer/src/main/resources/subtasks.mustache 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/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-16 15:37:22 UTC (rev 3001) +++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/storage/Storage.java 2014-06-17 16:02:11 UTC (rev 3002) @@ -1,6 +1,5 @@ package org.chorem.jtimer.storage; -import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.jtimer.entities.TimerTask; @@ -510,31 +509,40 @@ } public List getReportByProject(Long startDate, Long endDate){ - List list = new ArrayList<ReportTask>(); + + List list = new ArrayList<ReportTask>(); PreparedStatement statement = null; + PreparedStatement statement2 = null; try{ - statement = connection.prepareStatement("SELECT TA.name AS task, TA.parent AS parent, sum(TI.duration) AS totalduration" + - " FROM " + TABLE_TASK+" TA," + TABLE_TIME +" TI" + - " WHERE TA.taskId = TI.taskid" + - " AND TA.modificationDate >" + startDate + - " AND TA.modificationDate <" + endDate + - " GROUP BY TA.taskId"); + statement = connection.prepareStatement( + "SELECT TA.taskId AS taskid, TA.name AS task, TA.parent AS parent, sum(TI.duration) AS totalduration" + + " FROM " + TABLE_TASK+" TA," + TABLE_TIME +" TI" + + " WHERE TA.taskId = TI.taskid" + + " AND TA.modificationDate >" + startDate + + " AND TA.modificationDate <" + endDate + + " GROUP BY TA.taskId"); ResultSet rs = statement.executeQuery(); while(rs.next()){ - log.info("getReport"); - if(StringUtils.isNotBlank(rs.getString("parent"))){ + list.add(new ReportTask(rs.getString("task"),rs.getString("taskid"), rs.getString("parent") , rs.getLong("totalduration"))); + } - }else{ - list.add(new ReportTask(rs.getString("task"), rs.getLong("totalduration"))); - } + // not timed tasks + statement2 = connection.prepareStatement("SELECT * FROM " + TABLE_TASK + + " WHERE (taskId not in (SELECT taskid FROM " + TABLE_TIME + ")" + + " AND parent = '' )" + ); + rs = statement2.executeQuery(); + while(rs.next()){ + list.add(new ReportTask(rs.getString("name"), rs.getString("taskId"),rs.getString("parent"), (long) 0)); } }catch(SQLException ex) { throw new StorageException("Can't get report", ex); } finally { closeStatement(statement); + closeStatement(statement2); } return list; Added: branches/ng-jtimer/src/main/java/org/chorem/jtimer/utils/MustacheHandler.java =================================================================== --- branches/ng-jtimer/src/main/java/org/chorem/jtimer/utils/MustacheHandler.java (rev 0) +++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/utils/MustacheHandler.java 2014-06-17 16:02:11 UTC (rev 3002) @@ -0,0 +1,67 @@ +package org.chorem.jtimer.utils; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; + +/** + * Created by olivia on 17/06/14. + * <p/> + * Project name : jtimer + * <p/> + * Package name : org.chorem.jtimer.utils + */ +public class MustacheHandler { + + protected static final Log log = LogFactory.getLog(MustacheReport.class); + + List<ReportTask> tasks; + + List tasks() { + //On tri les taches avant de les envoyer au template + HashMap<String, ArrayList<ReportTask>> map = new HashMap<String,ArrayList<ReportTask>>(); + + Iterator iter = tasks.iterator(); + while(iter.hasNext()) { + + ReportTask t = (ReportTask)iter.next(); + + //un enfant dans map + if(map.containsKey(t.getTaskId())){ + for(ReportTask task :map.get(t.getTaskId())) + t.addChild(task); + } + + //un enfant + if(!t.getParent().equals("")){ + log.info("enfant"); + //On ajoute l'enfant à la map + ArrayList tmp = new ArrayList(); + + if(map.get(t.parent) != null){ + tmp=map.get(t.parent); + } + tmp.add(t); + + map.put(t.parent, tmp); + iter.remove(); + } + } + + return tasks; + } + + + /** + * Constructeur + * @param mustacheList la liste des taches + */ + public MustacheHandler(List<ReportTask> mustacheList){ + this.tasks = 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-16 15:37:22 UTC (rev 3001) +++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/utils/MustacheReport.java 2014-06-17 16:02:11 UTC (rev 3002) @@ -22,42 +22,41 @@ public class MustacheReport { protected static final Log log = LogFactory.getLog(MustacheReport.class); - //Storage - protected Storage storage; + protected Context context; - //Borne - protected long start; - protected long end; + protected List mustacheList; - List tasks() { - return storage.getReportByProject(start, end); - } /** * Default Constructor * @param context */ - public MustacheReport(Context context, long start, long end){ + public MustacheReport(Context context){ this.context = context; - storage = (Storage)context.getAttributes().get(Storage.class.getName()); - this.start = start; - this.end = end; } /** * Methode qui cree une moustache * @throws IOException */ - public String createMustache() throws IOException { + public String createByProjectMustache(String type, long start, long end) throws IOException { - log.info("create a Mustache"+start + " " +end); + log.info("create a Mustache "+start + " " +end); MustacheFactory mf = new DefaultMustacheFactory(); Mustache mustache = mf.compile("ByProject.mustache"); + //On recupere les taches + Storage storage = (Storage) context.getAttributes().get(Storage.class.getName()); + mustacheList = storage.getReportByProject(start, end); + StringWriter sw = new StringWriter(); - mustache.execute(sw,new MustacheReport(context,start,end)).flush(); + mustache.execute(sw, new MustacheHandler(mustacheList)).flush(); return sw.toString(); } + + public String createByDayMustache(String type, long startDate, long endDate) { + return null; + } } 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-16 15:37:22 UTC (rev 3001) +++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/utils/ReportTask.java 2014-06-17 16:02:11 UTC (rev 3002) @@ -13,15 +13,60 @@ public class ReportTask { /** Le nom de la tache*/ - String name; + protected String name; + protected String taskId; + protected String parent; + protected long time; + protected List subtasks; - long time; - List children; - - public ReportTask(String name, long time){ + /** + * Constructeur + * @param name le nom + * @param taskId l'identifiant + * @param parent l'identifiant du parent + * @param time le temps + */ + public ReportTask(String name, String taskId, String parent, long time){ + this.taskId = taskId; this.name = name; + this.parent = parent; this.time = time; - children = new ArrayList(); + + this.subtasks = new ArrayList(); } + /** Ajout */ + public void addChild(ReportTask t){ + this.subtasks.add(t); + this.time += t.getTime(); + } + + /**Getter */ + + public String getTaskId() { + return taskId; + } + + public String getName() { + return name; + } + + public String getParent() { + return parent; + } + + public long getTime() { + return time; + } + + @Override + public String toString() { + return "ReportTask{" + + "name='" + name + '\'' + + ", taskId='" + taskId + '\'' + + ", parent='" + parent + '\'' + + ", time=" + time + + ", subtasks=" + subtasks + + '}'; + } } 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-16 15:37:22 UTC (rev 3001) +++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/ReportResource.java 2014-06-17 16:02:11 UTC (rev 3002) @@ -30,8 +30,6 @@ @Get public Representation getReport() throws IOException { - log.info("Passage dans get report"); - String type ="BY_PROJECT"; String res=""; long startDate = (long) 0; @@ -39,20 +37,31 @@ try { type = String.valueOf(getQuery().getValues("type")); + } catch (Exception e) { + log.info("type non present dans l'url" + e); + } + try { startDate = Long.valueOf(getQuery().getValues("startDate")); + } catch (Exception e) { + log.info("type non present dans l'url" + e); + } + try { endDate = Long.valueOf(getQuery().getValues("endDate")); } catch (Exception e) { - log.error("Parametre non present dans l'url" + e); + log.info("type non present dans l'url" + e); } - MustacheReport report = new MustacheReport(getContext(), startDate, endDate); + MustacheReport report = new MustacheReport(getContext()); - if(type.equals("BY_PROJECT")){ - res = report.createMustache(); - log.info("Ce qui est produit " + res); - } + res = report.createByProjectMustache(type, startDate, endDate); + log.info("Ce qui est produit " + res); - return new StringRepresentation(res, MediaType.APPLICATION_JSON); + res = report.createByDayMustache(type, startDate, endDate); + log.info("Ce qui est produit " + res); + + + + return new StringRepresentation(res, MediaType.TEXT_JAVASCRIPT); } } \ No newline at end of file Modified: branches/ng-jtimer/src/main/resources/ByDay_template.mustache =================================================================== --- branches/ng-jtimer/src/main/resources/ByDay_template.mustache 2014-06-16 15:37:22 UTC (rev 3001) +++ branches/ng-jtimer/src/main/resources/ByDay_template.mustache 2014-06-17 16:02:11 UTC (rev 3002) @@ -1,8 +1,8 @@ +Rapport +======= + {{#days}} - Day : {{day}} - {{#tasks}} - Name : {{name}} | Time : {{time}} - {{> subtasks}} - {{/tasks}} + Jour : {{day}} + {{>ByProject}} {{/days}} Modified: branches/ng-jtimer/src/main/resources/ByProject.mustache =================================================================== --- branches/ng-jtimer/src/main/resources/ByProject.mustache 2014-06-16 15:37:22 UTC (rev 3001) +++ branches/ng-jtimer/src/main/resources/ByProject.mustache 2014-06-17 16:02:11 UTC (rev 3002) @@ -1,7 +1,13 @@ -Report by project : -=================== +Rapport: +======== +<hr/> {{#tasks}} - -{{name}} temps : {{time}} - {{>subtasks}} -{{/tasks}} \ No newline at end of file +<b>Projet : {{name}}</b> + +{{>subtasks}} + +Temps total : {{time}}|time + +<hr/> +{{/tasks}} Modified: branches/ng-jtimer/src/main/resources/subtasks.mustache =================================================================== --- branches/ng-jtimer/src/main/resources/subtasks.mustache 2014-06-16 15:37:22 UTC (rev 3001) +++ branches/ng-jtimer/src/main/resources/subtasks.mustache 2014-06-17 16:02:11 UTC (rev 3002) @@ -1,4 +1,4 @@ {{#subtasks}} - -{{name}} temps : {{time}} - {{> subtasks}} + -{{name}} temps : {{time}}|time + {{> subtasks}} {{/subtasks}} \ No newline at end of file Modified: branches/ng-jtimer/src/main/webapp/js/app.js =================================================================== --- branches/ng-jtimer/src/main/webapp/js/app.js 2014-06-16 15:37:22 UTC (rev 3001) +++ branches/ng-jtimer/src/main/webapp/js/app.js 2014-06-17 16:02:11 UTC (rev 3002) @@ -306,7 +306,7 @@ /** * Module de webtimer **/ -angular.module('webtimer', ['webtimerFilters', 'ngRoute', 'ngAnimate', 'ui.bootstrap','serverAccessService', 'serverTimeService' ]) +angular.module('webtimer', ['webtimerFilters', 'ngRoute', 'ngAnimate', 'ui.bootstrap','serverAccessService', 'serverTimeService','serverReportService' ]) .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-06-16 15:37:22 UTC (rev 3001) +++ branches/ng-jtimer/src/main/webapp/js/controllers.js 2014-06-17 16:02:11 UTC (rev 3002) @@ -964,7 +964,7 @@ }; } -function ReportModalInstanceCtrl($scope, $modalInstance, times, tasks){ +function ReportModalInstanceCtrl($scope, $modalInstance, times, tasks, serverReportAccess){ $scope.obj={ startDate : new Date(), @@ -973,8 +973,9 @@ }; $scope.radioModel = '5'; + $scope.htmlReport=""; - $scope.generateReport= function(){ + /*$scope.generateReport= function(){ report = []; angular.forEach(times, function(timeArray,task){ @@ -994,6 +995,14 @@ }); + }*/ + + $scope.generateReport= function(){ + serverReportAccess.get({}, function(response){ + console.log(response); + $scope.htmlReport = response; + } + ); } Modified: branches/ng-jtimer/src/main/webapp/js/service.js =================================================================== --- branches/ng-jtimer/src/main/webapp/js/service.js 2014-06-16 15:37:22 UTC (rev 3001) +++ branches/ng-jtimer/src/main/webapp/js/service.js 2014-06-17 16:02:11 UTC (rev 3002) @@ -31,3 +31,14 @@ ); } ); + +angular.module("serverReportService", ["ngResource"]) +.factory("serverReportAccess", function ( $resource) { + // Encapsule l'acces au server + return $resource("/rest/report",{}, + { + get : {method: 'GET', isArray: false}, + } + ); + } +); \ No newline at end of file Modified: branches/ng-jtimer/src/main/webapp/partials/reportModal.html =================================================================== --- branches/ng-jtimer/src/main/webapp/partials/reportModal.html 2014-06-16 15:37:22 UTC (rev 3001) +++ branches/ng-jtimer/src/main/webapp/partials/reportModal.html 2014-06-17 16:02:11 UTC (rev 3002) @@ -50,11 +50,12 @@ <div> <alert type="info" > - Rapport :<br/> + <!--Rapport :<br/> ========= <div ng-repeat="elem in obj.report"> {{elem.task}} : {{elem.time | time}} - </div> + </div>--> + {{htmlReport}} </alert> </div>
participants (1)
-
obruce@users.chorem.org