Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
joypan1 committed Mar 21, 2024
2 parents 3ad2826 + 28f6e38 commit 59c1763
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 39 deletions.
20 changes: 18 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ <h1>Longmetal 7127</h1>
<a href="pages/matchinfo.html"> Match Info </a>
<a href="pages/matchsummary.html"> Match Summary </a>
<a href="pages/aboutus.html"> About Us </a>
<button onclick="" style></button><input type="button" value="Submit" style="background: url(assets/refresh.jpg) no-repeat; width:70px; height:70px;">
<!-- <button onclick="" style></button><input type="button" value="Submit" style="background: url(assets/refresh.jpg) no-repeat; width:70px; height:70px;"> -->

</div>
</nav>
Expand All @@ -69,8 +69,24 @@ <h2>Team List</h2>
<!-- Alternatively, convert the website to a PWA for more native experience -->

</main>

<script src="index.js"></script>
</body>
<footer>
<div id="notes">
<p>I added some links to the bottom of the index page to help with troubleshooting, display the databases to a page, and delete the databases in the event you get those out of sync messages or wrong db version</p>

<p>
TODO:<br><br>
<ul>
<li>Add link to remote database to display contents</li>
<li>add local timestamp to matches table</li>
<li>fill out match summary page</li>
<li>sync databases across devices</li>
<li>add url identifier to match info to pull up match info</li>
<li>fix syncing for match info</li>
</ul>
</p>
</div>
<p style="margin-bottom: 50px;"><center><a href="/testing/dexie.html" target="_blank">Dispaly Database Contents</a> &nbsp;<a href="/testing/dexie.html" target="_blank">Delete Dexie Databases and Reload</a></center></p>
</footer>
</html>
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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) {
Expand Down
60 changes: 37 additions & 23 deletions pages/matchinfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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");
Expand All @@ -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);
Expand All @@ -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;
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pages/matchsummary.js
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
4 changes: 2 additions & 2 deletions pages/teamdetails.js
Original file line number Diff line number Diff line change
@@ -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 :-\
Expand Down
7 changes: 3 additions & 4 deletions testing/deletedexie.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions testing/dexie.js
Original file line number Diff line number Diff line change
@@ -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();
Expand Down

0 comments on commit 59c1763

Please sign in to comment.