diff --git a/index.html b/index.html index 890b714..9a2b4c7 100644 --- a/index.html +++ b/index.html @@ -43,7 +43,7 @@

Longmetal 7127

Match Info Match Summary About Us - + @@ -69,8 +69,24 @@

Team List

- + diff --git a/index.js b/index.js index 5e5933f..576393b 100644 --- a/index.js +++ b/index.js @@ -1,9 +1,9 @@ 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(16).stores({ +db.version(17).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" + matches: "++indexid, globalid, clienttimestamp, match, remoteid, active, rank, matchnumber, count1, count2, count3, count4, count5, count6, count7, stage, hangs, harmony, trap, otherinfo" }); // Assuming 'db' is your Dexie database instance @@ -118,7 +118,7 @@ const deleteTeams = async (event, id) => { }; function editTeam(globalid) { - window.open(`pages/teamdetails.html?globalid=${globalid}&match=1`, "_self"); //well, it defaults to new page so we will try _self + window.open(`pages/teamdetails.html?globalid=${globalid}`, "_self"); //well, it defaults to new page so we will try _self } function newMatch(globalid) { diff --git a/pages/matchinfo.js b/pages/matchinfo.js index e3621ad..97e372d 100644 --- a/pages/matchinfo.js +++ b/pages/matchinfo.js @@ -147,9 +147,9 @@ const db = new Dexie("Team Tracking App"); // matches: "++indexid, rank, matchnumber, count1, count2, count3, count4, count5, count6, count7, stage, hangs, harmony, otherinfo" // }); -db.version(16).stores({ +db.version(17).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" + matches: "++indexid, globalid, clienttimestamp, match, remoteid, active, rank, matchnumber, count1, count2, count3, count4, count5, count6, count7, stage, hangs, harmony, trap, otherinfo" }); // Version numbers must be changed whenever database objects (schema) are edited? See "Modify Schema" in https://dexie.org/docs/Tutorial/Understanding-the-basics @@ -222,9 +222,7 @@ document.addEventListener('DOMContentLoaded', async () => { }); //insert/update match data -async function submitMatchData(rank, teamnumber, globalid, matchnumber, - count1, count2, count3, count4, count5, count6, count7, - stage, hangs, harmony, trap, otherinfo ) { +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"); @@ -250,24 +248,39 @@ async function submitMatchData(rank, teamnumber, globalid, matchnumber, otherinfo: otherinfo, }; - const existingMatch = await db.matches.where('matchnumber').equals(parseInt(matchnumber)).first(); + //Joy - you were on the right track here - but there can be multiple teams in the same match? Or do they each get their own match number? + const existingMatch = await db.matches.where('matchnumber').equals(matchnumber).and(match => match.globalid === parseInt(globalid, 10)).first(); //if the team already exists then add match information 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:', existingMatch.id); - alert('Team data updated successfully:', existingMatch.id); - } 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.matches.add({...teammatchdata, matchnumber: matchnumber}); - console.log('Match info added successfully:', matchnumber, globalid); - alert('Match info added successfully:', matchnumber, globalid); + existingMatch.rank = rank; + existingMatch.teamnumber = teamnumber; + existingMatch.count1 = count1; + existingMatch.count2 = count2; + existingMatch.count3 = count3; + existingMatch.count4 = count4; + existingMatch.count5 = count5; + existingMatch.count6 = count6; + existingMatch.count7 = count7; + existingMatch.stage = stage; + existingMatch.hangs = hangs; + existingMatch.harmony = harmony; + existingMatch.trap = trap; + existingMatch.otherinfo = otherinfo; + + await db.matches + .where('matchnumber') + .equals(matchnumber) + .and(match => match.globalid === parseInt(globalid, 10)) + .modify(existingMatch); - // PROBABLY BROKEN HERE ********************************** - + console.log('Team data updated successfully:', existingMatch.teamnumber); + alert('Team data updated successfully:', existingMatch.teamnumber); + } else { //else create new match for the team and store???? + console.log("Match does not exist for this team: creating it"); + await db.matches.add({...teammatchdata, globalid: parseInt(globalid,10)}); + console.log('Match info added successfully:', teamnumber, globalid); + alert('Match info added successfully:', teamnumber, globalid); } } catch (error) { console.error("Error accessing database:", error); @@ -277,7 +290,8 @@ async function submitMatchData(rank, teamnumber, globalid, matchnumber, document.getElementById("submitmatchinfo").addEventListener('click', function(event){ // Make sure not to initialize the script before the button, or else there will be no communication - event.preventDefault(); + event.preventDefault(); + // not sure if you can .value a span html element // match data: const matchnumber = document.getElementById("matchnumber").value; @@ -299,9 +313,9 @@ document.getElementById("submitmatchinfo").addEventListener('click', function(ev const otherinfo = document.getElementById("otherinfo").value; // submitting data: - submitMatchData(rank, teamnumber, globalid, matchnumber, count1, count2, count3, count4, count5, count6, count7, stage, hangs, harmony, trap, otherinfo); - - alert("Match info submitted!"); + + submitMatchData(rank, teamnumber, globalid, matchnumber, count1, count2, count3, count4, count5, count6, count7, stage, hangs, harmony, trap, otherinfo); + //alert("Match info submitted!"); }); // Function to print all db matches to the console for debugging, BROKEN diff --git a/pages/matchsummary.js b/pages/matchsummary.js index 0c8c2dc..c4f7a0f 100644 --- a/pages/matchsummary.js +++ b/pages/matchsummary.js @@ -1,9 +1,9 @@ // Global Dexie database initialization const db = new Dexie("Team Tracking App"); -db.version(16).stores({ +db.version(17).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" + matches: "++indexid, globalid, clienttimestamp, match, remoteid, active, rank, matchnumber, count1, count2, count3, count4, count5, count6, count7, stage, hangs, harmony, trap, otherinfo" }); const urlParams = new URLSearchParams(window.location.search); diff --git a/pages/teamdetails.js b/pages/teamdetails.js index 887f369..14b9419 100644 --- a/pages/teamdetails.js +++ b/pages/teamdetails.js @@ -1,8 +1,8 @@ // Global Dexie database initialization const db = new Dexie("Team Tracking App"); -db.version(16).stores({ +db.version(17).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" + matches: "++indexid, globalid, clienttimestamp, match, remoteid, active, rank, matchnumber, count1, count2, count3, count4, count5, count6, count7, stage, hangs, harmony, trap, otherinfo" }); //I CHANGED ID TO INDEXID AS ID WAS CONFLICTING WITH THE AUTO INCREMENTED ID IN THE TABLE ON THE SQL SERVER *********************** Scrub that, I made a ton of changes :-\ diff --git a/testing/deletedexie.js b/testing/deletedexie.js index 540b975..098de6d 100644 --- a/testing/deletedexie.js +++ b/testing/deletedexie.js @@ -1,10 +1,9 @@ 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({ - teams: "++indexid, localtimestamp, remotetimestamp, 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", - matches: "++indexid, globalid, match, remoteid, active,localtimestamp, remotetimestamp, rank, matchnumber, count1, count2, count3, count4, count5, count6, count7, stage, hangs, harmony, otherinfo" +db.version(17).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, trap, otherinfo" }); // Assuming 'db' is your Dexie database instance diff --git a/testing/dexie.js b/testing/dexie.js index 9e2d359..83def9a 100644 --- a/testing/dexie.js +++ b/testing/dexie.js @@ -1,9 +1,9 @@ // Define your Dexie database const db = new Dexie("Team Tracking App"); -db.version(16).stores({ +db.version(17).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" - }); + matches: "++indexid, globalid, clienttimestamp, match, remoteid, active, rank, matchnumber, count1, count2, count3, count4, count5, count6, count7, stage, hangs, harmony, trap, otherinfo" +}); async function dumpDB() { await db.open();