diff -r 61669abf277f -r e8eecee6aadf src/main/kotlin/de/uapcore/lightpit/viewmodel/NavMenus.kt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/kotlin/de/uapcore/lightpit/viewmodel/NavMenus.kt Fri Apr 02 11:59:14 2021 +0200 @@ -0,0 +1,128 @@ +/* + * Copyright 2021 Mike Becker. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package de.uapcore.lightpit.viewmodel + +import de.uapcore.lightpit.entities.Component +import de.uapcore.lightpit.entities.Project +import de.uapcore.lightpit.entities.Version + +class NavMenuEntry( + val level: Int, + val caption: String, + val href: String, + val title: String = "", + val active: Boolean = false, + val resolveCaption: Boolean = false, + val iconColor: String? = null +) { + val iconUseCssClass = iconColor != null && !iconColor.startsWith("#") +} + +class NavMenu(val entries: List) + +fun projectNavMenu( + projects: List, + versions: List = emptyList(), + components: List = emptyList(), + selectedProject: Project? = null, + selectedVersion: Version? = null, + selectedComponent: Component? = null +) = NavMenu( + sequence { + val cnode = selectedComponent?.node ?: "-" + val vnode = selectedVersion?.node ?: "-" + for (project in projects) { + val active = project == selectedProject + yield( + NavMenuEntry( + level = 0, + caption = project.name, + href = "projects/${project.node}", + active = active + ) + ) + if (active) { + yield( + NavMenuEntry( + level = 1, + caption = "navmenu.versions", + resolveCaption = true, + href = "projects/${project.node}/versions/" + ) + ) + yield( + NavMenuEntry( + level = 2, + caption = "navmenu.all", + resolveCaption = true, + href = "projects/${project.node}/issues/-/${cnode}/", + iconColor = "#000000" + ) + ) + for (version in versions) { + yield( + NavMenuEntry( + level = 2, + caption = version.name, + title = "version.status.${version.status}", + href = "projects/${project.node}/issues/${version.node}/${cnode}/", + iconColor = "version-${version.status}", + active = version == selectedVersion + ) + ) + } + yield( + NavMenuEntry( + level = 1, + caption = "navmenu.components", + resolveCaption = true, + href = "projects/${project.node}/components/" + ) + ) + yield( + NavMenuEntry( + level = 2, + caption = "navmenu.all", + resolveCaption = true, + href = "projects/${project.node}/issues/${vnode}/-/", + iconColor = "#000000" + ) + ) + for (component in components) { + yield( + NavMenuEntry( + level = 2, + caption = component.name, + href = "projects/${project.node}/issues/${vnode}/${component.node}/", + iconColor = "${component.color}", + active = component == selectedComponent + ) + ) + } + } + } + }.toList() +)