Author: obruce Date: 2014-06-20 18:07:12 +0200 (Fri, 20 Jun 2014) New Revision: 3004 Url: http://forge.chorem.org/projects/jtimer/repository/revisions/3004 Log: changement pour le mustache debut properties pour requete du storage Added: branches/ng-jtimer/src/main/resources/jtimer-query.properties 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/utils/Resource/ReportTime.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/resources/subtasks.mustache branches/ng-jtimer/src/main/webapp/js/app.js branches/ng-jtimer/src/main/webapp/partials/reportModal.html branches/ng-jtimer/src/main/webapp/partials/tasks.html Modified: branches/ng-jtimer/src/main/java/org/chorem/jtimer/storage/Storage.java =================================================================== --- branches/ng-jtimer/src/main/java/org/chorem/jtimer/storage/Storage.java 2014-06-19 07:51:49 UTC (rev 3003) +++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/storage/Storage.java 2014-06-20 16:07:12 UTC (rev 3004) @@ -14,7 +14,9 @@ import java.sql.Statement; import java.util.ArrayList; import java.util.Date; +import java.util.HashMap; import java.util.List; +import java.util.Map; /** * Implementation du stockage des taches en base de données basée sur h2. @@ -521,7 +523,8 @@ PreparedStatement statement2 = null; try{ statement = connection.prepareStatement( - "SELECT TA.taskId AS taskid, TA.name AS task, TA.parent AS parent, sum(TI.duration) AS totalduration" + + "SELECT TA.taskId AS taskid, TA.name AS task, TA.parent AS parent," + + " TA.creationDate AS creationDate, sum(TI.duration) AS totalduration" + " FROM " + TABLE_TASK+" TA," + TABLE_TIME +" TI" + " WHERE TA.taskId = TI.taskid" + " AND TA.creationDate >" + startDate + @@ -531,7 +534,8 @@ ResultSet rs = statement.executeQuery(); while(rs.next()){ - list.add(new ReportTask(rs.getString("task"),rs.getString("taskid"), rs.getString("parent") , rs.getLong("totalduration"))); + list.add(new ReportTask(rs.getString("task"),rs.getString("taskid"), + rs.getString("parent") , rs.getLong("totalduration"), rs.getLong("creationDate"))); } // not timed tasks @@ -542,7 +546,8 @@ rs = statement2.executeQuery(); while(rs.next()){ - list.add(new ReportTask(rs.getString("name"), rs.getString("taskId"),rs.getString("parent"), (long) 0)); + list.add(new ReportTask(rs.getString("name"), rs.getString("taskId"), + rs.getString("parent"), (long) 0, rs.getLong("creationDate"))); } }catch(SQLException ex) { @@ -555,7 +560,75 @@ return list; } + public Map getReportByWeek(Long startDate, Long endDate){ + //treemap car date implemente comparable + HashMap<Integer, ArrayList> byWeekTasks = new HashMap<Integer, ArrayList>(); + PreparedStatement statement = null; + PreparedStatement statement2 = null; + + try{ + statement = connection.prepareStatement( + "SELECT WEEK(FROM_UNIXTIME(creationDate)) AS numWeek, TA.taskId AS taskid, TA.name AS task, TA.parent AS parent," + + " TA.creationDate AS creationDate, sum(TI.duration) AS totalduration" + + " FROM " + TABLE_TASK+" TA," + TABLE_TIME +" TI" + + " WHERE TA.taskId = TI.taskid" + + " AND TA.creationDate >" + startDate + + " AND TA.creationDate <" + endDate + + " GROUP BY TA.taskId, numWeek " + + " ORDER BY creationDate DESC"); + + + ResultSet rs = statement.executeQuery(); + while(rs.next()){ + Integer numWeek = rs.getInt("numWeek"); + ArrayList tasks; + if(byWeekTasks.containsKey(numWeek)){ + tasks = byWeekTasks.get(numWeek); + }else{ + tasks = new ArrayList(); + } + tasks.add(new ReportTask(rs.getString("task"),rs.getString("taskid"), + rs.getString("parent") , rs.getLong("totalduration"), rs.getLong("creationDate"))); + + byWeekTasks.put(numWeek, tasks); + } + + // 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()){ + ArrayList tasks; + + if(byWeekTasks.containsKey(0)){ + tasks = byWeekTasks.get(0); + }else{ + tasks = new ArrayList(); + } + tasks.add(new ReportTask(rs.getString("name"), rs.getString("taskId"), + rs.getString("parent"), (long) 0, rs.getLong("creationDate"))); + + byWeekTasks.put(0, tasks); + } + + + }catch(SQLException ex) { + throw new StorageException("Can't get report", ex); + } finally { + closeStatement(statement); + closeStatement(statement2); + } + + log.info("le map " + byWeekTasks.toString()); + + return byWeekTasks; + } + + /** Suppression de tuple **/ /** @@ -624,7 +697,7 @@ /** * Methode qui va va modifier l'attribut removed d'un timertask a l'aide de son identifiant * @param taskId l'identifiant de la tache - * @param time + * @param time le temps ou a lieu la modif */ public void removeTaskWithId(String taskId, long time) { PreparedStatement statement = null; 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-19 07:51:49 UTC (rev 3003) +++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/utils/MustacheReport.java 2014-06-20 16:07:12 UTC (rev 3004) @@ -24,6 +24,7 @@ protected static final Log log = LogFactory.getLog(MustacheReport.class); protected Context context; + protected Storage storage; protected List mustacheList; @@ -33,6 +34,7 @@ */ public MustacheReport(Context context){ this.context = context; + storage = (Storage) context.getAttributes().get(Storage.class.getName()); } /** @@ -41,12 +43,12 @@ */ public String createByProjectMustache(String type, long start, long end) throws IOException { - log.info("create a Mustache "+start + " " +end); + log.info("create a Mustache by project"); 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(); @@ -56,7 +58,17 @@ } - public String createByDayMustache(String type, long startDate, long endDate) { - return null; + public String createByWeekMustache(String type, long start, long end) { + log.info("create a Mustache by week"); + MustacheFactory mf = new DefaultMustacheFactory(); + Mustache mustache = mf.compile("ByWeek_template.mustache"); + + + storage.getReportByWeek(start, end); + + StringWriter sw = new StringWriter(); + //mustache.execute(sw, MustacheHandler.getByWeekReport()); + + return sw.toString(); } } 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-19 07:51:49 UTC (rev 3003) +++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/utils/ReportTask.java 2014-06-20 16:07:12 UTC (rev 3004) @@ -3,6 +3,7 @@ import org.chorem.jtimer.utils.Resource.ReportTime; import java.util.ArrayList; +import java.util.Date; import java.util.List; /** @@ -21,6 +22,8 @@ protected ReportTime time; protected List subtasks; + protected Date creationDate; + /** * Constructeur * @param name le nom @@ -28,7 +31,8 @@ * @param parent l'identifiant du parent * @param time le temps */ - public ReportTask(String name, String taskId, String parent, long time){ + public ReportTask(String name, String taskId, String parent, long time,long date){ + this.creationDate = new Date(date); this.taskId = taskId; this.name = name; this.parent = parent; Modified: branches/ng-jtimer/src/main/java/org/chorem/jtimer/utils/Resource/ReportTime.java =================================================================== --- branches/ng-jtimer/src/main/java/org/chorem/jtimer/utils/Resource/ReportTime.java 2014-06-19 07:51:49 UTC (rev 3003) +++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/utils/Resource/ReportTime.java 2014-06-20 16:07:12 UTC (rev 3004) @@ -1,5 +1,6 @@ package org.chorem.jtimer.utils.Resource; + /** * Created by olivia on 18/06/14. * <p/> @@ -24,6 +25,7 @@ * @param milliseconds time in ms */ public ReportTime(long milliseconds){ + this.ms =milliseconds; changeSecMinHours(); changeSecMinHoursString(); 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-19 07:51:49 UTC (rev 3003) +++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/ReportResource.java 2014-06-20 16:07:12 UTC (rev 3004) @@ -54,6 +54,7 @@ MustacheReport report = new MustacheReport(getContext()); + res = report.createByProjectMustache(type, startDate, endDate); log.info("Ce qui est produit " + res); Modified: branches/ng-jtimer/src/main/resources/jtimer-default.properties =================================================================== --- branches/ng-jtimer/src/main/resources/jtimer-default.properties 2014-06-19 07:51:49 UTC (rev 3003) +++ branches/ng-jtimer/src/main/resources/jtimer-default.properties 2014-06-20 16:07:12 UTC (rev 3004) @@ -2,5 +2,5 @@ # jTimer default properties ### # jTimer storage path -jtimer.storage.path=/tmp/jtimer/jtimer8081 +jtimer.storage.path=/home/olivia/Bureau/jtimer/jtimer8081 Added: branches/ng-jtimer/src/main/resources/jtimer-query.properties =================================================================== --- branches/ng-jtimer/src/main/resources/jtimer-query.properties (rev 0) +++ branches/ng-jtimer/src/main/resources/jtimer-query.properties 2014-06-20 16:07:12 UTC (rev 3004) @@ -0,0 +1,49 @@ +### +# This file contains all sql queries +### +#TABLE +TABLE_TASK=task +TABLE_TIME=tasktime +TABLE_VERSION=version +### +#CREATE SCHEMA +CREATE_TABLE_VERSION=CREATE TABLE version (version VARCHAR(10)) +CREATE_TABLE_TASK=CREATE TABLE task \ + (taskId VARCHAR(255) NOT NULL, \ + name VARCHAR(255) NOT NULL, \ + parent VARCHAR(255), \ + creationDate LONG, \ + modificationDate LONG, \ + hidden BOOLEAN, \ + note TEXT, \ + removed LONG, \ + PRIMARY KEY (taskId)) +CREATE_TABLE_TIME=CREATE TABLE time \ + (taskid VARCHAR(255) NOT NULL, \ + date LONG, \ + uuid varchar(255) unique, \ + duration LONG, \ + modificationDate LONG, \ + removed LONG, \ + PRIMARY KEY (taskid, date, uuid), \ + FOREIGN KEY (taskid) \ + REFERENCES task (taskId) \ + ON DELETE CASCADE) +#### +#INSERT +INSERT_VERSION_NUMBER=INSERT INTO VERSION VALUES('2.0') +INSERT_TASK=INSERT INTO ? (name, parent, taskId, hidden, note,creationDate, modificationDate, removed)" VALUES (?, ?, ?, ?, ?,?, ?, ?) +INSERT_TIME=INSERT INTO ? (taskid, date, uuid, duration, modificationDate, removed) VALUES(?, ?, ?, ?, ?, ?) +### +#SELECT +SELECT_TIMED_TASK="SELECT TA.*, sum(TI.duration) AS totalduration \ + FROM ? TA, ? TI \ + WHERE TA.taskId = TI.taskid \ + AND TA.modificationDate > ? \ + GROUP BY TA.taskId +SELECT_NOTTIMED_TASK=SELECT * \ + FROM ? \ + WHERE (taskId not in (SELECT taskid FROM ?)) \ + AND ?.modificationDate > ? +### +#DELETE \ No newline at end of file Modified: branches/ng-jtimer/src/main/resources/subtasks.mustache =================================================================== --- branches/ng-jtimer/src/main/resources/subtasks.mustache 2014-06-19 07:51:49 UTC (rev 3003) +++ branches/ng-jtimer/src/main/resources/subtasks.mustache 2014-06-20 16:07:12 UTC (rev 3004) @@ -1,6 +1,9 @@ <div style="margin-left:2em;"> {{#subtasks}} - -{{name}} temps : {{time.hh}}:{{time.mm}}:{{time.ss}} + <div style="display : block" > + <div style="min-width : 100px; max-width : 110px; display : inline-block;">-{{name}} :</div> + <div style="min-width : 100px; max-width : 150px; display : inline-block;">{{time.hh}}:{{time.mm}}:{{time.ss}} </div> + </div> {{> subtasks}} {{/subtasks}} </div> \ 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-19 07:51:49 UTC (rev 3003) +++ branches/ng-jtimer/src/main/webapp/js/app.js 2014-06-20 16:07:12 UTC (rev 3004) @@ -373,4 +373,19 @@ }); } } -}]); \ No newline at end of file +}]); + +/*angular.module('webtimer').directive('focusMe', function($timeout) { + return { + link: function($scope, element, attrs) { + $scope.$watch(attrs.focusMe, function(value) { + if(value === true) { + $timeout(function() { + element[0].focus(); + $scope[attrs.focusMe] = true; + }); + } + }); + } + }; +});*/ Modified: branches/ng-jtimer/src/main/webapp/partials/reportModal.html =================================================================== --- branches/ng-jtimer/src/main/webapp/partials/reportModal.html 2014-06-19 07:51:49 UTC (rev 3003) +++ branches/ng-jtimer/src/main/webapp/partials/reportModal.html 2014-06-20 16:07:12 UTC (rev 3004) @@ -1,11 +1,12 @@ <div> - <h2>Option du rapport:</h2> + <h2>Option du rapport :</h2> </div> <hr/> -<div> - <div> +<div > + <!-- Datepicker div --> + <div style="display : inline-block;vertical-align: top;"> De : <div ng-controller="ReportDatePickerCtrl" class="row"> <div class="col-md-6"> @@ -30,27 +31,21 @@ </div> </div> - <p> - - </p> + <div> - <div class="btn-group" ng-show="false"> - <label class="btn btn-primary" ng-change="changeFonc()" ng-model="radioModel" btn-radio="'1'">Jour</label> - <label class="btn btn-primary" ng-change="changeFonc()" ng-model="radioModel" btn-radio="'2'">Semaine</label> - <label class="btn btn-primary" ng-change="changeFonc()" ng-model="radioModel" btn-radio="'3'">Mois</label> - <label class="btn btn-primary" ng-change="changeFonc()" ng-model="radioModel" btn-radio="'4'">Année</label> - <label class="btn btn-primary" ng-change="changeFonc()" ng-model="radioModel" btn-radio="'5'">Projet</label> </div> - <p> - - </p> + + </div> - <div> + <div style="display : inline-block; vertical-align: top; width : 350px"> <alert type="info" > - <div ng-bind-html="toHTML(htmlReport)"></div> + <span> + <div ng-bind-html="toHTML(htmlReport)"></div> + </span> + </alert> </div> Modified: branches/ng-jtimer/src/main/webapp/partials/tasks.html =================================================================== --- branches/ng-jtimer/src/main/webapp/partials/tasks.html 2014-06-19 07:51:49 UTC (rev 3003) +++ branches/ng-jtimer/src/main/webapp/partials/tasks.html 2014-06-20 16:07:12 UTC (rev 3004) @@ -1,8 +1,8 @@ <div id="header"> <!--Header partie gauche --> <span class='left form-inline'> - <input class='search-query form-group form-control input-sm small_input' ng-model="query" placeholder="Search"> - <form ng-submit="addTask()"> + <input class='search-query form-group form-control input-sm small_input' style="display : inline-block;" ng-model="query" placeholder="Search"> + <form style="display : inline-block;" ng-submit="addTask()"> <input class='search-query form-group form-control input-sm small_input' ng-model="name" placeholder="New Task"> </form> @@ -70,7 +70,7 @@ <!--Project name visible and editable --> <form ng-submit="saveTask($node)" ng-show="$node.edit == 'name'"> - <input ng-model="$node.task.name" ng-blur="$node.edit == ''"> + <input ng-model="$node.task.name" ng-blur="$node.edit == ''" > </form> <span ng-click="editTask($node, 'name')" ng-show="$node.edit != 'name'">{{$node.task.name}} </span>