Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add FRC Nexus Integration to get team lineups #162

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions static/js/nexus_integration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const row = document.querySelector('#buttonBottomRow');

const nexusButton = document.createElement('button');
nexusButton.classList.add('btn', 'btn-dark', 'btn-lg', 'nexus');
nexusButton.textContent = 'Nexus'
row.prepend(nexusButton);

nexusButton.addEventListener('click', loadLineups)

async function loadLineups() {
let matchKey = document.querySelector('#matchName').textContent;
matchKey = matchKey.replace('Practice ', 'p');
matchKey = matchKey.replace('Match ', 'sf');
matchKey = matchKey.replace('Final ', 'f1m');

try {
let lineups = await(await fetch(`https://api.frc.nexus/v1/2023cc/${matchKey}/lineup`)).json();

let changed = false;
for(let i = 0; i < lineups.blue?.length; i++) {
let el = document.querySelector(`#statusB${i + 1} input.team-number`);
if(el.value === lineups.blue[i]) continue;
el.value = lineups.blue[i];
changed = true;
}
for(let i = 0; i < lineups.red?.length; i++) {
let el = document.querySelector(`#statusR${i + 1} input.team-number`);
if(el.value === lineups.red[i]) continue;
el.value = lineups.red[i];
changed = true;
}
if(changed) {
document.querySelector('#substituteTeams').disabled = false;
}
} catch (e) {
console.warn(e);
}
}
1 change: 1 addition & 0 deletions templates/match_play.html
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ <h4 class="modal-title">Confirm</h4>
{{define "script"}}
<script src="/static/js/match_timing.js"></script>
<script src="/static/js/match_play.js"></script>
<script src="/static/js/nexus_integration.js"></script>
{{end}}
{{define "matchPlayTeam"}}
<div class="row form-group" id="status{{.color}}{{.position}}">
Expand Down
Loading