From ba264e2e946da58e7a8c441903c98ff74128d4f7 Mon Sep 17 00:00:00 2001 From: max-wittig Date: Tue, 17 Jan 2017 14:04:30 +0100 Subject: [PATCH] projects are now sorted added css for totalTime border top --- .../builder/HTMLReportBuilder.kt | 17 +++++---- .../reportgenerator/builder/ReportBuilder.kt | 10 ++--- .../builder/css/reportStyle.css | 6 +++ .../reportgenerator/models/Project.kt | 9 +++++ .../reportgenerator/models/ProjectHolder.kt | 37 +++++++++++++++++++ 5 files changed, 67 insertions(+), 12 deletions(-) create mode 100644 src/com/maxwittig/reportgenerator/models/Project.kt create mode 100644 src/com/maxwittig/reportgenerator/models/ProjectHolder.kt diff --git a/src/com/maxwittig/reportgenerator/builder/HTMLReportBuilder.kt b/src/com/maxwittig/reportgenerator/builder/HTMLReportBuilder.kt index 2b69b9d..aa5809c 100644 --- a/src/com/maxwittig/reportgenerator/builder/HTMLReportBuilder.kt +++ b/src/com/maxwittig/reportgenerator/builder/HTMLReportBuilder.kt @@ -2,6 +2,7 @@ package com.maxwittig.reportgenerator.builder import com.googlecode.jatl.Html import com.maxwittig.reportgenerator.builder.ReportType +import com.maxwittig.reportgenerator.models.ProjectHolder import com.maxwittig.reportgenerator.models.TimekeeperTask import com.maxwittig.reportgenerator.utils.FileUtils import com.maxwittig.reportgenerator.utils.getTimeStringFromMilliSeconds @@ -84,26 +85,28 @@ class HTMLReportBuilder(timekeeperTasks : ArrayList, val reportT addTaskTable(tasks, body, format) body.br().end() body.h3().text(currentReportType.reportTypeName + " projects") - addProjectTable(body, getProjectTimeHashMap(tasks), currentReportType) + addProjectTable(body, createProjectHolder(tasks), currentReportType) } - private fun addProjectTable(htmlElement: Html, hashMap: Map, currentReportType: ReportType) + private fun addProjectTable(htmlElement: Html, projectHolder : ProjectHolder, currentReportType: ReportType) { val table = htmlElement.table() - addTableHead(table, arrayOf("ProjectName", "TotalTime")) + addTableHead(table, arrayOf("ProjectName", "Time")) val tBody = table.tbody() - for(key in hashMap.keys) + for(project in projectHolder.projects) { val tr = tBody.tr() //add projectname - tr.td().text(key).end() + tr.td().text(project.name).end() //add duration - tr.td().text(getTimeStringFromMilliSeconds(hashMap.get(key)!!*1000)).end() + tr.td().text(getTimeStringFromMilliSeconds(project.totalTime*1000)).end() tr.end() } val todayTimeRow = tBody.tr() - todayTimeRow.td().text("Total Time").end() + todayTimeRow.classAttr("totalTime") + val totalTimeTableData = todayTimeRow.td() + totalTimeTableData.text("Total Time").end() if(currentReportType == ReportType.MONTHLY) { diff --git a/src/com/maxwittig/reportgenerator/builder/ReportBuilder.kt b/src/com/maxwittig/reportgenerator/builder/ReportBuilder.kt index 50088cd..e998839 100644 --- a/src/com/maxwittig/reportgenerator/builder/ReportBuilder.kt +++ b/src/com/maxwittig/reportgenerator/builder/ReportBuilder.kt @@ -1,6 +1,7 @@ package com.maxwittig.reportgenerator.builder import com.maxwittig.reportgenerator.builder.ReportType +import com.maxwittig.reportgenerator.models.ProjectHolder import com.maxwittig.reportgenerator.models.TimekeeperTask import com.maxwittig.reportgenerator.utils.getTimeStringFromMilliSeconds import com.maxwittig.reportgenerator.utils.isSameDay @@ -151,16 +152,15 @@ abstract class ReportBuilder(private val timekeeperTasks : ArrayList) : Map + fun createProjectHolder(tasks : ArrayList) : ProjectHolder { - val hashMap = HashMap() + val projectHolder = ProjectHolder() for(task in tasks) { - hashMap.putIfAbsent(task.projectName, 0) - hashMap.put(task.projectName, hashMap.get(task.projectName)!! + task.duration) + projectHolder.addTime(task) } - return hashMap + return projectHolder } abstract fun getReport() : String diff --git a/src/com/maxwittig/reportgenerator/builder/css/reportStyle.css b/src/com/maxwittig/reportgenerator/builder/css/reportStyle.css index ba11ffd..20ec0d0 100644 --- a/src/com/maxwittig/reportgenerator/builder/css/reportStyle.css +++ b/src/com/maxwittig/reportgenerator/builder/css/reportStyle.css @@ -26,4 +26,10 @@ tbody table { width: 100%; + border-collapse:collapse +} + +tr.totalTime +{ + border-top: 1px solid darkgray; } \ No newline at end of file diff --git a/src/com/maxwittig/reportgenerator/models/Project.kt b/src/com/maxwittig/reportgenerator/models/Project.kt new file mode 100644 index 0000000..4dd5eb2 --- /dev/null +++ b/src/com/maxwittig/reportgenerator/models/Project.kt @@ -0,0 +1,9 @@ +package com.maxwittig.reportgenerator.models + + +class Project(val name: String) +{ + var totalTime : Long = 0 + get + set +} \ No newline at end of file diff --git a/src/com/maxwittig/reportgenerator/models/ProjectHolder.kt b/src/com/maxwittig/reportgenerator/models/ProjectHolder.kt new file mode 100644 index 0000000..c916ad6 --- /dev/null +++ b/src/com/maxwittig/reportgenerator/models/ProjectHolder.kt @@ -0,0 +1,37 @@ +package com.maxwittig.reportgenerator.models + +import java.util.* + + +class ProjectHolder +{ + var projects = ArrayList() + get + + fun addTime(task : TimekeeperTask) + { + val currentProjectName = task.projectName + var currentProject = getProject(currentProjectName) + if(currentProject == null) + { + currentProject = Project(currentProjectName) + projects.add(currentProject) + } + + currentProject.totalTime += task.duration + projects.sort { project1, project2 -> project1.totalTime.compareTo(project2.totalTime) } + } + + private fun getProject(projectName : String) : Project? + { + for(currentProject in projects) + { + if(currentProject.name == projectName) + { + return currentProject + } + } + + return null + } +} \ No newline at end of file