editView almost done

This commit is contained in:
2025-03-12 19:38:00 +01:00
commit cf2049798a
29 changed files with 3663 additions and 0 deletions

99
app/src/stores/counter.js Normal file
View File

@@ -0,0 +1,99 @@
import { ref, computed, watch } from 'vue'
import { defineStore } from 'pinia'
export const useWorkHoursStore = defineStore('workHours', () => {
const workHours = ref([
{
date: new Date(2025, 1, 1),
enterHour: 7,
enterMinute: 20,
leaveHour: 15,
leaveMinute: 15,
workHours: 7,
workMinutes: 55,
},
{
date: new Date(2025, 1, 2),
enterHour: 8,
enterMinute: 21,
leaveHour: 16,
leaveMinute: 16,
workHours: 7,
workMinutes: 55,
},
{
date: new Date(2025, 1, 3),
enterHour: 9,
enterMinute: 22,
leaveHour: 17,
leaveMinute: 17,
workHours: 7,
workMinutes: 55,
},
]);
const calculateWorkTime = (entry) => {
let totalMinutes = (entry.leaveHour * 60 + entry.leaveMinute) - (entry.enterHour * 60 + entry.enterMinute);
if (totalMinutes < 0) {
totalMinutes = 0;
}
entry.workHours = Math.floor(totalMinutes / 60);
entry.workMinutes = totalMinutes % 60;
};
// Automatyczne przeliczanie czasu pracy
watch(
() => workHours.value.map((entry, index) => ({
index,
enterHour: entry.enterHour,
enterMinute: entry.enterMinute,
leaveHour: entry.leaveHour,
leaveMinute: entry.leaveMinute,
})),
(newVal, oldVal) => {
newVal.forEach((newEntry, index) => {
const oldEntry = oldVal[index];
// Sprawdzamy, czy cokolwiek się zmieniło
if (
newEntry.enterHour !== oldEntry.enterHour ||
newEntry.enterMinute !== oldEntry.enterMinute ||
newEntry.leaveHour !== oldEntry.leaveHour ||
newEntry.leaveMinute !== oldEntry.leaveMinute
) {
calculateWorkTime(workHours.value[index]);
}
});
},
{ deep: true }
);
const getDate = (index) => {
const date = workHours.value[index].date; // Pobieramy datę
const day = String(date.getDate()).padStart(2, "0");
const month = String(date.getMonth() + 1).padStart(2, "0");
const year = date.getFullYear();
const formattedDate = `${day}.${month}.${year}`;
return formattedDate;
};
const getWeekday = (index) => {
const dayNames = ['NIE', 'PON', 'WTO', 'śRO', 'CZW', 'PIĄ', 'SOB'];
const weekday = workHours.value[index].date.getDay();
return [weekday, dayNames[weekday]];
}
const clear = () => {
workHours.value = [];
}
return {
workHours,
getDate,
getWeekday,
clear
}
})