aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Jaros <rjaros@finn.pl>2020-01-19 22:45:28 +0100
committerRobert Jaros <rjaros@finn.pl>2020-01-19 22:45:28 +0100
commit110c60e71d1f66a521764e3768b140744d28bee7 (patch)
tree12806b558beac8864aadf2a429ced54ebc8d22e4
parent0b908282fcbf397f30df3d47c41cafcbf0406bce (diff)
downloadkvision-110c60e71d1f66a521764e3768b140744d28bee7.tar.gz
kvision-110c60e71d1f66a521764e3768b140744d28bee7.tar.bz2
kvision-110c60e71d1f66a521764e3768b140744d28bee7.zip
Fix external URL prefix for SelectRemote and TabulatorRemote components
-rw-r--r--kvision-modules/kvision-bootstrap-select-remote/src/main/kotlin/pl/treksoft/kvision/form/select/SelectRemoteInput.kt8
-rw-r--r--kvision-modules/kvision-tabulator-remote/src/main/kotlin/pl/treksoft/kvision/tabulator/TabulatorRemote.kt16
2 files changed, 18 insertions, 6 deletions
diff --git a/kvision-modules/kvision-bootstrap-select-remote/src/main/kotlin/pl/treksoft/kvision/form/select/SelectRemoteInput.kt b/kvision-modules/kvision-bootstrap-select-remote/src/main/kotlin/pl/treksoft/kvision/form/select/SelectRemoteInput.kt
index ac05a6d3..391b53ef 100644
--- a/kvision-modules/kvision-bootstrap-select-remote/src/main/kotlin/pl/treksoft/kvision/form/select/SelectRemoteInput.kt
+++ b/kvision-modules/kvision-bootstrap-select-remote/src/main/kotlin/pl/treksoft/kvision/form/select/SelectRemoteInput.kt
@@ -27,6 +27,7 @@ import kotlinx.coroutines.launch
import kotlinx.serialization.ImplicitReflectionSerializer
import kotlinx.serialization.list
import kotlinx.serialization.stringify
+import org.w3c.dom.get
import pl.treksoft.kvision.core.Container
import pl.treksoft.kvision.remote.CallAgent
import pl.treksoft.kvision.remote.HttpMethod
@@ -35,6 +36,7 @@ import pl.treksoft.kvision.remote.KVServiceManager
import pl.treksoft.kvision.remote.RemoteOption
import pl.treksoft.kvision.utils.JSON
import pl.treksoft.kvision.utils.obj
+import kotlin.browser.window
external fun decodeURIComponent(encodedURI: String): String
@@ -62,6 +64,10 @@ open class SelectRemoteInput<T : Any>(
private val preload: Boolean = false,
classes: Set<String> = setOf()
) : SelectInput(null, value, multiple, null, classes) {
+
+ private val kvUrlPrefix = window["kv_remote_url_prefix"]
+ private val urlPrefix: String = if (kvUrlPrefix != undefined) kvUrlPrefix else ""
+
private val url: String
private val labelsCache = mutableMapOf<String, String>()
private var initRun = false
@@ -77,7 +83,7 @@ open class SelectRemoteInput<T : Any>(
}
val tempAjaxOptions = ajaxOptions ?: AjaxOptions()
this.ajaxOptions = tempAjaxOptions.copy(
- url = url,
+ url = urlPrefix + url,
preprocessData = {
@Suppress("UnsafeCastFromDynamic")
JSON.plain.parse(RemoteOption.serializer().list, it.result as String).map {
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 c3074640..b413066e 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
@@ -23,16 +23,18 @@ package pl.treksoft.kvision.tabulator
import kotlinx.serialization.ImplicitReflectionSerializer
import kotlinx.serialization.stringify
+import org.w3c.dom.get
import pl.treksoft.kvision.core.Container
+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.RemoteData
import pl.treksoft.kvision.remote.RemoteFilter
import pl.treksoft.kvision.remote.RemoteSorter
-import pl.treksoft.kvision.rest.HttpMethod
-import pl.treksoft.kvision.rest.RestClient
import pl.treksoft.kvision.table.TableType
import pl.treksoft.kvision.utils.JSON
+import kotlin.browser.window
/**
* Tabulator component connected to the multiplatform service.
@@ -56,13 +58,17 @@ open class TabulatorRemote<T : Any, E : Any>(
types: Set<TableType> = setOf(),
classes: Set<String> = setOf()
) : Tabulator<T>(null, false, options, types, classes) {
+
+ private val kvUrlPrefix = window["kv_remote_url_prefix"]
+ private val urlPrefix: String = if (kvUrlPrefix != undefined) kvUrlPrefix else ""
+
init {
val (url, method) =
serviceManager.getCalls()[function.toString().replace("\\s".toRegex(), "")]
?: throw IllegalStateException("Function not specified!")
- val restClient = RestClient()
- options.ajaxURL = url
+ val callAgent = CallAgent()
+ options.ajaxURL = urlPrefix + url
options.ajaxRequestFunc = { _, _, params ->
val page = params.page
val size = params.size
@@ -81,7 +87,7 @@ open class TabulatorRemote<T : Any, E : Any>(
val state = stateFunction?.invoke()
@Suppress("UnsafeCastFromDynamic")
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 ->
+ callAgent.remoteCall(url, data, method = HttpMethod.valueOf(method.name)).then { r: dynamic ->
val result = kotlin.js.JSON.parse<dynamic>(r.result as String)
@Suppress("UnsafeCastFromDynamic")
if (page != null) {