Skip to content
This repository has been archived by the owner on Dec 1, 2018. It is now read-only.

Commit

Permalink
projects are now sorted
Browse files Browse the repository at this point in the history
added css for totalTime border top
  • Loading branch information
max-wittig committed Jan 17, 2017
1 parent 1580ba3 commit ba264e2
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 12 deletions.
17 changes: 10 additions & 7 deletions src/com/maxwittig/reportgenerator/builder/HTMLReportBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -84,26 +85,28 @@ class HTMLReportBuilder(timekeeperTasks : ArrayList<TimekeeperTask>, 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<String,Long>, 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)
{
Expand Down
10 changes: 5 additions & 5 deletions src/com/maxwittig/reportgenerator/builder/ReportBuilder.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -151,16 +152,15 @@ abstract class ReportBuilder(private val timekeeperTasks : ArrayList<TimekeeperT
}


fun getProjectTimeHashMap(tasks : ArrayList<TimekeeperTask>) : Map<String, Long>
fun createProjectHolder(tasks : ArrayList<TimekeeperTask>) : ProjectHolder
{
val hashMap = HashMap<String,Long>()
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
Expand Down
6 changes: 6 additions & 0 deletions src/com/maxwittig/reportgenerator/builder/css/reportStyle.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,10 @@ tbody
table
{
width: 100%;
border-collapse:collapse
}

tr.totalTime
{
border-top: 1px solid darkgray;
}
9 changes: 9 additions & 0 deletions src/com/maxwittig/reportgenerator/models/Project.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.maxwittig.reportgenerator.models


class Project(val name: String)
{
var totalTime : Long = 0
get
set
}
37 changes: 37 additions & 0 deletions src/com/maxwittig/reportgenerator/models/ProjectHolder.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.maxwittig.reportgenerator.models

import java.util.*


class ProjectHolder
{
var projects = ArrayList<Project>()
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
}
}

0 comments on commit ba264e2

Please sign in to comment.