Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
joypan1 committed Feb 29, 2024
2 parents 26aa58b + de0fc63 commit a62d1d9
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 125 deletions.
11 changes: 10 additions & 1 deletion .github/workflows/main_scouting7127.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ jobs:
environment:
name: 'Production'
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
permissions:
id-token: write #This is required for requesting the JWT

steps:
- name: Download artifact from build job
Expand All @@ -55,12 +57,19 @@ jobs:

- name: Unzip artifact for deployment
run: unzip release.zip

- name: Login to Azure
uses: azure/login@v1
with:
client-id: ${{ secrets.AZUREAPPSERVICE_CLIENTID_A7E7377902BC4211865A0A422C8698B3 }}
tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID_C003070F549F4CD18D86D9DAA4A77D37 }}
subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID_1B5D7BD45FF8466A935EABC02D882A35 }}

- name: 'Deploy to Azure Web App'
uses: azure/webapps-deploy@v2
id: deploy-to-webapp
with:
app-name: 'Scouting7127'
slot-name: 'Production'
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_EC691B8978674A549C7C7DD389A10940 }}
package: .

3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@

# ignore ALL files in ANY directory named temp
temp/
phpMyAdmin/
phpMyAdmin/
.ostype
31 changes: 7 additions & 24 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,30 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'wasm-unsafe-eval' 'inline-speculation-rules' 'unsafe-inline' http://127.0.0.1:5500">

<!-- <meta http-equiv="Content-Security-Policy" content="script-src 'self' 'wasm-unsafe-eval' 'inline-speculation-rules' 'unsafe-inline' http://127.0.0.1:5500"> -->
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="expires" content="0">
<!-- <meta http-equiv="expires" content="0"> -->
<title>Teams</title>
<link rel="stylesheet" href="css/index.css" />
<script src="js/dexie.js"></script>

<!-- <script>
<script>
// Check that service workers are supported
if ("serviceWorker" in navigator) {
// Use the window load event to keep the page load performant
window.addEventListener("load", () => {
navigator.serviceWorker.register("./sw.js");
});
}
</script>
<script href="manifest.json"></script> -->
</script>

<script href="manifest.json"></script>

</head>

<body>
<script>
async function registerServiceWorker() {
if ("serviceWorker" in navigator) {
try {
const registration = await navigator.serviceWorker.register(
"sw.js"
);
console.log(
"Service Worker registered with scope:",
registration.scope
);
} catch (error) {
console.error("Service Worker registration failed:", error);
}
}
}

registerServiceWorker();
</script>
<nav>
<div class = "heading">
<h1>Longmetal 7127 test</h1>
Expand Down
26 changes: 13 additions & 13 deletions pages/teamdetails.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'wasm-unsafe-eval' 'inline-speculation-rules' 'unsafe-inline' http://127.0.0.1:5500">
<!-- <meta http-equiv="Content-Security-Policy" content="script-src 'self' 'wasm-unsafe-eval' 'inline-speculation-rules' 'unsafe-inline' http://127.0.0.1:5500"> -->
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="expires" content="0">
<!-- <meta http-equiv="expires" content="0"> -->
<title> Team Details</title>
<link rel="stylesheet" href="../css/teams.css" />
<script src="../js/dexie.js"></script>

