Sun, 04 Apr 2021 13:03:41 +0200
fixes some minor migration regressions
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@184 | 28 | import de.uapcore.lightpit.entities.Component |
universe@184 | 29 | import de.uapcore.lightpit.entities.Project |
universe@184 | 30 | import de.uapcore.lightpit.entities.Version |
universe@184 | 31 | |
universe@184 | 32 | class NavMenuEntry( |
universe@184 | 33 | val level: Int, |
universe@184 | 34 | val caption: String, |
universe@184 | 35 | val href: String, |
universe@184 | 36 | val title: String = "", |
universe@184 | 37 | val active: Boolean = false, |
universe@184 | 38 | val resolveCaption: Boolean = false, |
universe@184 | 39 | val iconColor: String? = null |
universe@184 | 40 | ) { |
universe@184 | 41 | val iconUseCssClass = iconColor != null && !iconColor.startsWith("#") |
universe@184 | 42 | } |
universe@184 | 43 | |
universe@184 | 44 | class NavMenu(val entries: List<NavMenuEntry>) |
universe@184 | 45 | |
universe@184 | 46 | fun projectNavMenu( |
universe@184 | 47 | projects: List<Project>, |
universe@184 | 48 | versions: List<Version> = emptyList(), |
universe@184 | 49 | components: List<Component> = emptyList(), |
universe@184 | 50 | selectedProject: Project? = null, |
universe@184 | 51 | selectedVersion: Version? = null, |
universe@184 | 52 | selectedComponent: Component? = null |
universe@184 | 53 | ) = NavMenu( |
universe@184 | 54 | sequence { |
universe@184 | 55 | val cnode = selectedComponent?.node ?: "-" |
universe@184 | 56 | val vnode = selectedVersion?.node ?: "-" |
universe@184 | 57 | for (project in projects) { |
universe@184 | 58 | val active = project == selectedProject |
universe@184 | 59 | yield( |
universe@184 | 60 | NavMenuEntry( |
universe@184 | 61 | level = 0, |
universe@184 | 62 | caption = project.name, |
universe@184 | 63 | href = "projects/${project.node}", |
universe@184 | 64 | active = active |
universe@184 | 65 | ) |
universe@184 | 66 | ) |
universe@184 | 67 | if (active) { |
universe@184 | 68 | yield( |
universe@184 | 69 | NavMenuEntry( |
universe@184 | 70 | level = 1, |
universe@184 | 71 | caption = "navmenu.versions", |
universe@184 | 72 | resolveCaption = true, |
universe@184 | 73 | href = "projects/${project.node}/versions/" |
universe@184 | 74 | ) |
universe@184 | 75 | ) |
universe@184 | 76 | yield( |
universe@184 | 77 | NavMenuEntry( |
universe@184 | 78 | level = 2, |
universe@184 | 79 | caption = "navmenu.all", |
universe@184 | 80 | resolveCaption = true, |
universe@184 | 81 | href = "projects/${project.node}/issues/-/${cnode}/", |
universe@184 | 82 | iconColor = "#000000" |
universe@184 | 83 | ) |
universe@184 | 84 | ) |
universe@184 | 85 | for (version in versions) { |
universe@184 | 86 | yield( |
universe@184 | 87 | NavMenuEntry( |
universe@184 | 88 | level = 2, |
universe@184 | 89 | caption = version.name, |
universe@184 | 90 | title = "version.status.${version.status}", |
universe@184 | 91 | href = "projects/${project.node}/issues/${version.node}/${cnode}/", |
universe@184 | 92 | iconColor = "version-${version.status}", |
universe@184 | 93 | active = version == selectedVersion |
universe@184 | 94 | ) |
universe@184 | 95 | ) |
universe@184 | 96 | } |
universe@184 | 97 | yield( |
universe@184 | 98 | NavMenuEntry( |
universe@184 | 99 | level = 1, |
universe@184 | 100 | caption = "navmenu.components", |
universe@184 | 101 | resolveCaption = true, |
universe@184 | 102 | href = "projects/${project.node}/components/" |
universe@184 | 103 | ) |
universe@184 | 104 | ) |
universe@184 | 105 | yield( |
universe@184 | 106 | NavMenuEntry( |
universe@184 | 107 | level = 2, |
universe@184 | 108 | caption = "navmenu.all", |
universe@184 | 109 | resolveCaption = true, |
universe@184 | 110 | href = "projects/${project.node}/issues/${vnode}/-/", |
universe@184 | 111 | iconColor = "#000000" |
universe@184 | 112 | ) |
universe@184 | 113 | ) |
universe@184 | 114 | for (component in components) { |
universe@184 | 115 | yield( |
universe@184 | 116 | NavMenuEntry( |
universe@184 | 117 | level = 2, |
universe@184 | 118 | caption = component.name, |
universe@184 | 119 | href = "projects/${project.node}/issues/${vnode}/${component.node}/", |
universe@184 | 120 | iconColor = "${component.color}", |
universe@184 | 121 | active = component == selectedComponent |
universe@184 | 122 | ) |
universe@184 | 123 | ) |
universe@184 | 124 | } |
universe@184 | 125 | } |
universe@184 | 126 | } |
universe@184 | 127 | }.toList() |
universe@184 | 128 | ) |