1
0
mirror of https://github.com/donaldzou/WGDashboard.git synced 2024-11-22 23:27:45 +01:00

Cleaned configuration.js

Removed unused functions and duplicated jQuery selector
This commit is contained in:
Donald Cheng Hong Zou 2021-12-29 23:26:15 -05:00
parent b9553e0a05
commit 7d9bf01d27
2 changed files with 194 additions and 201 deletions

View File

@ -883,10 +883,8 @@ def switch(config_name):
check=True, shell=True, capture_output=True).stdout check=True, shell=True, capture_output=True).stdout
except subprocess.CalledProcessError: except subprocess.CalledProcessError:
return redirect('/') return redirect('/')
return redirect(request.referrer) return redirect(request.referrer)
# Add peer # Add peer
@app.route('/add_peer/<config_name>', methods=['POST']) @app.route('/add_peer/<config_name>', methods=['POST'])
def add_peer(config_name): def add_peer(config_name):
@ -1315,7 +1313,7 @@ Dashboard Tools Related
def get_ping_ip(): def get_ping_ip():
config = request.form['config'] config = request.form['config']
sem.acquire(timeout=1) sem.acquire(timeout=1)
db = TinyDB(os.path.join(db_path, config_name + ".json")) db = TinyDB(os.path.join(db_path, config + ".json"))
html = "" html = ""
for i in db.all(): for i in db.all():
html += '<optgroup label="' + i['name'] + ' - ' + i['id'] + '">' html += '<optgroup label="' + i['name'] + ' - ' + i['id'] + '">'
@ -1411,7 +1409,7 @@ def init_dashboard():
config['Server']['dashboard_refresh_interval'] = '60000' config['Server']['dashboard_refresh_interval'] = '60000'
if 'dashboard_sort' not in config['Server']: if 'dashboard_sort' not in config['Server']:
config['Server']['dashboard_sort'] = 'status' config['Server']['dashboard_sort'] = 'status'
# Defualt dashboard peers setting # Default dashboard peers setting
if "Peers" not in config: if "Peers" not in config:
config['Peers'] = {} config['Peers'] = {}
if 'peer_global_DNS' not in config['Peers']: if 'peer_global_DNS' not in config['Peers']:
@ -1454,7 +1452,7 @@ if __name__ == "__main__":
UPDATE = check_update() UPDATE = check_update()
configuration_settings = get_dashboard_conf() configuration_settings = get_dashboard_conf()
app_ip = configuration_settings.get("Server", "app_ip") app_ip = configuration_settings.get("Server", "app_ip")
app_port = configuration_settings.get("Server", "app_port") app_port = int(configuration_settings.get("Server", "app_port"))
wg_conf_path = configuration_settings.get("Server", "wg_conf_path") wg_conf_path = configuration_settings.get("Server", "wg_conf_path")
configuration_settings.clear() configuration_settings.clear()
app.run(host=app_ip, debug=False, port=app_port) app.run(host=app_ip, debug=False, port=app_port)

View File

