next and previous lot buttons
parent
a80b7ec45b
commit
b9ae1e399c
|
|
@ -0,0 +1,3 @@
|
||||||
|
import type { RequestHandler } from "express";
|
||||||
|
export declare const handler: RequestHandler;
|
||||||
|
export default handler;
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
import * as configFunctions from "../../helpers/functions.config.js";
|
||||||
|
import { getNextLotId } from "../../helpers/lotOccupancyDB/getNextLotId.js";
|
||||||
|
export const handler = (request, response) => {
|
||||||
|
const lotId = request.params.lotId;
|
||||||
|
const nextLotId = getNextLotId(lotId);
|
||||||
|
if (!nextLotId) {
|
||||||
|
return response.redirect(configFunctions.getProperty("reverseProxy.urlPrefix") + "/lots/?error=noNextLotIdFound");
|
||||||
|
}
|
||||||
|
return response.redirect(configFunctions.getProperty("reverseProxy.urlPrefix") + "/lots/" + nextLotId);
|
||||||
|
};
|
||||||
|
export default handler;
|
||||||
|
|
@ -0,0 +1,26 @@
|
||||||
|
import type {
|
||||||
|
RequestHandler
|
||||||
|
} from "express";
|
||||||
|
|
||||||
|
import * as configFunctions from "../../helpers/functions.config.js";
|
||||||
|
|
||||||
|
import {
|
||||||
|
getNextLotId
|
||||||
|
} from "../../helpers/lotOccupancyDB/getNextLotId.js";
|
||||||
|
|
||||||
|
|
||||||
|
export const handler: RequestHandler = (request, response) => {
|
||||||
|
|
||||||
|
const lotId = request.params.lotId;
|
||||||
|
|
||||||
|
const nextLotId = getNextLotId(lotId);
|
||||||
|
|
||||||
|
if (!nextLotId) {
|
||||||
|
return response.redirect(configFunctions.getProperty("reverseProxy.urlPrefix") + "/lots/?error=noNextLotIdFound");
|
||||||
|
}
|
||||||
|
|
||||||
|
return response.redirect(configFunctions.getProperty("reverseProxy.urlPrefix") + "/lots/" + nextLotId);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
export default handler;
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
import type { RequestHandler } from "express";
|
||||||
|
export declare const handler: RequestHandler;
|
||||||
|
export default handler;
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
import * as configFunctions from "../../helpers/functions.config.js";
|
||||||
|
import { getPreviousLotId } from "../../helpers/lotOccupancyDB/getPreviousLotId.js";
|
||||||
|
export const handler = (request, response) => {
|
||||||
|
const lotId = request.params.lotId;
|
||||||
|
const previousLotId = getPreviousLotId(lotId);
|
||||||
|
if (!previousLotId) {
|
||||||
|
return response.redirect(configFunctions.getProperty("reverseProxy.urlPrefix") + "/lots/?error=noPreviousLotIdFound");
|
||||||
|
}
|
||||||
|
return response.redirect(configFunctions.getProperty("reverseProxy.urlPrefix") + "/lots/" + previousLotId);
|
||||||
|
};
|
||||||
|
export default handler;
|
||||||
|
|
@ -0,0 +1,26 @@
|
||||||
|
import type {
|
||||||
|
RequestHandler
|
||||||
|
} from "express";
|
||||||
|
|
||||||
|
import * as configFunctions from "../../helpers/functions.config.js";
|
||||||
|
|
||||||
|
import {
|
||||||
|
getPreviousLotId
|
||||||
|
} from "../../helpers/lotOccupancyDB/getPreviousLotId.js";
|
||||||
|
|
||||||
|
|
||||||
|
export const handler: RequestHandler = (request, response) => {
|
||||||
|
|
||||||
|
const lotId = request.params.lotId;
|
||||||
|
|
||||||
|
const previousLotId = getPreviousLotId(lotId);
|
||||||
|
|
||||||
|
if (!previousLotId) {
|
||||||
|
return response.redirect(configFunctions.getProperty("reverseProxy.urlPrefix") + "/lots/?error=noPreviousLotIdFound");
|
||||||
|
}
|
||||||
|
|
||||||
|
return response.redirect(configFunctions.getProperty("reverseProxy.urlPrefix") + "/lots/" + previousLotId);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
export default handler;
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
export declare const getNextLotId: (lotId: number | string) => number;
|
||||||
|
export default getNextLotId;
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
import sqlite from "better-sqlite3";
|
||||||
|
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
||||||
|
export const getNextLotId = (lotId) => {
|
||||||
|
const database = sqlite(databasePath, {
|
||||||
|
readonly: true
|
||||||
|
});
|
||||||
|
const result = database
|
||||||
|
.prepare("select lotId from Lots" +
|
||||||
|
" where recordDelete_timeMillis is null" +
|
||||||
|
" and lotName > (select lotName from Lots where lotId = ?)" +
|
||||||
|
" order by lotName" +
|
||||||
|
" limit 1")
|
||||||
|
.get(lotId);
|
||||||
|
database.close();
|
||||||
|
if (result) {
|
||||||
|
return result.lotId;
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
};
|
||||||
|
export default getNextLotId;
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
import sqlite from "better-sqlite3";
|
||||||
|
|
||||||
|
import {
|
||||||
|
lotOccupancyDB as databasePath
|
||||||
|
} from "../../data/databasePaths.js";
|
||||||
|
|
||||||
|
|
||||||
|
export const getNextLotId = (lotId: number | string): number => {
|
||||||
|
|
||||||
|
const database = sqlite(databasePath, {
|
||||||
|
readonly: true
|
||||||
|
});
|
||||||
|
|
||||||
|
const result: {
|
||||||
|
lotId: number
|
||||||
|
} = database
|
||||||
|
.prepare("select lotId from Lots" +
|
||||||
|
" where recordDelete_timeMillis is null" +
|
||||||
|
" and lotName > (select lotName from Lots where lotId = ?)" +
|
||||||
|
" order by lotName" +
|
||||||
|
" limit 1")
|
||||||
|
.get(lotId);
|
||||||
|
|
||||||
|
database.close();
|
||||||
|
|
||||||
|
if (result) {
|
||||||
|
return result.lotId;
|
||||||
|
}
|
||||||
|
|
||||||
|
return undefined;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
export default getNextLotId;
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
export declare const getPreviousLotId: (lotId: number | string) => number;
|
||||||
|
export default getPreviousLotId;
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
import sqlite from "better-sqlite3";
|
||||||
|
import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
||||||
|
export const getPreviousLotId = (lotId) => {
|
||||||
|
const database = sqlite(databasePath, {
|
||||||
|
readonly: true
|
||||||
|
});
|
||||||
|
const result = database
|
||||||
|
.prepare("select lotId from Lots" +
|
||||||
|
" where recordDelete_timeMillis is null" +
|
||||||
|
" and lotName < (select lotName from Lots where lotId = ?)" +
|
||||||
|
" order by lotName desc" +
|
||||||
|
" limit 1")
|
||||||
|
.get(lotId);
|
||||||
|
database.close();
|
||||||
|
if (result) {
|
||||||
|
return result.lotId;
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
};
|
||||||
|
export default getPreviousLotId;
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
import sqlite from "better-sqlite3";
|
||||||
|
|
||||||
|
import {
|
||||||
|
lotOccupancyDB as databasePath
|
||||||
|
} from "../../data/databasePaths.js";
|
||||||
|
|
||||||
|
|
||||||
|
export const getPreviousLotId = (lotId: number | string): number => {
|
||||||
|
|
||||||
|
const database = sqlite(databasePath, {
|
||||||
|
readonly: true
|
||||||
|
});
|
||||||
|
|
||||||
|
const result: {
|
||||||
|
lotId: number
|
||||||
|
} = database
|
||||||
|
.prepare("select lotId from Lots" +
|
||||||
|
" where recordDelete_timeMillis is null" +
|
||||||
|
" and lotName < (select lotName from Lots where lotId = ?)" +
|
||||||
|
" order by lotName desc" +
|
||||||
|
" limit 1")
|
||||||
|
.get(lotId);
|
||||||
|
|
||||||
|
database.close();
|
||||||
|
|
||||||
|
if (result) {
|
||||||
|
return result.lotId;
|
||||||
|
}
|
||||||
|
|
||||||
|
return undefined;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
export default getPreviousLotId;
|
||||||
|
|
@ -3,6 +3,8 @@ import * as permissionHandlers from "../handlers/permissions.js";
|
||||||
import handler_search from "../handlers/lots-get/search.js";
|
import handler_search from "../handlers/lots-get/search.js";
|
||||||
import handler_doSearchLots from "../handlers/lots-post/doSearchLots.js";
|
import handler_doSearchLots from "../handlers/lots-post/doSearchLots.js";
|
||||||
import handler_view from "../handlers/lots-get/view.js";
|
import handler_view from "../handlers/lots-get/view.js";
|
||||||
|
import handler_next from "../handlers/lots-get/next.js";
|
||||||
|
import handler_previous from "../handlers/lots-get/previous.js";
|
||||||
import handler_new from "../handlers/lots-get/new.js";
|
import handler_new from "../handlers/lots-get/new.js";
|
||||||
import handler_edit from "../handlers/lots-get/edit.js";
|
import handler_edit from "../handlers/lots-get/edit.js";
|
||||||
import handler_doCreateLot from "../handlers/lots-post/doCreateLot.js";
|
import handler_doCreateLot from "../handlers/lots-post/doCreateLot.js";
|
||||||
|
|
@ -15,6 +17,8 @@ router.get("/", handler_search);
|
||||||
router.post("/doSearchLots", handler_doSearchLots);
|
router.post("/doSearchLots", handler_doSearchLots);
|
||||||
router.get("/new", permissionHandlers.updateGetHandler, handler_new);
|
router.get("/new", permissionHandlers.updateGetHandler, handler_new);
|
||||||
router.get("/:lotId", handler_view);
|
router.get("/:lotId", handler_view);
|
||||||
|
router.get("/:lotId/next", handler_next);
|
||||||
|
router.get("/:lotId/previous", handler_previous);
|
||||||
router.get("/:lotId/edit", permissionHandlers.updateGetHandler, handler_edit);
|
router.get("/:lotId/edit", permissionHandlers.updateGetHandler, handler_edit);
|
||||||
router.post("/doCreateLot", permissionHandlers.updatePostHandler, handler_doCreateLot);
|
router.post("/doCreateLot", permissionHandlers.updatePostHandler, handler_doCreateLot);
|
||||||
router.post("/doUpdateLot", permissionHandlers.updatePostHandler, handler_doUpdateLot);
|
router.post("/doUpdateLot", permissionHandlers.updatePostHandler, handler_doUpdateLot);
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,9 @@ import handler_search from "../handlers/lots-get/search.js";
|
||||||
import handler_doSearchLots from "../handlers/lots-post/doSearchLots.js";
|
import handler_doSearchLots from "../handlers/lots-post/doSearchLots.js";
|
||||||
|
|
||||||
import handler_view from "../handlers/lots-get/view.js";
|
import handler_view from "../handlers/lots-get/view.js";
|
||||||
|
import handler_next from "../handlers/lots-get/next.js";
|
||||||
|
import handler_previous from "../handlers/lots-get/previous.js";
|
||||||
|
|
||||||
import handler_new from "../handlers/lots-get/new.js";
|
import handler_new from "../handlers/lots-get/new.js";
|
||||||
import handler_edit from "../handlers/lots-get/edit.js";
|
import handler_edit from "../handlers/lots-get/edit.js";
|
||||||
|
|
||||||
|
|
@ -46,6 +49,14 @@ router.get("/:lotId",
|
||||||
handler_view);
|
handler_view);
|
||||||
|
|
||||||
|
|
||||||
|
router.get("/:lotId/next",
|
||||||
|
handler_next);
|
||||||
|
|
||||||
|
|
||||||
|
router.get("/:lotId/previous",
|
||||||
|
handler_previous);
|
||||||
|
|
||||||
|
|
||||||
router.get("/:lotId/edit",
|
router.get("/:lotId/edit",
|
||||||
permissionHandlers.updateGetHandler,
|
permissionHandlers.updateGetHandler,
|
||||||
handler_edit);
|
handler_edit);
|
||||||
|
|
|
||||||
|
|
@ -19,16 +19,29 @@
|
||||||
<%= lot.lotName %>
|
<%= lot.lotName %>
|
||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
<% if (user.userProperties.canUpdate) { %>
|
|
||||||
<div class="fixed-container is-fixed-bottom-right mx-4 my-4 has-text-right is-hidden-print">
|
<div class="fixed-container is-fixed-bottom-right mx-4 my-4 has-text-right is-hidden-print">
|
||||||
|
|
||||||
|
<a class="button is-circle is-link has-tooltip-left"
|
||||||
|
data-tooltip="Previous <%= configFunctions.getProperty("aliases.lot") %>"
|
||||||
|
href="<%= urlPrefix %>/lots/<%= lot.lotId %>/previous">
|
||||||
|
<i class="fas fa-arrow-left" aria-hidden="true"></i>
|
||||||
|
<span class="sr-only">Previous <%= configFunctions.getProperty("aliases.lot") %></span>
|
||||||
|
</a>
|
||||||
|
<a class="button is-circle is-link has-tooltip-left"
|
||||||
|
data-tooltip="Next <%= configFunctions.getProperty("aliases.lot") %>"
|
||||||
|
href="<%= urlPrefix %>/lots/<%= lot.lotId %>/next">
|
||||||
|
<i class="fas fa-arrow-right" aria-hidden="true"></i>
|
||||||
|
<span class="sr-only">Next <%= configFunctions.getProperty("aliases.lot") %></span>
|
||||||
|
</a>
|
||||||
|
<% if (user.userProperties.canUpdate) { %>
|
||||||
<a class="button is-circle is-primary has-tooltip-left"
|
<a class="button is-circle is-primary has-tooltip-left"
|
||||||
data-tooltip="Update <%= configFunctions.getProperty("aliases.lot") %>"
|
data-tooltip="Update <%= configFunctions.getProperty("aliases.lot") %>"
|
||||||
href="<%= urlPrefix %>/lots/<%= lot.lotId %>/edit">
|
href="<%= urlPrefix %>/lots/<%= lot.lotId %>/edit">
|
||||||
<i class="fas fa-pencil-alt" aria-hidden="true"></i>
|
<i class="fas fa-pencil-alt" aria-hidden="true"></i>
|
||||||
<span class="sr-only">Update <%= configFunctions.getProperty("aliases.lot") %></span>
|
<span class="sr-only">Update <%= configFunctions.getProperty("aliases.lot") %></span>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
|
||||||
<% } %>
|
<% } %>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="columns">
|
<div class="columns">
|
||||||
<div class="column">
|
<div class="column">
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue