Skip to content

Commit

Permalink
Start of support for imageViews.
Browse files Browse the repository at this point in the history
Image Views associated with Software Systems will show on the Containers View page.
  • Loading branch information
qtzar committed Oct 23, 2023
1 parent e9e3ac7 commit 73ce67a
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 10 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions docs/example/workspace.dsl
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,18 @@ workspace "Big Bank plc" "This is an example workspace to illustrate the key fea
"generatr.markdown.flexmark.extensions" "Abbreviation,Admonition,AnchorLink,Attributes,Autolink,Definition,Emoji,Footnotes,GfmTaskList,GitLab,MediaTags,Tables,TableOfContents,Typographic"
}

image internetBankingSystem {
image internet-banking-system/images/system.png
}

image apiApplication {
image internet-banking-system/images/container.png
}

image accountsSummaryController {
image internet-banking-system/images/component.png
}

systemlandscape "SystemLandscape" {
include *
autoLayout
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,6 @@ fun ViewSet.hasDynamicViews(softwareSystem: SoftwareSystem) =

fun ViewSet.hasDeploymentViews(softwareSystem: SoftwareSystem) =
deploymentViews.any { it.softwareSystem == softwareSystem }

fun ViewSet.hasElementImageViews(elementId: String) =
imageViews.any { it.elementId == elementId}
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.hasComponentViews
import nl.avisi.structurizr.site.generatr.hasElementImageViews
import nl.avisi.structurizr.site.generatr.site.GeneratorContext

class SoftwareSystemComponentPageViewModel(generatorContext: GeneratorContext, softwareSystem: SoftwareSystem) :
Expand All @@ -10,5 +11,9 @@ class SoftwareSystemComponentPageViewModel(generatorContext: GeneratorContext, s
.filter { it.softwareSystem == softwareSystem }
.sortedBy { it.key }
.map { DiagramViewModel.forView(this, it, generatorContext.svgFactory) }
val visible = generatorContext.workspace.views.hasComponentViews(softwareSystem)
val images = generatorContext.workspace.views.imageViews
.filter { it.elementId == softwareSystem.id }
.sortedBy { it.key }
val diagramsVisible = generatorContext.workspace.views.hasComponentViews(softwareSystem)
val imagesVisible = generatorContext.workspace.views.hasElementImageViews(softwareSystem.id)
}
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.hasElementImageViews
import nl.avisi.structurizr.site.generatr.site.GeneratorContext

class SoftwareSystemContainerPageViewModel(generatorContext: GeneratorContext, softwareSystem: SoftwareSystem) :
Expand All @@ -10,5 +11,9 @@ class SoftwareSystemContainerPageViewModel(generatorContext: GeneratorContext, s
.filter { it.softwareSystem == softwareSystem }
.sortedBy { it.key }
.map { DiagramViewModel.forView(this, it, generatorContext.svgFactory) }
val visible = generatorContext.workspace.views.hasContainerViews(softwareSystem)
val images = generatorContext.workspace.views.imageViews
.filter { it.elementId == softwareSystem.id }
.sortedBy { it.key }
val diagramsVisible = generatorContext.workspace.views.hasContainerViews(softwareSystem)
val imagesVisible = generatorContext.workspace.views.hasElementImageViews(softwareSystem.id)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@ import kotlinx.html.HTML
import nl.avisi.structurizr.site.generatr.site.model.SoftwareSystemComponentPageViewModel

fun HTML.softwareSystemComponentPage(viewModel: SoftwareSystemComponentPageViewModel) {
if (viewModel.visible)
if (viewModel.diagramsVisible || viewModel.imagesVisible)
softwareSystemPage(viewModel) {
viewModel.diagrams.forEach {
diagram(it)
if (viewModel.diagramsVisible) {
viewModel.diagrams.forEach {
diagram(it)
}
}
if (viewModel.imagesVisible) {
viewModel.images.forEach {
rawImage(it.content)
}
}
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@ import kotlinx.html.HTML
import nl.avisi.structurizr.site.generatr.site.model.SoftwareSystemContainerPageViewModel

fun HTML.softwareSystemContainerPage(viewModel: SoftwareSystemContainerPageViewModel) {
if (viewModel.visible)
if (viewModel.diagramsVisible || viewModel.imagesVisible)
softwareSystemPage(viewModel) {
viewModel.diagrams.forEach {
diagram(it)
if (viewModel.diagramsVisible) {
viewModel.diagrams.forEach {
diagram(it)
}
}
if (viewModel.imagesVisible) {
viewModel.images.forEach {
rawImage(it.content)
}
}
}
else
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package nl.avisi.structurizr.site.generatr.site.views

import kotlinx.html.*

fun FlowContent.rawImage(data: String) {
img {
src = data
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ class SoftwareSystemComponentPageViewModelTest : ViewModelTest() {
generatorContext.workspace.model.addSoftwareSystem("Software system 2")
)

assertThat(viewModel.visible).isFalse()
assertThat(viewModel.diagramsVisible).isFalse()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@ class SoftwareSystemContainerPageViewModelTest : ViewModelTest() {
generatorContext.workspace.model.addSoftwareSystem("Software system 2")
)

assertThat(viewModel.visible).isFalse()
assertThat(viewModel.diagramsVisible).isFalse()
}
}

0 comments on commit 73ce67a

Please sign in to comment.