@@ -9,11 +9,12 @@ 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.form
12
+ import kotlinx.html.button
13
13
import kotlinx.html.h1
14
14
import kotlinx.html.i
15
+ import kotlinx.html.onClick
15
16
import kotlinx.html.p
16
- import kotlinx.html.postButton
17
+ import kotlinx.html.script
17
18
import kotlinx.html.span
18
19
import kotlinx.html.table
19
20
import kotlinx.html.tbody
@@ -22,6 +23,8 @@ import kotlinx.html.th
22
23
import kotlinx.html.thead
23
24
import kotlinx.html.title
24
25
import kotlinx.html.tr
26
+ import kotlinx.html.unsafe
27
+ import org.modelix.model.lazy.RepositoryId
25
28
import org.modelix.model.server.handlers.IRepositoriesManager
26
29
import org.modelix.model.server.templates.PageWithMenuBar
27
30
@@ -31,7 +34,28 @@ class RepositoryOverview(private val repoManager: IRepositoriesManager) {
31
34
application.routing {
32
35
get(" /repos" ) {
33
36
call.respondHtmlTemplate(PageWithMenuBar (" repos/" , " .." )) {
34
- headContent { title(" Repositories" ) }
37
+ headContent {
38
+ title(" Repositories" )
39
+ script(type = " text/javascript" ) {
40
+ unsafe {
41
+ + """
42
+ function removeBranch(repository, branch) {
43
+ if (confirm('Are you sure you want to delete the branch ' + branch + ' of repository ' +repository + '?')) {
44
+ fetch('../v2/repositories/' + repository + '/branches/' + branch, { method: 'DELETE'})
45
+ .then( _ => location.reload())
46
+ }
47
+ }
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
+ }
55
+ """ .trimIndent()
56
+ }
57
+ }
58
+ }
35
59
bodyContent { buildMainPage() }
36
60
}
37
61
}
@@ -47,7 +71,10 @@ class RepositoryOverview(private val repoManager: IRepositoriesManager) {
47
71
table {
48
72
thead {
49
73
tr {
50
- th { + " Repository" }
74
+ th {
75
+ colSpan = " 2"
76
+ + " Repository"
77
+ }
51
78
th { + " Branch" }
52
79
th {
53
80
colSpan = " 3"
@@ -58,11 +85,16 @@ class RepositoryOverview(private val repoManager: IRepositoriesManager) {
58
85
tbody {
59
86
for (repository in repositories) {
60
87
val branches = repoManager.getBranches(repository)
88
+ val repoRowSpan = branches.size.coerceAtLeast(1 ).plus(1 ).toString()
61
89
tr {
62
90
td {
63
- rowSpan = branches.size.coerceAtLeast( 1 ).plus( 1 ).toString()
91
+ rowSpan = repoRowSpan
64
92
+ repository.id
65
93
}
94
+ td {
95
+ rowSpan = repoRowSpan
96
+ buildDeleteRepositoryForm(repository.id)
97
+ }
66
98
}
67
99
if (branches.isEmpty()) {
68
100
tr {
@@ -80,13 +112,13 @@ class RepositoryOverview(private val repoManager: IRepositoriesManager) {
80
112
}
81
113
}
82
114
td {
83
- buildHistoryLink(branch.repositoryId .id, branch.branchName)
115
+ buildHistoryLink(repository .id, branch.branchName)
84
116
}
85
117
td {
86
- buildExploreLatestLink(branch.repositoryId .id, branch.branchName)
118
+ buildExploreLatestLink(repository .id, branch.branchName)
87
119
}
88
120
td {
89
- buildDeleteForm(branch.repositoryId.id )
121
+ buildDeleteBranchButton(repository.id, branch.branchName )
90
122
}
91
123
}
92
124
}
@@ -98,24 +130,31 @@ class RepositoryOverview(private val repoManager: IRepositoriesManager) {
98
130
}
99
131
}
100
132
101
- fun FlowOrInteractiveOrPhrasingContent.buildHistoryLink (repositoryId : String , branchName : String ) {
133
+ internal fun FlowOrInteractiveOrPhrasingContent.buildHistoryLink (repositoryId : String , branchName : String ) {
102
134
a(" ../history/${repositoryId.encodeURLPathPart()} /${branchName.encodeURLPathPart()} /" ) {
103
135
+ " Show History"
104
136
}
105
137
}
106
138
107
- fun FlowOrInteractiveOrPhrasingContent.buildExploreLatestLink (repositoryId : String , branchName : String ) {
139
+ internal fun FlowOrInteractiveOrPhrasingContent.buildExploreLatestLink (repositoryId : String , branchName : String ) {
108
140
a(" ../content/repositories/${repositoryId.encodeURLPathPart()} /branches/${branchName.encodeURLPathPart()} /latest/" ) {
109
141
+ " Explore Latest Version"
110
142
}
111
143
}
112
144
113
- fun FlowContent.buildDeleteForm (repositoryId : String ) {
114
- form {
115
- postButton {
116
- name = " delete"
117
- formAction = " ../v2/repositories/${repositoryId.encodeURLPathPart()} /delete"
118
- + " Delete Repository"
119
- }
145
+ internal fun FlowContent.buildDeleteRepositoryForm (repositoryId : String ) {
146
+ button {
147
+ name = " delete"
148
+ formAction = " ../v2/repositories/${repositoryId.encodeURLPathPart()} /delete"
149
+ onClick = " return removeRepository('${repositoryId.encodeURLPathPart()} ')"
150
+ + " Delete Repository"
151
+ }
152
+ }
153
+
154
+ internal fun FlowContent.buildDeleteBranchButton (repositoryId : String , branchName : String ) {
155
+ if (branchName == RepositoryId .DEFAULT_BRANCH ) return
156
+ button {
157
+ onClick = " return removeBranch('${repositoryId.encodeURLPathPart()} ', '${branchName.encodeURLPathPart()} ')"
158
+ + " Delete Branch"
120
159
}
121
160
}
0 commit comments