Skip to content

Commit

Permalink
Issue sfbrigade#48: added functionality for CSCategory column to disp…
Browse files Browse the repository at this point in the history
…lay Clery links
  • Loading branch information
juliahazer committed Mar 5, 2017
1 parent 84019ce commit 127f94d
Showing 1 changed file with 115 additions and 0 deletions.
115 changes: 115 additions & 0 deletions js/modules/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ var tableModule = (function(window, $) {
data: "resolution",
title: "Resolution",
name: "resolution",
}, /*Added the clery category*/{
data: "cscategory",
title: "CSCategory",
name: "cscategory",
}],
pageLength: 50,
footerCallback: function(tfoot, data, start, end, display) {
Expand All @@ -68,8 +72,119 @@ var tableModule = (function(window, $) {
_table = $('#example').DataTable(TABLE_CONFIG);
}

/*function that contains logic for clery category & then adjusts the
incidentJson with the new cscategory field based on this logic*/
function _csCategoryCheck(incidentJson){
for (var i = 0; i < incidentJson.length; i++){
if (!("cscategory" in incidentJson[i])){
incidentJson[i].cscategory = "";
}
switch (true){
case incidentJson[i].category === "ASSAULT":
if (incidentJson[i].descript.includes("AGGRAVATED")){
incidentJson[i].cscategory += "AGGRAVATED ASSAULT";
}
if ((incidentJson[i].descript.includes("WEAPON") ||
incidentJson[i].descript.includes("GUN") ||
incidentJson[i].descript.includes("KNIFE") ||
incidentJson[i].descript.includes("FIREARM") ||
incidentJson[i].descript.includes("SHOOTING")) &&
incidentJson[i].resolution.includes("ARREST")){
if (incidentJson[i].cscategory !== ""){
incidentJson[i].cscategory += ", ";
}
incidentJson[i].cscategory += "WEAPONS POSSESSION";
}
if (incidentJson[i].descript.includes("DATING")){
if (incidentJson[i].cscategory !== ""){
incidentJson[i].cscategory += ", ";
}
incidentJson[i].cscategory += "DATING VIOLENCE";
}
if (incidentJson[i].descript.includes("HATE") ||
incidentJson[i].descript.includes("TERROR")){
if (incidentJson[i].cscategory !== ""){
incidentJson[i].cscategory += ", ";
}
incidentJson[i].cscategory += "HATE CRIMES";
}
if (incidentJson[i].descript.includes("STALKING")){
if (incidentJson[i].cscategory !== ""){
incidentJson[i].cscategory += ", ";
}
incidentJson[i].cscategory += "STALKING";
}
break;
case incidentJson[i].category === "ARSON":
incidentJson[i].cscategory = "ARSON";
break;
case incidentJson[i].category === "BURGLARY":
incidentJson[i].cscategory = "BURGLARY";
break;
case ((incidentJson[i].category === "DRIVING UNDER THE INFLUENCE" &&
incidentJson[i].descript.includes("ALCOHOL") &&
incidentJson[i].resolution.includes("ARREST")) ||
(incidentJson[i].category === "DRUNKENNESS" &&
incidentJson[i].resolution.includes("ARREST")) ||
(incidentJson[i].category === "LIQUOR LAWS" &&
incidentJson[i].resolution.includes("ARREST")) ||
(incidentJson[i].category === "OTHER OFFENSES" &&
incidentJson[i].descript.includes("ALCOHOL") &&
incidentJson[i].resolution.includes("ARREST"))):
incidentJson[i].cscategory = "LIQUOR LAW VIOLATIONS";
break;
case ((incidentJson[i].category === "DRIVING UNDER THE INFLUENCE" &&
incidentJson[i].descript.includes("DRUGS") &&
incidentJson[i].resolution.includes("ARREST")) ||
(incidentJson[i].category === "DRUG/NARCOTIC" &&
incidentJson[i].resolution.includes("ARREST"))):
incidentJson[i].cscategory = "DRUG-RELATED VIOLATIONS";
break;
case incidentJson[i].category === "ROBBERY":
incidentJson[i].cscategory = "ROBBERY";
break;
case incidentJson[i].category === "SECONDARY CODES":
if (incidentJson[i].descript.includes("DOMESTIC VIOLENCE")){
incidentJson[i].cscategory += "DOMESTIC VIOLENCE";
}
if (incidentJson[i].descript.includes("PREJUDICE")){
if (incidentJson[i].cscategory !== ""){
incidentJson[i].cscategory += ", ";
}
incidentJson[i].cscategory += "HATE CRIMES";
}
if (incidentJson[i].descript.includes("WEAPONS")){
if (incidentJson[i].cscategory !== ""){
incidentJson[i].cscategory += ", ";
}
incidentJson[i].cscategory += "WEAPONS POSSESSION";
}
break;
case (incidentJson[i].category === "SEX OFFENSES, FORCIBLE" ||
incidentJson[i].category === "SEX OFFENSES, NON FORCIBLE"):
incidentJson[i].cscategory = "SEX OFFENSES";
break;
case incidentJson[i].category === "VEHICLE THEFT":
incidentJson[i].cscategory = "MOTOR VEHICLE THEFT";
break;
case (incidentJson[i].category === "WEAPON LAWS" &&
incidentJson[i].resolution.includes("ARREST")):
incidentJson[i].cscategory = "WEAPONS POSSESSION";
break;
default:
incidentJson[i].cscategory = "NONE";
break;
}
}
return incidentJson;
}

function _loadDataToTable(incidentJson) {
_table.clear();

incidentJson = _csCategoryCheck(incidentJson);


_table.rows.add(incidentJson);
_table.draw();
}
Expand Down

0 comments on commit 127f94d

Please sign in to comment.