From b60ebf78ccd0d15ff29b9b314a69065d9dd62a40 Mon Sep 17 00:00:00 2001 From: Dan Gowans Date: Fri, 30 Dec 2022 10:22:53 -0500 Subject: [PATCH] refactoring --- handlers/api-get/milestoneICS.js | 109 +++++++++++++++--------------- handlers/api-get/milestoneICS.ts | 112 +++++++++++++++---------------- 2 files changed, 109 insertions(+), 112 deletions(-) diff --git a/handlers/api-get/milestoneICS.js b/handlers/api-get/milestoneICS.js index 71ff5d6f..311a8f26 100644 --- a/handlers/api-get/milestoneICS.js +++ b/handlers/api-get/milestoneICS.js @@ -24,22 +24,20 @@ function buildEventSummary(milestone) { (milestone.workOrderMilestoneTypeId ? milestone.workOrderMilestoneType : milestone.workOrderMilestoneDescription).trim(); - if (milestone.workOrderLotOccupancies.length > 0) { - let occupantCount = 0; - for (const lotOccupancy of milestone.workOrderLotOccupancies) { - for (const occupant of lotOccupancy.lotOccupancyOccupants) { - occupantCount += 1; - if (occupantCount === 1) { - if (summary !== "") { - summary += ": "; - } - summary += occupant.occupantName; + let occupantCount = 0; + for (const lotOccupancy of milestone.workOrderLotOccupancies) { + for (const occupant of lotOccupancy.lotOccupancyOccupants) { + occupantCount += 1; + if (occupantCount === 1) { + if (summary !== "") { + summary += ": "; } + summary += occupant.occupantName; } } - if (occupantCount > 1) { - summary += " plus " + (occupantCount - 1); - } + } + if (occupantCount > 1) { + summary += " plus " + (occupantCount - 1); } return summary; } @@ -47,33 +45,32 @@ function buildEventDescriptionHTML_occupancies(request, milestone) { let descriptionHTML = ""; if (milestone.workOrderLotOccupancies.length > 0) { const urlRoot = getUrlRoot(request); - descriptionHTML = - "

Related " + - escapeHTML(configFunctions.getProperty("aliases.occupancies")) + - "

" + - '' + - ("") + - ("") + - "" + - "" + - ("") + - "" + - ""; + descriptionHTML = `

+ Related ${escapeHTML(configFunctions.getProperty("aliases.occupancies"))} +

+
" + escapeHTML(configFunctions.getProperty("aliases.occupancy")) + " Type" + escapeHTML(configFunctions.getProperty("aliases.lot")) + "Start DateEnd Date" + escapeHTML(configFunctions.getProperty("aliases.occupants")) + "
+ + + + + + + + `; for (const occupancy of milestone.workOrderLotOccupancies) { descriptionHTML += - "" + - ("") + - ("") + - ("") + + ` + + + ` + "" + @@ -85,7 +82,7 @@ function buildEventDescriptionHTML_occupancies(request, milestone) { escapeHTML(occupant.occupantName) + "
"; } - descriptionHTML += "" + ""; + descriptionHTML += ""; } descriptionHTML += "
${escapeHTML(configFunctions.getProperty("aliases.occupancy"))} Type${escapeHTML(configFunctions.getProperty("aliases.lot"))}Start DateEnd Date${escapeHTML(configFunctions.getProperty("aliases.occupants"))}
" + - '' + - escapeHTML(occupancy.occupancyType) + - "" + - (occupancy.lotName ? escapeHTML(occupancy.lotName) : "(Not Set)") + - "" + occupancy.occupancyStartDateString + "
+ + ${escapeHTML(occupancy.occupancyType)} + + + ${occupancy.lotName ? escapeHTML(occupancy.lotName) : "(Not Set)"} + + ${occupancy.occupancyStartDateString} + " + (occupancy.occupancyEndDate ? occupancy.occupancyEndDateString : "(No End Date)") + "
"; } @@ -100,9 +97,15 @@ function buildEventDescriptionHTML_lots(request, milestone) { escapeHTML(configFunctions.getProperty("aliases.lots")) + "" + '' + - ("") + - ("") + - ("") + + ` + + ` + "" + "" + ""; @@ -117,9 +120,9 @@ function buildEventDescriptionHTML_lots(request, milestone) { '">' + escapeHTML(lot.lotName) + "") + - ("") + - ("") + - ("") + + `` + + `` + + `` + ""; } descriptionHTML += "
" + escapeHTML(configFunctions.getProperty("aliases.lot")) + " Type" + escapeHTML(configFunctions.getProperty("aliases.map")) + "" + escapeHTML(configFunctions.getProperty("aliases.lot")) + " Type" + " + ${escapeHTML(configFunctions.getProperty("aliases.lot"))} Type + + ${escapeHTML(configFunctions.getProperty("aliases.map"))} + + ${escapeHTML(configFunctions.getProperty("aliases.lot"))} Type + Status
" + escapeHTML(lot.mapName) + "" + escapeHTML(lot.lotType) + "" + escapeHTML(lot.lotStatus) + "${escapeHTML(lot.mapName)}${escapeHTML(lot.lotType)}${escapeHTML(lot.lotStatus)}
"; @@ -148,15 +151,11 @@ function buildEventDescriptionHTML_prints(request, milestone) { } function buildEventDescriptionHTML(request, milestone) { const workOrderUrl = getWorkOrderUrl(request, milestone); - let descriptionHTML = "

Milestone Description

" + - "

" + - escapeHTML(milestone.workOrderMilestoneDescription) + - "

" + - "

Work Order #" + - milestone.workOrderNumber + - "

" + - ("

" + escapeHTML(milestone.workOrderDescription) + "

") + - ("

" + workOrderUrl + "

"); + let descriptionHTML = `

Milestone Description

+

${escapeHTML(milestone.workOrderMilestoneDescription)}

+

Work Order #${milestone.workOrderNumber}

+

${escapeHTML(milestone.workOrderDescription)}

+

${workOrderUrl}

`; descriptionHTML += buildEventDescriptionHTML_occupancies(request, milestone); descriptionHTML += buildEventDescriptionHTML_lots(request, milestone); descriptionHTML += buildEventDescriptionHTML_prints(request, milestone); @@ -202,7 +201,7 @@ export const handler = (request, response) => { url: urlRoot + "/workOrders" }); if (request.query.workOrderId && workOrderMilestones.length > 0) { - calendar.name("Work Order #" + workOrderMilestones[0].workOrderNumber); + calendar.name(`Work Order #${workOrderMilestones[0].workOrderNumber}`); calendar.url(urlRoot + "/workOrders/" + workOrderMilestones[0].workOrderId); } calendar.prodId({ diff --git a/handlers/api-get/milestoneICS.ts b/handlers/api-get/milestoneICS.ts index 08faf237..b1574406 100644 --- a/handlers/api-get/milestoneICS.ts +++ b/handlers/api-get/milestoneICS.ts @@ -46,26 +46,24 @@ function buildEventSummary(milestone: recordTypes.WorkOrderMilestone): string { : milestone.workOrderMilestoneDescription ).trim(); - if (milestone.workOrderLotOccupancies.length > 0) { - let occupantCount = 0; + let occupantCount = 0; - for (const lotOccupancy of milestone.workOrderLotOccupancies) { - for (const occupant of lotOccupancy.lotOccupancyOccupants) { - occupantCount += 1; + for (const lotOccupancy of milestone.workOrderLotOccupancies) { + for (const occupant of lotOccupancy.lotOccupancyOccupants) { + occupantCount += 1; - if (occupantCount === 1) { - if (summary !== "") { - summary += ": "; - } - - summary += occupant.occupantName; + if (occupantCount === 1) { + if (summary !== "") { + summary += ": "; } + + summary += occupant.occupantName; } } + } - if (occupantCount > 1) { - summary += " plus " + (occupantCount - 1); - } + if (occupantCount > 1) { + summary += " plus " + (occupantCount - 1); } return summary; @@ -80,34 +78,33 @@ function buildEventDescriptionHTML_occupancies( if (milestone.workOrderLotOccupancies.length > 0) { const urlRoot = getUrlRoot(request); - descriptionHTML = - "

Related " + - escapeHTML(configFunctions.getProperty("aliases.occupancies")) + - "

" + - '' + - ("") + - ("") + - "" + - "" + - ("") + - "" + - ""; + descriptionHTML = `

+ Related ${escapeHTML(configFunctions.getProperty("aliases.occupancies"))} +

+
" + escapeHTML(configFunctions.getProperty("aliases.occupancy")) + " Type" + escapeHTML(configFunctions.getProperty("aliases.lot")) + "Start DateEnd Date" + escapeHTML(configFunctions.getProperty("aliases.occupants")) + "
+ + + + + + + + `; for (const occupancy of milestone.workOrderLotOccupancies) { descriptionHTML += - "" + - ("") + - ("") + - ("") + + ` + + + ` + "" + @@ -121,7 +118,7 @@ function buildEventDescriptionHTML_occupancies( "
"; } - descriptionHTML += "" + ""; + descriptionHTML += ""; } descriptionHTML += "
${escapeHTML(configFunctions.getProperty("aliases.occupancy"))} Type${escapeHTML(configFunctions.getProperty("aliases.lot"))}Start DateEnd Date${escapeHTML(configFunctions.getProperty("aliases.occupants"))}
" + - '' + - escapeHTML(occupancy.occupancyType) + - "" + - (occupancy.lotName ? escapeHTML(occupancy.lotName) : "(Not Set)") + - "" + occupancy.occupancyStartDateString + "
+ + ${escapeHTML(occupancy.occupancyType)} + + + ${occupancy.lotName ? escapeHTML(occupancy.lotName) : "(Not Set)"} + + ${occupancy.occupancyStartDateString} + " + (occupancy.occupancyEndDate ? occupancy.occupancyEndDateString : "(No End Date)") + "
"; @@ -144,9 +141,15 @@ function buildEventDescriptionHTML_lots( escapeHTML(configFunctions.getProperty("aliases.lots")) + "" + '' + - ("") + - ("") + - ("") + + ` + + ` + "" + "" + ""; @@ -162,9 +165,9 @@ function buildEventDescriptionHTML_lots( '">' + escapeHTML(lot.lotName) + "") + - ("") + - ("") + - ("") + + `` + + `` + + `` + ""; } @@ -210,16 +213,11 @@ function buildEventDescriptionHTML( ): string { const workOrderUrl = getWorkOrderUrl(request, milestone); - let descriptionHTML = - "

Milestone Description

" + - "

" + - escapeHTML(milestone.workOrderMilestoneDescription) + - "

" + - "

Work Order #" + - milestone.workOrderNumber + - "

" + - ("

" + escapeHTML(milestone.workOrderDescription) + "

") + - ("

" + workOrderUrl + "

"); + let descriptionHTML = `

Milestone Description

+

${escapeHTML(milestone.workOrderMilestoneDescription)}

+

Work Order #${milestone.workOrderNumber}

+

${escapeHTML(milestone.workOrderDescription)}

+

${workOrderUrl}

`; descriptionHTML += buildEventDescriptionHTML_occupancies(request, milestone); descriptionHTML += buildEventDescriptionHTML_lots(request, milestone); @@ -286,7 +284,7 @@ export const handler: RequestHandler = (request, response) => { }); if (request.query.workOrderId && workOrderMilestones.length > 0) { - calendar.name("Work Order #" + workOrderMilestones[0].workOrderNumber); + calendar.name(`Work Order #${workOrderMilestones[0].workOrderNumber}`); calendar.url(urlRoot + "/workOrders/" + workOrderMilestones[0].workOrderId); }
" + escapeHTML(configFunctions.getProperty("aliases.lot")) + " Type" + escapeHTML(configFunctions.getProperty("aliases.map")) + "" + escapeHTML(configFunctions.getProperty("aliases.lot")) + " Type" + " + ${escapeHTML(configFunctions.getProperty("aliases.lot"))} Type + + ${escapeHTML(configFunctions.getProperty("aliases.map"))} + + ${escapeHTML(configFunctions.getProperty("aliases.lot"))} Type + Status
" + escapeHTML(lot.mapName) + "" + escapeHTML(lot.lotType) + "" + escapeHTML(lot.lotStatus) + "${escapeHTML(lot.mapName)}${escapeHTML(lot.lotType)}${escapeHTML(lot.lotStatus)}