Tue, 03 Aug 2021 12:22:10 +0200
fixes response locale not set for new sessions
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 */
26 package de.uapcore.lightpit.viewmodel
28 import de.uapcore.lightpit.entities.Component
29 import de.uapcore.lightpit.entities.Project
30 import de.uapcore.lightpit.entities.Version
31 import de.uapcore.lightpit.types.VersionStatus
33 class NavMenuEntry(
34 val level: Int,
35 val caption: String,
36 val href: String,
37 val title: String = "",
38 val active: Boolean = false,
39 val resolveCaption: Boolean = false,
40 val iconColor: String? = null
41 ) {
42 val iconUseCssClass = iconColor != null && !iconColor.startsWith("#")
43 }
45 class NavMenu(val entries: List<NavMenuEntry>)
47 fun projectNavMenu(
48 projects: List<Project>,
49 versions: List<Version> = emptyList(),
50 components: List<Component> = emptyList(),
51 selectedProject: Project? = null,
52 selectedVersion: Version? = null,
53 selectedComponent: Component? = null
54 ) = NavMenu(
55 sequence {
56 val cnode = selectedComponent?.node ?: "-"
57 val vnode = selectedVersion?.node ?: "-"
58 for (project in projects) {
59 val active = project == selectedProject
60 yield(
61 NavMenuEntry(
62 level = 0,
63 caption = project.name,
64 href = "projects/${project.node}",
65 active = active
66 )
67 )
68 if (active) {
69 yield(
70 NavMenuEntry(
71 level = 1,
72 caption = "navmenu.versions",
73 resolveCaption = true,
74 href = "projects/${project.node}/versions/"
75 )
76 )
77 yield(
78 NavMenuEntry(
79 level = 2,
80 caption = "navmenu.all",
81 resolveCaption = true,
82 href = "projects/${project.node}/issues/-/${cnode}/",
83 iconColor = "#000000"
84 )
85 )
86 for (version in versions.filter { it.status != VersionStatus.Deprecated }) {
87 yield(
88 NavMenuEntry(
89 level = 2,
90 caption = version.name,
91 title = "version.status.${version.status}",
92 href = "projects/${project.node}/issues/${version.node}/${cnode}/",
93 iconColor = "version-${version.status}",
94 active = version == selectedVersion
95 )
96 )
97 }
98 yield(
99 NavMenuEntry(
100 level = 1,
101 caption = "navmenu.components",
102 resolveCaption = true,
103 href = "projects/${project.node}/components/"
104 )
105 )
106 yield(
107 NavMenuEntry(
108 level = 2,
109 caption = "navmenu.all",
110 resolveCaption = true,
111 href = "projects/${project.node}/issues/${vnode}/-/",
112 iconColor = "#000000"
113 )
114 )
115 for (component in components) {
116 yield(
117 NavMenuEntry(
118 level = 2,
119 caption = component.name,
120 href = "projects/${project.node}/issues/${vnode}/${component.node}/",
121 iconColor = "${component.color}",
122 active = component == selectedComponent
123 )
124 )
125 }
126 }
127 }
128 }.toList()
129 )