Skip to content
Merged
22 changes: 10 additions & 12 deletions client/app/adr/modules/AdrListEntry.jsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
//Honestly, I could probably just delete this file.

import React from "react";
import MilpacParse from "./MilpacParse";
import lists from "../../reusableModules/BilletBank";

function AdrListEntry(props) {
let billetBankObject = lists.billetBankObject;
let selector = props.bBGroup;
const rosterGroups = props.rosterGroups.groups;
const selector = props.rGSelector;

return (
<div className="DepartmentContainer">
<div className="Title">{billetBankObject[selector].collapsibleTitle}</div>
<div className="ResponseContainer">
<MilpacParse
milpacArray={props.milpacArray}
headerTitles={billetBankObject[selector].positionTitles}
billetBankObject={billetBankObject[selector].positionIds}
/>
</div>
<div className="ResponseContainer">
<MilpacParse
milpacArray={props.milpacArray}
rosterGroups={rosterGroups[selector].positions}
subtitle={rosterGroups[selector].groupTitle}
/>
</div>
);
}
Expand Down
27 changes: 9 additions & 18 deletions client/app/adr/modules/ArrayMap.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,21 @@ milpac link, name and rank, and position title.*/

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

return (
<table>
<tbody>
{inputArray.map((subArray, index) => (
{inputArray.map((item, 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 key={item.listKey}>
<td>
<a href={"https://7cav.us/rosters/profile/" + item.itemKey}>
{item.fullName}
</a>
</td>
<td className="positionName">{item.position.positionTitle}</td>
</tr>
{subArray.map((item, subIndex) => (
<tr key={item.listKey}>
<td>
<a href={"https://7cav.us/rosters/profile/" + item.itemKey}>
{item.fullName}
</a>
</td>
<td className="positionName">{item.position.positionTitle}</td>
</tr>
))}
</React.Fragment>
))}
</tbody>
Expand Down
100 changes: 52 additions & 48 deletions client/app/adr/modules/MilpacParse.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ This particular instance of milpacArray is designed to parse an entire object fo
for each company within first battalion if asked to do so.*/

function MilpacParse(props) {
const billetBankObject = props.billetBankObject;
const rosterGroups = props.rosterGroups;
let milpacArray = props.milpacArray;

//Currently broken. Sypolt, pls fix.
//const uniqueNamesSet = new Set();
console.log(rosterGroups);

let returnArray = Array(billetBankObject.length)
.fill()
.map(() => []);
const uniqueNamesSet = new Set();

let returnArray = [];

//First, check the combat roster primaries for matching billet id's, then push them to the return array if match is found.

Expand All @@ -27,17 +26,17 @@ function MilpacParse(props) {
let primarySortKey =
milpacArray[0].combat.profiles[milpacIdCombat].primary.positionId;

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

//Next, check the combat roster secondaries for matching billet id's, then push to return array if match is found.
Expand All @@ -50,19 +49,17 @@ function MilpacParse(props) {
milpacArray[0].combat.profiles[milpacIdCombat].secondaries[index2]
.positionId;

if (!billetBankObject[index].includes(secondary.positionId)) {
continue;
if (rosterGroups[index].positionId == secondary.positionId) {
returnArray.push({
fullName: fullName,
position: secondary,
isPrimary: "false",
sortKey: rosterGroups[index].positionDisplayOrder,
itemKey: milpacIdCombat,
listKey: secondarySortKey + milpacIdCombat,
});
uniqueNamesSet.add(fullName);
}

returnArray[index].push({
fullName: fullName,
position: secondary,
isPrimary: "false",
sortKey: secondarySortKey,
itemKey: milpacIdCombat,
listKey: secondarySortKey + milpacIdCombat,
});
//uniqueNamesSet.add(fullName);
}
}
}
Expand All @@ -79,17 +76,17 @@ function MilpacParse(props) {

//Check the Reserve primaries, then push to return array if match is found.

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

//Check the Reserve secondaries, then push to return array if match is found.
Expand All @@ -102,34 +99,41 @@ function MilpacParse(props) {
milpacArray[0].reserve.profiles[milpacIdReserve].secondaries[rIndex]
.positionId;

if (!billetBankObject[index].includes(rSecondary.positionId)) {
continue;
if (rosterGroups[index].positionId == rSecondary.positionId) {
returnArray.push({
fullName: rFullName,
position: rSecondary,
isPrimary: "false",
sortKey: rosterGroups[index].positionDisplayOrder,
itemKey: milpacIdReserve,
listKey: rSecondarySortKey + milpacIdReserve,
});
uniqueNamesSet.add(rFullName);
}

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

// Sort the array based on the order of positionIds in the billetBankObject array. This is mostly accurate, however ranks are not taken into account in the final display

returnArray[index].sort((a, b) => {
const aIndex = billetBankObject[index].indexOf(a.sortKey);
const bIndex = billetBankObject[index].indexOf(b.sortKey);
return aIndex - bIndex;
});
}
}
returnArray.sort((a, b) => {
const aIndex = a.sortKey;
const bIndex = b.sortKey;
return aIndex - bIndex;
});

console.log(returnArray);

return (
<div className="ItemList">
<ArrayMap inputArray={returnArray} headerTitles={props.headerTitles} />
<div className="ParseBox">
<div className="CounterSubtitle">
<div className="Subtitle">{props.subtitle}</div>
<div align="right" className="Counter">
Unit Strength: {uniqueNamesSet.size}
</div>
</div>
<div className="ItemList">
<ArrayMap inputArray={returnArray} headerTitles={props.headerTitles} />
</div>
</div>
);
}
Expand Down
8 changes: 8 additions & 0 deletions client/app/adr/page.css
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,11 @@
/* No idea why i have to do this stupidity. For some reason if I dont do this, this shit becomes off centered */
transform-origin: 67% 67%;
}

.CounterSubtitle {
display: flex;
}

.Counter {
font-weight: bold;
}
39 changes: 33 additions & 6 deletions client/app/adr/page.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Link from "next/link";
import GetCombatRoster from "../reusableModules/getCombatRoster";
import GetReserveRoster from "../reusableModules/getReserveRoster";
import GetApiTimestamp from "../reusableModules/getApiTimestamp";
import GetRosterGroups from "../reusableModules/getGroups";
import AdrListEntry from "./modules/AdrListEntry";
import Logo from "../theme/adrLogo";
import "./page.css";
Expand All @@ -12,14 +13,30 @@ export const metadata = {
};

export default async function ActiveDutyRoster() {
const [combat, reserve, timestamp] = await Promise.all([
const [combat, reserve, timestamp, groups] = await Promise.all([
GetCombatRoster(),
GetReserveRoster(),
GetApiTimestamp(),
GetRosterGroups(),
]);

const milpacArray = [{ combat, reserve }];
const rosterGroups = groups;

const units = [
{ title: "Regimental Command", selectors: [0] },
{ title: "First Battalion", selectors: [2, 3, 4, 5, 6] },
{ title: "Second Battalion", selectors: [7, 8, 9, 10, 11] },
{ title: "Third Battalion", selectors: [12, 15, 13 /*, 14*/] },
{
title: "Auxiallary Combat Division",
selectors: [16, 17, 18 /*, 19*/, 20],
},
{
title: "Support Departments",
selectors: [1],
},
];
return (
<div className="MasterContainer">
<div className="p-nav-primary">
Expand Down Expand Up @@ -50,15 +67,25 @@ export default async function ActiveDutyRoster() {
</div>
</div>
<div className="ListContainer">
{/* note: bBGroup = Billet Bank Group */}
<AdrListEntry bBGroup="regi" milpacArray={milpacArray} />
<AdrListEntry bBGroup="oneSeven" milpacArray={milpacArray} />
<AdrListEntry bBGroup="twoSeven" milpacArray={milpacArray} />
{units.map((unit) => (
<div className="DepartmentContainer" key={unit.title}>
<div className="Title">{unit.title}</div>
{unit.selectors.map((selector) => (
<AdrListEntry
key={`${unit.title}-${selector}`} // Unique key for AdrListEntry
rGSelector={selector}
milpacArray={milpacArray}
rosterGroups={rosterGroups}
/>
))}
</div>
))}
{/*<AdrListEntry bBGroup="twoSeven" milpacArray={milpacArray} />
<AdrListEntry bBGroup="threeSeven" milpacArray={milpacArray} />
<AdrListEntry bBGroup="acd" milpacArray={milpacArray} />
<AdrListEntry bBGroup="secOps" milpacArray={milpacArray} />
<AdrListEntry bBGroup="roo" milpacArray={milpacArray} />
<AdrListEntry bBGroup="support" milpacArray={milpacArray} />
<AdrListEntry bBGroup="support" milpacArray={milpacArray} /> */}
</div>
</div>
);
Expand Down
17 changes: 17 additions & 0 deletions client/app/reusableModules/getGroups.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const CLIENT_TOKEN = process.env.NEXT_PUBLIC_CLIENT_TOKEN;
const GROUP_API_URL = process.env.GROUP_API_URL;

export default async function GetRosterGroups() {
const response = await fetch(GROUP_API_URL, {
headers: {
Authorization: CLIENT_TOKEN,
},
cache: "no-store",
});

if (!response.ok) {
throw new Error("HTTP Error! status: " + response.status);
}

return await response.json();
}
Loading