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@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@184: fun projectNavMenu( universe@184: projects: List, universe@184: versions: List = emptyList(), universe@184: components: List = emptyList(), universe@184: selectedProject: Project? = null, universe@184: selectedVersion: Version? = null, universe@184: selectedComponent: Component? = null universe@184: ) = NavMenu( universe@184: sequence { universe@184: val cnode = selectedComponent?.node ?: "-" universe@184: val vnode = selectedVersion?.node ?: "-" universe@184: for (project in projects) { universe@184: val active = project == selectedProject 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@184: iconColor = "#000000" universe@184: ) universe@184: ) universe@192: for (version in versions.filter { it.status != VersionStatus.Deprecated }) { 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@184: active = version == selectedVersion 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@184: iconColor = "#000000" universe@184: ) universe@184: ) universe@184: for (component in components) { universe@227: if (!component.active && component != selectedComponent) 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@184: active = component == selectedComponent universe@184: ) universe@184: ) universe@184: } universe@184: } universe@184: } universe@184: }.toList() universe@184: )