From 12a7be497ebeb2746dcdfdd73dd9b5ea35cbd97a Mon Sep 17 00:00:00 2001 From: ToxykAuBleu <46644925+ToxykAuBleu@users.noreply.github.com> Date: Mon, 12 May 2025 08:25:26 +0000 Subject: [PATCH] Editing incident creation page to include maintenance strategy option. Removing unused properties inside newIncident. --- src/lib/server/controllers/controller.js | 1 + .../manage/(app)/app/events/+page.svelte | 113 +++++++++++++----- 2 files changed, 84 insertions(+), 30 deletions(-) diff --git a/src/lib/server/controllers/controller.js b/src/lib/server/controllers/controller.js index 6e3474d..c200bb7 100644 --- a/src/lib/server/controllers/controller.js +++ b/src/lib/server/controllers/controller.js @@ -745,6 +745,7 @@ export const GetDataGroupByDayAlternative = async (monitor_tag, start, end, time }; export const CreateIncident = async (data) => { + // TODO: depending on incident_type && maintenance_strategy, we should make or not these next conditions. //return error if no title or startDateTime if (!data.title || !data.start_date_time) { throw new Error("Title and startDateTime are required"); diff --git a/src/routes/(manage)/manage/(app)/app/events/+page.svelte b/src/routes/(manage)/manage/(app)/app/events/+page.svelte index cd95be3..596cfb2 100644 --- a/src/routes/(manage)/manage/(app)/app/events/+page.svelte +++ b/src/routes/(manage)/manage/(app)/app/events/+page.svelte @@ -34,6 +34,7 @@ import { mode } from "mode-watcher"; import * as Select from "$lib/components/ui/select"; + import { ValidateCronExpression } from "$lib/clientTools.js"; export let data; let status = "OPEN"; let loadingData = false; @@ -99,12 +100,12 @@ endDatetime: null, startDatetime: null, start_date_time: null, - endDatetime: null, - ent_date_time: null, status: "OPEN", state: "INVESTIGATING", firstComment: "", - incident_type: "INCIDENT" + incident_type: "INCIDENT", + maintenance_strategy: "SINGLE", + cron: null }; } let isMounted = false; @@ -169,16 +170,33 @@ status: newIncident.status, state: newIncident.state, id: newIncident.id, - incident_type: newIncident.incident_type + incident_type: newIncident.incident_type, + maintenance_strategy: newIncident.maintenance_strategy, + cron: newIncident.cron }; - //convert data.start_date_time to timestamp - if (!!!toPost.start_date_time) { - invalidFormMessage = "Start Date Time is required"; - return; + + if ( + toPost.incident_type === "INCIDENT" || + (toPost.maintenance_strategy && toPost.maintenance_strategy === "SINGLE") + ) { + if (!!!toPost.start_date_time) { + invalidFormMessage = "Start Date Time is required"; + return; + } + //convert data.start_date_time to timestamp + toPost.start_date_time = parseInt(new Date(toPost.start_date_time).getTime() / 1000); + if (!!toPost.end_date_time) { + toPost.end_date_time = parseInt(new Date(toPost.end_date_time).getTime() / 1000); + } } - toPost.start_date_time = parseInt(new Date(toPost.start_date_time).getTime() / 1000); - if (!!toPost.end_date_time) { - toPost.end_date_time = parseInt(new Date(toPost.end_date_time).getTime() / 1000); + + if (toPost.incident_type === "MAINTENANCE" && toPost.maintenance_strategy === "RECURRING") { + // Validate cron expression. + const cronValidation = ValidateCronExpression(toPost.cron); + if (cronValidation.isValid === false) { + invalidFormMessage = "Cron invalid: " + cronValidation.message; + return; + } } if (toPost.incident_type == "MAINTENANCE") { @@ -775,33 +793,65 @@ {/if} -