lot occupant type maintenance

deepsource-autofix-76c6eb20
Dan Gowans 2022-08-26 11:10:07 -04:00
parent 8b798443ed
commit f7d91e5d09
37 changed files with 1099 additions and 88 deletions

View File

@ -0,0 +1,3 @@
import type { RequestHandler } from "express";
export declare const handler: RequestHandler;
export default handler;

View File

@ -0,0 +1,12 @@
import { addLotOccupantType } from "../../helpers/lotOccupancyDB/addLotOccupantType.js";
import { getLotOccupantTypes } from "../../helpers/functions.cache.js";
export const handler = async (request, response) => {
const lotOccupantTypeId = addLotOccupantType(request.body, request.session);
const lotOccupantTypes = getLotOccupantTypes();
response.json({
success: true,
lotOccupantTypeId,
lotOccupantTypes
});
};
export default handler;

View File

@ -0,0 +1,28 @@
import type {
RequestHandler
} from "express";
import {
addLotOccupantType
} from "../../helpers/lotOccupancyDB/addLotOccupantType.js";
import {
getLotOccupantTypes
} from "../../helpers/functions.cache.js";
export const handler: RequestHandler = async (request, response) => {
const lotOccupantTypeId = addLotOccupantType(request.body, request.session);
const lotOccupantTypes = getLotOccupantTypes();
response.json({
success: true,
lotOccupantTypeId,
lotOccupantTypes
});
};
export default handler;

View File

@ -0,0 +1,3 @@
import type { RequestHandler } from "express";
export declare const handler: RequestHandler;
export default handler;

View File

@ -0,0 +1,11 @@
import { deleteLotOccupantType } from "../../helpers/lotOccupancyDB/deleteLotOccupantType.js";
import { getLotOccupantTypes } from "../../helpers/functions.cache.js";
export const handler = async (request, response) => {
const success = deleteLotOccupantType(request.body.lotOccupantTypeId, request.session);
const lotOccupantTypes = getLotOccupantTypes();
response.json({
success,
lotOccupantTypes
});
};
export default handler;

View File

@ -0,0 +1,27 @@
import type {
RequestHandler
} from "express";
import {
deleteLotOccupantType
} from "../../helpers/lotOccupancyDB/deleteLotOccupantType.js";
import {
getLotOccupantTypes
} from "../../helpers/functions.cache.js";
export const handler: RequestHandler = async (request, response) => {
const success = deleteLotOccupantType(request.body.lotOccupantTypeId, request.session);
const lotOccupantTypes = getLotOccupantTypes();
response.json({
success,
lotOccupantTypes
});
};
export default handler;

View File

@ -0,0 +1,3 @@
import type { RequestHandler } from "express";
export declare const handler: RequestHandler;
export default handler;

View File

@ -0,0 +1,11 @@
import { moveLotOccupantTypeDown } from "../../helpers/lotOccupancyDB/moveLotOccupantTypeDown.js";
import { getLotOccupantTypes } from "../../helpers/functions.cache.js";
export const handler = async (request, response) => {
const success = moveLotOccupantTypeDown(request.body.lotOccupantTypeId);
const lotOccupantTypes = getLotOccupantTypes();
response.json({
success,
lotOccupantTypes
});
};
export default handler;

View File

@ -0,0 +1,27 @@
import type {
RequestHandler
} from "express";
import {
moveLotOccupantTypeDown
} from "../../helpers/lotOccupancyDB/moveLotOccupantTypeDown.js";
import {
getLotOccupantTypes
} from "../../helpers/functions.cache.js";
export const handler: RequestHandler = async (request, response) => {
const success = moveLotOccupantTypeDown(request.body.lotOccupantTypeId);
const lotOccupantTypes = getLotOccupantTypes();
response.json({
success,
lotOccupantTypes
});
};
export default handler;

View File

@ -0,0 +1,3 @@
import type { RequestHandler } from "express";
export declare const handler: RequestHandler;
export default handler;

View File

@ -0,0 +1,11 @@
import { moveLotOccupantTypeUp } from "../../helpers/lotOccupancyDB/moveLotOccupantTypeUp.js";
import { getLotOccupantTypes } from "../../helpers/functions.cache.js";
export const handler = async (request, response) => {
const success = moveLotOccupantTypeUp(request.body.lotOccupantTypeId);
const lotOccupantTypes = getLotOccupantTypes();
response.json({
success,
lotOccupantTypes
});
};
export default handler;

View File

@ -0,0 +1,27 @@
import type {
RequestHandler
} from "express";
import {
moveLotOccupantTypeUp
} from "../../helpers/lotOccupancyDB/moveLotOccupantTypeUp.js";
import {
getLotOccupantTypes
} from "../../helpers/functions.cache.js";
export const handler: RequestHandler = async (request, response) => {
const success = moveLotOccupantTypeUp(request.body.lotOccupantTypeId);
const lotOccupantTypes = getLotOccupantTypes();
response.json({
success,
lotOccupantTypes
});
};
export default handler;

View File

@ -0,0 +1,3 @@
import type { RequestHandler } from "express";
export declare const handler: RequestHandler;
export default handler;

View File

@ -0,0 +1,11 @@
import { updateLotOccupantType } from "../../helpers/lotOccupancyDB/updateLotOccupantType.js";
import { getLotOccupantTypes } from "../../helpers/functions.cache.js";
export const handler = async (request, response) => {
const success = updateLotOccupantType(request.body, request.session);
const lotOccupantTypes = getLotOccupantTypes();
response.json({
success,
lotOccupantTypes
});
};
export default handler;

View File

@ -0,0 +1,27 @@
import type {
RequestHandler
} from "express";
import {
updateLotOccupantType
} from "../../helpers/lotOccupancyDB/updateLotOccupantType.js";
import {
getLotOccupantTypes
} from "../../helpers/functions.cache.js";
export const handler: RequestHandler = async (request, response) => {
const success = updateLotOccupantType(request.body, request.session);
const lotOccupantTypes = getLotOccupantTypes();
response.json({
success,
lotOccupantTypes
});
};
export default handler;

