2018-11-04 19:56:06 +00:00
|
|
|
var target, use_tls, editor;
|
|
|
|
|
|
|
|
$('#get-services').click(function(){
|
|
|
|
var t = get_valid_target();
|
2019-03-13 03:38:30 +00:00
|
|
|
|
2019-03-14 01:58:11 +00:00
|
|
|
use_tls = "false";
|
2019-03-13 03:38:30 +00:00
|
|
|
var restart = "0"
|
|
|
|
if($('#restart-conn').is(":checked")) {
|
|
|
|
restart = "1"
|
|
|
|
}
|
2019-03-14 01:58:11 +00:00
|
|
|
|
|
|
|
if (target != t || restart == "1") {
|
|
|
|
target = t;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-11-04 19:56:06 +00:00
|
|
|
$('.other-elem').hide();
|
|
|
|
var button = $(this).html();
|
|
|
|
$.ajax({
|
2019-03-13 03:38:30 +00:00
|
|
|
url: "server/"+target+"/services?restart="+restart,
|
2018-11-04 19:56:06 +00:00
|
|
|
global: true,
|
|
|
|
method: "GET",
|
|
|
|
success: function(res){
|
|
|
|
if (res.error) {
|
|
|
|
target = "";
|
|
|
|
use_tls = "";
|
|
|
|
alert(res.error);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$("#select-service").html(new Option("Choose Service", ""));
|
|
|
|
$.each(res.data, (_, item) => $("#select-service").append(new Option(item, item)));
|
|
|
|
$('#choose-service').show();
|
|
|
|
},
|
|
|
|
error: function(_, _, errorThrown) {
|
|
|
|
target = "";
|
|
|
|
use_tls = "";
|
|
|
|
alert(errorThrown);
|
|
|
|
},
|
|
|
|
beforeSend: function(xhr){
|
2019-03-12 04:18:27 +00:00
|
|
|
$('#choose-service').hide();
|
2018-11-04 19:56:06 +00:00
|
|
|
xhr.setRequestHeader('use_tls', use_tls);
|
|
|
|
$(this).html("Loading...");
|
2019-03-12 04:18:27 +00:00
|
|
|
show_loading();
|
2018-11-04 19:56:06 +00:00
|
|
|
},
|
|
|
|
complete: function(){
|
2019-03-13 03:38:30 +00:00
|
|
|
applyConnCount();
|
2018-11-04 19:56:06 +00:00
|
|
|
$(this).html(button);
|
2019-03-12 04:18:27 +00:00
|
|
|
hide_loading();
|
2018-11-04 19:56:06 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#select-service').change(function(){
|
|
|
|
var selected = $(this).val();
|
|
|
|
if (selected == "") {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$('#body-request').hide();
|
|
|
|
$('#response').hide();
|
|
|
|
$.ajax({
|
|
|
|
url: "server/"+target+"/service/"+selected+"/functions",
|
|
|
|
global: true,
|
|
|
|
method: "GET",
|
|
|
|
success: function(res){
|
|
|
|
if (res.error) {
|
|
|
|
alert(res.error);
|
|
|
|
return;
|
|
|
|
}
|
2018-11-05 03:57:30 +00:00
|
|
|
$("#select-function").html(new Option("Choose Method", ""));
|
2018-11-04 19:56:06 +00:00
|
|
|
$.each(res.data, (_, item) => $("#select-function").append(new Option(item.substr(selected.length) , item)));
|
|
|
|
$('#choose-function').show();
|
|
|
|
},
|
|
|
|
error: err,
|
|
|
|
beforeSend: function(xhr){
|
2019-03-12 04:18:27 +00:00
|
|
|
$('#choose-function').hide();
|
2018-11-04 19:56:06 +00:00
|
|
|
xhr.setRequestHeader('use_tls', use_tls);
|
|
|
|
show_loading();
|
|
|
|
},
|
|
|
|
complete: function(){
|
|
|
|
hide_loading();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#select-function').change(function(){
|
|
|
|
var selected = $(this).val();
|
|
|
|
if (selected == "") {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$('#response').hide();
|
|
|
|
$.ajax({
|
|
|
|
url: "server/"+target+"/function/"+selected+"/describe",
|
|
|
|
global: true,
|
|
|
|
method: "GET",
|
|
|
|
success: function(res){
|
|
|
|
if (res.error) {
|
|
|
|
alert(res.error);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
generate_editor(res.data.template);
|
|
|
|
$("#schema-proto").html(PR.prettyPrintOne(res.data.schema));
|
|
|
|
$('#body-request').show();
|
|
|
|
},
|
|
|
|
error: err,
|
|
|
|
beforeSend: function(xhr){
|
2019-03-12 04:18:27 +00:00
|
|
|
$('#body-request').hide();
|
2018-11-04 19:56:06 +00:00
|
|
|
xhr.setRequestHeader('use_tls', use_tls);
|
|
|
|
show_loading();
|
|
|
|
},
|
|
|
|
complete: function(){
|
|
|
|
hide_loading();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
$('#invoke-func').click(function(){
|
|
|
|
var func = $('#select-function').val();
|
|
|
|
if (func == "") {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
var body = editor.getValue();
|
|
|
|
var button = $(this).html();
|
|
|
|
$.ajax({
|
|
|
|
url: "server/"+target+"/function/"+func+"/invoke",
|
|
|
|
global: true,
|
|
|
|
method: "POST",
|
|
|
|
data: body,
|
|
|
|
dataType: "json",
|
|
|
|
success: function(res){
|
|
|
|
if (res.error) {
|
|
|
|
alert(res.error);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$("#json-response").html(PR.prettyPrintOne(res.data.result));
|
|
|
|
$("#timer-resp span").html(res.data.timer);
|
|
|
|
$('#response').show();
|
|
|
|
},
|
|
|
|
error: err,
|
|
|
|
beforeSend: function(xhr){
|
2019-03-12 04:18:27 +00:00
|
|
|
$('#response').hide();
|
2018-11-04 19:56:06 +00:00
|
|
|
xhr.setRequestHeader('use_tls', use_tls);
|
|
|
|
$(this).html("Loading...");
|
2019-03-12 04:18:27 +00:00
|
|
|
show_loading();
|
2018-11-04 19:56:06 +00:00
|
|
|
},
|
|
|
|
complete: function(){
|
|
|
|
$(this).html(button);
|
2019-03-12 04:18:27 +00:00
|
|
|
hide_loading();
|
2018-11-04 19:56:06 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
function generate_editor(content) {
|
|
|
|
if(editor) {
|
|
|
|
editor.setValue(content);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
$("#editor").html(content);
|
|
|
|
editor = ace.edit("editor");
|
|
|
|
editor.setOptions({
|
|
|
|
maxLines: Infinity
|
|
|
|
});
|
|
|
|
editor.renderer.setScrollMargin(10, 10, 10, 10);
|
|
|
|
editor.setTheme("ace/theme/github");
|
|
|
|
editor.session.setMode("ace/mode/json");
|
|
|
|
editor.renderer.setShowGutter(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_valid_target() {
|
|
|
|
t = $('#server-target').val().trim();
|
|
|
|
if (t == "") {
|
|
|
|
return target;
|
|
|
|
}
|
|
|
|
|
|
|
|
ts = t.split("://");
|
|
|
|
if (ts.length > 1) {
|
|
|
|
$('#server-target').val(ts[1]);
|
|
|
|
return ts[1];
|
|
|
|
}
|
|
|
|
return ts[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
function err(_, _, errorThrown) {
|
|
|
|
alert(errorThrown);
|
|
|
|
}
|
|
|
|
|
|
|
|
function show_loading() {
|
2019-03-12 04:18:27 +00:00
|
|
|
$('.spinner').show();
|
2018-11-04 19:56:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function hide_loading() {
|
2019-03-12 04:18:27 +00:00
|
|
|
$('.spinner').hide();
|
2019-03-13 03:38:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$(".connections ul").on("click", "i", function(){
|
2019-04-05 01:58:49 +00:00
|
|
|
$icon = $(this);
|
2019-03-13 03:38:30 +00:00
|
|
|
$parent = $(this).parent("li");
|
|
|
|
var ip = $(this).siblings("span").text();
|
|
|
|
|
|
|
|
$.ajax({
|
2019-03-21 02:43:47 +00:00
|
|
|
url: "active/close/" + ip,
|
2019-03-13 03:38:30 +00:00
|
|
|
global: true,
|
|
|
|
method: "DELETE",
|
|
|
|
success: function(res){
|
2019-04-05 01:58:49 +00:00
|
|
|
$('[data-toggle="tooltip"]').tooltip('hide');
|
2019-03-13 03:38:30 +00:00
|
|
|
if(res.data.success) {
|
|
|
|
$parent.remove();
|
|
|
|
updateCountNum();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
error: err,
|
|
|
|
beforeSend: function(xhr){
|
2019-04-05 01:58:49 +00:00
|
|
|
$icon.attr('class', 'fa fa-spinner');
|
2019-03-13 03:38:30 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
function updateCountNum() {
|
|
|
|
$(".connections .title span").html($(".connections ul li").length);
|
|
|
|
}
|
|
|
|
|
|
|
|
function applyConnCount() {
|
2019-04-02 09:24:26 +00:00
|
|
|
$('[data-toggle="tooltip"]').tooltip('hide');
|
|
|
|
|
2019-03-13 03:38:30 +00:00
|
|
|
$.ajax({
|
|
|
|
url: "active/get",
|
|
|
|
global: true,
|
|
|
|
method: "GET",
|
|
|
|
success: function(res){
|
|
|
|
$(".connections .title span").html(res.data.length);
|
|
|
|
$(".connections .nav").html("");
|
|
|
|
res.data.forEach(function(item){
|
|
|
|
$list = $("#conn-list-template").clone();
|
|
|
|
$list.find(".ip").html(item);
|
|
|
|
$(".connections .nav").append($list.html());
|
|
|
|
});
|
2019-03-14 01:35:34 +00:00
|
|
|
refreshToolTip();
|
2019-03-13 03:38:30 +00:00
|
|
|
},
|
2019-03-14 02:11:18 +00:00
|
|
|
error: function (_, _, thrownError) {
|
|
|
|
console.warn("Failed to update active connections", thrownError)
|
|
|
|
},
|
2019-03-13 03:38:30 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function refreshConnCount() {
|
|
|
|
applyConnCount();
|
2019-04-02 09:24:26 +00:00
|
|
|
setTimeout(refreshConnCount, 10000);
|
2019-03-13 03:38:30 +00:00
|
|
|
}
|
|
|
|
|
2019-03-14 01:35:34 +00:00
|
|
|
function refreshToolTip() {
|
|
|
|
$(function () {
|
2019-04-02 02:45:50 +00:00
|
|
|
$('[data-toggle="tooltip"]').tooltip('dispose');
|
|
|
|
$('[data-toggle="tooltip"]').tooltip();
|
2019-03-14 01:35:34 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-03-13 03:38:30 +00:00
|
|
|
$(document).ready(function(){
|
|
|
|
refreshConnCount();
|
|
|
|
});
|