This is an automated email from the ASF dual-hosted git repository.
joergrade pushed a commit to branch kvision-6-upgrade
in repository https://gitbox.apache.org/repos/asf/causeway.git
The following commit(s) were added to refs/heads/kvision-6-upgrade by this push:
new 96d2b1942a CAUSEWAY-3264 LogEntry icons refactored
96d2b1942a is described below
commit 96d2b1942ada728f55b7e0a59cba761a5ef6765d
Author: Jörg Rade <[email protected]>
AuthorDate: Sat Sep 9 00:35:44 2023 +0200
CAUSEWAY-3264 LogEntry icons refactored
---
.../causeway/client/kroviz/core/event/LogEntry.kt | 33 +++--
.../client/kroviz/ui/core/ColumnFactory.kt | 2 -
.../client/kroviz/ui/panel/EventLogTable.kt | 139 +++++++++------------
3 files changed, 82 insertions(+), 92 deletions(-)
diff --git
a/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/core/event/LogEntry.kt
b/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/core/event/LogEntry.kt
index d0bfd31c60..df4e67d0a3 100644
---
a/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/core/event/LogEntry.kt
+++
b/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/core/event/LogEntry.kt
@@ -53,13 +53,15 @@ enum class EventState(val id: String, val iconName: String,
val style: ButtonSty
@Serializable
data class LogEntry(
@Contextual val rs: ResourceSpecification,
- val method: String? = "",
- val request: String = "",
+ @Contextual val method: String? = "",
+ @Contextual val request: String = "",
@Contextual val createdAt: Date = Date(),
) {
+ @Contextual
val url: String = rs.url //rs?.url
//?. is required, otherwise Tabulator.js/EventLogTable shows no entries
+ @Contextual
val subType = rs?.subType
//?. is required, otherwise Tabulator.js/EventLogTable shows no entries
@@ -116,6 +118,9 @@ data class LogEntry(
@Contextual
var runningAtEnd = 0
+ @Contextual
+ var icon = "<i class='fas fa-plug'></i>"
+
// alternative constructor for UI events (e.g. from user interaction)
@JsName("secondaryConstructor")
constructor(title: String, aggregator: BaseAggregator) :
this(ResourceSpecification(""), "", "") {
@@ -130,22 +135,33 @@ data class LogEntry(
duration = (date.getTime() - createdAt.getTime()).toInt()
}
+ private fun setState(eventState: EventState) {
+ state = eventState
+ val color = when {
+ state.style.equals(ButtonStyle.DANGER) -> "red"
+ state.style.equals(ButtonStyle.WARNING) -> "yellow"
+ state.style.equals(ButtonStyle.SUCCESS) -> "green"
+ else -> "blue"
+ }
+ icon = "<i class='${state.iconName}' style='color: ${color}'></i>"
+ }
+
fun setError(error: String) {
calculate()
fault = error
- state = EventState.ERROR
+ setState(EventState.ERROR)
type = Represention.ERROR.type
}
fun setUndefined(error: String) {
calculate()
fault = error
- state = EventState.MISSING
+ setState(EventState.MISSING)
}
fun setClose() {
updatedAt = Date()
- state = EventState.CLOSED
+ setState(EventState.CLOSED)
}
fun setSuccess() {
@@ -156,15 +172,16 @@ data class LogEntry(
val size = blob?.size ?: 0
responseLength = size.toInt()
}
- state = when {
+ val eventState = when {
url.startsWith(Constants.krokiUrl) -> EventState.SUCCESS_IMG
subType == Constants.subTypeXml -> EventState.SUCCESS_XML
else -> EventState.SUCCESS_JS
}
+ setState(eventState)
}
fun setCached() {
- state = EventState.DUPLICATE
+ setState(EventState.DUPLICATE)
}
internal fun isCached(rs: ResourceSpecification, method: String): Boolean {
@@ -179,7 +196,7 @@ data class LogEntry(
}
fun setReload() {
- state = EventState.RELOAD
+ setState(EventState.RELOAD)
}
fun getTransferObject(): TransferObject? {
diff --git
a/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/ui/core/ColumnFactory.kt
b/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/ui/core/ColumnFactory.kt
index 083d269456..c5963b689e 100644
---
a/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/ui/core/ColumnFactory.kt
+++
b/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/ui/core/ColumnFactory.kt
@@ -32,7 +32,6 @@ import
org.apache.causeway.client.kroviz.core.model.PropertyDetails
import org.apache.causeway.client.kroviz.to.TObject
import org.apache.causeway.client.kroviz.to.ValueType
import org.apache.causeway.client.kroviz.to.Vega5
-import org.apache.causeway.client.kroviz.ui.menu.ContextMenuBuilder
import org.apache.causeway.client.kroviz.ui.menu.DynamicMenuBuilder
import org.apache.causeway.client.kroviz.utils.js.Vega
@@ -77,7 +76,6 @@ class ColumnFactory {
)
}
-
private fun getObjectFromCell(cell: Tabulator.CellComponent): TObject {
val row = cell.getRow()
val exposer = row.getData() as Exposer
diff --git
a/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/ui/panel/EventLogTable.kt
b/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/ui/panel/EventLogTable.kt
index 00b0825e81..96fa8209a2 100644
---
a/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/ui/panel/EventLogTable.kt
+++
b/incubator/clients/kroviz/src/main/kotlin/org/apache/causeway/client/kroviz/ui/panel/EventLogTable.kt
@@ -18,34 +18,32 @@
*/
package org.apache.causeway.client.kroviz.ui.panel
-import io.kvision.core.*
-import io.kvision.html.Button
-import io.kvision.html.ButtonStyle
+import io.kvision.core.AlignItems
+import io.kvision.core.Border
+import io.kvision.core.FlexWrap
import io.kvision.panel.VPanel
import io.kvision.panel.hPanel
import io.kvision.tabulator.*
+import io.kvision.tabulator.js.Tabulator.CellComponent
import io.kvision.utils.obj
import io.kvision.utils.px
import org.apache.causeway.client.kroviz.core.event.EventState
import org.apache.causeway.client.kroviz.core.event.LogEntry
-import org.apache.causeway.client.kroviz.to.TObject
import org.apache.causeway.client.kroviz.ui.builder.TableBuilder
-import org.apache.causeway.client.kroviz.ui.core.Constants
import org.apache.causeway.client.kroviz.ui.dialog.EventLogDetail
import org.apache.causeway.client.kroviz.ui.menu.DynamicMenuBuilder
-import org.apache.causeway.client.kroviz.utils.StringUtils
class EventLogTable(val model: List<LogEntry>, filterState: EventState? =
null) : VPanel() {
val tabulator: Tabulator<dynamic>
private val columns = listOf(
-// buildCdForTableMenu(),
-// buildCdForTitle(),
+ buildCdForTableMenu(),
+ buildCdForTitle(),
buildCdForType(),
-// buildCdForState(),
+ buildCdForState(),
buildCdForMethod(),
buildCdForAggregators(),
- buildCdForRequestLenght(),
+ buildCdForRequestLength(),
buildCdForResponse(),
buildCdForResponseLength(),
buildCdForCacheHits(),
@@ -58,12 +56,20 @@ class EventLogTable(val model: List<LogEntry>, filterState:
EventState? = null)
return ColumnDefinition(
download = false,
title = "",
- field = "state_1",
+ field = "icon_1",
width = "50",
headerMenu = DynamicMenuBuilder().buildTableMenu(this),
hozAlign = Align.CENTER,
- vertAlign = VAlign.MIDDLE,
- formatterComponentFunction = { _, _, data ->
buildActionButton(data) }
+ vertAlign = VAlign.BOTTOM,
+ formatter = Formatter.HTML,
+ clickMenu = { _: dynamic, cellComponent: CellComponent ->
+ val le = getObjectFromCell(cellComponent)
+ EventLogDetail(le).open()
+ }
+ //val tto = TooltipOptions(title = data.title)
+ // tabulator tooltip is buggy: often the tooltip doesn't go away
and the color is not settable
+ //b.enableTooltip(tto)
+ // if (le.obj is TObject)
b.setDragDropData(Constants.stdMimeType, le.url)
)
}
@@ -74,15 +80,28 @@ class EventLogTable(val model: List<LogEntry>, filterState:
EventState? = null)
field = "title_1",
headerFilter = Editor.INPUT,
width = "700",
- formatterComponentFunction = { _, _, data ->
buildObjectButton(data) })
+ formatter = Formatter.LINK
+ )
}
private fun buildCdForState(): ColumnDefinition<dynamic> {
- return ColumnDefinition("State", "state_1", width = "100",
headerFilter = Editor.INPUT, download = false)
+ return ColumnDefinition(
+ "State",
+ "state_1",
+ width = "100",
+ headerFilter = Editor.INPUT,
+ download = false
+ )
}
private fun buildCdForMethod(): ColumnDefinition<dynamic> {
- return ColumnDefinition("Method", "method_1", width = "100",
headerFilter = Editor.INPUT, download = false)
+ return ColumnDefinition(
+ "Method",
+ "method_1",
+ width = "100",
+ headerFilter = Editor.INPUT,
+ download = false
+ )
}
private fun buildCdForAggregators(): ColumnDefinition<dynamic> {
@@ -105,14 +124,8 @@ class EventLogTable(val model: List<LogEntry>,
filterState: EventState? = null)
)
}
- private fun buildCdForRequestLenght(): ColumnDefinition<dynamic> {
- return ColumnDefinition(
- "req.len",
- field = "requestLength_1",
- width = "100",
- hozAlign = Align.RIGHT,
- download = false
- )
+ private fun buildCdForRequestLength(): ColumnDefinition<dynamic> {
+ return buildCdForNumber("req.len", "requestLength_1")
}
private fun buildCdForResponse(): ColumnDefinition<dynamic> {
@@ -126,29 +139,21 @@ class EventLogTable(val model: List<LogEntry>,
filterState: EventState? = null)
}
private fun buildCdForResponseLength(): ColumnDefinition<dynamic> {
- return ColumnDefinition(
- "resp.len",
- field = "responseLength_1",
- width = "100",
- hozAlign = Align.RIGHT,
- download = false
- )
+ return buildCdForNumber("resp.len", "responseLength_1")
}
private fun buildCdForCacheHits(): ColumnDefinition<dynamic> {
- return ColumnDefinition(
- "cacheHits",
- field = "cacheHits_1",
- width = "100",
- hozAlign = Align.RIGHT,
- download = false
- )
+ return buildCdForNumber("cacheHits", "cacheHits_1")
}
private fun buildCdForDuration(): ColumnDefinition<dynamic> {
+ return buildCdForNumber("duration", "duration_1")
+ }
+
+ private fun buildCdForNumber(title: String, field: String):
ColumnDefinition<dynamic> {
return ColumnDefinition(
- "duration",
- field = "duration_1",
+ title = title,
+ field = field,
width = "100",
hozAlign = Align.RIGHT,
download = false
@@ -156,23 +161,18 @@ class EventLogTable(val model: List<LogEntry>,
filterState: EventState? = null)
}
private fun buildCdForCreatedAt(): ColumnDefinition<dynamic> {
- return ColumnDefinition(
- download = false,
- title = "Created",
- field = "createdAt_1",
- sorter = Sorter.DATETIME,
- formatter = Formatter.DATETIME,
- formatterParams = obj
- { outputFormat = "HH:mm:ss.SSS" },
- width = "100"
- )
+ return buildCdForDateTime("Created", "createdAt_1")
}
private fun buildCdForUpdatedAt(): ColumnDefinition<dynamic> {
+ return buildCdForDateTime("Updated", "updatedAt_1")
+ }
+
+ private fun buildCdForDateTime(title: String, field: String):
ColumnDefinition<dynamic> {
return ColumnDefinition(
download = false,
- title = "Updated",
- field = "updatedAt_1",
+ title = title,
+ field = field,
sorter = Sorter.DATETIME,
formatter = Formatter.DATETIME,
formatterParams = obj
@@ -181,34 +181,6 @@ class EventLogTable(val model: List<LogEntry>,
filterState: EventState? = null)
)
}
- private fun buildObjectButton(data: LogEntry): Button {
- val b = Button(
- text = StringUtils.shorten(data.title),
- icon = data.state.iconName,
- style = ButtonStyle.LINK
- )
- b.onClick {
- kotlinx.browser.window.open(data.title) //IMPROVE should be URL
- }
- //val tto = TooltipOptions(title = data.title)
- // tabulator tooltip is buggy: often the tooltip doesn't go away and
the color is not settable
- //b.enableTooltip(tto)
- if (data.obj is TObject) b.setDragDropData(Constants.stdMimeType,
data.url)
- return b
- }
-
- private fun buildActionButton(data: LogEntry): Button {
- val b = Button(
- text = "",
- icon = "fa fa-info-circle",
- style = data.state.style
- )
- b.onClick { EventLogDetail(data).open() }
- b.margin = CssSize(-10, UNIT.px)
- b.addCssClass("btn-sm")
- return b
- }
-
init {
hPanel(
FlexWrap.NOWRAP,
@@ -222,8 +194,6 @@ class EventLogTable(val model: List<LogEntry>, filterState:
EventState? = null)
model.forEach {
data.add(it.asDynamic())
}
- console.log("[ELT_init]")
- console.log(data)
tabulator = TableBuilder().createTabulator(data, columns)
tabulator.setEventListener<Tabulator<dynamic>> {
@@ -238,4 +208,9 @@ class EventLogTable(val model: List<LogEntry>, filterState:
EventState? = null)
add(tabulator)
}
+ private fun getObjectFromCell(cell: CellComponent): LogEntry {
+ val row = cell.getRow()
+ return row.getData() as LogEntry
+ }
+
}