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

Sun, 04 Apr 2021 13:03:41 +0200

author
Mike Becker <universe@uap-core.de>
date
Sun, 04 Apr 2021 13:03:41 +0200
changeset 186
05eec764facd
parent 184
e8eecee6aadf
child 192
997e2c97ba34
permissions
-rw-r--r--

fixes some minor migration regressions

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

mercurial