@ -1,27 +1,26 @@
let $body = $("body"); let $body = $("body");
// Progress Bar // Progress Bar
let $progress_bar = $(".progress-bar") let $progress_bar = $(".progress-bar");
function startProgressBar(){ function startProgressBar(){
$progress_bar.css("width","0%") $progress_bar.css("width","0%")
$progress_bar.css("opacity", "100") .css("opacity", "100")
$progress_bar.css("background", "rgb(255,69,69)") .css("background", "rgb(255,69,69)")
$progress_bar.css("background", "linear-gradient(145deg, rgba(255,69,69,1) 0%, rgba(0,115,186,1) 100%)") .css("background",
$progress_bar.css("width","25%") "linear-gradient(145deg, rgba(255,69,69,1) 0%, rgba(0,115,186,1) 100%)")
.css("width","25%");
setTimeout(function(){ setTimeout(function(){
stillLoadingProgressBar(); stillLoadingProgressBar();
},300) },300);
} }
function stillLoadingProgressBar(){ function stillLoadingProgressBar(){
$progress_bar.css("transition", "3s ease-in-out") $progress_bar.css("transition", "3s ease-in-out").css("width", "75%");
$progress_bar.css("width", "75%")
} }
function endProgressBar(){ function endProgressBar(){
$progress_bar.css("transition", "0.3s ease-in-out") $progress_bar.css("transition", "0.3s ease-in-out").css("width","100%");
$progress_bar.css("width","100%")
setTimeout(function(){ setTimeout(function(){
$progress_bar.css("opacity", "0") $progress_bar.css("opacity", "0");
},250) },250);
} }
@ -34,9 +33,9 @@ function showToast(msg) {
// Config Toggle // Config Toggle
$body.on("click", ".switch", function (){ $body.on("click", ".switch", function (){
$(this).siblings($(".spinner-border")).css("display", "inline-block"); $(this).siblings($(".spinner-border")).css("display", "inline-block");
$(this).remove() $(this).remove();
location.replace("/switch/"+$(this).attr('id')); location.replace("/switch/"+$(this).attr('id'));
}) });
// Generating Keys // Generating Keys
function generate_key(){ function generate_key(){
@ -44,12 +43,12 @@ function generate_key(){
"url": "/generate_peer", "url": "/generate_peer",
"method": "GET", "method": "GET",
}).done(function(res){ }).done(function(res){
$("#private_key").val(res.private_key) $("#private_key").val(res.private_key);
$("#public_key").val(res.public_key) $("#public_key").val(res.public_key);
$("#preshare_key").val(res.preshared_key) $("#preshare_key").val(res.preshared_key);
$("#add_peer_alert").addClass("d-none"); $("#add_peer_alert").addClass("d-none");
$("#re_generate_key i").removeClass("rotating") $("#re_generate_key i").removeClass("rotating");
}) });
} }
function generate_public_key(){ function generate_public_key(){
$.ajax({ $.ajax({
@ -58,53 +57,59 @@ function generate_public_key(){
"headers":{"Content-Type": "application/json"}, "headers":{"Content-Type": "application/json"},
"data": JSON.stringify({"private_key": $("#private_key").val()}) "data": JSON.stringify({"private_key": $("#private_key").val()})
}).done(function(res){ }).done(function(res){
if(res['status'] === "failed"){ if(res.status === "failed"){
$("#add_peer_alert").html(res['msg']); $("#add_peer_alert").html(res.msg).removeClass("d-none");
$("#add_peer_alert").removeClass("d-none");
}else{ }else{
$("#add_peer_alert").addClass("d-none"); $("#add_peer_alert").addClass("d-none");
} }
$("#public_key").val(res['data']) $("#public_key").val(res.data);
$("#re_generate_key i").removeClass("rotating") $("#re_generate_key i").removeClass("rotating");
}) });
} }
// Add Peer // Add Peer
$("#private_key").on("change",function(){ $("#private_key").on("change",function(){
if ($("#private_key").val().length > 0){ if ($(this).val().length > 0){
$("#re_generate_key i").addClass("rotating") $("#re_generate_key i").addClass("rotating");
generate_public_key() generate_public_key();
}else{ }else{
$("#public_key").removeAttr("disabled") $("#public_key").removeAttr("disabled").val("");
$("#public_key").val("")
} }
}) });
$('#add_modal').on('show.bs.modal', function (event) { $('#add_modal').on('show.bs.modal', function (event) {
generate_key() generate_key();
}) });
$("#re_generate_key").click(function (){ $("#re_generate_key").on("click",function (){
$("#public_key").attr("disabled","disabled") $("#public_key").attr("disabled","disabled");
$("#re_generate_key i").addClass("rotating") $("#re_generate_key i").addClass("rotating");
generate_key() generate_key();
}) });
let addModal = new bootstrap.Modal(document.getElementById('add_modal'), { let addModal = new bootstrap.Modal(document.getElementById('add_modal'), {
keyboard: false keyboard: false
}) });
$(".add_btn").on("click", function(){ $(".add_btn").on("click", function(){
addModal.toggle(); addModal.toggle();
}) });
$("#save_peer").on("click",function(){ $("#save_peer").on("click",function(){
$(this).attr("disabled","disabled") let $public_key = $("#public_key");
$(this).html("Saving...") let $private_key = $("#private_key");
let $allowed_ips = $("#allowed_ips");
let $new_add_DNS = $("#new_add_DNS");
let $new_add_endpoint_allowed_ip = $("#new_add_endpoint_allowed_ip");
let $new_add_name = $("#new_add_name");
let $new_add_MTU = $("#new_add_MTU");
let $new_add_keep_alive = $("#new_add_keep_alive");
let $enable_preshare_key = $("#enable_preshare_key");
if ($("#allowed_ips").val() !== "" && $("#public_key").val() !== "" && $("#new_add_DNS").val() !== "" && $("#new_add_endpoint_allowed_ip").val() != ""){ $(this).attr("disabled","disabled");
var conf = $(this).attr('conf_id') $(this).html("Saving...");
var data_list = [$("#private_key"), $("#allowed_ips"), $("#new_add_name"), $("#new_add_DNS"), $("#new_add_endpoint_allowed_ip"),$("#new_add_MTU"),$("#new_add_keep_alive")] if ($allowed_ips.val() !== "" && $public_key.val() !== "" && $new_add_DNS.val() !== "" && $new_add_endpoint_allowed_ip.val() !== ""){
for (var i = 0; i < data_list.length; i++){ let conf = $(this).attr('conf_id');
data_list[i].attr("disabled", "disabled") let data_list = [$private_key, $allowed_ips, $new_add_name, $new_add_DNS, $new_add_endpoint_allowed_ip,$new_add_MTU, $new_add_keep_alive];
} data_list.forEach((ele) => ele.attr("disabled", "disabled"));
$.ajax({ $.ajax({
method: "POST", method: "POST",
url: "/add_peer/"+conf, url: "/add_peer/"+conf,
@ -112,71 +117,67 @@ $("#save_peer").on("click",function(){
"Content-Type": "application/json" "Content-Type": "application/json"
}, },
data: JSON.stringify({ data: JSON.stringify({
"private_key":$("#private_key").val(), "private_key":$private_key.val(),
"public_key":$("#public_key").val(), "public_key":$public_key.val(),
"allowed_ips": $("#allowed_ips").val(), "allowed_ips": $allowed_ips.val(),
"name":$("#new_add_name").val(), "name":$new_add_name.val(),
"DNS": $("#new_add_DNS").val(), "DNS": $new_add_DNS.val(),
"endpoint_allowed_ip": $("#new_add_endpoint_allowed_ip").val(), "endpoint_allowed_ip": $new_add_endpoint_allowed_ip.val(),
"MTU": $("#new_add_MTU").val(), "MTU": $new_add_MTU.val(),
"keep_alive": $("#new_add_keep_alive").val(), "keep_alive": $new_add_keep_alive.val(),
"enable_preshared_key": $("#enable_preshare_key").prop("checked"), "enable_preshared_key": $enable_preshare_key.prop("checked"),
}), }),
success: function (response){ success: function (response){
if(response != "true"){ if(response !== "true"){
$("#add_peer_alert").html(response); $("#add_peer_alert").html(response).removeClass("d-none");
$("#add_peer_alert").removeClass("d-none"); data_list.forEach((ele) => ele.removeAttr("disabled"));
for (var i = 0; i < data_list.length; i++){ $("#save_peer").removeAttr("disabled").html("Save");
data_list[i].removeAttr("disabled", "disabled")
}
$("#save_peer").removeAttr("disabled")
$("#save_peer").html("Save")
} }
else{ else{
load_data(""); load_data("");
addModal.hide(); addModal.toggle();
} }
} }
}) });
}else{ }else{
$("#add_peer_alert").html("Please fill in all required box."); $("#add_peer_alert").html("Please fill in all required box.").removeClass("d-none");
$("#add_peer_alert").removeClass("d-none"); $(this).removeAttr("disabled");
$(this).removeAttr("disabled") $(this).html("Save");
$(this).html("Save")
} }
}) });
var qrcodeModal = new bootstrap.Modal(document.getElementById('qrcode_modal'), {
keyboard: false
})
let qrcodeModal = new bootstrap.Modal(document.getElementById('qrcode_modal'), {
keyboard: false
});
// QR Code // QR Code
$body.on("click", ".btn-qrcode-peer", function (){ $body.on("click", ".btn-qrcode-peer", function (){
var src = $(this).attr('img_src'); let src = $(this).attr('img_src');
$.ajax({ $.ajax({
"url": src, "url": src,
"method": "GET" "method": "GET"
}).done(function(res){ }).done(function(res){
$("#qrcode_img").attr('src', res) $("#qrcode_img").attr('src', res);
qrcodeModal.toggle(); qrcodeModal.toggle();
}) });
}) });
// Delete Peer Modal // Delete Peer Modal
var deleteModal = new bootstrap.Modal(document.getElementById('delete_modal'), { let deleteModal = new bootstrap.Modal(document.getElementById('delete_modal'), {
keyboard: false keyboard: false
}); });
$body.on("click", ".btn-delete-peer", function(){ $body.on("click", ".btn-delete-peer", function(){
var peer_id = $(this).attr("id"); let peer_id = $(this).attr("id");
$("#delete_peer").attr("peer_id", peer_id); $("#delete_peer").attr("peer_id", peer_id);
deleteModal.toggle(); deleteModal.toggle();
}) });
$("#delete_peer").click(function(){ $("#delete_peer").on("click",function(){
$(this).attr("disabled","disabled") $(this).attr("disabled","disabled");
$(this).html("Deleting...") $(this).html("Deleting...");
var peer_id = $(this).attr("peer_id"); let peer_id = $(this).attr("peer_id");
var config = $(this).attr("conf_id"); let config = $(this).attr("conf_id");
$.ajax({ $.ajax({
method: "POST", method: "POST",
url: "/remove_peer/"+config, url: "/remove_peer/"+config,
@ -186,28 +187,26 @@ $("#delete_peer").click(function(){
data: JSON.stringify({"action": "delete", "peer_id": peer_id}), data: JSON.stringify({"action": "delete", "peer_id": peer_id}),
success: function (response){ success: function (response){
if(response !== "true"){ if(response !== "true"){
$("#remove_peer_alert").html(response+$("#add_peer_alert").html()); $("#remove_peer_alert").html(response+$("#add_peer_alert").html()).removeClass("d-none");
$("#remove_peer_alert").removeClass("d-none");
} }
else{ else{
deleteModal.toggle(); deleteModal.toggle();
load_data($('#search_peer_textbox').val()); load_data($('#search_peer_textbox').val());
$('#alertToast').toast('show'); $('#alertToast').toast('show');
$('#alertToast .toast-body').html("Peer deleted!"); $('#alertToast .toast-body').html("Peer deleted!");
$("#delete_peer").removeAttr("disabled") $("#delete_peer").removeAttr("disabled").html("Delete");
$("#delete_peer").html("Delete")
} }
} }
}) });
}); });
// Peer Setting Modal // Peer Setting Modal
var settingModal = new bootstrap.Modal(document.getElementById('setting_modal'), { let settingModal = new bootstrap.Modal(document.getElementById('setting_modal'), {
keyboard: false keyboard: false
}) });
$body.on("click", ".btn-setting-peer", function(){ $body.on("click", ".btn-setting-peer", function(){
startProgressBar() startProgressBar();
var peer_id = $(this).attr("id"); let peer_id = $(this).attr("id");
$("#save_peer_setting").attr("peer_id", peer_id); $("#save_peer_setting").attr("peer_id", peer_id);
$.ajax({ $.ajax({
method: "POST", method: "POST",
@ -217,63 +216,65 @@ $body.on("click", ".btn-setting-peer", function(){
}, },
data: JSON.stringify({"id": peer_id}), data: JSON.stringify({"id": peer_id}),
success: function(response){ success: function(response){
var peer_name = ((response['name'] === "") ? "Untitled Peer" : response['name']) let peer_name = ((response.name === "") ? "Untitled Peer" : response.name);
$("#setting_modal .peer_name").html(peer_name); $("#setting_modal .peer_name").html(peer_name);
$("#setting_modal #peer_name_textbox").val(response['name']) $("#setting_modal #peer_name_textbox").val(response.name);
$("#setting_modal #peer_private_key_textbox").val(response['private_key']) $("#setting_modal #peer_private_key_textbox").val(response.private_key);
$("#setting_modal #peer_DNS_textbox").val(response['DNS']) $("#setting_modal #peer_DNS_textbox").val(response.DNS);
$("#setting_modal #peer_allowed_ip_textbox").val(response['allowed_ip']) $("#setting_modal #peer_allowed_ip_textbox").val(response.allowed_ip);
$("#setting_modal #peer_endpoint_allowed_ips").val(response['endpoint_allowed_ip']) $("#setting_modal #peer_endpoint_allowed_ips").val(response.endpoint_allowed_ip);
$("#setting_modal #peer_mtu").val(response['mtu']) $("#setting_modal #peer_mtu").val(response.mtu);
$("#setting_modal #peer_keep_alive").val(response['keep_alive']) $("#setting_modal #peer_keep_alive").val(response.keep_alive);
$("#setting_modal #peer_preshared_key_textbox").val(response["preshared_key"]) $("#setting_modal #peer_preshared_key_textbox").val(response.preshared_key);
settingModal.toggle(); settingModal.toggle();
endProgressBar() endProgressBar();
} }
}) });
}); });
$('#setting_modal').on('hidden.bs.modal', function (event) { $('#setting_modal').on('hidden.bs.modal', function (event) {
$("#setting_peer_alert").addClass("d-none"); $("#setting_peer_alert").addClass("d-none");
}) });
$("#peer_private_key_textbox").change(function(){ $("#peer_private_key_textbox").on("change",function(){
let $save_peer_setting = $("#save_peer_setting");
if ($(this).val().length > 0){ if ($(this).val().length > 0){
$.ajax({ $.ajax({
"url": "/check_key_match/"+$("#save_peer_setting").attr("conf_id"), "url": "/check_key_match/"+$save_peer_setting.attr("conf_id"),
"method": "POST", "method": "POST",
"headers":{"Content-Type": "application/json"}, "headers":{"Content-Type": "application/json"},
"data": JSON.stringify({ "data": JSON.stringify({
"private_key": $("#peer_private_key_textbox").val(), "private_key": $("#peer_private_key_textbox").val(),
"public_key": $("#save_peer_setting").attr("peer_id") "public_key": $save_peer_setting.attr("peer_id")
}) })
}).done(function(res){ }).done(function(res){
if(res['status'] == "failed"){ if(res.status === "failed"){
$("#setting_peer_alert").html(res['msg']); $("#setting_peer_alert").html(res.status).removeClass("d-none");
$("#setting_peer_alert").removeClass("d-none");
}else{ }else{
$("#setting_peer_alert").addClass("d-none"); $("#setting_peer_alert").addClass("d-none");
} }
}) });
} }
}) });
$("#save_peer_setting").click(function (){ $("#save_peer_setting").on("click",function (){
$(this).attr("disabled","disabled") $(this).attr("disabled","disabled");
$(this).html("Saving...") $(this).html("Saving...");
if ($("#peer_DNS_textbox").val() !== "" && let $peer_DNS_textbox = $("#peer_DNS_textbox");
$("#peer_allowed_ip_textbox").val() !== "" && let $peer_allowed_ip_textbox = $("#peer_allowed_ip_textbox");
$("#peer_endpoint_allowed_ips").val() != "" let $peer_endpoint_allowed_ips = $("#peer_endpoint_allowed_ips");
){ let $peer_name_textbox = $("#peer_name_textbox");
var peer_id = $(this).attr("peer_id"); let $peer_private_key_textbox = $("#peer_private_key_textbox");
var conf_id = $(this).attr("conf_id"); let $peer_preshared_key_textbox = $("#peer_preshared_key_textbox");
var data_list = [ let $peer_mtu = $("#peer_mtu");
$("#peer_name_textbox"), $("#peer_DNS_textbox"), $("#peer_private_key_textbox"), $("#peer_preshared_key_textbox"), let $peer_keep_alive = $("#peer_keep_alive");
$("#peer_allowed_ip_textbox"), $("#peer_endpoint_allowed_ips"), $("#peer_mtu"), $("#peer_keep_alive")
] if ($peer_DNS_textbox.val() !== "" &&
for (var i = 0; i < data_list.length; i++){ $peer_allowed_ip_textbox.val() !== "" && $peer_endpoint_allowed_ips.val() !== ""){
data_list[i].attr("disabled", "disabled") let peer_id = $(this).attr("peer_id");
} let conf_id = $(this).attr("conf_id");
let data_list = [$peer_name_textbox, $peer_DNS_textbox, $peer_private_key_textbox, $peer_preshared_key_textbox, $peer_allowed_ip_textbox, $peer_endpoint_allowed_ips, $peer_mtu, $peer_keep_alive];
data_list.forEach((ele) => ele.attr("disabled","disabled"));
$.ajax({ $.ajax({
method: "POST", method: "POST",
url: "/save_peer_setting/"+conf_id, url: "/save_peer_setting/"+conf_id,
@ -282,54 +283,47 @@ $("#save_peer_setting").click(function (){
}, },
data: JSON.stringify({ data: JSON.stringify({
id: peer_id, id: peer_id,
name: $("#peer_name_textbox").val(), name: $peer_name_textbox.val(),
DNS: $("#peer_DNS_textbox").val(), DNS: $peer_DNS_textbox.val(),
private_key: $("#peer_private_key_textbox").val(), private_key: $peer_private_key_textbox.val(),
allowed_ip: $("#peer_allowed_ip_textbox").val(), allowed_ip: $peer_allowed_ip_textbox.val(),
endpoint_allowed_ip: $("#peer_endpoint_allowed_ips").val(), endpoint_allowed_ip: $peer_endpoint_allowed_ips.val(),
MTU: $("#peer_mtu").val(), MTU: $peer_mtu.val(),
keep_alive: $("#peer_keep_alive").val(), keep_alive: $peer_keep_alive.val(),
preshared_key: $("#peer_preshared_key_textbox").val() preshared_key: $peer_preshared_key_textbox.val()
}), }),
success: function (response){ success: function (response){
if (response['status'] === "failed"){ if (response.status === "failed"){
$("#setting_peer_alert").html(response['msg']); $("#setting_peer_alert").html(response.msg).removeClass("d-none");
$("#setting_peer_alert").removeClass("d-none");
}else{ }else{
settingModal.toggle(); settingModal.toggle();
load_data($('#search_peer_textbox').val()) load_data($('#search_peer_textbox').val());
$('#alertToast').toast('show'); $('#alertToast').toast('show');
$('#alertToast .toast-body').html("Peer Saved!"); $('#alertToast .toast-body').html("Peer Saved!");
} }
$("#save_peer_setting").removeAttr("disabled") $("#save_peer_setting").removeAttr("disabled").html("Save");
$("#save_peer_setting").html("Save") data_list.forEach((ele) => ele.removeAttr("disabled"));
for (var i = 0; i < data_list.length; i++){
data_list[i].removeAttr("disabled")
}
} }
}) });
}else{ }else{
$("#setting_peer_alert").html("Please fill in all required box."); $("#setting_peer_alert").html("Please fill in all required box.").removeClass("d-none");
$("#setting_peer_alert").removeClass("d-none"); $("#save_peer_setting").removeAttr("disabled").html("Save");
$("#save_peer_setting").removeAttr("disabled")
$("#save_peer_setting").html("Save")
} }
});
$(".peer_private_key_textbox_switch").on("click",function (){
}) let $peer_private_key_textbox = $("#peer_private_key_textbox");
let mode = (($peer_private_key_textbox.attr('type') === 'password') ? "text":"password");
$(".peer_private_key_textbox_switch").click(function (){ let icon = (($peer_private_key_textbox.attr('type') === 'password') ? "bi bi-eye-slash-fill":"bi bi-eye-fill");
let mode = (($("#peer_private_key_textbox").attr('type') === 'password') ? "text":"password") $peer_private_key_textbox.attr('type',mode);
let icon = (($("#peer_private_key_textbox").attr('type') === 'password') ? "bi bi-eye-slash-fill":"bi bi-eye-fill") $(".peer_private_key_textbox_switch i").removeClass().addClass(icon);
$("#peer_private_key_textbox").attr('type',mode) });
$(".peer_private_key_textbox_switch i").removeClass().addClass(icon)
})
// Search Peer // Search Peer
var typingTimer; let typingTimer;
var doneTypingInterval = 200; let doneTypingInterval = 200;
var $input = $('#search_peer_textbox'); let $input = $('#search_peer_textbox');
$input.on('keyup', function () { $input.on('keyup', function () {
clearTimeout(typingTimer); clearTimeout(typingTimer);
typingTimer = setTimeout(doneTyping, doneTypingInterval); typingTimer = setTimeout(doneTyping, doneTypingInterval);
@ -338,9 +332,10 @@ $input.on('keydown', function () {
clearTimeout(typingTimer); clearTimeout(typingTimer);
}); });
function doneTyping () { function doneTyping () {
load_data($('#search_peer_textbox').val()); load_data($input.val());
} }
// Sorting // Sorting
$body.on("change", "#sort_by_dropdown", function (){ $body.on("change", "#sort_by_dropdown", function (){
$.ajax({ $.ajax({
@ -349,33 +344,38 @@ $body.on("change", "#sort_by_dropdown", function (){
headers:{"Content-Type": "application/json"}, headers:{"Content-Type": "application/json"},
url: "/update_dashboard_sort", url: "/update_dashboard_sort",
success: function (res){ success: function (res){
load_data($('#search_peer_textbox').val()) load_data($('#search_peer_textbox').val());
} }
}) });
}) });
// Click key to copy // Click key to copy animation
$body.on("mouseenter", ".key", function(){ $body.on("mouseenter", ".key", function(){
var label = $(this).parent().siblings().children()[1] let label = $(this).parent().siblings().children()[1];
label.style.opacity = "100" label.style.opacity = "100";
}) })
$body.on("mouseout", ".key", function(){ $body.on("mouseout", ".key", function(){
var label = $(this).parent().siblings().children()[1] let label = $(this).parent().siblings().children()[1];
label.style.opacity = "0" label.style.opacity = "0";
setTimeout(function (){ setTimeout(function (){
label.innerHTML = "CLICK TO COPY" label.innerHTML = "CLICK TO COPY";
},200) },200);
}); });
$body.on("click", ".key", function(){ $body.on("click", ".key", function(){
var label = $(this).parent().siblings().children()[1] var label = $(this).parent().siblings().children()[1];
copyToClipboard($(this)) copyToClipboard($(this));
label.innerHTML = "COPIED!" label.innerHTML = "COPIED!";
}) });
/**
* CopyToClipboard
* @param element
*/
function copyToClipboard(element) { function copyToClipboard(element) {
var $temp = $("<input>"); let $temp = $("<input>");
$body.append($temp); $body.append($temp);
$temp.val($(element).text()).select(); $temp.val($(element).text()).trigger( "select" );
document.execCommand("copy"); document.execCommand("copy");
$temp.remove(); $temp.remove();
} }
@ -384,7 +384,7 @@ function copyToClipboard(element) {
$body.on("click", ".update_interval", function(){ $body.on("click", ".update_interval", function(){
let prev = $(".interval-btn-group.active button"); let prev = $(".interval-btn-group.active button");
$(".interval-btn-group button").removeClass("active"); $(".interval-btn-group button").removeClass("active");
let _new = $(this) let _new = $(this);
_new.addClass("active"); _new.addClass("active");
let interval = $(this).data("refresh-interval"); let interval = $(this).data("refresh-interval");
$.ajax({ $.ajax({
@ -407,12 +407,13 @@ $body.on("click", ".update_interval", function(){
} }
}) })
}); });
// Refresh Button
$body.on("click", ".refresh", function (){ $body.on("click", ".refresh", function (){
load_data($('#search_peer_textbox').val()); load_data($('#search_peer_textbox').val());
}); });
// Switch display mode // Switch display mode
$body.on("click", ".display_mode", function(){ $body.on("click", ".display_mode", function(){
$(".display-btn-group button").removeClass("active"); $(".display-btn-group button").removeClass("active");
@ -426,7 +427,7 @@ $body.on("click", ".display_mode", function(){
if (display_mode === "list"){ if (display_mode === "list"){
Array($(".peer_list").children()).forEach(function(child){ Array($(".peer_list").children()).forEach(function(child){
$(child).removeClass().addClass("col-12"); $(child).removeClass().addClass("col-12");
}) });
showToast("Displaying as List"); showToast("Displaying as List");
}else{ }else{
Array($(".peer_list").children()).forEach(function(child){ Array($(".peer_list").children()).forEach(function(child){
@ -436,11 +437,5 @@ $body.on("click", ".display_mode", function(){
} }
} }
} }
}) });
}) });
// Pre-share key
// $("#enable_preshare_key").on("change", function(){
// $(".preshare_key_container").css("display", $(".preshare_key_container").css("display") === "none" ? "block":"none");
//
// })