-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #333 from qtzar/DynamicDiagrams
Added support for Dynamic Diagrams
- Loading branch information
Showing
7 changed files
with
116 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
...otlin/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemDynamicPageViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
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.site.GeneratorContext | ||
|
||
class SoftwareSystemDynamicPageViewModel(generatorContext: GeneratorContext, softwareSystem: SoftwareSystem) : | ||
SoftwareSystemPageViewModel(generatorContext, softwareSystem, Tab.DYNAMIC) { | ||
val diagrams = generatorContext.workspace.views.dynamicViews | ||
.filter { it.softwareSystem == softwareSystem } | ||
.sortedBy { it.key } | ||
.map { DiagramViewModel.forView(this, it, generatorContext.svgFactory) } | ||
val visible = generatorContext.workspace.views.hasDynamicViews(softwareSystem) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/main/kotlin/nl/avisi/structurizr/site/generatr/site/views/SoftwareSystemDynamicPage.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package nl.avisi.structurizr.site.generatr.site.views | ||
|
||
import kotlinx.html.HTML | ||
import nl.avisi.structurizr.site.generatr.site.model.SoftwareSystemDynamicPageViewModel | ||
|
||
fun HTML.softwareSystemDynamicPage(viewModel: SoftwareSystemDynamicPageViewModel) { | ||
if (viewModel.visible) | ||
softwareSystemPage(viewModel) { | ||
viewModel.diagrams.forEach { | ||
diagram(it) | ||
} | ||
} | ||
else | ||
redirectUpPage() | ||
} |
63 changes: 63 additions & 0 deletions
63
...n/nl/avisi/structurizr/site/generatr/site/model/SoftwareSystemDynamicPageViewModelTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
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 | ||
|
||
class SoftwareSystemDynamicPageViewModelTest : 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") | ||
generatorContext.workspace.views.createDynamicView(backend, "backend-dynamic", "Dynamic view 1") | ||
generatorContext.workspace.views.createDynamicView(frontend, "frontend-dynamic", "Dynamic view 2") | ||
} | ||
|
||
@Test | ||
fun `active tab`() { | ||
val viewModel = SoftwareSystemDynamicPageViewModel(generatorContext, softwareSystem) | ||
|
||
assertThat(viewModel.tabs.single { it.link.active }.tab) | ||
.isEqualTo(SoftwareSystemPageViewModel.Tab.DYNAMIC) | ||
} | ||
|
||
@Test | ||
fun `diagrams sorted by key`() { | ||
val viewModel = SoftwareSystemDynamicPageViewModel(generatorContext, softwareSystem) | ||
|
||
assertThat(viewModel.diagrams).containsExactly( | ||
DiagramViewModel( | ||
"backend-dynamic", | ||
"Backend - Dynamic", | ||
"""<svg viewBox="0 0 800 900"></svg>""", | ||
800, | ||
ImageViewModel(viewModel, "/svg/backend-dynamic.svg"), | ||
ImageViewModel(viewModel, "/png/backend-dynamic.png"), | ||
ImageViewModel(viewModel, "/puml/backend-dynamic.puml") | ||
), | ||
DiagramViewModel( | ||
"frontend-dynamic", | ||
"Frontend - Dynamic", | ||
"""<svg viewBox="0 0 800 900"></svg>""", | ||
800, | ||
ImageViewModel(viewModel, "/svg/frontend-dynamic.svg"), | ||
ImageViewModel(viewModel, "/png/frontend-dynamic.png"), | ||
ImageViewModel(viewModel, "/puml/frontend-dynamic.puml") | ||
) | ||
) | ||
} | ||
|
||
@Test | ||
fun `hidden view`() { | ||
val viewModel = SoftwareSystemDynamicPageViewModel( | ||
generatorContext, | ||
generatorContext.workspace.model.addSoftwareSystem("Software system 2") | ||
) | ||
|
||
assertThat(viewModel.visible).isFalse() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters