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

Redirect to software system home on hidden tabs #101

Merged
merged 1 commit into from
Nov 29, 2022
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -3,9 +3,26 @@ package nl.avisi.structurizr.site.generatr
import com.structurizr.model.Location
import com.structurizr.model.Model
import com.structurizr.model.SoftwareSystem
import com.structurizr.view.ViewSet

val Model.includedSoftwareSystems: List<SoftwareSystem>
get() = softwareSystems.filter { it.includedSoftwareSystem }

val SoftwareSystem.includedSoftwareSystem
get () = this.location != Location.External
get() = this.location != Location.External

fun SoftwareSystem.hasDecisions() = documentation.decisions.isNotEmpty()

fun SoftwareSystem.hasDocumentationSections() = documentation.sections.size >= 2

fun ViewSet.hasSystemContextViews(softwareSystem: SoftwareSystem) =
systemContextViews.any { it.softwareSystem == softwareSystem }

fun ViewSet.hasContainerViews(softwareSystem: SoftwareSystem) =
containerViews.any { it.softwareSystem == softwareSystem }

fun ViewSet.hasComponentViews(softwareSystem: SoftwareSystem) =
componentViews.any { it.softwareSystem == softwareSystem }

fun ViewSet.hasDeploymentViews(softwareSystem: SoftwareSystem) =
deploymentViews.any { it.softwareSystem == softwareSystem }
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ fun generateSite(
private fun deleteOldHashes(exportDir: File) = exportDir.walk().filter { it.extension == "md5" }
.forEach { it.delete() }


private fun copyAssets(assetsDir: File, exportDir: File) {
assetsDir.copyRecursively(exportDir, overwrite = true)
}
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.SoftwareSystem
import nl.avisi.structurizr.site.generatr.hasComponentViews
import nl.avisi.structurizr.site.generatr.site.GeneratorContext

class SoftwareSystemComponentPageViewModel(generatorContext: GeneratorContext, softwareSystem: SoftwareSystem) :
Expand All @@ -9,4 +10,5 @@ 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)
}
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.SoftwareSystem
import nl.avisi.structurizr.site.generatr.hasContainerViews
import nl.avisi.structurizr.site.generatr.site.GeneratorContext

class SoftwareSystemContainerPageViewModel(generatorContext: GeneratorContext, softwareSystem: SoftwareSystem) :
Expand All @@ -9,4 +10,5 @@ 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)
}
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.SoftwareSystem
import nl.avisi.structurizr.site.generatr.hasSystemContextViews
import nl.avisi.structurizr.site.generatr.site.GeneratorContext

