Skip to content

Commit

Permalink
Refactor 2 electric boogaloo (#54)
Browse files Browse the repository at this point in the history
* move stuff to billetbank

* new modules

* refactor 2 electric boogaloo

* why do you do this to me, prettier?
  • Loading branch information
Vercin-G authored Sep 26, 2023
1 parent 15277e0 commit 6eb20a6
Show file tree
Hide file tree
Showing 5 changed files with 214 additions and 190 deletions.
30 changes: 18 additions & 12 deletions client/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function MilpacRequest() {
alt="ADR Logo"
title="Return to the main website"
width="17em"
height=""
height="3em"
/>
</a>
</div>
Expand Down Expand Up @@ -143,54 +143,60 @@ function MilpacRequest() {
<div className="ListContainer">
<CombinedFunction
billetBankObject={lists.billetBankObject.regi.positionIds}
collapsibleTitle="Regimental Command"
collapsibleTitle={lists.billetBankObject.regi.collapsibleTitle}
headerTitles={lists.billetBankObject.regi.positionTitles}
milpacArray={milpacArray}
usePrimaryOnly={true}
usePrimaryOnly={lists.billetBankObject.regi.isPrimaryOnly}
/>
<CombinedFunction
billetBankObject={lists.billetBankObject.oneSeven.positionIds}
collapsibleTitle="First Battalion"
collapsibleTitle={
lists.billetBankObject.oneSeven.collapsibleTitle
}
headerTitles={lists.billetBankObject.oneSeven.positionTitles}
milpacArray={milpacArray}
usePrimaryOnly={true}
usePrimaryOnly={lists.billetBankObject.oneSeven.isPrimaryOnly}
/>
<CombinedFunction
billetBankObject={lists.billetBankObject.twoSeven.positionIds}
collapsibleTitle="Second Battalion"
collapsibleTitle={
lists.billetBankObject.twoSeven.collapsibleTitle
}
headerTitles={lists.billetBankObject.twoSeven.positionTitles}
milpacArray={milpacArray}
usePrimaryOnly={true}
usePrimaryOnly={lists.billetBankObject.twoSeven.isPrimaryOnly}
/>
<CombinedFunction
billetBankObject={lists.billetBankObject.acd.positionIds}
collapsibleTitle="Auxillary Combat Division"
collapsibleTitle={lists.billetBankObject.acd.collapsibleTitle}
headerTitles={lists.billetBankObject.acd.positionTitles}
milpacArray={milpacArray}
/>
<CombinedFunction
billetBankObject={lists.billetBankObject.imo.positionIds}
collapsibleTitle="Information Management Office"
collapsibleTitle={lists.billetBankObject.imo.collapsibleTitle}
headerTitles={lists.billetBankObject.imo.positionTitles}
milpacArray={milpacArray}
/>
<CombinedFunction
billetBankObject={lists.billetBankObject.secOps.positionIds}
collapsibleTitle="Security Operations"
collapsibleTitle={lists.billetBankObject.secOps.collapsibleTitle}
headerTitles={lists.billetBankObject.secOps.positionTitles}
milpacArray={milpacArray}
/>
<CombinedFunction
billetBankObject={lists.billetBankObject.roo.positionIds}
collapsibleTitle="Recruitment Oversight Office"
collapsibleTitle={lists.billetBankObject.roo.collapsibleTitle}
headerTitles={lists.billetBankObject.roo.positionTitles}
milpacArray={milpacArray}
/>
<CombinedFunction
billetBankObject={
lists.billetBankObject.supportDepartments.positionIds
}
collapsibleTitle="Support Departments"
collapsibleTitle={
lists.billetBankObject.supportDepartments.collapsibleTitle
}
headerTitles={
lists.billetBankObject.supportDepartments.positionTitles
}
Expand Down
41 changes: 41 additions & 0 deletions client/src/modules/Generic/ArrayMap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React from "react";

/*This function is probably the most complicated code in the ADR. Essentially, it takes inputArray and headerTitles, and iterates through the first layer of inputArray's arrays
which in this case is the battalion level. At the battalion level, it creates a table row for each company, adding the company title (defined in BilletBank.js) and unit strength counter.
After the title and counter are created for the company level, the lists themselves for each company are created, which are the second layer of arrays. The lists themselves contain
milpac link, name and rank, and position title.*/

function ArrayMap(props) {
let inputArray = props.inputArray;

return (
<table>
<tbody>
{inputArray.map((subArray, index) => (
<React.Fragment key={`fragment-${index}`}>
<tr key={`header-${index}`}>
<th className="Subtitle" align="left">
{props.headerTitles[index]}
</th>
<th align="right" className="Counter">
Unit Strength: {inputArray[index].length}
</th>
</tr>
{subArray.map((item, subIndex) => (
<tr key={item.listKey}>
<td>
<a href={"https://7cav.us/rosters/profile/" + item.itemKey}>
{item.fullName}
</a>
</td>
<td>{item.position.positionTitle}</td>
</tr>
))}
</React.Fragment>
))}
</tbody>
</table>
);
}

export default ArrayMap;
8 changes: 8 additions & 0 deletions client/src/modules/Generic/BilletBank.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const regiCommand = [
const regi = {
positionIds: [regiCommand],
positionTitles: ["Command Staff"],
collapsibleTitle: "Regimental Command",
};

//1-7
Expand Down Expand Up @@ -187,6 +188,7 @@ const oneSeven = {
"Bravo Troop",
"Charlie Company",
],
collapsibleTitle: "First Battalion",
};

//2-7
Expand Down Expand Up @@ -348,6 +350,7 @@ const twoSeven = {
"Bravo Company",
"Charlie Company",
],
collapsibleTitle: "Second Battalion",
};

//ACD
Expand Down Expand Up @@ -524,6 +527,7 @@ const acd = {
"Star Citizen Starter Platoon",
"Future Concepts Center",
],
collapsibleTitle: "First Battalion",
};

//IMO
Expand Down Expand Up @@ -565,6 +569,7 @@ const imo = {
"S6 - Information Management",
"Wiki Administration Group",
],
collapsibleTitle: "Information Management Office",
};

