Fix Issue with ä, ö, ü in usernames. After implementing the following code, increase the appVersion in rotamaster.config.js to 5.4.3.
# encode JSON explicit to UTF-8 no BOM
$utf8Bytes = [System.Text.Encoding]::UTF8.GetBytes($jsonData)
$utf8Json = [System.Text.Encoding]::UTF8.GetString($utf8Bytes)
# encode JSON to URL
$encodedJson = [System.Web.HttpUtility]::UrlEncode($utf8Json)
# Set cookie with encoded JSON no BOM and URL encoded, add 1 day to expiry date
Set-PodeCookie -Name "CurrentUser" -Value $encodedJson -ExpiryDate (Get-Date).AddDays(1)
function getCookie(name) {
const value = `; ${document.cookie}`;
const parts = value.split(`; ${name}=`);
if (parts.length === 2) {
let cookieValue = parts.pop().split(';').shift();
try {
// URL-Dekodierung und Umwandlung von "+" zurück in Leerzeichen
cookieValue = decodeURIComponent(cookieValue).replace(/\+/g, " ");
// JSON parsen
const parsedValue = JSON.parse(cookieValue);
return parsedValue;
} catch (error) {
console.error('Error parsing cookie value:', error, cookieValue);
return null;
}
}
return null;
}
After implementing the following code, increase the appVersion in rotamaster.config.js to 5.4.2.
- Add login to the extendedProps in RotaMaster.psm1
- Fix swissHolidays for Summary in rotamaster.main.js
- Add a parameter holidays in calculateWorkdays
- Add a parameter holidays in setModalEventData
- Add new function getEasterSunday
- Add new function getSwissHolidays
- Add new function formatDateToLocalISO
Add-PodeRoute -Method Get -Path 'api/event/read/:person' ... -ScriptBlock {
...
$sql = 'SELECT id,person,login,email,"type",start,end,alias FROM v_events'
...
$sql = "SELECT id,person,login,email,""type"",start,end,alias FROM v_events WHERE person = '$($person'"
...
extendedProps = [PSCustomObject]@{
login = $item.login
email = $item.email
alias = $item.alias
}
...
}
async function getEventSummary(calendarData, selectedYear) {
...
let swissHolidays = getSwissHolidays(selectedYear)
...
result[person].ferienIntervals.forEach(interval => {
totalVacationDays += calculateWorkdays(interval.start, interval.end, swissHolidays);
});
...
result[person].PikettPeerIntervals.forEach(interval => {
totalPikettPeerDays += calculateWorkdays(interval.start, interval.end, swissHolidays);
});
...
}
function calculateWorkdays(startDate, endDate, holidays)
...
while (currentDate.getTime() < endDate.getTime()) {
const dayOfWeek = currentDate.getDay(); // Get the day of the week (0-6)
const formattedDate = formatDateToLocalISO(currentDate); // Format the date as 'YYYY-MM-DD'
const isWeekend = dayOfWeek === 0 || dayOfWeek === 6; // Sunday = 0, Saturday = 6
const isSwissHoliday = holidays.includes(formattedDate); // Check if the current date is a Swiss holiday
if(!isSwissHoliday && !isWeekend){
count++; // Count only weekdays
}
// Move to the next day
currentDate.setDate(currentDate.getDate() + 1);
}
}
function setModalEventData(event) {
let swissHolidays = getSwissHolidays(event.start.getFullYear());
...
for (const [key, value] of Object.entries(event.extendedProps)) {
if(value === 'Pikett'){
days = calculatePikettkdays(event.start,event.end)
}else{
days = calculateWorkdays(event.start, event.end, swissHolidays)
}
};
...
}
function getEasterSunday(year)
function getSwissHolidays(year)
function formatDateToLocalISO(date)
Fix if the user set the startdate less than the enddate in index.html on
// Default form submit and to call the API to add the event
document.querySelector('form');
Adding the OpsGenie integration with add and remove override. To remove the override, the events table requires a column for the OpsGenie override alias.
New structure in table events:
-- Add column alias
ALTER TABLE events
ADD alias TEXT;
and in view v_events:
-- Delete View v_events
DROP VIEW v_events;
-- Create the view for events with alias
CREATE VIEW v_events
AS
SELECT
e.id,
e.person,
e.type,
e.start,
e.end,
e.alias,
p.login,
p.firstname,
p.name,
p.email,
e.created,
e.author
FROM
events e
INNER JOIN person p ON (p.name || ' ' || p.firstname) = e.person
WHERE e.active = 1
ORDER BY
e.id ASC;
Adding a column for deleted records instead to remove the record.
New structure in table events:
-- Add column active
ALTER TABLE events
ADD active INTEGER NOT NULL
DEFAULT 1;
-- Add column deleted
ALTER TABLE events
ADD deleted TEXT;
and create a new view v_events_deleted:
-- Create the view for deleted events
CREATE VIEW v_events_deleted
AS
SELECT
e.id,
e.person,
e.type,
e.start,
e.end,
e.alias,
p.login,
p.firstname,
p.name,
p.email,
e.created,
e.deleted,
e.author
FROM
events e
INNER JOIN person p ON (p.name || ' ' || p.firstname) = e.person
WHERE e.active = 0
ORDER BY
e.id ASC;
Re-create the View for Pikett.
DROP VIEW v_pikett;
-- Create the view for pikett
CREATE VIEW v_pikett
AS
SELECT
e.person,
e.type,
e.alias,
e.start,
e.end,
e.deleted,
p.login,
p.email
FROM
events e
INNER JOIN person p ON (p.name || ' ' || p.firstname) = e.person
WHERE
e.type = 'Pikett'
ORDER BY
e.start ASC;