1.1 --- a/src/main/kotlin/de/uapcore/lightpit/servlet/FeedServlet.kt Sat Oct 09 20:05:39 2021 +0200 1.2 +++ b/src/main/kotlin/de/uapcore/lightpit/servlet/FeedServlet.kt Sun Oct 10 14:46:10 2021 +0200 1.3 @@ -25,6 +25,8 @@ 1.4 1.5 package de.uapcore.lightpit.servlet 1.6 1.7 +import com.github.difflib.text.DiffRow 1.8 +import com.github.difflib.text.DiffRowGenerator 1.9 import de.uapcore.lightpit.AbstractServlet 1.10 import de.uapcore.lightpit.HttpRequest 1.11 import de.uapcore.lightpit.dao.DataAccessObject 1.12 @@ -36,6 +38,7 @@ 1.13 import java.text.SimpleDateFormat 1.14 import javax.servlet.annotation.WebServlet 1.15 1.16 + 1.17 @WebServlet(urlPatterns = ["/feed/*"]) 1.18 class FeedServlet : AbstractServlet() { 1.19 1.20 @@ -43,8 +46,6 @@ 1.21 get("/%project/issues.rss", this::issues) 1.22 } 1.23 1.24 - private fun String.convertLF() = replace("\r", "").replace("\n", "<br>") 1.25 - 1.26 private fun fullContent(issue: IssueHistoryData) = IssueDiff( 1.27 issue.id, 1.28 issue.subject, 1.29 @@ -52,7 +53,7 @@ 1.30 issue.status.name, 1.31 issue.category.name, 1.32 issue.subject, 1.33 - issue.description.convertLF(), 1.34 + issue.description.replace("\r", ""), 1.35 issue.assignee, 1.36 issue.eta?.let { SimpleDateFormat("dd.MM.yyyy").format(it) } ?: "", 1.37 issue.affected, 1.38 @@ -60,9 +61,38 @@ 1.39 ) 1.40 1.41 private fun diffContent(cur: IssueHistoryData, next: IssueHistoryData): IssueDiff { 1.42 + val generator = DiffRowGenerator.create() 1.43 + .showInlineDiffs(true) 1.44 + .mergeOriginalRevised(true) 1.45 + .inlineDiffByWord(true) 1.46 + .oldTag { start -> if (start) "<strike style=\"color:red\">" else "</strike>" } 1.47 + .newTag { start -> if (start) "<i style=\"color: green\">" else "</i>" } 1.48 + .build() 1.49 + 1.50 val prev = fullContent(next) 1.51 val diff = fullContent(cur) 1.52 - // TODO: compute and apply diff 1.53 + 1.54 + val result = generator.generateDiffRows( 1.55 + listOf(prev.subject, prev.component, prev.status, 1.56 + prev.category, prev.assignee, prev.eta, prev.affected, prev.resolved), 1.57 + listOf(diff.subject, diff.component, diff.status, 1.58 + diff.category, diff.assignee, diff.eta, diff.affected, diff.resolved) 1.59 + ) 1.60 + 1.61 + diff.subject = result[0].oldLine 1.62 + diff.component = result[1].oldLine 1.63 + diff.status = result[2].oldLine 1.64 + diff.category = result[3].oldLine 1.65 + diff.assignee = result[4].oldLine 1.66 + diff.eta = result[5].oldLine 1.67 + diff.affected = result[6].oldLine 1.68 + diff.resolved = result[7].oldLine 1.69 + 1.70 + diff.description = generator.generateDiffRows( 1.71 + prev.description.split('\n'), 1.72 + diff.description.split('\n') 1.73 + ).joinToString("<br>", transform = DiffRow::getOldLine) 1.74 + 1.75 return diff 1.76 } 1.77