Update play.html

Allow to pass query settings via server URI
This commit is contained in:
kolsys 2021-08-04 12:48:56 +03:00 committed by GitHub
parent d9c9422a44
commit e740d8e643
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -361,23 +361,22 @@
function postImpl(posted_request_num, query) function postImpl(posted_request_num, query)
{ {
/// TODO: Check if URL already contains query string (append parameters). const user = document.getElementById('user').value;
const password = document.getElementById('password').value;
let user = document.getElementById('user').value; const server_address = document.getElementById('url').value;
let password = document.getElementById('password').value;
let server_address = document.getElementById('url').value; const url = server_address +
(~server_address.indexOf('?') ? '&' : '?') +
let url = server_address +
/// Ask server to allow cross-domain requests. /// Ask server to allow cross-domain requests.
'?add_http_cors_header=1' + 'add_http_cors_header=1' +
'&user=' + encodeURIComponent(user) + '&user=' + encodeURIComponent(user) +
'&password=' + encodeURIComponent(password) + '&password=' + encodeURIComponent(password) +
'&default_format=JSONCompact' + '&default_format=JSONCompact' +
/// Safety settings to prevent results that browser cannot display. /// Safety settings to prevent results that browser cannot display.
'&max_result_rows=1000&max_result_bytes=10000000&result_overflow_mode=break'; '&max_result_rows=1000&max_result_bytes=10000000&result_overflow_mode=break';
let xhr = new XMLHttpRequest; const xhr = new XMLHttpRequest;
xhr.open('POST', url, true); xhr.open('POST', url, true);
@ -391,12 +390,12 @@
/// The query is saved in browser history (in state JSON object) /// The query is saved in browser history (in state JSON object)
/// as well as in URL fragment identifier. /// as well as in URL fragment identifier.
if (query != previous_query) { if (query != previous_query) {
let state = { const state = {
query: query, query: query,
status: this.status, status: this.status,
response: this.response.length > 100000 ? null : this.response /// Lower than the browser's limit. response: this.response.length > 100000 ? null : this.response /// Lower than the browser's limit.
}; };
let title = "ClickHouse Query: " + query; const title = "ClickHouse Query: " + query;
let history_url = window.location.pathname + '?user=' + encodeURIComponent(user); let history_url = window.location.pathname + '?user=' + encodeURIComponent(user);
if (server_address != location.origin) { if (server_address != location.origin) {