Skip to content

Commit

Permalink
Added Partial Time Off
Browse files Browse the repository at this point in the history
  • Loading branch information
Emmennater committed May 14, 2024
1 parent 42331d9 commit 6488727
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<ul>
<li>Click a day once to take time off.</li>
<li>Click again to go back.</li>
<li>Right Click to specify time off.</li>
</ul>

<h2>Settings</h2>
Expand Down
15 changes: 14 additions & 1 deletion src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,23 @@ function dayClicked(e, day, i) {

if (button == "left") {
Settings.setMinPTOWarning(false);
dayObject.toggleSub();
if (dayObject.data.time) {
dayObject.data.time = 0;
} else {
dayObject.toggleSub();
}
updatePTO();
}

if (button == "right") {
let subTime = parseFloat(prompt("Enter time off:"));
if (!isNaN(subTime)) {
dayObject.data.sub = false;
dayObject.setTime(-subTime);
updatePTO();
}
}

saveChanges();
}

Expand Down
7 changes: 6 additions & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,18 @@ class Day {
let mode = "none";
if (this.data.sub) mode = "sub";
else if (this.data.add) mode = "add";
else if (this.data.time < 0) mode = "sub";
return mode;
}

setTimeOff(time) {
this.data.timeOff = time;
}

setTime(time) {
this.data.time = time;
}

toggleSub() {
this.data.sub = !this.data.sub;
}
Expand All @@ -234,7 +239,7 @@ class Day {
if (this.isStartingDay()) return Settings.start;
let time = this.data.time;
if (this.data.add) time += Settings.getSetting("add");
if (this.data.sub) time -= Settings.getSetting("sub");
if (this.data.sub) time -= this.data.subTime || Settings.getSetting("sub");
return time;
}

Expand Down

0 comments on commit 6488727

Please sign in to comment.