Mon, 30 Oct 2023 14:44:36 +0100
add possibility to show issues w/o version or component - fixes #335
universe@184 | 1 | /* |
universe@184 | 2 | * Copyright 2021 Mike Becker. All rights reserved. |
universe@184 | 3 | * |
universe@184 | 4 | * Redistribution and use in source and binary forms, with or without |
universe@184 | 5 | * modification, are permitted provided that the following conditions are met: |
universe@184 | 6 | * |
universe@184 | 7 | * 1. Redistributions of source code must retain the above copyright |
universe@184 | 8 | * notice, this list of conditions and the following disclaimer. |
universe@184 | 9 | * |
universe@184 | 10 | * 2. Redistributions in binary form must reproduce the above copyright |
universe@184 | 11 | * notice, this list of conditions and the following disclaimer in the |
universe@184 | 12 | * documentation and/or other materials provided with the distribution. |
universe@184 | 13 | * |
universe@184 | 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
universe@184 | 15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
universe@184 | 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
universe@184 | 17 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
universe@184 | 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
universe@184 | 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
universe@184 | 20 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
universe@184 | 21 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
universe@184 | 22 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
universe@184 | 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
universe@184 | 24 | */ |
universe@184 | 25 | |
universe@184 | 26 | package de.uapcore.lightpit.viewmodel |
universe@184 | 27 | |
universe@292 | 28 | import de.uapcore.lightpit.OptionalPathInfo |
universe@184 | 29 | import de.uapcore.lightpit.entities.Component |
universe@184 | 30 | import de.uapcore.lightpit.entities.Project |
universe@184 | 31 | import de.uapcore.lightpit.entities.Version |
universe@192 | 32 | import de.uapcore.lightpit.types.VersionStatus |
universe@184 | 33 | |
universe@184 | 34 | class NavMenuEntry( |
universe@184 | 35 | val level: Int, |
universe@184 | 36 | val caption: String, |
universe@184 | 37 | val href: String, |
universe@184 | 38 | val title: String = "", |
universe@184 | 39 | val active: Boolean = false, |
universe@184 | 40 | val resolveCaption: Boolean = false, |
universe@184 | 41 | val iconColor: String? = null |
universe@184 | 42 | ) { |
universe@184 | 43 | val iconUseCssClass = iconColor != null && !iconColor.startsWith("#") |
universe@184 | 44 | } |
universe@184 | 45 | |
universe@184 | 46 | class NavMenu(val entries: List<NavMenuEntry>) |
universe@184 | 47 | |
universe@292 | 48 | fun projectNavMenu(projects: List<Project>) = NavMenu( |
universe@184 | 49 | sequence { |
universe@184 | 50 | for (project in projects) { |
universe@292 | 51 | yield( |
universe@292 | 52 | NavMenuEntry( |
universe@292 | 53 | level = 0, |
universe@292 | 54 | caption = project.name, |
universe@292 | 55 | href = "projects/${project.node}", |
universe@292 | 56 | ) |
universe@292 | 57 | ) |
universe@292 | 58 | } |
universe@292 | 59 | }.toList() |
universe@292 | 60 | ) |
universe@292 | 61 | |
universe@292 | 62 | fun projectNavMenu(projects: List<Project>, pathInfos: PathInfos) = NavMenu( |
universe@292 | 63 | sequence { |
universe@292 | 64 | val cnode = pathInfos.componentInfo.node |
universe@292 | 65 | val vnode = pathInfos.versionInfo.node |
universe@292 | 66 | for (project in projects) { |
universe@292 | 67 | val active = project == pathInfos.projectInfo.project |
universe@184 | 68 | yield( |
universe@184 | 69 | NavMenuEntry( |
universe@184 | 70 | level = 0, |
universe@184 | 71 | caption = project.name, |
universe@184 | 72 | href = "projects/${project.node}", |
universe@184 | 73 | active = active |
universe@184 | 74 | ) |
universe@184 | 75 | ) |
universe@184 | 76 | if (active) { |
universe@184 | 77 | yield( |
universe@184 | 78 | NavMenuEntry( |
universe@184 | 79 | level = 1, |
universe@184 | 80 | caption = "navmenu.versions", |
universe@184 | 81 | resolveCaption = true, |
universe@184 | 82 | href = "projects/${project.node}/versions/" |
universe@184 | 83 | ) |
universe@184 | 84 | ) |
universe@184 | 85 | yield( |
universe@184 | 86 | NavMenuEntry( |
universe@184 | 87 | level = 2, |
universe@184 | 88 | caption = "navmenu.all", |
universe@184 | 89 | resolveCaption = true, |
universe@184 | 90 | href = "projects/${project.node}/issues/-/${cnode}/", |
universe@292 | 91 | iconColor = "#000000", |
universe@292 | 92 | active = vnode == "-", |
universe@184 | 93 | ) |
universe@184 | 94 | ) |
universe@292 | 95 | yield( |
universe@292 | 96 | NavMenuEntry( |
universe@292 | 97 | level = 2, |
universe@292 | 98 | caption = "navmenu.none", |
universe@292 | 99 | resolveCaption = true, |
universe@292 | 100 | href = "projects/${project.node}/issues/~/${cnode}/", |
universe@292 | 101 | iconColor = "#000000", |
universe@292 | 102 | active = vnode == "~", |
universe@292 | 103 | ) |
universe@292 | 104 | ) |
universe@292 | 105 | for (version in pathInfos.projectInfo.versions) { |
universe@292 | 106 | if (version.status == VersionStatus.Deprecated && vnode != version.node) continue |
universe@184 | 107 | yield( |
universe@184 | 108 | NavMenuEntry( |
universe@184 | 109 | level = 2, |
universe@184 | 110 | caption = version.name, |
universe@184 | 111 | title = "version.status.${version.status}", |
universe@184 | 112 | href = "projects/${project.node}/issues/${version.node}/${cnode}/", |
universe@184 | 113 | iconColor = "version-${version.status}", |
universe@292 | 114 | active = version.node == vnode |
universe@184 | 115 | ) |
universe@184 | 116 | ) |
universe@184 | 117 | } |
universe@184 | 118 | yield( |
universe@184 | 119 | NavMenuEntry( |
universe@184 | 120 | level = 1, |
universe@184 | 121 | caption = "navmenu.components", |
universe@184 | 122 | resolveCaption = true, |
universe@184 | 123 | href = "projects/${project.node}/components/" |
universe@184 | 124 | ) |
universe@184 | 125 | ) |
universe@184 | 126 | yield( |
universe@184 | 127 | NavMenuEntry( |
universe@184 | 128 | level = 2, |
universe@184 | 129 | caption = "navmenu.all", |
universe@184 | 130 | resolveCaption = true, |
universe@184 | 131 | href = "projects/${project.node}/issues/${vnode}/-/", |
universe@292 | 132 | iconColor = "#000000", |
universe@292 | 133 | active = cnode == "-", |
universe@184 | 134 | ) |
universe@184 | 135 | ) |
universe@292 | 136 | yield( |
universe@292 | 137 | NavMenuEntry( |
universe@292 | 138 | level = 2, |
universe@292 | 139 | caption = "navmenu.none", |
universe@292 | 140 | resolveCaption = true, |
universe@292 | 141 | href = "projects/${project.node}/issues/${vnode}/~/", |
universe@292 | 142 | iconColor = "#000000", |
universe@292 | 143 | active = cnode == "~", |
universe@292 | 144 | ) |
universe@292 | 145 | ) |
universe@292 | 146 | for (component in pathInfos.projectInfo.components) { |
universe@292 | 147 | if (!component.active && component.node != cnode) continue |
universe@184 | 148 | yield( |
universe@184 | 149 | NavMenuEntry( |
universe@184 | 150 | level = 2, |
universe@184 | 151 | caption = component.name, |
universe@184 | 152 | href = "projects/${project.node}/issues/${vnode}/${component.node}/", |
universe@184 | 153 | iconColor = "${component.color}", |
universe@292 | 154 | active = component.node == cnode |
universe@184 | 155 | ) |
universe@184 | 156 | ) |
universe@184 | 157 | } |
universe@184 | 158 | } |
universe@184 | 159 | } |
universe@184 | 160 | }.toList() |
universe@184 | 161 | ) |