From 5ca0a1a5ffedd2dea41e1eea0938cc11dc2cfd6a Mon Sep 17 00:00:00 2001 From: "Will C aka \"Big Bercin" <97210222+Vercin-G@users.noreply.github.com> Date: Thu, 7 Sep 2023 19:48:22 -0600 Subject: [PATCH 1/3] Statistics Section (Reworked) (#46) * Statistics Section * Minor reworks * remove empty file --------- Co-authored-by: SyniRon <66834451+SyniRon@users.noreply.github.com> --- client/src/App.js | 142 ++++++++++++++++++++ client/src/modules/Generic/StrengthCount.js | 61 +++++++++ 2 files changed, 203 insertions(+) create mode 100644 client/src/modules/Generic/StrengthCount.js diff --git a/client/src/App.js b/client/src/App.js index a398f03..bdacb6b 100644 --- a/client/src/App.js +++ b/client/src/App.js @@ -3,6 +3,7 @@ import "./App.css"; import Collapsible from "react-collapsible"; import lists from "./modules/Generic/BilletBank"; import MilpacParse from "./modules/Generic/MilpacParse"; +import StrengthCount from "./modules/Generic/StrengthCount"; import ErrorMessage from "./errorMessage"; const CLIENT_TOKEN = process.env.REACT_APP_CLIENT_TOKEN; const combatApiUrl = process.env.REACT_APP_COMBAT_API_URL; @@ -456,6 +457,147 @@ function MilpacRequest() { +
+ + {/* We need to do a count for combined, 1-7, 2-7 and acd in that order*/} +
+ + + + + +
+
+ + + + + +
+
+ + + + + +
+
+ +
+
+
)} diff --git a/client/src/modules/Generic/StrengthCount.js b/client/src/modules/Generic/StrengthCount.js new file mode 100644 index 0000000..8e53629 --- /dev/null +++ b/client/src/modules/Generic/StrengthCount.js @@ -0,0 +1,61 @@ +import React from "react"; + +function StrengthCount(props) { + var useCompanyLevelLogic = props.useCompanyLevelLogic; + + if (useCompanyLevelLogic !== true) { + var combinedArray = []; + var milpacArray = props.milpacArray; + var billetIDs = props.billetIDs; + var subtitle = props.subtitle; + + for (var milpacIdCombat in milpacArray[0].combat.profiles) { + var primary = milpacArray[0].combat.profiles[milpacIdCombat].primary; + + for (var billetIdArray in billetIDs) { + if (billetIDs[billetIdArray].includes(primary.positionId)) { + combinedArray.push({ position: primary }); + } + } + } + + return ( +
+
+
{subtitle}
+
+ Overall Strength{": "} + {combinedArray.length} +
+
+
+ ); + } else if (useCompanyLevelLogic === true) { + combinedArray = []; + milpacArray = props.milpacArray; + billetIDs = props.billetIDs; + var subSubtitle = props.subSubtitle; + + for (milpacIdCombat in milpacArray[0].combat.profiles) { + primary = milpacArray[0].combat.profiles[milpacIdCombat].primary; + + for (billetIdArray in billetIDs) { + if (billetIDs[billetIdArray].includes(primary.positionId)) { + combinedArray.push({ position: primary }); + } + } + } + + return ( +
+
+ {subSubtitle} + {": "} + {combinedArray.length} +
+
+ ); + } +} + +export default StrengthCount; From 2149bfcd6498b71ac03663bb114cfc26bc80a799 Mon Sep 17 00:00:00 2001 From: "Will C aka \"Big Bercin" <97210222+Vercin-G@users.noreply.github.com> Date: Sun, 10 Sep 2023 04:15:48 -0600 Subject: [PATCH 2/3] Readme.md Update (#47) * Update README.md Made the readme prettier and much more comprehensive for first time users. --------- Co-authored-by: SyniRon <66834451+SyniRon@users.noreply.github.com> --- README.md | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 61 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 691bf5d..136fecf 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,74 @@ -# 7th Cavalry ADR +

+## Overview [![Server ADR Deployment](https://github.com/7Cav/adr/actions/workflows/server_adr_push.yml/badge.svg)](https://github.com/7Cav/adr/actions/workflows/server_adr_push.yml) [![Client ADR Deployment](https://github.com/7Cav/adr/actions/workflows/client_adr_push.yml/badge.svg)](https://github.com/7Cav/adr/actions/workflows/client_adr_push.yml) -## Overview - -This is a React application designed to display roster data fetched from the 7th Cavalry API. The project is structured as a client-server architecture and includes basic authentication for enhanced security. +The Active Duty Roster (ADR) is a Reactjs based app designed to automatically track membership of every position within the 7th Cavalry Gaming Regiment via the 7th Cavalry API. The ADR is structured as a client-server architecture and includes basic authentication for enhanced security. Though the ADR is accurate, semi-regular maintenence is needed in order to keep tracked billets up to date. ## Table of Contents -- [Updating ADR](#updating-adr) +- [Running Locally](#running-locally) + - [Requirements](#requirements) + - [Authorization](#authorization) + - [Getting Started](#getting-started) +- [Updating the ADR](#updating-the-adr) - [Add New Billet in Existing Category](#add-new-billet-in-existing-category) - [Add New Category](#add-new-category) - [TODO](#todo) -## Updating ADR +## Running Locally + +### Requirements + +In order to run the ADR locally for development, you need the following: +- A valid [7th Cavalry Gaming](https://7cav.us/) account with member-level privileges (i.e. not a public account). +- An instance of [Node.js](https://nodejs.org/en) installed on your system. +- Your choice of IDE such as [VSCode](https://code.visualstudio.com/). + +#### Authorization + +Before you get started with your server, you require two methods of authentication. You require both an API token from 7th Cavalry Gaming and a local clientside token. + +To get and apply your API token do the following steps: + +1. Log into your 7th Cavalry Gaming account. +2. Navigate to your [Connected Accounts](https://7cav.us/account/connected-accounts/) and select the "view account" button for auth.7cav.us +3. Once you have logged into keycloak, copy the provided API token into your clipboard. +4. Open the adr project folder and navigate to `adr/server/credentials`. Inside should be a file named `example_token.js`. +5. Make a duplicate `example_token.js` and rename it to `token.js`. +6. Inside the new `token.js` file, paste your API token in the `API_TOKEN` constant and save the file. + +To make a clientside token, do the following: + +1. Open the adr project folder and navigate to `/client`. +2. Inside the Client folder create a nameless `.env` file. When opened, the directory should be `adr/client/.env` +3. Paste the following code into the `.env` file. + +```dotenv +REACT_APP_CLIENT_TOKEN ='XXXXXX' +REACT_APP_COMBAT_API_URL=http://localhost:4000/roster/combat +REACT_APP_RESERVE_API_URL=http://localhost:4000/roster/reserves +REACT_APP_CACHE_TIMESTAMP_URL=http://localhost:4000/cache-timestamp +``` +4. Replace the `REACT_APP_CLIENT_TOKEN` constant with a password of your choice and save. +5. Navigate to `adr/server/credentials/token.js` and ensure the `CLIENT_TOKEN` constant matches the same constant in the previous `.env` file and save. + +### Getting Started + +Before initializing the server, the dependancies for the ADR need to be installed on your end. + +- Open a terminal/cmd prompt and navigate to the adr project folder and execute the command `npm install`. +- Once the install finishes, navigate to `adr/client` and execute the previous command. + +You should now be ready to run the Server and the Client. + +- Open two terminals. On the first terminal navigate to `adr/server` and enter the command `node server.js`. You should see that the server is listening on localhost:4000 and can be additionally verified by visiting localhost:4000 on your browser. +- On the second terminal, navigate to `adr/client/src` and run the command `npm start`. Once the clientside is running, you should be automatically redirected to localhost:3000 on your browser. A sucessful response is when the ADR is completely filled. + +You are now good to go! `adr/client/src/app.js` is the primary file in which everything on the clientside is ran. Closing the terminals will close the servers. Happy Coding! + +## Updating the ADR ### Add New Billet in Existing Category @@ -87,6 +141,7 @@ const billetBank = { ## TODO +- [ ] Add tutorial for updating Statistics - [ ] Change cache warning on client to display time since cache refresh - [ ] Investigate the feasibility of sorting by rank after billet sorting (Subsorting? Consider using QuickSort) - [ ] Add graphical data visualization From c9153263297b8aadc167c19b3e6936fead185c98 Mon Sep 17 00:00:00 2001 From: Ron <66834451+SyniRon@users.noreply.github.com> Date: Mon, 11 Sep 2023 00:29:37 -0400 Subject: [PATCH 3/3] fix unit strength counter to ignore duplicates (#48) --- client/src/modules/Generic/MilpacParse.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/client/src/modules/Generic/MilpacParse.js b/client/src/modules/Generic/MilpacParse.js index 3a8ac66..4d19474 100644 --- a/client/src/modules/Generic/MilpacParse.js +++ b/client/src/modules/Generic/MilpacParse.js @@ -1,6 +1,7 @@ import React from "react"; function MilpacParse(props) { + const uniqueNamesSet = new Set(); var array = []; var milpacArray = props.milpacArray; var billetIDs = props.billetIDs; @@ -25,6 +26,7 @@ function MilpacParse(props) { itemKey: milpacIdCombat, listKey: primarySortKey + milpacIdCombat, }); + uniqueNamesSet.add(fullName); } for (var index in milpacArray[0].combat.profiles[milpacIdCombat] @@ -47,6 +49,7 @@ function MilpacParse(props) { itemKey: milpacIdCombat, listKey: secondarySortKey + milpacIdCombat, }); + uniqueNamesSet.add(fullName); } } @@ -68,6 +71,7 @@ function MilpacParse(props) { itemKey: milpacIdReserve, listKey: rPrimarySortKey + milpacIdReserve, }); + uniqueNamesSet.add(rFullName); } for (var rIndex in milpacArray[0].reserve.profiles[milpacIdReserve] @@ -90,6 +94,7 @@ function MilpacParse(props) { itemKey: milpacIdReserve, listKey: rSecondarySortKey + milpacIdReserve, }); + uniqueNamesSet.add(rFullName); } } @@ -104,7 +109,7 @@ function MilpacParse(props) {
{subtitle}
-
Unit Strength: {array.length}
+
Unit Strength: {uniqueNamesSet.size}
@@ -152,6 +157,7 @@ function MilpacParse(props) { itemKey: milpacIdCombat, listKey: primarySortKey + milpacIdCombat, }); + uniqueNamesSet.add(fullName); } } @@ -166,7 +172,7 @@ function MilpacParse(props) {
{subtitle}
-
Unit Strength: {array.length}
+
Unit Strength: {uniqueNamesSet.size}