Tue, 03 Aug 2021 12:22:10 +0200
fixes response locale not set for new sessions
universe@184 | 1 | /* |
universe@184 | 2 | * Copyright 2021 Mike Becker. All rights reserved. |
universe@184 | 3 | * |
universe@184 | 4 | * Redistribution and use in source and binary forms, with or without |
universe@184 | 5 | * modification, are permitted provided that the following conditions are met: |
universe@184 | 6 | * |
universe@184 | 7 | * 1. Redistributions of source code must retain the above copyright |
universe@184 | 8 | * notice, this list of conditions and the following disclaimer. |
universe@184 | 9 | * |
universe@184 | 10 | * 2. Redistributions in binary form must reproduce the above copyright |
universe@184 | 11 | * notice, this list of conditions and the following disclaimer in the |
universe@184 | 12 | * documentation and/or other materials provided with the distribution. |
universe@184 | 13 | * |
universe@184 | 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
universe@184 | 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
universe@184 | 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
universe@184 | 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
universe@184 | 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
universe@184 | 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
universe@184 | 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
universe@184 | 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
universe@184 | 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
universe@184 | 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
universe@184 | 24 | */ |
universe@184 | 25 | |
universe@184 | 26 | package de.uapcore.lightpit.viewmodel |
universe@184 | 27 | |
universe@184 | 28 | import com.vladsch.flexmark.ext.gfm.strikethrough.StrikethroughExtension |
universe@184 | 29 | import com.vladsch.flexmark.ext.tables.TablesExtension |
universe@184 | 30 | import com.vladsch.flexmark.html.HtmlRenderer |
universe@184 | 31 | import com.vladsch.flexmark.parser.Parser |
universe@184 | 32 | import com.vladsch.flexmark.util.data.MutableDataSet |
universe@184 | 33 | import de.uapcore.lightpit.entities.* |
universe@184 | 34 | import de.uapcore.lightpit.types.IssueCategory |
universe@184 | 35 | import de.uapcore.lightpit.types.IssueStatus |
universe@184 | 36 | import de.uapcore.lightpit.types.IssueStatusPhase |
universe@184 | 37 | import de.uapcore.lightpit.types.VersionStatus |
universe@184 | 38 | import kotlin.math.roundToInt |
universe@184 | 39 | |
universe@184 | 40 | class IssueSummary { |
universe@184 | 41 | var open = 0 |
universe@184 | 42 | var active = 0 |
universe@184 | 43 | var done = 0 |
universe@184 | 44 | |
universe@184 | 45 | val total get() = open + active + done |
universe@184 | 46 | |
universe@184 | 47 | val openPercent get() = 100 - activePercent - donePercent |
universe@184 | 48 | val activePercent get() = if (total > 0) (100f * active / total).roundToInt() else 0 |
universe@184 | 49 | val donePercent get() = if (total > 0) (100f * done / total).roundToInt() else 100 |
universe@184 | 50 | |
universe@184 | 51 | /** |
universe@184 | 52 | * Adds the specified issue to the summary by incrementing the respective counter. |
universe@184 | 53 | * @param issue the issue |
universe@184 | 54 | */ |
universe@184 | 55 | fun add(issue: Issue) { |
universe@184 | 56 | when (issue.status.phase) { |
universe@184 | 57 | IssueStatusPhase.Open -> open++ |
universe@184 | 58 | IssueStatusPhase.WorkInProgress -> active++ |
universe@184 | 59 | IssueStatusPhase.Done -> done++ |
universe@184 | 60 | } |
universe@184 | 61 | } |
universe@184 | 62 | } |
universe@184 | 63 | |
universe@184 | 64 | class IssueDetailView( |
universe@184 | 65 | val issue: Issue, |
universe@184 | 66 | val comments: List<IssueComment>, |
universe@184 | 67 | val project: Project, |
universe@184 | 68 | val version: Version? = null, |
universe@184 | 69 | val component: Component? = null |
universe@184 | 70 | ) : View() { |
universe@184 | 71 | |
universe@184 | 72 | init { |
universe@184 | 73 | val options = MutableDataSet() |
universe@184 | 74 | .set(Parser.EXTENSIONS, listOf(TablesExtension.create(), StrikethroughExtension.create())) |
universe@184 | 75 | val parser = Parser.builder(options).build() |
universe@184 | 76 | val renderer = HtmlRenderer.builder(options).build() |
universe@184 | 77 | val process = fun(it: String) = renderer.render(parser.parse(it)) |
universe@184 | 78 | |
universe@186 | 79 | issue.description = process(issue.description?:"") |
universe@184 | 80 | for (comment in comments) { |
universe@207 | 81 | comment.commentFormatted = process(comment.comment) |
universe@184 | 82 | } |
universe@184 | 83 | } |
universe@184 | 84 | } |
universe@184 | 85 | |
universe@184 | 86 | class IssueEditView( |
universe@184 | 87 | val issue: Issue, |
universe@184 | 88 | val versions: List<Version>, |
universe@184 | 89 | val components: List<Component>, |
universe@184 | 90 | val users: List<User>, |
universe@184 | 91 | val project: Project, // TODO: allow null values to create issues from the IssuesServlet |
universe@184 | 92 | val version: Version? = null, |
universe@184 | 93 | val component: Component? = null |
universe@184 | 94 | ) : EditView() { |
universe@184 | 95 | |
universe@184 | 96 | val versionsUpcoming: List<Version> |
universe@184 | 97 | val versionsRecent: List<Version> |
universe@184 | 98 | |
universe@184 | 99 | val issueStatus = IssueStatus.values() |
universe@184 | 100 | val issueCategory = IssueCategory.values() |
universe@184 | 101 | |
universe@184 | 102 | init { |
universe@184 | 103 | val recent = mutableListOf<Version>() |
universe@184 | 104 | val upcoming = mutableListOf<Version>() |
universe@184 | 105 | recent.addAll(issue.affectedVersions) |
universe@184 | 106 | upcoming.addAll(issue.resolvedVersions) |
universe@184 | 107 | for (v in versions) { |
universe@184 | 108 | if (v.status.isReleased) { |
universe@184 | 109 | if (v.status != VersionStatus.Deprecated) recent.add(v) |
universe@184 | 110 | } else { |
universe@184 | 111 | upcoming.add(v) |
universe@184 | 112 | } |
universe@184 | 113 | } |
universe@186 | 114 | versionsRecent = recent.distinct() |
universe@186 | 115 | versionsUpcoming = upcoming.distinct() |
universe@184 | 116 | } |
universe@184 | 117 | } |
universe@184 | 118 |