<script>
// Check that service workers are supported
if ("serviceWorker" in navigator) {
// Use the window load event to keep the page load performant
window.addEventListener("load", () => {
navigator.serviceWorker.register("../sw2.js");
});
<!-- <script>
// Check that service workers are supported
if ("serviceWorker" in navigator) {
// Use the window load event to keep the page load performant
window.addEventListener("load", () => {
navigator.serviceWorker.register("./sw.js");
});
}
</script>
</script> -->

<script href="manifest.json"></script>
</head>
Expand All @@ -27,17 +27,18 @@
<nav class="nav">
<div class = "heading">
<h1> Longmetal 7127 </h1>
<h1> Longmetal 7127 v2</h1>
</div>
<div class = "topnav">
<a href="../index.html"> Teams </a>
<a href="../"> Teams </a>
<a href="teamdetails.html"> Team Details </a>
<a href="aboutus.html"> About Us </a>
</div>
</nav>

<header>
<div>
<h1> Team Details </h1>
<h1> Team Details v1</h1>
</div>
</header>
<br>
Expand Down Expand Up @@ -128,7 +129,6 @@ <h2> Abilities </h2><br>
<label for="either">Either</label>

<p>Stage abilities:</p>
<form action="/action_page.php">
<p class="ptext">Stage abilities:</p>
<input type="checkbox" id="spotlight" name="spotlight" value="spotlight">
<label for="spotlight"> Enters stage</label><br>
Expand Down
40 changes: 16 additions & 24 deletions pages/teamdetails.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,19 @@
document.addEventListener('DOMContentLoaded', async () => {
// Initialize Dexie database
const db = new Dexie("Team Tracking App");
db.version(1).stores({
teams: "++id, teamname, globalid"
});

// Retrieve data from IndexedDB and fill the textbox if it exists
const existingData = await db.teams.get(1); // Assuming you have only one record
if (existingData && existingData.todo) {
document.getElementById('teamname').value = existingData.teamname;
}

// Event listener for submit button
document.getElementById('submitButton').addEventListener('click', async () => {
const newData = document.getElementById('teamname').value;

// Save or update data in IndexedDB
if (existingData) {
await db.teams.update(1, { teamname: newData });
try {
const urlParams = new URLSearchParams(window.location.search);
const globalid = parseInt(urlParams.get('globalid'));

const db = new Dexie("Team Tracking App");
db.version(1).stores({ teams: "++id, teamname, globalid" });

const team = await db.teams.where('globalid').equals(globalid).first();
if (team) {
const teamDetailsDiv = document.getElementById('teamname');
teamDetailsDiv.value = `${team.teamname}`;
} else {
await db.teams.add({ teamname: newData });
console.log(`Team with ID ${globalid} not found.`);
}

alert('Data saved successfully!');
});
});
} catch (error) {
console.error("Error accessing database:", error);
}
});
67 changes: 45 additions & 22 deletions sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,52 @@ self.addEventListener("install", async (event) => {
});

// Fetching resources
self.addEventListener("fetch", (event) => {
self.addEventListener('fetch', event => {
event.respondWith(
(async () => {
const cache = await caches.open(cacheName);

try {
const cachedResponse = await cache.match(event.request);
if (cachedResponse) {
console.log("cachedResponse: ", event.request.url);
return cachedResponse;
}

const fetchResponse = await fetch(event.request);
if (fetchResponse) {
console.log("fetchResponse: ", event.request.url);
await cache.put(event.request, fetchResponse.clone());
return fetchResponse;
// Try fetching from the network first
fetch(event.request)
.then(response => {
// If request succeeds, clone the response to cache and return the response
if (response && response.status === 200) {
const responseToCache = response.clone();
caches.open(cacheName)
.then(cache => {
cache.put(event.request, responseToCache);
});
return response;
}
} catch (error) {
console.log("Fetch failed: ", error);
const cachedResponse = await cache.match("index.html");
return cachedResponse;
}
})()
// If request fails (e.g., network error), fall back to the cache
return caches.match(event.request);
})
.catch(error => {
// If fetch from network fails, try serving from cache
return caches.match(event.request);
})
);
});


// self.addEventListener("fetch", (event) => {
// event.respondWith(
// (async () => {
// const cache = await caches.open(cacheName);
// try {
// const cachedResponse = await cache.match(event.request);
// if (cachedResponse) {
// console.log("cachedResponse: ", event.request.url);
// return cachedResponse;
// }
// const fetchResponse = await fetch(event.request);
// if (fetchResponse) {
// console.log("fetchResponse: ", event.request.url);
// await cache.put(event.request, fetchResponse.clone());
// return fetchResponse;
// }
// } catch (error) {
// console.log("Fetch failed: ", error);
// const cachedResponse = await cache.match("index.html");
// return cachedResponse;
// }
// })()
// );
// });
40 changes: 0 additions & 40 deletions sw2.js

This file was deleted.

0 comments on commit a62d1d9

Please sign in to comment.