23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 */ |
24 */ |
25 |
25 |
26 package de.uapcore.lightpit.viewmodel |
26 package de.uapcore.lightpit.viewmodel |
27 |
27 |
|
28 import de.uapcore.lightpit.OptionalPathInfo |
28 import de.uapcore.lightpit.entities.Component |
29 import de.uapcore.lightpit.entities.Component |
29 import de.uapcore.lightpit.entities.Project |
30 import de.uapcore.lightpit.entities.Project |
30 import de.uapcore.lightpit.entities.Version |
31 import de.uapcore.lightpit.entities.Version |
31 import de.uapcore.lightpit.types.VersionStatus |
32 import de.uapcore.lightpit.types.VersionStatus |
32 |
33 |
42 val iconUseCssClass = iconColor != null && !iconColor.startsWith("#") |
43 val iconUseCssClass = iconColor != null && !iconColor.startsWith("#") |
43 } |
44 } |
44 |
45 |
45 class NavMenu(val entries: List<NavMenuEntry>) |
46 class NavMenu(val entries: List<NavMenuEntry>) |
46 |
47 |
47 fun projectNavMenu( |
48 fun projectNavMenu(projects: List<Project>) = NavMenu( |
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 { |
49 sequence { |
56 val cnode = selectedComponent?.node ?: "-" |
|
57 val vnode = selectedVersion?.node ?: "-" |
|
58 for (project in projects) { |
50 for (project in projects) { |
59 val active = project == selectedProject |
51 yield( |
|
52 NavMenuEntry( |
|
53 level = 0, |
|
54 caption = project.name, |
|
55 href = "projects/${project.node}", |
|
56 ) |
|
57 ) |
|
58 } |
|
59 }.toList() |
|
60 ) |
|
61 |
|
62 fun projectNavMenu(projects: List<Project>, pathInfos: PathInfos) = NavMenu( |
|
63 sequence { |
|
64 val cnode = pathInfos.componentInfo.node |
|
65 val vnode = pathInfos.versionInfo.node |
|
66 for (project in projects) { |
|
67 val active = project == pathInfos.projectInfo.project |
60 yield( |
68 yield( |
61 NavMenuEntry( |
69 NavMenuEntry( |
62 level = 0, |
70 level = 0, |
63 caption = project.name, |
71 caption = project.name, |
64 href = "projects/${project.node}", |
72 href = "projects/${project.node}", |
78 NavMenuEntry( |
86 NavMenuEntry( |
79 level = 2, |
87 level = 2, |
80 caption = "navmenu.all", |
88 caption = "navmenu.all", |
81 resolveCaption = true, |
89 resolveCaption = true, |
82 href = "projects/${project.node}/issues/-/${cnode}/", |
90 href = "projects/${project.node}/issues/-/${cnode}/", |
83 iconColor = "#000000" |
91 iconColor = "#000000", |
|
92 active = vnode == "-", |
84 ) |
93 ) |
85 ) |
94 ) |
86 for (version in versions.filter { it.status != VersionStatus.Deprecated }) { |
95 yield( |
|
96 NavMenuEntry( |
|
97 level = 2, |
|
98 caption = "navmenu.none", |
|
99 resolveCaption = true, |
|
100 href = "projects/${project.node}/issues/~/${cnode}/", |
|
101 iconColor = "#000000", |
|
102 active = vnode == "~", |
|
103 ) |
|
104 ) |
|
105 for (version in pathInfos.projectInfo.versions) { |
|
106 if (version.status == VersionStatus.Deprecated && vnode != version.node) continue |
87 yield( |
107 yield( |
88 NavMenuEntry( |
108 NavMenuEntry( |
89 level = 2, |
109 level = 2, |
90 caption = version.name, |
110 caption = version.name, |
91 title = "version.status.${version.status}", |
111 title = "version.status.${version.status}", |
92 href = "projects/${project.node}/issues/${version.node}/${cnode}/", |
112 href = "projects/${project.node}/issues/${version.node}/${cnode}/", |
93 iconColor = "version-${version.status}", |
113 iconColor = "version-${version.status}", |
94 active = version == selectedVersion |
114 active = version.node == vnode |
95 ) |
115 ) |
96 ) |
116 ) |
97 } |
117 } |
98 yield( |
118 yield( |
99 NavMenuEntry( |
119 NavMenuEntry( |
107 NavMenuEntry( |
127 NavMenuEntry( |
108 level = 2, |
128 level = 2, |
109 caption = "navmenu.all", |
129 caption = "navmenu.all", |
110 resolveCaption = true, |
130 resolveCaption = true, |
111 href = "projects/${project.node}/issues/${vnode}/-/", |
131 href = "projects/${project.node}/issues/${vnode}/-/", |
112 iconColor = "#000000" |
132 iconColor = "#000000", |
|
133 active = cnode == "-", |
113 ) |
134 ) |
114 ) |
135 ) |
115 for (component in components) { |
136 yield( |
116 if (!component.active && component != selectedComponent) continue |
137 NavMenuEntry( |
|
138 level = 2, |
|
139 caption = "navmenu.none", |
|
140 resolveCaption = true, |
|
141 href = "projects/${project.node}/issues/${vnode}/~/", |
|
142 iconColor = "#000000", |
|
143 active = cnode == "~", |
|
144 ) |
|
145 ) |
|
146 for (component in pathInfos.projectInfo.components) { |
|
147 if (!component.active && component.node != cnode) continue |
117 yield( |
148 yield( |
118 NavMenuEntry( |
149 NavMenuEntry( |
119 level = 2, |
150 level = 2, |
120 caption = component.name, |
151 caption = component.name, |
121 href = "projects/${project.node}/issues/${vnode}/${component.node}/", |
152 href = "projects/${project.node}/issues/${vnode}/${component.node}/", |
122 iconColor = "${component.color}", |
153 iconColor = "${component.color}", |
123 active = component == selectedComponent |
154 active = component.node == cnode |
124 ) |
155 ) |
125 ) |
156 ) |
126 } |
157 } |
127 } |
158 } |
128 } |
159 } |