class SoftwareSystemContextPageViewModel(generatorContext: GeneratorContext, softwareSystem: SoftwareSystem) :
Expand All @@ -9,4 +10,5 @@ class SoftwareSystemContextPageViewModel(generatorContext: GeneratorContext, sof
.filter { it.softwareSystem == softwareSystem }
.sortedBy { it.key }
.map { DiagramViewModel.forView(this, it, generatorContext.svgFactory) }
val visible = generatorContext.workspace.views.hasSystemContextViews(softwareSystem)
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package nl.avisi.structurizr.site.generatr.site.model

import com.structurizr.model.SoftwareSystem
import nl.avisi.structurizr.site.generatr.hasDecisions
import nl.avisi.structurizr.site.generatr.site.GeneratorContext

class SoftwareSystemDecisionsPageViewModel(generatorContext: GeneratorContext, softwareSystem: SoftwareSystem) :
SoftwareSystemPageViewModel(generatorContext, softwareSystem, Tab.DECISIONS) {
val decisionsTable = createDecisionsTableViewModel(softwareSystem.documentation.decisions) {
"$url/${it.id}"
}
val visible = softwareSystem.hasDecisions()
}
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.SoftwareSystem
import nl.avisi.structurizr.site.generatr.hasDeploymentViews
import nl.avisi.structurizr.site.generatr.site.GeneratorContext

class SoftwareSystemDeploymentPageViewModel(generatorContext: GeneratorContext, softwareSystem: SoftwareSystem) :
Expand All @@ -9,4 +10,5 @@ class SoftwareSystemDeploymentPageViewModel(generatorContext: GeneratorContext,
.filter { it.softwareSystem == softwareSystem }
.sortedBy { it.key }
.map { DiagramViewModel.forView(this, it, generatorContext.svgFactory) }
val visible = generatorContext.workspace.views.hasDeploymentViews(softwareSystem)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
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.hasContainerViews
import nl.avisi.structurizr.site.generatr.hasDecisions
import nl.avisi.structurizr.site.generatr.hasDeploymentViews
import nl.avisi.structurizr.site.generatr.hasDocumentationSections
import nl.avisi.structurizr.site.generatr.hasSystemContextViews
import nl.avisi.structurizr.site.generatr.normalize
import nl.avisi.structurizr.site.generatr.site.GeneratorContext

Expand Down Expand Up @@ -30,12 +36,12 @@ open class SoftwareSystemPageViewModel(
get() = when (tab) {
Tab.HOME -> true
Tab.DEPENDENCIES -> true
Tab.SYSTEM_CONTEXT -> generatorContext.workspace.views.systemContextViews.any { it.softwareSystem == softwareSystem }
Tab.CONTAINER -> generatorContext.workspace.views.containerViews.any { it.softwareSystem == softwareSystem }
Tab.COMPONENT -> generatorContext.workspace.views.componentViews.any { it.softwareSystem == softwareSystem }
Tab.DEPLOYMENT -> generatorContext.workspace.views.deploymentViews.any { it.softwareSystem == softwareSystem }
Tab.DECISIONS -> softwareSystem.documentation.decisions.isNotEmpty()
Tab.SECTIONS -> softwareSystem.documentation.sections.size >= 2
Tab.SYSTEM_CONTEXT -> generatorContext.workspace.views.hasSystemContextViews(softwareSystem)
Tab.CONTAINER -> generatorContext.workspace.views.hasContainerViews(softwareSystem)
Tab.COMPONENT -> generatorContext.workspace.views.hasComponentViews(softwareSystem)
Tab.DEPLOYMENT -> generatorContext.workspace.views.hasDeploymentViews(softwareSystem)
Tab.DECISIONS -> softwareSystem.hasDecisions()
Tab.SECTIONS -> softwareSystem.hasDocumentationSections()
}
}

Expand All @@ -50,7 +56,7 @@ open class SoftwareSystemPageViewModel(
TabViewModel(Tab.DEPLOYMENT),
TabViewModel(Tab.DEPENDENCIES),
TabViewModel(Tab.DECISIONS, exactLink = false),
TabViewModel(Tab.SECTIONS, exactLink = false),
TabViewModel(Tab.SECTIONS, exactLink = false)
)

val description: String = softwareSystem.description
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package nl.avisi.structurizr.site.generatr.site.model

import com.structurizr.model.SoftwareSystem
import nl.avisi.structurizr.site.generatr.hasDocumentationSections
import nl.avisi.structurizr.site.generatr.site.GeneratorContext

class SoftwareSystemSectionsPageViewModel(generatorContext: GeneratorContext, softwareSystem: SoftwareSystem) :
SoftwareSystemPageViewModel(generatorContext, softwareSystem, Tab.SECTIONS) {
val sectionsTable = createSectionsTableViewModel(softwareSystem.documentation.sections) {
"$url/${it.order}"
}
val visible = softwareSystem.hasDocumentationSections()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package nl.avisi.structurizr.site.generatr.site.views

import kotlinx.html.HTML
import kotlinx.html.body
import kotlinx.html.head
import kotlinx.html.meta
import kotlinx.html.title

fun HTML.redirectUpPage() {
attributes["lang"] = "en"
head {
meta {
httpEquiv = "refresh"
content = "0; url=../"
}
title { +"Structurizr site generatr" }
}
body()
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ import kotlinx.html.HTML
import nl.avisi.structurizr.site.generatr.site.model.SoftwareSystemComponentPageViewModel

fun HTML.softwareSystemComponentPage(viewModel: SoftwareSystemComponentPageViewModel) {
softwareSystemPage(viewModel) {
viewModel.diagrams.forEach {
diagram(it)
if (viewModel.visible)
softwareSystemPage(viewModel) {
viewModel.diagrams.forEach {
diagram(it)
}
}
}
else
redirectUpPage()
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ import kotlinx.html.HTML
import nl.avisi.structurizr.site.generatr.site.model.SoftwareSystemContainerPageViewModel

fun HTML.softwareSystemContainerPage(viewModel: SoftwareSystemContainerPageViewModel) {
softwareSystemPage(viewModel) {
viewModel.diagrams.forEach {
diagram(it)
if (viewModel.visible)
softwareSystemPage(viewModel) {
viewModel.diagrams.forEach {
diagram(it)
}
}
}
else
redirectUpPage()
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ import kotlinx.html.HTML
import nl.avisi.structurizr.site.generatr.site.model.SoftwareSystemContextPageViewModel

fun HTML.softwareSystemContextPage(viewModel: SoftwareSystemContextPageViewModel) {
softwareSystemPage(viewModel) {
viewModel.diagrams.forEach {
diagram(it)
if (viewModel.visible)
softwareSystemPage(viewModel) {
viewModel.diagrams.forEach {
diagram(it)
}
}
}
else
redirectUpPage()
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import kotlinx.html.HTML
import nl.avisi.structurizr.site.generatr.site.model.SoftwareSystemDecisionsPageViewModel

fun HTML.softwareSystemDecisionsPage(viewModel: SoftwareSystemDecisionsPageViewModel) {
softwareSystemPage(viewModel) {
table(viewModel.decisionsTable)
}
if (viewModel.visible)
softwareSystemPage(viewModel) {
table(viewModel.decisionsTable)
}
else
redirectUpPage()
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ import kotlinx.html.HTML
import nl.avisi.structurizr.site.generatr.site.model.SoftwareSystemDeploymentPageViewModel

fun HTML.softwareSystemDeploymentPage(viewModel: SoftwareSystemDeploymentPageViewModel) {
softwareSystemPage(viewModel) {
viewModel.diagrams.forEach {
diagram(it)
if (viewModel.visible)
softwareSystemPage(viewModel) {
viewModel.diagrams.forEach {
diagram(it)
}
}
}
else
redirectUpPage()
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import kotlinx.html.HTML
import nl.avisi.structurizr.site.generatr.site.model.SoftwareSystemSectionsPageViewModel

fun HTML.softwareSystemSectionsPage(viewModel: SoftwareSystemSectionsPageViewModel) {
softwareSystemPage(viewModel) {
table(viewModel.sectionsTable)
}
if (viewModel.visible)
softwareSystemPage(viewModel) {
table(viewModel.sectionsTable)
}
else
redirectUpPage()
}
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.isEqualTo
import assertk.assertions.isFalse
import com.structurizr.model.SoftwareSystem
import kotlin.test.Test

Expand Down Expand Up @@ -48,4 +49,14 @@ class SoftwareSystemComponentPageViewModelTest : ViewModelTest() {
)
)
}

@Test
fun `hidden view`() {
val viewModel = SoftwareSystemComponentPageViewModel(
generatorContext,
generatorContext.workspace.model.addSoftwareSystem("Software system 2")
)

assertThat(viewModel.visible).isFalse()
}
}
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.isEqualTo
import assertk.assertions.isFalse
import com.structurizr.model.SoftwareSystem
import kotlin.test.Test

Expand Down Expand Up @@ -47,4 +48,14 @@ class SoftwareSystemContainerPageViewModelTest : ViewModelTest() {
)
)
}

@Test
fun `hidden view`() {
val viewModel = SoftwareSystemContainerPageViewModel(
generatorContext,
generatorContext.workspace.model.addSoftwareSystem("Software system 2")
)

assertThat(viewModel.visible).isFalse()
}
}
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 assertk.assertThat
import assertk.assertions.containsExactly
import assertk.assertions.isFalse
import com.structurizr.model.SoftwareSystem
import kotlin.test.Test

Expand Down Expand Up @@ -38,4 +39,14 @@ class SoftwareSystemContextPageViewModelTest : ViewModelTest() {
)
)
}

@Test
fun `hidden view`() {
val viewModel = SoftwareSystemContextPageViewModel(
generatorContext,
generatorContext.workspace.model.addSoftwareSystem("Software system 2")
)

assertThat(viewModel.visible).isFalse()
}
}
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 assertk.assertThat
import assertk.assertions.isEqualTo
import assertk.assertions.isFalse
import nl.avisi.structurizr.site.generatr.normalize
import kotlin.test.Test

Expand Down Expand Up @@ -30,4 +31,14 @@ class SoftwareSystemDecisionsPageViewModelTest : ViewModelTest() {
}
)
}

@Test
fun `hidden view`() {
val viewModel = SoftwareSystemDecisionsPageViewModel(
generatorContext,
generatorContext.workspace.model.addSoftwareSystem("Software system 2")
)

assertThat(viewModel.visible).isFalse()
}
}
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.isEqualTo
import assertk.assertions.isFalse
import com.structurizr.model.SoftwareSystem
import kotlin.test.Test

Expand Down Expand Up @@ -47,4 +48,14 @@ class SoftwareSystemDeploymentPageViewModelTest : ViewModelTest() {
)
)
}

@Test
fun `hidden view`() {
val viewModel = SoftwareSystemDeploymentPageViewModel(
generatorContext,
generatorContext.workspace.model.addSoftwareSystem("Software system 2")
)

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