1.1 --- a/src/main/kotlin/de/uapcore/lightpit/viewmodel/Issues.kt Tue Jan 03 18:25:51 2023 +0100 1.2 +++ b/src/main/kotlin/de/uapcore/lightpit/viewmodel/Issues.kt Sun Jan 08 17:07:26 2023 +0100 1.3 @@ -31,6 +31,7 @@ 1.4 import com.vladsch.flexmark.parser.Parser 1.5 import com.vladsch.flexmark.util.data.MutableDataSet 1.6 import com.vladsch.flexmark.util.data.SharedDataKeys 1.7 +import de.uapcore.lightpit.HttpRequest 1.8 import de.uapcore.lightpit.entities.* 1.9 import de.uapcore.lightpit.types.* 1.10 import kotlin.math.roundToInt 1.11 @@ -111,8 +112,9 @@ 1.12 val options = MutableDataSet() 1.13 .set(SharedDataKeys.EXTENSIONS, listOf(TablesExtension.create(), StrikethroughExtension.create())) 1.14 parser = Parser.builder(options).build() 1.15 - renderer = HtmlRenderer.builder(options 1.16 - .set(HtmlRenderer.ESCAPE_HTML, true) 1.17 + renderer = HtmlRenderer.builder( 1.18 + options 1.19 + .set(HtmlRenderer.ESCAPE_HTML, true) 1.20 ).build() 1.21 1.22 issue.description = formatMarkdown(issue.description ?: "") 1.23 @@ -164,3 +166,57 @@ 1.24 } 1.25 } 1.26 1.27 +class IssueFilter(http: HttpRequest) { 1.28 + 1.29 + val issueStatus = IssueStatus.values() 1.30 + val issueCategory = IssueCategory.values() 1.31 + val flagIncludeDone = "f.0" 1.32 + val flagMine = "f.1" 1.33 + val flagBlocker = "f.2" 1.34 + 1.35 + val includeDone: Boolean = evalFlag(http, flagIncludeDone) 1.36 + val onlyMine: Boolean = evalFlag(http, flagMine) 1.37 + val onlyBlocker: Boolean = evalFlag(http, flagBlocker) 1.38 + val status: List<IssueStatus> = evalEnum(http, "s") 1.39 + val category: List<IssueCategory> = evalEnum(http, "c") 1.40 + 1.41 + private fun evalFlag(http: HttpRequest, name: String): Boolean { 1.42 + val param = http.paramArray("filter") 1.43 + if (param.isNotEmpty()) { 1.44 + if (param.contains(name)) { 1.45 + http.session.setAttribute(name, true) 1.46 + } else { 1.47 + http.session.removeAttribute(name) 1.48 + } 1.49 + } 1.50 + return http.session.getAttribute(name) != null 1.51 + } 1.52 + 1.53 + private inline fun <reified T : Enum<T>> evalEnum(http: HttpRequest, prefix: String): List<T> { 1.54 + val sattr = "f.${prefix}" 1.55 + val param = http.paramArray("filter") 1.56 + if (param.isNotEmpty()) { 1.57 + val list = param.filter { it.startsWith("${prefix}.") } 1.58 + .map { it.substring(prefix.length + 1) } 1.59 + .map { 1.60 + try { 1.61 + // quick and very dirty validation 1.62 + enumValueOf<T>(it) 1.63 + } catch (_: IllegalArgumentException) { 1.64 + // skip 1.65 + } 1.66 + } 1.67 + if (list.isEmpty()) { 1.68 + http.session.removeAttribute(sattr) 1.69 + } else { 1.70 + http.session.setAttribute(sattr, list.joinToString(",")) 1.71 + } 1.72 + } 1.73 + 1.74 + return http.session.getAttribute(sattr) 1.75 + ?.toString() 1.76 + ?.split(",") 1.77 + ?.map { enumValueOf(it) } 1.78 + ?: emptyList() 1.79 + } 1.80 +}