aboutsummaryrefslogtreecommitdiff
path: root/kvision-modules/kvision-server-ktor/src/main/kotlin/pl/treksoft/kvision
diff options
context:
space:
mode:
authorRobert Jaros <rjaros@finn.pl>2019-07-08 12:43:17 +0200
committerRobert Jaros <rjaros@finn.pl>2019-07-08 12:43:17 +0200
commit0acabe1d44111a3a118116d526b415572caf8050 (patch)
treee252f8ddd28687a36477d7fdd125686e82f85386 /kvision-modules/kvision-server-ktor/src/main/kotlin/pl/treksoft/kvision
parentc0a51a9be91b8f438ec7605558465bf8a8aac404 (diff)
downloadkvision-0acabe1d44111a3a118116d526b415572caf8050.tar.gz
kvision-0acabe1d44111a3a118116d526b415572caf8050.tar.bz2
kvision-0acabe1d44111a3a118116d526b415572caf8050.zip
New tabulator-remote module.
Diffstat (limited to 'kvision-modules/kvision-server-ktor/src/main/kotlin/pl/treksoft/kvision')
-rw-r--r--kvision-modules/kvision-server-ktor/src/main/kotlin/pl/treksoft/kvision/remote/KVServiceManager.kt45
1 files changed, 45 insertions, 0 deletions
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 3c5391b6..c5c579a6 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
@@ -457,6 +457,51 @@ actual open class KVServiceManager<T : Any> actual constructor(val serviceClass:
}
/**
+ * Binds a given function of the receiver as a tabulator component source
+ * @param function a function of the receiver
+ */
+ @Suppress("TooGenericExceptionCaught")
+ protected actual inline fun <reified RET> bind(
+ noinline function: T.(Int?, Int?, List<RemoteFilter>?, List<RemoteSorter>?) -> 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>()
+ if (jsonRpcRequest.params.size == 4) {
+ val param1 = getParameter<Int?>(jsonRpcRequest.params[0])
+ val param2 = getParameter<Int?>(jsonRpcRequest.params[1])
+ val param3 = getParameter<List<RemoteFilter>?>(jsonRpcRequest.params[2])
+ val param4 = getParameter<List<RemoteSorter>?>(jsonRpcRequest.params[3])
+ try {
+ val result = function.invoke(service, param1, param2, param3, param4)
+ call.respond(
+ JsonRpcResponse(
+ id = jsonRpcRequest.id,
+ result = mapper.writeValueAsString(result)
+ )
+ )
+ } catch (e: Exception) {
+ LOG.error(e.message, e)
+ call.respond(
+ JsonRpcResponse(
+ id = jsonRpcRequest.id,
+ error = e.message ?: "Error"
+ )
+ )
+ }
+ } else {
+ call.respond(
+ JsonRpcResponse(
+ id = jsonRpcRequest.id,
+ error = "Invalid parameters"
+ )
+ )
+ }
+ }
+ }
+
+ /**
* @suppress Internal method
*/
fun addRoute(