Skip to content

Commit

Permalink
added more to matchsummary.js, copying teamdetails.js. changed db ver…
Browse files Browse the repository at this point in the history
…sion
  • Loading branch information
joypan1 committed Mar 20, 2024
1 parent fed178e commit 4b2c424
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 57 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const db = new Dexie("Team Tracking App");
//trap was in there twice throwing errors so I removed the last one of them (2nd to last entry)

db.version(15).stores({
db.version(16).stores({
teams: "++indexid, globalid, clienttimestamp, teamname, teamnumber, teamschool, alliancescore, active, moreinfo, startingpos, Leaveszone, scores1amp, scores1speaker, picksup, scores2amp, scores2speaker, preferredScoringMethod, preferredIntakeMethod, prefintake, spotlight, trap, alone, hangsWithAnother, attemptsSpotlight, coop",
matches: "++indexid, globalid, clienttimestamp, match, remoteid, active, rank, matchnumber, count1, count2, count3, count4, count5, count6, count7, stage, hangs, harmony, otherinfo"
});
Expand Down
128 changes: 85 additions & 43 deletions pages/matchinfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,10 @@ const db = new Dexie("Team Tracking App");
// matches: "++indexid, rank, matchnumber, count1, count2, count3, count4, count5, count6, count7, stage, hangs, harmony, otherinfo"
// });

db.version(15).stores({
teams: "++indexid, clienttimestamp, teamname, globalid, teamnumber, teamschool, alliancescore, active",
preferences: "++indexid, globalid, match, moreinfo, startingpos, Leaveszone, scores1amp, scores1speaker, picksup, scores2amp, scores2speaker, preferredScoringMethod, preferredIntakeMethod, prefintake, spotlight, trap, alone, hangsWithAnother, attemptsSpotlight, coop, clienttimestamp",
matches: "++indexid, globalid, match, remoteid, active, clienttimestamp, rank, matchnumber, count1, count2, count3, count4, count5, count6, count7, stage, hangs, harmony, otherinfo"
});
db.version(16).stores({
teams: "++indexid, globalid, clienttimestamp, teamname, teamnumber, teamschool, alliancescore, active, moreinfo, startingpos, Leaveszone, scores1amp, scores1speaker, picksup, scores2amp, scores2speaker, preferredScoringMethod, preferredIntakeMethod, prefintake, spotlight, trap, alone, hangsWithAnother, attemptsSpotlight, coop",
matches: "++indexid, globalid, clienttimestamp, match, remoteid, active, rank, matchnumber, count1, count2, count3, count4, count5, count6, count7, stage, hangs, harmony, otherinfo"
});

// Version numbers must be changed whenever database objects (schema) are edited? See "Modify Schema" in https://dexie.org/docs/Tutorial/Understanding-the-basics
// db = database
Expand All @@ -169,31 +168,75 @@ db.version(15).stores({
- opening a match will show the data that you inputted originally in match form
*/


const teamnumber = document.getElementById("teamnumber").value;
// in order to submit match data for a specific team from the general match info page,
// you need to get the globalid of an existing, matching team entry with the teamnumber submitted on matchinfo.html?

//const teamsDB = db.teams.toArray();

function getTeamWithNumber(teamnumber) {
try {
const team = db.teams.where(parseInt('teamnumber')).equals(parseInt(teamnumber));
return team;
//const globalid = team.globalid;
} catch (error){
console.log("The team number for the selected team was not inputted in the team details page. Please add team number.");
console.error(error);
}
}
const urlParams = new URLSearchParams(window.location.search);
const globalid = parseInt(urlParams.get('globalid'), 10);
const thismatch = urlParams.get('match');

function getTeamWithGlobalID(team) {
document.addEventListener('DOMContentLoaded', async () => {

}

try {
// Use the globally initialized db instance
const match = await db.matches.where('match').equals(parseInt(thismatch)).first();
const team = await db.teams.where('globalid').equals(parseInt(globalid,10)).first();
// is match of type int?

if(match) { // if match exists, AKA accessing it from match summary page after creation of match
//text values
const matchnumberElm = document.getElementById("matchnumber");
matchnumberElm.value = match.matchnumber || '';
const rankElm = document.getElementById("rank");
rankElm.value = match.rank || '';
const teamnumberElm = document.getElementById("teamnumber");
teamnumberElm.value = team.teamnumber || '';

const count1Elm = document.getElementById("count1");
count1Elm.innerHTML = match.count1 || ''; // since the counts are span elements, use innerHTML?
const count2Elm = document.getElementById("count2");
count2Elm.innerHTML = match.count2 || '';
const count3Elm = document.getElementById("count3");
count3Elm.innerHTML = match.count3 || '';
const count4Elm = document.getElementById("count4");
count4Elm.innerHTML = match.count4 || '';
const count5Elm = document.getElementById("count5");
count5Elm.innerHTML = match.count5 || '';
const count6Elm = document.getElementById("count6");
count6Elm.innerHTML = match.count6 || '';
const count7Elm = document.getElementById("count7");
count7Elm.innerHTML = match.count7 || '';

//checkbox values - checked
const stageElm = document.getElementById("stage");
stageElm.checked = match.stage || false;
const hangsElm = document.getElementById("hangs");
hangsElm.checked = match.hangs || false;
const harmonyElm = document.getElementById("harmony");
harmonyElm.checked = match.harmony || false;
const trapElm = document.getElementById("trap");
trapElm.checked = match.trap || false;

//also text value
const otherinfoElm = document.getElementById("otherinfo");
otherinfoElm.value = match.otherinfo || '';
} else {
console.log(`Match ${match} not found`);
}

} catch (error) {
console.error("Error accessing database:", error);
}
});

//insert/update match data
async function submitMatchData(rank, teamnumber, globalid, matchnumber,
count1, count2, count3, count4, count5, count6, count7,
stage, hangs, harmony, trap, otherinfo ) {

//insert team data
async function submitMatchData( rank, teamnumber, globalid, matchnumber, count1, count2, count3, count4, count5, count6, count7, stage, hangs, harmony, trap, otherinfo ) {
try {
let clienttimestamp = moment().tz("America/New_York").format("YYYY-MM-DD HH:mm:ss");
//has to have a comma even after the last element
const teammatchdata = {
rank: rank,
teamnumber: teamnumber,
Expand All @@ -212,26 +255,27 @@ async function submitMatchData( rank, teamnumber, globalid, matchnumber, count1,
hangs: hangs,
harmony: harmony,
trap: trap,
otherinfo: otherinfo
otherinfo: otherinfo,
};

const existingTeam = await db.teams.where('globalid').equals(parseInt(globalid,10)).first();
const existingMatch = await db.matches.where('match').equals(parseInt(match)).first();

//if the team already exists then add match information
if (existingTeam) {
await db.teams.update(existingTeam.id, teammatchdata);
if (existingMatch) {
await db.matches.update(existingMatch.id, teammatchdata);
// does this not work bc teammatchdata is not yet a field in db?
console.log('Team data updated successfully:', existingTeam.id);
alert('Team data updated successfully:', existingTeam.id);
} else { //else, error
console.error("Team does not exist:", error);
/*
} else { //else create new match for the team and store????
console.error("Match does not exist:", error);
let DateObj = new Date();
const globalid = DateObj.getTime();
await db.teams.add({...teammatchdata, globalid: parseInt(globalid,10)});
//const globalid = DateObj.getTime();
await db.matches.add({...teammatchdata, globalid: parseInt(globalid,10)});
console.log('Match info added successfully:', teamnumber, globalid);
alert('Match info added successfully:', teamnumber, globalid);
*/

// PROBABLY BROKEN HERE **********************************

}
} catch (error) {
console.error("Error accessing database:", error);
Expand All @@ -252,13 +296,13 @@ document.getElementById("submitmatchinfo").addEventListener('click', function(ev
const rank = document.getElementById("rank").value;
const teamnumber = document.getElementById("teamnumber").value;

const count1 = document.getElementById("count1").value;
const count2 = document.getElementById("count2").value;
const count3 = document.getElementById("count3").value;
const count4 = document.getElementById("count4").value;
const count5 = document.getElementById("count5").value;
const count6 = document.getElementById("count6").value;
const count7 = document.getElementById("count7").value;
const count1 = document.getElementById("count1").innerHTML;
const count2 = document.getElementById("count2").innerHTML;
const count3 = document.getElementById("count3").innerHTML;
const count4 = document.getElementById("count4").innerHTML;
const count5 = document.getElementById("count5").innerHTML;
const count6 = document.getElementById("count6").innerHTML;
const count7 = document.getElementById("count7").innerHTML;

const stage = document.getElementById("stage").checked;
const hangs = document.getElementById("hangs").checked;
Expand All @@ -267,8 +311,6 @@ document.getElementById("submitmatchinfo").addEventListener('click', function(ev
const otherinfo = document.getElementById("otherinfo").value;

// submitting data:
const urlParams = new URLSearchParams(window.location.search);
const globalid = parseInt(urlParams.get("globalid"),10);

submitMatchData(rank, teamnumber, globalid, matchnumber, count1, count2, count3, count4, count5, count6, count7, stage, hangs, harmony, trap, otherinfo);

Expand Down
6 changes: 1 addition & 5 deletions pages/matchsummary.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,7 @@ <h2> Team: <span class="teamnameeditable" id="teamnameeditable">NULL_TEAMNAME</s


<button class="matchnum" id="clickme"> Match 4 (Click Me) </button>
<button class="matchnum"> Match 7 </button>
<button class="matchnum"> Match 13 </button>
<button class="matchnum"> Match 15 </button>
<button class="matchnum"> Match 23 </button>
<button class="matchnum"> Match 28 </button>


<script>
document.getElementById("clickme").onclick = () => {
Expand Down
13 changes: 6 additions & 7 deletions pages/matchsummary.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// Global Dexie database initialization
const db = new Dexie("Team Tracking App");
db.version(15).stores({
teams: "++indexid, globalid, clienttimestamp, teamname, teamnumber, teamschool, alliancescore, active",
preferences: "++indexid, globalid, clienttimestamp, match, moreinfo, startingpos, Leaveszone, scores1amp, scores1speaker, picksup, scores2amp, scores2speaker, preferredScoringMethod, preferredIntakeMethod, prefintake, spotlight, trap, alone, hangsWithAnother, attemptsSpotlight, coop",
matches: "++indexid, globalid, clienttimestamp, match, remoteid, active, rank, matchnumber, count1, count2, count3, count4, count5, count6, count7, stage, hangs, harmony, otherinfo"
db.version(16).stores({
teams: "++indexid, globalid, clienttimestamp, teamname, teamnumber, teamschool, alliancescore, active, moreinfo, startingpos, Leaveszone, scores1amp, scores1speaker, picksup, scores2amp, scores2speaker, preferredScoringMethod, preferredIntakeMethod, prefintake, spotlight, trap, alone, hangsWithAnother, attemptsSpotlight, coop",
matches: "++indexid, globalid, clienttimestamp, match, remoteid, active, rank, matchnumber, count1, count2, count3, count4, count5, count6, count7, stage, hangs, harmony, otherinfo"
});

const urlParams = new URLSearchParams(window.location.search);
Expand Down Expand Up @@ -35,7 +34,7 @@ const getMatches = async () => {
const allMatches = await db.matches.toArray();
// check if allMatches is not empty
if (allMatches && allMatches.length > 0) {
/*match_list.innerHTML = allMatches
match_list.innerHTML = allMatches
.map(matches =>
<div class="match">
<div class="content">
Expand All @@ -47,9 +46,9 @@ const getMatches = async () => {
</div>
</div>

//BROKEN CODE //////////
// BROKEN CODE //////////
)
.join("");*/
.join("");
} else {
//Handle case when no matches are found
match_list.innerHTML = "<p> No matches found. </p>";
Expand Down
2 changes: 1 addition & 1 deletion pages/teamdetails.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Global Dexie database initialization
const db = new Dexie("Team Tracking App");
db.version(15).stores({
db.version(16).stores({
teams: "++indexid, globalid, clienttimestamp, teamname, teamnumber, teamschool, alliancescore, active, moreinfo, startingpos, Leaveszone, scores1amp, scores1speaker, picksup, scores2amp, scores2speaker, preferredScoringMethod, preferredIntakeMethod, prefintake, spotlight, trap, alone, hangsWithAnother, attemptsSpotlight, coop",
matches: "++indexid, globalid, clienttimestamp, match, remoteid, active, rank, matchnumber, count1, count2, count3, count4, count5, count6, count7, stage, hangs, harmony, otherinfo"
});
Expand Down

0 comments on commit 4b2c424

Please sign in to comment.