Mon, 05 Aug 2024 19:38:47 +0200
fix removing filter not working
fixes #407
/* * 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.Project import de.uapcore.lightpit.types.VersionStatus 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<NavMenuEntry>) fun projectNavMenu(projects: List<Project>) = NavMenu( sequence { for (project in projects) { yield( NavMenuEntry( level = 0, caption = project.name, href = "projects/${project.node}", ) ) } }.toList() ) fun projectNavMenu(projects: List<Project>, pathInfos: PathInfosFull) = NavMenu( sequence { val cnode = pathInfos.componentInfo.node val vnode = pathInfos.versionInfo.node for (project in projects) { val active = project == pathInfos.projectInfo.project 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", active = vnode == "-", ) ) yield( NavMenuEntry( level = 2, caption = "navmenu.none", resolveCaption = true, href = "projects/${project.node}/issues/~/${cnode}/", iconColor = "#000000", active = vnode == "~", ) ) for (version in pathInfos.projectInfo.versions) { if (version.status == VersionStatus.Deprecated && vnode != version.node) continue 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.node == vnode ) ) } 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", active = cnode == "-", ) ) yield( NavMenuEntry( level = 2, caption = "navmenu.none", resolveCaption = true, href = "projects/${project.node}/issues/${vnode}/~/", iconColor = "#000000", active = cnode == "~", ) ) for (component in pathInfos.projectInfo.components) { if (!component.active && component.node != cnode) continue yield( NavMenuEntry( level = 2, caption = component.name, href = "projects/${project.node}/issues/${vnode}/${component.node}/", iconColor = "${component.color}", active = component.node == cnode ) ) } } } }.toList() )