@@ -9,12 +9,14 @@ import io.ktor.server.routing.routing
9
9
import kotlinx.html.FlowContent
10
10
import kotlinx.html.FlowOrInteractiveOrPhrasingContent
11
11
import kotlinx.html.a
12
+ import kotlinx.html.button
12
13
import kotlinx.html.form
13
14
import kotlinx.html.h1
14
15
import kotlinx.html.i
15
16
import kotlinx.html.onClick
16
17
import kotlinx.html.p
17
18
import kotlinx.html.postButton
19
+ import kotlinx.html.script
18
20
import kotlinx.html.span
19
21
import kotlinx.html.table
20
22
import kotlinx.html.tbody
@@ -23,6 +25,8 @@ import kotlinx.html.th
23
25
import kotlinx.html.thead
24
26
import kotlinx.html.title
25
27
import kotlinx.html.tr
28
+ import kotlinx.html.unsafe
29
+ import org.modelix.model.lazy.RepositoryId
26
30
import org.modelix.model.server.handlers.IRepositoriesManager
27
31
import org.modelix.model.server.templates.PageWithMenuBar
28
32
@@ -32,7 +36,21 @@ class RepositoryOverview(private val repoManager: IRepositoriesManager) {
32
36
application.routing {
33
37
get(" /repos" ) {
34
38
call.respondHtmlTemplate(PageWithMenuBar (" repos/" , " .." )) {
35
- headContent { title(" Repositories" ) }
39
+ headContent {
40
+ title(" Repositories" )
41
+ script(type = " text/javascript" ) {
42
+ unsafe {
43
+ + """
44
+ function removeBranch(repository, branch) {
45
+ if (confirm('Are you sure you want to delete the branch' + branch +' of repository' +repository + '?')) {
46
+ fetch('../v2/repositories/' + repository + '/branches/' + branch, { method: 'DELETE'})
47
+ .then( _ => location.reload())
48
+ }
49
+ }
50
+ """ .trimIndent()
51
+ }
52
+ }
53
+ }
36
54
bodyContent { buildMainPage() }
37
55
}
38
56
}
@@ -89,10 +107,13 @@ class RepositoryOverview(private val repoManager: IRepositoriesManager) {
89
107
}
90
108
}
91
109
td {
92
- buildHistoryLink(branch.repositoryId .id, branch.branchName)
110
+ buildHistoryLink(repository .id, branch.branchName)
93
111
}
94
112
td {
95
- buildExploreLatestLink(branch.repositoryId.id, branch.branchName)
113
+ buildExploreLatestLink(repository.id, branch.branchName)
114
+ }
115
+ td {
116
+ buildDeleteBranchButton(repository.id, branch.branchName)
96
117
}
97
118
}
98
119
}
@@ -104,19 +125,19 @@ class RepositoryOverview(private val repoManager: IRepositoriesManager) {
104
125
}
105
126
}
106
127
107
- fun FlowOrInteractiveOrPhrasingContent.buildHistoryLink (repositoryId : String , branchName : String ) {
128
+ internal fun FlowOrInteractiveOrPhrasingContent.buildHistoryLink (repositoryId : String , branchName : String ) {
108
129
a(" ../history/${repositoryId.encodeURLPathPart()} /${branchName.encodeURLPathPart()} /" ) {
109
130
+ " Show History"
110
131
}
111
132
}
112
133
113
- fun FlowOrInteractiveOrPhrasingContent.buildExploreLatestLink (repositoryId : String , branchName : String ) {
134
+ internal fun FlowOrInteractiveOrPhrasingContent.buildExploreLatestLink (repositoryId : String , branchName : String ) {
114
135
a(" ../content/repositories/${repositoryId.encodeURLPathPart()} /branches/${branchName.encodeURLPathPart()} /latest/" ) {
115
136
+ " Explore Latest Version"
116
137
}
117
138
}
118
139
119
- fun FlowContent.buildDeleteRepositoryForm (repositoryId : String ) {
140
+ internal fun FlowContent.buildDeleteRepositoryForm (repositoryId : String ) {
120
141
form {
121
142
postButton {
122
143
name = " delete"
@@ -126,3 +147,11 @@ fun FlowContent.buildDeleteRepositoryForm(repositoryId: String) {
126
147
}
127
148
}
128
149
}
150
+
151
+ internal fun FlowContent.buildDeleteBranchButton (repositoryId : String , branchName : String ) {
152
+ if (branchName == RepositoryId .DEFAULT_BRANCH ) return
153
+ button {
154
+ onClick = " return removeBranch('${repositoryId.encodeURLPathPart()} ', '${branchName.encodeURLPathPart()} ')"
155
+ + " Delete Branch"
156
+ }
157
+ }
0 commit comments