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