reduce url duplication

deepsource-autofix-76c6eb20
Dan Gowans 2023-01-05 13:04:56 -05:00
parent da821b1d28
commit c33e52102e
7 changed files with 42 additions and 48 deletions

View File

@ -353,25 +353,26 @@ Object.defineProperty(exports, "__esModule", { value: true });
* URLs
*/
const urlPrefix = document.querySelector("main").dataset.urlPrefix;
function getRecordURL(recordTypePlural, recordId, edit, time) {
return (urlPrefix +
"/" +
recordTypePlural +
"/" +
recordId +
(edit ? "/edit" : "") +
(time ? "/?t=" + Date.now() : ""));
}
function getMapURL(mapId, edit = false, time = false) {
return urlPrefix + "/maps/" + mapId + (edit ? "/edit" : "") + (time ? "/?t=" + Date.now() : "");
return getRecordURL("maps", mapId, edit, time);
}
function getLotURL(lotId, edit = false, time = false) {
return urlPrefix + "/lots/" + lotId + (edit ? "/edit" : "") + (time ? "/?t=" + Date.now() : "");
return getRecordURL("lots", lotId, edit, time);
}
function getLotOccupancyURL(lotOccupancyId, edit = false, time = false) {
return (urlPrefix +
"/lotOccupancies/" +
lotOccupancyId +
(edit ? "/edit" : "") +
(time ? "/?t=" + Date.now() : ""));
return getRecordURL("lotOccupancies", lotOccupancyId, edit, time);
}
function getWorkOrderURL(workOrderId, edit = false, time = false) {
return (urlPrefix +
"/workOrders/" +
workOrderId +
(edit ? "/edit" : "") +
(time ? "/?t=" + Date.now() : ""));
return getRecordURL("workOrders", workOrderId, edit, time);
}
/*
* Declare LOS

View File

@ -438,32 +438,37 @@ declare const bulmaJS: BulmaJS;
const urlPrefix = document.querySelector("main")!.dataset.urlPrefix!;
function getRecordURL(
recordTypePlural: "maps" | "lots" | "lotOccupancies" | "workOrders",
recordId: number | string,
edit: boolean,
time: boolean
): string {
return (
urlPrefix +
"/" +
recordTypePlural +
"/" +
recordId +
(edit ? "/edit" : "") +
(time ? "/?t=" + Date.now() : "")
);
}
function getMapURL(mapId: number | string, edit = false, time = false) {
return urlPrefix + "/maps/" + mapId + (edit ? "/edit" : "") + (time ? "/?t=" + Date.now() : "");
return getRecordURL("maps", mapId, edit, time);
}
function getLotURL(lotId: number | string, edit = false, time = false) {
return urlPrefix + "/lots/" + lotId + (edit ? "/edit" : "") + (time ? "/?t=" + Date.now() : "");
return getRecordURL("lots", lotId, edit, time);
}
function getLotOccupancyURL(lotOccupancyId: number | string, edit = false, time = false) {
return (
urlPrefix +
"/lotOccupancies/" +
lotOccupancyId +
(edit ? "/edit" : "") +
(time ? "/?t=" + Date.now() : "")
);
return getRecordURL("lotOccupancies", lotOccupancyId, edit, time);
}
function getWorkOrderURL(workOrderId: number | string, edit = false, time = false) {
return (
urlPrefix +
"/workOrders/" +
workOrderId +
(edit ? "/edit" : "") +
(time ? "/?t=" + Date.now() : "")
);
return getRecordURL("workOrders", workOrderId, edit, time);
}
/*

View File

@ -247,9 +247,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
"</td>" +
("<td>" +
'<a class="has-text-weight-bold" href="' +
cityssm.escapeHTML(los.urlPrefix) +
"/lotOccupancies/" +
lotOccupancy.lotOccupancyId +
los.getLotOccupancyURL(lotOccupancy.lotOccupancyId) +
'">' +
cityssm.escapeHTML(lotOccupancy.occupancyType || "") +
"</a>" +
@ -434,9 +432,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
rowElement.innerHTML =
"<td>" +
'<a class="has-text-weight-bold" href="' +
cityssm.escapeHTML(los.urlPrefix) +
"/lots/" +
lot.lotId +
los.getLotURL(lot.lotId) +
'">' +
cityssm.escapeHTML(lot.lotName || "") +
"</a>" +

View File

@ -119,9 +119,7 @@ function renderRelatedOccupancies() {
"</td>" +
("<td>" +
'<a class="has-text-weight-bold" href="' +
cityssm.escapeHTML(los.urlPrefix) +
"/lotOccupancies/" +
lotOccupancy.lotOccupancyId +
los.getLotOccupancyURL(lotOccupancy.lotOccupancyId) +
'">' +
cityssm.escapeHTML(lotOccupancy.occupancyType || "") +
"</a>" +
@ -306,9 +304,7 @@ function renderRelatedLots() {
rowElement.innerHTML =
"<td>" +
'<a class="has-text-weight-bold" href="' +
cityssm.escapeHTML(los.urlPrefix) +
"/lots/" +
lot.lotId +
los.getLotURL(lot.lotId) +
'">' +
cityssm.escapeHTML(lot.lotName || "") +
"</a>" +

View File

@ -174,9 +174,7 @@ function renderRelatedOccupancies(): void {
"</td>" +
("<td>" +
'<a class="has-text-weight-bold" href="' +
cityssm.escapeHTML(los.urlPrefix) +
"/lotOccupancies/" +
lotOccupancy.lotOccupancyId +
los.getLotOccupancyURL(lotOccupancy.lotOccupancyId!) +
'">' +
cityssm.escapeHTML(lotOccupancy.occupancyType || "") +
"</a>" +
@ -427,9 +425,7 @@ function renderRelatedLots(): void {
rowElement.innerHTML =
"<td>" +
'<a class="has-text-weight-bold" href="' +
cityssm.escapeHTML(los.urlPrefix) +
"/lots/" +
lot.lotId +
los.getLotURL(lot.lotId) +
'">' +
cityssm.escapeHTML(lot.lotName || "") +
"</a>" +

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long