Skip to content

Commit 36ff0f0

Browse files
committed
WIP try to add progress polling
1 parent a96263e commit 36ff0f0

File tree

6 files changed

+76
-127
lines changed

6 files changed

+76
-127
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// package app.cash.backfila.ui
2+
//
3+
// class ProgressUpdater {
4+
// fun backfillProgress(backfillName: String, numerator: Number, denominator: Number): String {
5+
// println("Backfill $backfillName is ${numerator.toDouble() / denominator.toDouble() * 100}% complete")
6+
// }
7+
// }

service/src/main/kotlin/app/cash/backfila/ui/components/DashboardLayout.kt

Lines changed: 0 additions & 117 deletions
This file was deleted.

service/src/main/kotlin/app/cash/backfila/ui/components/DashboardPageLayout.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ class DashboardPageLayout @Inject constructor(
8484
type = "module"
8585
src = "/static/js/autocomplete_controller.js"
8686
}
87+
script {
88+
type = "module"
89+
src = "/static/js/auto_reload_controller.js"
90+
}
8791
script {
8892
type = "module"
8993
src = "/static/js/search_bar_controller.js"
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package app.cash.backfila.ui.components
2+
3+
import kotlin.math.round
4+
import kotlinx.html.TagConsumer
5+
import kotlinx.html.div
6+
import kotlinx.html.style
7+
8+
fun TagConsumer<*>.ProgressBarReloader(numerator: Number, denominator: Number) {
9+
div("w-full bg-gray-200 rounded-full dark:bg-gray-700") {
10+
val percentComplete = if (numerator.toInt() == 0) 0 else round((numerator.toDouble() / denominator.toDouble()) * 100)
11+
// Don't show blue sliver for 0%, just show the gray empty bar
12+
val showPartialBarStyle = if (percentComplete.toInt() != 0) "bg-blue-600" else ""
13+
div(
14+
"$showPartialBarStyle text-xs font-medium text-blue-100 text-center p-0.5 leading-none rounded-full",
15+
) {
16+
style = "width: ${if (percentComplete.toInt() == 0) 100 else percentComplete}%"
17+
+"""$percentComplete%"""
18+
}
19+
}
20+
}

service/src/main/kotlin/app/cash/backfila/ui/pages/ServiceShowAction.kt

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@ import app.cash.backfila.ui.components.PageTitle
77
import java.net.HttpURLConnection
88
import javax.inject.Inject
99
import javax.inject.Singleton
10-
import kotlinx.html.role
11-
import kotlinx.html.ul
10+
import kotlinx.html.div
11+
import misk.scope.ActionScoped
1212
import misk.security.authz.Authenticated
13+
import misk.tokens.TokenGenerator
14+
import misk.turbo.turbo_frame
1315
import misk.web.Get
16+
import misk.web.HttpCall
1417
import misk.web.PathParam
1518
import misk.web.QueryParam
1619
import misk.web.Response
@@ -23,9 +26,15 @@ import okhttp3.Headers
2326

2427
@Singleton
2528
class ServiceShowAction @Inject constructor(
26-
private val getBackfillRunsAction: GetBackfillRunsAction,
29+
private val clientHttpCall: ActionScoped<HttpCall>,
2730
private val dashboardPageLayout: DashboardPageLayout,
31+
private val getBackfillRunsAction: GetBackfillRunsAction,
32+
private val tokenGenerator: TokenGenerator,
2833
) : WebAction {
34+
private val path by lazy {
35+
clientHttpCall.get().url.encodedPath
36+
}
37+
2938
@Get(PATH)
3039
@ResponseContentType(MediaTypes.TEXT_HTML)
3140
@Authenticated(capabilities = ["users"])
@@ -50,15 +59,18 @@ class ServiceShowAction @Inject constructor(
5059
val htmlResponseBody = dashboardPageLayout.newBuilder()
5160
.title("$label | Backfila")
5261
.buildHtmlResponseBody {
53-
PageTitle("Service", label)
62+
div {
63+
attributes["data-controller"] = "auto-reload"
64+
attributes["data-auto-reload-target"] = "frame"
5465

55-
// TODO Add completed table
56-
// TODO Add deleted support?
57-
BackfillsTable(true, backfillRuns.running_backfills)
58-
BackfillsTable(false, backfillRuns.paused_backfills)
66+
PageTitle("Service", label)
5967

60-
ul("space-y-3") {
61-
role = "list"
68+
// TODO Add completed table
69+
// TODO Add deleted support?
70+
// turbo_frame(id = "backfill-tables", src = path.replace("services", "services/progress/${tokenGenerator.generate()}")) {
71+
BackfillsTable(true, backfillRuns.running_backfills)
72+
BackfillsTable(false, backfillRuns.paused_backfills)
73+
// }
6274
}
6375
}
6476

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { Application, Controller } from "../cache/stimulus/3.1.0/stimulus.min.js";
2+
window.Stimulus = Application.start();
3+
4+
Stimulus.register("auto-reload", class extends Controller {
5+
static targets = ["frame"];
6+
7+
connect() {
8+
console.log("Auto-reload connected...");
9+
this.reloadInterval = setInterval(() => {
10+
console.log("Reloading Turbo Frame...");
11+
this.reloadFrame();
12+
}, 5000); // 5000 milliseconds = 5 seconds
13+
}
14+
15+
disconnect() {
16+
console.log("Clearing auto-reload interval...");
17+
clearInterval(this.reloadInterval);
18+
}
19+
20+
reloadFrame() {
21+
this.frameTarget.src = this.frameTarget.src;
22+
}
23+
});

0 commit comments

Comments
 (0)