quicker reordering of occupancy types and fields
parent
ff4e50185d
commit
3fd54c5120
|
|
@ -1,7 +1,9 @@
|
||||||
import { moveOccupancyTypeDown } from "../../helpers/lotOccupancyDB/moveOccupancyTypeDown.js";
|
import { moveOccupancyTypeDown, moveOccupancyTypeDownToBottom } from "../../helpers/lotOccupancyDB/moveOccupancyTypeDown.js";
|
||||||
import { getAllOccupancyTypeFields, getOccupancyTypes } from "../../helpers/functions.cache.js";
|
import { getAllOccupancyTypeFields, getOccupancyTypes } from "../../helpers/functions.cache.js";
|
||||||
export const handler = async (request, response) => {
|
export const handler = async (request, response) => {
|
||||||
const success = moveOccupancyTypeDown(request.body.occupancyTypeId);
|
const success = request.body.moveToBottom === "1"
|
||||||
|
? moveOccupancyTypeDownToBottom(request.body.occupancyTypeId)
|
||||||
|
: moveOccupancyTypeDown(request.body.occupancyTypeId);
|
||||||
const occupancyTypes = getOccupancyTypes();
|
const occupancyTypes = getOccupancyTypes();
|
||||||
const allOccupancyTypeFields = getAllOccupancyTypeFields();
|
const allOccupancyTypeFields = getAllOccupancyTypeFields();
|
||||||
response.json({
|
response.json({
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,17 @@
|
||||||
import type { RequestHandler } from "express";
|
import type { RequestHandler } from "express";
|
||||||
|
|
||||||
import { moveOccupancyTypeDown } from "../../helpers/lotOccupancyDB/moveOccupancyTypeDown.js";
|
import {
|
||||||
|
moveOccupancyTypeDown,
|
||||||
|
moveOccupancyTypeDownToBottom
|
||||||
|
} from "../../helpers/lotOccupancyDB/moveOccupancyTypeDown.js";
|
||||||
|
|
||||||
import { getAllOccupancyTypeFields, getOccupancyTypes } from "../../helpers/functions.cache.js";
|
import { getAllOccupancyTypeFields, getOccupancyTypes } from "../../helpers/functions.cache.js";
|
||||||
|
|
||||||
export const handler: RequestHandler = async (request, response) => {
|
export const handler: RequestHandler = async (request, response) => {
|
||||||
const success = moveOccupancyTypeDown(request.body.occupancyTypeId);
|
const success =
|
||||||
|
request.body.moveToBottom === "1"
|
||||||
|
? moveOccupancyTypeDownToBottom(request.body.occupancyTypeId)
|
||||||
|
: moveOccupancyTypeDown(request.body.occupancyTypeId);
|
||||||
|
|
||||||
const occupancyTypes = getOccupancyTypes();
|
const occupancyTypes = getOccupancyTypes();
|
||||||
const allOccupancyTypeFields = getAllOccupancyTypeFields();
|
const allOccupancyTypeFields = getAllOccupancyTypeFields();
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
import { moveOccupancyTypeFieldDown } from "../../helpers/lotOccupancyDB/moveOccupancyTypeFieldDown.js";
|
import { moveOccupancyTypeFieldDown, moveOccupancyTypeFieldDownToBottom } from "../../helpers/lotOccupancyDB/moveOccupancyTypeFieldDown.js";
|
||||||
import { getAllOccupancyTypeFields, getOccupancyTypes } from "../../helpers/functions.cache.js";
|
import { getAllOccupancyTypeFields, getOccupancyTypes } from "../../helpers/functions.cache.js";
|
||||||
export const handler = async (request, response) => {
|
export const handler = async (request, response) => {
|
||||||
const success = moveOccupancyTypeFieldDown(request.body.occupancyTypeFieldId);
|
const success = request.body.moveToBottom === "1"
|
||||||
|
? moveOccupancyTypeFieldDownToBottom(request.body.occupancyTypeFieldId)
|
||||||
|
: moveOccupancyTypeFieldDown(request.body.occupancyTypeFieldId);
|
||||||
const occupancyTypes = getOccupancyTypes();
|
const occupancyTypes = getOccupancyTypes();
|
||||||
const allOccupancyTypeFields = getAllOccupancyTypeFields();
|
const allOccupancyTypeFields = getAllOccupancyTypeFields();
|
||||||
response.json({
|
response.json({
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,17 @@
|
||||||
import type { RequestHandler } from "express";
|
import type { RequestHandler } from "express";
|
||||||
|
|
||||||
import { moveOccupancyTypeFieldDown } from "../../helpers/lotOccupancyDB/moveOccupancyTypeFieldDown.js";
|
import {
|
||||||
|
moveOccupancyTypeFieldDown,
|
||||||
|
moveOccupancyTypeFieldDownToBottom
|
||||||
|
} from "../../helpers/lotOccupancyDB/moveOccupancyTypeFieldDown.js";
|
||||||
|
|
||||||
import { getAllOccupancyTypeFields, getOccupancyTypes } from "../../helpers/functions.cache.js";
|
import { getAllOccupancyTypeFields, getOccupancyTypes } from "../../helpers/functions.cache.js";
|
||||||
|
|
||||||
export const handler: RequestHandler = async (request, response) => {
|
export const handler: RequestHandler = async (request, response) => {
|
||||||
const success = moveOccupancyTypeFieldDown(request.body.occupancyTypeFieldId);
|
const success =
|
||||||
|
request.body.moveToBottom === "1"
|
||||||
|
? moveOccupancyTypeFieldDownToBottom(request.body.occupancyTypeFieldId)
|
||||||
|
: moveOccupancyTypeFieldDown(request.body.occupancyTypeFieldId);
|
||||||
|
|
||||||
const occupancyTypes = getOccupancyTypes();
|
const occupancyTypes = getOccupancyTypes();
|
||||||
const allOccupancyTypeFields = getAllOccupancyTypeFields();
|
const allOccupancyTypeFields = getAllOccupancyTypeFields();
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
import { moveOccupancyTypeFieldUp } from "../../helpers/lotOccupancyDB/moveOccupancyTypeFieldUp.js";
|
import { moveOccupancyTypeFieldUp, moveOccupancyTypeFieldUpToTop } from "../../helpers/lotOccupancyDB/moveOccupancyTypeFieldUp.js";
|
||||||
import { getAllOccupancyTypeFields, getOccupancyTypes } from "../../helpers/functions.cache.js";
|
import { getAllOccupancyTypeFields, getOccupancyTypes } from "../../helpers/functions.cache.js";
|
||||||
export const handler = async (request, response) => {
|
export const handler = async (request, response) => {
|
||||||
const success = moveOccupancyTypeFieldUp(request.body.occupancyTypeFieldId);
|
const success = request.body.moveToTop === "1"
|
||||||
|
? moveOccupancyTypeFieldUpToTop(request.body.occupancyTypeFieldId)
|
||||||
|
: moveOccupancyTypeFieldUp(request.body.occupancyTypeFieldId);
|
||||||
const occupancyTypes = getOccupancyTypes();
|
const occupancyTypes = getOccupancyTypes();
|
||||||
const allOccupancyTypeFields = getAllOccupancyTypeFields();
|
const allOccupancyTypeFields = getAllOccupancyTypeFields();
|
||||||
response.json({
|
response.json({
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,17 @@
|
||||||
import type { RequestHandler } from "express";
|
import type { RequestHandler } from "express";
|
||||||
|
|
||||||
import { moveOccupancyTypeFieldUp } from "../../helpers/lotOccupancyDB/moveOccupancyTypeFieldUp.js";
|
import {
|
||||||
|
moveOccupancyTypeFieldUp,
|
||||||
|
moveOccupancyTypeFieldUpToTop
|
||||||
|
} from "../../helpers/lotOccupancyDB/moveOccupancyTypeFieldUp.js";
|
||||||
|
|
||||||
import { getAllOccupancyTypeFields, getOccupancyTypes } from "../../helpers/functions.cache.js";
|
import { getAllOccupancyTypeFields, getOccupancyTypes } from "../../helpers/functions.cache.js";
|
||||||
|
|
||||||
export const handler: RequestHandler = async (request, response) => {
|
export const handler: RequestHandler = async (request, response) => {
|
||||||
const success = moveOccupancyTypeFieldUp(request.body.occupancyTypeFieldId);
|
const success =
|
||||||
|
request.body.moveToTop === "1"
|
||||||
|
? moveOccupancyTypeFieldUpToTop(request.body.occupancyTypeFieldId)
|
||||||
|
: moveOccupancyTypeFieldUp(request.body.occupancyTypeFieldId);
|
||||||
|
|
||||||
const occupancyTypes = getOccupancyTypes();
|
const occupancyTypes = getOccupancyTypes();
|
||||||
const allOccupancyTypeFields = getAllOccupancyTypeFields();
|
const allOccupancyTypeFields = getAllOccupancyTypeFields();
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
import { moveOccupancyTypeUp } from "../../helpers/lotOccupancyDB/moveOccupancyTypeUp.js";
|
import { moveOccupancyTypeUp, moveOccupancyTypeUpToTop } from "../../helpers/lotOccupancyDB/moveOccupancyTypeUp.js";
|
||||||
import { getAllOccupancyTypeFields, getOccupancyTypes } from "../../helpers/functions.cache.js";
|
import { getAllOccupancyTypeFields, getOccupancyTypes } from "../../helpers/functions.cache.js";
|
||||||
export const handler = async (request, response) => {
|
export const handler = async (request, response) => {
|
||||||
const success = moveOccupancyTypeUp(request.body.occupancyTypeId);
|
const success = request.body.moveToTop === "1"
|
||||||
|
? moveOccupancyTypeUpToTop(request.body.occupancyTypeId)
|
||||||
|
: moveOccupancyTypeUp(request.body.occupancyTypeId);
|
||||||
const occupancyTypes = getOccupancyTypes();
|
const occupancyTypes = getOccupancyTypes();
|
||||||
const allOccupancyTypeFields = getAllOccupancyTypeFields();
|
const allOccupancyTypeFields = getAllOccupancyTypeFields();
|
||||||
response.json({
|
response.json({
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,17 @@
|
||||||
import type { RequestHandler } from "express";
|
import type { RequestHandler } from "express";
|
||||||
|
|
||||||
import { moveOccupancyTypeUp } from "../../helpers/lotOccupancyDB/moveOccupancyTypeUp.js";
|
import {
|
||||||
|
moveOccupancyTypeUp,
|
||||||
|
moveOccupancyTypeUpToTop
|
||||||
|
} from "../../helpers/lotOccupancyDB/moveOccupancyTypeUp.js";
|
||||||
|
|
||||||
import { getAllOccupancyTypeFields, getOccupancyTypes } from "../../helpers/functions.cache.js";
|
import { getAllOccupancyTypeFields, getOccupancyTypes } from "../../helpers/functions.cache.js";
|
||||||
|
|
||||||
export const handler: RequestHandler = async (request, response) => {
|
export const handler: RequestHandler = async (request, response) => {
|
||||||
const success = moveOccupancyTypeUp(request.body.occupancyTypeId);
|
const success =
|
||||||
|
request.body.moveToTop === "1"
|
||||||
|
? moveOccupancyTypeUpToTop(request.body.occupancyTypeId)
|
||||||
|
: moveOccupancyTypeUp(request.body.occupancyTypeId);
|
||||||
|
|
||||||
const occupancyTypes = getOccupancyTypes();
|
const occupancyTypes = getOccupancyTypes();
|
||||||
const allOccupancyTypeFields = getAllOccupancyTypeFields();
|
const allOccupancyTypeFields = getAllOccupancyTypeFields();
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,3 @@
|
||||||
export declare const moveOccupancyTypeDown: (occupancyTypeId: number | string) => boolean;
|
export declare const moveOccupancyTypeDown: (occupancyTypeId: number | string) => boolean;
|
||||||
|
export declare const moveOccupancyTypeDownToBottom: (occupancyTypeId: number | string) => boolean;
|
||||||
export default moveOccupancyTypeDown;
|
export default moveOccupancyTypeDown;
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,7 @@ import { clearOccupancyTypesCache } from "../functions.cache.js";
|
||||||
export const moveOccupancyTypeDown = (occupancyTypeId) => {
|
export const moveOccupancyTypeDown = (occupancyTypeId) => {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
const currentOrderNumber = database
|
const currentOrderNumber = database
|
||||||
.prepare("select orderNumber" +
|
.prepare("select orderNumber from OccupancyTypes where occupancyTypeId = ?")
|
||||||
" from OccupancyTypes" +
|
|
||||||
" where occupancyTypeId = ?")
|
|
||||||
.get(occupancyTypeId).orderNumber;
|
.get(occupancyTypeId).orderNumber;
|
||||||
database
|
database
|
||||||
.prepare("update OccupancyTypes" +
|
.prepare("update OccupancyTypes" +
|
||||||
|
|
@ -15,12 +13,35 @@ export const moveOccupancyTypeDown = (occupancyTypeId) => {
|
||||||
" and orderNumber = ? + 1")
|
" and orderNumber = ? + 1")
|
||||||
.run(currentOrderNumber);
|
.run(currentOrderNumber);
|
||||||
const result = database
|
const result = database
|
||||||
.prepare("update OccupancyTypes" +
|
.prepare("update OccupancyTypes set orderNumber = ? + 1 where occupancyTypeId = ?")
|
||||||
" set orderNumber = ? + 1" +
|
|
||||||
" where occupancyTypeId = ?")
|
|
||||||
.run(currentOrderNumber, occupancyTypeId);
|
.run(currentOrderNumber, occupancyTypeId);
|
||||||
database.close();
|
database.close();
|
||||||
clearOccupancyTypesCache();
|
clearOccupancyTypesCache();
|
||||||
return result.changes > 0;
|
return result.changes > 0;
|
||||||
};
|
};
|
||||||
|
export const moveOccupancyTypeDownToBottom = (occupancyTypeId) => {
|
||||||
|
const database = sqlite(databasePath);
|
||||||
|
const currentOrderNumber = database
|
||||||
|
.prepare("select orderNumber from OccupancyTypes where occupancyTypeId = ?")
|
||||||
|
.get(occupancyTypeId).orderNumber;
|
||||||
|
const maxOrderNumber = database
|
||||||
|
.prepare("select max(orderNumber) as maxOrderNumber" +
|
||||||
|
" from OccupancyTypes" +
|
||||||
|
" where recordDelete_timeMillis is null")
|
||||||
|
.get().maxOrderNumber;
|
||||||
|
if (currentOrderNumber !== maxOrderNumber) {
|
||||||
|
database
|
||||||
|
.prepare("update OccupancyTypes set orderNumber = ? + 1 where occupancyTypeId = ?")
|
||||||
|
.run(maxOrderNumber, occupancyTypeId);
|
||||||
|
database
|
||||||
|
.prepare("update OccupancyTypes" +
|
||||||
|
" set orderNumber = orderNumber - 1" +
|
||||||
|
" where recordDelete_timeMillis is null" +
|
||||||
|
" and orderNumber > ?")
|
||||||
|
.run(currentOrderNumber);
|
||||||
|
}
|
||||||
|
database.close();
|
||||||
|
clearOccupancyTypesCache();
|
||||||
|
return true;
|
||||||
|
};
|
||||||
export default moveOccupancyTypeDown;
|
export default moveOccupancyTypeDown;
|
||||||
|
|
|
||||||
|
|
@ -4,17 +4,11 @@ import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
||||||
|
|
||||||
import { clearOccupancyTypesCache } from "../functions.cache.js";
|
import { clearOccupancyTypesCache } from "../functions.cache.js";
|
||||||
|
|
||||||
export const moveOccupancyTypeDown = (
|
export const moveOccupancyTypeDown = (occupancyTypeId: number | string): boolean => {
|
||||||
occupancyTypeId: number | string
|
|
||||||
): boolean => {
|
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
|
|
||||||
const currentOrderNumber: number = database
|
const currentOrderNumber: number = database
|
||||||
.prepare(
|
.prepare("select orderNumber from OccupancyTypes where occupancyTypeId = ?")
|
||||||
"select orderNumber" +
|
|
||||||
" from OccupancyTypes" +
|
|
||||||
" where occupancyTypeId = ?"
|
|
||||||
)
|
|
||||||
.get(occupancyTypeId).orderNumber;
|
.get(occupancyTypeId).orderNumber;
|
||||||
|
|
||||||
database
|
database
|
||||||
|
|
@ -27,11 +21,7 @@ export const moveOccupancyTypeDown = (
|
||||||
.run(currentOrderNumber);
|
.run(currentOrderNumber);
|
||||||
|
|
||||||
const result = database
|
const result = database
|
||||||
.prepare(
|
.prepare("update OccupancyTypes set orderNumber = ? + 1 where occupancyTypeId = ?")
|
||||||
"update OccupancyTypes" +
|
|
||||||
" set orderNumber = ? + 1" +
|
|
||||||
" where occupancyTypeId = ?"
|
|
||||||
)
|
|
||||||
.run(currentOrderNumber, occupancyTypeId);
|
.run(currentOrderNumber, occupancyTypeId);
|
||||||
|
|
||||||
database.close();
|
database.close();
|
||||||
|
|
@ -41,4 +31,41 @@ export const moveOccupancyTypeDown = (
|
||||||
return result.changes > 0;
|
return result.changes > 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const moveOccupancyTypeDownToBottom = (occupancyTypeId: number | string): boolean => {
|
||||||
|
const database = sqlite(databasePath);
|
||||||
|
|
||||||
|
const currentOrderNumber: number = database
|
||||||
|
.prepare("select orderNumber from OccupancyTypes where occupancyTypeId = ?")
|
||||||
|
.get(occupancyTypeId).orderNumber;
|
||||||
|
|
||||||
|
const maxOrderNumber: number = database
|
||||||
|
.prepare(
|
||||||
|
"select max(orderNumber) as maxOrderNumber" +
|
||||||
|
" from OccupancyTypes" +
|
||||||
|
" where recordDelete_timeMillis is null"
|
||||||
|
)
|
||||||
|
.get().maxOrderNumber;
|
||||||
|
|
||||||
|
if (currentOrderNumber !== maxOrderNumber) {
|
||||||
|
database
|
||||||
|
.prepare("update OccupancyTypes set orderNumber = ? + 1 where occupancyTypeId = ?")
|
||||||
|
.run(maxOrderNumber, occupancyTypeId);
|
||||||
|
|
||||||
|
database
|
||||||
|
.prepare(
|
||||||
|
"update OccupancyTypes" +
|
||||||
|
" set orderNumber = orderNumber - 1" +
|
||||||
|
" where recordDelete_timeMillis is null" +
|
||||||
|
" and orderNumber > ?"
|
||||||
|
)
|
||||||
|
.run(currentOrderNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
database.close();
|
||||||
|
|
||||||
|
clearOccupancyTypesCache();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
export default moveOccupancyTypeDown;
|
export default moveOccupancyTypeDown;
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,3 @@
|
||||||
export declare const moveOccupancyTypeFieldDown: (occupancyTypeFieldId: number | string) => boolean;
|
export declare const moveOccupancyTypeFieldDown: (occupancyTypeFieldId: number | string) => boolean;
|
||||||
|
export declare const moveOccupancyTypeFieldDownToBottom: (occupancyTypeFieldId: number | string) => boolean;
|
||||||
export default moveOccupancyTypeFieldDown;
|
export default moveOccupancyTypeFieldDown;
|
||||||
|
|
|
||||||
|
|
@ -26,4 +26,42 @@ export const moveOccupancyTypeFieldDown = (occupancyTypeFieldId) => {
|
||||||
clearOccupancyTypesCache();
|
clearOccupancyTypesCache();
|
||||||
return result.changes > 0;
|
return result.changes > 0;
|
||||||
};
|
};
|
||||||
|
export const moveOccupancyTypeFieldDownToBottom = (occupancyTypeFieldId) => {
|
||||||
|
const database = sqlite(databasePath);
|
||||||
|
const currentField = database
|
||||||
|
.prepare("select occupancyTypeId, orderNumber" +
|
||||||
|
" from OccupancyTypeFields" +
|
||||||
|
" where occupancyTypeFieldId = ?")
|
||||||
|
.get(occupancyTypeFieldId);
|
||||||
|
const occupancyTypeParameters = [];
|
||||||
|
if (currentField.occupancyTypeId) {
|
||||||
|
occupancyTypeParameters.push(currentField.occupancyTypeId);
|
||||||
|
}
|
||||||
|
const maxOrderNumber = database
|
||||||
|
.prepare("select max(orderNumber) as maxOrderNumber" +
|
||||||
|
" from OccupancyTypeFields" +
|
||||||
|
" where recordDelete_timeMillis is null" +
|
||||||
|
(currentField.occupancyTypeId
|
||||||
|
? " and occupancyTypeId = ?"
|
||||||
|
: " and occupancyTypeId is null"))
|
||||||
|
.get(occupancyTypeParameters).maxOrderNumber;
|
||||||
|
if (currentField.orderNumber !== maxOrderNumber) {
|
||||||
|
database
|
||||||
|
.prepare("update OccupancyTypeFields set orderNumber = ? + 1 where occupancyTypeFieldId = ?")
|
||||||
|
.run(maxOrderNumber, occupancyTypeFieldId);
|
||||||
|
occupancyTypeParameters.push(currentField.orderNumber);
|
||||||
|
database
|
||||||
|
.prepare("update OccupancyTypeFields" +
|
||||||
|
" set orderNumber = orderNumber - 1" +
|
||||||
|
" where recordDelete_timeMillis is null" +
|
||||||
|
(currentField.occupancyTypeId
|
||||||
|
? " and occupancyTypeId = ?"
|
||||||
|
: " and occupancyTypeId is null") +
|
||||||
|
" and orderNumber > ?")
|
||||||
|
.run(occupancyTypeParameters);
|
||||||
|
}
|
||||||
|
database.close();
|
||||||
|
clearOccupancyTypesCache();
|
||||||
|
return true;
|
||||||
|
};
|
||||||
export default moveOccupancyTypeFieldDown;
|
export default moveOccupancyTypeFieldDown;
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,7 @@ import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
||||||
|
|
||||||
import { clearOccupancyTypesCache } from "../functions.cache.js";
|
import { clearOccupancyTypesCache } from "../functions.cache.js";
|
||||||
|
|
||||||
export const moveOccupancyTypeFieldDown = (
|
export const moveOccupancyTypeFieldDown = (occupancyTypeFieldId: number | string): boolean => {
|
||||||
occupancyTypeFieldId: number | string
|
|
||||||
): boolean => {
|
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
|
|
||||||
const currentField: { occupancyTypeId?: number; orderNumber: number } = database
|
const currentField: { occupancyTypeId?: number; orderNumber: number } = database
|
||||||
|
|
@ -44,4 +42,63 @@ export const moveOccupancyTypeFieldDown = (
|
||||||
return result.changes > 0;
|
return result.changes > 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const moveOccupancyTypeFieldDownToBottom = (
|
||||||
|
occupancyTypeFieldId: number | string
|
||||||
|
): boolean => {
|
||||||
|
const database = sqlite(databasePath);
|
||||||
|
|
||||||
|
const currentField: { occupancyTypeId?: number; orderNumber: number } = database
|
||||||
|
.prepare(
|
||||||
|
"select occupancyTypeId, orderNumber" +
|
||||||
|
" from OccupancyTypeFields" +
|
||||||
|
" where occupancyTypeFieldId = ?"
|
||||||
|
)
|
||||||
|
.get(occupancyTypeFieldId);
|
||||||
|
|
||||||
|
const occupancyTypeParameters = [];
|
||||||
|
|
||||||
|
if (currentField.occupancyTypeId) {
|
||||||
|
occupancyTypeParameters.push(currentField.occupancyTypeId);
|
||||||
|
}
|
||||||
|
|
||||||
|
const maxOrderNumber: number = database
|
||||||
|
.prepare(
|
||||||
|
"select max(orderNumber) as maxOrderNumber" +
|
||||||
|
" from OccupancyTypeFields" +
|
||||||
|
" where recordDelete_timeMillis is null" +
|
||||||
|
(currentField.occupancyTypeId
|
||||||
|
? " and occupancyTypeId = ?"
|
||||||
|
: " and occupancyTypeId is null")
|
||||||
|
)
|
||||||
|
.get(occupancyTypeParameters).maxOrderNumber;
|
||||||
|
|
||||||
|
if (currentField.orderNumber !== maxOrderNumber) {
|
||||||
|
database
|
||||||
|
.prepare(
|
||||||
|
"update OccupancyTypeFields set orderNumber = ? + 1 where occupancyTypeFieldId = ?"
|
||||||
|
)
|
||||||
|
.run(maxOrderNumber, occupancyTypeFieldId);
|
||||||
|
|
||||||
|
occupancyTypeParameters.push(currentField.orderNumber);
|
||||||
|
|
||||||
|
database
|
||||||
|
.prepare(
|
||||||
|
"update OccupancyTypeFields" +
|
||||||
|
" set orderNumber = orderNumber - 1" +
|
||||||
|
" where recordDelete_timeMillis is null" +
|
||||||
|
(currentField.occupancyTypeId
|
||||||
|
? " and occupancyTypeId = ?"
|
||||||
|
: " and occupancyTypeId is null") +
|
||||||
|
" and orderNumber > ?"
|
||||||
|
)
|
||||||
|
.run(occupancyTypeParameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
database.close();
|
||||||
|
|
||||||
|
clearOccupancyTypesCache();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
export default moveOccupancyTypeFieldDown;
|
export default moveOccupancyTypeFieldDown;
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,3 @@
|
||||||
export declare const moveOccupancyTypeFieldUp: (occupancyTypeFieldId: number | string) => boolean;
|
export declare const moveOccupancyTypeFieldUp: (occupancyTypeFieldId: number | string) => boolean;
|
||||||
|
export declare const moveOccupancyTypeFieldUpToTop: (occupancyTypeFieldId: number | string) => boolean;
|
||||||
export default moveOccupancyTypeFieldUp;
|
export default moveOccupancyTypeFieldUp;
|
||||||
|
|
|
||||||
|
|
@ -30,4 +30,35 @@ export const moveOccupancyTypeFieldUp = (occupancyTypeFieldId) => {
|
||||||
clearOccupancyTypesCache();
|
clearOccupancyTypesCache();
|
||||||
return result.changes > 0;
|
return result.changes > 0;
|
||||||
};
|
};
|
||||||
|
export const moveOccupancyTypeFieldUpToTop = (occupancyTypeFieldId) => {
|
||||||
|
const database = sqlite(databasePath);
|
||||||
|
const currentField = database
|
||||||
|
.prepare("select occupancyTypeId, orderNumber" +
|
||||||
|
" from OccupancyTypeFields" +
|
||||||
|
" where occupancyTypeFieldId = ?")
|
||||||
|
.get(occupancyTypeFieldId);
|
||||||
|
if (currentField.orderNumber > 0) {
|
||||||
|
database
|
||||||
|
.prepare("update OccupancyTypeFields set orderNumber = -1" +
|
||||||
|
" where occupancyTypeFieldId = ?")
|
||||||
|
.run(occupancyTypeFieldId);
|
||||||
|
const occupancyTypeParameters = [];
|
||||||
|
if (currentField.occupancyTypeId) {
|
||||||
|
occupancyTypeParameters.push(currentField.occupancyTypeId);
|
||||||
|
}
|
||||||
|
occupancyTypeParameters.push(currentField.orderNumber);
|
||||||
|
database
|
||||||
|
.prepare("update OccupancyTypeFields" +
|
||||||
|
" set orderNumber = orderNumber + 1" +
|
||||||
|
" where recordDelete_timeMillis is null" +
|
||||||
|
(currentField.occupancyTypeId
|
||||||
|
? " and occupancyTypeId = ?"
|
||||||
|
: " and occupancyTypeId is null") +
|
||||||
|
" and orderNumber < ?")
|
||||||
|
.run(occupancyTypeParameters);
|
||||||
|
}
|
||||||
|
database.close();
|
||||||
|
clearOccupancyTypesCache();
|
||||||
|
return true;
|
||||||
|
};
|
||||||
export default moveOccupancyTypeFieldUp;
|
export default moveOccupancyTypeFieldUp;
|
||||||
|
|
|
||||||
|
|
@ -47,4 +47,51 @@ export const moveOccupancyTypeFieldUp = (occupancyTypeFieldId: number | string):
|
||||||
return result.changes > 0;
|
return result.changes > 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const moveOccupancyTypeFieldUpToTop = (occupancyTypeFieldId: number | string): boolean => {
|
||||||
|
const database = sqlite(databasePath);
|
||||||
|
|
||||||
|
const currentField: { occupancyTypeId?: number; orderNumber: number } = database
|
||||||
|
.prepare(
|
||||||
|
"select occupancyTypeId, orderNumber" +
|
||||||
|
" from OccupancyTypeFields" +
|
||||||
|
" where occupancyTypeFieldId = ?"
|
||||||
|
)
|
||||||
|
.get(occupancyTypeFieldId);
|
||||||
|
|
||||||
|
if (currentField.orderNumber > 0) {
|
||||||
|
database
|
||||||
|
.prepare(
|
||||||
|
"update OccupancyTypeFields set orderNumber = -1" +
|
||||||
|
" where occupancyTypeFieldId = ?"
|
||||||
|
)
|
||||||
|
.run(occupancyTypeFieldId);
|
||||||
|
|
||||||
|
const occupancyTypeParameters = [];
|
||||||
|
|
||||||
|
if (currentField.occupancyTypeId) {
|
||||||
|
occupancyTypeParameters.push(currentField.occupancyTypeId);
|
||||||
|
}
|
||||||
|
|
||||||
|
occupancyTypeParameters.push(currentField.orderNumber);
|
||||||
|
|
||||||
|
database
|
||||||
|
.prepare(
|
||||||
|
"update OccupancyTypeFields" +
|
||||||
|
" set orderNumber = orderNumber + 1" +
|
||||||
|
" where recordDelete_timeMillis is null" +
|
||||||
|
(currentField.occupancyTypeId
|
||||||
|
? " and occupancyTypeId = ?"
|
||||||
|
: " and occupancyTypeId is null") +
|
||||||
|
" and orderNumber < ?"
|
||||||
|
)
|
||||||
|
.run(occupancyTypeParameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
database.close();
|
||||||
|
|
||||||
|
clearOccupancyTypesCache();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
export default moveOccupancyTypeFieldUp;
|
export default moveOccupancyTypeFieldUp;
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,3 @@
|
||||||
export declare const moveOccupancyTypeUp: (occupancyTypeId: number | string) => boolean;
|
export declare const moveOccupancyTypeUp: (occupancyTypeId: number | string) => boolean;
|
||||||
|
export declare const moveOccupancyTypeUpToTop: (occupancyTypeId: number | string) => boolean;
|
||||||
export default moveOccupancyTypeUp;
|
export default moveOccupancyTypeUp;
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,7 @@ import { clearOccupancyTypesCache } from "../functions.cache.js";
|
||||||
export const moveOccupancyTypeUp = (occupancyTypeId) => {
|
export const moveOccupancyTypeUp = (occupancyTypeId) => {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
const currentOrderNumber = database
|
const currentOrderNumber = database
|
||||||
.prepare("select orderNumber" +
|
.prepare("select orderNumber from OccupancyTypes where occupancyTypeId = ?")
|
||||||
" from OccupancyTypes" +
|
|
||||||
" where occupancyTypeId = ?")
|
|
||||||
.get(occupancyTypeId).orderNumber;
|
.get(occupancyTypeId).orderNumber;
|
||||||
if (currentOrderNumber <= 0) {
|
if (currentOrderNumber <= 0) {
|
||||||
database.close();
|
database.close();
|
||||||
|
|
@ -19,12 +17,30 @@ export const moveOccupancyTypeUp = (occupancyTypeId) => {
|
||||||
" and orderNumber = ? - 1")
|
" and orderNumber = ? - 1")
|
||||||
.run(currentOrderNumber);
|
.run(currentOrderNumber);
|
||||||
const result = database
|
const result = database
|
||||||
.prepare("update OccupancyTypes" +
|
.prepare("update OccupancyTypes set orderNumber = ? - 1 where occupancyTypeId = ?")
|
||||||
" set orderNumber = ? - 1" +
|
|
||||||
" where occupancyTypeId = ?")
|
|
||||||
.run(currentOrderNumber, occupancyTypeId);
|
.run(currentOrderNumber, occupancyTypeId);
|
||||||
database.close();
|
database.close();
|
||||||
clearOccupancyTypesCache();
|
clearOccupancyTypesCache();
|
||||||
return result.changes > 0;
|
return result.changes > 0;
|
||||||
};
|
};
|
||||||
|
export const moveOccupancyTypeUpToTop = (occupancyTypeId) => {
|
||||||
|
const database = sqlite(databasePath);
|
||||||
|
const currentOrderNumber = database
|
||||||
|
.prepare("select orderNumber from OccupancyTypes where occupancyTypeId = ?")
|
||||||
|
.get(occupancyTypeId).orderNumber;
|
||||||
|
if (currentOrderNumber > 0) {
|
||||||
|
database
|
||||||
|
.prepare("update OccupancyTypes set orderNumber = -1 where occupancyTypeId = ?")
|
||||||
|
.run(occupancyTypeId);
|
||||||
|
database
|
||||||
|
.prepare("update OccupancyTypes" +
|
||||||
|
" set orderNumber = orderNumber + 1" +
|
||||||
|
" where recordDelete_timeMillis is null" +
|
||||||
|
" and orderNumber < ?")
|
||||||
|
.run(currentOrderNumber);
|
||||||
|
}
|
||||||
|
database.close();
|
||||||
|
clearOccupancyTypesCache();
|
||||||
|
return true;
|
||||||
|
};
|
||||||
export default moveOccupancyTypeUp;
|
export default moveOccupancyTypeUp;
|
||||||
|
|
|
||||||
|
|
@ -4,17 +4,11 @@ import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
||||||
|
|
||||||
import { clearOccupancyTypesCache } from "../functions.cache.js";
|
import { clearOccupancyTypesCache } from "../functions.cache.js";
|
||||||
|
|
||||||
export const moveOccupancyTypeUp = (
|
export const moveOccupancyTypeUp = (occupancyTypeId: number | string): boolean => {
|
||||||
occupancyTypeId: number | string
|
|
||||||
): boolean => {
|
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
|
|
||||||
const currentOrderNumber: number = database
|
const currentOrderNumber: number = database
|
||||||
.prepare(
|
.prepare("select orderNumber from OccupancyTypes where occupancyTypeId = ?")
|
||||||
"select orderNumber" +
|
|
||||||
" from OccupancyTypes" +
|
|
||||||
" where occupancyTypeId = ?"
|
|
||||||
)
|
|
||||||
.get(occupancyTypeId).orderNumber;
|
.get(occupancyTypeId).orderNumber;
|
||||||
|
|
||||||
if (currentOrderNumber <= 0) {
|
if (currentOrderNumber <= 0) {
|
||||||
|
|
@ -32,11 +26,7 @@ export const moveOccupancyTypeUp = (
|
||||||
.run(currentOrderNumber);
|
.run(currentOrderNumber);
|
||||||
|
|
||||||
const result = database
|
const result = database
|
||||||
.prepare(
|
.prepare("update OccupancyTypes set orderNumber = ? - 1 where occupancyTypeId = ?")
|
||||||
"update OccupancyTypes" +
|
|
||||||
" set orderNumber = ? - 1" +
|
|
||||||
" where occupancyTypeId = ?"
|
|
||||||
)
|
|
||||||
.run(currentOrderNumber, occupancyTypeId);
|
.run(currentOrderNumber, occupancyTypeId);
|
||||||
|
|
||||||
database.close();
|
database.close();
|
||||||
|
|
@ -46,4 +36,33 @@ export const moveOccupancyTypeUp = (
|
||||||
return result.changes > 0;
|
return result.changes > 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const moveOccupancyTypeUpToTop = (occupancyTypeId: number | string): boolean => {
|
||||||
|
const database = sqlite(databasePath);
|
||||||
|
|
||||||
|
const currentOrderNumber: number = database
|
||||||
|
.prepare("select orderNumber from OccupancyTypes where occupancyTypeId = ?")
|
||||||
|
.get(occupancyTypeId).orderNumber;
|
||||||
|
|
||||||
|
if (currentOrderNumber > 0) {
|
||||||
|
database
|
||||||
|
.prepare("update OccupancyTypes set orderNumber = -1 where occupancyTypeId = ?")
|
||||||
|
.run(occupancyTypeId);
|
||||||
|
|
||||||
|
database
|
||||||
|
.prepare(
|
||||||
|
"update OccupancyTypes" +
|
||||||
|
" set orderNumber = orderNumber + 1" +
|
||||||
|
" where recordDelete_timeMillis is null" +
|
||||||
|
" and orderNumber < ?"
|
||||||
|
)
|
||||||
|
.run(currentOrderNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
database.close();
|
||||||
|
|
||||||
|
clearOccupancyTypesCache();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
export default moveOccupancyTypeUp;
|
export default moveOccupancyTypeUp;
|
||||||
|
|
|
||||||
|
|
@ -128,14 +128,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
clickEvent.preventDefault();
|
clickEvent.preventDefault();
|
||||||
const occupancyTypeId = clickEvent.currentTarget.closest(".container--occupancyType").dataset.occupancyTypeId;
|
const occupancyTypeId = clickEvent.currentTarget.closest(".container--occupancyType").dataset.occupancyTypeId;
|
||||||
cityssm.postJSON(urlPrefix + "/admin/doMoveOccupancyTypeUp", {
|
cityssm.postJSON(urlPrefix + "/admin/doMoveOccupancyTypeUp", {
|
||||||
occupancyTypeId
|
occupancyTypeId,
|
||||||
|
moveToTop: clickEvent.shiftKey ? "1" : "0"
|
||||||
}, occupancyTypeResponseHandler);
|
}, occupancyTypeResponseHandler);
|
||||||
};
|
};
|
||||||
const moveOccupancyTypeDown = (clickEvent) => {
|
const moveOccupancyTypeDown = (clickEvent) => {
|
||||||
clickEvent.preventDefault();
|
clickEvent.preventDefault();
|
||||||
const occupancyTypeId = clickEvent.currentTarget.closest(".container--occupancyType").dataset.occupancyTypeId;
|
const occupancyTypeId = clickEvent.currentTarget.closest(".container--occupancyType").dataset.occupancyTypeId;
|
||||||
cityssm.postJSON(urlPrefix + "/admin/doMoveOccupancyTypeDown", {
|
cityssm.postJSON(urlPrefix + "/admin/doMoveOccupancyTypeDown", {
|
||||||
occupancyTypeId
|
occupancyTypeId,
|
||||||
|
moveToBottom: clickEvent.shiftKey ? "1" : "0"
|
||||||
}, occupancyTypeResponseHandler);
|
}, occupancyTypeResponseHandler);
|
||||||
};
|
};
|
||||||
const openEditOccupancyTypeField = (occupancyTypeId, occupancyTypeFieldId) => {
|
const openEditOccupancyTypeField = (occupancyTypeId, occupancyTypeFieldId) => {
|
||||||
|
|
@ -243,14 +245,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
clickEvent.preventDefault();
|
clickEvent.preventDefault();
|
||||||
const occupancyTypeFieldId = clickEvent.currentTarget.closest(".container--occupancyTypeField").dataset.occupancyTypeFieldId;
|
const occupancyTypeFieldId = clickEvent.currentTarget.closest(".container--occupancyTypeField").dataset.occupancyTypeFieldId;
|
||||||
cityssm.postJSON(urlPrefix + "/admin/doMoveOccupancyTypeFieldUp", {
|
cityssm.postJSON(urlPrefix + "/admin/doMoveOccupancyTypeFieldUp", {
|
||||||
occupancyTypeFieldId
|
occupancyTypeFieldId,
|
||||||
|
moveToTop: clickEvent.shiftKey ? "1" : "0"
|
||||||
}, occupancyTypeResponseHandler);
|
}, occupancyTypeResponseHandler);
|
||||||
};
|
};
|
||||||
const moveOccupancyTypeFieldDown = (clickEvent) => {
|
const moveOccupancyTypeFieldDown = (clickEvent) => {
|
||||||
clickEvent.preventDefault();
|
clickEvent.preventDefault();
|
||||||
const occupancyTypeFieldId = clickEvent.currentTarget.closest(".container--occupancyTypeField").dataset.occupancyTypeFieldId;
|
const occupancyTypeFieldId = clickEvent.currentTarget.closest(".container--occupancyTypeField").dataset.occupancyTypeFieldId;
|
||||||
cityssm.postJSON(urlPrefix + "/admin/doMoveOccupancyTypeFieldDown", {
|
cityssm.postJSON(urlPrefix + "/admin/doMoveOccupancyTypeFieldDown", {
|
||||||
occupancyTypeFieldId
|
occupancyTypeFieldId,
|
||||||
|
moveToBottom: clickEvent.shiftKey ? "1" : "0"
|
||||||
}, occupancyTypeResponseHandler);
|
}, occupancyTypeResponseHandler);
|
||||||
};
|
};
|
||||||
const renderOccupancyTypeFields = (panelElement, occupancyTypeId, occupancyTypeFields) => {
|
const renderOccupancyTypeFields = (panelElement, occupancyTypeId, occupancyTypeFields) => {
|
||||||
|
|
|
||||||
|
|
@ -245,7 +245,7 @@ declare const bulmaJS: BulmaJS;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const moveOccupancyTypeUp = (clickEvent: Event) => {
|
const moveOccupancyTypeUp = (clickEvent: MouseEvent) => {
|
||||||
clickEvent.preventDefault();
|
clickEvent.preventDefault();
|
||||||
|
|
||||||
const occupancyTypeId = (
|
const occupancyTypeId = (
|
||||||
|
|
@ -257,13 +257,14 @@ declare const bulmaJS: BulmaJS;
|
||||||
cityssm.postJSON(
|
cityssm.postJSON(
|
||||||
urlPrefix + "/admin/doMoveOccupancyTypeUp",
|
urlPrefix + "/admin/doMoveOccupancyTypeUp",
|
||||||
{
|
{
|
||||||
occupancyTypeId
|
occupancyTypeId,
|
||||||
|
moveToTop: clickEvent.shiftKey ? "1" : "0"
|
||||||
},
|
},
|
||||||
occupancyTypeResponseHandler
|
occupancyTypeResponseHandler
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const moveOccupancyTypeDown = (clickEvent: Event) => {
|
const moveOccupancyTypeDown = (clickEvent: MouseEvent) => {
|
||||||
clickEvent.preventDefault();
|
clickEvent.preventDefault();
|
||||||
|
|
||||||
const occupancyTypeId = (
|
const occupancyTypeId = (
|
||||||
|
|
@ -275,7 +276,8 @@ declare const bulmaJS: BulmaJS;
|
||||||
cityssm.postJSON(
|
cityssm.postJSON(
|
||||||
urlPrefix + "/admin/doMoveOccupancyTypeDown",
|
urlPrefix + "/admin/doMoveOccupancyTypeDown",
|
||||||
{
|
{
|
||||||
occupancyTypeId
|
occupancyTypeId,
|
||||||
|
moveToBottom: clickEvent.shiftKey ? "1" : "0"
|
||||||
},
|
},
|
||||||
occupancyTypeResponseHandler
|
occupancyTypeResponseHandler
|
||||||
);
|
);
|
||||||
|
|
@ -465,7 +467,7 @@ declare const bulmaJS: BulmaJS;
|
||||||
openEditOccupancyTypeField(occupancyTypeId, occupancyTypeFieldId);
|
openEditOccupancyTypeField(occupancyTypeId, occupancyTypeFieldId);
|
||||||
};
|
};
|
||||||
|
|
||||||
const moveOccupancyTypeFieldUp = (clickEvent: Event) => {
|
const moveOccupancyTypeFieldUp = (clickEvent: MouseEvent) => {
|
||||||
clickEvent.preventDefault();
|
clickEvent.preventDefault();
|
||||||
|
|
||||||
const occupancyTypeFieldId = (
|
const occupancyTypeFieldId = (
|
||||||
|
|
@ -477,13 +479,14 @@ declare const bulmaJS: BulmaJS;
|
||||||
cityssm.postJSON(
|
cityssm.postJSON(
|
||||||
urlPrefix + "/admin/doMoveOccupancyTypeFieldUp",
|
urlPrefix + "/admin/doMoveOccupancyTypeFieldUp",
|
||||||
{
|
{
|
||||||
occupancyTypeFieldId
|
occupancyTypeFieldId,
|
||||||
|
moveToTop: clickEvent.shiftKey ? "1" : "0"
|
||||||
},
|
},
|
||||||
occupancyTypeResponseHandler
|
occupancyTypeResponseHandler
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const moveOccupancyTypeFieldDown = (clickEvent: Event) => {
|
const moveOccupancyTypeFieldDown = (clickEvent: MouseEvent) => {
|
||||||
clickEvent.preventDefault();
|
clickEvent.preventDefault();
|
||||||
|
|
||||||
const occupancyTypeFieldId = (
|
const occupancyTypeFieldId = (
|
||||||
|
|
@ -495,7 +498,8 @@ declare const bulmaJS: BulmaJS;
|
||||||
cityssm.postJSON(
|
cityssm.postJSON(
|
||||||
urlPrefix + "/admin/doMoveOccupancyTypeFieldDown",
|
urlPrefix + "/admin/doMoveOccupancyTypeFieldDown",
|
||||||
{
|
{
|
||||||
occupancyTypeFieldId
|
occupancyTypeFieldId,
|
||||||
|
moveToBottom: clickEvent.shiftKey ? "1" : "0"
|
||||||
},
|
},
|
||||||
occupancyTypeResponseHandler
|
occupancyTypeResponseHandler
|
||||||
);
|
);
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue