Skip to content

Commit

Permalink
fix multi user, update screenshot
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjones-plip committed Feb 18, 2023
1 parent 3cf8777 commit e90f1b1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 33 deletions.
62 changes: 29 additions & 33 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,12 @@
<script src="{{ url_for('static', filename='jquery-3.6.3.min.js') }}"></script>
<script>
$.getJSON( "/config", function( data ) {
let times, rand_dom;
$.each( data, function( computer, user ) {
rand_dom = '_' + uuidv4();
times = get_times(rand_dom);
let rand_dom = '_' + uuidv4();
let times = get_times(rand_dom);
// todo - click doesn't work and radio spans accross users'
$("#people").append(
"<span class='user' id='" + user + "'>" +
"<span class='user' id='" + user + rand_dom + "'>" +
"<p class='h3'>" + user + "<span class='notify loading'></span></p>" +
"<span class='time_wrapper'>" +
"Unused: <span class='time time_left'>...</span> " +
Expand All @@ -156,15 +155,15 @@
"</span>"
);

$('#' + user + " .notify").show().html("Loading...");
$('#' + user + ' .btn').addClass("disabled");
$('#' + user + ' .btn-check').addClass("disabled");
$('#' + user + rand_dom + " .notify").show().html("Loading...");
$('#' + user + rand_dom + ' .btn').addClass("disabled");
$('#' + user + rand_dom + ' .btn-check').addClass("disabled");

setInterval(function () {
$('#' + user + " .loading").fadeIn(1300).fadeOut(1300);
$('#' + user + rand_dom + " .loading").fadeIn(1300).fadeOut(1300);
}, 1400);
$.getJSON( "/get_usage/" + computer + "/" + user, function( usage ) {
render_user_to_dom(user, computer, usage);
render_user_to_dom(user, computer, usage, rand_dom);
});
});
});
Expand All @@ -185,19 +184,17 @@
});
}

function add_click_handler(){
$(".save_me" ).click(function() {
console.log('test');
const user = $( this ).attr('user');
function add_click_handler(user, rand_dom){
$("#" + user + rand_dom + " .save_me" ).click(function() {
const computer = $( this ).attr('computer');
const action = $( '#' + user + ' input[name="action"]:checked').val();
const seconds = $( '#' + user + ' input[name="seconds"]:checked').val();
const action = $( '#' + user + rand_dom + ' input[name="action"]:checked').val();
const seconds = $( '#' + user + rand_dom + ' input[name="seconds"]:checked').val();
if(action !== undefined && seconds !== undefined){
$('input').prop('checked', false);
add_or_remove_time(user, computer, action, seconds);
$( '#' + user + ' .notify').html('Updated!').fadeIn(function() {
add_or_remove_time(user, computer, action, seconds, rand_dom);
$( '#' + user + rand_dom + ' .notify').html('Updated!').fadeIn(function() {
setTimeout(function() {
$('#' + user + ' .notify').fadeOut("slow");
$('#' + user + rand_dom + ' .notify').fadeOut("slow");
}, 1000);
});
} else {
Expand All @@ -206,40 +203,39 @@
});
}

function render_user_to_dom(user, computer, usage){
function render_user_to_dom(user, computer, usage, rand_dom){
if(usage.result === 'success') {
$( '#' + user + ' .notify').fadeOut().html('Loaded!').fadeIn(function() {
$( '#' + user + rand_dom + ' .notify').fadeOut().html('Loaded!').fadeIn(function() {
setTimeout(function() {
$('#' + user + ' .notify').fadeOut("slow");
$('#' + user + rand_dom + ' .notify').fadeOut("slow");
}, 1000);
});
$('#' + user + " .time_left").html(secondsToHms(usage.time_left));
$('#' + user + " .time_spent").html(secondsToHms(usage.time_spent));
$('#' + user + " .loading").removeClass('loading');
$('#' + user + ' .btn').removeClass("disabled");
$('#' + user + ' .btn-check').removeClass("disabled");
add_click_handler();
$('#' + user + rand_dom + " .time_left").html(secondsToHms(usage.time_left));
$('#' + user + rand_dom + " .time_spent").html(secondsToHms(usage.time_spent));
$('#' + user + rand_dom + " .loading").removeClass('loading');
$('#' + user + rand_dom + ' .btn').removeClass("disabled");
$('#' + user + rand_dom + ' .btn-check').removeClass("disabled");
add_click_handler(user, rand_dom);
} else {
$('#' + user + " .time_wrapper").html("Connection to " + computer + " failed. Off? Conf.py wrong? Bad Auth?");
$('#' + user + " .notify").addClass("error").html("Error");
$('#' + user + rand_dom + " .time_wrapper").html(computer + " failed. Off? Bad Auth?");
$('#' + user + rand_dom + " .notify").addClass("error").html("Error");
}
}

function get_buttons(user, computer, state = 'enabled'){

}

function add_or_remove_time(user, computer, action, seconds){
function add_or_remove_time(user, computer, action, seconds, rand_dom){
let form;
if(action === 'add'){
form = 'increase_time'
} else {
form = 'decrease_time'
}
console.log("add_or_remove_time callded: form", form,"computer", computer,"user",user,"seconds",seconds);
$.getJSON("/" + form + "/" + computer + "/" + user + "/" + seconds, function( data ) {
$('#' + user + " .time_left").html(secondsToHms(data.time_left));
$('#' + user + " .time_spent").html(secondsToHms(data.time_spent));
$('#' + user + rand_dom + " .time_left").html(secondsToHms(data.time_left));
$('#' + user + rand_dom + " .time_spent").html(secondsToHms(data.time_spent));
});
}

Expand Down
Binary file modified timekpr-next-remote.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e90f1b1

Please sign in to comment.