diff --git a/data/config_example.json b/data/config_example.json index 1616e90..6e09a80 100644 --- a/data/config_example.json +++ b/data/config_example.json @@ -3,5 +3,8 @@ "toAddress":"max@example.com", "password":"Testing123", "smtpHost": "smtp.example.com", - "port":500 + "port":500, + "dailyReport": true, + "weeklyReport": false, + "monthlyReport": true } \ No newline at end of file diff --git a/src/com/maxwittig/reportgenerator/ReportType.kt b/src/com/maxwittig/reportgenerator/ReportType.kt index 0b62b16..8c7f914 100644 --- a/src/com/maxwittig/reportgenerator/ReportType.kt +++ b/src/com/maxwittig/reportgenerator/ReportType.kt @@ -17,7 +17,7 @@ enum class ReportType { return MONTHLY } - + else if(weeklyEnabled && isLastDayOfTheWeek()) { return WEEKLY diff --git a/src/com/maxwittig/reportgenerator/builder/HTMLReportBuilder.kt b/src/com/maxwittig/reportgenerator/builder/HTMLReportBuilder.kt index 6b2d0d3..cb8e1a7 100644 --- a/src/com/maxwittig/reportgenerator/builder/HTMLReportBuilder.kt +++ b/src/com/maxwittig/reportgenerator/builder/HTMLReportBuilder.kt @@ -3,8 +3,8 @@ package com.maxwittig.reportgenerator.builder import com.googlecode.jatl.Html import com.maxwittig.reportgenerator.ReportType import com.maxwittig.reportgenerator.models.TimekeeperTask -import com.maxwittig.reportgenerator.utils.getTimeStringFromSeconds -import java.io.File +import com.maxwittig.reportgenerator.utils.FileUtils +import com.maxwittig.reportgenerator.utils.getTimeStringFromMilliSeconds import java.io.StringWriter import java.text.SimpleDateFormat import java.util.* @@ -23,7 +23,6 @@ class HTMLReportBuilder(timekeeperTasks : ArrayList,val reportTy if(reportType == ReportType.MONTHLY && monthlyTasks.isNotEmpty()) { body.h1().text("Your " + reportType.toString().toLowerCase() + " report").end() - body.h3().text("Your 10 longest tasks this month").end() addMonthlyHTML(body) } else @@ -33,8 +32,11 @@ class HTMLReportBuilder(timekeeperTasks : ArrayList,val reportTy addWeeklyHTML(body) } - body.br().end() - body.hr().end() + if(reportType != ReportType.DAILY) + { + body.br().end() + body.hr().end() + } if(todayTasks.isNotEmpty()) { @@ -51,12 +53,14 @@ class HTMLReportBuilder(timekeeperTasks : ArrayList,val reportTy private fun addHead() { val head = html.head() - head.style().type("text/css").text(File("src/com/maxwittig/reportgenerator/builder/css/reportStyle.css").readText()).end() + val css = FileUtils.getFileContentFromJar("/com/maxwittig/reportgenerator/builder/css/reportStyle.css") + head.style().type("text/css").text(css).end() head.end() } private fun addMonthlyHTML(body : Html) { + body.h3().text("Your 10 longest tasks this month").end() val format = SimpleDateFormat("dd.MM.yyyy - HH:mm:ss") addTaskTable(monthlyTasks, body, format) body.br() @@ -71,8 +75,10 @@ class HTMLReportBuilder(timekeeperTasks : ArrayList,val reportTy private fun addTodayHTML(body : Html) { val format = SimpleDateFormat("dd.MM.yyyy - HH:mm:ss") + body.h3().text("Daily Tasks") addTaskTable(todayTasks, body, format) body.br().end() + body.h3().text("Daily Projects") addProjectTable(body, getDailyProjectTimeHashMap()) } @@ -87,7 +93,7 @@ class HTMLReportBuilder(timekeeperTasks : ArrayList,val reportTy //add projectname tr.td().text(key).end() //add duration - tr.td().text(getTimeStringFromSeconds(hashMap.get(key)!!)).end() + tr.td().text(getTimeStringFromMilliSeconds(hashMap.get(key)!!*1000)).end() tr.end() } @@ -135,7 +141,7 @@ class HTMLReportBuilder(timekeeperTasks : ArrayList,val reportTy val row = tBody.tr() row.td().text(format.format(task.startTime)).end() row.td().text(format.format(task.endTime)).end() - row.td().text(getTimeStringFromSeconds(task.duration)).end() + row.td().text(getTimeStringFromMilliSeconds(task.duration*1000)).end() row.td().text(task.projectName).end() row.td().text(task.taskName).end() row.end() diff --git a/src/com/maxwittig/reportgenerator/builder/ReportBuilder.kt b/src/com/maxwittig/reportgenerator/builder/ReportBuilder.kt index 4ea3a47..ff6ecac 100644 --- a/src/com/maxwittig/reportgenerator/builder/ReportBuilder.kt +++ b/src/com/maxwittig/reportgenerator/builder/ReportBuilder.kt @@ -2,7 +2,7 @@ package com.maxwittig.reportgenerator.builder import com.maxwittig.reportgenerator.ReportType import com.maxwittig.reportgenerator.models.TimekeeperTask -import com.maxwittig.reportgenerator.utils.getTimeStringFromSeconds +import com.maxwittig.reportgenerator.utils.getTimeStringFromMilliSeconds import com.maxwittig.reportgenerator.utils.isSameDay import com.maxwittig.reportgenerator.utils.isSameMonth import com.maxwittig.reportgenerator.utils.isSameWeek @@ -93,7 +93,7 @@ abstract class ReportBuilder(private val timekeeperTasks : ArrayList diff --git a/src/com/maxwittig/reportgenerator/tests/HTMLReportBuilderTest.kt b/src/com/maxwittig/reportgenerator/tests/HTMLReportBuilderTest.kt index 6347d77..03bacc5 100644 --- a/src/com/maxwittig/reportgenerator/tests/HTMLReportBuilderTest.kt +++ b/src/com/maxwittig/reportgenerator/tests/HTMLReportBuilderTest.kt @@ -48,6 +48,15 @@ class HTMLReportBuilderTest File("data/testResults/monthly.html").writeText(reportBuilder.getReport()) } + @Test + fun dailyReportTest() + { + val taskList = getRandomTimekeeperTaskArrayList() + val now = getRandomDateInTheYear() + val reportBuilder = HTMLReportBuilder(taskList, ReportType.DAILY, todaysDate = now) + File("data/testResults/daily.html").writeText(reportBuilder.getReport()) + } + private fun getRandomWordFromList() : String { return wordList[Random().nextInt(wordList.size)] diff --git a/src/com/maxwittig/reportgenerator/utils/DateUtils.kt b/src/com/maxwittig/reportgenerator/utils/DateUtils.kt index 1ff5deb..68029ca 100644 --- a/src/com/maxwittig/reportgenerator/utils/DateUtils.kt +++ b/src/com/maxwittig/reportgenerator/utils/DateUtils.kt @@ -37,7 +37,7 @@ fun isLastDayOfTheWeek() : Boolean return now.dayOfWeek.value == 7 } -fun getTimeStringFromSeconds(totalTime : Long) : String +fun getTimeStringFromMilliSeconds(totalTime : Long) : String { val hms = String.format("%02d:%02d:%02d", TimeUnit.MILLISECONDS.toHours(totalTime), TimeUnit.MILLISECONDS.toMinutes(totalTime) % TimeUnit.HOURS.toMinutes(1), diff --git a/src/com/maxwittig/reportgenerator/utils/FileUtils.kt b/src/com/maxwittig/reportgenerator/utils/FileUtils.kt new file mode 100644 index 0000000..dfbfc77 --- /dev/null +++ b/src/com/maxwittig/reportgenerator/utils/FileUtils.kt @@ -0,0 +1,30 @@ +package com.maxwittig.reportgenerator.utils + +import java.io.BufferedInputStream +import java.io.BufferedReader +import java.io.InputStreamReader + + +class FileUtils +{ + + companion object + { + fun getFileContentFromJar(path: String): String? + { + val inputStream = FileUtils::class.java.getResourceAsStream(path) + val bufferedInputStream = BufferedInputStream(inputStream) + val bufferedReader = BufferedReader(InputStreamReader(bufferedInputStream)) + var line: String? = "" + val text = StringBuilder() + + while (line != null) + { + line = bufferedReader.readLine() + if (line != null) + text.append(line) + } + return text.toString() + } + } +} \ No newline at end of file