Author: obruce Date: 2014-06-16 17:37:22 +0200 (Mon, 16 Jun 2014) New Revision: 3001 Url: http://forge.chorem.org/projects/jtimer/repository/revisions/3001 Log: Ajout d'un petit peu de moustache (en cours) pour le rapport Added: branches/ng-jtimer/src/main/java/org/chorem/jtimer/utils/ 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/resources/ByDay_template.mustache branches/ng-jtimer/src/main/resources/ByProject.mustache branches/ng-jtimer/src/main/resources/subtasks.mustache Modified: branches/ng-jtimer/pom.xml branches/ng-jtimer/src/main/java/org/chorem/jtimer/storage/Storage.java branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/ReportResource.java branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/RestApplication.java branches/ng-jtimer/src/main/resources/jtimer-default.properties branches/ng-jtimer/src/main/webapp/js/app.js 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-06-13 15:23:28 UTC (rev 3000) +++ branches/ng-jtimer/pom.xml 2014-06-16 15:37:22 UTC (rev 3001) @@ -161,7 +161,12 @@ </build> <dependencies> - <dependency> + <dependency> + <groupId>com.github.spullara.mustache.java</groupId> + <artifactId>compiler</artifactId> + <version>0.8.15</version> + </dependency> + <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> </dependency> 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-13 15:23:28 UTC (rev 3000) +++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/storage/Storage.java 2014-06-16 15:37:22 UTC (rev 3001) @@ -1,9 +1,11 @@ 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; import org.chorem.jtimer.entities.TimerTime; +import org.chorem.jtimer.utils.ReportTask; import java.sql.Connection; import java.sql.DriverManager; @@ -507,12 +509,11 @@ return times; } - public String getRepportByProject(Long startDate, Long endDate){ - String res = "Rapport\n ========== \n"; - long tot = (long) 0; + public List getReportByProject(Long startDate, Long endDate){ + List list = new ArrayList<ReportTask>(); PreparedStatement statement = null; try{ - statement = connection.prepareStatement("SELECT TA.name AS task, sum(TI.duration) AS totalduration" + + 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 + @@ -521,18 +522,22 @@ ResultSet rs = statement.executeQuery(); while(rs.next()){ - res += rs.getString("task") + " : " +rs.getLong("totalduration") + ", \n"; - tot += rs.getLong("totalduration"); + log.info("getReport"); + if(StringUtils.isNotBlank(rs.getString("parent"))){ + + }else{ + list.add(new ReportTask(rs.getString("task"), rs.getLong("totalduration"))); + } + } - res +="Totale : " + tot; }catch(SQLException ex) { throw new StorageException("Can't get report", ex); } finally { closeStatement(statement); } - return res; + return list; } Added: branches/ng-jtimer/src/main/java/org/chorem/jtimer/utils/MustacheReport.java =================================================================== --- branches/ng-jtimer/src/main/java/org/chorem/jtimer/utils/MustacheReport.java (rev 0) +++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/utils/MustacheReport.java 2014-06-16 15:37:22 UTC (rev 3001) @@ -0,0 +1,63 @@ +package org.chorem.jtimer.utils; + +import com.github.mustachejava.DefaultMustacheFactory; +import com.github.mustachejava.Mustache; +import com.github.mustachejava.MustacheFactory; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.jtimer.storage.Storage; +import org.restlet.Context; + +import java.io.IOException; +import java.io.StringWriter; +import java.util.List; + +/** + * Created by olivia on 16/06/14. + * <p/> + * Project name : jtimer + * <p/> + * Package name : org.chorem.jtimer.utils + */ +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; + + List tasks() { + return storage.getReportByProject(start, end); + } + + /** + * Default Constructor + * @param context + */ + public MustacheReport(Context context, long start, long end){ + 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 { + + log.info("create a Mustache"+start + " " +end); + MustacheFactory mf = new DefaultMustacheFactory(); + Mustache mustache = mf.compile("ByProject.mustache"); + + StringWriter sw = new StringWriter(); + mustache.execute(sw,new MustacheReport(context,start,end)).flush(); + + return sw.toString(); + } + +} Added: branches/ng-jtimer/src/main/java/org/chorem/jtimer/utils/ReportTask.java =================================================================== --- branches/ng-jtimer/src/main/java/org/chorem/jtimer/utils/ReportTask.java (rev 0) +++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/utils/ReportTask.java 2014-06-16 15:37:22 UTC (rev 3001) @@ -0,0 +1,27 @@ +package org.chorem.jtimer.utils; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created by olivia on 16/06/14. + * <p/> + * Project name : jtimer + * <p/> + * Package name : org.chorem.jtimer.utils + */ +public class ReportTask { + + /** Le nom de la tache*/ + String name; + + long time; + List children; + + public ReportTask(String name, long time){ + this.name = name; + this.time = time; + children = new ArrayList(); + } + +} 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-13 15:23:28 UTC (rev 3000) +++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/ReportResource.java 2014-06-16 15:37:22 UTC (rev 3001) @@ -1,8 +1,15 @@ package org.chorem.jtimer.web; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.chorem.jtimer.utils.MustacheReport; +import org.restlet.data.MediaType; import org.restlet.representation.Representation; +import org.restlet.representation.StringRepresentation; import org.restlet.resource.Get; +import java.io.IOException; + /** * Created by olivia on 11/06/14. * <p/> @@ -12,44 +19,40 @@ */ public class ReportResource extends AbstractResource { + protected static final Log log = LogFactory.getLog(ReportResource.class); + /** * Methode qui retourne la representation du rapport * Suite a une requete de type GET * * @return representation du rapport */ - @Get("json") - public Representation getReport() { + @Get + public Representation getReport() throws IOException { - String type =""; + log.info("Passage dans get report"); + String type ="BY_PROJECT"; + String res=""; + long startDate = (long) 0; + long endDate = Long.MAX_VALUE; + try { type = String.valueOf(getQuery().getValues("type")); + startDate = Long.valueOf(getQuery().getValues("startDate")); + endDate = Long.valueOf(getQuery().getValues("endDate")); } catch (Exception e) { - e.printStackTrace(); + log.error("Parametre non present dans l'url" + e); } - switch (type){ - case "BY_DAY": - break; + MustacheReport report = new MustacheReport(getContext(), startDate, endDate); - case "BY_WEEK": - break; - case "BY_MONTH": - break; - - case "BY_YEAR": - break; - - case "BY_PROJECT": - break; - - default: - //By project - break; + if(type.equals("BY_PROJECT")){ + res = report.createMustache(); + log.info("Ce qui est produit " + res); } - return null; + return new StringRepresentation(res, MediaType.APPLICATION_JSON); } } \ 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-06-13 15:23:28 UTC (rev 3000) +++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/RestApplication.java 2014-06-16 15:37:22 UTC (rev 3001) @@ -23,10 +23,11 @@ /** Resource qui va pousser les elements vers d'autres serveurs */ protected TiersServerResource tiers = new TiersServerResource(); + protected static final Log log = LogFactory.getLog(RestApplication.class); /** Determine si la connexion est établie */ //TODO obruce 05/06/2014 to change when configuration available - protected boolean connected = true; + protected boolean connected = false; /**Application configuration */ JtimerConfig jtimerConf; @@ -55,7 +56,7 @@ router.attach("/tasks/task/{taskId}", TaskResource.class); router.attach("/tasks/time/{taskId}", TimeResource.class); router.attach("/tasks/time", TimesResource.class); - router.attach("/tasks/report", ReportResource.class); + router.attach("/report", ReportResource.class); //router.attach("/tiers", TiersServerResource.class); Added: branches/ng-jtimer/src/main/resources/ByDay_template.mustache =================================================================== --- branches/ng-jtimer/src/main/resources/ByDay_template.mustache (rev 0) +++ branches/ng-jtimer/src/main/resources/ByDay_template.mustache 2014-06-16 15:37:22 UTC (rev 3001) @@ -0,0 +1,8 @@ +{{#days}} + Day : {{day}} + {{#tasks}} + Name : {{name}} | Time : {{time}} + {{> subtasks}} + {{/tasks}} +{{/days}} + Added: branches/ng-jtimer/src/main/resources/ByProject.mustache =================================================================== --- branches/ng-jtimer/src/main/resources/ByProject.mustache (rev 0) +++ branches/ng-jtimer/src/main/resources/ByProject.mustache 2014-06-16 15:37:22 UTC (rev 3001) @@ -0,0 +1,7 @@ +Report by project : +=================== + +{{#tasks}} + -{{name}} temps : {{time}} + {{>subtasks}} +{{/tasks}} \ No newline at end of file Modified: branches/ng-jtimer/src/main/resources/jtimer-default.properties =================================================================== --- branches/ng-jtimer/src/main/resources/jtimer-default.properties 2014-06-13 15:23:28 UTC (rev 3000) +++ branches/ng-jtimer/src/main/resources/jtimer-default.properties 2014-06-16 15:37:22 UTC (rev 3001) @@ -2,5 +2,5 @@ # jTimer default properties ### # jTimer storage path -jtimer.storage.path=/home/olivia/Bureau/jtimer/jtimer/jtimer8081 +jtimer.storage.path=/tmp/jtimer/jtimer8081 Added: branches/ng-jtimer/src/main/resources/subtasks.mustache =================================================================== --- branches/ng-jtimer/src/main/resources/subtasks.mustache (rev 0) +++ branches/ng-jtimer/src/main/resources/subtasks.mustache 2014-06-16 15:37:22 UTC (rev 3001) @@ -0,0 +1,4 @@ +{{#subtasks}} + -{{name}} temps : {{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-13 15:23:28 UTC (rev 3000) +++ branches/ng-jtimer/src/main/webapp/js/app.js 2014-06-16 15:37:22 UTC (rev 3001) @@ -258,8 +258,8 @@ service.callback.status(true); }; - ws.onerror = function() { - console.log('Websocket error'); + ws.onerror = function(evt) { + console.log('Websocket error' + evt); }; ws.onclose = function() { Modified: branches/ng-jtimer/src/main/webapp/js/controllers.js =================================================================== --- branches/ng-jtimer/src/main/webapp/js/controllers.js 2014-06-13 15:23:28 UTC (rev 3000) +++ branches/ng-jtimer/src/main/webapp/js/controllers.js 2014-06-16 15:37:22 UTC (rev 3001) @@ -713,6 +713,11 @@ save(); }; + /** Methode qui va tenter d'envoyer la tâche vers le serveur */ + $scope.persistToServ = function(task){ + + }; + /** * Active/desactive le comptage de temps pour une tache * @param {type} task @@ -771,12 +776,6 @@ } }); - - var testWebsocket = function(){ - jTimerWebsocket.send(JSON.stringify($scope.data.tasks)); - console.log("un message est envoyé websocket") - }; - /** Idleness*/ /** @@ -945,11 +944,7 @@ // connect to webscocket server (go client) wtWebsocket.connect(); - jTimerWebsocket.connect(); - testWebsocket(); - - } Modified: branches/ng-jtimer/src/main/webapp/partials/tasks.html =================================================================== --- branches/ng-jtimer/src/main/webapp/partials/tasks.html 2014-06-13 15:23:28 UTC (rev 3000) +++ branches/ng-jtimer/src/main/webapp/partials/tasks.html 2014-06-16 15:37:22 UTC (rev 3001) @@ -90,7 +90,9 @@ ng-show="!$node.task.isRoot() "> <i class="glyphicon glyphicon-pencil" ></i> </a> - + <a class="btn btn-default btn-xs" ng-click="persistToServ($node.task)"> + <i class="glyphicon glyphicon-floppy-disk" ></i> + </a> </span> </div>