quick sorting lot types
parent
d78232d852
commit
a929d31ede
|
|
@ -1,7 +1,9 @@
|
||||||
import { moveLotTypeDown } from "../../helpers/lotOccupancyDB/moveLotTypeDown.js";
|
import { moveLotTypeDown, moveLotTypeDownToBottom } from "../../helpers/lotOccupancyDB/moveLotTypeDown.js";
|
||||||
import { getLotTypes } from "../../helpers/functions.cache.js";
|
import { getLotTypes } from "../../helpers/functions.cache.js";
|
||||||
export const handler = async (request, response) => {
|
export const handler = async (request, response) => {
|
||||||
const success = moveLotTypeDown(request.body.lotTypeId);
|
const success = request.body.moveToBottom === "1"
|
||||||
|
? moveLotTypeDownToBottom(request.body.lotTypeId)
|
||||||
|
: moveLotTypeDown(request.body.lotTypeId);
|
||||||
const lotTypes = getLotTypes();
|
const lotTypes = getLotTypes();
|
||||||
response.json({
|
response.json({
|
||||||
success,
|
success,
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,17 @@
|
||||||
import type { RequestHandler } from "express";
|
import type { RequestHandler } from "express";
|
||||||
|
|
||||||
import { moveLotTypeDown } from "../../helpers/lotOccupancyDB/moveLotTypeDown.js";
|
import {
|
||||||
|
moveLotTypeDown,
|
||||||
|
moveLotTypeDownToBottom
|
||||||
|
} from "../../helpers/lotOccupancyDB/moveLotTypeDown.js";
|
||||||
|
|
||||||
import { getLotTypes } from "../../helpers/functions.cache.js";
|
import { getLotTypes } from "../../helpers/functions.cache.js";
|
||||||
|
|
||||||
export const handler: RequestHandler = async (request, response) => {
|
export const handler: RequestHandler = async (request, response) => {
|
||||||
const success = moveLotTypeDown(request.body.lotTypeId);
|
const success =
|
||||||
|
request.body.moveToBottom === "1"
|
||||||
|
? moveLotTypeDownToBottom(request.body.lotTypeId)
|
||||||
|
: moveLotTypeDown(request.body.lotTypeId);
|
||||||
|
|
||||||
const lotTypes = getLotTypes();
|
const lotTypes = getLotTypes();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
import { moveLotTypeFieldDown } from "../../helpers/lotOccupancyDB/moveLotTypeFieldDown.js";
|
import { moveLotTypeFieldDown, moveLotTypeFieldDownToBottom } from "../../helpers/lotOccupancyDB/moveLotTypeFieldDown.js";
|
||||||
import { getLotTypes } from "../../helpers/functions.cache.js";
|
import { getLotTypes } from "../../helpers/functions.cache.js";
|
||||||
export const handler = async (request, response) => {
|
export const handler = async (request, response) => {
|
||||||
const success = moveLotTypeFieldDown(request.body.lotTypeFieldId);
|
const success = request.body.moveToBottom === "1"
|
||||||
|
? moveLotTypeFieldDownToBottom(request.body.lotTypeFieldId)
|
||||||
|
: moveLotTypeFieldDown(request.body.lotTypeFieldId);
|
||||||
const lotTypes = getLotTypes();
|
const lotTypes = getLotTypes();
|
||||||
response.json({
|
response.json({
|
||||||
success,
|
success,
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,17 @@
|
||||||
import type { RequestHandler } from "express";
|
import type { RequestHandler } from "express";
|
||||||
|
|
||||||
import { moveLotTypeFieldDown } from "../../helpers/lotOccupancyDB/moveLotTypeFieldDown.js";
|
import {
|
||||||
|
moveLotTypeFieldDown,
|
||||||
|
moveLotTypeFieldDownToBottom
|
||||||
|
} from "../../helpers/lotOccupancyDB/moveLotTypeFieldDown.js";
|
||||||
|
|
||||||
import { getLotTypes } from "../../helpers/functions.cache.js";
|
import { getLotTypes } from "../../helpers/functions.cache.js";
|
||||||
|
|
||||||
export const handler: RequestHandler = async (request, response) => {
|
export const handler: RequestHandler = async (request, response) => {
|
||||||
const success = moveLotTypeFieldDown(request.body.lotTypeFieldId);
|
const success =
|
||||||
|
request.body.moveToBottom === "1"
|
||||||
|
? moveLotTypeFieldDownToBottom(request.body.lotTypeFieldId)
|
||||||
|
: moveLotTypeFieldDown(request.body.lotTypeFieldId);
|
||||||
|
|
||||||
const lotTypes = getLotTypes();
|
const lotTypes = getLotTypes();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
import { moveLotTypeFieldUp } from "../../helpers/lotOccupancyDB/moveLotTypeFieldUp.js";
|
import { moveLotTypeFieldUp, moveLotTypeFieldUpToTop } from "../../helpers/lotOccupancyDB/moveLotTypeFieldUp.js";
|
||||||
import { getLotTypes } from "../../helpers/functions.cache.js";
|
import { getLotTypes } from "../../helpers/functions.cache.js";
|
||||||
export const handler = async (request, response) => {
|
export const handler = async (request, response) => {
|
||||||
const success = moveLotTypeFieldUp(request.body.lotTypeFieldId);
|
const success = request.body.moveToTop === "1"
|
||||||
|
? moveLotTypeFieldUpToTop(request.body.lotTypeFieldId)
|
||||||
|
: moveLotTypeFieldUp(request.body.lotTypeFieldId);
|
||||||
const lotTypes = getLotTypes();
|
const lotTypes = getLotTypes();
|
||||||
response.json({
|
response.json({
|
||||||
success,
|
success,
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,17 @@
|
||||||
import type { RequestHandler } from "express";
|
import type { RequestHandler } from "express";
|
||||||
|
|
||||||
import { moveLotTypeFieldUp } from "../../helpers/lotOccupancyDB/moveLotTypeFieldUp.js";
|
import {
|
||||||
|
moveLotTypeFieldUp,
|
||||||
|
moveLotTypeFieldUpToTop
|
||||||
|
} from "../../helpers/lotOccupancyDB/moveLotTypeFieldUp.js";
|
||||||
|
|
||||||
import { getLotTypes } from "../../helpers/functions.cache.js";
|
import { getLotTypes } from "../../helpers/functions.cache.js";
|
||||||
|
|
||||||
export const handler: RequestHandler = async (request, response) => {
|
export const handler: RequestHandler = async (request, response) => {
|
||||||
const success = moveLotTypeFieldUp(request.body.lotTypeFieldId);
|
const success =
|
||||||
|
request.body.moveToTop === "1"
|
||||||
|
? moveLotTypeFieldUpToTop(request.body.lotTypeFieldId)
|
||||||
|
: moveLotTypeFieldUp(request.body.lotTypeFieldId);
|
||||||
|
|
||||||
const lotTypes = getLotTypes();
|
const lotTypes = getLotTypes();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
import { moveLotTypeUp } from "../../helpers/lotOccupancyDB/moveLotTypeUp.js";
|
import { moveLotTypeUp, moveLotTypeUpToTop } from "../../helpers/lotOccupancyDB/moveLotTypeUp.js";
|
||||||
import { getLotTypes } from "../../helpers/functions.cache.js";
|
import { getLotTypes } from "../../helpers/functions.cache.js";
|
||||||
export const handler = async (request, response) => {
|
export const handler = async (request, response) => {
|
||||||
const success = moveLotTypeUp(request.body.lotTypeId);
|
const success = request.body.moveToTop === "1"
|
||||||
|
? moveLotTypeUpToTop(request.body.lotTypeId)
|
||||||
|
: moveLotTypeUp(request.body.lotTypeId);
|
||||||
const lotTypes = getLotTypes();
|
const lotTypes = getLotTypes();
|
||||||
response.json({
|
response.json({
|
||||||
success,
|
success,
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,14 @@
|
||||||
import type { RequestHandler } from "express";
|
import type { RequestHandler } from "express";
|
||||||
|
|
||||||
import { moveLotTypeUp } from "../../helpers/lotOccupancyDB/moveLotTypeUp.js";
|
import { moveLotTypeUp, moveLotTypeUpToTop } from "../../helpers/lotOccupancyDB/moveLotTypeUp.js";
|
||||||
|
|
||||||
import { getLotTypes } from "../../helpers/functions.cache.js";
|
import { getLotTypes } from "../../helpers/functions.cache.js";
|
||||||
|
|
||||||
export const handler: RequestHandler = async (request, response) => {
|
export const handler: RequestHandler = async (request, response) => {
|
||||||
const success = moveLotTypeUp(request.body.lotTypeId);
|
const success =
|
||||||
|
request.body.moveToTop === "1"
|
||||||
|
? moveLotTypeUpToTop(request.body.lotTypeId)
|
||||||
|
: moveLotTypeUp(request.body.lotTypeId);
|
||||||
|
|
||||||
const lotTypes = getLotTypes();
|
const lotTypes = getLotTypes();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,3 @@
|
||||||
export declare const moveLotTypeDown: (lotTypeId: number | string) => boolean;
|
export declare const moveLotTypeDown: (lotTypeId: number | string) => boolean;
|
||||||
|
export declare const moveLotTypeDownToBottom: (lotTypeId: number | string) => boolean;
|
||||||
export default moveLotTypeDown;
|
export default moveLotTypeDown;
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import { clearLotTypesCache } from "../functions.cache.js";
|
||||||
export const moveLotTypeDown = (lotTypeId) => {
|
export const moveLotTypeDown = (lotTypeId) => {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
const currentOrderNumber = database
|
const currentOrderNumber = database
|
||||||
.prepare("select orderNumber" + " from LotTypes" + " where lotTypeId = ?")
|
.prepare("select orderNumber from LotTypes where lotTypeId = ?")
|
||||||
.get(lotTypeId).orderNumber;
|
.get(lotTypeId).orderNumber;
|
||||||
database
|
database
|
||||||
.prepare("update LotTypes" +
|
.prepare("update LotTypes" +
|
||||||
|
|
@ -13,10 +13,35 @@ export const moveLotTypeDown = (lotTypeId) => {
|
||||||
" and orderNumber = ? + 1")
|
" and orderNumber = ? + 1")
|
||||||
.run(currentOrderNumber);
|
.run(currentOrderNumber);
|
||||||
const result = database
|
const result = database
|
||||||
.prepare("update LotTypes" + " set orderNumber = ? + 1" + " where lotTypeId = ?")
|
.prepare("update LotTypes set orderNumber = ? + 1 where lotTypeId = ?")
|
||||||
.run(currentOrderNumber, lotTypeId);
|
.run(currentOrderNumber, lotTypeId);
|
||||||
database.close();
|
database.close();
|
||||||
clearLotTypesCache();
|
clearLotTypesCache();
|
||||||
return result.changes > 0;
|
return result.changes > 0;
|
||||||
};
|
};
|
||||||
|
export const moveLotTypeDownToBottom = (lotTypeId) => {
|
||||||
|
const database = sqlite(databasePath);
|
||||||
|
const currentOrderNumber = database
|
||||||
|
.prepare("select orderNumber from LotTypes where lotTypeId = ?")
|
||||||
|
.get(lotTypeId).orderNumber;
|
||||||
|
const maxOrderNumber = database
|
||||||
|
.prepare("select max(orderNumber) as maxOrderNumber" +
|
||||||
|
" from LotTypes" +
|
||||||
|
" where recordDelete_timeMillis is null")
|
||||||
|
.get().maxOrderNumber;
|
||||||
|
if (currentOrderNumber !== maxOrderNumber) {
|
||||||
|
database
|
||||||
|
.prepare("update LotTypes set orderNumber = ? + 1 where lotTypeId = ?")
|
||||||
|
.run(maxOrderNumber, lotTypeId);
|
||||||
|
database
|
||||||
|
.prepare("update LotTypes" +
|
||||||
|
" set orderNumber = orderNumber - 1" +
|
||||||
|
" where recordDelete_timeMillis is null" +
|
||||||
|
" and orderNumber > ?")
|
||||||
|
.run(currentOrderNumber);
|
||||||
|
}
|
||||||
|
database.close();
|
||||||
|
clearLotTypesCache();
|
||||||
|
return true;
|
||||||
|
};
|
||||||
export default moveLotTypeDown;
|
export default moveLotTypeDown;
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ export const moveLotTypeDown = (lotTypeId: number | string): boolean => {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
|
|
||||||
const currentOrderNumber: number = database
|
const currentOrderNumber: number = database
|
||||||
.prepare("select orderNumber" + " from LotTypes" + " where lotTypeId = ?")
|
.prepare("select orderNumber from LotTypes where lotTypeId = ?")
|
||||||
.get(lotTypeId).orderNumber;
|
.get(lotTypeId).orderNumber;
|
||||||
|
|
||||||
database
|
database
|
||||||
|
|
@ -21,7 +21,7 @@ export const moveLotTypeDown = (lotTypeId: number | string): boolean => {
|
||||||
.run(currentOrderNumber);
|
.run(currentOrderNumber);
|
||||||
|
|
||||||
const result = database
|
const result = database
|
||||||
.prepare("update LotTypes" + " set orderNumber = ? + 1" + " where lotTypeId = ?")
|
.prepare("update LotTypes set orderNumber = ? + 1 where lotTypeId = ?")
|
||||||
.run(currentOrderNumber, lotTypeId);
|
.run(currentOrderNumber, lotTypeId);
|
||||||
|
|
||||||
database.close();
|
database.close();
|
||||||
|
|
@ -31,4 +31,41 @@ export const moveLotTypeDown = (lotTypeId: number | string): boolean => {
|
||||||
return result.changes > 0;
|
return result.changes > 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const moveLotTypeDownToBottom = (lotTypeId: number | string): boolean => {
|
||||||
|
const database = sqlite(databasePath);
|
||||||
|
|
||||||
|
const currentOrderNumber: number = database
|
||||||
|
.prepare("select orderNumber from LotTypes where lotTypeId = ?")
|
||||||
|
.get(lotTypeId).orderNumber;
|
||||||
|
|
||||||
|
const maxOrderNumber: number = database
|
||||||
|
.prepare(
|
||||||
|
"select max(orderNumber) as maxOrderNumber" +
|
||||||
|
" from LotTypes" +
|
||||||
|
" where recordDelete_timeMillis is null"
|
||||||
|
)
|
||||||
|
.get().maxOrderNumber;
|
||||||
|
|
||||||
|
if (currentOrderNumber !== maxOrderNumber) {
|
||||||
|
database
|
||||||
|
.prepare("update LotTypes set orderNumber = ? + 1 where lotTypeId = ?")
|
||||||
|
.run(maxOrderNumber, lotTypeId);
|
||||||
|
|
||||||
|
database
|
||||||
|
.prepare(
|
||||||
|
"update LotTypes" +
|
||||||
|
" set orderNumber = orderNumber - 1" +
|
||||||
|
" where recordDelete_timeMillis is null" +
|
||||||
|
" and orderNumber > ?"
|
||||||
|
)
|
||||||
|
.run(currentOrderNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
database.close();
|
||||||
|
|
||||||
|
clearLotTypesCache();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
export default moveLotTypeDown;
|
export default moveLotTypeDown;
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,3 @@
|
||||||
export declare const moveLotTypeFieldDown: (lotTypeFieldId: number | string) => boolean;
|
export declare const moveLotTypeFieldDown: (lotTypeFieldId: number | string) => boolean;
|
||||||
|
export declare const moveLotTypeFieldDownToBottom: (lotTypeFieldId: number | string) => boolean;
|
||||||
export default moveLotTypeFieldDown;
|
export default moveLotTypeFieldDown;
|
||||||
|
|
|
||||||
|
|
@ -20,4 +20,31 @@ export const moveLotTypeFieldDown = (lotTypeFieldId) => {
|
||||||
clearLotTypesCache();
|
clearLotTypesCache();
|
||||||
return result.changes > 0;
|
return result.changes > 0;
|
||||||
};
|
};
|
||||||
|
export const moveLotTypeFieldDownToBottom = (lotTypeFieldId) => {
|
||||||
|
const database = sqlite(databasePath);
|
||||||
|
const currentField = database
|
||||||
|
.prepare("select lotTypeId, orderNumber from LotTypeFields where lotTypeFieldId = ?")
|
||||||
|
.get(lotTypeFieldId);
|
||||||
|
const maxOrderNumber = database
|
||||||
|
.prepare("select max(orderNumber) as maxOrderNumber" +
|
||||||
|
" from LotTypeFields" +
|
||||||
|
" where recordDelete_timeMillis is null" +
|
||||||
|
" and lotTypeId = ?")
|
||||||
|
.get(currentField.lotTypeId).maxOrderNumber;
|
||||||
|
if (currentField.orderNumber !== maxOrderNumber) {
|
||||||
|
database
|
||||||
|
.prepare("update LotTypeFields set orderNumber = ? + 1 where lotTypeFieldId = ?")
|
||||||
|
.run(maxOrderNumber, lotTypeFieldId);
|
||||||
|
database
|
||||||
|
.prepare("update LotTypeFields" +
|
||||||
|
" set orderNumber = orderNumber - 1" +
|
||||||
|
" where recordDelete_timeMillis is null" +
|
||||||
|
" and lotTypeId = ?" +
|
||||||
|
" and orderNumber > ?")
|
||||||
|
.run(currentField.lotTypeId, currentField.orderNumber);
|
||||||
|
}
|
||||||
|
database.close();
|
||||||
|
clearLotTypesCache();
|
||||||
|
return true;
|
||||||
|
};
|
||||||
export default moveLotTypeFieldDown;
|
export default moveLotTypeFieldDown;
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,7 @@ export const moveLotTypeFieldDown = (lotTypeFieldId: number | string): boolean =
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
|
|
||||||
const currentField: { lotTypeId?: number; orderNumber: number } = database
|
const currentField: { lotTypeId?: number; orderNumber: number } = database
|
||||||
.prepare(
|
.prepare("select lotTypeId, orderNumber from LotTypeFields where lotTypeFieldId = ?")
|
||||||
"select lotTypeId, orderNumber from LotTypeFields where lotTypeFieldId = ?"
|
|
||||||
)
|
|
||||||
.get(lotTypeFieldId);
|
.get(lotTypeFieldId);
|
||||||
|
|
||||||
database
|
database
|
||||||
|
|
@ -34,4 +32,43 @@ export const moveLotTypeFieldDown = (lotTypeFieldId: number | string): boolean =
|
||||||
return result.changes > 0;
|
return result.changes > 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const moveLotTypeFieldDownToBottom = (lotTypeFieldId: number | string): boolean => {
|
||||||
|
const database = sqlite(databasePath);
|
||||||
|
|
||||||
|
const currentField: { lotTypeId?: number; orderNumber: number } = database
|
||||||
|
.prepare("select lotTypeId, orderNumber from LotTypeFields where lotTypeFieldId = ?")
|
||||||
|
.get(lotTypeFieldId);
|
||||||
|
|
||||||
|
const maxOrderNumber: number = database
|
||||||
|
.prepare(
|
||||||
|
"select max(orderNumber) as maxOrderNumber" +
|
||||||
|
" from LotTypeFields" +
|
||||||
|
" where recordDelete_timeMillis is null" +
|
||||||
|
" and lotTypeId = ?"
|
||||||
|
)
|
||||||
|
.get(currentField.lotTypeId).maxOrderNumber;
|
||||||
|
|
||||||
|
if (currentField.orderNumber !== maxOrderNumber) {
|
||||||
|
database
|
||||||
|
.prepare("update LotTypeFields set orderNumber = ? + 1 where lotTypeFieldId = ?")
|
||||||
|
.run(maxOrderNumber, lotTypeFieldId);
|
||||||
|
|
||||||
|
database
|
||||||
|
.prepare(
|
||||||
|
"update LotTypeFields" +
|
||||||
|
" set orderNumber = orderNumber - 1" +
|
||||||
|
" where recordDelete_timeMillis is null" +
|
||||||
|
" and lotTypeId = ?" +
|
||||||
|
" and orderNumber > ?"
|
||||||
|
)
|
||||||
|
.run(currentField.lotTypeId, currentField.orderNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
database.close();
|
||||||
|
|
||||||
|
clearLotTypesCache();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
export default moveLotTypeFieldDown;
|
export default moveLotTypeFieldDown;
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,3 @@
|
||||||
export declare const moveLotTypeFieldUp: (lotTypeFieldId: number | string) => boolean;
|
export declare const moveLotTypeFieldUp: (lotTypeFieldId: number | string) => boolean;
|
||||||
|
export declare const moveLotTypeFieldUpToTop: (lotTypeFieldId: number | string) => boolean;
|
||||||
export default moveLotTypeFieldUp;
|
export default moveLotTypeFieldUp;
|
||||||
|
|
|
||||||
|
|
@ -24,4 +24,25 @@ export const moveLotTypeFieldUp = (lotTypeFieldId) => {
|
||||||
clearLotTypesCache();
|
clearLotTypesCache();
|
||||||
return result.changes > 0;
|
return result.changes > 0;
|
||||||
};
|
};
|
||||||
|
export const moveLotTypeFieldUpToTop = (lotTypeFieldId) => {
|
||||||
|
const database = sqlite(databasePath);
|
||||||
|
const currentField = database
|
||||||
|
.prepare("select lotTypeId, orderNumber from LotTypeFields where lotTypeFieldId = ?")
|
||||||
|
.get(lotTypeFieldId);
|
||||||
|
if (currentField.orderNumber > 0) {
|
||||||
|
database
|
||||||
|
.prepare("update LotTypeFields set orderNumber = -1 where lotTypeFieldId = ?")
|
||||||
|
.run(lotTypeFieldId);
|
||||||
|
database
|
||||||
|
.prepare("update LotTypeFields" +
|
||||||
|
" set orderNumber = orderNumber + 1" +
|
||||||
|
" where recordDelete_timeMillis is null" +
|
||||||
|
" and lotTypeId = ?" +
|
||||||
|
" and orderNumber < ?")
|
||||||
|
.run(currentField.lotTypeId, currentField.orderNumber);
|
||||||
|
}
|
||||||
|
database.close();
|
||||||
|
clearLotTypesCache();
|
||||||
|
return true;
|
||||||
|
};
|
||||||
export default moveLotTypeFieldUp;
|
export default moveLotTypeFieldUp;
|
||||||
|
|
|
||||||
|
|
@ -37,4 +37,34 @@ export const moveLotTypeFieldUp = (lotTypeFieldId: number | string): boolean =>
|
||||||
return result.changes > 0;
|
return result.changes > 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const moveLotTypeFieldUpToTop = (lotTypeFieldId: number | string): boolean => {
|
||||||
|
const database = sqlite(databasePath);
|
||||||
|
|
||||||
|
const currentField: { lotTypeId: number; orderNumber: number } = database
|
||||||
|
.prepare("select lotTypeId, orderNumber from LotTypeFields where lotTypeFieldId = ?")
|
||||||
|
.get(lotTypeFieldId);
|
||||||
|
|
||||||
|
if (currentField.orderNumber > 0) {
|
||||||
|
database
|
||||||
|
.prepare("update LotTypeFields set orderNumber = -1 where lotTypeFieldId = ?")
|
||||||
|
.run(lotTypeFieldId);
|
||||||
|
|
||||||
|
database
|
||||||
|
.prepare(
|
||||||
|
"update LotTypeFields" +
|
||||||
|
" set orderNumber = orderNumber + 1" +
|
||||||
|
" where recordDelete_timeMillis is null" +
|
||||||
|
" and lotTypeId = ?" +
|
||||||
|
" and orderNumber < ?"
|
||||||
|
)
|
||||||
|
.run(currentField.lotTypeId, currentField.orderNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
database.close();
|
||||||
|
|
||||||
|
clearLotTypesCache();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
export default moveLotTypeFieldUp;
|
export default moveLotTypeFieldUp;
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,3 @@
|
||||||
export declare const moveLotTypeUp: (lotTypeId: number | string) => boolean;
|
export declare const moveLotTypeUp: (lotTypeId: number | string) => boolean;
|
||||||
|
export declare const moveLotTypeUpToTop: (lotTypeId: number | string) => boolean;
|
||||||
export default moveLotTypeUp;
|
export default moveLotTypeUp;
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,7 @@ import { clearLotTypesCache } from "../functions.cache.js";
|
||||||
export const moveLotTypeUp = (lotTypeId) => {
|
export const moveLotTypeUp = (lotTypeId) => {
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
const currentOrderNumber = database
|
const currentOrderNumber = database
|
||||||
.prepare("select orderNumber" +
|
.prepare("select orderNumber from LotTypes where lotTypeId = ?")
|
||||||
" from LotTypes" +
|
|
||||||
" where lotTypeId = ?")
|
|
||||||
.get(lotTypeId).orderNumber;
|
.get(lotTypeId).orderNumber;
|
||||||
if (currentOrderNumber <= 0) {
|
if (currentOrderNumber <= 0) {
|
||||||
database.close();
|
database.close();
|
||||||
|
|
@ -19,12 +17,28 @@ export const moveLotTypeUp = (lotTypeId) => {
|
||||||
" and orderNumber = ? - 1")
|
" and orderNumber = ? - 1")
|
||||||
.run(currentOrderNumber);
|
.run(currentOrderNumber);
|
||||||
const result = database
|
const result = database
|
||||||
.prepare("update LotTypes" +
|
.prepare("update LotTypes set orderNumber = ? - 1 where lotTypeId = ?")
|
||||||
" set orderNumber = ? - 1" +
|
|
||||||
" where lotTypeId = ?")
|
|
||||||
.run(currentOrderNumber, lotTypeId);
|
.run(currentOrderNumber, lotTypeId);
|
||||||
database.close();
|
database.close();
|
||||||
clearLotTypesCache();
|
clearLotTypesCache();
|
||||||
return result.changes > 0;
|
return result.changes > 0;
|
||||||
};
|
};
|
||||||
|
export const moveLotTypeUpToTop = (lotTypeId) => {
|
||||||
|
const database = sqlite(databasePath);
|
||||||
|
const currentOrderNumber = database
|
||||||
|
.prepare("select orderNumber from LotTypes where lotTypeId = ?")
|
||||||
|
.get(lotTypeId).orderNumber;
|
||||||
|
if (currentOrderNumber > 0) {
|
||||||
|
database.prepare("update LotTypes set orderNumber = -1 where lotTypeId = ?").run(lotTypeId);
|
||||||
|
database
|
||||||
|
.prepare("update LotTypes" +
|
||||||
|
" set orderNumber = orderNumber + 1" +
|
||||||
|
" where recordDelete_timeMillis is null" +
|
||||||
|
" and orderNumber < ?")
|
||||||
|
.run(currentOrderNumber);
|
||||||
|
}
|
||||||
|
database.close();
|
||||||
|
clearLotTypesCache();
|
||||||
|
return true;
|
||||||
|
};
|
||||||
export default moveLotTypeUp;
|
export default moveLotTypeUp;
|
||||||
|
|
|
||||||
|
|
@ -4,17 +4,11 @@ import { lotOccupancyDB as databasePath } from "../../data/databasePaths.js";
|
||||||
|
|
||||||
import { clearLotTypesCache } from "../functions.cache.js";
|
import { clearLotTypesCache } from "../functions.cache.js";
|
||||||
|
|
||||||
export const moveLotTypeUp = (
|
export const moveLotTypeUp = (lotTypeId: number | string): boolean => {
|
||||||
lotTypeId: number | string
|
|
||||||
): boolean => {
|
|
||||||
const database = sqlite(databasePath);
|
const database = sqlite(databasePath);
|
||||||
|
|
||||||
const currentOrderNumber: number = database
|
const currentOrderNumber: number = database
|
||||||
.prepare(
|
.prepare("select orderNumber from LotTypes where lotTypeId = ?")
|
||||||
"select orderNumber" +
|
|
||||||
" from LotTypes" +
|
|
||||||
" where lotTypeId = ?"
|
|
||||||
)
|
|
||||||
.get(lotTypeId).orderNumber;
|
.get(lotTypeId).orderNumber;
|
||||||
|
|
||||||
if (currentOrderNumber <= 0) {
|
if (currentOrderNumber <= 0) {
|
||||||
|
|
@ -32,11 +26,7 @@ export const moveLotTypeUp = (
|
||||||
.run(currentOrderNumber);
|
.run(currentOrderNumber);
|
||||||
|
|
||||||
const result = database
|
const result = database
|
||||||
.prepare(
|
.prepare("update LotTypes set orderNumber = ? - 1 where lotTypeId = ?")
|
||||||
"update LotTypes" +
|
|
||||||
" set orderNumber = ? - 1" +
|
|
||||||
" where lotTypeId = ?"
|
|
||||||
)
|
|
||||||
.run(currentOrderNumber, lotTypeId);
|
.run(currentOrderNumber, lotTypeId);
|
||||||
|
|
||||||
database.close();
|
database.close();
|
||||||
|
|
@ -46,4 +36,31 @@ export const moveLotTypeUp = (
|
||||||
return result.changes > 0;
|
return result.changes > 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const moveLotTypeUpToTop = (lotTypeId: number | string): boolean => {
|
||||||
|
const database = sqlite(databasePath);
|
||||||
|
|
||||||
|
const currentOrderNumber: number = database
|
||||||
|
.prepare("select orderNumber from LotTypes where lotTypeId = ?")
|
||||||
|
.get(lotTypeId).orderNumber;
|
||||||
|
|
||||||
|
if (currentOrderNumber > 0) {
|
||||||
|
database.prepare("update LotTypes set orderNumber = -1 where lotTypeId = ?").run(lotTypeId);
|
||||||
|
|
||||||
|
database
|
||||||
|
.prepare(
|
||||||
|
"update LotTypes" +
|
||||||
|
" set orderNumber = orderNumber + 1" +
|
||||||
|
" where recordDelete_timeMillis is null" +
|
||||||
|
" and orderNumber < ?"
|
||||||
|
)
|
||||||
|
.run(currentOrderNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
database.close();
|
||||||
|
|
||||||
|
clearLotTypesCache();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
export default moveLotTypeUp;
|
export default moveLotTypeUp;
|
||||||
|
|
|
||||||
|
|
@ -127,14 +127,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
clickEvent.preventDefault();
|
clickEvent.preventDefault();
|
||||||
const lotTypeId = clickEvent.currentTarget.closest(".container--lotType").dataset.lotTypeId;
|
const lotTypeId = clickEvent.currentTarget.closest(".container--lotType").dataset.lotTypeId;
|
||||||
cityssm.postJSON(urlPrefix + "/admin/doMoveLotTypeUp", {
|
cityssm.postJSON(urlPrefix + "/admin/doMoveLotTypeUp", {
|
||||||
lotTypeId
|
lotTypeId,
|
||||||
|
moveToTop: clickEvent.shiftKey ? "1" : "0"
|
||||||
}, lotTypeResponseHandler);
|
}, lotTypeResponseHandler);
|
||||||
};
|
};
|
||||||
const moveLotTypeDown = (clickEvent) => {
|
const moveLotTypeDown = (clickEvent) => {
|
||||||
clickEvent.preventDefault();
|
clickEvent.preventDefault();
|
||||||
const lotTypeId = clickEvent.currentTarget.closest(".container--lotType").dataset.lotTypeId;
|
const lotTypeId = clickEvent.currentTarget.closest(".container--lotType").dataset.lotTypeId;
|
||||||
cityssm.postJSON(urlPrefix + "/admin/doMoveLotTypeDown", {
|
cityssm.postJSON(urlPrefix + "/admin/doMoveLotTypeDown", {
|
||||||
lotTypeId
|
lotTypeId,
|
||||||
|
moveToBottom: clickEvent.shiftKey ? "1" : "0"
|
||||||
}, lotTypeResponseHandler);
|
}, lotTypeResponseHandler);
|
||||||
};
|
};
|
||||||
const openEditLotTypeField = (lotTypeId, lotTypeFieldId) => {
|
const openEditLotTypeField = (lotTypeId, lotTypeFieldId) => {
|
||||||
|
|
@ -239,14 +241,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
clickEvent.preventDefault();
|
clickEvent.preventDefault();
|
||||||
const lotTypeFieldId = clickEvent.currentTarget.closest(".container--lotTypeField").dataset.lotTypeFieldId;
|
const lotTypeFieldId = clickEvent.currentTarget.closest(".container--lotTypeField").dataset.lotTypeFieldId;
|
||||||
cityssm.postJSON(urlPrefix + "/admin/doMoveLotTypeFieldUp", {
|
cityssm.postJSON(urlPrefix + "/admin/doMoveLotTypeFieldUp", {
|
||||||
lotTypeFieldId
|
lotTypeFieldId,
|
||||||
|
moveToTop: clickEvent.shiftKey ? "1" : "0"
|
||||||
}, lotTypeResponseHandler);
|
}, lotTypeResponseHandler);
|
||||||
};
|
};
|
||||||
const moveLotTypeFieldDown = (clickEvent) => {
|
const moveLotTypeFieldDown = (clickEvent) => {
|
||||||
clickEvent.preventDefault();
|
clickEvent.preventDefault();
|
||||||
const lotTypeFieldId = clickEvent.currentTarget.closest(".container--lotTypeField").dataset.lotTypeFieldId;
|
const lotTypeFieldId = clickEvent.currentTarget.closest(".container--lotTypeField").dataset.lotTypeFieldId;
|
||||||
cityssm.postJSON(urlPrefix + "/admin/doMoveLotTypeFieldDown", {
|
cityssm.postJSON(urlPrefix + "/admin/doMoveLotTypeFieldDown", {
|
||||||
lotTypeFieldId
|
lotTypeFieldId,
|
||||||
|
moveToBottom: clickEvent.shiftKey ? "1" : "0"
|
||||||
}, lotTypeResponseHandler);
|
}, lotTypeResponseHandler);
|
||||||
};
|
};
|
||||||
const renderLotTypeFields = (panelElement, lotTypeId, lotTypeFields) => {
|
const renderLotTypeFields = (panelElement, lotTypeId, lotTypeFields) => {
|
||||||
|
|
|
||||||
|
|
@ -221,7 +221,7 @@ declare const bulmaJS: BulmaJS;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const moveLotTypeUp = (clickEvent: Event) => {
|
const moveLotTypeUp = (clickEvent: MouseEvent) => {
|
||||||
clickEvent.preventDefault();
|
clickEvent.preventDefault();
|
||||||
|
|
||||||
const lotTypeId = (
|
const lotTypeId = (
|
||||||
|
|
@ -231,13 +231,14 @@ declare const bulmaJS: BulmaJS;
|
||||||
cityssm.postJSON(
|
cityssm.postJSON(
|
||||||
urlPrefix + "/admin/doMoveLotTypeUp",
|
urlPrefix + "/admin/doMoveLotTypeUp",
|
||||||
{
|
{
|
||||||
lotTypeId
|
lotTypeId,
|
||||||
|
moveToTop: clickEvent.shiftKey ? "1" : "0"
|
||||||
},
|
},
|
||||||
lotTypeResponseHandler
|
lotTypeResponseHandler
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const moveLotTypeDown = (clickEvent: Event) => {
|
const moveLotTypeDown = (clickEvent: MouseEvent) => {
|
||||||
clickEvent.preventDefault();
|
clickEvent.preventDefault();
|
||||||
|
|
||||||
const lotTypeId = (
|
const lotTypeId = (
|
||||||
|
|
@ -247,7 +248,8 @@ declare const bulmaJS: BulmaJS;
|
||||||
cityssm.postJSON(
|
cityssm.postJSON(
|
||||||
urlPrefix + "/admin/doMoveLotTypeDown",
|
urlPrefix + "/admin/doMoveLotTypeDown",
|
||||||
{
|
{
|
||||||
lotTypeId
|
lotTypeId,
|
||||||
|
moveToBottom: clickEvent.shiftKey ? "1" : "0"
|
||||||
},
|
},
|
||||||
lotTypeResponseHandler
|
lotTypeResponseHandler
|
||||||
);
|
);
|
||||||
|
|
@ -429,7 +431,7 @@ declare const bulmaJS: BulmaJS;
|
||||||
openEditLotTypeField(lotTypeId, lotTypeFieldId);
|
openEditLotTypeField(lotTypeId, lotTypeFieldId);
|
||||||
};
|
};
|
||||||
|
|
||||||
const moveLotTypeFieldUp = (clickEvent: Event) => {
|
const moveLotTypeFieldUp = (clickEvent: MouseEvent) => {
|
||||||
clickEvent.preventDefault();
|
clickEvent.preventDefault();
|
||||||
|
|
||||||
const lotTypeFieldId = (
|
const lotTypeFieldId = (
|
||||||
|
|
@ -441,13 +443,14 @@ declare const bulmaJS: BulmaJS;
|
||||||
cityssm.postJSON(
|
cityssm.postJSON(
|
||||||
urlPrefix + "/admin/doMoveLotTypeFieldUp",
|
urlPrefix + "/admin/doMoveLotTypeFieldUp",
|
||||||
{
|
{
|
||||||
lotTypeFieldId
|
lotTypeFieldId,
|
||||||
|
moveToTop: clickEvent.shiftKey ? "1" : "0"
|
||||||
},
|
},
|
||||||
lotTypeResponseHandler
|
lotTypeResponseHandler
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const moveLotTypeFieldDown = (clickEvent: Event) => {
|
const moveLotTypeFieldDown = (clickEvent: MouseEvent) => {
|
||||||
clickEvent.preventDefault();
|
clickEvent.preventDefault();
|
||||||
|
|
||||||
const lotTypeFieldId = (
|
const lotTypeFieldId = (
|
||||||
|
|
@ -459,7 +462,8 @@ declare const bulmaJS: BulmaJS;
|
||||||
cityssm.postJSON(
|
cityssm.postJSON(
|
||||||
urlPrefix + "/admin/doMoveLotTypeFieldDown",
|
urlPrefix + "/admin/doMoveLotTypeFieldDown",
|
||||||
{
|
{
|
||||||
lotTypeFieldId
|
lotTypeFieldId,
|
||||||
|
moveToBottom: clickEvent.shiftKey ? "1" : "0"
|
||||||
},
|
},
|
||||||
lotTypeResponseHandler
|
lotTypeResponseHandler
|
||||||
);
|
);
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue