Last active
January 4, 2024 12:45
-
-
Save gander/943e39c606b0e568adf0d1432b497dec to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Redmine: Safe Time Entry | |
// @include https://*/issues/* | |
// @include https://*/time_entries/* | |
// ==/UserScript== | |
jQuery(document).on( | |
"input change click focus blur", | |
"#time_entry_hours", | |
function () { | |
const $this = jQuery(this); | |
const color = (function (match) { | |
if (match === null) return ""; | |
switch (parseInt(match[1] ?? match[2]) % 3) { | |
case 0: | |
return "#1e90ff"; | |
case 1: | |
return "#008000"; | |
case 2: | |
return "#ff0000"; | |
} | |
})(/\d+[:h](\d+)|(\d+)m/.exec($this.val())); | |
$this.css({ "border-color": color, color }); | |
} | |
); | |
setTimeout(() => jQuery("#time_entry_hours").trigger('click'), 100); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
W Redmine czas na raporcie jest zapisany w postaci ułamkowej, gdzie część całkowita to godziny, a ułamkowe to pozostałe minuty. Problemem jest zaś to, że ułamki te są zaokrąglone do dwóch miejsc po przecinku, co oznacza, że dla pewnych wartości następuje utrata lub dodanie wartości. Dla przykładu, 10 minut zyskuje w ten sposób 20 sekund, natomiast 5 minut traci 20 sekund. Napisałem więc ten skrypt, który koloruje pole dodawania czasu pracy, i oznacza na czerwono stratę, na zielono zysk, a na niebiesko wartość bez zmian. Obsługuje formaty
30m
,30min
,1h30
,1h30m
,1:30
.