Prise en compte du capital négatif corrigée
This commit is contained in:
parent
a9fcac9551
commit
b4c1ed8980
@ -16,8 +16,6 @@ const Me = imports.misc.extensionUtils.getCurrentExtension();
|
||||
|
||||
const version = Gtk.get_major_version();
|
||||
|
||||
log(`GTK version is ${version}`);
|
||||
|
||||
let myPopup;
|
||||
let started = false;
|
||||
let key = get_config('key');
|
||||
@ -97,10 +95,17 @@ class MyPopup extends PanelMenu.Button {
|
||||
let workedHours = Math.floor(workedToday / 60);
|
||||
let workedMinutes = workedToday % 60;
|
||||
|
||||
let capitalToMinutes = result.capitaltime.replace('+', '').split(':');
|
||||
let positiveCapital = result.capitaltime.includes('+');
|
||||
|
||||
let capitalToMinutes = result.capitaltime.replace('-', '').replace('+', '').split(':');
|
||||
capitalToMinutes = parseInt(capitalToMinutes[0]) * 60 + parseInt(capitalToMinutes[1]);
|
||||
|
||||
let workedTodayPlusCapital = workedToday + capitalToMinutes
|
||||
if(positiveCapital) {
|
||||
var workedTodayPlusCapital = workedToday + capitalToMinutes
|
||||
} else {
|
||||
var workedTodayPlusCapital = workedToday - capitalToMinutes
|
||||
}
|
||||
|
||||
let diff = 7*60 - workedTodayPlusCapital
|
||||
let diffHours = Math.floor(diff / 60);
|
||||
let diffMinutes = diff % 60;
|
||||
@ -121,16 +126,19 @@ class MyPopup extends PanelMenu.Button {
|
||||
|
||||
|
||||
startItem.connect('activate', () => {
|
||||
if(started){
|
||||
send_request('https://badge.cadoles.com/ninebadge/rest/clockout', 'POST', key)
|
||||
started = false
|
||||
label.set_text('DÉBUT POINTAGE');
|
||||
} else {
|
||||
send_request('https://badge.cadoles.com/ninebadge/rest/clockin', 'POST', key)
|
||||
label.set_text('FIN POINTAGE');
|
||||
started = true
|
||||
try {
|
||||
if(started){
|
||||
send_request('https://badge.cadoles.com/ninebadge/rest/clockout', 'POST', key)
|
||||
started = false
|
||||
label.set_text('DÉBUT POINTAGE');
|
||||
} else {
|
||||
send_request('https://badge.cadoles.com/ninebadge/rest/clockin', 'POST', key)
|
||||
label.set_text('FIN POINTAGE');
|
||||
started = true
|
||||
}
|
||||
} catch(error) {
|
||||
log(error);
|
||||
}
|
||||
log(started);
|
||||
});
|
||||
|
||||
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
|
||||
@ -144,10 +152,14 @@ class MyPopup extends PanelMenu.Button {
|
||||
this.menu.addMenuItem(validateItem);
|
||||
|
||||
validateItem.connect('activate', () => {
|
||||
send_request('https://badge.cadoles.com/ninebadge/rest/clockout', 'POST', key)
|
||||
started = false
|
||||
label.set_text('DÉBUT POINTAGE');
|
||||
send_request('https://badge.cadoles.com/ninebadge/rest/validate', 'POST', key)
|
||||
try {
|
||||
send_request('https://badge.cadoles.com/ninebadge/rest/clockout', 'POST', key)
|
||||
started = false
|
||||
label.set_text('DÉBUT POINTAGE');
|
||||
send_request('https://badge.cadoles.com/ninebadge/rest/validate', 'POST', key)
|
||||
} catch(error) {
|
||||
log(error);
|
||||
}
|
||||
});
|
||||
|
||||
// you can close, open and toggle the menu with
|
||||
@ -158,7 +170,7 @@ class MyPopup extends PanelMenu.Button {
|
||||
});
|
||||
|
||||
function send_request(url, type='POST', key) {
|
||||
let [ok, out, err, exit] = GLib.spawn_command_line_sync(`/usr/bin/curl --insecure -X ${type} -d '{"key": "${key}"}' -H "Content-Type: application/json" ${url} -o /tmp/test.json`);
|
||||
let [ok, out, err, exit] = GLib.spawn_command_line_sync(`/usr/bin/curl --insecure --max-time 2 -X ${type} -d '{"key": "${key}"}' -H "Content-Type: application/json" ${url} -o /tmp/test.json`);
|
||||
let text = GLib.file_get_contents('/tmp/test.json')[1];
|
||||
let json_result = JSON.parse(text);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user