From 4bd650eff23bb3c4892b75df33597d8368c14cf3 Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Thu, 7 Nov 2019 13:33:07 +0100 Subject: Send additional state with TabulatorRemote request --- .../kotlin/pl/treksoft/kvision/tabulator/TabulatorRemote.kt | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'kvision-modules/kvision-tabulator-remote/src/main/kotlin/pl/treksoft') diff --git a/kvision-modules/kvision-tabulator-remote/src/main/kotlin/pl/treksoft/kvision/tabulator/TabulatorRemote.kt b/kvision-modules/kvision-tabulator-remote/src/main/kotlin/pl/treksoft/kvision/tabulator/TabulatorRemote.kt index 33cf44b3..c3074640 100644 --- a/kvision-modules/kvision-tabulator-remote/src/main/kotlin/pl/treksoft/kvision/tabulator/TabulatorRemote.kt +++ b/kvision-modules/kvision-tabulator-remote/src/main/kotlin/pl/treksoft/kvision/tabulator/TabulatorRemote.kt @@ -42,6 +42,7 @@ import pl.treksoft.kvision.utils.JSON * @param E type of service manager * @param serviceManager multiplatform service manager * @param function multiplatform service method returning tabulator rows data + * @param stateFunction a function to generate the state object passed with the remote request * @param options tabulator options * @param types a set of table types * @param classes a set of CSS class names @@ -49,7 +50,8 @@ import pl.treksoft.kvision.utils.JSON @UseExperimental(ImplicitReflectionSerializer::class) open class TabulatorRemote( serviceManager: KVServiceManager, - function: suspend E.(Int?, Int?, List?, List?) -> RemoteData, + function: suspend E.(Int?, Int?, List?, List?, String?) -> RemoteData, + stateFunction: (() -> String)? = null, options: TabulatorOptions = TabulatorOptions(), types: Set = setOf(), classes: Set = setOf() @@ -76,8 +78,9 @@ open class TabulatorRemote( } else { null } + val state = stateFunction?.invoke() @Suppress("UnsafeCastFromDynamic") - val data = JSON.plain.stringify(JsonRpcRequest(0, url, listOf(page, size, filters, sorters))) + val data = JSON.plain.stringify(JsonRpcRequest(0, url, listOf(page, size, filters, sorters, state))) restClient.remoteCall(url, data, method = HttpMethod.valueOf(method.name)).then { r: dynamic -> val result = kotlin.js.JSON.parse(r.result as String) @Suppress("UnsafeCastFromDynamic") @@ -98,13 +101,14 @@ open class TabulatorRemote( */ fun Container.tabulatorRemote( serviceManager: KVServiceManager, - function: suspend E.(Int?, Int?, List?, List?) -> RemoteData, + function: suspend E.(Int?, Int?, List?, List?, String?) -> RemoteData, + stateFunction: (() -> String)? = null, options: TabulatorOptions = TabulatorOptions(), types: Set = setOf(), classes: Set = setOf(), init: (TabulatorRemote.() -> Unit)? = null ): TabulatorRemote { - val tabulatorRemote = TabulatorRemote(serviceManager, function, options, types, classes) + val tabulatorRemote = TabulatorRemote(serviceManager, function, stateFunction, options, types, classes) init?.invoke(tabulatorRemote) this.add(tabulatorRemote) return tabulatorRemote -- cgit