View File

@ -10,7 +10,7 @@ export const addLotOccupantType = (lotOccupantTypeForm, requestSession) => {
" recordCreate_userName, recordCreate_timeMillis," +
" recordUpdate_userName, recordUpdate_timeMillis)" +
" values (?, ?, ?, ?, ?, ?)")
.run(lotOccupantTypeForm.lotOccupantType, (lotOccupantTypeForm.orderNumber || 0), requestSession.user.userName, rightNowMillis, requestSession.user.userName, rightNowMillis);
.run(lotOccupantTypeForm.lotOccupantType, (lotOccupantTypeForm.orderNumber || -1), requestSession.user.userName, rightNowMillis, requestSession.user.userName, rightNowMillis);
database.close();
clearLotOccupantTypesCache();
return result.lastInsertRowid;

View File

@ -28,7 +28,7 @@ export const addLotOccupantType =
" recordUpdate_userName, recordUpdate_timeMillis)" +
" values (?, ?, ?, ?, ?, ?)")
.run(lotOccupantTypeForm.lotOccupantType,
(lotOccupantTypeForm.orderNumber || 0),
(lotOccupantTypeForm.orderNumber || -1),
requestSession.user.userName,
rightNowMillis,
requestSession.user.userName,

View File

@ -0,0 +1,3 @@
import type * as recordTypes from "../../types/recordTypes";
export declare const deleteLotOccupantType: (lotOccupantTypeId: number | string, requestSession: recordTypes.PartialSession) => boolean;
export default deleteLotOccupantType;

View File

@ -0,0 +1,17 @@
import sqlite from "better-sqlite3";
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
import { clearLotOccupantTypesCache } from "../functions.cache.js";
export const deleteLotOccupantType = (lotOccupantTypeId, requestSession) => {
const database = sqlite(databasePath);
const rightNowMillis = Date.now();
const result = database
.prepare("update LotOccupantTypes" +
" set recordDelete_userName = ?," +
" recordDelete_timeMillis = ?" +
" where lotOccupantTypeId = ?")
.run(requestSession.user.userName, rightNowMillis, lotOccupantTypeId);
database.close();
clearLotOccupantTypesCache();
return (result.changes > 0);
};
export default deleteLotOccupantType;

View File

@ -0,0 +1,39 @@
import sqlite from "better-sqlite3";
import {
lotOccupancyDB as databasePath
} from "../../data/databasePaths.js";
import {
clearLotOccupantTypesCache
} from "../functions.cache.js";
import type * as recordTypes from "../../types/recordTypes";
export const deleteLotOccupantType =
(lotOccupantTypeId: number | string,
requestSession: recordTypes.PartialSession): boolean => {
const database = sqlite(databasePath);
const rightNowMillis = Date.now();
const result = database
.prepare("update LotOccupantTypes" +
" set recordDelete_userName = ?," +
" recordDelete_timeMillis = ?" +
" where lotOccupantTypeId = ?")
.run(requestSession.user.userName,
rightNowMillis,
lotOccupantTypeId);
database.close();
clearLotOccupantTypesCache();
return (result.changes > 0);
};
export default deleteLotOccupantType;

View File

@ -1,15 +1,24 @@
import sqlite from "better-sqlite3";
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
export const getLotOccupantTypes = () => {
const database = sqlite(databasePath, {
readonly: true
});
const database = sqlite(databasePath);
const lotOccupantTypes = database
.prepare("select lotOccupantTypeId, lotOccupantType" +
" from LotOccupantTypes" +
" where recordDelete_timeMillis is null" +
" order by orderNumber, lotOccupantType")
.all();
let expectedOrderNumber = 0;
for (const lotOccupantType of lotOccupantTypes) {
if (lotOccupantType.orderNumber !== expectedOrderNumber) {
database.prepare("update LotOccupantTypes" +
" set orderNumber = ?" +
" where lotOccupantTypeId = ?")
.run(expectedOrderNumber, lotOccupantType.lotOccupantTypeId);
lotOccupantType.orderNumber = expectedOrderNumber;
}
expectedOrderNumber += 1;
}
database.close();
return lotOccupantTypes;
};

View File

@ -9,9 +9,7 @@ import type * as recordTypes from "../../types/recordTypes";
export const getLotOccupantTypes = (): recordTypes.LotOccupantType[] => {
const database = sqlite(databasePath, {
readonly: true
});
const database = sqlite(databasePath);
const lotOccupantTypes: recordTypes.LotOccupantType[] = database
.prepare("select lotOccupantTypeId, lotOccupantType" +
@ -20,6 +18,24 @@ export const getLotOccupantTypes = (): recordTypes.LotOccupantType[] => {
" order by orderNumber, lotOccupantType")
.all();
let expectedOrderNumber = 0;
for (const lotOccupantType of lotOccupantTypes) {
if (lotOccupantType.orderNumber !== expectedOrderNumber) {
database.prepare("update LotOccupantTypes" +
" set orderNumber = ?" +
" where lotOccupantTypeId = ?")
.run(expectedOrderNumber,
lotOccupantType.lotOccupantTypeId);
lotOccupantType.orderNumber = expectedOrderNumber;
}
expectedOrderNumber += 1;
}
database.close();
return lotOccupantTypes;

View File

@ -0,0 +1,2 @@
export declare const moveLotOccupantTypeDown: (lotOccupantTypeId: number | string) => boolean;
export default moveLotOccupantTypeDown;

View File

@ -0,0 +1,26 @@
import sqlite from "better-sqlite3";
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
import { clearLotOccupantTypesCache } from "../functions.cache.js";
export const moveLotOccupantTypeDown = (lotOccupantTypeId) => {
const database = sqlite(databasePath);
const currentOrderNumber = database.prepare("select orderNumber" +
" from LotOccupantTypes" +
" where lotOccupantTypeId = ?")
.get(lotOccupantTypeId)
.orderNumber;
database
.prepare("update LotOccupantTypes" +
" set orderNumber = orderNumber - 1" +
" where recordDelete_timeMillis is null" +
" and orderNumber = ? + 1")
.run(currentOrderNumber);
const result = database
.prepare("update LotOccupantTypes" +
" set orderNumber = ? + 1" +
" where lotOccupantTypeId = ?")
.run(currentOrderNumber, lotOccupantTypeId);
database.close();
clearLotOccupantTypesCache();
return result.changes > 0;
};
export default moveLotOccupantTypeDown;

View File

@ -0,0 +1,44 @@
import sqlite from "better-sqlite3";
import {
lotOccupancyDB as databasePath
} from "../../data/databasePaths.js";
import {
clearLotOccupantTypesCache
} from "../functions.cache.js";
export const moveLotOccupantTypeDown =
(lotOccupantTypeId: number | string): boolean => {
const database = sqlite(databasePath);
const currentOrderNumber: number = database.prepare("select orderNumber" +
" from LotOccupantTypes" +
" where lotOccupantTypeId = ?")
.get(lotOccupantTypeId)
.orderNumber;
database
.prepare("update LotOccupantTypes" +
" set orderNumber = orderNumber - 1" +
" where recordDelete_timeMillis is null" +
" and orderNumber = ? + 1")
.run(currentOrderNumber);
const result = database
.prepare("update LotOccupantTypes" +
" set orderNumber = ? + 1" +
" where lotOccupantTypeId = ?")
.run(currentOrderNumber, lotOccupantTypeId);
database.close();
clearLotOccupantTypesCache();
return result.changes > 0;
};
export default moveLotOccupantTypeDown;

View File

@ -0,0 +1,2 @@
export declare const moveLotOccupantTypeUp: (lotOccupantTypeId: number | string) => boolean;
export default moveLotOccupantTypeUp;

View File

@ -0,0 +1,30 @@
import sqlite from "better-sqlite3";
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
import { clearLotOccupantTypesCache } from "../functions.cache.js";
export const moveLotOccupantTypeUp = (lotOccupantTypeId) => {
const database = sqlite(databasePath);
const currentOrderNumber = database.prepare("select orderNumber" +
" from LotOccupantTypes" +
" where lotOccupantTypeId = ?")
.get(lotOccupantTypeId)
.orderNumber;
if (currentOrderNumber <= 0) {
database.close();
return true;
}
database
.prepare("update LotOccupantTypes" +
" set orderNumber = orderNumber + 1" +
" where recordDelete_timeMillis is null" +
" and orderNumber = ? - 1")
.run(currentOrderNumber);
const result = database
.prepare("update LotOccupantTypes" +
" set orderNumber = ? - 1" +
" where lotOccupantTypeId = ?")
.run(currentOrderNumber, lotOccupantTypeId);
database.close();
clearLotOccupantTypesCache();
return result.changes > 0;
};
export default moveLotOccupantTypeUp;

View File

@ -0,0 +1,49 @@
import sqlite from "better-sqlite3";
import {
lotOccupancyDB as databasePath
} from "../../data/databasePaths.js";
import {
clearLotOccupantTypesCache
} from "../functions.cache.js";
export const moveLotOccupantTypeUp =
(lotOccupantTypeId: number | string): boolean => {
const database = sqlite(databasePath);
const currentOrderNumber: number = database.prepare("select orderNumber" +
" from LotOccupantTypes" +
" where lotOccupantTypeId = ?")
.get(lotOccupantTypeId)
.orderNumber;
if (currentOrderNumber <= 0) {
database.close();
return true;
}
database
.prepare("update LotOccupantTypes" +
" set orderNumber = orderNumber + 1" +
" where recordDelete_timeMillis is null" +
" and orderNumber = ? - 1")
.run(currentOrderNumber);
const result = database
.prepare("update LotOccupantTypes" +
" set orderNumber = ? - 1" +
" where lotOccupantTypeId = ?")
.run(currentOrderNumber, lotOccupantTypeId);
database.close();
clearLotOccupantTypesCache();
return result.changes > 0;
};
export default moveLotOccupantTypeUp;

View File

@ -0,0 +1,7 @@
import type * as recordTypes from "../../types/recordTypes";
interface UpdateLotOccupantTypeForm {
lotOccupantTypeId: number | string;
lotOccupantType: string;
}
export declare const updateLotOccupantType: (lotOccupantTypeForm: UpdateLotOccupantTypeForm, requestSession: recordTypes.PartialSession) => boolean;
export default updateLotOccupantType;

View File

@ -0,0 +1,19 @@
import sqlite from "better-sqlite3";
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
import { clearLotOccupantTypesCache } from "../functions.cache.js";
export const updateLotOccupantType = (lotOccupantTypeForm, requestSession) => {
const database = sqlite(databasePath);
const rightNowMillis = Date.now();
const result = database
.prepare("update LotOccupantTypes" +
" set lotOccupantType = ?," +
" recordUpdate_userName = ?," +
" recordUpdate_timeMillis = ?" +
" where lotOccupantTypeId = ?" +
" and recordDelete_timeMillis is null")
.run(lotOccupantTypeForm.lotOccupantType, requestSession.user.userName, rightNowMillis, lotOccupantTypeForm.lotOccupantTypeId);
database.close();
clearLotOccupantTypesCache();
return result.changes > 0;
};
export default updateLotOccupantType;

View File

@ -0,0 +1,47 @@
import sqlite from "better-sqlite3";
import {
lotOccupancyDB as databasePath
} from "../../data/databasePaths.js";
import {
clearLotOccupantTypesCache
} from "../functions.cache.js";
import type * as recordTypes from "../../types/recordTypes";
interface UpdateLotOccupantTypeForm {
lotOccupantTypeId: number | string;
lotOccupantType: string;
}
export const updateLotOccupantType =
(lotOccupantTypeForm: UpdateLotOccupantTypeForm, requestSession: recordTypes.PartialSession): boolean => {
const database = sqlite(databasePath);
const rightNowMillis = Date.now();
const result = database
.prepare("update LotOccupantTypes" +
" set lotOccupantType = ?," +
" recordUpdate_userName = ?," +
" recordUpdate_timeMillis = ?" +
" where lotOccupantTypeId = ?" +
" and recordDelete_timeMillis is null")
.run(lotOccupantTypeForm.lotOccupantType,
requestSession.user.userName,
rightNowMillis,
lotOccupantTypeForm.lotOccupantTypeId);
database.close();
clearLotOccupantTypesCache();
return result.changes > 0;
};
export default updateLotOccupantType;

View File

@ -352,4 +352,181 @@ Object.defineProperty(exports, "__esModule", { value: true });
});
});
renderLotStatuses();
let lotOccupantTypes = exports.lotOccupantTypes;
delete exports.lotOccupantTypes;
const updateLotOccupantType = (submitEvent) => {
submitEvent.preventDefault();
cityssm.postJSON(urlPrefix + "/admin/doUpdateLotOccupantType", submitEvent.currentTarget, (responseJSON) => {
if (responseJSON.success) {
lotOccupantTypes = responseJSON.lotOccupantTypes;
bulmaJS.alert({
message: exports.aliases.lot + " " + exports.aliases.occupant + " Type Updated Successfully",
contextualColorName: "success"
});
}
else {
bulmaJS.alert({
title: "Error Updating " + exports.aliases.lot + " " + exports.aliases.occupant + " Type",
message: responseJSON.errorMessage,
contextualColorName: "danger"
});
}
});
};
const deleteLotOccupantType = (clickEvent) => {
const tableRowElement = clickEvent.currentTarget.closest("tr");
const lotOccupantTypeId = tableRowElement.dataset.lotOccupantTypeId;
const doDelete = () => {
cityssm.postJSON(urlPrefix + "/admin/doDeleteLotOccupantType", {
lotOccupantTypeId
}, (responseJSON) => {
if (responseJSON.success) {
lotOccupantTypes = responseJSON.lotOccupantTypes;
if (lotOccupantTypes.length === 0) {
renderLotOccupantTypes();
}
else {
tableRowElement.remove();
}
bulmaJS.alert({
message: exports.aliases.lot + " " + exports.aliases.occupant + " Type Deleted Successfully",
contextualColorName: "success"
});
}
else {
bulmaJS.alert({
title: "Error Deleting " + exports.aliases.lot + " " + exports.aliases.occupant + " Type",
message: responseJSON.errorMessage,
contextualColorName: "danger"
});
}
});
};
bulmaJS.confirm({
title: "Delete " + exports.aliases.lot + " " + exports.aliases.occupant + " Type",
message: "Are you sure you want to delete this " + exports.aliases.lot.toLowerCase() + " " + exports.aliases.occupant.toLowerCase() + " type?<br />" +
"Note that no " + exports.aliases.lot.toLowerCase() + " " + exports.aliases.occupancy.toLowerCase() + " will be removed.",
messageIsHtml: true,
contextualColorName: "warning",
okButton: {
text: "Yes, Delete " + exports.aliases.lot + " " + exports.aliases.occupant + " Type",
callbackFunction: doDelete
}
});
};
const moveLotOccupantTypeUp = (clickEvent) => {
const tableRowElement = clickEvent.currentTarget.closest("tr");
const lotOccupantTypeId = tableRowElement.dataset.lotOccupantTypeId;
cityssm.postJSON(urlPrefix + "/admin/doMoveLotOccupantTypeUp", {
lotOccupantTypeId
}, (responseJSON) => {
if (responseJSON.success) {
lotOccupantTypes = responseJSON.lotOccupantTypes;
renderLotOccupantTypes();
}
else {
bulmaJS.alert({
title: "Error Moving " + exports.aliases.lot + " " + exports.aliases.occupant + " Type",
message: responseJSON.errorMessage,
contextualColorName: "danger"
});
}
});
};
const moveLotOccupantTypeDown = (clickEvent) => {
const tableRowElement = clickEvent.currentTarget.closest("tr");
const lotOccupantTypeId = tableRowElement.dataset.lotOccupantTypeId;
cityssm.postJSON(urlPrefix + "/admin/doMoveLotOccupantTypeDown", {
lotOccupantTypeId
}, (responseJSON) => {
if (responseJSON.success) {
lotOccupantTypes = responseJSON.lotOccupantTypes;
renderLotOccupantTypes();
}
else {
bulmaJS.alert({
title: "Error Moving " + exports.aliases.lot + " " + exports.aliases.occupant + " Type",
message: responseJSON.errorMessage,
contextualColorName: "danger"
});
}
});
};
const renderLotOccupantTypes = () => {
const containerElement = document.querySelector("#container--lotOccupantTypes");
if (workOrderTypes.length === 0) {
containerElement.innerHTML = "<tr>" +
"<td colspan=\"2\">" +
"<div class=\"message is-warning\">" +
"<p class=\"message-body\">There are no active " + cityssm.escapeHTML(exports.aliases.lot.toLowerCase()) + " " + cityssm.escapeHTML(exports.aliases.occupant.toLowerCase()) + " types.</p>" +
"</div>" +
"</td>" +
"</tr>";
return;
}
containerElement.innerHTML = "";
for (const lotOccupantType of lotOccupantTypes) {
const tableRowElement = document.createElement("tr");
tableRowElement.dataset.lotOccupantTypeId = lotOccupantType.lotOccupantTypeId.toString();
tableRowElement.innerHTML = "<td>" +
"<form>" +
"<input name=\"lotOccupantTypeId\" type=\"hidden\" value=\"" + lotOccupantType.lotOccupantTypeId.toString() + "\" />" +
("<div class=\"field has-addons\">" +
"<div class=\"control\">" +
"<input class=\"input\" name=\"lotOccupantType\" type=\"text\" value=\"" + cityssm.escapeHTML(lotOccupantType.lotOccupantType) + "\" maxlength=\"100\" required />" +
"</div>" +
"<div class=\"control\">" +
"<button class=\"button is-success\" type=\"submit\"><i class=\"fas fa-save\" aria-hidden=\"true\"></i></button>" +
"</div>" +
"</div>") +
"</form>" +
"</td>" +
"<td class=\"is-nowrap\">" +
"<div class=\"field is-grouped\">" +
"<div class=\"control\">" +
("<div class=\"field has-addons\">" +
"<div class=\"control\">" +
"<button class=\"button button--moveLotOccupantTypeUp\" data-tooltip=\"Move Up\" type=\"button\" aria-label=\"Move Up\"><i class=\"fas fa-arrow-up\" aria-hidden=\"true\"></i></button>" +
"</div>" +
"<div class=\"control\">" +
"<button class=\"button button--moveLotOccupantTypeDown\" data-tooltip=\"Move Down\" type=\"button\" aria-label=\"Move Down\"><i class=\"fas fa-arrow-down\" aria-hidden=\"true\"></i></button>" +
"</div>" +
"</div>") +
"</div>" +
"<div class=\"control\">" +
"<button class=\"button is-danger is-light button--deleteLotOccupantType\"" +
" data-tooltip=\"Delete " + cityssm.escapeHTML(exports.aliases.lot) + " " + cityssm.escapeHTML(exports.aliases.occupant) + " Type\" type=\"button\"" +
" aria-label=\"Delete " + cityssm.escapeHTML(exports.aliases.lot) + " " + cityssm.escapeHTML(exports.aliases.occupant) + " Type\">" +
"<i class=\"fas fa-trash\" aria-hidden=\"true\"></i>" +
"</button>" +
"</div>" +
"</div>" +
"</td>";
tableRowElement.querySelector("form").addEventListener("submit", updateLotOccupantType);
tableRowElement.querySelector(".button--moveLotOccupantTypeUp").addEventListener("click", moveLotOccupantTypeUp);
tableRowElement.querySelector(".button--moveLotOccupantTypeDown").addEventListener("click", moveLotOccupantTypeDown);
tableRowElement.querySelector(".button--deleteLotOccupantType").addEventListener("click", deleteLotOccupantType);
containerElement.append(tableRowElement);
}
};
document.querySelector("#form--addLotOccupantType").addEventListener("submit", (submitEvent) => {
submitEvent.preventDefault();
const formElement = submitEvent.currentTarget;
cityssm.postJSON(urlPrefix + "/admin/doAddLotOccupantType", formElement, (responseJSON) => {
if (responseJSON.success) {
lotOccupantTypes = responseJSON.lotOccupantTypes;
renderLotOccupantTypes();
formElement.reset();
formElement.querySelector("input").focus();
}
else {
bulmaJS.alert({
title: "Error Adding " + exports.aliases.lot + " " + exports.aliases.occupant + " Type",
message: responseJSON.errorMessage,
contextualColorName: "danger"
});
}
});
});
renderLotOccupantTypes();
})();

