Skip to content

Commit c0beae2

Browse files
committed
fix(model-server): add force-reload after repository deletion
1 parent c5378db commit c0beae2

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

model-server/src/main/kotlin/org/modelix/model/server/handlers/ui/RepositoryOverview.kt

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@ import kotlinx.html.FlowContent
1010
import kotlinx.html.FlowOrInteractiveOrPhrasingContent
1111
import kotlinx.html.a
1212
import kotlinx.html.button
13-
import kotlinx.html.form
1413
import kotlinx.html.h1
1514
import kotlinx.html.i
1615
import kotlinx.html.onClick
1716
import kotlinx.html.p
18-
import kotlinx.html.postButton
1917
import kotlinx.html.script
2018
import kotlinx.html.span
2119
import kotlinx.html.table
@@ -42,11 +40,18 @@ class RepositoryOverview(private val repoManager: IRepositoriesManager) {
4240
unsafe {
4341
+"""
4442
function removeBranch(repository, branch) {
45-
if (confirm('Are you sure you want to delete the branch' + branch +' of repository' +repository + '?')) {
43+
if (confirm('Are you sure you want to delete the branch ' + branch + ' of repository ' +repository + '?')) {
4644
fetch('../v2/repositories/' + repository + '/branches/' + branch, { method: 'DELETE'})
4745
.then( _ => location.reload())
4846
}
4947
}
48+
49+
function removeRepository(repository) {
50+
if (confirm('Are you sure you want to delete the repository ' + repository + '?')) {
51+
fetch('../v2/repositories/' + repository + '/delete', { method: 'POST'})
52+
.then( _ => location.reload())
53+
}
54+
}
5055
""".trimIndent()
5156
}
5257
}
@@ -138,13 +143,11 @@ internal fun FlowOrInteractiveOrPhrasingContent.buildExploreLatestLink(repositor
138143
}
139144

140145
internal fun FlowContent.buildDeleteRepositoryForm(repositoryId: String) {
141-
form {
142-
postButton {
143-
name = "delete"
144-
formAction = "../v2/repositories/${repositoryId.encodeURLPathPart()}/delete"
145-
onClick = "return confirm('Are you sure you want to delete the repository $repositoryId?')"
146-
+"Delete Repository"
147-
}
146+
button {
147+
name = "delete"
148+
formAction = "../v2/repositories/${repositoryId.encodeURLPathPart()}/delete"
149+
onClick = "return removeRepository('${repositoryId.encodeURLPathPart()}')"
150+
+"Delete Repository"
148151
}
149152
}
150153

model-server/src/test/kotlin/org/modelix/model/server/handlers/ui/RepositoryOverviewTest.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ class RepositoryOverviewTest {
4747
}
4848

4949
@Test
50-
fun `delete repository form action is encoded properly`() {
50+
fun `delete repository button parameters encoded properly`() {
5151
val html = createHTML(prettyPrint = false).span {
5252
buildDeleteRepositoryForm("repository/v1")
5353
}
5454

5555
val document = Jsoup.parse(html)
56-
val formAction = document.getElementsByTag("button").first()?.attribute("formaction")?.value
57-
assertEquals("../v2/repositories/repository%2Fv1/delete", formAction)
56+
val onClick = document.getElementsByTag("button").first()?.attribute("onclick")?.value
57+
assertEquals("return removeRepository('repository%2Fv1')", onClick)
5858
}
5959

6060
@Test

0 commit comments

Comments
 (0)