diff options
author | Robert Jaros <rjaros@finn.pl> | 2019-07-13 00:21:33 +0200 |
---|---|---|
committer | Robert Jaros <rjaros@finn.pl> | 2019-07-13 00:59:50 +0200 |
commit | a804e0aa277efc1b46c1111b0ad8302d267684b2 (patch) | |
tree | dbd5329f003b386b5196b510526c9cee75db3514 | |
parent | 7fe158d0f2243c460c4f1848bb7989c559362cdf (diff) | |
download | kvision-a804e0aa277efc1b46c1111b0ad8302d267684b2.tar.gz kvision-a804e0aa277efc1b46c1111b0ad8302d267684b2.tar.bz2 kvision-a804e0aa277efc1b46c1111b0ad8302d267684b2.zip |
Refactor RemoteSelect -> SelectRemote and RemoteTabulator -> TabulatorRemote
9 files changed, 53 insertions, 46 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 786143e8..006aba89 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 @@ -115,7 +115,7 @@ expect open class KVServiceManager<T : Any>(serviceClass: KClass<T>) { * @param function a function of the receiver */ protected fun bind( - function: T.(String?, String?) -> List<RemoteSelectOption> + function: T.(String?, String?) -> List<RemoteOption> ) /** diff --git a/kvision-modules/kvision-common-remote/src/main/kotlin/pl/treksoft/kvision/remote/RemoteTypes.kt b/kvision-modules/kvision-common-remote/src/main/kotlin/pl/treksoft/kvision/remote/RemoteTypes.kt index 7285295b..29cb6a9b 100644 --- a/kvision-modules/kvision-common-remote/src/main/kotlin/pl/treksoft/kvision/remote/RemoteTypes.kt +++ b/kvision-modules/kvision-common-remote/src/main/kotlin/pl/treksoft/kvision/remote/RemoteTypes.kt @@ -24,7 +24,7 @@ package pl.treksoft.kvision.remote import kotlinx.serialization.Serializable @Serializable -data class RemoteSelectOption( +data class RemoteOption( val value: String? = null, val text: String? = null, val className: String? = null, @@ -36,6 +36,7 @@ data class RemoteSelectOption( ) @Serializable +@Suppress("ConstructorParameterNaming") data class RemoteData<T>(val data: List<T> = listOf(), val last_page: Int = 0) @Serializable 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 5b5ae87f..829ccbd6 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 @@ -133,7 +133,7 @@ actual open class KVServiceManager<T : Any> actual constructor(serviceClass: KCl * @param function a function of the receiver */ protected actual fun bind( - function: T.(String?, String?) -> List<RemoteSelectOption> + function: T.(String?, String?) -> List<RemoteOption> ) { val routeDef = "route${this::class.simpleName}${counter++}" calls[function.toString().replace("\\s".toRegex(), "")] = Pair("/kv/$routeDef", HttpMethod.POST) diff --git a/kvision-modules/kvision-select-remote/src/main/kotlin/pl/treksoft/kvision/form/select/RemoteSelect.kt b/kvision-modules/kvision-select-remote/src/main/kotlin/pl/treksoft/kvision/form/select/SelectRemote.kt index 0e30d0fd..ea9d369b 100644 --- a/kvision-modules/kvision-select-remote/src/main/kotlin/pl/treksoft/kvision/form/select/RemoteSelect.kt +++ b/kvision-modules/kvision-select-remote/src/main/kotlin/pl/treksoft/kvision/form/select/SelectRemote.kt @@ -30,11 +30,11 @@ import pl.treksoft.kvision.form.HelpBlock import pl.treksoft.kvision.form.StringFormControl import pl.treksoft.kvision.panel.SimplePanel import pl.treksoft.kvision.remote.KVServiceManager -import pl.treksoft.kvision.remote.RemoteSelectOption +import pl.treksoft.kvision.remote.RemoteOption import pl.treksoft.kvision.utils.SnOn /** - * The form field component for RemoteSelect control. + * The form field component for SelectRemote control. * * @constructor * @param value selected value @@ -47,10 +47,10 @@ import pl.treksoft.kvision.utils.SnOn * @param rich determines if [label] can contain HTML code */ @Suppress("TooManyFunctions") -open class RemoteSelect<T : Any>( +open class SelectRemote<T : Any>( value: String? = null, serviceManager: KVServiceManager<T>, - function: T.(String?, String?) -> List<RemoteSelectOption>, + function: T.(String?, String?) -> List<RemoteOption>, name: String? = null, multiple: Boolean = false, ajaxOptions: AjaxOptions? = null, @@ -146,8 +146,8 @@ open class RemoteSelect<T : Any>( flabel.rich = value } - private val idc = "kv_form_remoteselect_$counter" - final override val input: RemoteSelectInput<T> = RemoteSelectInput( + private val idc = "kv_form_SelectRemote_$counter" + final override val input: SelectRemoteInput<T> = SelectRemoteInput( value, serviceManager, function, multiple, ajaxOptions, setOf("form-control") ).apply { @@ -251,15 +251,15 @@ open class RemoteSelect<T : Any>( * * It takes the same parameters as the constructor of the built component. */ - fun <T : Any> Container.remoteSelect( + fun <T : Any> Container.selectRemote( value: String? = null, serviceManager: KVServiceManager<T>, - function: T.(String?, String?) -> List<RemoteSelectOption>, name: String? = null, + function: T.(String?, String?) -> List<RemoteOption>, name: String? = null, multiple: Boolean = false, ajaxOptions: AjaxOptions? = null, label: String? = null, - rich: Boolean = false, init: (RemoteSelect<T>.() -> Unit)? = null - ): RemoteSelect<T> { - val remoteSelect = - RemoteSelect( + rich: Boolean = false, init: (SelectRemote<T>.() -> Unit)? = null + ): SelectRemote<T> { + val selectRemote = + SelectRemote( value, serviceManager, function, @@ -269,8 +269,8 @@ open class RemoteSelect<T : Any>( label, rich ).apply { init?.invoke(this) } - this.add(remoteSelect) - return remoteSelect + this.add(selectRemote) + return selectRemote } } } diff --git a/kvision-modules/kvision-select-remote/src/main/kotlin/pl/treksoft/kvision/form/select/RemoteSelectInput.kt b/kvision-modules/kvision-select-remote/src/main/kotlin/pl/treksoft/kvision/form/select/SelectRemoteInput.kt index ff1b04f4..4c891d30 100644 --- a/kvision-modules/kvision-select-remote/src/main/kotlin/pl/treksoft/kvision/form/select/RemoteSelectInput.kt +++ b/kvision-modules/kvision-select-remote/src/main/kotlin/pl/treksoft/kvision/form/select/SelectRemoteInput.kt @@ -32,7 +32,7 @@ import pl.treksoft.kvision.remote.CallAgent import pl.treksoft.kvision.remote.HttpMethod import pl.treksoft.kvision.remote.JsonRpcRequest import pl.treksoft.kvision.remote.KVServiceManager -import pl.treksoft.kvision.remote.RemoteSelectOption +import pl.treksoft.kvision.remote.RemoteOption import pl.treksoft.kvision.utils.JSON import pl.treksoft.kvision.utils.obj @@ -50,10 +50,10 @@ external fun decodeURIComponent(encodedURI: String): String * @param classes a set of CSS class names */ @UseExperimental(ImplicitReflectionSerializer::class) -open class RemoteSelectInput<T : Any>( +open class SelectRemoteInput<T : Any>( value: String? = null, serviceManager: KVServiceManager<T>, - function: T.(String?, String?) -> List<RemoteSelectOption>, + function: T.(String?, String?) -> List<RemoteOption>, multiple: Boolean = false, ajaxOptions: AjaxOptions? = null, classes: Set<String> = setOf() @@ -68,7 +68,7 @@ open class RemoteSelectInput<T : Any>( val tempAjaxOptions = ajaxOptions ?: AjaxOptions() this.ajaxOptions = tempAjaxOptions.copy(url = url, preprocessData = { @Suppress("UnsafeCastFromDynamic") - JSON.plain.parse(RemoteSelectOption.serializer().list, it.result as String).map { + JSON.plain.parse(RemoteOption.serializer().list, it.result as String).map { obj { this.value = it.value if (it.text != null) this.text = it.text @@ -96,14 +96,14 @@ open class RemoteSelectInput<T : Any>( JSON.plain.stringify(JsonRpcRequest(0, url, listOf(null, value))), HttpMethod.POST ).asDeferred().await() - JSON.plain.parse(RemoteSelectOption.serializer().list, initials.result as String).map { + JSON.plain.parse(RemoteOption.serializer().list, initials.result as String).map { add(SelectOption(it.value, it.text, selected = true)) } - this@RemoteSelectInput.refreshSelectInput() + this@SelectRemoteInput.refreshSelectInput() } } if (this.ajaxOptions?.emptyRequest == true) { - this.setInternalEventListener<RemoteSelect<*>> { + this.setInternalEventListener<SelectRemote<*>> { shownBsSelect = { val input = self.getElementJQuery()?.parent()?.find("input") input?.trigger("keyup", null) @@ -120,20 +120,20 @@ open class RemoteSelectInput<T : Any>( * * It takes the same parameters as the constructor of the built component. */ - fun <T : Any> Container.remoteSelectInput( + fun <T : Any> Container.selectRemoteInput( value: String? = null, serviceManager: KVServiceManager<T>, - function: T.(String?, String?) -> List<RemoteSelectOption>, + function: T.(String?, String?) -> List<RemoteOption>, multiple: Boolean = false, ajaxOptions: AjaxOptions? = null, - classes: Set<String> = setOf(), init: (RemoteSelectInput<T>.() -> Unit)? = null - ): RemoteSelectInput<T> { - val remoteSelectInput = - RemoteSelectInput(value, serviceManager, function, multiple, ajaxOptions, classes).apply { + classes: Set<String> = setOf(), init: (SelectRemoteInput<T>.() -> Unit)? = null + ): SelectRemoteInput<T> { + val selectRemoteInput = + SelectRemoteInput(value, serviceManager, function, multiple, ajaxOptions, classes).apply { init?.invoke(this) } - this.add(remoteSelectInput) - return remoteSelectInput + this.add(selectRemoteInput) + return selectRemoteInput } } 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 a2bb2386..4c4d4af0 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 @@ -42,7 +42,7 @@ import kotlin.reflect.KClass /** * Multiplatform service manager for Jooby. */ -@Suppress("LargeClass") +@Suppress("LargeClass", "TooManyFunctions") @UseExperimental(ExperimentalCoroutinesApi::class) actual open class KVServiceManager<T : Any> actual constructor(val serviceClass: KClass<T>) { @@ -396,7 +396,7 @@ actual open class KVServiceManager<T : Any> actual constructor(val serviceClass: */ @Suppress("TooGenericExceptionCaught") protected actual fun bind( - function: T.(String?, String?) -> List<RemoteSelectOption> + function: T.(String?, String?) -> List<RemoteOption> ) { val routeDef = "route${this::class.simpleName}${counter++}" routes.add { @@ -440,10 +440,12 @@ actual open class KVServiceManager<T : Any> actual constructor(val serviceClass: routes.add { call(HttpMethod.POST, "/kv/$routeDef") { req, res -> val jsonRpcRequest = req.body(JsonRpcRequest::class.java) + @Suppress("MagicNumber") 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]) + @Suppress("MagicNumber") val param4 = getParameter<List<RemoteSorter>?>(jsonRpcRequest.params[3]) val injector = req.require(Injector::class.java) val service = injector.getInstance(serviceClass.java) 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 c5c579a6..847604fb 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 @@ -55,7 +55,7 @@ import kotlin.reflect.KClass */ @KtorExperimentalAPI @UseExperimental(ExperimentalCoroutinesApi::class) -@Suppress("LargeClass") +@Suppress("LargeClass", "TooManyFunctions") actual open class KVServiceManager<T : Any> actual constructor(val serviceClass: KClass<T>) { companion object { @@ -419,7 +419,7 @@ actual open class KVServiceManager<T : Any> actual constructor(val serviceClass: */ @Suppress("TooGenericExceptionCaught") protected actual fun bind( - function: T.(String?, String?) -> List<RemoteSelectOption> + function: T.(String?, String?) -> List<RemoteOption> ) { val routeDef = "route${this::class.simpleName}${counter++}" addRoute(HttpMethod.POST, "/kv/$routeDef") { @@ -468,10 +468,12 @@ actual open class KVServiceManager<T : Any> actual constructor(val serviceClass: 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) { 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]) try { val result = function.invoke(service, param1, param2, param3, param4) 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 ab64c50d..185356da 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 @@ -43,7 +43,7 @@ import kotlin.reflect.KClass * Multiplatform service manager for Spring Boot. */ @UseExperimental(ExperimentalCoroutinesApi::class) -@Suppress("LargeClass") +@Suppress("LargeClass", "TooManyFunctions") actual open class KVServiceManager<T : Any> actual constructor(val serviceClass: KClass<T>) { companion object { @@ -455,7 +455,7 @@ actual open class KVServiceManager<T : Any> actual constructor(val serviceClass: */ @Suppress("TooGenericExceptionCaught") protected actual fun bind( - function: T.(String?, String?) -> List<RemoteSelectOption> + function: T.(String?, String?) -> List<RemoteOption> ) { val routeDef = "route${this::class.simpleName}${counter++}" addRoute(HttpMethod.POST, "/kv/$routeDef") { req, res, ctx -> @@ -510,10 +510,12 @@ actual open class KVServiceManager<T : Any> actual constructor(val serviceClass: addRoute(HttpMethod.POST, "/kv/$routeDef") { req, res, ctx -> val service = ctx.getBean(serviceClass.java) val jsonRpcRequest = mapper.readValue(req.inputStream, JsonRpcRequest::class.java) + @Suppress("MagicNumber") 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]) + @Suppress("MagicNumber") val param4 = getParameter<List<RemoteSorter>?>(jsonRpcRequest.params[3]) try { val result = function.invoke(service, param1, param2, param3, param4) diff --git a/kvision-modules/kvision-tabulator-remote/src/main/kotlin/pl/treksoft/kvision/tabulator/RemoteTabulator.kt b/kvision-modules/kvision-tabulator-remote/src/main/kotlin/pl/treksoft/kvision/tabulator/TabulatorRemote.kt index 8070a187..4478b942 100644 --- a/kvision-modules/kvision-tabulator-remote/src/main/kotlin/pl/treksoft/kvision/tabulator/RemoteTabulator.kt +++ b/kvision-modules/kvision-tabulator-remote/src/main/kotlin/pl/treksoft/kvision/tabulator/TabulatorRemote.kt @@ -47,7 +47,7 @@ import pl.treksoft.kvision.utils.JSON * @param classes a set of CSS class names */ @UseExperimental(ImplicitReflectionSerializer::class) -open class RemoteTabulator<T : Any, E : Any>( +open class TabulatorRemote<T : Any, E : Any>( serviceManager: KVServiceManager<E>, function: E.(Int?, Int?, List<RemoteFilter>?, List<RemoteSorter>?) -> RemoteData<T>, options: TabulatorOptions<T> = TabulatorOptions(), @@ -96,18 +96,18 @@ open class RemoteTabulator<T : Any, E : Any>( * * It takes the same parameters as the constructor of the built component. */ - fun <T : Any, E : Any> Container.remoteTabulator( + fun <T : Any, E : Any> Container.tabulatorRemote( serviceManager: KVServiceManager<E>, function: E.(Int?, Int?, List<RemoteFilter>?, List<RemoteSorter>?) -> RemoteData<T>, options: TabulatorOptions<T> = TabulatorOptions(), types: Set<TableType> = setOf(), classes: Set<String> = setOf(), - init: (RemoteTabulator<T, E>.() -> Unit)? = null - ): RemoteTabulator<T, E> { - val remoteTabulator = RemoteTabulator(serviceManager, function, options, types, classes) - init?.invoke(remoteTabulator) - this.add(remoteTabulator) - return remoteTabulator + init: (TabulatorRemote<T, E>.() -> Unit)? = null + ): TabulatorRemote<T, E> { + val tabulatorRemote = TabulatorRemote(serviceManager, function, options, types, classes) + init?.invoke(tabulatorRemote) + this.add(tabulatorRemote) + return tabulatorRemote } } |