diff --git a/handlers/lotOccupancies-get/edit.js b/handlers/lotOccupancies-get/edit.js index f47e87b1..a166d4f0 100644 --- a/handlers/lotOccupancies-get/edit.js +++ b/handlers/lotOccupancies-get/edit.js @@ -1,4 +1,4 @@ -import { getLotOccupantTypes, getLotStatuses, getLotTypes, getOccupancyTypes, getWorkOrderTypes } from "../../helpers/functions.cache.js"; +import { getLotOccupantTypes, getLotStatuses, getLotTypes, getOccupancyTypePrintsById, getOccupancyTypes, getWorkOrderTypes } from "../../helpers/functions.cache.js"; import * as configFunctions from "../../helpers/functions.config.js"; import { getLotOccupancy } from "../../helpers/lotOccupancyDB/getLotOccupancy.js"; import { getMaps } from "../../helpers/lotOccupancyDB/getMaps.js"; @@ -8,6 +8,7 @@ export const handler = (request, response) => { return response.redirect(configFunctions.getProperty("reverseProxy.urlPrefix") + "/lotOccupancies/?error=lotOccupancyIdNotFound"); } + const occupancyTypePrints = getOccupancyTypePrintsById(lotOccupancy.occupancyTypeId); const occupancyTypes = getOccupancyTypes(); const lotOccupantTypes = getLotOccupantTypes(); const lotTypes = getLotTypes(); @@ -20,6 +21,7 @@ export const handler = (request, response) => { configFunctions.getProperty("aliases.occupancy") + " Update", lotOccupancy, + occupancyTypePrints, occupancyTypes, lotOccupantTypes, lotTypes, diff --git a/handlers/lotOccupancies-get/edit.ts b/handlers/lotOccupancies-get/edit.ts index 186def10..a93244af 100644 --- a/handlers/lotOccupancies-get/edit.ts +++ b/handlers/lotOccupancies-get/edit.ts @@ -4,6 +4,7 @@ import { getLotOccupantTypes, getLotStatuses, getLotTypes, + getOccupancyTypePrintsById, getOccupancyTypes, getWorkOrderTypes } from "../../helpers/functions.cache.js"; @@ -23,6 +24,8 @@ export const handler: RequestHandler = (request, response) => { ); } + const occupancyTypePrints = getOccupancyTypePrintsById(lotOccupancy.occupancyTypeId); + const occupancyTypes = getOccupancyTypes(); const lotOccupantTypes = getLotOccupantTypes(); const lotTypes = getLotTypes(); @@ -37,6 +40,7 @@ export const handler: RequestHandler = (request, response) => { configFunctions.getProperty("aliases.occupancy") + " Update", lotOccupancy, + occupancyTypePrints, occupancyTypes, lotOccupantTypes, diff --git a/handlers/lotOccupancies-get/view.js b/handlers/lotOccupancies-get/view.js index 11d01b25..84b21966 100644 --- a/handlers/lotOccupancies-get/view.js +++ b/handlers/lotOccupancies-get/view.js @@ -1,3 +1,4 @@ +import { getOccupancyTypePrintsById } from "../../helpers/functions.cache.js"; import * as configFunctions from "../../helpers/functions.config.js"; import { getLotOccupancy } from "../../helpers/lotOccupancyDB/getLotOccupancy.js"; export const handler = (request, response) => { @@ -6,12 +7,14 @@ export const handler = (request, response) => { return response.redirect(configFunctions.getProperty("reverseProxy.urlPrefix") + "/lotOccupancies/?error=lotOccupancyIdNotFound"); } + const occupancyTypePrints = getOccupancyTypePrintsById(lotOccupancy.occupancyTypeId); return response.render("lotOccupancy-view", { headTitle: configFunctions.getProperty("aliases.lot") + " " + configFunctions.getProperty("aliases.occupancy") + " View", - lotOccupancy + lotOccupancy, + occupancyTypePrints }); }; export default handler; diff --git a/handlers/lotOccupancies-get/view.ts b/handlers/lotOccupancies-get/view.ts index ae12e322..a2d8cc7e 100644 --- a/handlers/lotOccupancies-get/view.ts +++ b/handlers/lotOccupancies-get/view.ts @@ -1,4 +1,5 @@ import type { RequestHandler } from "express"; +import { getOccupancyTypePrintsById } from "../../helpers/functions.cache.js"; import * as configFunctions from "../../helpers/functions.config.js"; @@ -14,13 +15,16 @@ export const handler: RequestHandler = (request, response) => { ); } + const occupancyTypePrints = getOccupancyTypePrintsById(lotOccupancy.occupancyTypeId); + return response.render("lotOccupancy-view", { headTitle: configFunctions.getProperty("aliases.lot") + " " + configFunctions.getProperty("aliases.occupancy") + " View", - lotOccupancy + lotOccupancy, + occupancyTypePrints }); }; diff --git a/helpers/functions.cache.d.ts b/helpers/functions.cache.d.ts index f4234232..89ca6314 100644 --- a/helpers/functions.cache.d.ts +++ b/helpers/functions.cache.d.ts @@ -15,6 +15,7 @@ export declare function getOccupancyTypes(): recordTypes.OccupancyType[]; export declare function getAllOccupancyTypeFields(): recordTypes.OccupancyTypeField[]; export declare function getOccupancyTypeById(occupancyTypeId: number): recordTypes.OccupancyType; export declare function getOccupancyTypeByOccupancyType(occupancyTypeString: string): recordTypes.OccupancyType; +export declare function getOccupancyTypePrintsById(occupancyTypeId: number): string[]; export declare function clearOccupancyTypesCache(): void; export declare function getWorkOrderTypes(): recordTypes.WorkOrderType[]; export declare function clearWorkOrderTypesCache(): void; diff --git a/helpers/functions.cache.js b/helpers/functions.cache.js index f466967b..1aeca76c 100644 --- a/helpers/functions.cache.js +++ b/helpers/functions.cache.js @@ -1,3 +1,4 @@ +import * as configFunctions from "./functions.config.js"; import { getLotOccupantTypes as getLotOccupantTypesFromDatabase } from "./lotOccupancyDB/getLotOccupantTypes.js"; import { getLotStatuses as getLotStatusesFromDatabase } from "./lotOccupancyDB/getLotStatuses.js"; import { getLotTypes as getLotTypesFromDatabase } from "./lotOccupancyDB/getLotTypes.js"; @@ -101,6 +102,16 @@ export function getOccupancyTypeByOccupancyType(occupancyTypeString) { return currentOccupancyType.occupancyType.toLowerCase() === occupancyTypeLowerCase; }); } +export function getOccupancyTypePrintsById(occupancyTypeId) { + const occupancyType = getOccupancyTypeById(occupancyTypeId); + if (!occupancyType || occupancyType.occupancyTypePrints.length === 0) { + return []; + } + if (occupancyType.occupancyTypePrints.includes("*")) { + return configFunctions.getProperty("settings.lotOccupancy.prints"); + } + return occupancyType.occupancyTypePrints; +} export function clearOccupancyTypesCache() { occupancyTypes = undefined; allOccupancyTypeFields = undefined; diff --git a/helpers/functions.cache.ts b/helpers/functions.cache.ts index fdd2946b..4e37c266 100644 --- a/helpers/functions.cache.ts +++ b/helpers/functions.cache.ts @@ -1,3 +1,5 @@ +import * as configFunctions from "./functions.config.js"; + import { getLotOccupantTypes as getLotOccupantTypesFromDatabase } from "./lotOccupancyDB/getLotOccupantTypes.js"; import { getLotStatuses as getLotStatusesFromDatabase } from "./lotOccupancyDB/getLotStatuses.js"; @@ -161,6 +163,21 @@ export function getOccupancyTypeByOccupancyType(occupancyTypeString: string) { }); } +export function getOccupancyTypePrintsById(occupancyTypeId: number): string[] { + + const occupancyType = getOccupancyTypeById(occupancyTypeId); + + if (!occupancyType || occupancyType.occupancyTypePrints.length === 0) { + return []; + } + + if (occupancyType.occupancyTypePrints.includes("*")) { + return configFunctions.getProperty("settings.lotOccupancy.prints"); + } + + return occupancyType.occupancyTypePrints; +} + export function clearOccupancyTypesCache() { occupancyTypes = undefined; allOccupancyTypeFields = undefined; diff --git a/helpers/initializer.database.js b/helpers/initializer.database.js index 90e9e8a3..56150436 100644 --- a/helpers/initializer.database.js +++ b/helpers/initializer.database.js @@ -24,7 +24,8 @@ export const initializeDatabase = () => { ")") .run(); lotOccupancyDB - .prepare("create index if not exists idx_lottypes_ordernumber" + " on LotTypes (orderNumber, lotType)") + .prepare("create index if not exists idx_lottypes_ordernumber" + + " on LotTypes (orderNumber, lotType)") .run(); lotOccupancyDB .prepare("create table if not exists LotTypeFields (" + @@ -55,7 +56,8 @@ export const initializeDatabase = () => { ")") .run(); lotOccupancyDB - .prepare("create index if not exists idx_lotstatuses_ordernumber" + " on LotStatuses (orderNumber, lotStatus)") + .prepare("create index if not exists idx_lotstatuses_ordernumber" + + " on LotStatuses (orderNumber, lotStatus)") .run(); lotOccupancyDB .prepare("create table if not exists Maps (" + @@ -151,6 +153,21 @@ export const initializeDatabase = () => { .prepare("create index if not exists idx_occupancytypefields_ordernumber" + " on OccupancyTypeFields (occupancyTypeId, orderNumber, occupancyTypeField)") .run(); + lotOccupancyDB + .prepare("create table if not exists OccupancyTypePrints (" + + "occupancyTypeId integer not null," + + " printEJS varchar(100) not null," + + " orderNumber smallint not null default 0," + + recordColumns + + "," + + " primary key (occupancyTypeId, printEJS)," + + " foreign key (occupancyTypeId) references OccupancyTypes (occupancyTypeId)" + + ")") + .run(); + lotOccupancyDB + .prepare("create index if not exists idx_occupancytypeprints_ordernumber" + + " on OccupancyTypePrints (occupancyTypeId, orderNumber, printEJS)") + .run(); lotOccupancyDB .prepare("create table if not exists LotOccupantTypes (" + "lotOccupantTypeId integer not null primary key autoincrement," + @@ -258,7 +275,8 @@ export const initializeDatabase = () => { ")") .run(); lotOccupancyDB - .prepare("create index if not exists idx_fees_ordernumber" + " on Fees (orderNumber, feeName)") + .prepare("create index if not exists idx_fees_ordernumber" + + " on Fees (orderNumber, feeName)") .run(); lotOccupancyDB .prepare("create table if not exists LotOccupancyFees (" + diff --git a/helpers/initializer.database.ts b/helpers/initializer.database.ts index 799c6e16..8a49e1cb 100644 --- a/helpers/initializer.database.ts +++ b/helpers/initializer.database.ts @@ -17,7 +17,9 @@ export const initializeDatabase = (): boolean => { const lotOccupancyDB = sqlite(databasePath); const row = lotOccupancyDB - .prepare("select name from sqlite_master where type = 'table' and name = 'WorkOrderMilestones'") + .prepare( + "select name from sqlite_master where type = 'table' and name = 'WorkOrderMilestones'" + ) .get(); if (!row) { @@ -37,7 +39,10 @@ export const initializeDatabase = (): boolean => { .run(); lotOccupancyDB - .prepare("create index if not exists idx_lottypes_ordernumber" + " on LotTypes (orderNumber, lotType)") + .prepare( + "create index if not exists idx_lottypes_ordernumber" + + " on LotTypes (orderNumber, lotType)" + ) .run(); lotOccupancyDB @@ -79,7 +84,8 @@ export const initializeDatabase = (): boolean => { lotOccupancyDB .prepare( - "create index if not exists idx_lotstatuses_ordernumber" + " on LotStatuses (orderNumber, lotStatus)" + "create index if not exists idx_lotstatuses_ordernumber" + + " on LotStatuses (orderNumber, lotStatus)" ) .run(); @@ -208,6 +214,27 @@ export const initializeDatabase = (): boolean => { ) .run(); + lotOccupancyDB + .prepare( + "create table if not exists OccupancyTypePrints (" + + "occupancyTypeId integer not null," + + " printEJS varchar(100) not null," + + " orderNumber smallint not null default 0," + + recordColumns + + "," + + " primary key (occupancyTypeId, printEJS)," + + " foreign key (occupancyTypeId) references OccupancyTypes (occupancyTypeId)" + + ")" + ) + .run(); + + lotOccupancyDB + .prepare( + "create index if not exists idx_occupancytypeprints_ordernumber" + + " on OccupancyTypePrints (occupancyTypeId, orderNumber, printEJS)" + ) + .run(); + lotOccupancyDB .prepare( "create table if not exists LotOccupantTypes (" + @@ -344,7 +371,10 @@ export const initializeDatabase = (): boolean => { .run(); lotOccupancyDB - .prepare("create index if not exists idx_fees_ordernumber" + " on Fees (orderNumber, feeName)") + .prepare( + "create index if not exists idx_fees_ordernumber" + + " on Fees (orderNumber, feeName)" + ) .run(); lotOccupancyDB diff --git a/helpers/lotOccupancyDB/getLotOccupancies.js b/helpers/lotOccupancyDB/getLotOccupancies.js index 865fd91a..701203bd 100644 --- a/helpers/lotOccupancyDB/getLotOccupancies.js +++ b/helpers/lotOccupancyDB/getLotOccupancies.js @@ -1,6 +1,8 @@ import sqlite from "better-sqlite3"; import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; import { dateIntegerToString, dateStringToInteger, dateToInteger } from "@cityssm/expressjs-server-js/dateTimeFns.js"; +import * as configFunctions from "../functions.config.js"; +import { getOccupancyTypeById } from "../functions.cache.js"; import { getLotOccupancyOccupants } from "./getLotOccupancyOccupants.js"; const buildWhereClause = (filters) => { let sqlWhereClause = " where o.recordDelete_timeMillis is null"; @@ -123,15 +125,21 @@ export const getLotOccupancies = (filters, options, connectedDatabase) => { " left join Maps m on l.mapId = m.mapId" + sqlWhereClause + " order by o.occupancyStartDate desc, ifnull(o.occupancyEndDate, 99999999) desc, l.lotName, o.lotId" + - (options.limit !== -1 - ? " limit " + options.limit + " offset " + options.offset - : "")) + (options.limit === -1 + ? "" + : " limit " + options.limit + " offset " + options.offset)) .all(sqlParameters); if (options.limit === -1) { count = lotOccupancies.length; } - if (options.includeOccupants) { - for (const lotOccupancy of lotOccupancies) { + for (const lotOccupancy of lotOccupancies) { + const occupancyType = getOccupancyTypeById(lotOccupancy.occupancyTypeId); + if (occupancyType) { + lotOccupancy.printEJS = occupancyType.occupancyTypePrints.includes("*") + ? configFunctions.getProperty("settings.lotOccupancy.prints")[0] + : occupancyType.occupancyTypePrints[0]; + } + if (options.includeOccupants) { lotOccupancy.lotOccupancyOccupants = getLotOccupancyOccupants(lotOccupancy.lotOccupancyId, database); } } diff --git a/helpers/lotOccupancyDB/getLotOccupancies.ts b/helpers/lotOccupancyDB/getLotOccupancies.ts index 7550719c..06dc0178 100644 --- a/helpers/lotOccupancyDB/getLotOccupancies.ts +++ b/helpers/lotOccupancyDB/getLotOccupancies.ts @@ -8,6 +8,9 @@ import { dateToInteger } from "@cityssm/expressjs-server-js/dateTimeFns.js"; +import * as configFunctions from "../functions.config.js"; + +import { getOccupancyTypeById } from "../functions.cache.js"; import { getLotOccupancyOccupants } from "./getLotOccupancyOccupants.js"; import type * as recordTypes from "../../types/recordTypes"; @@ -190,9 +193,9 @@ export const getLotOccupancies = ( " left join Maps m on l.mapId = m.mapId" + sqlWhereClause + " order by o.occupancyStartDate desc, ifnull(o.occupancyEndDate, 99999999) desc, l.lotName, o.lotId" + - (options.limit !== -1 - ? " limit " + options.limit + " offset " + options.offset - : "") + (options.limit === -1 + ? "" + : " limit " + options.limit + " offset " + options.offset) ) .all(sqlParameters); @@ -200,8 +203,16 @@ export const getLotOccupancies = ( count = lotOccupancies.length; } - if (options.includeOccupants) { - for (const lotOccupancy of lotOccupancies) { + for (const lotOccupancy of lotOccupancies) { + const occupancyType = getOccupancyTypeById(lotOccupancy.occupancyTypeId); + + if (occupancyType) { + lotOccupancy.printEJS = occupancyType.occupancyTypePrints.includes("*") + ? configFunctions.getProperty("settings.lotOccupancy.prints")[0] + : occupancyType.occupancyTypePrints[0]; + } + + if (options.includeOccupants) { lotOccupancy.lotOccupancyOccupants = getLotOccupancyOccupants( lotOccupancy.lotOccupancyId as number, database diff --git a/helpers/lotOccupancyDB/getOccupancyTypePrints.d.ts b/helpers/lotOccupancyDB/getOccupancyTypePrints.d.ts new file mode 100644 index 00000000..f329b610 --- /dev/null +++ b/helpers/lotOccupancyDB/getOccupancyTypePrints.d.ts @@ -0,0 +1,3 @@ +import sqlite from "better-sqlite3"; +export declare const getOccupancyTypePrints: (occupancyTypeId: number, connectedDatabase?: sqlite.Database) => string[]; +export default getOccupancyTypePrints; diff --git a/helpers/lotOccupancyDB/getOccupancyTypePrints.js b/helpers/lotOccupancyDB/getOccupancyTypePrints.js new file mode 100644 index 00000000..a3619c7d --- /dev/null +++ b/helpers/lotOccupancyDB/getOccupancyTypePrints.js @@ -0,0 +1,41 @@ +import sqlite from "better-sqlite3"; +import * as configFunctions from "../functions.config.js"; +import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; +const availablePrints = configFunctions.getProperty("settings.lotOccupancy.prints"); +const userFunction_configContainsPrintEJS = (printEJS) => { + if (printEJS === "*" || availablePrints.includes(printEJS)) { + return 1; + } + return 0; +}; +export const getOccupancyTypePrints = (occupancyTypeId, connectedDatabase) => { + const database = connectedDatabase || sqlite(databasePath); + database.function("userFn_configContainsPrintEJS", userFunction_configContainsPrintEJS); + const results = database + .prepare("select printEJS, orderNumber" + + " from OccupancyTypePrints" + + " where recordDelete_timeMillis is null" + + " and occupancyTypeId = ?" + + " and userFn_configContainsPrintEJS(printEJS) = 1" + + " order by orderNumber, printEJS") + .all(occupancyTypeId); + let expectedOrderNumber = -1; + const prints = []; + for (const result of results) { + expectedOrderNumber += 1; + if (result.orderNumber !== expectedOrderNumber) { + database + .prepare("update OccupancyTypeFields" + + " set orderNumber = ?" + + " where occupancyTypeId = ?" + + " and printEJS = ?") + .run(expectedOrderNumber, occupancyTypeId, result.printEJS); + } + prints.push(result.printEJS); + } + if (!connectedDatabase) { + database.close(); + } + return prints; +}; +export default getOccupancyTypePrints; diff --git a/helpers/lotOccupancyDB/getOccupancyTypePrints.ts b/helpers/lotOccupancyDB/getOccupancyTypePrints.ts new file mode 100644 index 00000000..2a8bba32 --- /dev/null +++ b/helpers/lotOccupancyDB/getOccupancyTypePrints.ts @@ -0,0 +1,63 @@ +import sqlite from "better-sqlite3"; + +import * as configFunctions from "../functions.config.js"; +import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; + +const availablePrints = configFunctions.getProperty("settings.lotOccupancy.prints"); + +const userFunction_configContainsPrintEJS = (printEJS: string): number => { + if (printEJS === "*" || availablePrints.includes(printEJS)) { + return 1; + } + + return 0; +}; + +export const getOccupancyTypePrints = ( + occupancyTypeId: number, + connectedDatabase?: sqlite.Database +): string[] => { + const database = connectedDatabase || sqlite(databasePath); + + database.function("userFn_configContainsPrintEJS", userFunction_configContainsPrintEJS); + + const results: { printEJS: string; orderNumber: number }[] = database + .prepare( + "select printEJS, orderNumber" + + " from OccupancyTypePrints" + + " where recordDelete_timeMillis is null" + + " and occupancyTypeId = ?" + + " and userFn_configContainsPrintEJS(printEJS) = 1" + + " order by orderNumber, printEJS" + ) + .all(occupancyTypeId); + + let expectedOrderNumber = -1; + + const prints = []; + + for (const result of results) { + expectedOrderNumber += 1; + + if (result.orderNumber !== expectedOrderNumber) { + database + .prepare( + "update OccupancyTypeFields" + + " set orderNumber = ?" + + " where occupancyTypeId = ?" + + " and printEJS = ?" + ) + .run(expectedOrderNumber, occupancyTypeId, result.printEJS); + } + + prints.push(result.printEJS); + } + + if (!connectedDatabase) { + database.close(); + } + + return prints; +}; + +export default getOccupancyTypePrints; diff --git a/helpers/lotOccupancyDB/getOccupancyTypes.js b/helpers/lotOccupancyDB/getOccupancyTypes.js index 37b9225a..35761c61 100644 --- a/helpers/lotOccupancyDB/getOccupancyTypes.js +++ b/helpers/lotOccupancyDB/getOccupancyTypes.js @@ -1,6 +1,7 @@ import sqlite from "better-sqlite3"; import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; import { getOccupancyTypeFields } from "./getOccupancyTypeFields.js"; +import { getOccupancyTypePrints } from "./getOccupancyTypePrints.js"; export const getOccupancyTypes = () => { const database = sqlite(databasePath); const occupancyTypes = database @@ -19,6 +20,7 @@ export const getOccupancyTypes = () => { occupancyType.orderNumber = expectedTypeOrderNumber; } occupancyType.occupancyTypeFields = getOccupancyTypeFields(occupancyType.occupancyTypeId, database); + occupancyType.occupancyTypePrints = getOccupancyTypePrints(occupancyType.occupancyTypeId, database); let expectedFieldOrderNumber = -1; for (const occupancyTypeField of occupancyType.occupancyTypeFields) { expectedFieldOrderNumber += 1; diff --git a/helpers/lotOccupancyDB/getOccupancyTypes.ts b/helpers/lotOccupancyDB/getOccupancyTypes.ts index 7362e237..bc2e8a67 100644 --- a/helpers/lotOccupancyDB/getOccupancyTypes.ts +++ b/helpers/lotOccupancyDB/getOccupancyTypes.ts @@ -3,6 +3,7 @@ import sqlite from "better-sqlite3"; import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js"; import { getOccupancyTypeFields } from "./getOccupancyTypeFields.js"; +import { getOccupancyTypePrints } from "./getOccupancyTypePrints.js"; import type * as recordTypes from "../../types/recordTypes"; @@ -37,6 +38,11 @@ export const getOccupancyTypes = (): recordTypes.OccupancyType[] => { occupancyType.occupancyTypeId, database ); + + occupancyType.occupancyTypePrints = getOccupancyTypePrints( + occupancyType.occupancyTypeId, + database + ); let expectedFieldOrderNumber = -1; diff --git a/public-typescript/lotOccupancySearch.js b/public-typescript/lotOccupancySearch.js index 0e60b076..2264340a 100644 --- a/public-typescript/lotOccupancySearch.js +++ b/public-typescript/lotOccupancySearch.js @@ -2,7 +2,6 @@ Object.defineProperty(exports, "__esModule", { value: true }); (() => { const los = exports.los; - const lotOccupancyPrints = exports.lotOccupancyPrints; const searchFilterFormElement = document.querySelector("#form--searchFilters"); const searchResultsContainerElement = document.querySelector("#container--searchResults"); const limit = Number.parseInt(document.querySelector("#searchFilter--limit").value, 10); @@ -111,19 +110,19 @@ Object.defineProperty(exports, "__esModule", { value: true }); : '(No End Date)') + "") + ("" + occupantsHTML + "") + - (lotOccupancyPrints.length > 0 - ? "" + - '" + + (lotOccupancy.printEJS + ? '' + '' + - "" + - "" + "" : "") + + "" + ""); } searchResultsContainerElement.innerHTML = @@ -135,9 +134,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); ("" + cityssm.escapeHTML(exports.aliases.occupancyStartDate) + "") + "End Date" + ("" + cityssm.escapeHTML(exports.aliases.occupants) + "") + - (lotOccupancyPrints.length > 0 - ? 'Print' - : "") + + 'Print' + "" + "" + '
' + diff --git a/public-typescript/lotOccupancySearch.ts b/public-typescript/lotOccupancySearch.ts index 0fbaebcd..356cc8df 100644 --- a/public-typescript/lotOccupancySearch.ts +++ b/public-typescript/lotOccupancySearch.ts @@ -10,8 +10,6 @@ declare const cityssm: cityssmGlobal; (() => { const los = exports.los as globalTypes.LOS; - const lotOccupancyPrints: string[] = exports.lotOccupancyPrints; - const searchFilterFormElement = document.querySelector( "#form--searchFilters" ) as HTMLFormElement; @@ -145,19 +143,19 @@ declare const cityssm: cityssmGlobal; : '(No End Date)') + "") + ("
") + - (lotOccupancyPrints.length > 0 - ? "" + "" : "") + + "" + "" ); } @@ -171,9 +169,7 @@ declare const cityssm: cityssmGlobal; ("") + "" + ("") + - (lotOccupancyPrints.length > 0 - ? '' - : "") + + '' + "" + "
" + occupantsHTML + "" + - '" + + (lotOccupancy.printEJS + ? '' + '' + - "" + - "
" + cityssm.escapeHTML(exports.aliases.occupancyStartDate) + "End Date" + cityssm.escapeHTML(exports.aliases.occupants) + "PrintPrint
" + '
' + diff --git a/public/javascripts/lotOccupancySearch.min.js b/public/javascripts/lotOccupancySearch.min.js index 47020421..6564b9b6 100644 --- a/public/javascripts/lotOccupancySearch.min.js +++ b/public/javascripts/lotOccupancySearch.min.js @@ -1 +1 @@ -"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),(()=>{const t=exports.los,a=exports.lotOccupancyPrints,e=document.querySelector("#form--searchFilters"),s=document.querySelector("#container--searchResults"),c=Number.parseInt(document.querySelector("#searchFilter--limit").value,10),i=document.querySelector("#searchFilter--offset"),o=()=>{const o=Number.parseInt(i.value,10);s.innerHTML='

Loading '+exports.aliases.occupancies+"...
",cityssm.postJSON(t.urlPrefix+"/lotOccupancies/doSearchLotOccupancies",e,e=>{if(0===e.lotOccupancies.length)return void(s.innerHTML='

There are no '+cityssm.escapeHTML(exports.aliases.occupancy.toLowerCase())+" records that meet the search criteria.

");const i=document.createElement("tbody"),r=cityssm.dateToString(new Date);for(const s of e.lotOccupancies){let e="";e=s.occupancyStartDateString<=r&&(""===s.occupancyEndDateString||s.occupancyEndDateString>=r)?'':s.occupancyStartDateString>r?'':'';let c="";for(const t of s.lotOccupancyOccupants)c+=' '+cityssm.escapeHTML(t.occupantName||"")+"
";i.insertAdjacentHTML("beforeend",'
"+(a.length>0?'':"")+"")}s.innerHTML='
'+e+''+cityssm.escapeHTML(s.occupancyType)+""+(s.lotName?''+cityssm.escapeHTML(s.lotName)+"":'(No '+cityssm.escapeHTML(exports.aliases.lot)+")")+'
'+cityssm.escapeHTML(s.mapName||"")+"
"+s.occupancyStartDateString+""+(s.occupancyEndDate?s.occupancyEndDateString:'(No End Date)')+""+c+"
"+(a.length>0?'':"")+'
'+cityssm.escapeHTML(exports.aliases.occupancy)+" Type"+cityssm.escapeHTML(exports.aliases.lot)+""+cityssm.escapeHTML(exports.aliases.occupancyStartDate)+"End Date"+cityssm.escapeHTML(exports.aliases.occupants)+"Print
Displaying '+(o+1).toString()+" to "+Math.min(e.count,c+o)+" of "+e.count+'
'+(o>0?'
':"")+(c+o
':"")+"
",s.querySelector("table").append(i),o>0&&s.querySelector("button[data-page='previous']").addEventListener("click",l),c+o{i.value="0",o()},l=()=>{i.value=Math.max(Number.parseInt(i.value,10)-c,0).toString(),o()},n=()=>{i.value=(Number.parseInt(i.value,10)+c).toString(),o()},p=e.querySelectorAll("input, select");for(const t of p)t.addEventListener("change",r);e.addEventListener("submit",t=>{t.preventDefault(),r()}),o()})(); \ No newline at end of file +"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),(()=>{const t=exports.los,a=document.querySelector("#form--searchFilters"),e=document.querySelector("#container--searchResults"),s=Number.parseInt(document.querySelector("#searchFilter--limit").value,10),c=document.querySelector("#searchFilter--offset"),i=()=>{const i=Number.parseInt(c.value,10);e.innerHTML='

Loading '+exports.aliases.occupancies+"...
",cityssm.postJSON(t.urlPrefix+"/lotOccupancies/doSearchLotOccupancies",a,a=>{if(0===a.lotOccupancies.length)return void(e.innerHTML='

There are no '+cityssm.escapeHTML(exports.aliases.occupancy.toLowerCase())+" records that meet the search criteria.

");const c=document.createElement("tbody"),r=cityssm.dateToString(new Date);for(const e of a.lotOccupancies){let a="";a=e.occupancyStartDateString<=r&&(""===e.occupancyEndDateString||e.occupancyEndDateString>=r)?'':e.occupancyStartDateString>r?'':'';let s="";for(const t of e.lotOccupancyOccupants)s+=' '+cityssm.escapeHTML(t.occupantName||"")+"
";c.insertAdjacentHTML("beforeend",'
")}e.innerHTML='
'+a+''+cityssm.escapeHTML(e.occupancyType)+""+(e.lotName?''+cityssm.escapeHTML(e.lotName)+"":'(No '+cityssm.escapeHTML(exports.aliases.lot)+")")+'
'+cityssm.escapeHTML(e.mapName||"")+"
"+e.occupancyStartDateString+""+(e.occupancyEndDate?e.occupancyEndDateString:'(No End Date)')+""+s+""+(e.printEJS?'':"")+"
'+cityssm.escapeHTML(exports.aliases.occupancy)+" Type"+cityssm.escapeHTML(exports.aliases.lot)+""+cityssm.escapeHTML(exports.aliases.occupancyStartDate)+"End Date"+cityssm.escapeHTML(exports.aliases.occupants)+'Print
Displaying '+(i+1).toString()+" to "+Math.min(a.count,s+i)+" of "+a.count+'
'+(i>0?'
':"")+(s+i
':"")+"
",e.querySelector("table").append(c),i>0&&e.querySelector("button[data-page='previous']").addEventListener("click",o),s+i{c.value="0",i()},o=()=>{c.value=Math.max(Number.parseInt(c.value,10)-s,0).toString(),i()},n=()=>{c.value=(Number.parseInt(c.value,10)+s).toString(),i()},l=a.querySelectorAll("input, select");for(const t of l)t.addEventListener("change",r);a.addEventListener("submit",t=>{t.preventDefault(),r()}),i()})(); \ No newline at end of file diff --git a/types/recordTypes.d.ts b/types/recordTypes.d.ts index b5dc3d25..9b10758c 100644 --- a/types/recordTypes.d.ts +++ b/types/recordTypes.d.ts @@ -80,6 +80,7 @@ export interface OccupancyType extends Record { occupancyType: string; orderNumber?: number; occupancyTypeFields?: OccupancyTypeField[]; + occupancyTypePrints?: string[]; } export interface OccupancyTypeField { occupancyTypeFieldId?: number; @@ -178,6 +179,7 @@ export interface LotOccupancy extends Record { lotOccupancyId?: number; occupancyTypeId?: number; occupancyType?: string; + printEJS?: string; lotId?: number; lotTypeId?: number; lotType?: string; diff --git a/types/recordTypes.ts b/types/recordTypes.ts index 074b64e5..a8156bdf 100644 --- a/types/recordTypes.ts +++ b/types/recordTypes.ts @@ -108,6 +108,7 @@ export interface OccupancyType extends Record { occupancyType: string; orderNumber?: number; occupancyTypeFields?: OccupancyTypeField[]; + occupancyTypePrints?: string[]; } export interface OccupancyTypeField { @@ -236,6 +237,7 @@ export interface LotOccupancy extends Record { occupancyTypeId?: number; occupancyType?: string; + printEJS?: string; lotId?: number; lotTypeId?: number; diff --git a/views/lotOccupancy-edit.ejs b/views/lotOccupancy-edit.ejs index 3f13117d..b0fd9d48 100644 --- a/views/lotOccupancy-edit.ejs +++ b/views/lotOccupancy-edit.ejs @@ -46,10 +46,10 @@ - <% if (configFunctions.getProperty("settings.lotOccupancy.prints").length > 0) { %> + <% if (occupancyTypePrints.length > 0) { %>
- <% if (configFunctions.getProperty("settings.lotOccupancy.prints").length === 1) { %> + <% if (occupancyTypePrints.length === 1) { %> /?lotOccupancyId=<%= lotOccupancy.lotOccupancyId %>" target="_blank"> Print @@ -65,7 +65,7 @@
- <% if (configFunctions.getProperty("settings.lotOccupancy.prints").length > 0) { %> + <% if (occupancyTypePrints.length > 0) { %>