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