From 110c60e71d1f66a521764e3768b140744d28bee7 Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Sun, 19 Jan 2020 22:45:28 +0100 Subject: Fix external URL prefix for SelectRemote and TabulatorRemote components --- .../pl/treksoft/kvision/tabulator/TabulatorRemote.kt | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'kvision-modules/kvision-tabulator-remote/src/main/kotlin/pl/treksoft') 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( types: Set = setOf(), classes: Set = setOf() ) : Tabulator(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( 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(r.result as String) @Suppress("UnsafeCastFromDynamic") if (page != null) { -- cgit