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

changeset 292
703591e739f4
parent 227
f0ede8046b59
     1.1 --- a/src/main/kotlin/de/uapcore/lightpit/viewmodel/NavMenus.kt	Mon Oct 30 10:06:22 2023 +0100
     1.2 +++ b/src/main/kotlin/de/uapcore/lightpit/viewmodel/NavMenus.kt	Mon Oct 30 14:44:36 2023 +0100
     1.3 @@ -25,6 +25,7 @@
     1.4  
     1.5  package de.uapcore.lightpit.viewmodel
     1.6  
     1.7 +import de.uapcore.lightpit.OptionalPathInfo
     1.8  import de.uapcore.lightpit.entities.Component
     1.9  import de.uapcore.lightpit.entities.Project
    1.10  import de.uapcore.lightpit.entities.Version
    1.11 @@ -44,19 +45,26 @@
    1.12  
    1.13  class NavMenu(val entries: List<NavMenuEntry>)
    1.14  
    1.15 -fun projectNavMenu(
    1.16 -    projects: List<Project>,
    1.17 -    versions: List<Version> = emptyList(),
    1.18 -    components: List<Component> = emptyList(),
    1.19 -    selectedProject: Project? = null,
    1.20 -    selectedVersion: Version? = null,
    1.21 -    selectedComponent: Component? = null
    1.22 -) = NavMenu(
    1.23 +fun projectNavMenu(projects: List<Project>) = NavMenu(
    1.24      sequence {
    1.25 -        val cnode = selectedComponent?.node ?: "-"
    1.26 -        val vnode = selectedVersion?.node ?: "-"
    1.27          for (project in projects) {
    1.28 -            val active = project == selectedProject
    1.29 +            yield(
    1.30 +                NavMenuEntry(
    1.31 +                    level = 0,
    1.32 +                    caption = project.name,
    1.33 +                    href = "projects/${project.node}",
    1.34 +                )
    1.35 +            )
    1.36 +        }
    1.37 +    }.toList()
    1.38 +)
    1.39 +
    1.40 +fun projectNavMenu(projects: List<Project>, pathInfos: PathInfos) = NavMenu(
    1.41 +    sequence {
    1.42 +        val cnode = pathInfos.componentInfo.node
    1.43 +        val vnode = pathInfos.versionInfo.node
    1.44 +        for (project in projects) {
    1.45 +            val active = project == pathInfos.projectInfo.project
    1.46              yield(
    1.47                  NavMenuEntry(
    1.48                      level = 0,
    1.49 @@ -80,10 +88,22 @@
    1.50                          caption = "navmenu.all",
    1.51                          resolveCaption = true,
    1.52                          href = "projects/${project.node}/issues/-/${cnode}/",
    1.53 -                        iconColor = "#000000"
    1.54 +                        iconColor = "#000000",
    1.55 +                        active = vnode == "-",
    1.56                      )
    1.57                  )
    1.58 -                for (version in versions.filter { it.status != VersionStatus.Deprecated }) {
    1.59 +                yield(
    1.60 +                    NavMenuEntry(
    1.61 +                        level = 2,
    1.62 +                        caption = "navmenu.none",
    1.63 +                        resolveCaption = true,
    1.64 +                        href = "projects/${project.node}/issues/~/${cnode}/",
    1.65 +                        iconColor = "#000000",
    1.66 +                        active = vnode == "~",
    1.67 +                    )
    1.68 +                )
    1.69 +                for (version in pathInfos.projectInfo.versions) {
    1.70 +                    if (version.status == VersionStatus.Deprecated && vnode != version.node) continue
    1.71                      yield(
    1.72                          NavMenuEntry(
    1.73                              level = 2,
    1.74 @@ -91,7 +111,7 @@
    1.75                              title = "version.status.${version.status}",
    1.76                              href = "projects/${project.node}/issues/${version.node}/${cnode}/",
    1.77                              iconColor = "version-${version.status}",
    1.78 -                            active = version == selectedVersion
    1.79 +                            active = version.node == vnode
    1.80                          )
    1.81                      )
    1.82                  }
    1.83 @@ -109,18 +129,29 @@
    1.84                          caption = "navmenu.all",
    1.85                          resolveCaption = true,
    1.86                          href = "projects/${project.node}/issues/${vnode}/-/",
    1.87 -                        iconColor = "#000000"
    1.88 +                        iconColor = "#000000",
    1.89 +                        active = cnode == "-",
    1.90                      )
    1.91                  )
    1.92 -                for (component in components) {
    1.93 -                    if (!component.active && component != selectedComponent) continue
    1.94 +                yield(
    1.95 +                    NavMenuEntry(
    1.96 +                        level = 2,
    1.97 +                        caption = "navmenu.none",
    1.98 +                        resolveCaption = true,
    1.99 +                        href = "projects/${project.node}/issues/${vnode}/~/",
   1.100 +                        iconColor = "#000000",
   1.101 +                        active = cnode == "~",
   1.102 +                    )
   1.103 +                )
   1.104 +                for (component in pathInfos.projectInfo.components) {
   1.105 +                    if (!component.active && component.node != cnode) continue
   1.106                      yield(
   1.107                          NavMenuEntry(
   1.108                              level = 2,
   1.109                              caption = component.name,
   1.110                              href = "projects/${project.node}/issues/${vnode}/${component.node}/",
   1.111                              iconColor = "${component.color}",
   1.112 -                            active = component == selectedComponent
   1.113 +                            active = component.node == cnode
   1.114                          )
   1.115                      )
   1.116                  }

mercurial