reduce move duplication

deepsource-autofix-76c6eb20
Dan Gowans 2023-01-04 14:20:16 -05:00
parent 32b32cf43a
commit 35dbc09d82
14 changed files with 58 additions and 150 deletions

View File

@ -1,7 +1,7 @@
import { moveFeeCategoryDown, moveFeeCategoryDownToBottom } from "../../helpers/lotOccupancyDB/moveFeeCategoryDown.js"; import { moveFeeCategoryDown, moveFeeCategoryDownToBottom } from "../../helpers/lotOccupancyDB/moveFeeCategoryDown.js";
import { getFeeCategories } from "../../helpers/lotOccupancyDB/getFeeCategories.js"; import { getFeeCategories } from "../../helpers/lotOccupancyDB/getFeeCategories.js";
export const handler = async (request, response) => { export const handler = async (request, response) => {
const success = request.body.moveToBottom === "1" const success = request.body.moveToEnd === "1"
? moveFeeCategoryDownToBottom(request.body.feeCategoryId) ? moveFeeCategoryDownToBottom(request.body.feeCategoryId)
: moveFeeCategoryDown(request.body.feeCategoryId); : moveFeeCategoryDown(request.body.feeCategoryId);
const feeCategories = getFeeCategories({}, { const feeCategories = getFeeCategories({}, {

View File

@ -9,7 +9,7 @@ import { getFeeCategories } from "../../helpers/lotOccupancyDB/getFeeCategories.
export const handler: RequestHandler = async (request, response) => { export const handler: RequestHandler = async (request, response) => {
const success = const success =
request.body.moveToBottom === "1" request.body.moveToEnd === "1"
? moveFeeCategoryDownToBottom(request.body.feeCategoryId) ? moveFeeCategoryDownToBottom(request.body.feeCategoryId)
: moveFeeCategoryDown(request.body.feeCategoryId); : moveFeeCategoryDown(request.body.feeCategoryId);

View File

@ -1,7 +1,7 @@
import { moveFeeCategoryUp, moveFeeCategoryUpToTop } from "../../helpers/lotOccupancyDB/moveFeeCategoryUp.js"; import { moveFeeCategoryUp, moveFeeCategoryUpToTop } from "../../helpers/lotOccupancyDB/moveFeeCategoryUp.js";
import { getFeeCategories } from "../../helpers/lotOccupancyDB/getFeeCategories.js"; import { getFeeCategories } from "../../helpers/lotOccupancyDB/getFeeCategories.js";
export const handler = async (request, response) => { export const handler = async (request, response) => {
const success = request.body.moveToTop === "1" const success = request.body.moveToEnd === "1"
? moveFeeCategoryUpToTop(request.body.feeCategoryId) ? moveFeeCategoryUpToTop(request.body.feeCategoryId)
: moveFeeCategoryUp(request.body.feeCategoryId); : moveFeeCategoryUp(request.body.feeCategoryId);
const feeCategories = getFeeCategories({}, { const feeCategories = getFeeCategories({}, {

View File

@ -9,7 +9,7 @@ import { getFeeCategories } from "../../helpers/lotOccupancyDB/getFeeCategories.
export const handler: RequestHandler = async (request, response) => { export const handler: RequestHandler = async (request, response) => {
const success = const success =
request.body.moveToTop === "1" request.body.moveToEnd === "1"
? moveFeeCategoryUpToTop(request.body.feeCategoryId) ? moveFeeCategoryUpToTop(request.body.feeCategoryId)
: moveFeeCategoryUp(request.body.feeCategoryId); : moveFeeCategoryUp(request.body.feeCategoryId);

View File

@ -1,7 +1,7 @@
import { moveFeeDown, moveFeeDownToBottom } from "../../helpers/lotOccupancyDB/moveFeeDown.js"; import { moveFeeDown, moveFeeDownToBottom } from "../../helpers/lotOccupancyDB/moveFeeDown.js";
import { getFeeCategories } from "../../helpers/lotOccupancyDB/getFeeCategories.js"; import { getFeeCategories } from "../../helpers/lotOccupancyDB/getFeeCategories.js";
export const handler = async (request, response) => { export const handler = async (request, response) => {
const success = request.body.moveToBottom === "1" const success = request.body.moveToEnd === "1"
? moveFeeDownToBottom(request.body.feeId) ? moveFeeDownToBottom(request.body.feeId)
: moveFeeDown(request.body.feeId); : moveFeeDown(request.body.feeId);
const feeCategories = getFeeCategories({}, { const feeCategories = getFeeCategories({}, {

View File

@ -6,7 +6,7 @@ import { getFeeCategories } from "../../helpers/lotOccupancyDB/getFeeCategories.
export const handler: RequestHandler = async (request, response) => { export const handler: RequestHandler = async (request, response) => {
const success = const success =
request.body.moveToBottom === "1" request.body.moveToEnd === "1"
? moveFeeDownToBottom(request.body.feeId) ? moveFeeDownToBottom(request.body.feeId)
: moveFeeDown(request.body.feeId); : moveFeeDown(request.body.feeId);

View File

@ -1,7 +1,7 @@
import { moveFeeUp, moveFeeUpToTop } from "../../helpers/lotOccupancyDB/moveFeeUp.js"; import { moveFeeUp, moveFeeUpToTop } from "../../helpers/lotOccupancyDB/moveFeeUp.js";
import { getFeeCategories } from "../../helpers/lotOccupancyDB/getFeeCategories.js"; import { getFeeCategories } from "../../helpers/lotOccupancyDB/getFeeCategories.js";
export const handler = async (request, response) => { export const handler = async (request, response) => {
const success = request.body.moveToTop === "1" const success = request.body.moveToEnd === "1"
? moveFeeUpToTop(request.body.feeId) ? moveFeeUpToTop(request.body.feeId)
: moveFeeUp(request.body.feeId); : moveFeeUp(request.body.feeId);
const feeCategories = getFeeCategories({}, { const feeCategories = getFeeCategories({}, {

View File

@ -6,7 +6,7 @@ import { getFeeCategories } from "../../helpers/lotOccupancyDB/getFeeCategories.
export const handler: RequestHandler = async (request, response) => { export const handler: RequestHandler = async (request, response) => {
const success = const success =
request.body.moveToTop === "1" request.body.moveToEnd === "1"
? moveFeeUpToTop(request.body.feeId) ? moveFeeUpToTop(request.body.feeId)
: moveFeeUp(request.body.feeId); : moveFeeUp(request.body.feeId);

View File

@ -142,8 +142,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
"</div>") + "</div>") +
"</div>"; "</div>";
panelBlockElement.querySelector("a").addEventListener("click", openEditFee); panelBlockElement.querySelector("a").addEventListener("click", openEditFee);
panelBlockElement.querySelector(".button--moveFeeUp").addEventListener("click", moveFeeUp); panelBlockElement.querySelector(".button--moveFeeUp").addEventListener("click", moveFee);
panelBlockElement.querySelector(".button--moveFeeDown").addEventListener("click", moveFeeDown); panelBlockElement.querySelector(".button--moveFeeDown").addEventListener("click", moveFee);
feeCategoryContainerElement.append(panelBlockElement); feeCategoryContainerElement.append(panelBlockElement);
} }
} }
@ -153,8 +153,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
feeCategoryContainerElement feeCategoryContainerElement
.querySelector(".button--addFee") .querySelector(".button--addFee")
.addEventListener("click", openAddFee); .addEventListener("click", openAddFee);
feeCategoryContainerElement.querySelector(".button--moveFeeCategoryUp").addEventListener("click", moveFeeCategoryUp); feeCategoryContainerElement.querySelector(".button--moveFeeCategoryUp").addEventListener("click", moveFeeCategory);
feeCategoryContainerElement.querySelector(".button--moveFeeCategoryDown").addEventListener("click", moveFeeCategoryDown); feeCategoryContainerElement.querySelector(".button--moveFeeCategoryDown").addEventListener("click", moveFeeCategory);
feeCategoriesContainerElement.append(feeCategoryContainerElement); feeCategoriesContainerElement.append(feeCategoryContainerElement);
} }
} }
@ -260,30 +260,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
} }
}); });
} }
function moveFeeCategoryUp(clickEvent) { function moveFeeCategory(clickEvent) {
const feeCategoryId = Number.parseInt(clickEvent.currentTarget.closest(".container--feeCategory").dataset.feeCategoryId, 10); const buttonElement = clickEvent.currentTarget;
cityssm.postJSON(los.urlPrefix + "/admin/doMoveFeeCategoryUp", { const feeCategoryId = Number.parseInt(buttonElement.closest(".container--feeCategory").dataset
.feeCategoryId, 10);
cityssm.postJSON(los.urlPrefix +
"/admin/" +
(buttonElement.dataset.direction === "up"
? "doMoveFeeCategoryUp"
: "doMoveFeeCategoryDown"), {
feeCategoryId, feeCategoryId,
moveToTop: clickEvent.shiftKey ? "1" : "0" moveToEnd: clickEvent.shiftKey ? "1" : "0"
}, (responseJSON) => {
if (responseJSON.success) {
feeCategories = responseJSON.feeCategories;
renderFeeCategories();
}
else {
bulmaJS.alert({
title: "Error Moving Fee Category",
message: responseJSON.errorMessage || "",
contextualColorName: "danger"
});
}
});
}
function moveFeeCategoryDown(clickEvent) {
const feeCategoryId = Number.parseInt(clickEvent.currentTarget.closest(".container--feeCategory").dataset.feeCategoryId, 10);
cityssm.postJSON(los.urlPrefix + "/admin/doMoveFeeCategoryDown", {
feeCategoryId,
moveToBottom: clickEvent.shiftKey ? "1" : "0"
}, (responseJSON) => { }, (responseJSON) => {
if (responseJSON.success) { if (responseJSON.success) {
feeCategories = responseJSON.feeCategories; feeCategories = responseJSON.feeCategories;
@ -562,32 +549,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
} }
}); });
} }
function moveFeeUp(clickEvent) { function moveFee(clickEvent) {
const feeContainerElement = clickEvent.currentTarget.closest(".container--fee"); const buttonElement = clickEvent.currentTarget;
const feeContainerElement = buttonElement.closest(".container--fee");
const feeId = Number.parseInt(feeContainerElement.dataset.feeId, 10); const feeId = Number.parseInt(feeContainerElement.dataset.feeId, 10);
cityssm.postJSON(los.urlPrefix + "/admin/doMoveFeeUp", { cityssm.postJSON(los.urlPrefix +
"/admin/" +
(buttonElement.dataset.direction === "up" ? "doMoveFeeUp" : "doMoveFeeDown"), {
feeId, feeId,
moveToTop: clickEvent.shiftKey ? "1" : "0" moveToEnd: clickEvent.shiftKey ? "1" : "0"
}, (responseJSON) => {
if (responseJSON.success) {
feeCategories = responseJSON.feeCategories;
renderFeeCategories();
}
else {
bulmaJS.alert({
title: "Error Moving Fee",
message: responseJSON.errorMessage || "",
contextualColorName: "danger"
});
}
});
}
function moveFeeDown(clickEvent) {
const feeContainerElement = clickEvent.currentTarget.closest(".container--fee");
const feeId = Number.parseInt(feeContainerElement.dataset.feeId, 10);
cityssm.postJSON(los.urlPrefix + "/admin/doMoveFeeDown", {
feeId,
moveToBottom: clickEvent.shiftKey ? "1" : "0"
}, (responseJSON) => { }, (responseJSON) => {
if (responseJSON.success) { if (responseJSON.success) {
feeCategories = responseJSON.feeCategories; feeCategories = responseJSON.feeCategories;

View File

@ -179,11 +179,11 @@ declare const bulmaJS: BulmaJS;
( (
panelBlockElement.querySelector(".button--moveFeeUp") as HTMLButtonElement panelBlockElement.querySelector(".button--moveFeeUp") as HTMLButtonElement
).addEventListener("click", moveFeeUp); ).addEventListener("click", moveFee);
( (
panelBlockElement.querySelector(".button--moveFeeDown") as HTMLButtonElement panelBlockElement.querySelector(".button--moveFeeDown") as HTMLButtonElement
).addEventListener("click", moveFeeDown); ).addEventListener("click", moveFee);
feeCategoryContainerElement.append(panelBlockElement); feeCategoryContainerElement.append(panelBlockElement);
} }
@ -201,13 +201,13 @@ declare const bulmaJS: BulmaJS;
feeCategoryContainerElement.querySelector( feeCategoryContainerElement.querySelector(
".button--moveFeeCategoryUp" ".button--moveFeeCategoryUp"
) as HTMLButtonElement ) as HTMLButtonElement
).addEventListener("click", moveFeeCategoryUp); ).addEventListener("click", moveFeeCategory);
( (
feeCategoryContainerElement.querySelector( feeCategoryContainerElement.querySelector(
".button--moveFeeCategoryDown" ".button--moveFeeCategoryDown"
) as HTMLButtonElement ) as HTMLButtonElement
).addEventListener("click", moveFeeCategoryDown); ).addEventListener("click", moveFeeCategory);
feeCategoriesContainerElement.append(feeCategoryContainerElement); feeCategoriesContainerElement.append(feeCategoryContainerElement);
} }
@ -378,56 +378,24 @@ declare const bulmaJS: BulmaJS;
}); });
} }
function moveFeeCategoryUp(clickEvent: MouseEvent): void { function moveFeeCategory(clickEvent: MouseEvent): void {
const buttonElement = clickEvent.currentTarget as HTMLButtonElement;
const feeCategoryId = Number.parseInt( const feeCategoryId = Number.parseInt(
( (buttonElement.closest(".container--feeCategory") as HTMLElement).dataset
(clickEvent.currentTarget as HTMLElement).closest( .feeCategoryId!,
".container--feeCategory"
) as HTMLElement
).dataset.feeCategoryId!,
10 10
); );
cityssm.postJSON( cityssm.postJSON(
los.urlPrefix + "/admin/doMoveFeeCategoryUp", los.urlPrefix +
"/admin/" +
(buttonElement.dataset.direction === "up"
? "doMoveFeeCategoryUp"
: "doMoveFeeCategoryDown"),
{ {
feeCategoryId, feeCategoryId,
moveToTop: clickEvent.shiftKey ? "1" : "0" moveToEnd: clickEvent.shiftKey ? "1" : "0"
},
(responseJSON: {
success: boolean;
errorMessage?: string;
feeCategories?: recordTypes.FeeCategory[];
}) => {
if (responseJSON.success) {
feeCategories = responseJSON.feeCategories!;
renderFeeCategories();
} else {
bulmaJS.alert({
title: "Error Moving Fee Category",
message: responseJSON.errorMessage || "",
contextualColorName: "danger"
});
}
}
);
}
function moveFeeCategoryDown(clickEvent: MouseEvent): void {
const feeCategoryId = Number.parseInt(
(
(clickEvent.currentTarget as HTMLElement).closest(
".container--feeCategory"
) as HTMLElement
).dataset.feeCategoryId!,
10
);
cityssm.postJSON(
los.urlPrefix + "/admin/doMoveFeeCategoryDown",
{
feeCategoryId,
moveToBottom: clickEvent.shiftKey ? "1" : "0"
}, },
(responseJSON: { (responseJSON: {
success: boolean; success: boolean;
@ -874,50 +842,20 @@ declare const bulmaJS: BulmaJS;
}); });
} }
function moveFeeUp(clickEvent: MouseEvent): void { function moveFee(clickEvent: MouseEvent): void {
const feeContainerElement = (clickEvent.currentTarget as HTMLElement).closest( const buttonElement = clickEvent.currentTarget as HTMLButtonElement;
".container--fee"
) as HTMLElement; const feeContainerElement = buttonElement.closest(".container--fee") as HTMLElement;
const feeId = Number.parseInt(feeContainerElement.dataset.feeId!, 10); const feeId = Number.parseInt(feeContainerElement.dataset.feeId!, 10);
cityssm.postJSON( cityssm.postJSON(
los.urlPrefix + "/admin/doMoveFeeUp", los.urlPrefix +
"/admin/" +
(buttonElement.dataset.direction === "up" ? "doMoveFeeUp" : "doMoveFeeDown"),
{ {
feeId, feeId,
moveToTop: clickEvent.shiftKey ? "1" : "0" moveToEnd: clickEvent.shiftKey ? "1" : "0"
},
(responseJSON: {
success: boolean;
errorMessage?: string;
feeCategories?: recordTypes.FeeCategory[];
}) => {
if (responseJSON.success) {
feeCategories = responseJSON.feeCategories!;
renderFeeCategories();
} else {
bulmaJS.alert({
title: "Error Moving Fee",
message: responseJSON.errorMessage || "",
contextualColorName: "danger"
});
}
}
);
}
function moveFeeDown(clickEvent: MouseEvent): void {
const feeContainerElement = (clickEvent.currentTarget as HTMLElement).closest(
".container--fee"
) as HTMLElement;
const feeId = Number.parseInt(feeContainerElement.dataset.feeId!, 10);
cityssm.postJSON(
los.urlPrefix + "/admin/doMoveFeeDown",
{
feeId,
moveToBottom: clickEvent.shiftKey ? "1" : "0"
}, },
(responseJSON: { (responseJSON: {
success: boolean; success: boolean;

View File

@ -293,14 +293,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
<div class="control"> <div class="control">
<button <button
class="button ${isSmall ? "is-small" : ""} ${upButtonClassNames}" class="button ${isSmall ? "is-small" : ""} ${upButtonClassNames}"
data-tooltip="Move Up" type="button" aria-label="Move Up"> data-tooltip="Move Up" data-direction="up" type="button" aria-label="Move Up">
<i class="fas fa-arrow-up" aria-hidden="true"></i> <i class="fas fa-arrow-up" aria-hidden="true"></i>
</button> </button>
</div> </div>
<div class="control"> <div class="control">
<button <button
class="button ${isSmall ? "is-small" : ""} ${downButtonClassNames}" class="button ${isSmall ? "is-small" : ""} ${downButtonClassNames}"
data-tooltip="Move Down" type="button" aria-label="Move Down"> data-tooltip="Move Down" data-direction="down" type="button" aria-label="Move Down">
<i class="fas fa-arrow-down" aria-hidden="true"></i> <i class="fas fa-arrow-down" aria-hidden="true"></i>
</button> </button>
</div> </div>

View File

@ -376,14 +376,14 @@ declare const bulmaJS: BulmaJS;
<div class="control"> <div class="control">
<button <button
class="button ${isSmall ? "is-small" : ""} ${upButtonClassNames}" class="button ${isSmall ? "is-small" : ""} ${upButtonClassNames}"
data-tooltip="Move Up" type="button" aria-label="Move Up"> data-tooltip="Move Up" data-direction="up" type="button" aria-label="Move Up">
<i class="fas fa-arrow-up" aria-hidden="true"></i> <i class="fas fa-arrow-up" aria-hidden="true"></i>
</button> </button>
</div> </div>
<div class="control"> <div class="control">
<button <button
class="button ${isSmall ? "is-small" : ""} ${downButtonClassNames}" class="button ${isSmall ? "is-small" : ""} ${downButtonClassNames}"
data-tooltip="Move Down" type="button" aria-label="Move Down"> data-tooltip="Move Down" data-direction="down" type="button" aria-label="Move Down">
<i class="fas fa-arrow-down" aria-hidden="true"></i> <i class="fas fa-arrow-down" aria-hidden="true"></i>
</button> </button>
</div> </div>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long