//ROO
Expand Down Expand Up @@ -611,6 +616,7 @@ const roo = {
"Recruit Training Command",
"S5 - Public Relations",
],
collapsibleTitle: "Recruitment Oversight Office",
};

//SecOps
Expand All @@ -628,6 +634,7 @@ const secOps = {
"Military Police",
"S2 - Intelligence and Security",
],
collapsibleTitle: "Security Operations",
};

//Support
Expand Down Expand Up @@ -738,6 +745,7 @@ const supportDepartments = {
"S7 - Training",
"Leadership Development",
],
collapsibleTitle: "Support Departments",
};

// Overall export Object
Expand Down
185 changes: 7 additions & 178 deletions client/src/modules/Generic/CombinedFunction.js
Original file line number Diff line number Diff line change
@@ -1,193 +1,22 @@
import React from "react";
import Collapsible from "react-collapsible";
import MilpacParse from "./MilpacParse.js";

function CombinedFunction(props) {
const billetBankObject = props.billetBankObject;
const uniqueNamesSet = new Set();

let collapsibleTitle = props.collapsibleTitle;
let headerTitles = props.headerTitles;
let milpacArray = props.milpacArray;

let array = Array(billetBankObject.length)
.fill()
.map(() => []);

if (props.usePrimaryOnly === true) {
for (let milpacIdCombat in milpacArray[0].combat.profiles) {
let name = milpacArray[0].combat.profiles[milpacIdCombat].realName;
let rank = milpacArray[0].combat.profiles[milpacIdCombat].rank.rankFull;
let primary = milpacArray[0].combat.profiles[milpacIdCombat].primary;
let fullName = rank + " " + name;
let primarySortKey =
milpacArray[0].combat.profiles[milpacIdCombat].primary.positionId;

for (let index in billetBankObject) {
if (billetBankObject[index].includes(primary.positionId)) {
array[index].push({
fullName: fullName,
position: primary,
isPrimary: "true",
sortKey: primarySortKey,
itemKey: milpacIdCombat,
listKey: primarySortKey + milpacIdCombat,
});
uniqueNamesSet.add(fullName);

// Sorting the array based on the order of positionIds in the billetBankObject array
array[index].sort((a, b) => {
const aIndex = billetBankObject[index].indexOf(a.sortKey);
const bIndex = billetBankObject[index].indexOf(b.sortKey);
return aIndex - bIndex;
});
}
}
}
} else if (props.usePrimaryOnly !== true) {
for (let milpacIdCombat in milpacArray[0].combat.profiles) {
let name = milpacArray[0].combat.profiles[milpacIdCombat].realName;
let rank = milpacArray[0].combat.profiles[milpacIdCombat].rank.rankFull;
let primary = milpacArray[0].combat.profiles[milpacIdCombat].primary;
let fullName = rank + " " + name;
let primarySortKey =
milpacArray[0].combat.profiles[milpacIdCombat].primary.positionId;

for (let index in billetBankObject) {
if (billetBankObject[index].includes(primary.positionId)) {
array[index].push({
fullName: fullName,
position: primary,
isPrimary: "true",
sortKey: primarySortKey,
itemKey: milpacIdCombat,
listKey: primarySortKey + milpacIdCombat,
});
uniqueNamesSet.add(fullName);
}

for (let index2 in milpacArray[0].combat.profiles[milpacIdCombat]
.secondaries) {
let secondary =
milpacArray[0].combat.profiles[milpacIdCombat].secondaries[index2];
let secondarySortKey =
milpacArray[0].combat.profiles[milpacIdCombat].secondaries[index2]
.positionId;

if (!billetBankObject[index].includes(secondary.positionId)) {
continue;
}

array[index].push({
fullName: fullName,
position: secondary,
isPrimary: "false",
sortKey: secondarySortKey,
itemKey: milpacIdCombat,
listKey: secondarySortKey + milpacIdCombat,
});
uniqueNamesSet.add(fullName);
}
}
}

for (let milpacIdReserve in milpacArray[0].reserve.profiles) {
let rName = milpacArray[0].reserve.profiles[milpacIdReserve].realName;
let rRank =
milpacArray[0].reserve.profiles[milpacIdReserve].rank.rankFull;
let rPrimary = milpacArray[0].reserve.profiles[milpacIdReserve].primary;
let rFullName = rRank + " " + rName;
let rPrimarySortKey =
milpacArray[0].reserve.profiles[milpacIdReserve].primary.positionId;

for (let index in billetBankObject) {
if (billetBankObject[index].includes(rPrimary.positionId)) {
array[index].push({
fullName: rFullName,
position: rPrimary,
isPrimary: "true",
sortKey: rPrimarySortKey,
itemKey: milpacIdReserve,
listKey: rPrimarySortKey + milpacIdReserve,
});
uniqueNamesSet.add(rFullName);
}

for (let rIndex in milpacArray[0].reserve.profiles[milpacIdReserve]
.secondaries) {
let rSecondary =
milpacArray[0].reserve.profiles[milpacIdReserve].secondaries[
rIndex
];
let rSecondarySortKey =
milpacArray[0].reserve.profiles[milpacIdReserve].secondaries[rIndex]
.positionId;

if (!billetBankObject[index].includes(rSecondary.positionId)) {
continue;
}

array[index].push({
fullName: rFullName,
position: rSecondary,
isPrimary: "false",
sortKey: rSecondarySortKey,
itemKey: milpacIdReserve,
listKey: rSecondarySortKey + milpacIdReserve,
});
uniqueNamesSet.add(rFullName);
}

// Sorting the array based on the order of positionIds in the billetBankObject array
array[index].sort((a, b) => {
const aIndex = billetBankObject[index].indexOf(a.sortKey);
const bIndex = billetBankObject[index].indexOf(b.sortKey);
return aIndex - bIndex;
});
}
}
}

return (
<div className="DepartmentContainer">
<Collapsible
trigger={collapsibleTitle}
trigger={props.collapsibleTitle}
triggerClassName="Title"
triggerOpenedClassName="Title"
open={true}
>
<div className="ResponseContainer">
<div className="ItemList">
<table>
<tbody>
{array.map((subArray, index) => (
<React.Fragment key={`fragment-${index}`}>
<tr key={`header-${index}`}>
<th className="Subtitle" align="left">
{headerTitles[index]}
</th>
<th align="right" className="Counter">
Unit Strength: {array[index].length}
</th>
</tr>
{subArray.map((item, subIndex) => (
<tr key={item.listKey}>
<td>
<a
href={
"https://7cav.us/rosters/profile/" + item.itemKey
}
>
{item.fullName}
</a>
</td>
<td>{item.position.positionTitle}</td>
</tr>
))}
</React.Fragment>
))}
</tbody>
</table>
</div>
<MilpacParse
milpacArray={props.milpacArray}
headerTitles={props.headerTitles}
billetBankObject={props.billetBankObject}
/>
</div>
</Collapsible>
</div>
Expand Down
Loading

0 comments on commit 6eb20a6

Please sign in to comment.