diff --git a/src/main/kotlin/nl/avisi/structurizr/site/generatr/StructurizrUtilities.kt b/src/main/kotlin/nl/avisi/structurizr/site/generatr/StructurizrUtilities.kt index bf3fe669..6fad37aa 100644 --- a/src/main/kotlin/nl/avisi/structurizr/site/generatr/StructurizrUtilities.kt +++ b/src/main/kotlin/nl/avisi/structurizr/site/generatr/StructurizrUtilities.kt @@ -4,7 +4,9 @@ import com.structurizr.model.Container import com.structurizr.model.Location import com.structurizr.model.Model import com.structurizr.model.SoftwareSystem +import com.structurizr.view.ImageView import com.structurizr.view.ViewSet +import nl.avisi.structurizr.site.generatr.site.GeneratorContext val Model.includedSoftwareSystems: List get() = softwareSystems.filter { it.includedSoftwareSystem } @@ -48,5 +50,28 @@ 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} +fun getImagesForSystem(generatorContext: GeneratorContext, softwareSystem: SoftwareSystem): List { + return generatorContext.workspace.views.imageViews + .filter { it.elementId == softwareSystem.id } + .sortedBy { it.key } +} + +fun getImagesForContainer(generatorContext: GeneratorContext, softwareSystem: SoftwareSystem): List { + val images = mutableListOf() + softwareSystem.containers.forEach{ container -> + images += generatorContext.workspace.views.imageViews + .filter { it.elementId == container.id } + } + return images +} + +fun getImagesForComponent(generatorContext: GeneratorContext, softwareSystem: SoftwareSystem): List { + val images = mutableListOf() + softwareSystem.containers.forEach { container -> + container.components.forEach { component -> + images += generatorContext.workspace.views.imageViews + .filter { it.elementId == component.id } + } + } + return images +} diff --git a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/SiteGenerator.kt b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/SiteGenerator.kt index 9dd41dca..b1c7dac2 100644 --- a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/SiteGenerator.kt +++ b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/SiteGenerator.kt @@ -134,6 +134,7 @@ private fun generateHtmlFiles(context: GeneratorContext, branchDir: File) { add { writeHtmlFile(branchDir, SoftwareSystemContextPageViewModel(context, it)) } add { writeHtmlFile(branchDir, SoftwareSystemContainerPageViewModel(context, it)) } add { writeHtmlFile(branchDir, SoftwareSystemComponentPageViewModel(context, it)) } + add { writeHtmlFile(branchDir, SoftwareSystemCodePageViewModel(context, it)) } add { writeHtmlFile(branchDir, SoftwareSystemDynamicPageViewModel(context, it)) } add { writeHtmlFile(branchDir, SoftwareSystemDeploymentPageViewModel(context, it)) } add { writeHtmlFile(branchDir, SoftwareSystemDependenciesPageViewModel(context, it)) } @@ -187,6 +188,7 @@ private fun writeHtmlFile(exportDir: File, viewModel: PageViewModel) { is SoftwareSystemContainerSectionPageViewModel -> softwareSystemContainerSectionPage(viewModel) is SoftwareSystemContainerSectionsPageViewModel -> softwareSystemContainerSectionsPage(viewModel) is SoftwareSystemComponentPageViewModel -> softwareSystemComponentPage(viewModel) + is SoftwareSystemCodePageViewModel -> softwareSystemCodePage(viewModel) is SoftwareSystemDynamicPageViewModel -> softwareSystemDynamicPage(viewModel) is SoftwareSystemDeploymentPageViewModel -> softwareSystemDeploymentPage(viewModel) is SoftwareSystemDependenciesPageViewModel -> softwareSystemDependenciesPage(viewModel) diff --git a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemCodePageViewModel.kt b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemCodePageViewModel.kt new file mode 100644 index 00000000..6e89f4ae --- /dev/null +++ b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemCodePageViewModel.kt @@ -0,0 +1,13 @@ +package nl.avisi.structurizr.site.generatr.site.model + +import com.structurizr.model.SoftwareSystem +import nl.avisi.structurizr.site.generatr.getImagesForComponent +import nl.avisi.structurizr.site.generatr.site.GeneratorContext + +class SoftwareSystemCodePageViewModel(generatorContext: GeneratorContext, softwareSystem: SoftwareSystem) : + SoftwareSystemPageViewModel(generatorContext, softwareSystem, Tab.CODE) { + val images = getImagesForComponent(generatorContext,softwareSystem) + val imagesVisible = images.isNotEmpty() +} + + diff --git a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemComponentPageViewModel.kt b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemComponentPageViewModel.kt index 2d161668..cf3deb4e 100644 --- a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemComponentPageViewModel.kt +++ b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemComponentPageViewModel.kt @@ -1,8 +1,8 @@ package nl.avisi.structurizr.site.generatr.site.model import com.structurizr.model.SoftwareSystem +import nl.avisi.structurizr.site.generatr.getImagesForContainer 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) : @@ -11,9 +11,9 @@ class SoftwareSystemComponentPageViewModel(generatorContext: GeneratorContext, s .filter { it.softwareSystem == softwareSystem } .sortedBy { it.key } .map { DiagramViewModel.forView(this, it, generatorContext.svgFactory) } - val images = generatorContext.workspace.views.imageViews - .filter { it.elementId == softwareSystem.id } - .sortedBy { it.key } + val images = getImagesForContainer(generatorContext,softwareSystem) val diagramsVisible = generatorContext.workspace.views.hasComponentViews(softwareSystem) - val imagesVisible = generatorContext.workspace.views.hasElementImageViews(softwareSystem.id) + val imagesVisible = images.isNotEmpty() } + + diff --git a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemContainerPageViewModel.kt b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemContainerPageViewModel.kt index 61c50b5d..3993e559 100644 --- a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemContainerPageViewModel.kt +++ b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemContainerPageViewModel.kt @@ -1,8 +1,8 @@ package nl.avisi.structurizr.site.generatr.site.model import com.structurizr.model.SoftwareSystem +import nl.avisi.structurizr.site.generatr.getImagesForSystem 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) : @@ -11,9 +11,7 @@ class SoftwareSystemContainerPageViewModel(generatorContext: GeneratorContext, s .filter { it.softwareSystem == softwareSystem } .sortedBy { it.key } .map { DiagramViewModel.forView(this, it, generatorContext.svgFactory) } - val images = generatorContext.workspace.views.imageViews - .filter { it.elementId == softwareSystem.id } - .sortedBy { it.key } + val images = getImagesForSystem(generatorContext,softwareSystem) val diagramsVisible = generatorContext.workspace.views.hasContainerViews(softwareSystem) - val imagesVisible = generatorContext.workspace.views.hasElementImageViews(softwareSystem.id) + val imagesVisible = images.isNotEmpty() } diff --git a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemPageViewModel.kt b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemPageViewModel.kt index c163e39d..308f4764 100644 --- a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemPageViewModel.kt +++ b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemPageViewModel.kt @@ -9,7 +9,7 @@ open class SoftwareSystemPageViewModel( private val softwareSystem: SoftwareSystem, tab: Tab ) : PageViewModel(generatorContext) { - enum class Tab { HOME, SYSTEM_CONTEXT, CONTAINER, COMPONENT, DYNAMIC, DEPLOYMENT, DEPENDENCIES, DECISIONS, SECTIONS } + enum class Tab { HOME, SYSTEM_CONTEXT, CONTAINER, COMPONENT, CODE, DYNAMIC, DEPLOYMENT, DEPENDENCIES, DECISIONS, SECTIONS } inner class TabViewModel(val tab: Tab, exactLink: Boolean = true) { val link = LinkViewModel(this@SoftwareSystemPageViewModel, title, url(softwareSystem, tab), exactLink) @@ -20,6 +20,7 @@ open class SoftwareSystemPageViewModel( Tab.SYSTEM_CONTEXT -> "Context views" Tab.CONTAINER -> "Container views" Tab.COMPONENT -> "Component views" + Tab.CODE -> "Code views" Tab.DYNAMIC -> "Dynamic views" Tab.DEPLOYMENT -> "Deployment views" Tab.DEPENDENCIES -> "Dependencies" @@ -34,6 +35,8 @@ open class SoftwareSystemPageViewModel( Tab.SYSTEM_CONTEXT -> generatorContext.workspace.views.hasSystemContextViews(softwareSystem) Tab.CONTAINER -> generatorContext.workspace.views.hasContainerViews(softwareSystem) Tab.COMPONENT -> generatorContext.workspace.views.hasComponentViews(softwareSystem) + //TODO + Tab.CODE -> true Tab.DYNAMIC -> generatorContext.workspace.views.hasDynamicViews(softwareSystem) Tab.DEPLOYMENT -> generatorContext.workspace.views.hasDeploymentViews(softwareSystem) Tab.DECISIONS -> softwareSystem.hasDecisions() or softwareSystem.hasContainerDecisions() @@ -49,6 +52,7 @@ open class SoftwareSystemPageViewModel( TabViewModel(Tab.SYSTEM_CONTEXT), TabViewModel(Tab.CONTAINER), TabViewModel(Tab.COMPONENT), + TabViewModel(Tab.CODE), TabViewModel(Tab.DYNAMIC), TabViewModel(Tab.DEPLOYMENT), TabViewModel(Tab.DEPENDENCIES), @@ -66,6 +70,7 @@ open class SoftwareSystemPageViewModel( Tab.SYSTEM_CONTEXT -> "$home/context" Tab.CONTAINER -> "$home/container" Tab.COMPONENT -> "$home/component" + Tab.CODE -> "$home/code" Tab.DYNAMIC -> "$home/dynamic" Tab.DEPLOYMENT -> "$home/deployment" Tab.DEPENDENCIES -> "$home/dependencies" diff --git a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/views/rawImage.kt b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/views/RawImage.kt similarity index 100% rename from src/main/kotlin/nl/avisi/structurizr/site/generatr/site/views/rawImage.kt rename to src/main/kotlin/nl/avisi/structurizr/site/generatr/site/views/RawImage.kt diff --git a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/views/SoftwareSystemCodePage.kt b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/views/SoftwareSystemCodePage.kt new file mode 100644 index 00000000..70c04c52 --- /dev/null +++ b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/views/SoftwareSystemCodePage.kt @@ -0,0 +1,15 @@ +package nl.avisi.structurizr.site.generatr.site.views + +import kotlinx.html.HTML +import nl.avisi.structurizr.site.generatr.site.model.SoftwareSystemCodePageViewModel + +fun HTML.softwareSystemCodePage(viewModel: SoftwareSystemCodePageViewModel) { + if (viewModel.imagesVisible) { + softwareSystemPage(viewModel) { + viewModel.images.forEach { + rawImage(it.content) + } + } + } else + redirectUpPage() +} diff --git a/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemPageViewModelTest.kt b/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemPageViewModelTest.kt index d1b35d19..15378f57 100644 --- a/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemPageViewModelTest.kt +++ b/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemPageViewModelTest.kt @@ -61,6 +61,7 @@ class SoftwareSystemPageViewModelTest : ViewModelTest() { Tab.SYSTEM_CONTEXT, Tab.CONTAINER, Tab.COMPONENT, + Tab.CODE, Tab.DYNAMIC, Tab.DEPLOYMENT, Tab.DEPENDENCIES, @@ -73,6 +74,7 @@ class SoftwareSystemPageViewModelTest : ViewModelTest() { "Context views", "Container views", "Component views", + "Code views", "Dynamic views", "Deployment views", "Dependencies",