From 474195d3aa862686712cfe6c800dc43f8fee8ec5 Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Wed, 19 Dec 2018 12:14:03 +0100 Subject: An addon remote module for select component. --- .../treksoft/kvision/remote/SpringRemoteAgent.kt | 36 ++++++++++++++-------- .../kvision/remote/SpringServiceManager.kt | 24 +++++++++++---- 2 files changed, 42 insertions(+), 18 deletions(-) (limited to 'kvision-modules/kvision-remote/src/main') diff --git a/kvision-modules/kvision-remote/src/main/kotlin/pl/treksoft/kvision/remote/SpringRemoteAgent.kt b/kvision-modules/kvision-remote/src/main/kotlin/pl/treksoft/kvision/remote/SpringRemoteAgent.kt index fea16b99..2f6b765a 100644 --- a/kvision-modules/kvision-remote/src/main/kotlin/pl/treksoft/kvision/remote/SpringRemoteAgent.kt +++ b/kvision-modules/kvision-remote/src/main/kotlin/pl/treksoft/kvision/remote/SpringRemoteAgent.kt @@ -44,7 +44,8 @@ open class SpringRemoteAgent(val serviceManager: SpringServiceManager call(noinline function: suspend T.() -> RET): RET { val (url, method) = - serviceManager.getCalls()[function.toString()] ?: throw IllegalStateException("Function not specified!") + serviceManager.getCalls()[function.toString().replace("\\s".toRegex(), "")] + ?: throw IllegalStateException("Function not specified!") return callAgent.jsonRpcCall(url, method = method).then { try { @Suppress("UNCHECKED_CAST") @@ -67,7 +68,8 @@ open class SpringRemoteAgent(val serviceManager: SpringServiceManager List ): List { val (url, method) = - serviceManager.getCalls()[function.toString()] ?: throw IllegalStateException("Function not specified!") + serviceManager.getCalls()[function.toString().replace("\\s".toRegex(), "")] + ?: throw IllegalStateException("Function not specified!") return callAgent.jsonRpcCall(url, method = method).then { try { deserializeList(it, RET::class.js.name) @@ -90,7 +92,8 @@ open class SpringRemoteAgent(val serviceManager: SpringServiceManager(val serviceManager: SpringServiceManager { val data = serialize(p) val (url, method) = - serviceManager.getCalls()[function.toString()] ?: throw IllegalStateException("Function not specified!") + serviceManager.getCalls()[function.toString().replace("\\s".toRegex(), "")] + ?: throw IllegalStateException("Function not specified!") return callAgent.jsonRpcCall(url, listOf(data), method).then { try { deserializeList(it, RET::class.js.name) @@ -138,7 +142,8 @@ open class SpringRemoteAgent(val serviceManager: SpringServiceManager(val serviceManager: SpringServiceManager(it, RET::class.js.name) @@ -188,7 +194,8 @@ open class SpringRemoteAgent(val serviceManager: SpringServiceManager(val serviceManager: SpringServiceManager(it, RET::class.js.name) @@ -240,7 +248,8 @@ open class SpringRemoteAgent(val serviceManager: SpringServiceManager(val serviceManager: SpringServiceManager(it, RET::class.js.name) @@ -305,7 +315,8 @@ open class SpringRemoteAgent(val serviceManager: SpringServiceManager(val serviceManager: SpringServiceManager(it, RET::class.js.name) diff --git a/kvision-modules/kvision-remote/src/main/kotlin/pl/treksoft/kvision/remote/SpringServiceManager.kt b/kvision-modules/kvision-remote/src/main/kotlin/pl/treksoft/kvision/remote/SpringServiceManager.kt index 524347d7..61ae32ba 100644 --- a/kvision-modules/kvision-remote/src/main/kotlin/pl/treksoft/kvision/remote/SpringServiceManager.kt +++ b/kvision-modules/kvision-remote/src/main/kotlin/pl/treksoft/kvision/remote/SpringServiceManager.kt @@ -42,7 +42,7 @@ actual open class SpringServiceManager actual constructor(serviceClass: route: String?, method: RpcHttpMethod ) { val routeDef = route ?: "route${this::class.simpleName}${counter++}" - calls[function.toString()] = Pair("/kv/$routeDef", method) + calls[function.toString().replace("\\s".toRegex(), "")] = Pair("/kv/$routeDef", method) } /** @@ -56,7 +56,7 @@ actual open class SpringServiceManager actual constructor(serviceClass: route: String?, method: RpcHttpMethod ) { val routeDef = route ?: "route${this::class.simpleName}${counter++}" - calls[function.toString()] = Pair("/kv/$routeDef", method) + calls[function.toString().replace("\\s".toRegex(), "")] = Pair("/kv/$routeDef", method) } /** @@ -70,7 +70,7 @@ actual open class SpringServiceManager actual constructor(serviceClass: route: String?, method: RpcHttpMethod ) { val routeDef = route ?: "route${this::class.simpleName}${counter++}" - calls[function.toString()] = Pair("/kv/$routeDef", method) + calls[function.toString().replace("\\s".toRegex(), "")] = Pair("/kv/$routeDef", method) } /** @@ -84,7 +84,7 @@ actual open class SpringServiceManager actual constructor(serviceClass: route: String?, method: RpcHttpMethod ) { val routeDef = route ?: "route${this::class.simpleName}${counter++}" - calls[function.toString()] = Pair("/kv/$routeDef", method) + calls[function.toString().replace("\\s".toRegex(), "")] = Pair("/kv/$routeDef", method) } /** @@ -98,7 +98,7 @@ actual open class SpringServiceManager actual constructor(serviceClass: route: String?, method: RpcHttpMethod ) { val routeDef = route ?: "route${this::class.simpleName}${counter++}" - calls[function.toString()] = Pair("/kv/$routeDef", method) + calls[function.toString().replace("\\s".toRegex(), "")] = Pair("/kv/$routeDef", method) } /** @@ -114,11 +114,23 @@ actual open class SpringServiceManager actual constructor(serviceClass: method: RpcHttpMethod ) { val routeDef = route ?: "route${this::class.simpleName}${counter++}" - calls[function.toString()] = Pair("/kv/$routeDef", method) + calls[function.toString().replace("\\s".toRegex(), "")] = Pair("/kv/$routeDef", method) + } + + /** + * Binds a given function of the receiver as a select options source + * @param function a function of the receiver + */ + protected actual fun bind( + function: T.(String) -> List + ) { + val routeDef = "route${this::class.simpleName}${counter++}" + calls[function.toString().replace("\\s".toRegex(), "")] = Pair("/kv/$routeDef", RpcHttpMethod.POST) } /** * Returns the map of defined paths. */ override fun getCalls(): Map> = calls + } -- cgit