Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enable optional Diagrams List Index #629

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import com.structurizr.model.SoftwareSystem
import com.structurizr.model.StaticStructureElement
import com.structurizr.view.ViewSet
import nl.avisi.structurizr.site.generatr.site.GeneratorContext
import nl.avisi.structurizr.site.generatr.site.model.DiagramViewModel
import nl.avisi.structurizr.site.generatr.site.model.ImageViewViewModel

val Workspace.includedSoftwareSystems: List<SoftwareSystem>
get() = model.softwareSystems.filter {
Expand All @@ -17,6 +19,11 @@ fun Workspace.hasImageViews(id: String) = views.imageViews.any { it.elementId ==

fun Workspace.hasComponentDiagrams(container: Container) = views.componentViews.any { it.container == container}

fun Workspace.listIndexViewEnabled(
diagrams: List<DiagramViewModel>?,
images: List<ImageViewViewModel>?
) = ((diagrams?.count() ?: 0) + (images?.count() ?: 0)) > 1
galuszkak marked this conversation as resolved.
Show resolved Hide resolved

val SoftwareSystem.hasContainers
get() = this.containers.isNotEmpty()

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package nl.avisi.structurizr.site.generatr.site.model


data class DiagramIndexListViewModel(
galuszkak marked this conversation as resolved.
Show resolved Hide resolved
val diagrams: List<DiagramViewModel>?,
galuszkak marked this conversation as resolved.
Show resolved Hide resolved
val images: List<ImageViewViewModel>?,
galuszkak marked this conversation as resolved.
Show resolved Hide resolved
val showList: Boolean
galuszkak marked this conversation as resolved.
Show resolved Hide resolved
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.structurizr.view.View
data class DiagramViewModel(
val key: String,
val name: String,
val title: String?,
jenspav marked this conversation as resolved.
Show resolved Hide resolved
val description: String?,
val svg: String?,
val diagramWidthInPixels: Int?,
Expand All @@ -14,19 +15,21 @@ data class DiagramViewModel(
) {
companion object {
fun forView(pageViewModel: PageViewModel, view: View, svgFactory: (key: String, url: String) -> String?) =
forView(pageViewModel, view.key, view.name, view.description.ifBlank { null }, svgFactory)
forView(pageViewModel, view.key, view.name, view.title, view.description.ifBlank { null }, svgFactory)

fun forView(
pageViewModel: PageViewModel,
key: String,
name: String,
title: String?,
description: String?,
svgFactory: (key: String, url: String) -> String?
): DiagramViewModel {
val svg = svgFactory(key, pageViewModel.url)
return DiagramViewModel(
key,
name,
title,
description,
svg,
extractDiagramWidthInPixels(svg),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package nl.avisi.structurizr.site.generatr.site.model

import com.structurizr.model.Container
import com.structurizr.model.Component
import nl.avisi.structurizr.site.generatr.listIndexViewEnabled
import nl.avisi.structurizr.site.generatr.normalize
import nl.avisi.structurizr.site.generatr.site.GeneratorContext

Expand All @@ -16,7 +17,11 @@ class SoftwareSystemContainerComponentCodePageViewModel(generatorContext: Genera
val visible = images.isNotEmpty()
val containerTabs = createContainersCodeTabViewModel(generatorContext, container.softwareSystem)
val componentTabs = createComponentsTabViewModel(generatorContext, container)

val diagramIndexListViewModel = DiagramIndexListViewModel(
galuszkak marked this conversation as resolved.
Show resolved Hide resolved
null,
galuszkak marked this conversation as resolved.
Show resolved Hide resolved
images,
generatorContext.workspace.listIndexViewEnabled(null, images)
)
companion object {
fun url(container: Container, component: Component?) = "${url(container.softwareSystem, Tab.CODE)}/${container.name.normalize()}/${component?.name?.normalize()}"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package nl.avisi.structurizr.site.generatr.site.model

import com.structurizr.model.Container
import nl.avisi.structurizr.site.generatr.includedProperties
import nl.avisi.structurizr.site.generatr.listIndexViewEnabled
import nl.avisi.structurizr.site.generatr.normalize
import nl.avisi.structurizr.site.generatr.site.GeneratorContext

Expand All @@ -21,6 +22,11 @@ class SoftwareSystemContainerComponentsPageViewModel(generatorContext: Generator
val propertiesTable = createPropertiesTableViewModel(container.includedProperties)
val visible = diagrams.isNotEmpty() or images.isNotEmpty() or hasProperties
val containerTabs = createContainersComponentTabViewModel(generatorContext, container.softwareSystem)
val diagramIndexListViewModel = DiagramIndexListViewModel(
diagrams,
images,
generatorContext.workspace.listIndexViewEnabled(diagrams, images)
)
companion object {
fun url(container: Container) = "${url(container.softwareSystem, Tab.COMPONENT)}/${container.name.normalize()}"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package nl.avisi.structurizr.site.generatr.site.model

import com.structurizr.model.SoftwareSystem
import nl.avisi.structurizr.site.generatr.hasContainerViews
import nl.avisi.structurizr.site.generatr.listIndexViewEnabled
import nl.avisi.structurizr.site.generatr.site.GeneratorContext

class SoftwareSystemContainerPageViewModel(generatorContext: GeneratorContext, softwareSystem: SoftwareSystem) :
Expand All @@ -15,4 +16,9 @@ class SoftwareSystemContainerPageViewModel(generatorContext: GeneratorContext, s
.sortedBy { it.key }
.map { ImageViewViewModel(it) }
val visible = generatorContext.workspace.views.hasContainerViews(generatorContext.workspace, softwareSystem) || images.isNotEmpty()
val diagramIndexListViewModel = DiagramIndexListViewModel(
diagrams,
images,
generatorContext.workspace.listIndexViewEnabled(diagrams, images)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package nl.avisi.structurizr.site.generatr.site.model

import com.structurizr.model.SoftwareSystem
import nl.avisi.structurizr.site.generatr.hasSystemContextViews
import nl.avisi.structurizr.site.generatr.listIndexViewEnabled
import nl.avisi.structurizr.site.generatr.site.GeneratorContext

class SoftwareSystemContextPageViewModel(generatorContext: GeneratorContext, softwareSystem: SoftwareSystem) :
Expand All @@ -11,4 +12,9 @@ class SoftwareSystemContextPageViewModel(generatorContext: GeneratorContext, sof
.sortedBy { it.key }
.map { DiagramViewModel.forView(this, it, generatorContext.svgFactory) }
val visible = generatorContext.workspace.views.hasSystemContextViews(softwareSystem)
val diagramIndexListViewModel = DiagramIndexListViewModel(
diagrams,
null,
generatorContext.workspace.listIndexViewEnabled(diagrams, null)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package nl.avisi.structurizr.site.generatr.site.model

import com.structurizr.model.SoftwareSystem
import nl.avisi.structurizr.site.generatr.hasDeploymentViews
import nl.avisi.structurizr.site.generatr.listIndexViewEnabled
import nl.avisi.structurizr.site.generatr.site.GeneratorContext

class SoftwareSystemDeploymentPageViewModel(generatorContext: GeneratorContext, softwareSystem: SoftwareSystem) :
Expand All @@ -11,4 +12,9 @@ class SoftwareSystemDeploymentPageViewModel(generatorContext: GeneratorContext,
.sortedBy { it.key }
.map { DiagramViewModel.forView(this, it, generatorContext.svgFactory) }
val visible = generatorContext.workspace.views.hasDeploymentViews(softwareSystem)
val diagramIndexListViewModel = DiagramIndexListViewModel(
diagrams,
null,
generatorContext.workspace.listIndexViewEnabled(diagrams, null)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package nl.avisi.structurizr.site.generatr.site.model

import com.structurizr.model.SoftwareSystem
import nl.avisi.structurizr.site.generatr.hasDynamicViews
import nl.avisi.structurizr.site.generatr.listIndexViewEnabled
import nl.avisi.structurizr.site.generatr.site.GeneratorContext

class SoftwareSystemDynamicPageViewModel(generatorContext: GeneratorContext, softwareSystem: SoftwareSystem) :
Expand All @@ -11,4 +12,9 @@ class SoftwareSystemDynamicPageViewModel(generatorContext: GeneratorContext, sof
.sortedBy { it.key }
.map { DiagramViewModel.forView(this, it, generatorContext.svgFactory) }
val visible = generatorContext.workspace.views.hasDynamicViews(softwareSystem)
val diagramIndexListViewModel = DiagramIndexListViewModel(
diagrams,
null,
generatorContext.workspace.listIndexViewEnabled(diagrams, null)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ fun Element.transformEmbeddedDiagramElements(
val key = it.attr("src").substring(embedPrefix.length)
val name = it.attr("alt").ifBlank { key }
val html = createHTML().div {
diagram(DiagramViewModel.forView(pageViewModel, key, name, null, svgFactory))
diagram(DiagramViewModel.forView(pageViewModel, key, name, null, null, svgFactory))
}

it.parent()?.append(html)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fun FlowContent.diagram(viewModel: DiagramViewModel) {

figure {
style = "width: min(100%, ${viewModel.diagramWidthInPixels}px);"

attributes["id"] = viewModel.key
rawHtml(viewModel.svg)
figcaption {
a {
Expand Down
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file should be named DiagramIndex.kt.

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package nl.avisi.structurizr.site.generatr.site.views

import kotlinx.html.*
import nl.avisi.structurizr.site.generatr.site.model.DiagramIndexListViewModel
import nl.avisi.structurizr.site.generatr.site.model.DiagramViewModel

fun FlowContent.diagramIndexList(viewModel: DiagramIndexListViewModel) {
galuszkak marked this conversation as resolved.
Show resolved Hide resolved
if(viewModel.showList) {
jenspav marked this conversation as resolved.
Show resolved Hide resolved
h5 {
jenspav marked this conversation as resolved.
Show resolved Hide resolved
+"Jump to: "
}
ul {
viewModel.diagrams?.forEach {
jenspav marked this conversation as resolved.
Show resolved Hide resolved
li {
a(href = "#${it.key}") {
+(it.title ?: it.name)
}
}
}
viewModel.images?.forEach {
jenspav marked this conversation as resolved.
Show resolved Hide resolved
li {
a(href = "#${it.key}") {
+(it.title ?: it.name)
jenspav marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ fun FlowContent.image(viewModel: ImageViewViewModel) {

figure {
style = "width: fit-content;"

attributes["id"] = viewModel.key

p(classes = "has-text-weight-bold") { +viewModel.title }
img { src = viewModel.content }
figcaption {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ fun HTML.softwareSystemContainerComponentCodePage(viewModel: SoftwareSystemConta
}
}
}
diagramIndexList(viewModel.diagramIndexListViewModel)
viewModel.images.forEach { image(it) }
}
} else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ fun HTML.softwareSystemContainerComponentsPage(viewModel: SoftwareSystemContaine
}
}
}
diagramIndexList(viewModel.diagramIndexListViewModel)
viewModel.diagrams.forEach { diagram(it) }
viewModel.images.forEach { image(it) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import nl.avisi.structurizr.site.generatr.site.model.SoftwareSystemContainerPage
fun HTML.softwareSystemContainerPage(viewModel: SoftwareSystemContainerPageViewModel) {
if (viewModel.visible)
softwareSystemPage(viewModel) {
diagramIndexList(viewModel.diagramIndexListViewModel)
viewModel.diagrams.forEach { diagram(it) }
viewModel.images.forEach { image(it) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import nl.avisi.structurizr.site.generatr.site.model.SoftwareSystemContextPageVi
fun HTML.softwareSystemContextPage(viewModel: SoftwareSystemContextPageViewModel) {
if (viewModel.visible)
softwareSystemPage(viewModel) {
viewModel.diagrams.forEach {
diagram(it)
}
diagramIndexList(viewModel.diagramIndexListViewModel)
viewModel.diagrams.forEach { diagram(it) }
}
else
redirectUpPage()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import nl.avisi.structurizr.site.generatr.site.model.SoftwareSystemDeploymentPag
fun HTML.softwareSystemDeploymentPage(viewModel: SoftwareSystemDeploymentPageViewModel) {
if (viewModel.visible)
softwareSystemPage(viewModel) {
diagramIndexList(viewModel.diagramIndexListViewModel)
viewModel.diagrams.forEach {
jenspav marked this conversation as resolved.
Show resolved Hide resolved
diagram(it)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import nl.avisi.structurizr.site.generatr.site.model.SoftwareSystemDynamicPageVi
fun HTML.softwareSystemDynamicPage(viewModel: SoftwareSystemDynamicPageViewModel) {
if (viewModel.visible)
softwareSystemPage(viewModel) {
diagramIndexList(viewModel.diagramIndexListViewModel)
viewModel.diagrams.forEach {
jenspav marked this conversation as resolved.
Show resolved Hide resolved
diagram(it)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ class AsciidocToHtmlTest : ViewModelTest() {
<div class="imageblock content">
<div class="content">
<div>
<figure style="width: min(100%, 800px);">
<figure style="width: min(100%, 800px);" id="SystemLandscape">
<div>
<svg viewBox="0 0 800 900"></svg>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ class MarkdownToHtmlTest : ViewModelTest() {
"""
<p>
<div>
<figure style="width: min(100%, 800px);">
<figure style="width: min(100%, 800px);" id="SystemLandscape">
<div>
<svg viewBox="0 0 800 900"></svg>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class SoftwareSystemContainerComponentsPageViewModelTest : ViewModelTest() {
DiagramViewModel(
"component-1-backend",
"Software system - Backend - Components",
null,
"Component view 1 - Backend",
"""<svg viewBox="0 0 800 900"></svg>""",
800,
Expand All @@ -82,6 +83,7 @@ class SoftwareSystemContainerComponentsPageViewModelTest : ViewModelTest() {
DiagramViewModel(
"component-2-backend",
"Software system - Backend - Components",
null,
"Component view 2 - Backend",
"""<svg viewBox="0 0 800 900"></svg>""",
800,
Expand All @@ -97,6 +99,7 @@ class SoftwareSystemContainerComponentsPageViewModelTest : ViewModelTest() {
DiagramViewModel(
"component-1-frontend",
"Software system - Frontend - Components",
null,
"Component view 1 - Frontend",
"""<svg viewBox="0 0 800 900"></svg>""",
800,
Expand All @@ -107,6 +110,7 @@ class SoftwareSystemContainerComponentsPageViewModelTest : ViewModelTest() {
DiagramViewModel(
"component-2-frontend",
"Software system - Frontend - Components",
null,
"Component view 2 - Frontend",
"""<svg viewBox="0 0 800 900"></svg>""",
800,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class SoftwareSystemContainerPageViewModelTest : ViewModelTest() {
DiagramViewModel(
"container-1",
"Software system - Containers",
null,
"Container view 1",
"""<svg viewBox="0 0 800 900"></svg>""",
800,
Expand All @@ -45,6 +46,7 @@ class SoftwareSystemContainerPageViewModelTest : ViewModelTest() {
DiagramViewModel(
"container-2",
"Software system - Containers",
null,
"Container view 2",
"""<svg viewBox="0 0 800 900"></svg>""",
800,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package nl.avisi.structurizr.site.generatr.site.model
import assertk.assertThat
import assertk.assertions.containsExactly
import assertk.assertions.isFalse
import assertk.assertions.isTrue
import com.structurizr.model.SoftwareSystem
import kotlin.test.Test

Expand All @@ -22,6 +23,7 @@ class SoftwareSystemContextPageViewModelTest : ViewModelTest() {
DiagramViewModel(
"context-1",
"Software system - System Context",
null,
"System context view 1",
"""<svg viewBox="0 0 800 900"></svg>""",
800,
Expand All @@ -32,6 +34,7 @@ class SoftwareSystemContextPageViewModelTest : ViewModelTest() {
DiagramViewModel(
"context-2",
"Software system - System Context",
null,
"System context view 2",
"""<svg viewBox="0 0 800 900"></svg>""",
800,
Expand All @@ -51,4 +54,10 @@ class SoftwareSystemContextPageViewModelTest : ViewModelTest() {

assertThat(viewModel.visible).isFalse()
}

@Test
fun `show list is enabled`() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a similar test to other page tests as well, also with variations with/without diagrams and image views.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done some initial tests on all pages. Probably we could do more, let me know if this would be enough or you need more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above, would be nice to always test both scenarios. Also please adjust the test names to use the words index and visible instead of show and list .

val viewModel = SoftwareSystemContextPageViewModel(generatorContext, softwareSystem)
assertThat(viewModel.diagramIndexListViewModel.showList).isTrue()
}
}
Loading
Loading