diff options
author | Robert Jaros <rjaros@finn.pl> | 2019-11-07 13:33:07 +0100 |
---|---|---|
committer | Robert Jaros <rjaros@finn.pl> | 2019-11-07 13:33:07 +0100 |
commit | 4bd650eff23bb3c4892b75df33597d8368c14cf3 (patch) | |
tree | 76b5241873e7c4f660688c52c173a7fa0eaa9d0d /kvision-modules/kvision-tabulator-remote/src/main/kotlin/pl/treksoft/kvision | |
parent | b635f78389cd032ead73a771a6fb8a02b2273159 (diff) | |
download | kvision-4bd650eff23bb3c4892b75df33597d8368c14cf3.tar.gz kvision-4bd650eff23bb3c4892b75df33597d8368c14cf3.tar.bz2 kvision-4bd650eff23bb3c4892b75df33597d8368c14cf3.zip |
Send additional state with TabulatorRemote request
Diffstat (limited to 'kvision-modules/kvision-tabulator-remote/src/main/kotlin/pl/treksoft/kvision')
-rw-r--r-- | kvision-modules/kvision-tabulator-remote/src/main/kotlin/pl/treksoft/kvision/tabulator/TabulatorRemote.kt | 12 |
1 files changed, 8 insertions, 4 deletions
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<T : Any, E : Any>( serviceManager: KVServiceManager<E>, - function: suspend E.(Int?, Int?, List<RemoteFilter>?, List<RemoteSorter>?) -> RemoteData<T>, + function: suspend E.(Int?, Int?, List<RemoteFilter>?, List<RemoteSorter>?, String?) -> RemoteData<T>, + stateFunction: (() -> String)? = null, options: TabulatorOptions<T> = TabulatorOptions(), types: Set<TableType> = setOf(), classes: Set<String> = setOf() @@ -76,8 +78,9 @@ open class TabulatorRemote<T : Any, E : Any>( } 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<dynamic>(r.result as String) @Suppress("UnsafeCastFromDynamic") @@ -98,13 +101,14 @@ open class TabulatorRemote<T : Any, E : Any>( */ fun <T : Any, E : Any> Container.tabulatorRemote( serviceManager: KVServiceManager<E>, - function: suspend E.(Int?, Int?, List<RemoteFilter>?, List<RemoteSorter>?) -> RemoteData<T>, + function: suspend E.(Int?, Int?, List<RemoteFilter>?, List<RemoteSorter>?, String?) -> RemoteData<T>, + stateFunction: (() -> String)? = null, options: TabulatorOptions<T> = TabulatorOptions(), types: Set<TableType> = setOf(), classes: Set<String> = setOf(), init: (TabulatorRemote<T, E>.() -> Unit)? = null ): TabulatorRemote<T, E> { - 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 |