r3021 - in branches/ng-jtimer/src/main: java/org/chorem/jtimer/config java/org/chorem/jtimer/storage java/org/chorem/jtimer/web resources webapp/js webapp/partials
Author: obruce Date: 2014-07-28 18:09:16 +0200 (Mon, 28 Jul 2014) New Revision: 3021 Url: http://forge.chorem.org/projects/jtimer/repository/revisions/3021 Log: Report: changement g?\195?\169n?\195?\169ral utilisation du path pour toutes les requetes Modified: branches/ng-jtimer/src/main/java/org/chorem/jtimer/config/JtimerConfig.java branches/ng-jtimer/src/main/java/org/chorem/jtimer/config/JtimerConfigOption.java 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/resources/jtimer-default.properties 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/reportModal.html Modified: branches/ng-jtimer/src/main/java/org/chorem/jtimer/config/JtimerConfig.java =================================================================== --- branches/ng-jtimer/src/main/java/org/chorem/jtimer/config/JtimerConfig.java 2014-07-23 15:46:46 UTC (rev 3020) +++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/config/JtimerConfig.java 2014-07-28 16:09:16 UTC (rev 3021) @@ -142,6 +142,27 @@ public String getStorageQuerySelectRemovedTaskTime(){ return appConfig.getOption(JtimerConfigOption.JTIMER_STORAGE_SELECT_REMOVED_TASKTIME.getKey()); } + /** New Report Function **/ + public String getStorageQuerySelectReportByProject(){ + return appConfig.getOption(JtimerConfigOption.JTIMER_STORAGE_SELECT_REPORT_BYPROJECT.getKey()); + } + + public String getStorageQuerySelectReportByYear(){ + return appConfig.getOption(JtimerConfigOption.JTIMER_STORAGE_SELECT_REPORT_BYYEAR.getKey()); + } + + public String getStorageQuerySelectReportByMonth(){ + return appConfig.getOption(JtimerConfigOption.JTIMER_STORAGE_SELECT_REPORT_BYMONTH.getKey()); + } + + public String getStorageQuerySelectReportByWeek(){ + return appConfig.getOption(JtimerConfigOption.JTIMER_STORAGE_SELECT_REPORT_BYWEEK.getKey()); + } + + public String getStorageQuerySelectReportByDay(){ + return appConfig.getOption(JtimerConfigOption.JTIMER_STORAGE_SELECT_REPORT_BYDAY.getKey()); + } + public String getStorageQuerySelectReportTasks(){ return appConfig.getOption(JtimerConfigOption.JTIMER_STORAGE_SELECT_REPORT_TIMEDTASKS.getKey()); } @@ -151,6 +172,12 @@ public String getStorageQuerySelectReportWeekTimedTasks(){ return appConfig.getOption(JtimerConfigOption.JTIMER_STORAGE_SELECT_REPORT_WEEK_TIMEDTASKS.getKey()); } + public String getStorageQuerySelectReportYearTimedTasks(){ + return appConfig.getOption(JtimerConfigOption.JTIMER_STORAGE_SELECT_REPORT_YEAR_TIMEDTASKS.getKey()); + } + public String getStorageQuerySelectReportMonthTimedTasks(){ + return appConfig.getOption(JtimerConfigOption.JTIMER_STORAGE_SELECT_REPORT_MONTH_TIMEDTASKS.getKey()); + } public String getStorageQuerySelectAlarmOnDate(){ return appConfig.getOption(JtimerConfigOption.JTIMER_STORAGE_SELECT_ALARM_ONDATE.getKey()); } Modified: branches/ng-jtimer/src/main/java/org/chorem/jtimer/config/JtimerConfigOption.java =================================================================== --- branches/ng-jtimer/src/main/java/org/chorem/jtimer/config/JtimerConfigOption.java 2014-07-23 15:46:46 UTC (rev 3020) +++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/config/JtimerConfigOption.java 2014-07-28 16:09:16 UTC (rev 3021) @@ -148,6 +148,36 @@ "", String.class ), + JTIMER_STORAGE_SELECT_REPORT_BYPROJECT( + "jtimer.storage.select.report.byProject", + "requête de selection des taches minutées entre deux bornes filtrer par projet", + "", + String.class + ), + JTIMER_STORAGE_SELECT_REPORT_BYYEAR( + "jtimer.storage.select.report.byYear", + "requête de selection des taches minutées entre deux bornes filtrer par year", + "", + String.class + ), + JTIMER_STORAGE_SELECT_REPORT_BYMONTH( + "jtimer.storage.select.report.byMonth", + "requête de selection des taches minutées entre deux bornes filtrer par month", + "", + String.class + ), + JTIMER_STORAGE_SELECT_REPORT_BYWEEK( + "jtimer.storage.select.report.byWeek", + "requête de selection des taches minutées entre deux bornes filtrer par semaine", + "", + String.class + ), + JTIMER_STORAGE_SELECT_REPORT_BYDAY( + "jtimer.storage.select.report.byDay", + "requête de selection des taches minutées entre deux bornes filtrer par jour", + "", + String.class + ), JTIMER_STORAGE_SELECT_REPORT_TIMEDTASKS( "jtimer.storage.select.report.timedtasks", "requête de selection des taches minutées entre deux bornes", @@ -166,6 +196,18 @@ "", String.class ), + JTIMER_STORAGE_SELECT_REPORT_YEAR_TIMEDTASKS( + "jtimer.storage.select.report.year.timedtasks", + "requête de selection des taches minutees sur une annee", + "", + String.class + ), + JTIMER_STORAGE_SELECT_REPORT_MONTH_TIMEDTASKS( + "jtimer.storage.select.report.month.timedtasks", + "requête de selection des taches minutees sur un mois", + "", + String.class + ), JTIMER_STORAGE_SELECT_ALARM_ONDATE( "jtimer.storage.select.alarm.ondate", "requête de selection des alarmes ", 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-07-23 15:46:46 UTC (rev 3020) +++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/storage/Storage.java 2014-07-28 16:09:16 UTC (rev 3021) @@ -542,22 +542,23 @@ * Methode qui retourne les taches minutees entre deux bornes par projet * @param startDate la borne inferieur * @param endDate la borne superieur - * @return un hashmap {key: parentId, value: array of task} + * @return un hashmap {key: Id, value: task} */ - public HashMap<String, Set<ReportTask>> getReportByProject(Long startDate, Long endDate){ + public HashMap<String, ReportTask> getReportByProject(Long startDate, Long endDate, String[] toReport){ - Set<String> parentSet = new HashSet<String>(); //Set des parents pour eviter les doublons - HashMap map = new HashMap(); + HashMap<String, ReportTask> map = new HashMap(); + PreparedStatement statement = null; - PreparedStatement statement2 = null; + try{ - statement = connection.prepareStatement(config.getStorageQuerySelectReportTasks()); + statement = connection.prepareStatement(config.getStorageQuerySelectReportByProject()); statement.setObject(1, new Date(startDate)); statement.setObject(2, new Date(endDate)); + statement.setObject(3, toReport); ResultSet rs = statement.executeQuery(); - while(rs.next()){ + while(rs.next()) { String name = rs.getString("name"); String taskId = rs.getString("taskId"); @@ -566,98 +567,91 @@ ReportTask task = new ReportTask(name,taskId,parent,totalDuration); - if(!parent.equals("")) { - parentSet.add(rs.getString("parent")); - } + map.put(taskId, task); + } - //Arraylist of reportask for the map - Set tmp = new HashSet(); - if(map.containsKey(rs.getString("parent"))){ - tmp = (HashSet) map.get(rs.getString("parent")); - } - tmp.add(task); + }catch(SQLException ex) { + throw new StorageException("Can't get report", ex); + } finally { + closeStatement(statement); + } - //add key: parentId value : the created reportTask - map.put(rs.getString("parent"), tmp); - } - //Tant que tous les parents n'ont pas ete recupere on boucle - while(!parentSet.isEmpty()) { - //On va chercher les taches parent - statement2 = connection.prepareStatement(config.getStorageQuerySelectParentTask()); - statement2.setObject(1, parentSet.toArray(new String[parentSet.size()])); + return map; + } - //On vide le parentSet avant de verifier si les taches parentes ont des parents - parentSet.clear(); + /** + * Methode qui retourne les taches minutees entre deux bornes par jour + * @param startDate borne inferieur + * @param endDate la borne superieur + * @return un hashmap {key: parentId, value: array of task} + */ + public HashMap<String,Set<ReportTask>> getReportByDay(Long startDate, Long endDate, String[] toReport){ + HashMap<String,Set<ReportTask>> res = new HashMap<>(); + PreparedStatement statement = null; - //On execute la requete - rs = statement2.executeQuery(); + try{ + statement = connection.prepareStatement(config.getStorageQuerySelectReportByDay()); + // les bornes + statement.setObject(1, new Date(startDate)); + statement.setObject(2, new Date(endDate)); + statement.setObject(3, toReport); - while (rs.next()) { + ResultSet rs = statement.executeQuery(); + while(rs.next()) { - String name = rs.getString("name"); - String taskId = rs.getString("taskId"); - String parent=rs.getString("parent"); - long totalDuration = (long) 0; + String period = rs.getString("day")+" - " +rs.getString("month") +" - "+ rs.getString("year"); - ReportTask task = new ReportTask(name,taskId,parent,totalDuration); + //Si le Year n'est pas présent + if(res.get(period)==null) { + res.put(period, new HashSet<ReportTask>()); + } - //On ajoute le parent de la tache au set - if(!parent.equals("")) { - parentSet.add(rs.getString("parent")); - } + String name = rs.getString("name"); + String taskId = rs.getString("taskId"); + String parent=rs.getString("parent"); + long totalDuration = rs.getLong("totalduration"); - Set tmp = new HashSet(); - if (map.containsKey(rs.getString("parent"))) { - tmp = (HashSet) map.get(rs.getString("parent")); - } - tmp.add(task); - map.put(rs.getString("parent"), tmp); + ReportTask task = new ReportTask(name,taskId,parent,totalDuration); - } + //On ajoute le resultat: year, set de reportTask + res.get(period).add(task); } }catch(SQLException ex) { throw new StorageException("Can't get report", ex); } finally { closeStatement(statement); - closeStatement(statement2); } - return map; + return res; } - /** * Methode qui retourne les taches minutees entre deux bornes par semaine * @param startDate borne inferieur * @param endDate la borne superieur * @return un hashmap {key: parentId, value: array of task} */ - public HashMap<Integer,HashMap<String, Set<ReportTask>>> getReportByWeek(Long startDate, Long endDate){ + public HashMap<String,Set<ReportTask>> getReportByWeek(Long startDate, Long endDate, String[] toReport){ + HashMap<String,Set<ReportTask>> res = new HashMap<>(); + PreparedStatement statement = null; - //Le resultat sous forme string parent, array de reportTask - HashMap<Integer,HashMap<String, Set<ReportTask>>> res = new HashMap<>(); - - HashMap<Integer, Set<String>> parentWeekHash = new HashMap<>(); - - PreparedStatement statement = null; - PreparedStatement statement2 = null; try{ - //Les taches minutees sur les differentes semaines - statement = connection.prepareStatement(config.getStorageQuerySelectReportWeekTimedTasks()); - + statement = connection.prepareStatement(config.getStorageQuerySelectReportByWeek()); + // les bornes statement.setObject(1, new Date(startDate)); statement.setObject(2, new Date(endDate)); + statement.setObject(3, toReport); ResultSet rs = statement.executeQuery(); - while(rs.next()) { - int week = rs.getInt("week"); - //Si la week n'est pas présent - if(res.get(week)==null) { - res.put(week, new HashMap<String, Set<ReportTask>>()); + String period = rs.getString("week") +" - "+ rs.getString("year"); + + //Si le Year n'est pas présent + if(res.get(period)==null) { + res.put(period, new HashSet<ReportTask>()); } String name = rs.getString("name"); @@ -667,83 +661,105 @@ ReportTask task = new ReportTask(name,taskId,parent,totalDuration); - //On ajoute les elements au set du resultat - Set tmp; - if(res.containsKey(week) && res.get(week).containsKey(parent)){ - tmp = (Set)res.get(week).get(parent); - }else{ - tmp=new HashSet<>(); - } - tmp.add(task); + //On ajoute le resultat: year, set de reportTask + res.get(period).add(task); + } - //On ajoute le resultat: week, set de reportTask - res.get(week).put(parent, tmp); + }catch(SQLException ex) { + throw new StorageException("Can't get report", ex); + } finally { + closeStatement(statement); + } - //On ajoute le parent pour le week au set de parent - Set tmp2; - if (parentWeekHash.containsKey(week)) { - tmp2 = (Set)parentWeekHash.get(week); - }else{ - tmp2=new HashSet<>(); + return res; + } + + public HashMap<String,Set<ReportTask>> getReportByMonth(Long startDate, Long endDate, String[] toReport){ + + HashMap<String,Set<ReportTask>> res = new HashMap<>(); + PreparedStatement statement = null; + + try{ + statement = connection.prepareStatement(config.getStorageQuerySelectReportByMonth()); + // les bornes + statement.setObject(1, new Date(startDate)); + statement.setObject(2, new Date(endDate)); + statement.setObject(3, toReport); + + ResultSet rs = statement.executeQuery(); + while(rs.next()) { + + String period = rs.getString("month") +" - "+ rs.getString("year"); + + //Si le Year n'est pas présent + if(res.get(period)==null) { + res.put(period, new HashSet<ReportTask>()); } - tmp2.add(parent); - parentWeekHash.put(week,tmp2); + String name = rs.getString("name"); + String taskId = rs.getString("taskId"); + String parent=rs.getString("parent"); + long totalDuration = rs.getLong("totalduration"); + ReportTask task = new ReportTask(name,taskId,parent,totalDuration); + + //On ajoute le resultat: year, set de reportTask + res.get(period).add(task); } - Set<Integer> keySet = parentWeekHash.keySet(); - // not timed tasks - for(Integer key : keySet){ + }catch(SQLException ex) { + throw new StorageException("Can't get report", ex); + } finally { + closeStatement(statement); + } - //Tant que tous les parents n'ont pas ete recupere on boucle - while(!parentWeekHash.get(key).isEmpty()) { - //On va chercher les taches parent - statement2 = connection.prepareStatement(config.getStorageQuerySelectParentTask()); - statement2.setObject(1, parentWeekHash.get(key).toArray(new String[parentWeekHash.get(key).size()])); + return res; + } - //On vide le parentSet avant de verifier si les taches parentes ont des parents - parentWeekHash.get(key).clear(); + /** + * Method that returns the collection of timed tasks + * @param startDate the start date + * @param endDate the end date + * @param toReport task to be reported + * @return the collection of timed tasks + */ + public HashMap<String,Set<ReportTask>> getReportByYear(Long startDate, Long endDate, String[] toReport){ - //On execute la requete - rs = statement2.executeQuery(); + HashMap<String,Set<ReportTask>> res = new HashMap<>(); + PreparedStatement statement = null; - while (rs.next()) { + try{ + statement = connection.prepareStatement(config.getStorageQuerySelectReportByYear()); + // les bornes + statement.setObject(1, new Date(startDate)); + statement.setObject(2, new Date(endDate)); + statement.setObject(3, toReport); - String name = rs.getString("name"); - String taskId = rs.getString("taskId"); - String parent=rs.getString("parent"); - long totalDuration = (long) 0; + ResultSet rs = statement.executeQuery(); + while(rs.next()) { - ReportTask task = new ReportTask(name,taskId,parent,totalDuration); + String year = rs.getString("year"); - //On ajoute le parent de la tache au set - if(!parent.equals("")) { - parentWeekHash.get(key).add(rs.getString("parent")); - } + //Si le Year n'est pas présent + if(res.get(year)==null) { + res.put(year, new HashSet<ReportTask>()); + } - //On ajoute les elements au set du resultat - Set tmp; - if (res.get(key).containsKey(parent)) { - tmp = (Set)res.get(key).get(parent); - }else{ - tmp=new HashSet<>(); - } - tmp.add(task); + String name = rs.getString("name"); + String taskId = rs.getString("taskId"); + String parent=rs.getString("parent"); + long totalDuration = rs.getLong("totalduration"); - //On ajoute le resultat: week, set de reportTask - res.get(key).put(parent, tmp); + ReportTask task = new ReportTask(name,taskId,parent,totalDuration); - } - } + //On ajoute le resultat: year, set de reportTask + res.get(year).add(task); } - }catch(SQLException ex) { throw new StorageException("Can't get report", ex); } finally { closeStatement(statement); - closeStatement(statement2); } return res; 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-07-23 15:46:46 UTC (rev 3020) +++ branches/ng-jtimer/src/main/java/org/chorem/jtimer/web/ReportResource.java 2014-07-28 16:09:16 UTC (rev 3021) @@ -6,7 +6,6 @@ import org.apache.commons.logging.LogFactory; 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.Post; @@ -44,84 +43,72 @@ */ @Post("json") public Representation getReport(Representation representation) throws IOException { - ArrayList toReport = new ArrayList(); + // Les elements voulus par l'interface + String[] toReport; - if(representation.isAvailable()) { - String repr1 = representation.getText(); - Gson gson = new Gson(); - toReport = gson.fromJson(repr1, ArrayList.class); - } + String repr1 = representation.getText(); + Gson gson = new Gson(); + toReport = gson.fromJson(repr1, String[].class); - String json="[]"; + + String json="[No data]"; String type =""; - long startDate = (long) 0; - long endDate = Long.MAX_VALUE; + long startDate; + long endDate; try { type = String.valueOf(getQuery().getValues("type")); log.info("type " +type); } catch (Exception e) { log.info("Rapport : type non present dans l'url" + e); + } try { startDate = Long.valueOf(getQuery().getValues("start_Date")); log.info("start" +startDate); } catch (Exception e) { log.info("Rapport : startDate non present dans l'url" + e); + startDate = (long) 0; } try { endDate = Long.valueOf(getQuery().getValues("end_Date")); log.info("end" +endDate); } catch (Exception e) { log.info("Rapport : endDate non present dans l'url" + e); + endDate = Long.MAX_VALUE; } //On ne recupere que les elements interessants - Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create(); + gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create(); if(type.equals("Project")) { - HashMap<String, Set<ReportTask>> storedTask = storage.getReportByProject(startDate, endDate); - ArrayList<ReportTask> res = new ArrayList<>(); //l'arraylist de resultat + HashMap<String, ReportTask> storedTask = storage.getReportByProject(startDate, endDate,toReport); + json = gson.toJson(storedTask, HashMap.class); - if(!storedTask.isEmpty()) { - //On parcours le map récupérer de la base pour recéer l'arbre - for (ReportTask rt : storedTask.get("")) { - recursivSortTask(storedTask, rt, res); - } + }else if(type.equals("Day")){ - //On enleve les éléments non voulus - recursiveRemoveUnreportedTask(res, toReport); + HashMap storedTask = storage.getReportByDay(startDate, endDate, toReport); + json = gson.toJson(storedTask, HashMap.class); - } + }else if(type.equals("Month")){ - json = gson.toJson(res, ArrayList.class); + HashMap storedTask = storage.getReportByMonth(startDate, endDate, toReport); + json = gson.toJson(storedTask, HashMap.class); - } + }else if(type.equals("Week")){ - if(type.equals("Week")) { - HashMap<Integer, HashMap<String, Set<ReportTask>>> storedTask = storage.getReportByWeek(startDate, endDate); - HashMap<Integer, ArrayList<ReportTask>> res = new HashMap<>(); + HashMap storedTask = storage.getReportByWeek(startDate, endDate, toReport); + json = gson.toJson(storedTask, HashMap.class); - Iterator iter = storedTask.keySet().iterator(); - while (iter.hasNext()) { - Integer key = (Integer) iter.next(); + }else if(type.equals("Year")){ - ArrayList<ReportTask> tmp = new ArrayList<>(); + HashMap storedTask = storage.getReportByYear(startDate, endDate,toReport); + json = gson.toJson(storedTask, HashMap.class); - for (ReportTask rt : storedTask.get(key).get("")) { - recursivSortTask(storedTask.get(key), rt, tmp); - } - recursiveRemoveUnreportedTask(tmp, (ArrayList<String>) toReport.clone()); - - res.put(key, tmp); - } - - - json = gson.toJson(res, HashMap.class); } - return new StringRepresentation(json, MediaType.TEXT_HTML); + return new StringRepresentation(json); } /** Modified: branches/ng-jtimer/src/main/resources/jtimer-default.properties =================================================================== --- branches/ng-jtimer/src/main/resources/jtimer-default.properties 2014-07-23 15:46:46 UTC (rev 3020) +++ branches/ng-jtimer/src/main/resources/jtimer-default.properties 2014-07-28 16:09:16 UTC (rev 3021) @@ -2,7 +2,7 @@ # jTimer default properties ### # jTimer storage path -jtimer.storage.path=/home/olivia/Bureau/jtimer/jtimer/BDDNewDepart +jtimer.storage.path=/home/olivia/Bureau/jtimer/jtimer/BDDNNe ### # SQL properties ### @@ -96,16 +96,76 @@ AND TI.creationDate BETWEEN ? AND ? \ AND TA.removed = 0 \ GROUP BY TA.taskId +jtimer.storage.select.report.rootTask=SELECT TA.* AS totalduration \ + FROM task TA \ + WHERE TA.taskId = TI.taskid \ + AND TI.creationDate BETWEEN ? AND ? \ + AND ARRAY_LENGTH(TA.path) = 1 \ + AND TA.removed = 0 \ + GROUP BY TA.taskId +jtimer.storage.select.report.byProject=SELECT TA.*, sum(TI.duration) AS totalduration \ + FROM task TA, tasktime TI \ + WHERE TA.taskId = TI.taskid \ + AND TI.creationDate BETWEEN ? AND ? \ + AND ARRAY_CONTAINS(?, TA.taskid) \ + AND TA.removed = 0 \ + GROUP BY TA.taskId +jtimer.storage.select.report.byYear=SELECT YEAR(TI.creationDate) as year, TA.*, sum(TI.duration) AS totalduration \ + FROM task TA, tasktime TI \ + WHERE TA.taskId = TI.taskid \ + AND TI.creationDate BETWEEN ? AND ? \ + AND ARRAY_CONTAINS(TA.path, TA.taskid) \ + AND ARRAY_CONTAINS(?, TA.taskid) \ + AND TA.removed = 0 \ + GROUP BY TA.taskId , year +jtimer.storage.select.report.byMonth=SELECT MONTH(TI.creationDate) as month, YEAR(TI.creationDate) as year, TA.*, sum(TI.duration) AS totalduration \ + FROM task TA, tasktime TI \ + WHERE TA.taskId = TI.taskid \ + AND TI.creationDate BETWEEN ? AND ? \ + AND ARRAY_CONTAINS(TA.path, TA.taskid) \ + AND ARRAY_CONTAINS(?, TA.taskid) \ + AND TA.removed = 0 \ + GROUP BY TA.taskId , month, year +jtimer.storage.select.report.byWeek=SELECT WEEK(TI.creationDate) as week,YEAR(TI.creationDate) as year, TA.*, sum(TI.duration) AS totalduration \ + FROM task TA, tasktime TI \ + WHERE TA.taskId = TI.taskid \ + AND TI.creationDate BETWEEN ? AND ? \ + AND ARRAY_CONTAINS(TA.path, TA.taskid) \ + AND ARRAY_CONTAINS(?, TA.taskid) \ + AND TA.removed = 0 \ + GROUP BY TA.taskId , week, year +jtimer.storage.select.report.byDay=SELECT EXTRACT(DAY FROM TI.creationDate) as day,MONTH(TI.creationDate) as month,YEAR(TI.creationDate) as year, TA.*, sum(TI.duration) AS totalduration \ + FROM task TA, tasktime TI \ + WHERE TA.taskId = TI.taskid \ + AND TI.creationDate BETWEEN ? AND ? \ + AND ARRAY_CONTAINS(TA.path, TA.taskid) \ + AND ARRAY_CONTAINS(?, TA.taskid) \ + AND TA.removed = 0 \ + GROUP BY TA.taskId , day, month, year jtimer.storage.select.report.roottasks=SELECT * \ FROM task \ WHERE (taskId not in (SELECT taskid FROM tasktime) AND removed = 0 ) -jtimer.storage.select.report.week.timedtasks=SELECT WEEK(TI.creationDate) as week, TA.* , sum(TI.duration) AS totalduration \ +jtimer.storage.select.report.week.timedtasks=SELECT WEEK(TI.creationDate) as week, YEAR(TI.creationDate) as year, TA.* , sum(TI.duration) AS totalduration \ FROM task TA, tasktime TI \ WHERE TA.taskId = TI.taskid \ AND TI.creationDate BETWEEN ? AND ? \ AND TA.removed = 0 \ - GROUP BY TA.taskId, week \ + GROUP BY TA.taskId, week, year \ ORDER BY TA.creationDate DESC +jtimer.storage.select.report.year.timedtasks=SELECT YEAR(TI.creationDate) as year, TA.* , sum(TI.duration) AS totalduration \ + FROM task TA, tasktime TI \ + WHERE TA.taskId = TI.taskid \ + AND TI.creationDate BETWEEN ? AND ? \ + AND TA.removed = 0 \ + GROUP BY TA.taskId, year \ + ORDER BY TA.creationDate DESC +jtimer.storage.select.report.month.timedtasks=SELECT MONTH(TI.creationDate) as month, YEAR(TI.creationDate) as year, TA.* , sum(TI.duration) AS totalduration \ + FROM task TA, tasktime TI \ + WHERE TA.taskId = TI.taskid \ + AND TI.creationDate BETWEEN ? AND ? \ + AND TA.removed = 0 \ + GROUP BY TA.taskId, year, month \ + ORDER BY TA.creationDate DESC jtimer.storage.select.alarm.ondate= SELECT * \ FROM taskalarm \ WHERE modificationDate > ? Modified: branches/ng-jtimer/src/main/webapp/js/controllers.js =================================================================== --- branches/ng-jtimer/src/main/webapp/js/controllers.js 2014-07-23 15:46:46 UTC (rev 3020) +++ branches/ng-jtimer/src/main/webapp/js/controllers.js 2014-07-28 16:09:16 UTC (rev 3021) @@ -1268,10 +1268,13 @@ }; } - +/** + * Controller of the report modal instance + * + */ function ReportModalInstanceCtrl($scope, $modalInstance,$http, $sce, serverReportAccess, tree){ - $scope.modal={radioModel: "Project", showTime : true}; + $scope.modal={radioModel: "Year", showTime : true}; $scope.tree = tree; @@ -1281,18 +1284,22 @@ function getMonday(date) { d = date; var day = d.getDay(), - diff = d.getDate() - day + (day == 0 ? -6:1); // adjust when day is sunday + diff = d.getDate() - day + (day == 0 ? -6:1); return new Date(d.setDate(diff)); } - - + /** object to keep date */ $scope.obj={ startDate : getMonday(new Date()), endDate : new Date() }; + /** + * Returns the previous week of the datepicker date + * @return the previous week + */ $scope.previousWeek = function(){ + var beforeOneWeek = new Date($scope.obj.startDate.getTime() - 60 * 60 * 24 * 7 * 1000); day = beforeOneWeek.getDay(); diffToMonday = beforeOneWeek.getDate() - day + (day === 0 ? -6 : 1); @@ -1300,14 +1307,28 @@ // Updating scope date $scope.obj.startDate = new Date(beforeOneWeek.setDate(diffToMonday)); $scope.obj.endDate = new Date(beforeOneWeek.setDate(diffToMonday + 6)); + + $scope.generateReport(); }; - $scope.currentWeek= function(){ + /** + * Returns the current week of the datepicker date + * @return the current week + */ + $scope.currentWeek= function() + { $scope.obj.startDate = getMonday(new Date()); $scope.obj.endDate = new Date(); + + $scope.generateReport(); }; - $scope.nextWeek= function(){ + /** + * Returns the next week of the datepicker date + * @return the next week + */ + $scope.nextWeek= function() + { var afterOneWeek = new Date($scope.obj.startDate.getTime() + 60 * 60 * 24 * 7 * 1000); day = afterOneWeek.getDay(); diffToMonday = afterOneWeek.getDate() - day + (day === 0 ? -6 : 1); @@ -1316,16 +1337,50 @@ $scope.obj.startDate = new Date(afterOneWeek.setDate(diffToMonday)); $scope.obj.endDate = new Date(afterOneWeek.setDate(diffToMonday + 6)); + $scope.generateReport(); + }; $scope.obj.endDate.setHours(23,59,59,999); - $scope.htmlReport="Générer un rapport"; + $scope.htmlReport="Générer un rapport"; - $scope.toHTML = function (data) { - return $sce.trustAsHtml(data); - } + /** + * Method that returns the total time for a task + */ + $scope.getTotalProjectTime = function(node, res){ + angular.forEach(node.children, function(child){ + + //if there is time on the child we add it, else we try to look on the child's child + if($scope.taskData[child.task.taskId]){ + res+= $scope.taskData[child.task.taskId].selftime; + }else{ + res+= $scope.getTotalProjectTime(child,0); + } + }); + + return res; + }; + + /** + * Method that returns the total time for a task + */ + $scope.getTotalPeriodTime = function(node, res, period){ + + angular.forEach(node.children, function(child){ + + //if there is time on the child we add it, else we try to look on the child's child + if($scope.taskData[period][child.task.taskId]){ + res+= $scope.taskData[period][child.task.taskId]; + }else{ + res+= $scope.getTotalPeriodTime(child,0, period); + } + }); + + return res; + }; + /** * Methode de generation du rapport * @@ -1346,6 +1401,7 @@ var recurseGenerateChildReport = function(child){ + // On parcours les data pour maj angular.forEach(child.children, function(childnode){recurseGenerateChildReport(childnode)}); if(child.task.isReported){ toReportTask.push(child.task.taskId); @@ -1359,40 +1415,43 @@ .success(function(data){ if($scope.modal.radioModel=='Project'){ + $scope.taskData = data; + }else{ - $scope.htmlReport = data; - $scope.reportedTask=[]; - angular.forEach(data, function(d){ - $scope.reportedTask.push({ - name : d.name, - selftime : d.selftime, - childtime : d.childtime, - subtasks : d.subtasks}); - }); - console.log($scope.reportedTask); - } + console.log(data); + $scope.taskData={}; - if($scope.modal.radioModel=='Week'){ - $scope.htmlReport = data; - //on l'envoi dans l'interface - angular.forEach(data, function(array,week){ + angular.forEach(data, function(array,period){ + if( $scope.modal.radioModel=='Month'){ + var monthArray= ["", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]; - angular.forEach(array, function(rt){ - if(!$scope.reportWeek[week]){$scope.reportWeek[week]=[];} - $scope.reportWeek[week].push({ - name : rt.name, - selftime : rt.selftime, - childtime : rt.childtime, - subtasks : rt.subtasks}); + //period format : "m - yyyy" + var tmp = monthArray[parseInt(period[0])] + " - " +period[4]+period[5]+period[6]+period[7]; + + period=tmp; + } + if( $scope.modal.radioModel=='Day'){ + var monthArray= ["", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]; + + //period format : "j - m - yyyy" + var tmp = period.split(" "); + period = tmp[0] +" "+ monthArray[parseInt(tmp[2])] +" " +tmp[4]; + } + + $scope.taskData[period]={}; + angular.forEach(array, function(task){ + $scope.taskData[period][task.taskId]=task.selftime; }); - }); - console.log($scope.reportWeek); } } ); + + $scope.isGenerated=true; } + //On force la premiere synchro + $scope.generateReport(); /** * Methode qui check les box du parent jusqu'aux enfants @@ -1411,17 +1470,23 @@ angular.forEach(node.children, function(child){ recurseReportChild(child) }); + + $scope.generateReport(); } /**Check all checkbox*/ $scope.checkAll= function(){ recurseChildEncapsulated(tree, true); + $scope.generateReport(); + }; /**Uncheck all checkbox*/ $scope.uncheckAll= function(){ recurseChildEncapsulated(tree,false); + + $scope.generateReport(); }; /** Modified: branches/ng-jtimer/src/main/webapp/js/entities.js =================================================================== --- branches/ng-jtimer/src/main/webapp/js/entities.js 2014-07-23 15:46:46 UTC (rev 3020) +++ branches/ng-jtimer/src/main/webapp/js/entities.js 2014-07-28 16:09:16 UTC (rev 3021) @@ -2,7 +2,8 @@ * Genere un UUID * @returns {String} */ -function generateUUID(){ +function generateUUID() +{ var d = Date.now(); var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { var r = (d + Math.random()*16)%16 | 0; @@ -16,7 +17,8 @@ * Retourne la date d'aujourd'hui sous la forme "2013-O7-25" * @returns {String} */ -function today() { +function today() +{ var result = moment().format("YYYY-MM-DD"); return result; } @@ -28,16 +30,21 @@ * @param {ngAnimator} animate l'objet permettant de supprimer un noeud dans le DOM * @returns {Cache} */ -var Cache = function(animate) { +var Cache = function(animate) +{ this.animate = animate; }; -Cache.prototype.put = function(node, element, scope) { + +Cache.prototype.put = function(node, element, scope) +{ var id = node.task.taskId; this[id] = {node: node, element: element, scope: scope}; }; -Cache.prototype.get = function(nodeOrId) { + +Cache.prototype.get = function(nodeOrId) +{ var id = nodeOrId; - if (!angular.isString(nodeOrId)) { + if (!angular.isString(nodeOrId)){ id = nodeOrId.task.taskId; } var result = this[id]; @@ -45,13 +52,18 @@ return result; }; -Cache.prototype.clear = function() { - for (var key in this) { - if (this.hasOwnProperty(key) && key !== "animate") { +Cache.prototype.clear = function() +{ + for (var key in this){ + + if (this.hasOwnProperty(key) && key !== "animate"){ + var entry = this[key]; this.animate.leave(entry.element); entry.scope.$destroy(); + } + } }; @@ -59,7 +71,8 @@ * Toutes les donnees qui demandent d'etre traitees par le serveur * @returns {tdListData} */ -var tdListData = function(){ +var tdListData = function() +{ //Les timestamp de dernier acces this.lastTimeAccess = 0; this.lastTaskAccess = 0; @@ -81,7 +94,8 @@ * Converti l'objet tdListData en Json * @returns {JSON} */ -tdListData.prototype.toJson = function() { +tdListData.prototype.toJson = function() +{ var result = angular.toJson(this); return result; }; @@ -261,24 +275,29 @@ return task; } - /** * Ce retire de l'arbre * @returns {undefined} */ -TreeNode.prototype.remove = function() { +TreeNode.prototype.remove = function() +{ if (this.parent) { + var brothers = this.parent.children; var match = brothers.indexOf(this); if (match > -1 ) { + brothers.splice(match, 1); delete this.parent; + } + } }; -TreeNode.prototype.addChild = function(node) { +TreeNode.prototype.addChild = function(node) +{ node.parent = this; this.children.push(node); }; @@ -288,7 +307,8 @@ * @param {TreeNode} node * @returns {undefined} */ -TreeNode.prototype.copyState = function(node) { +TreeNode.prototype.copyState = function(node) +{ this.$$open = node.$$open; }; @@ -298,7 +318,7 @@ * @param {Array of TaskTime} taskTimes * @returns {undefined} */ -TreeNode.prototype.setTaskTimes = function(taskTimes) { +TreeNode.prototype.setTaskTimes = function(taskTimes){ this.localTimes = taskTimes; }; @@ -386,7 +406,8 @@ */ var Task = function (name,taskId, parentTaskId) { - if(taskId == undefined){ + if(taskId == undefined) + { this.taskId =generateUUID(); }else{ this.taskId = taskId; @@ -395,7 +416,8 @@ this.modificationDate = Date.now(); this.removed = 0; - if(parentTaskId == undefined){ + if(parentTaskId == undefined) + { this.parent = ""; }else{ this.parent = parentTaskId; Modified: branches/ng-jtimer/src/main/webapp/partials/reportModal.html =================================================================== --- branches/ng-jtimer/src/main/webapp/partials/reportModal.html 2014-07-23 15:46:46 UTC (rev 3020) +++ branches/ng-jtimer/src/main/webapp/partials/reportModal.html 2014-07-28 16:09:16 UTC (rev 3021) @@ -13,7 +13,7 @@ <div style="margin-left:2px;" ng-controller="ReportDatePickerCtrl" class="row"> <div class="col-md-6"> <p class="input-group medium_input"> - <input type="text" class="form-control" datepicker-popup="{{format}}" ng-model="obj.startDate" is-open="opened" min-date="minDate" max-date="obj.endDate" ng-required="true" close-text="Close" /> + <input type="text" class="form-control" datepicker-popup="{{format}}" ng-model="obj.startDate" ng-change="generateReport()" is-open="opened" min-date="minDate" max-date="obj.endDate" ng-required="true" close-text="Close" /> <span class="input-group-btn"> <button type="button" class="btn btn-default" ng-click="open($event)"><i class="glyphicon glyphicon-calendar"></i></button> </span> @@ -25,7 +25,7 @@ <div style="margin-left:1px;margin-right:1px;" class="row" ng-controller="ReportDatePickerCtrl"> <div class="col-md-6"> <p class="input-group medium_input"> - <input type="text" class="form-control" datepicker-popup="{{format}}" ng-model="obj.endDate" is-open="opened" min-date="obj.startDate" max-date="maxDate" ng-required="true" close-text="Close" /> + <input type="text" class="form-control" datepicker-popup="{{format}}" ng-model="obj.endDate" ng-change="generateReport()" is-open="opened" min-date="obj.startDate" max-date="maxDate" ng-required="true" close-text="Close" /> <span class="input-group-btn"> <button type="button" class="btn btn-default" ng-click="open($event)"><i class="glyphicon glyphicon-calendar"></i></button> </span> @@ -48,15 +48,15 @@ <h4>Group by :</h4> <div style="margin-left:25px;" > <div class="btn-group"> - <label class="btn btn-default" ng-model="modal.radioModel" btn-radio="'Project'">Project</label> - <label class="btn btn-default" ng-model="modal.radioModel" disabled="true" btn-radio="'Day'">Day</label> - <label class="btn btn-default" ng-model="modal.radioModel" btn-radio="'Week'">Week</label> + <label class="btn btn-default" ng-model="modal.radioModel" ng-change="generateReport()" btn-radio="'Project'">Project</label> + <label class="btn btn-default" ng-model="modal.radioModel" ng-change="generateReport()" btn-radio="'Day'">Day</label> + <label class="btn btn-default" ng-model="modal.radioModel" ng-change="generateReport()" btn-radio="'Week'">Week</label> </div> <br/> <div style="margin-left:30px;" class="btn-group"> - <label class="btn btn-default" ng-model="modal.radioModel" disabled="true" btn-radio="'Month'">Month</label> - <label class="btn btn-default" ng-model="modal.radioModel" disabled="true" btn-radio="'Year'">Year</label> + <label class="btn btn-default" ng-model="modal.radioModel" ng-change="generateReport()" btn-radio="'Month'">Month</label> + <label class="btn btn-default" ng-model="modal.radioModel" ng-change="generateReport()" btn-radio="'Year'">Year</label> </div> </div> @@ -76,13 +76,11 @@ <!-- Div du body wt-tree-repeat Angular js directive in app.js--> <div class="tbody" - wt-tree-repeat="tree | orderBy:'task.name'" - wt-force-open="query || forceExpanded"> + wt-tree-repeat="tree | orderBy:'task.name'"> <div class="tr" ng-class="{'current-row' : ($node.task === currentTask), 'selected-row' : ($node.task === selectedTask)}"> - <!--ng-click="setSelectedTask($node.task)" - ng-keydown="keyPressed($event)">ng-dblclick="timeTask($node.task)"--> + <div class="td"> <span class="spacer level{{$level}}"></span> @@ -91,7 +89,7 @@ <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 --> + <!--Project name--> <input type="checkbox" ng-model="$node.task.isReported" ng-change="setChildrenCheckbox($node)"> <span>{{$node.task.name}} </span> @@ -111,52 +109,87 @@ <div style="display : inline-block; vertical-align: top; width : 350px"> <alert type="info" > - <span contenteditable="true" ng-show="!reportTask.length" > - <h4><b>Generate Report :</b></h4> + <span contenteditable="true" ng-if="isGenerated" > + <h4><b>Report :</b></h4> - <!--Report by Project --> <div ng-if="modal.radioModel=='Project'"> - <div ng-repeat="task in reportedTask" > - <b>Project : {{task.name}} </b> - <div style="margin-left : 10px" ng-repeat="subtask in task.subtasks" ng-include="'./partials/reportNestedTask.html'"> + <div> + <div class='table'> + <div class="tbody" + wt-tree-repeat="tree | orderBy:'task.name'" + wt-force-open="true"> + + <div ng-if="$node.task.isRoot()"> + + <br/> + </div> + + <div class="tr" ng-show="taskData[$node.task.taskId].selftime || ($node.task.isRoot() && getTotalProjectTime($node,0) != 0 )"> + + <div class="td" > + <span class="spacer level{{$level}}"></span> + <b ng-if="$node.task.isRoot()">Projet : {{$node.task.name}}</b> + <span ng-if="!$node.task.isRoot()">{{$node.task.name}} </span> + </div > + + <div class="td" ng-show="!$node.task.isRoot() && taskData[$node.task.taskId].selftime && modal.showTime" > + <span class="spacer level{{$level}}"></span> + <span>{{taskData[$node.task.taskId].selftime |time }} </span> + + </div> + + <div class="td" ng-show="$node.task.isRoot()" > + <span class="spacer level{{$level}}"></span> + <b> Total : {{getTotalProjectTime($node,0) |time }} </b> + + </div> + </div> + </div> </div> - <br/> - Temps total : {{task.childtime|time}} - <hr/> </div> - - <span ng-show="reportedTask.length == 0" > - No timed tasks. - </span> </div> + <!--Report by week/year/month/day --> + <div ng-if="modal.radioModel=='Week' || modal.radioModel=='Year' || modal.radioModel=='Month'|| modal.radioModel=='Day'"> - <!--Report by week --> - <div ng-if="modal.radioModel=='Week'"> - <div ng-repeat="(week,array) in reportWeek" > - <b> - Week {{week}} </b><br/> - ========== - <br/><br/> + <div ng-repeat="(period, tasks) in taskData"> + <b> {{modal.radioModel}} : {{period}} </b> + <div class='table'> - <div style="margin-left : 10px" ng-repeat="(index, task) in array" > - <b>Project : {{task.name}} </b> - <div style="margin-left : 10px" ng-repeat="subtask in task.subtasks" ng-include="'./partials/reportNestedTask.html'"> + <div class="tbody" + wt-tree-repeat="tree | orderBy:'task.name'" + wt-force-open="true"> + <div class="tr" ng-show="taskData[period][$node.task.taskId] || ($node.task.isRoot() && getTotalPeriodTime($node,0, period) != 0 ) "> + + <div class="td" > + <span class="spacer level{{$level}}"></span> + <b ng-if="$node.task.isRoot()">Projet : {{$node.task.name}}</b> + <span ng-if="!$node.task.isRoot()">{{$node.task.name}} </span> + </div > + + <div class="td" ng-show="!$node.task.isRoot() && taskData[period][$node.task.taskId] && modal.showTime" > + <span class="spacer level{{$level}}"></span> + <span>{{tasks[$node.task.taskId] |time }} </span> + + </div> + + <div class="td" ng-show="$node.task.isRoot()" > + <span class="spacer level{{$level}}"></span> + <b> Total : {{getTotalPeriodTime($node,0,period) |time }} </b> + + </div> + </div> </div> - <br/> - Temps total : {{task.childtime|time}} - <hr/> </div> </div> - - <span ng-show="!reportWeek" > - No timed tasks. - </span> </div> </span > + <span ng-if="!taskData"> + No timed task. + </span> </alert> </div>
participants (1)
-
obruce@users.chorem.org