Skip to content

Commit

Permalink
Merge branch 'feature/enabled-list-index-diagrams' of github.com:Flyr…
Browse files Browse the repository at this point in the history
…Inc/structurizr-site-generatr into feature/enabled-list-index-diagrams
  • Loading branch information
galuszkak committed Oct 30, 2024
2 parents 5abdb99 + 53fb1fe commit b55d9a6
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 13 deletions.
3 changes: 3 additions & 0 deletions docs/example/workspace.dsl
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ workspace "Big Bank plc" "This is an example workspace to illustrate the key fea
apiApplication = container "API Application" "Provides Internet banking functionality via a JSON/HTTPS API." "Java and Spring MVC" {
!adrs internet-banking-system/api-application/adr
!docs internet-banking-system/api-application/docs
properties {
Owner "Team 1"
}
signinController = component "Sign In Controller" "Allows users to sign in to the Internet Banking System." "Spring MVC Rest Controller"
accountsSummaryController = component "Accounts Summary Controller" "Provides customers with a summary of their bank accounts." "Spring MVC Rest Controller"
resetPasswordController = component "Reset Password Controller" "Allows users to reset their passwords with a single use URL." "Spring MVC Rest Controller"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package nl.avisi.structurizr.site.generatr
import com.structurizr.Workspace
import com.structurizr.model.Container
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
Expand All @@ -26,8 +27,8 @@ fun Workspace.listIndexViewEnabled(
val SoftwareSystem.hasContainers
get() = this.containers.isNotEmpty()

val SoftwareSystem.includedProperties
get() = this.properties.filterNot { (name, _) -> name == "structurizr.dsl.identifier" }
val StaticStructureElement.includedProperties
get() = this.properties.filterNot { (name, _) -> name.startsWith("structurizr.") or name.startsWith("generatr.") }

val Container.hasComponents
get() = this.components.isNotEmpty()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import kotlinx.html.*
import kotlinx.html.stream.appendHTML
import nl.avisi.structurizr.site.generatr.hasComponentDiagrams
import nl.avisi.structurizr.site.generatr.hasImageViews
import nl.avisi.structurizr.site.generatr.includedProperties
import nl.avisi.structurizr.site.generatr.includedSoftwareSystems
import nl.avisi.structurizr.site.generatr.site.model.*
import nl.avisi.structurizr.site.generatr.site.views.*
Expand Down Expand Up @@ -174,6 +175,7 @@ private fun generateHtmlFiles(context: GeneratorContext, branchDir: File) {
it.containers
.filter { container ->
context.workspace.hasComponentDiagrams(container) or
container.includedProperties.isNotEmpty() or
context.workspace.hasImageViews(container.id) }
.forEach { container ->
add { writeHtmlFile(branchDir, SoftwareSystemContainerComponentsPageViewModel(context, container)) } }
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 com.structurizr.model.SoftwareSystem
import nl.avisi.structurizr.site.generatr.hasComponentDiagrams
import nl.avisi.structurizr.site.generatr.hasImageViews
import nl.avisi.structurizr.site.generatr.includedProperties
import nl.avisi.structurizr.site.generatr.site.GeneratorContext

fun SoftwareSystemPageViewModel.createContainersComponentTabViewModel(
Expand All @@ -13,7 +14,8 @@ fun SoftwareSystemPageViewModel.createContainersComponentTabViewModel(
.containers
.sortedBy { it.name }
.filter { container ->
generatorContext.workspace.hasComponentDiagrams(container) or
container.includedProperties.isNotEmpty() or
generatorContext.workspace.hasComponentDiagrams(container) or
generatorContext.workspace.hasImageViews(container.id) }
.map {
ContainerTabViewModel(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,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 @@ -17,7 +18,9 @@ class SoftwareSystemContainerComponentsPageViewModel(generatorContext: Generator
.sortedBy { it.key }
.map { ImageViewViewModel(it) }

val visible = diagrams.isNotEmpty() or images.isNotEmpty()
val hasProperties = container.includedProperties.isNotEmpty()
val propertiesTable = createPropertiesTableViewModel(container.includedProperties)
val visible = diagrams.isNotEmpty() or images.isNotEmpty() or hasProperties
val containerTabs = createContainersComponentTabViewModel(generatorContext, container.softwareSystem)
val diagramIndexListViewModel = DiagramIndexListViewModel(
diagrams,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package nl.avisi.structurizr.site.generatr.site.views

import kotlinx.html.HTML
import kotlinx.html.div
import kotlinx.html.li
import kotlinx.html.ul
import kotlinx.html.*
import nl.avisi.structurizr.site.generatr.site.model.SoftwareSystemContainerComponentsPageViewModel

fun HTML.softwareSystemContainerComponentsPage(viewModel: SoftwareSystemContainerComponentsPageViewModel) {
Expand All @@ -22,6 +19,11 @@ fun HTML.softwareSystemContainerComponentsPage(viewModel: SoftwareSystemContaine
diagramIndexList(viewModel.diagramIndexListViewModel)
viewModel.diagrams.forEach { diagram(it) }
viewModel.images.forEach { image(it) }

if(viewModel.hasProperties) {
h3 { +"Properties" }
table(viewModel.propertiesTable)
}
}
} else
redirectUpPage()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package nl.avisi.structurizr.site.generatr.site

import com.structurizr.Workspace
import nl.avisi.structurizr.site.generatr.includedProperties
import kotlin.test.Test
import kotlin.test.assertEquals

class StructurizrUtilitiesTest {

protected val svgFactory = { _: String, _: String -> "" }

protected fun generatorContext(
workspaceName: String = "Workspace name",
branches: List<String> = listOf("main"),
currentBranch: String = "main",
version: String = "1.0.0"
) = GeneratorContext(version, Workspace(workspaceName, ""), branches, currentBranch, false, svgFactory)

@Test
fun `includedProperties filters out structurizr and generatr properties`() {
val element = generatorContext().workspace.model.addSoftwareSystem("System 1")
element.addProperty("structurizr.key", "value")
element.addProperty("generatr.key", "value")
element.addProperty("structurizrnotquite.key", "value")
element.addProperty("generatrbut.not.key", "value")
element.addProperty("other.key", "value")

val includedProperties = element.includedProperties

assertEquals(3, includedProperties.size)
assertEquals(includedProperties.keys, setOf("structurizrnotquite.key", "generatrbut.not.key", "other.key"))
}

@Test
fun `includedProperties returns all properties when none are filtered out`() {
val element = generatorContext().workspace.model.addSoftwareSystem("System 1")
element.addProperty("key1", "value1")
element.addProperty("key2", "value2")

val includedProperties = element.includedProperties

assertEquals(2, includedProperties.size)
assertEquals("key1", includedProperties.keys.first())
assertEquals("key2", includedProperties.keys.last())
}

@Test
fun `includedProperties returns empty map when no properties are set`() {
val element = generatorContext().workspace.model.addSoftwareSystem("System 1")
val includedProperties = element.includedProperties
assertEquals(0, includedProperties.size)
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
package nl.avisi.structurizr.site.generatr.site.model

import assertk.assertThat
import assertk.assertions.containsExactly
import assertk.assertions.hasSize
import assertk.assertions.isEqualTo
import assertk.assertions.isFalse
import assertk.assertions.isTrue
import assertk.assertions.*
import com.structurizr.model.Container
import com.structurizr.model.SoftwareSystem
import nl.avisi.structurizr.site.generatr.normalize
import kotlin.test.Test
import kotlin.test.assertTrue

class SoftwareSystemContainerComponentsPageViewModelTest : ViewModelTest() {
private val generatorContext = generatorContext()
private val softwareSystem: SoftwareSystem = generatorContext.workspace.model
.addSoftwareSystem("Software system").also {
val backend = it.addContainer("Backend")
val frontend = it.addContainer("Frontend")
it.addContainer("Api").also { c ->
c.addProperty("test", "value")
}
generatorContext.workspace.views.createComponentView(backend, "component-1-backend", "Component view 1 - Backend")
generatorContext.workspace.views.createComponentView(backend, "component-2-backend", "Component view 2 - Backend")

Expand All @@ -26,6 +26,7 @@ class SoftwareSystemContainerComponentsPageViewModelTest : ViewModelTest() {

private val backendContainer: Container = softwareSystem.containers.elementAt(0)
private val frontendContainer: Container = softwareSystem.containers.elementAt(1)
private val apiContainer: Container = softwareSystem.containers.elementAt(2)
private val backendImageView = createImageView(generatorContext.workspace, backendContainer)
private val frontendImageView = createImageView(generatorContext.workspace, frontendContainer)

Expand All @@ -40,10 +41,12 @@ class SoftwareSystemContainerComponentsPageViewModelTest : ViewModelTest() {
fun `container tabs`() {
val viewModel = SoftwareSystemContainerComponentsPageViewModel(generatorContext, backendContainer)
val componentTabList = listOf(
ContainerTabViewModel(viewModel, "Api", "/software-system/component/api"),
ContainerTabViewModel(viewModel, "Backend", "/software-system/component/backend"),
ContainerTabViewModel(viewModel, "Frontend", "/software-system/component/frontend"))
assertThat(viewModel.containerTabs.elementAtOrNull(0)).isEqualTo(componentTabList.elementAt(0))
assertThat(viewModel.containerTabs.elementAtOrNull(1)).isEqualTo(componentTabList.elementAt(1))
assertThat(viewModel.containerTabs.elementAtOrNull(2)).isEqualTo(componentTabList.elementAt(2))
}

@Test
Expand Down Expand Up @@ -131,6 +134,15 @@ class SoftwareSystemContainerComponentsPageViewModelTest : ViewModelTest() {
assertThat(viewModel.images.single().imageView).isEqualTo(frontendImageView)
}

@Test
fun `has only properties`() {
val viewModel = SoftwareSystemContainerComponentsPageViewModel(generatorContext, apiContainer)
assertTrue(viewModel.visible)
assertThat(viewModel.propertiesTable.bodyRows).isNotEmpty()
assertThat(viewModel.images).isEmpty()
assertThat(viewModel.diagrams).isEmpty()
}

@Test
fun `hidden view`() {
val viewModel = SoftwareSystemContainerComponentsPageViewModel(generatorContext, softwareSystem.addContainer("Container"))
Expand Down

0 comments on commit b55d9a6

Please sign in to comment.