View File

@ -80,12 +80,12 @@ declare const bulmaJS: BulmaJS;
} else {
tableRowElement.remove();
}
bulmaJS.alert({
message: "Work Order Type Deleted Successfully",
contextualColorName: "success"
});
} else {
bulmaJS.alert({
title: "Error Deleting Work Order Type",
@ -116,27 +116,27 @@ declare const bulmaJS: BulmaJS;
const workOrderTypeId = tableRowElement.dataset.workOrderTypeId;
cityssm.postJSON(urlPrefix + "/admin/doMoveWorkOrderTypeUp", {
workOrderTypeId
},
(responseJSON: {
success: boolean;
errorMessage ? : string;
workOrderTypes ? : recordTypes.WorkOrderType[];
}) => {
workOrderTypeId
},
(responseJSON: {
success: boolean;
errorMessage ? : string;
workOrderTypes ? : recordTypes.WorkOrderType[];
}) => {
if (responseJSON.success) {
if (responseJSON.success) {
workOrderTypes = responseJSON.workOrderTypes;
renderWorkOrderTypes();
workOrderTypes = responseJSON.workOrderTypes;
renderWorkOrderTypes();
} else {
bulmaJS.alert({
title: "Error Moving Work Order Type",
message: responseJSON.errorMessage,
contextualColorName: "danger"
});
}
});
} else {
bulmaJS.alert({
title: "Error Moving Work Order Type",
message: responseJSON.errorMessage,
contextualColorName: "danger"
});
}
});
};
const moveWorkOrderTypeDown = (clickEvent: Event) => {
@ -146,27 +146,27 @@ declare const bulmaJS: BulmaJS;
const workOrderTypeId = tableRowElement.dataset.workOrderTypeId;
cityssm.postJSON(urlPrefix + "/admin/doMoveWorkOrderTypeDown", {
workOrderTypeId
},
(responseJSON: {
success: boolean;
errorMessage ? : string;
workOrderTypes ? : recordTypes.WorkOrderType[];
}) => {
workOrderTypeId
},
(responseJSON: {
success: boolean;
errorMessage ? : string;
workOrderTypes ? : recordTypes.WorkOrderType[];
}) => {
if (responseJSON.success) {
if (responseJSON.success) {
workOrderTypes = responseJSON.workOrderTypes;
renderWorkOrderTypes();
workOrderTypes = responseJSON.workOrderTypes;
renderWorkOrderTypes();
} else {
bulmaJS.alert({
title: "Error Moving Work Order Type",
message: responseJSON.errorMessage,
contextualColorName: "danger"
});
}
});
} else {
bulmaJS.alert({
title: "Error Moving Work Order Type",
message: responseJSON.errorMessage,
contextualColorName: "danger"
});
}
});
};
const renderWorkOrderTypes = () => {
@ -330,12 +330,12 @@ declare const bulmaJS: BulmaJS;
} else {
tableRowElement.remove();
}
bulmaJS.alert({
message: exports.aliases.lot + " Status Deleted Successfully",
contextualColorName: "success"
});
} else {
bulmaJS.alert({
title: "Error Deleting " + exports.aliases.lot + " Status",
@ -366,27 +366,27 @@ declare const bulmaJS: BulmaJS;
const lotStatusId = tableRowElement.dataset.lotStatusId;
cityssm.postJSON(urlPrefix + "/admin/doMoveLotStatusUp", {
lotStatusId
},
(responseJSON: {
success: boolean;
errorMessage ? : string;
lotStatuses ? : recordTypes.LotStatus[];
}) => {
lotStatusId
},
(responseJSON: {
success: boolean;
errorMessage ? : string;
lotStatuses ? : recordTypes.LotStatus[];
}) => {
if (responseJSON.success) {
if (responseJSON.success) {
lotStatuses = responseJSON.lotStatuses;
renderLotStatuses();
lotStatuses = responseJSON.lotStatuses;
renderLotStatuses();
} else {
bulmaJS.alert({
title: "Error Moving " + exports.aliases.lot + " Status",
message: responseJSON.errorMessage,
contextualColorName: "danger"
});
}
});
} else {
bulmaJS.alert({
title: "Error Moving " + exports.aliases.lot + " Status",
message: responseJSON.errorMessage,
contextualColorName: "danger"
});
}
});
};
const moveLotStatusDown = (clickEvent: Event) => {
@ -396,27 +396,27 @@ declare const bulmaJS: BulmaJS;
const lotStatusId = tableRowElement.dataset.lotStatusId;
cityssm.postJSON(urlPrefix + "/admin/doMoveLotStatusDown", {
lotStatusId
},
(responseJSON: {
success: boolean;
errorMessage ? : string;
lotStatuses ? : recordTypes.LotStatus[];
}) => {
lotStatusId
},
(responseJSON: {
success: boolean;
errorMessage ? : string;
lotStatuses ? : recordTypes.LotStatus[];
}) => {
if (responseJSON.success) {
if (responseJSON.success) {
lotStatuses = responseJSON.lotStatuses;
renderLotStatuses();
lotStatuses = responseJSON.lotStatuses;
renderLotStatuses();
} else {
bulmaJS.alert({
title: "Error Moving " + exports.aliases.lot + " Status",
message: responseJSON.errorMessage,
contextualColorName: "danger"
});
}
});
} else {
bulmaJS.alert({
title: "Error Moving " + exports.aliases.lot + " Status",
message: responseJSON.errorMessage,
contextualColorName: "danger"
});
}
});
};
const renderLotStatuses = () => {
@ -516,4 +516,257 @@ declare const bulmaJS: BulmaJS;
});
renderLotStatuses();
/*
* Lot Occupant Types
*/
let lotOccupantTypes: recordTypes.LotOccupantType[] = exports.lotOccupantTypes;
delete exports.lotOccupantTypes;
const updateLotOccupantType = (submitEvent: SubmitEvent) => {
submitEvent.preventDefault();
cityssm.postJSON(urlPrefix + "/admin/doUpdateLotOccupantType",
submitEvent.currentTarget,
(responseJSON: {
success: boolean;
errorMessage ? : string;
lotOccupantTypes ? : recordTypes.LotOccupantType[];
}) => {
if (responseJSON.success) {
lotOccupantTypes = responseJSON.lotOccupantTypes;
bulmaJS.alert({
message: exports.aliases.lot + " " + exports.aliases.occupant + " Type Updated Successfully",
contextualColorName: "success"
});
} else {
bulmaJS.alert({
title: "Error Updating " + exports.aliases.lot + " " + exports.aliases.occupant + " Type",
message: responseJSON.errorMessage,
contextualColorName: "danger"
});
}
});
};
const deleteLotOccupantType = (clickEvent: Event) => {
const tableRowElement = (clickEvent.currentTarget as HTMLElement).closest("tr");
const lotOccupantTypeId = tableRowElement.dataset.lotOccupantTypeId;
const doDelete = () => {
cityssm.postJSON(urlPrefix + "/admin/doDeleteLotOccupantType", {
lotOccupantTypeId
},
(responseJSON: {
success: boolean;
errorMessage ? : string;
lotOccupantTypes ? : recordTypes.LotOccupantType[];
}) => {
if (responseJSON.success) {
lotOccupantTypes = responseJSON.lotOccupantTypes;
if (lotOccupantTypes.length === 0) {
renderLotOccupantTypes();
} else {
tableRowElement.remove();
}
bulmaJS.alert({
message: exports.aliases.lot + " " + exports.aliases.occupant + " Type Deleted Successfully",
contextualColorName: "success"
});
} else {
bulmaJS.alert({
title: "Error Deleting " + exports.aliases.lot + " " + exports.aliases.occupant + " Type",
message: responseJSON.errorMessage,
contextualColorName: "danger"
});
}
});
};
bulmaJS.confirm({
title: "Delete " + exports.aliases.lot + " " + exports.aliases.occupant + " Type",
message: "Are you sure you want to delete this " + exports.aliases.lot.toLowerCase() + " " + exports.aliases.occupant.toLowerCase() + " type?<br />" +
"Note that no " + exports.aliases.lot.toLowerCase() + " " + exports.aliases.occupancy.toLowerCase() + " will be removed.",
messageIsHtml: true,
contextualColorName: "warning",
okButton: {
text: "Yes, Delete " + exports.aliases.lot + " " + exports.aliases.occupant + " Type",
callbackFunction: doDelete
}
});
};
const moveLotOccupantTypeUp = (clickEvent: Event) => {
const tableRowElement = (clickEvent.currentTarget as HTMLElement).closest("tr");
const lotOccupantTypeId = tableRowElement.dataset.lotOccupantTypeId;
cityssm.postJSON(urlPrefix + "/admin/doMoveLotOccupantTypeUp", {
lotOccupantTypeId
},
(responseJSON: {
success: boolean;
errorMessage ? : string;
lotOccupantTypes ? : recordTypes.LotOccupantType[];
}) => {
if (responseJSON.success) {
lotOccupantTypes = responseJSON.lotOccupantTypes;
renderLotOccupantTypes();
} else {
bulmaJS.alert({
title: "Error Moving " + exports.aliases.lot + " " + exports.aliases.occupant + " Type",
message: responseJSON.errorMessage,
contextualColorName: "danger"
});
}
});
};
const moveLotOccupantTypeDown = (clickEvent: Event) => {
const tableRowElement = (clickEvent.currentTarget as HTMLElement).closest("tr");
const lotOccupantTypeId = tableRowElement.dataset.lotOccupantTypeId;
cityssm.postJSON(urlPrefix + "/admin/doMoveLotOccupantTypeDown", {
lotOccupantTypeId
},
(responseJSON: {
success: boolean;
errorMessage ? : string;
lotOccupantTypes ? : recordTypes.LotOccupantType[];
}) => {
if (responseJSON.success) {
lotOccupantTypes = responseJSON.lotOccupantTypes;
renderLotOccupantTypes();
} else {
bulmaJS.alert({
title: "Error Moving " + exports.aliases.lot + " " + exports.aliases.occupant + " Type",
message: responseJSON.errorMessage,
contextualColorName: "danger"
});
}
});
};
const renderLotOccupantTypes = () => {
const containerElement = document.querySelector("#container--lotOccupantTypes") as HTMLTableSectionElement;
if (workOrderTypes.length === 0) {
containerElement.innerHTML = "<tr>" +
"<td colspan=\"2\">" +
"<div class=\"message is-warning\">" +
"<p class=\"message-body\">There are no active " + cityssm.escapeHTML(exports.aliases.lot.toLowerCase()) + " " + cityssm.escapeHTML(exports.aliases.occupant.toLowerCase()) + " types.</p>" +
"</div>" +
"</td>" +
"</tr>";
return;
}
containerElement.innerHTML = "";
for (const lotOccupantType of lotOccupantTypes) {
const tableRowElement = document.createElement("tr");
tableRowElement.dataset.lotOccupantTypeId = lotOccupantType.lotOccupantTypeId.toString();
tableRowElement.innerHTML = "<td>" +
"<form>" +
"<input name=\"lotOccupantTypeId\" type=\"hidden\" value=\"" + lotOccupantType.lotOccupantTypeId.toString() + "\" />" +
("<div class=\"field has-addons\">" +
"<div class=\"control\">" +
"<input class=\"input\" name=\"lotOccupantType\" type=\"text\" value=\"" + cityssm.escapeHTML(lotOccupantType.lotOccupantType) + "\" maxlength=\"100\" required />" +
"</div>" +
"<div class=\"control\">" +
"<button class=\"button is-success\" type=\"submit\"><i class=\"fas fa-save\" aria-hidden=\"true\"></i></button>" +
"</div>" +
"</div>") +
"</form>" +
"</td>" +
"<td class=\"is-nowrap\">" +
"<div class=\"field is-grouped\">" +
"<div class=\"control\">" +
("<div class=\"field has-addons\">" +
"<div class=\"control\">" +
"<button class=\"button button--moveLotOccupantTypeUp\" data-tooltip=\"Move Up\" type=\"button\" aria-label=\"Move Up\"><i class=\"fas fa-arrow-up\" aria-hidden=\"true\"></i></button>" +
"</div>" +
"<div class=\"control\">" +
"<button class=\"button button--moveLotOccupantTypeDown\" data-tooltip=\"Move Down\" type=\"button\" aria-label=\"Move Down\"><i class=\"fas fa-arrow-down\" aria-hidden=\"true\"></i></button>" +
"</div>" +
"</div>") +
"</div>" +
"<div class=\"control\">" +
"<button class=\"button is-danger is-light button--deleteLotOccupantType\"" +
" data-tooltip=\"Delete " + cityssm.escapeHTML(exports.aliases.lot) + " " + cityssm.escapeHTML(exports.aliases.occupant) + " Type\" type=\"button\"" +
" aria-label=\"Delete " + cityssm.escapeHTML(exports.aliases.lot) + " " + cityssm.escapeHTML(exports.aliases.occupant) + " Type\">" +
"<i class=\"fas fa-trash\" aria-hidden=\"true\"></i>" +
"</button>" +
"</div>" +
"</div>" +
"</td>";
tableRowElement.querySelector("form").addEventListener("submit", updateLotOccupantType);
tableRowElement.querySelector(".button--moveLotOccupantTypeUp").addEventListener("click", moveLotOccupantTypeUp);
tableRowElement.querySelector(".button--moveLotOccupantTypeDown").addEventListener("click", moveLotOccupantTypeDown);
tableRowElement.querySelector(".button--deleteLotOccupantType").addEventListener("click", deleteLotOccupantType);
containerElement.append(tableRowElement);
}
};
document.querySelector("#form--addLotOccupantType").addEventListener("submit", (submitEvent: SubmitEvent) => {
submitEvent.preventDefault();
const formElement = submitEvent.currentTarget as HTMLFormElement;
cityssm.postJSON(urlPrefix + "/admin/doAddLotOccupantType",
formElement,
(responseJSON: {
success: boolean;
errorMessage ? : string;
lotOccupantTypes ? : recordTypes.LotOccupantType[];
}) => {
if (responseJSON.success) {
lotOccupantTypes = responseJSON.lotOccupantTypes;
renderLotOccupantTypes();
formElement.reset();
formElement.querySelector("input").focus();
} else {
bulmaJS.alert({
title: "Error Adding " + exports.aliases.lot + " " + exports.aliases.occupant + " Type",
message: responseJSON.errorMessage,
contextualColorName: "danger"
});
}
});
});
renderLotOccupantTypes();
})();

