Skip to content

Commit 0ce177e

Browse files
authored
Merge pull request #515 from modelix/feature/delete-repo-via-web-ui
feat(model-server): Minor web UI improvements
2 parents c5de340 + 4ab2e10 commit 0ce177e

File tree

3 files changed

+53
-4
lines changed

3 files changed

+53
-4
lines changed

model-server-openapi/specifications/model-server-html.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,23 @@ paths:
3737
examples:
3838
Example#1:
3939
value: "../repos/"
40+
/content/{repository}/{branch}/latest:
41+
get:
42+
operationId: getContentRepositoryBranchLatest
43+
parameters:
44+
- name: repository
45+
in: "path"
46+
required: true
47+
schema:
48+
type: string
49+
- name: branch
50+
in: "path"
51+
required: true
52+
schema:
53+
type: string
54+
responses:
55+
"200":
56+
$ref: '#/components/responses/200'
4057
/content/{versionHash}:
4158
get:
4259
operationId: getVersionHash

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ import org.modelix.model.api.ITree
4343
import org.modelix.model.api.PNodeAdapter
4444
import org.modelix.model.api.TreePointer
4545
import org.modelix.model.client.IModelClient
46+
import org.modelix.model.lazy.BranchReference
4647
import org.modelix.model.lazy.CLVersion
48+
import org.modelix.model.lazy.RepositoryId
4749
import org.modelix.model.server.templates.PageWithMenuBar
4850
import kotlin.collections.set
4951

@@ -54,6 +56,26 @@ class ContentExplorer(private val client: IModelClient, private val repoManager:
5456
get<Paths.getContent> {
5557
call.respondRedirect("../repos/")
5658
}
59+
get<Paths.getContentRepositoryBranchLatest> {
60+
val repository = call.parameters["repository"]
61+
val branch = call.parameters["branch"]
62+
if (repository.isNullOrEmpty()) {
63+
call.respondText("repository not found", status = HttpStatusCode.BadRequest)
64+
return@get
65+
}
66+
if (branch.isNullOrEmpty()) {
67+
call.respondText("branch not found", status = HttpStatusCode.BadRequest)
68+
return@get
69+
}
70+
71+
val latestVersion = repoManager.getVersion(BranchReference(RepositoryId(repository), branch))
72+
if (latestVersion == null) {
73+
call.respondText("unable to find latest version", status = HttpStatusCode.InternalServerError)
74+
return@get
75+
} else {
76+
call.respondRedirect("../../../${latestVersion.getContentHash()}/")
77+
}
78+
}
5779
get<Paths.getVersionHash> {
5880
val versionHash = call.parameters["versionHash"]
5981
if (versionHash.isNullOrEmpty()) {

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ import io.ktor.server.routing.routing
99
import kotlinx.html.FlowContent
1010
import kotlinx.html.FlowOrInteractiveOrPhrasingContent
1111
import kotlinx.html.a
12+
import kotlinx.html.form
1213
import kotlinx.html.h1
1314
import kotlinx.html.i
1415
import kotlinx.html.p
16+
import kotlinx.html.postButton
1517
import kotlinx.html.span
1618
import kotlinx.html.table
1719
import kotlinx.html.tbody
@@ -48,7 +50,7 @@ class RepositoryOverview(private val repoManager: RepositoriesManager) {
4850
th { +"Repository" }
4951
th { +"Branch" }
5052
th {
51-
colSpan = "2"
53+
colSpan = "3"
5254
+"Actions"
5355
}
5456
}
@@ -67,6 +69,7 @@ class RepositoryOverview(private val repoManager: RepositoriesManager) {
6769
td { }
6870
td { }
6971
td { }
72+
td { }
7073
}
7174
} else {
7275
for (branch in branches) {
@@ -80,12 +83,19 @@ class RepositoryOverview(private val repoManager: RepositoriesManager) {
8083
buildHistoryLink(branch.repositoryId.id, branch.branchName)
8184
}
8285
td {
83-
val latestVersion = repoManager.getVersion(branch)
84-
?: throw RuntimeException("Branch not found: $branch")
85-
a("../content/${latestVersion.getContentHash()}/") {
86+
a("../content/$repository/${branch.branchName}/latest/") {
8687
+"Explore Latest Version"
8788
}
8889
}
90+
td {
91+
form {
92+
postButton {
93+
name = "delete"
94+
formAction = "../v2/repositories/${branch.repositoryId.id}/delete"
95+
+"Delete Repository"
96+
}
97+
}
98+
}
8999
}
90100
}
91101
}

0 commit comments

Comments
 (0)