function SetUiStateRunning() { $('#resultTable').html(''); $('#resultInfo').html('waiting for result...'); $('#msgContainer').attr('class', 'alert alert-warning'); $('#performanceDataTable tbody').html(''); } function SetUiStateError(msg) { $('#resultInfo').html(msg); $('#msgContainer').attr('class', 'alert alert-danger'); $('#performanceDataTable tbody').html(''); } function SetUiStateSuccess(msg) { $('#msgContainer').attr('class', 'alert alert-success'); $('#resultInfo').html(msg); } function GetHyriseUrl() { var endpointUrl = $('#endpointInput').val(); return endpointUrl; } function GetQuery() { var query = $('#queryInput').val(); // Check whether a part of the query has been selected var selectedText = GetSelectedText(); if (query.indexOf(selectedText) >= 0) { query = selectedText; } return query; } /** * Bootstrap */ $(function() { LoadSampleQueries('sample-queries.sql'); // Simple query submit $('#submitBtn').click(function() { SetUiStateRunning(); var query = GetQuery(); var hyrise = new HyriseConnector(GetHyriseUrl()); hyrise.executeSQL(query, function(result) { console.log("Query result: ", result); // On Success SetUiStateSuccess('Result contains ' + result.real_size + ' rows'); UpdateResultTable(result); UpdatePerformanceData(result.performanceData); }, function(xhr, status, error) { // console.log(arguments); // On Error var msg = 'Error when fetching result. Possibly no connection to Hyrise.'; if (xhr.responseJSON) msg = xhr.responseJSON.error[0]; SetUiStateError(msg); }); }); $('#queryInput').keypress(function(evt) { if (evt.keyCode == 13 && evt.shiftKey) { $('#submitBtn').click(); return false; } return true; }); // Benchmark submit $('#benchmarkBtn').click(function() { SetUiStateRunning(); var query = GetQuery(); var hyrise = new HyriseConnector(GetHyriseUrl()); // TODO: hardcoded 5 var numRuns = parseInt($('#benchmarkInput').val()); hyrise.benchmarkSQL(query, numRuns, function(result) { console.log("Benchmark result: ", result); UpdatePerformanceData(result.performanceData); SetUiStateSuccess('Success! See PerformanceData for results.'); }); }); // Setup Table triggers var table = document.querySelector('#performanceDataTable'); $('#performanceDataTable thead th').click(function() { var key = $(this).attr('data-key'); if (table._sortKey && table._sortKey == key) table._asc = !table._asc; else table._asc = true; var sign = (table._asc) ? 1 : -1; if (table._data) { table._sortKey = key; SortTableData(table); InsertPerformanceData(table._data); } }); }); function GetSelectedText() { var text = ""; if (window.getSelection) { text = window.getSelection().toString(); } else if (document.selection && document.selection.type != "Control") { text = document.selection.createRange().text; } return (text === "") ? null : text; } function LoadSampleQueries(url) { $.get(url, function(data) { var lines = data.split('\n'); var name, query = "", isBuggy = false; $.each(lines, function(i, line) { if (line[0] == '#') { // Append last query if (name && !isBuggy) AddSampleQuery(name, query); if (name && isBuggy) AddBuggyQuery(name, query); // New query isBuggy = (line[1] == '!'); name = line.substring((isBuggy) ? 3 : 2); query = ""; } else { query += line + '\n'; } }); if (name && !isBuggy) AddSampleQuery(name, query); if (name && isBuggy) AddBuggyQuery(name, query); }); } function AddSampleQuery(name, query) { var btn = $(''); btn.click(function(evt) { $('#queryInput').val(query); if (!evt.shiftKey) { $('#submitBtn').click(); } }); $('#sampleQueries').append(btn); } function AddBuggyQuery(name, query) { var btn = $(''); btn.click(function(evt) { $('#queryInput').val(query); if (!evt.shiftKey) { $('#submitBtn').click(); } }); $('#buggyQueries').append(btn); } function CreateElement(tag, value) { return $('<' + tag + '>' + value + '' + tag + '>'); }; function UpdateResultTable(result) { // Present result json in result-view var table = $('#resultTable'); table.html(''); var th = $('