File diff suppressed because one or more lines are too long

View File

@ -18,6 +18,11 @@ import handler_doUpdateLotStatus from "../handlers/admin-post/doUpdateLotStatus.
import handler_doMoveLotStatusUp from "../handlers/admin-post/doMoveLotStatusUp.js";
import handler_doMoveLotStatusDown from "../handlers/admin-post/doMoveLotStatusDown.js";
import handler_doDeleteLotStatus from "../handlers/admin-post/doDeleteLotStatus.js";
import handler_doAddLotOccupantType from "../handlers/admin-post/doAddLotOccupantType.js";
import handler_doUpdateLotOccupantType from "../handlers/admin-post/doUpdateLotOccupantType.js";
import handler_doMoveLotOccupantTypeUp from "../handlers/admin-post/doMoveLotOccupantTypeUp.js";
import handler_doMoveLotOccupantTypeDown from "../handlers/admin-post/doMoveLotOccupantTypeDown.js";
import handler_doDeleteLotOccupantType from "../handlers/admin-post/doDeleteLotOccupantType.js";
export const router = Router();
router.get("/fees", permissionHandlers.adminGetHandler, handler_fees);
router.post("/doAddFeeCategory", permissionHandlers.adminPostHandler, handler_doAddFeeCategory);
@ -33,8 +38,13 @@ router.post("/doMoveWorkOrderTypeUp", permissionHandlers.adminPostHandler, handl
router.post("/doMoveWorkOrderTypeDown", permissionHandlers.adminPostHandler, handler_doMoveWorkOrderTypeDown);
router.post("/doDeleteWorkOrderType", permissionHandlers.adminPostHandler, handler_doDeleteWorkOrderType);
router.post("/doAddLotStatus", permissionHandlers.adminPostHandler, handler_doAddLotStatus);
router.post("/doUpdateLotStatuse", permissionHandlers.adminPostHandler, handler_doUpdateLotStatus);
router.post("/doUpdateLotStatus", permissionHandlers.adminPostHandler, handler_doUpdateLotStatus);
router.post("/doMoveLotStatusUp", permissionHandlers.adminPostHandler, handler_doMoveLotStatusUp);
router.post("/doMoveLotStatusDown", permissionHandlers.adminPostHandler, handler_doMoveLotStatusDown);
router.post("/doDeleteLotStatus", permissionHandlers.adminPostHandler, handler_doDeleteLotStatus);
router.post("/doAddLotOccupantType", permissionHandlers.adminPostHandler, handler_doAddLotOccupantType);
router.post("/doUpdateLotOccupantType", permissionHandlers.adminPostHandler, handler_doUpdateLotOccupantType);
router.post("/doMoveLotOccupantTypeUp", permissionHandlers.adminPostHandler, handler_doMoveLotOccupantTypeUp);
router.post("/doMoveLotOccupantTypeDown", permissionHandlers.adminPostHandler, handler_doMoveLotOccupantTypeDown);
router.post("/doDeleteLotOccupantType", permissionHandlers.adminPostHandler, handler_doDeleteLotOccupantType);
export default router;

View File

@ -27,6 +27,12 @@ import handler_doMoveLotStatusUp from "../handlers/admin-post/doMoveLotStatusUp.
import handler_doMoveLotStatusDown from "../handlers/admin-post/doMoveLotStatusDown.js";
import handler_doDeleteLotStatus from "../handlers/admin-post/doDeleteLotStatus.js";
import handler_doAddLotOccupantType from "../handlers/admin-post/doAddLotOccupantType.js";
import handler_doUpdateLotOccupantType from "../handlers/admin-post/doUpdateLotOccupantType.js";
import handler_doMoveLotOccupantTypeUp from "../handlers/admin-post/doMoveLotOccupantTypeUp.js";
import handler_doMoveLotOccupantTypeDown from "../handlers/admin-post/doMoveLotOccupantTypeDown.js";
import handler_doDeleteLotOccupantType from "../handlers/admin-post/doDeleteLotOccupantType.js";
export const router = Router();
@ -91,12 +97,11 @@ router.post("/doDeleteWorkOrderType",
// Config Tables - Lot Statuses
router.post("/doAddLotStatus",
permissionHandlers.adminPostHandler,
handler_doAddLotStatus);
router.post("/doUpdateLotStatuse",
router.post("/doUpdateLotStatus",
permissionHandlers.adminPostHandler,
handler_doUpdateLotStatus);
@ -112,5 +117,27 @@ router.post("/doDeleteLotStatus",
permissionHandlers.adminPostHandler,
handler_doDeleteLotStatus);
// Config Tables - Lot Occupant Types
router.post("/doAddLotOccupantType",
permissionHandlers.adminPostHandler,
handler_doAddLotOccupantType);
router.post("/doUpdateLotOccupantType",
permissionHandlers.adminPostHandler,
handler_doUpdateLotOccupantType);
router.post("/doMoveLotOccupantTypeUp",
permissionHandlers.adminPostHandler,
handler_doMoveLotOccupantTypeUp);
router.post("/doMoveLotOccupantTypeDown",
permissionHandlers.adminPostHandler,
handler_doMoveLotOccupantTypeDown);
router.post("/doDeleteLotOccupantType",
permissionHandlers.adminPostHandler,
handler_doDeleteLotOccupantType);
export default router;

View File

@ -107,6 +107,33 @@
</div>
<div class="is-hidden" id="tab--lotOccupantTypes">
<h2 class="title is-4"><%= configFunctions.getProperty("aliases.lot") %> <%= configFunctions.getProperty("aliases.occupant") %> Types</h2>
<table class="table is-striped is-hoverable">
<thead>
<tr>
<th><%= configFunctions.getProperty("aliases.lot") %> <%= configFunctions.getProperty("aliases.occupant") %> Type</th>
<th class="has-text-centered has-width-1">Options</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="2">
<form id="form--addLotOccupantType">
<div class="field has-addons">
<div class="control is-expanded">
<input class="input" name="lotOccupantType" type="text" maxlength="100" placeholder="New <%= configFunctions.getProperty("aliases.lot") %> <%= configFunctions.getProperty("aliases.occupant") %> Type" required />
</div>
<div class="control">
<button class="button is-success" data-tooltip="Add Type" type="submit" aria-label="Add Type">
<i class="fas fa-plus" aria-hidden="true"></i>
</button>
</div>
</div>
</form>
</td>
</tr>
</tbody>
<tbody id="container--lotOccupantTypes"></tbody>
</table>
</div>
</div>