From 6c1c0e7bb02843a8088a011dbfb224605c201dd7 Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Wed, 20 May 2020 15:11:04 +0200 Subject: Support relative links for remote endpoints --- .../main/kotlin/pl/treksoft/kvision/form/select/SelectRemoteInput.kt | 4 ++-- .../main/kotlin/pl/treksoft/kvision/form/text/TypeaheadRemoteInput.kt | 4 ++-- .../src/main/kotlin/pl/treksoft/kvision/tabulator/TabulatorRemote.kt | 4 ++-- 3 files changed, 6 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 b6319a6b..b2dad8fe 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 @@ -67,7 +67,7 @@ open class SelectRemoteInput( ) : 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 urlPrefix: String = if (kvUrlPrefix != undefined) "$kvUrlPrefix/" else "" private val url: String private val labelsCache = mutableMapOf() @@ -84,7 +84,7 @@ open class SelectRemoteInput( } val tempAjaxOptions = ajaxOptions ?: AjaxOptions() this.ajaxOptions = tempAjaxOptions.copy( - url = urlPrefix + url, + url = urlPrefix + url.drop(1), preprocessData = { @Suppress("UnsafeCastFromDynamic") JSON.plain.parse(RemoteOption.serializer().list, it.result as String).map { diff --git a/kvision-modules/kvision-bootstrap-typeahead-remote/src/main/kotlin/pl/treksoft/kvision/form/text/TypeaheadRemoteInput.kt b/kvision-modules/kvision-bootstrap-typeahead-remote/src/main/kotlin/pl/treksoft/kvision/form/text/TypeaheadRemoteInput.kt index 0693756b..932a86ff 100644 --- a/kvision-modules/kvision-bootstrap-typeahead-remote/src/main/kotlin/pl/treksoft/kvision/form/text/TypeaheadRemoteInput.kt +++ b/kvision-modules/kvision-bootstrap-typeahead-remote/src/main/kotlin/pl/treksoft/kvision/form/text/TypeaheadRemoteInput.kt @@ -57,14 +57,14 @@ open class TypeaheadRemoteInput( ) : TypeaheadInput(null, null, items, minLength, delay, type, value, classes) { private val kvUrlPrefix = window["kv_remote_url_prefix"] - private val urlPrefix: String = if (kvUrlPrefix != undefined) kvUrlPrefix else "" + 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!") this.ajaxOptions = TaAjaxOptions( - urlPrefix + url, + urlPrefix + url.drop(1), preprocessQuery = { query -> val state = stateFunction?.invoke() JSON.plain.stringify(JsonRpcRequest(0, url, listOf(query, state))) 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 e4473ed8..e61ced55 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 @@ -61,7 +61,7 @@ open class TabulatorRemote( ) : Tabulator(null, false, options, types, classes) { private val kvUrlPrefix = window["kv_remote_url_prefix"] - private val urlPrefix: String = if (kvUrlPrefix != undefined) kvUrlPrefix else "" + private val urlPrefix: String = if (kvUrlPrefix != undefined) "$kvUrlPrefix/" else "" init { val (url, method) = @@ -69,7 +69,7 @@ open class TabulatorRemote( ?: throw IllegalStateException("Function not specified!") val callAgent = CallAgent() - options.ajaxURL = urlPrefix + url + options.ajaxURL = urlPrefix + url.drop(1) options.ajaxRequestFunc = { _, _, params -> val page = params.page val size = params.size -- cgit