From 2c34f8a789033417be5c7637401ecd12236ac309 Mon Sep 17 00:00:00 2001
From: Rameen260 <98580766+Rameen260@users.noreply.github.com>
Date: Wed, 4 Dec 2024 01:19:39 -0500
Subject: [PATCH 1/4] The individual days are showing in preferences, there is
still some backend code that is using the old getHoursPerDay function
---
js/time-balance.js | 26 ++++++++++++---
js/user-preferences.js | 27 +++++++++++++--
src/preferences.html | 6 ++++
src/preferences.js | 76 ++++++++++++++++++++++++++++++++++++++++++
4 files changed, 128 insertions(+), 7 deletions(-)
diff --git a/js/time-balance.js b/js/time-balance.js
index 7c30164b6..33cc60c2f 100644
--- a/js/time-balance.js
+++ b/js/time-balance.js
@@ -64,12 +64,26 @@ function _getOverallBalanceStartDate()
return savedPreferences['overall-balance-start-date'];
}
-function _getHoursPerDay()
+// function _getHoursPerDay()
+// {
+// const savedPreferences = getUserPreferences();
+// return savedPreferences['hours-per-day'];
+// }
+
+function _getHoursForDay(dayIndex)
{
const savedPreferences = getUserPreferences();
- return savedPreferences['hours-per-day'];
+ const days = [
+ 'sunday',
+ 'monday',
+ 'tuesday',
+ 'wednesday',
+ 'thursday',
+ 'friday',
+ 'saturday'
+ ];
+ return savedPreferences[`hours-${days[dayIndex]}`] || '08:00';
}
-
/**
* Given an array of times from a day in the flexible calendar, returns the
* day total according to same calculation rules as those of the calendar.
@@ -170,7 +184,7 @@ async function computeAllTimeBalanceUntil(limitDate)
const totals = _getDayTotalsFromStores(firstDate, limitDate);
const preferences = getUserPreferences();
- const hoursPerDay = _getHoursPerDay();
+ // const hoursPerDay = _getHoursPerDay();
let allTimeTotal = '00:00';
const date = new Date(firstDate);
const limitDateStr = getDateStr(limitDate);
@@ -179,8 +193,10 @@ async function computeAllTimeBalanceUntil(limitDate)
{
if (showDay(date.getFullYear(), date.getMonth(), date.getDate(), preferences))
{
+ const dayIndex = date.getDay();
+ const dayHours = _getHoursForDay(dayIndex);
const dayTotal = dateStr in totals ? totals[dateStr] : '00:00';
- const dayBalance = subtractTime(hoursPerDay, dayTotal);
+ const dayBalance = subtractTime(dayHours, dayTotal);
allTimeTotal = sumTime(dayBalance, allTimeTotal);
}
date.setDate(date.getDate() + 1);
diff --git a/js/user-preferences.js b/js/user-preferences.js
index 6d6b4464c..4ee7cec52 100644
--- a/js/user-preferences.js
+++ b/js/user-preferences.js
@@ -32,7 +32,14 @@ const defaultPreferences = {
'close-to-tray': true,
'minimize-to-tray': true,
'hide-non-working-days': false,
- 'hours-per-day': '08:00',
+ 'hours-sunday': '08:00',
+ 'hours-monday': '08:00',
+ 'hours-tuesday': '08:00',
+ 'hours-wednesday': '08:00',
+ 'hours-thursday': '08:00',
+ 'hours-friday': '08:00',
+ 'hours-saturday': '08:00',
+ 'hours-per-day': '08:00', //probably need to remove
'enable-prefill-break-time': false,
'break-time-interval': '00:30',
'notification': true,
@@ -76,6 +83,13 @@ const timeInputs = [
'notifications-interval',
'hours-per-day',
'break-time-interval',
+ 'hours-sunday',
+ 'hours-monday',
+ 'hours-tuesday',
+ 'hours-wednesday',
+ 'hours-thursday',
+ 'hours-friday',
+ 'hours-saturday',
];
const isNotBoolean = (val) => typeof val !== 'boolean';
@@ -111,7 +125,9 @@ function savePreferences(preferencesOptions, filePath = getPreferencesFilePath()
{
try
{
- getFs().writeFileSync(filePath, JSON.stringify(preferencesOptions));
+ const preferencesToSave = { ...defaultPreferences, ...preferencesOptions };
+ getFs().writeFileSync(filePath, JSON.stringify(preferencesToSave));
+
}
catch (err)
{
@@ -190,6 +206,13 @@ function initPreferencesFileIfNotExistsOrInvalid(filePath = getPreferencesFilePa
'notifications-interval' : () => isNotificationInterval(value),
'hours-per-day' : () => validateTime(value),
'break-time-interval' : () => validateTime(value),
+ 'hours-sunday': () => validateTime(value),
+ 'hours-monday': () => validateTime(value),
+ 'hours-tuesday': () => validateTime(value),
+ 'hours-wednesday': () => validateTime(value),
+ 'hours-thursday': () => validateTime(value),
+ 'hours-friday': () => validateTime(value),
+ 'hours-saturday': () => validateTime(value),
};
if (!timeValidationEnum[key]())
{
diff --git a/src/preferences.html b/src/preferences.html
index d5f663f09..b48ad8370 100644
--- a/src/preferences.html
+++ b/src/preferences.html
@@ -44,6 +44,12 @@
Enable prefilling of break time
diff --git a/src/preferences.js b/src/preferences.js
index 7aeb1a276..f04cb9c33 100644
--- a/src/preferences.js
+++ b/src/preferences.js
@@ -65,7 +65,13 @@ function refreshContent()
function changeValue(type, newVal)
{
+ //preferences[type] = "03:00 07:00 04:00 02:00 03:00 03:00 05:00";
preferences[type] = newVal;
+ //preferences["hours-per-day"] = "03:00 07:00 04:00 02:00 03:00 03:00 05:00";
+ //console.log("HELP friday "+ preferences["hours-friday"]);
+ //console.log("HELP2 "+ preferences["hours-per-day"]);
+ console.log('HELP2 '+ preferences[type]);
+
window.mainApi.notifyNewPreferences(preferences);
}
@@ -182,6 +188,76 @@ function renderPreferencesWindow()
{
notificationsInterval.prop('disabled', !repetition.is(':checked'));
});
+
+ const days = [
+ { id: 'sunday', label: 'Sunday' },
+ { id: 'monday', label: 'Monday' },
+ { id: 'tuesday', label: 'Tuesday' },
+ { id: 'wednesday', label: 'Wednesday' },
+ { id: 'thursday', label: 'Thursday' },
+ { id: 'friday', label: 'Friday' },
+ { id: 'saturday', label: 'Saturday' },
+ ];
+
+ const hoursContainer = $('#hours-container');
+
+ function updateHoursInputs()
+ {
+ hoursContainer.empty(); // Clear previous inputs
+
+ days.forEach(day =>
+ {
+ const isChecked = $(`#${day.id}`).is(':checked');
+ if (isChecked)
+ {
+ const inputId = `hours-${day.id}`;
+ const storedValue = usersStyles[inputId] || '08:00'; // Default or saved value
+
+ const inputHTML = `
+
+
+
+
+ `;
+ hoursContainer.append(inputHTML);
+
+ $(`#${inputId}`).on('change', function()
+ {
+ if (this.checkValidity())
+ {
+ changeValue(inputId, this.value);
+ }
+ });
+ }
+ });
+ }
+
+ days.forEach(day =>
+ {
+ const checkbox = $(`#${day.id}`);
+ if (checkbox)
+ {
+ checkbox.prop('checked', usersStyles[`working-days-${day.id}`] || false);
+
+ checkbox.on('change', function()
+ {
+ changeValue(`working-days-${day.id}`, this.checked);
+ updateHoursInputs();
+ });
+ }
+ });
+
+ updateHoursInputs();
+
}
/* istanbul ignore next */
$(() =>
From 81f4956e28e8d771dfefc078d0615104dae1b114 Mon Sep 17 00:00:00 2001
From: Rameen260 <98580766+Rameen260@users.noreply.github.com>
Date: Wed, 4 Dec 2024 02:28:45 -0500
Subject: [PATCH 2/4] Balance should be working
---
renderer/classes/BaseCalendar.js | 19 ++++++-
renderer/classes/FlexibleDayCalendar.js | 50 +++++++++++------
renderer/classes/FlexibleMonthCalendar.js | 66 ++++++++++++++---------
3 files changed, 94 insertions(+), 41 deletions(-)
diff --git a/renderer/classes/BaseCalendar.js b/renderer/classes/BaseCalendar.js
index 1c1ed0d67..12c29abbd 100644
--- a/renderer/classes/BaseCalendar.js
+++ b/renderer/classes/BaseCalendar.js
@@ -336,6 +336,19 @@ class BaseCalendar
return this._preferences['hours-per-day'];
}
+ _getHoursForDay(dayIndex) {
+ const days = [
+ 'sunday',
+ 'monday',
+ 'tuesday',
+ 'wednesday',
+ 'thursday',
+ 'friday',
+ 'saturday'
+ ];
+ return this._preferences[`hours-${days[dayIndex]}`] || '08:00';
+ }
+
/**
* Returns if "hide non-working days" was set in preferences.
* @return {Boolean}
@@ -659,8 +672,10 @@ class BaseCalendar
}
if (timesAreProgressing)
{
- const lastTime = validatedTimes[validatedTimes.length-1];
- const remainingTime = subtractTime(dayTotal, this._getHoursPerDay());
+ const lastTime = validatedTimes[validatedTimes.length - 1];
+ const dayIndex = new Date(this._getTodayYear(), this._getTodayMonth(), this._getTodayDate()).getDay();
+ const dayHours = this._getHoursForDay(dayIndex);
+ const remainingTime = subtractTime(dayTotal, dayHours);
leaveBy = sumTime(lastTime, remainingTime);
}
}
diff --git a/renderer/classes/FlexibleDayCalendar.js b/renderer/classes/FlexibleDayCalendar.js
index 6baa64e2c..cc8ce07f3 100644
--- a/renderer/classes/FlexibleDayCalendar.js
+++ b/renderer/classes/FlexibleDayCalendar.js
@@ -49,6 +49,25 @@ class FlexibleDayCalendar extends BaseCalendar
$('#calendar').html(body);
$('html').attr('data-view', 'flexible-day');
}
+ /**
+ * Returns the working hours for the specified day of the week.
+ */
+ _getHoursForDay(dayIndex)
+ {
+ const dayKeys = [
+ 'hours-sunday',
+ 'hours-monday',
+ 'hours-tuesday',
+ 'hours-wednesday',
+ 'hours-thursday',
+ 'hours-friday',
+ 'hours-saturday'
+ ];
+ if (dayIndex < 0 || dayIndex > 6) {
+ throw new Error('Invalid dayIndex provided to _getHoursForDay.');
+ }
+ return this._preferences[dayKeys[dayIndex]] || '08:00';
+ }
/**
* Returns the header of the page, with the image, name and a message.
@@ -390,33 +409,32 @@ class FlexibleDayCalendar extends BaseCalendar
let countDays = false;
const limit = this._getCountToday() ? this._getCalendarDate() : (yesterday.getMonth() !== this._getCalendarMonth() ? 0 : yesterday.getDate());
- for (let day = 1; day <= limit; ++day)
- {
- if (!this._showDay(this._getCalendarYear(), this._getCalendarMonth(), day))
- {
+ for (let day = 1; day <= limit; ++day) {
+ if (!this._showDay(this._getCalendarYear(), this._getCalendarMonth(), day)) {
continue;
}
-
const dayTotal = this._getDayTotal(this._getCalendarYear(), this._getCalendarMonth(), day);
- if (dayTotal !== undefined)
- {
+ if (dayTotal !== undefined) {
countDays = true;
- monthTotalWorked = sumTime(monthTotalWorked, dayTotal);
+
+ const dayIndex = new Date(this._getCalendarYear(), this._getCalendarMonth(), day).getDay(); // Get current day
+ const hoursForDay = this._getHoursForDay(dayIndex);
+ const dayBalance = subtractTime(hoursForDay, dayTotal);
+ monthTotalWorked = sumTime(monthTotalWorked, dayBalance);
}
- if (countDays)
- {
+ if (countDays) {
workingDaysToCompute += 1;
}
}
- const monthTotalToWork = multiplyTime(this._getHoursPerDay(), workingDaysToCompute * -1);
- const balance = sumTime(monthTotalToWork, monthTotalWorked);
+
+ const balance = monthTotalWorked;
const balanceElement = $('#month-balance');
- if (balanceElement)
- {
+ if (balanceElement) {
balanceElement.html(balance);
balanceElement.removeClass('text-success text-danger');
balanceElement.addClass(isNegative(balance) ? 'text-danger' : 'text-success');
}
+
}
/**
@@ -438,7 +456,9 @@ class FlexibleDayCalendar extends BaseCalendar
const dayTotal = $('.day-total span').html();
if (dayTotal !== undefined && dayTotal.length > 0)
{
- const dayBalance = subtractTime(this._getHoursPerDay(), dayTotal);
+ const dayIndex = new Date(this._getTodayYear(), this._getTodayMonth(), this._getTodayDate()).getDay();
+ const dayHours = this._getHoursForDay(dayIndex);
+ const dayBalance = subtractTime(dayHours, dayTotal);
$('#leave-day-balance').val(dayBalance);
$('#leave-day-balance').removeClass('text-success text-danger');
$('#leave-day-balance').addClass(isNegative(dayBalance) ? 'text-danger' : 'text-success');
diff --git a/renderer/classes/FlexibleMonthCalendar.js b/renderer/classes/FlexibleMonthCalendar.js
index 4bb413de1..d093e02f0 100644
--- a/renderer/classes/FlexibleMonthCalendar.js
+++ b/renderer/classes/FlexibleMonthCalendar.js
@@ -60,7 +60,20 @@ class FlexibleMonthCalendar extends BaseCalendar
}
return targetDate;
}
-
+ /* Returns the working hours for the specified day of the week. */
+ _getHoursForDay(dayIndex)
+ {
+ const dayKeys = [
+ 'hours-sunday',
+ 'hours-monday',
+ 'hours-tuesday',
+ 'hours-wednesday',
+ 'hours-thursday',
+ 'hours-friday',
+ 'hours-saturday'
+ ];
+ return this._preferences[dayKeys[dayIndex]] || '08:00'; // Default to '08:00' if no preference is set
+ }
/*
* Generates the calendar HTML view.
*/
@@ -499,52 +512,56 @@ class FlexibleMonthCalendar extends BaseCalendar
/*
* Updates the monthly time balance.
*/
- _updateBalance()
- {
+ _updateBalance() {
const now = new Date();
const monthLength = getMonthLength(this._getCalendarYear(), this._getCalendarMonth());
- let workingDaysToCompute = 0;
+ let workingDaysToCompute = [];
let monthTotalWorked = '00:00';
let countDays = false;
let isNextDay = false;
-
- for (let day = 1; day <= monthLength; ++day)
- {
- const isToday = (now.getDate() === day && now.getMonth() === this._getCalendarMonth() && now.getFullYear() === this._getCalendarYear());
+
+ for (let day = 1; day <= monthLength; ++day) {
+ const isToday = now.getDate() === day &&
+ now.getMonth() === this._getCalendarMonth() &&
+ now.getFullYear() === this._getCalendarYear();
+
// balance should consider preferences and count or not today
- if (isToday && !this._getCountToday() || isNextDay && this._getCountToday())
- {
+ if (isToday && !this._getCountToday() || isNextDay && this._getCountToday()) {
break;
}
isNextDay = isToday;
-
- if (!this._showDay(this._getCalendarYear(), this._getCalendarMonth(), day))
- {
+
+ if (!this._showDay(this._getCalendarYear(), this._getCalendarMonth(), day)) {
continue;
}
-
+
const dayTotal = this._getDayTotal(this._getCalendarYear(), this._getCalendarMonth(), day);
- if (dayTotal !== undefined && dayTotal.length !== 0)
- {
+ if (dayTotal) {
countDays = true;
monthTotalWorked = sumTime(monthTotalWorked, dayTotal);
- }
- if (countDays)
- {
- workingDaysToCompute += 1;
+
+ const dayIndex = new Date(this._getCalendarYear(), this._getCalendarMonth(), day).getDay();
+ workingDaysToCompute.push(dayIndex);
}
}
- const monthTotalToWork = multiplyTime(this._getHoursPerDay(), workingDaysToCompute * -1);
+
+ const monthTotalToWork = workingDaysToCompute.reduce((total, dayIndex) => {
+ return sumTime(total, multiplyTime(this._getHoursForDay(dayIndex), -1));
+ }, '00:00');
+
const balance = sumTime(monthTotalToWork, monthTotalWorked);
+
+
const balanceElement = $('#month-balance');
- if (balanceElement)
- {
+ if (balanceElement) {
balanceElement.val(balance);
balanceElement.removeClass('text-success text-danger');
balanceElement.addClass(isNegative(balance) ? 'text-danger' : 'text-success');
}
this._updateAllTimeBalance();
}
+
+
/*
* Updates data displayed based on the database.
@@ -630,7 +647,8 @@ class FlexibleMonthCalendar extends BaseCalendar
const dayTotal = $('#' + dateKey).parent().find(' .day-total span').html();
if (dayTotal !== undefined && dayTotal.length > 0)
{
- const dayBalance = subtractTime(this._getHoursPerDay(), dayTotal);
+ const dayIndex = new Date(this._getTodayYear(), this._getTodayMonth(), this._getTodayDate()).getDay();
+ const dayBalance = subtractTime(this._getHoursForDay(dayIndex), dayTotal);
$('#leave-day-balance').html(dayBalance);
$('#leave-day-balance').removeClass('text-success text-danger');
$('#leave-day-balance').addClass(isNegative(dayBalance) ? 'text-danger' : 'text-success');
From 3a3bc4864f4115fae36b1f8a80ec8d53b3ef53c8 Mon Sep 17 00:00:00 2001
From: Rameen260 <98580766+Rameen260@users.noreply.github.com>
Date: Wed, 4 Dec 2024 03:55:21 -0500
Subject: [PATCH 3/4] basecalender failing tests
---
renderer/classes/BaseCalendar.js | 5 +-
renderer/classes/FlexibleDayCalendar.js | 42 ++++++++---------
renderer/classes/FlexibleMonthCalendar.js | 45 ++++++++++--------
src/preferences.html | 18 +++-----
src/preferences.js | 56 ++++++++++++-----------
5 files changed, 85 insertions(+), 81 deletions(-)
diff --git a/renderer/classes/BaseCalendar.js b/renderer/classes/BaseCalendar.js
index 12c29abbd..df472ab11 100644
--- a/renderer/classes/BaseCalendar.js
+++ b/renderer/classes/BaseCalendar.js
@@ -336,7 +336,8 @@ class BaseCalendar
return this._preferences['hours-per-day'];
}
- _getHoursForDay(dayIndex) {
+ _getHoursForDay(dayIndex)
+ {
const days = [
'sunday',
'monday',
@@ -346,7 +347,7 @@ class BaseCalendar
'friday',
'saturday'
];
- return this._preferences[`hours-${days[dayIndex]}`] || '08:00';
+ return this._preferences[`hours-${days[dayIndex]}`] || '08:00';
}
/**
diff --git a/renderer/classes/FlexibleDayCalendar.js b/renderer/classes/FlexibleDayCalendar.js
index cc8ce07f3..1f85d905b 100644
--- a/renderer/classes/FlexibleDayCalendar.js
+++ b/renderer/classes/FlexibleDayCalendar.js
@@ -2,7 +2,6 @@
import {
isNegative,
- multiplyTime,
subtractTime,
sumTime,
validateTime
@@ -63,7 +62,8 @@ class FlexibleDayCalendar extends BaseCalendar
'hours-friday',
'hours-saturday'
];
- if (dayIndex < 0 || dayIndex > 6) {
+ if (dayIndex < 0 || dayIndex > 6)
+ {
throw new Error('Invalid dayIndex provided to _getHoursForDay.');
}
return this._preferences[dayKeys[dayIndex]] || '08:00';
@@ -404,37 +404,37 @@ class FlexibleDayCalendar extends BaseCalendar
{
const yesterday = new Date(this._calendarDate);
yesterday.setDate(this._calendarDate.getDate() - 1);
- let workingDaysToCompute = 0,
- monthTotalWorked = '00:00';
- let countDays = false;
+
+ let monthTotalWorked = '00:00';
const limit = this._getCountToday() ? this._getCalendarDate() : (yesterday.getMonth() !== this._getCalendarMonth() ? 0 : yesterday.getDate());
- for (let day = 1; day <= limit; ++day) {
- if (!this._showDay(this._getCalendarYear(), this._getCalendarMonth(), day)) {
+ for (let day = 1; day <= limit; ++day)
+ {
+ if (!this._showDay(this._getCalendarYear(), this._getCalendarMonth(), day))
+ {
continue;
}
const dayTotal = this._getDayTotal(this._getCalendarYear(), this._getCalendarMonth(), day);
- if (dayTotal !== undefined) {
- countDays = true;
-
- const dayIndex = new Date(this._getCalendarYear(), this._getCalendarMonth(), day).getDay(); // Get current day
- const hoursForDay = this._getHoursForDay(dayIndex);
+ if (dayTotal !== undefined)
+ {
+
+ const dayIndex = new Date(this._getCalendarYear(), this._getCalendarMonth(), day).getDay(); // Get current day
+ const hoursForDay = this._getHoursForDay(dayIndex);
const dayBalance = subtractTime(hoursForDay, dayTotal);
- monthTotalWorked = sumTime(monthTotalWorked, dayBalance);
- }
- if (countDays) {
- workingDaysToCompute += 1;
+ monthTotalWorked = sumTime(monthTotalWorked, dayBalance);
}
+
}
-
+
const balance = monthTotalWorked;
const balanceElement = $('#month-balance');
- if (balanceElement) {
+ if (balanceElement)
+ {
balanceElement.html(balance);
balanceElement.removeClass('text-success text-danger');
balanceElement.addClass(isNegative(balance) ? 'text-danger' : 'text-success');
}
-
+
}
/**
@@ -456,8 +456,8 @@ class FlexibleDayCalendar extends BaseCalendar
const dayTotal = $('.day-total span').html();
if (dayTotal !== undefined && dayTotal.length > 0)
{
- const dayIndex = new Date(this._getTodayYear(), this._getTodayMonth(), this._getTodayDate()).getDay();
- const dayHours = this._getHoursForDay(dayIndex);
+ const dayIndex = new Date(this._getTodayYear(), this._getTodayMonth(), this._getTodayDate()).getDay();
+ const dayHours = this._getHoursForDay(dayIndex);
const dayBalance = subtractTime(dayHours, dayTotal);
$('#leave-day-balance').val(dayBalance);
$('#leave-day-balance').removeClass('text-success text-danger');
diff --git a/renderer/classes/FlexibleMonthCalendar.js b/renderer/classes/FlexibleMonthCalendar.js
index d093e02f0..92e377da8 100644
--- a/renderer/classes/FlexibleMonthCalendar.js
+++ b/renderer/classes/FlexibleMonthCalendar.js
@@ -512,56 +512,61 @@ class FlexibleMonthCalendar extends BaseCalendar
/*
* Updates the monthly time balance.
*/
- _updateBalance() {
+ _updateBalance()
+ {
const now = new Date();
const monthLength = getMonthLength(this._getCalendarYear(), this._getCalendarMonth());
- let workingDaysToCompute = [];
+ const workingDaysToCompute = [];
let monthTotalWorked = '00:00';
- let countDays = false;
let isNextDay = false;
-
- for (let day = 1; day <= monthLength; ++day) {
+
+ for (let day = 1; day <= monthLength; ++day)
+ {
const isToday = now.getDate() === day &&
now.getMonth() === this._getCalendarMonth() &&
now.getFullYear() === this._getCalendarYear();
-
- // balance should consider preferences and count or not today
- if (isToday && !this._getCountToday() || isNextDay && this._getCountToday()) {
+
+ // balance should consider preferences and count or notyyyyyyyyyyyyyyyyyyyyyyyy today
+ if (isToday && !this._getCountToday() || isNextDay && this._getCountToday())
+ {
break;
}
isNextDay = isToday;
-
- if (!this._showDay(this._getCalendarYear(), this._getCalendarMonth(), day)) {
+
+ if (!this._showDay(this._getCalendarYear(), this._getCalendarMonth(), day))
+ {
continue;
}
-
+
const dayTotal = this._getDayTotal(this._getCalendarYear(), this._getCalendarMonth(), day);
- if (dayTotal) {
- countDays = true;
+ if (dayTotal)
+ {
monthTotalWorked = sumTime(monthTotalWorked, dayTotal);
const dayIndex = new Date(this._getCalendarYear(), this._getCalendarMonth(), day).getDay();
workingDaysToCompute.push(dayIndex);
}
}
-
- const monthTotalToWork = workingDaysToCompute.reduce((total, dayIndex) => {
+
+ const monthTotalToWork = workingDaysToCompute.reduce((total, dayIndex) =>
+ {
return sumTime(total, multiplyTime(this._getHoursForDay(dayIndex), -1));
}, '00:00');
-
+
const balance = sumTime(monthTotalToWork, monthTotalWorked);
-
+
const balanceElement = $('#month-balance');
- if (balanceElement) {
+ if (balanceElement)
+ {
balanceElement.val(balance);
balanceElement.removeClass('text-success text-danger');
balanceElement.addClass(isNegative(balance) ? 'text-danger' : 'text-success');
}
this._updateAllTimeBalance();
}
-
-
+
+
/*
* Updates data displayed based on the database.
diff --git a/src/preferences.html b/src/preferences.html
index b48ad8370..98ed0840c 100644
--- a/src/preferences.html
+++ b/src/preferences.html
@@ -36,20 +36,16 @@
-
- Set hours for selected days
+
+
+
+
Hide non-working days (Month View)
+
+
Enable prefilling of break time
diff --git a/src/preferences.js b/src/preferences.js
index f04cb9c33..33a344573 100644
--- a/src/preferences.js
+++ b/src/preferences.js
@@ -65,12 +65,9 @@ function refreshContent()
function changeValue(type, newVal)
{
- //preferences[type] = "03:00 07:00 04:00 02:00 03:00 03:00 05:00";
+
preferences[type] = newVal;
- //preferences["hours-per-day"] = "03:00 07:00 04:00 02:00 03:00 03:00 05:00";
- //console.log("HELP friday "+ preferences["hours-friday"]);
- //console.log("HELP2 "+ preferences["hours-per-day"]);
- console.log('HELP2 '+ preferences[type]);
+
window.mainApi.notifyNewPreferences(preferences);
}
@@ -190,20 +187,20 @@ function renderPreferencesWindow()
});
const days = [
- { id: 'sunday', label: 'Sunday' },
- { id: 'monday', label: 'Monday' },
- { id: 'tuesday', label: 'Tuesday' },
- { id: 'wednesday', label: 'Wednesday' },
- { id: 'thursday', label: 'Thursday' },
- { id: 'friday', label: 'Friday' },
- { id: 'saturday', label: 'Saturday' },
+ { id: 'sunday', label: 'sun' },
+ { id: 'monday', label: 'mon' },
+ { id: 'tuesday', label: 'tue' },
+ { id: 'wednesday', label: 'wed' },
+ { id: 'thursday', label: 'thu' },
+ { id: 'friday', label: 'fri' },
+ { id: 'saturday', label: 'sat' },
];
const hoursContainer = $('#hours-container');
function updateHoursInputs()
{
- hoursContainer.empty(); // Clear previous inputs
+ hoursContainer.empty();
days.forEach(day =>
{
@@ -214,20 +211,21 @@ function renderPreferencesWindow()
const storedValue = usersStyles[inputId] || '08:00'; // Default or saved value
const inputHTML = `
-
-
-
-
- `;
+
+ `;
hoursContainer.append(inputHTML);
$(`#${inputId}`).on('change', function()
@@ -239,6 +237,10 @@ function renderPreferencesWindow()
});
}
});
+ window.mainApi.getLanguageDataPromise().then(languageData =>
+ {
+ translatePage(usersStyles.language, languageData.data, 'Preferences');
+ });
}
days.forEach(day =>
From a896c82885151a4bb54b45e6d25c0399761ad7a7 Mon Sep 17 00:00:00 2001
From: Rameen260 <98580766+Rameen260@users.noreply.github.com>
Date: Wed, 4 Dec 2024 03:55:21 -0500
Subject: [PATCH 4/4] Added option to select hours for all days
---
renderer/classes/BaseCalendar.js | 5 +-
renderer/classes/FlexibleDayCalendar.js | 42 ++++++++---------
renderer/classes/FlexibleMonthCalendar.js | 45 ++++++++++--------
src/preferences.html | 18 +++-----
src/preferences.js | 56 ++++++++++++-----------
5 files changed, 85 insertions(+), 81 deletions(-)
diff --git a/renderer/classes/BaseCalendar.js b/renderer/classes/BaseCalendar.js
index 12c29abbd..df472ab11 100644
--- a/renderer/classes/BaseCalendar.js
+++ b/renderer/classes/BaseCalendar.js
@@ -336,7 +336,8 @@ class BaseCalendar
return this._preferences['hours-per-day'];
}
- _getHoursForDay(dayIndex) {
+ _getHoursForDay(dayIndex)
+ {
const days = [
'sunday',
'monday',
@@ -346,7 +347,7 @@ class BaseCalendar
'friday',
'saturday'
];
- return this._preferences[`hours-${days[dayIndex]}`] || '08:00';
+ return this._preferences[`hours-${days[dayIndex]}`] || '08:00';
}
/**
diff --git a/renderer/classes/FlexibleDayCalendar.js b/renderer/classes/FlexibleDayCalendar.js
index cc8ce07f3..1f85d905b 100644
--- a/renderer/classes/FlexibleDayCalendar.js
+++ b/renderer/classes/FlexibleDayCalendar.js
@@ -2,7 +2,6 @@
import {
isNegative,
- multiplyTime,
subtractTime,
sumTime,
validateTime
@@ -63,7 +62,8 @@ class FlexibleDayCalendar extends BaseCalendar
'hours-friday',
'hours-saturday'
];
- if (dayIndex < 0 || dayIndex > 6) {
+ if (dayIndex < 0 || dayIndex > 6)
+ {
throw new Error('Invalid dayIndex provided to _getHoursForDay.');
}
return this._preferences[dayKeys[dayIndex]] || '08:00';
@@ -404,37 +404,37 @@ class FlexibleDayCalendar extends BaseCalendar
{
const yesterday = new Date(this._calendarDate);
yesterday.setDate(this._calendarDate.getDate() - 1);
- let workingDaysToCompute = 0,
- monthTotalWorked = '00:00';
- let countDays = false;
+
+ let monthTotalWorked = '00:00';
const limit = this._getCountToday() ? this._getCalendarDate() : (yesterday.getMonth() !== this._getCalendarMonth() ? 0 : yesterday.getDate());
- for (let day = 1; day <= limit; ++day) {
- if (!this._showDay(this._getCalendarYear(), this._getCalendarMonth(), day)) {
+ for (let day = 1; day <= limit; ++day)
+ {
+ if (!this._showDay(this._getCalendarYear(), this._getCalendarMonth(), day))
+ {
continue;
}
const dayTotal = this._getDayTotal(this._getCalendarYear(), this._getCalendarMonth(), day);
- if (dayTotal !== undefined) {
- countDays = true;
-
- const dayIndex = new Date(this._getCalendarYear(), this._getCalendarMonth(), day).getDay(); // Get current day
- const hoursForDay = this._getHoursForDay(dayIndex);
+ if (dayTotal !== undefined)
+ {
+
+ const dayIndex = new Date(this._getCalendarYear(), this._getCalendarMonth(), day).getDay(); // Get current day
+ const hoursForDay = this._getHoursForDay(dayIndex);
const dayBalance = subtractTime(hoursForDay, dayTotal);
- monthTotalWorked = sumTime(monthTotalWorked, dayBalance);
- }
- if (countDays) {
- workingDaysToCompute += 1;
+ monthTotalWorked = sumTime(monthTotalWorked, dayBalance);
}
+
}
-
+
const balance = monthTotalWorked;
const balanceElement = $('#month-balance');
- if (balanceElement) {
+ if (balanceElement)
+ {
balanceElement.html(balance);
balanceElement.removeClass('text-success text-danger');
balanceElement.addClass(isNegative(balance) ? 'text-danger' : 'text-success');
}
-
+
}
/**
@@ -456,8 +456,8 @@ class FlexibleDayCalendar extends BaseCalendar
const dayTotal = $('.day-total span').html();
if (dayTotal !== undefined && dayTotal.length > 0)
{
- const dayIndex = new Date(this._getTodayYear(), this._getTodayMonth(), this._getTodayDate()).getDay();
- const dayHours = this._getHoursForDay(dayIndex);
+ const dayIndex = new Date(this._getTodayYear(), this._getTodayMonth(), this._getTodayDate()).getDay();
+ const dayHours = this._getHoursForDay(dayIndex);
const dayBalance = subtractTime(dayHours, dayTotal);
$('#leave-day-balance').val(dayBalance);
$('#leave-day-balance').removeClass('text-success text-danger');
diff --git a/renderer/classes/FlexibleMonthCalendar.js b/renderer/classes/FlexibleMonthCalendar.js
index d093e02f0..92e377da8 100644
--- a/renderer/classes/FlexibleMonthCalendar.js
+++ b/renderer/classes/FlexibleMonthCalendar.js
@@ -512,56 +512,61 @@ class FlexibleMonthCalendar extends BaseCalendar
/*
* Updates the monthly time balance.
*/
- _updateBalance() {
+ _updateBalance()
+ {
const now = new Date();
const monthLength = getMonthLength(this._getCalendarYear(), this._getCalendarMonth());
- let workingDaysToCompute = [];
+ const workingDaysToCompute = [];
let monthTotalWorked = '00:00';
- let countDays = false;
let isNextDay = false;
-
- for (let day = 1; day <= monthLength; ++day) {
+
+ for (let day = 1; day <= monthLength; ++day)
+ {
const isToday = now.getDate() === day &&
now.getMonth() === this._getCalendarMonth() &&
now.getFullYear() === this._getCalendarYear();
-
- // balance should consider preferences and count or not today
- if (isToday && !this._getCountToday() || isNextDay && this._getCountToday()) {
+
+ // balance should consider preferences and count or notyyyyyyyyyyyyyyyyyyyyyyyy today
+ if (isToday && !this._getCountToday() || isNextDay && this._getCountToday())
+ {
break;
}
isNextDay = isToday;
-
- if (!this._showDay(this._getCalendarYear(), this._getCalendarMonth(), day)) {
+
+ if (!this._showDay(this._getCalendarYear(), this._getCalendarMonth(), day))
+ {
continue;
}
-
+
const dayTotal = this._getDayTotal(this._getCalendarYear(), this._getCalendarMonth(), day);
- if (dayTotal) {
- countDays = true;
+ if (dayTotal)
+ {
monthTotalWorked = sumTime(monthTotalWorked, dayTotal);
const dayIndex = new Date(this._getCalendarYear(), this._getCalendarMonth(), day).getDay();
workingDaysToCompute.push(dayIndex);
}
}
-
- const monthTotalToWork = workingDaysToCompute.reduce((total, dayIndex) => {
+
+ const monthTotalToWork = workingDaysToCompute.reduce((total, dayIndex) =>
+ {
return sumTime(total, multiplyTime(this._getHoursForDay(dayIndex), -1));
}, '00:00');
-
+
const balance = sumTime(monthTotalToWork, monthTotalWorked);
-
+
const balanceElement = $('#month-balance');
- if (balanceElement) {
+ if (balanceElement)
+ {
balanceElement.val(balance);
balanceElement.removeClass('text-success text-danger');
balanceElement.addClass(isNegative(balance) ? 'text-danger' : 'text-success');
}
this._updateAllTimeBalance();
}
-
-
+
+
/*
* Updates data displayed based on the database.
diff --git a/src/preferences.html b/src/preferences.html
index b48ad8370..98ed0840c 100644
--- a/src/preferences.html
+++ b/src/preferences.html
@@ -36,20 +36,16 @@
-
-
Hide non-working days (Month View)
-
-
-
-
- Set hours for selected days
+
+
+
+
Hide non-working days (Month View)
+
+
Enable prefilling of break time
diff --git a/src/preferences.js b/src/preferences.js
index f04cb9c33..33a344573 100644
--- a/src/preferences.js
+++ b/src/preferences.js
@@ -65,12 +65,9 @@ function refreshContent()
function changeValue(type, newVal)
{
- //preferences[type] = "03:00 07:00 04:00 02:00 03:00 03:00 05:00";
+
preferences[type] = newVal;
- //preferences["hours-per-day"] = "03:00 07:00 04:00 02:00 03:00 03:00 05:00";
- //console.log("HELP friday "+ preferences["hours-friday"]);
- //console.log("HELP2 "+ preferences["hours-per-day"]);
- console.log('HELP2 '+ preferences[type]);
+
window.mainApi.notifyNewPreferences(preferences);
}
@@ -190,20 +187,20 @@ function renderPreferencesWindow()
});
const days = [
- { id: 'sunday', label: 'Sunday' },
- { id: 'monday', label: 'Monday' },
- { id: 'tuesday', label: 'Tuesday' },
- { id: 'wednesday', label: 'Wednesday' },
- { id: 'thursday', label: 'Thursday' },
- { id: 'friday', label: 'Friday' },
- { id: 'saturday', label: 'Saturday' },
+ { id: 'sunday', label: 'sun' },
+ { id: 'monday', label: 'mon' },
+ { id: 'tuesday', label: 'tue' },
+ { id: 'wednesday', label: 'wed' },
+ { id: 'thursday', label: 'thu' },
+ { id: 'friday', label: 'fri' },
+ { id: 'saturday', label: 'sat' },
];
const hoursContainer = $('#hours-container');
function updateHoursInputs()
{
- hoursContainer.empty(); // Clear previous inputs
+ hoursContainer.empty();
days.forEach(day =>
{
@@ -214,20 +211,21 @@ function renderPreferencesWindow()
const storedValue = usersStyles[inputId] || '08:00'; // Default or saved value
const inputHTML = `
-
-
-
-
- `;
+
+ `;
hoursContainer.append(inputHTML);
$(`#${inputId}`).on('change', function()
@@ -239,6 +237,10 @@ function renderPreferencesWindow()
});
}
});
+ window.mainApi.getLanguageDataPromise().then(languageData =>
+ {
+ translatePage(usersStyles.language, languageData.data, 'Preferences');
+ });
}
days.forEach(day =>