src/main/kotlin/de/uapcore/lightpit/viewmodel/NavMenus.kt

Thu, 13 May 2021 19:31:09 +0200

author
Mike Becker <universe@uap-core.de>
date
Thu, 13 May 2021 19:31:09 +0200
changeset 198
94f174d591ab
parent 192
997e2c97ba34
child 227
f0ede8046b59
permissions
-rw-r--r--

fixes wrong handling of feeds - only one channel per feed is allowed

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

mercurial