diff -r d8ec2d8ffa82 -r ca5501d851fa src/main/kotlin/de/uapcore/lightpit/viewmodel/Issues.kt --- a/src/main/kotlin/de/uapcore/lightpit/viewmodel/Issues.kt Tue Jan 03 18:25:51 2023 +0100 +++ b/src/main/kotlin/de/uapcore/lightpit/viewmodel/Issues.kt Sun Jan 08 17:07:26 2023 +0100 @@ -31,6 +31,7 @@ import com.vladsch.flexmark.parser.Parser import com.vladsch.flexmark.util.data.MutableDataSet import com.vladsch.flexmark.util.data.SharedDataKeys +import de.uapcore.lightpit.HttpRequest import de.uapcore.lightpit.entities.* import de.uapcore.lightpit.types.* import kotlin.math.roundToInt @@ -111,8 +112,9 @@ val options = MutableDataSet() .set(SharedDataKeys.EXTENSIONS, listOf(TablesExtension.create(), StrikethroughExtension.create())) parser = Parser.builder(options).build() - renderer = HtmlRenderer.builder(options - .set(HtmlRenderer.ESCAPE_HTML, true) + renderer = HtmlRenderer.builder( + options + .set(HtmlRenderer.ESCAPE_HTML, true) ).build() issue.description = formatMarkdown(issue.description ?: "") @@ -164,3 +166,57 @@ } } +class IssueFilter(http: HttpRequest) { + + val issueStatus = IssueStatus.values() + val issueCategory = IssueCategory.values() + val flagIncludeDone = "f.0" + val flagMine = "f.1" + val flagBlocker = "f.2" + + val includeDone: Boolean = evalFlag(http, flagIncludeDone) + val onlyMine: Boolean = evalFlag(http, flagMine) + val onlyBlocker: Boolean = evalFlag(http, flagBlocker) + val status: List = evalEnum(http, "s") + val category: List = evalEnum(http, "c") + + private fun evalFlag(http: HttpRequest, name: String): Boolean { + val param = http.paramArray("filter") + if (param.isNotEmpty()) { + if (param.contains(name)) { + http.session.setAttribute(name, true) + } else { + http.session.removeAttribute(name) + } + } + return http.session.getAttribute(name) != null + } + + private inline fun > evalEnum(http: HttpRequest, prefix: String): List { + val sattr = "f.${prefix}" + val param = http.paramArray("filter") + if (param.isNotEmpty()) { + val list = param.filter { it.startsWith("${prefix}.") } + .map { it.substring(prefix.length + 1) } + .map { + try { + // quick and very dirty validation + enumValueOf(it) + } catch (_: IllegalArgumentException) { + // skip + } + } + if (list.isEmpty()) { + http.session.removeAttribute(sattr) + } else { + http.session.setAttribute(sattr, list.joinToString(",")) + } + } + + return http.session.getAttribute(sattr) + ?.toString() + ?.split(",") + ?.map { enumValueOf(it) } + ?: emptyList() + } +}