diff options
Diffstat (limited to 'kvision-modules')
6 files changed, 25 insertions, 15 deletions
diff --git a/kvision-modules/kvision-common-remote/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt b/kvision-modules/kvision-common-remote/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt index 3d0b5115..09239fdd 100644 --- a/kvision-modules/kvision-common-remote/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt +++ b/kvision-modules/kvision-common-remote/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt @@ -123,7 +123,7 @@ expect open class KVServiceManager<T : Any>(serviceClass: KClass<T>) { * @param function a function of the receiver */ protected inline fun <reified RET> bindTabulatorRemote( - noinline function: suspend T.(Int?, Int?, List<RemoteFilter>?, List<RemoteSorter>?) -> RemoteData<RET> + noinline function: suspend T.(Int?, Int?, List<RemoteFilter>?, List<RemoteSorter>?, String?) -> RemoteData<RET> ) /** diff --git a/kvision-modules/kvision-remote/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt b/kvision-modules/kvision-remote/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt index 5c7cac7f..c257645d 100644 --- a/kvision-modules/kvision-remote/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt +++ b/kvision-modules/kvision-remote/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt @@ -144,7 +144,7 @@ actual open class KVServiceManager<T : Any> actual constructor(serviceClass: KCl * @param function a function of the receiver */ protected actual inline fun <reified RET> bindTabulatorRemote( - noinline function: suspend T.(Int?, Int?, List<RemoteFilter>?, List<RemoteSorter>?) -> RemoteData<RET> + noinline function: suspend T.(Int?, Int?, List<RemoteFilter>?, List<RemoteSorter>?, String?) -> RemoteData<RET> ) { val routeDef = "route${this::class.simpleName}${counter++}" calls[function.toString().replace("\\s".toRegex(), "")] = Pair("/kv/$routeDef", HttpMethod.POST) diff --git a/kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt b/kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt index df8d20c7..ac799769 100644 --- a/kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt +++ b/kvision-modules/kvision-server-jooby/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt @@ -465,24 +465,26 @@ actual open class KVServiceManager<T : Any> actual constructor(val serviceClass: */ @Suppress("TooGenericExceptionCaught") protected actual inline fun <reified RET> bindTabulatorRemote( - noinline function: suspend T.(Int?, Int?, List<RemoteFilter>?, List<RemoteSorter>?) -> RemoteData<RET> + noinline function: suspend T.(Int?, Int?, List<RemoteFilter>?, List<RemoteSorter>?, String?) -> RemoteData<RET> ) { val routeDef = "route${this::class.simpleName}${counter++}" routes.add { call(HttpMethod.POST, "/kv/$routeDef") { req, res -> val jsonRpcRequest = req.body(JsonRpcRequest::class.java) @Suppress("MagicNumber") - if (jsonRpcRequest.params.size == 4) { + if (jsonRpcRequest.params.size == 5) { val param1 = getParameter<Int?>(jsonRpcRequest.params[0]) val param2 = getParameter<Int?>(jsonRpcRequest.params[1]) val param3 = getParameter<List<RemoteFilter>?>(jsonRpcRequest.params[2]) @Suppress("MagicNumber") val param4 = getParameter<List<RemoteSorter>?>(jsonRpcRequest.params[3]) + @Suppress("MagicNumber") + val param5 = getParameter<String?>(jsonRpcRequest.params[4]) val injector = req.require(Injector::class.java) val service = injector.getInstance(serviceClass.java) GlobalScope.launch(start = CoroutineStart.UNDISPATCHED) { try { - val result = function.invoke(service, param1, param2, param3, param4) + val result = function.invoke(service, param1, param2, param3, param4, param5) res.send( JsonRpcResponse( id = jsonRpcRequest.id, diff --git a/kvision-modules/kvision-server-ktor/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt b/kvision-modules/kvision-server-ktor/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt index 8b766aee..ec487e08 100644 --- a/kvision-modules/kvision-server-ktor/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt +++ b/kvision-modules/kvision-server-ktor/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt @@ -497,21 +497,23 @@ actual open class KVServiceManager<T : Any> actual constructor(val serviceClass: */ @Suppress("TooGenericExceptionCaught") protected actual inline fun <reified RET> bindTabulatorRemote( - noinline function: suspend T.(Int?, Int?, List<RemoteFilter>?, List<RemoteSorter>?) -> RemoteData<RET> + noinline function: suspend T.(Int?, Int?, List<RemoteFilter>?, List<RemoteSorter>?, String?) -> RemoteData<RET> ) { val routeDef = "route${this::class.simpleName}${counter++}" addRoute(HttpMethod.POST, "/kv/$routeDef") { val service = call.injector.createChildInjector(DummyWsSessionModule()).getInstance(serviceClass.java) val jsonRpcRequest = call.receive<JsonRpcRequest>() @Suppress("MagicNumber") - if (jsonRpcRequest.params.size == 4) { + if (jsonRpcRequest.params.size == 5) { val param1 = getParameter<Int?>(jsonRpcRequest.params[0]) val param2 = getParameter<Int?>(jsonRpcRequest.params[1]) val param3 = getParameter<List<RemoteFilter>?>(jsonRpcRequest.params[2]) @Suppress("MagicNumber") val param4 = getParameter<List<RemoteSorter>?>(jsonRpcRequest.params[3]) + @Suppress("MagicNumber") + val param5 = getParameter<String?>(jsonRpcRequest.params[4]) try { - val result = function.invoke(service, param1, param2, param3, param4) + val result = function.invoke(service, param1, param2, param3, param4, param5) call.respond( JsonRpcResponse( id = jsonRpcRequest.id, diff --git a/kvision-modules/kvision-server-spring-boot/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt b/kvision-modules/kvision-server-spring-boot/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt index 8008d529..fcd4b411 100644 --- a/kvision-modules/kvision-server-spring-boot/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt +++ b/kvision-modules/kvision-server-spring-boot/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt @@ -566,7 +566,7 @@ actual open class KVServiceManager<T : Any> actual constructor(val serviceClass: */ @Suppress("TooGenericExceptionCaught") protected actual inline fun <reified RET> bindTabulatorRemote( - noinline function: suspend T.(Int?, Int?, List<RemoteFilter>?, List<RemoteSorter>?) -> RemoteData<RET> + noinline function: suspend T.(Int?, Int?, List<RemoteFilter>?, List<RemoteSorter>?, String?) -> RemoteData<RET> ) { val routeDef = "route${this::class.simpleName}${counter++}" addRoute(HttpMethod.POST, "/kv/$routeDef") { req, ctx -> @@ -574,14 +574,16 @@ actual open class KVServiceManager<T : Any> actual constructor(val serviceClass: initializeService(service, req) val jsonRpcRequest = req.awaitBody<JsonRpcRequest>() @Suppress("MagicNumber") - if (jsonRpcRequest.params.size == 4) { + if (jsonRpcRequest.params.size == 5) { val param1 = getParameter<Int?>(jsonRpcRequest.params[0]) val param2 = getParameter<Int?>(jsonRpcRequest.params[1]) val param3 = getParameter<List<RemoteFilter>?>(jsonRpcRequest.params[2]) @Suppress("MagicNumber") val param4 = getParameter<List<RemoteSorter>?>(jsonRpcRequest.params[3]) + @Suppress("MagicNumber") + val param5 = getParameter<String?>(jsonRpcRequest.params[4]) try { - val result = function.invoke(service, param1, param2, param3, param4) + val result = function.invoke(service, param1, param2, param3, param4, param5) ServerResponse.ok().json().bodyValueAndAwait( mapper.writeValueAsString( JsonRpcResponse( 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 |