Skip to content

Commit

Permalink
current status type key filter
Browse files Browse the repository at this point in the history
  • Loading branch information
dangowans committed Jan 4, 2022
1 parent 2c3fc97 commit e85d0b9
Show file tree
Hide file tree
Showing 14 changed files with 175 additions and 8 deletions.
3 changes: 2 additions & 1 deletion handlers/dashboard/doGetRecords.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ export const handler = async (request, response) => {
recordNumber: request.body.recordNumber,
recordTag: request.body.recordTag,
recordDateStringGTE: request.body["recordDateString-gte"],
recordDateStringLTE: request.body["recordDateString-lte"]
recordDateStringLTE: request.body["recordDateString-lte"],
statusTypeKey: request.body.statusTypeKey
}, {
limit: Number.parseInt(request.body.limit, 10),
offset: Number.parseInt(request.body.offset, 10)
Expand Down
3 changes: 2 additions & 1 deletion handlers/dashboard/doGetRecords.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export const handler: RequestHandler = async (request, response) => {
recordNumber: request.body.recordNumber,
recordTag: request.body.recordTag,
recordDateStringGTE: request.body["recordDateString-gte"],
recordDateStringLTE: request.body["recordDateString-lte"]
recordDateStringLTE: request.body["recordDateString-lte"],
statusTypeKey: request.body.statusTypeKey
}, {
limit: Number.parseInt(request.body.limit, 10),
offset: Number.parseInt(request.body.offset, 10)
Expand Down
3 changes: 3 additions & 0 deletions handlers/dashboard/doGetStatusTypes.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import type { RequestHandler } from "express";
export declare const handler: RequestHandler;
export default handler;
8 changes: 8 additions & 0 deletions handlers/dashboard/doGetStatusTypes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { getStatusTypes } from "../../helpers/recordsDB/getStatusTypes.js";
export const handler = async (request, response) => {
const statusTypes = await getStatusTypes(request.body.recordTypeKey);
return response.json({
statusTypes
});
};
export default handler;
16 changes: 16 additions & 0 deletions handlers/dashboard/doGetStatusTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { RequestHandler } from "express";

import { getStatusTypes } from "../../helpers/recordsDB/getStatusTypes.js";


export const handler: RequestHandler = async (request, response) => {

const statusTypes = await getStatusTypes(request.body.recordTypeKey);

return response.json({
statusTypes
});
};


export default handler;
1 change: 1 addition & 0 deletions helpers/recordsDB/getRecords.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export declare const getRecords: (parameters: {
recordTag?: string;
recordDateStringGTE?: string;
recordDateStringLTE?: string;
statusTypeKey?: string;
}, options: {
limit: number;
offset: number;
Expand Down
14 changes: 13 additions & 1 deletion helpers/recordsDB/getRecords.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ export const getRecords = async (parameters, options, requestSession) => {
resultsRequest = resultsRequest.input("recordDateStringLTE", parameters.recordDateStringLTE);
whereSQL += " and recordDate <= @recordDateStringLTE";
}
if (parameters.statusTypeKey && parameters.statusTypeKey !== "") {
countRequest = countRequest.input("statusTypeKey", parameters.statusTypeKey);
resultsRequest = resultsRequest.input("statusTypeKey", parameters.statusTypeKey);
whereSQL += " and s.statusTypeKey = @statusTypeKey";
}
if (parameters.searchString !== "") {
const searchStringSplit = parameters.searchString.trim().split(" ");
for (const [index, element] of searchStringSplit.entries()) {
Expand All @@ -57,7 +62,14 @@ export const getRecords = async (parameters, options, requestSession) => {
")";
}
}
const countResult = await countRequest.query("select count(*) as cnt from CR.Records" +
const countResult = await countRequest.query("select count(*) as cnt from CR.Records r" +
" outer apply (" +
"select top 1 s.statusTime, s.statusTypeKey, t.statusType" +
" from CR.RecordStatusLog s" +
" left join CR.StatusTypes t on s.statusTypeKey = t.statusTypeKey" +
" where r.recordID = s.recordID" +
" and recordDelete_datetime is null" +
" order by statusTime desc, statusLogID desc) s" +
whereSQL);
returnObject.count = countResult.recordset[0].cnt;
if (returnObject.count === 0) {
Expand Down
16 changes: 15 additions & 1 deletion helpers/recordsDB/getRecords.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const getRecords = async (parameters: {
recordTag?: string;
recordDateStringGTE?: string;
recordDateStringLTE?: string;
statusTypeKey?: string;
}, options: {
limit: number;
offset: number;
Expand Down Expand Up @@ -76,6 +77,12 @@ export const getRecords = async (parameters: {
whereSQL += " and recordDate <= @recordDateStringLTE";
}

if (parameters.statusTypeKey && parameters.statusTypeKey !== "") {
countRequest = countRequest.input("statusTypeKey", parameters.statusTypeKey);
resultsRequest = resultsRequest.input("statusTypeKey", parameters.statusTypeKey);
whereSQL += " and s.statusTypeKey = @statusTypeKey";
}

if (parameters.searchString !== "") {

const searchStringSplit = parameters.searchString.trim().split(" ");
Expand All @@ -97,7 +104,14 @@ export const getRecords = async (parameters: {
}
}

const countResult = await countRequest.query("select count(*) as cnt from CR.Records" +
const countResult = await countRequest.query("select count(*) as cnt from CR.Records r" +
" outer apply (" +
"select top 1 s.statusTime, s.statusTypeKey, t.statusType" +
" from CR.RecordStatusLog s" +
" left join CR.StatusTypes t on s.statusTypeKey = t.statusTypeKey" +
" where r.recordID = s.recordID" +
" and recordDelete_datetime is null" +
" order by statusTime desc, statusLogID desc) s" +
whereSQL);

returnObject.count = countResult.recordset[0].cnt;
Expand Down
35 changes: 35 additions & 0 deletions public-typescript/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,41 @@ Object.defineProperty(exports, "__esModule", { value: true });
offsetElement.value = "0";
searchRecordsFunction();
};
const recordTypeKeyElement = document.querySelector("#search--recordTypeKey");
const statusTypeKeyElement = document.querySelector("#search--statusTypeKey");
const statusTypeKeyMap = new Map();
const renderStatusTypeKey = () => {
statusTypeKeyElement.innerHTML = "<option value=\"\" selected>(All Statuses)</option>";
if (!statusTypeKeyMap.has(recordTypeKeyElement.value)) {
return;
}
for (const statusType of statusTypeKeyMap.get(recordTypeKeyElement.value)) {
if (!statusType.isActive || statusType.recordCount === 0) {
continue;
}
const optionElement = document.createElement("option");
optionElement.value = statusType.statusTypeKey;
optionElement.textContent = statusType.statusType;
statusTypeKeyElement.append(optionElement);
}
};
recordTypeKeyElement.addEventListener("change", () => {
statusTypeKeyElement.innerHTML = "<option value=\"\" selected>(All Statuses)</option>";
if (recordTypeKeyElement.value === "") {
}
else if (statusTypeKeyMap.has(recordTypeKeyElement.value)) {
renderStatusTypeKey();
}
else {
const recordTypeKey = recordTypeKeyElement.value;
cityssm.postJSON(urlPrefix + "/dashboard/doGetStatusTypes", {
recordTypeKey
}, (responseJSON) => {
statusTypeKeyMap.set(recordTypeKey, responseJSON.statusTypes);
renderStatusTypeKey();
});
}
});
searchFormElement.addEventListener("submit", resetOffsetAndSearchFunction);
const filterElements = searchFormElement.querySelectorAll("input, select");
for (const filterElement of filterElements) {
Expand Down
57 changes: 57 additions & 0 deletions public-typescript/dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,63 @@ declare const cityssm: cityssmGlobal;
searchRecordsFunction();
};

/*
* Status Type Key
*/

const recordTypeKeyElement = document.querySelector("#search--recordTypeKey") as HTMLSelectElement;
const statusTypeKeyElement = document.querySelector("#search--statusTypeKey") as HTMLSelectElement;

const statusTypeKeyMap = new Map<string, recordTypes.StatusType[]>();

const renderStatusTypeKey = () => {

statusTypeKeyElement.innerHTML = "<option value=\"\" selected>(All Statuses)</option>";

if (!statusTypeKeyMap.has(recordTypeKeyElement.value)) {
return;
}

for (const statusType of statusTypeKeyMap.get(recordTypeKeyElement.value)) {

if (!statusType.isActive || statusType.recordCount === 0) {
continue;
}

const optionElement = document.createElement("option");
optionElement.value = statusType.statusTypeKey;
optionElement.textContent = statusType.statusType;
statusTypeKeyElement.append(optionElement);
}
};

recordTypeKeyElement.addEventListener("change", () => {

statusTypeKeyElement.innerHTML = "<option value=\"\" selected>(All Statuses)</option>";

if (recordTypeKeyElement.value === "") {
// ignore

} else if (statusTypeKeyMap.has(recordTypeKeyElement.value)) {
renderStatusTypeKey();

} else {

const recordTypeKey = recordTypeKeyElement.value;

cityssm.postJSON(urlPrefix + "/dashboard/doGetStatusTypes", {
recordTypeKey
}, (responseJSON: { statusTypes: recordTypes.StatusType[] }) => {
statusTypeKeyMap.set(recordTypeKey, responseJSON.statusTypes);
renderStatusTypeKey();
})
}
});

/*
* Initialize form
*/

searchFormElement.addEventListener("submit", resetOffsetAndSearchFunction);

const filterElements = searchFormElement.querySelectorAll("input, select");
Expand Down
2 changes: 1 addition & 1 deletion public/javascripts/dashboard.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions routes/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import { Router } from "express";
import handler_dashboard from "../handlers/dashboard/dashboard.js";
import handler_doGetRecords from "../handlers/dashboard/doGetRecords.js";
import handler_doGetRecordTagsForSearch from "../handlers/dashboard/doGetRecordTagsForSearch.js";
import handler_doGetStatusTypes from "../handlers/dashboard/doGetStatusTypes.js";
export const router = Router();
router.get("/", handler_dashboard);
router.post("/doGetRecords", handler_doGetRecords);
router.post("/doGetRecordTagsForSearch", handler_doGetRecordTagsForSearch);
router.post("/doGetStatusTypes", handler_doGetStatusTypes);
export default router;
2 changes: 2 additions & 0 deletions routes/dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import handler_dashboard from "../handlers/dashboard/dashboard.js";

import handler_doGetRecords from "../handlers/dashboard/doGetRecords.js";
import handler_doGetRecordTagsForSearch from "../handlers/dashboard/doGetRecordTagsForSearch.js";
import handler_doGetStatusTypes from "../handlers/dashboard/doGetStatusTypes.js";


export const router = Router();
Expand All @@ -15,6 +16,7 @@ router.get("/", handler_dashboard);

router.post("/doGetRecords", handler_doGetRecords);
router.post("/doGetRecordTagsForSearch", handler_doGetRecordTagsForSearch);
router.post("/doGetStatusTypes", handler_doGetStatusTypes);


export default router;
Loading

0 comments on commit e85d0b9

Please sign in to comment.