Skip to content

Commit

Permalink
Merge pull request #6 from Team334/pwa
Browse files Browse the repository at this point in the history
PWA + Fixes
  • Loading branch information
cherriae authored Feb 20, 2025
2 parents f6f47ce + 4a9995f commit 1173fe7
Show file tree
Hide file tree
Showing 23 changed files with 1,267 additions and 1,068 deletions.
11 changes: 11 additions & 0 deletions app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,17 @@ def handle_exception(e):
def rate_limit_error(e):
return render_template("429.html"), 429

@app.route('/static/manifest.json')
def serve_manifest():
return send_from_directory(app.static_folder, 'manifest.json')

@app.route('/static/js/service-worker.js')
def serve_service_worker():
response = make_response(send_from_directory(app.static_folder, 'js/service-worker.js'))
response.headers['Service-Worker-Allowed'] = '/'
response.headers['Cache-Control'] = 'no-cache'
return response

return app


Expand Down
533 changes: 292 additions & 241 deletions app/scout/routes.py

Large diffs are not rendered by default.

414 changes: 236 additions & 178 deletions app/scout/scouting_utils.py

Large diffs are not rendered by default.

Binary file added app/static/icons/icon-128x128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/static/icons/icon-144x144.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/static/icons/icon-152x152.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/static/icons/icon-192x192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/static/icons/icon-384x384.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/static/icons/icon-512x512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/static/icons/icon-72x72.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/static/icons/icon-96x96.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion app/static/js/CanvasCoordinateSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ class CanvasCoordinateSystem {
}

drawPath(points, color = 'red', width = 2) {
if (!points || points.length < 2) return;
if (!points || points.length < 2) {
return;
}

this.ctx.beginPath();
this.ctx.moveTo(points[0].x, points[0].y);
Expand Down
941 changes: 375 additions & 566 deletions app/static/js/compare.js

Large diffs are not rendered by default.

26 changes: 20 additions & 6 deletions app/static/js/scout.add.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,19 @@ function startDrawing(e) {
}

function draw(e) {
if (!isDrawing) return;
if (!isDrawing) {
return;
}
e.preventDefault();
const point = getPointFromEvent(e);
currentPath.push(point);
redrawPaths();
}

function stopDrawing(e) {
if (!isDrawing) return;
if (!isDrawing) {
return;
}
e.preventDefault();
isDrawing = false;
if (currentPath.length > 1) {
Expand Down Expand Up @@ -123,13 +127,13 @@ function redrawPaths() {

function updateHiddenInput() {
const input = document.getElementById('auto_path');
input.value = JSON.stringify(paths);
input.value = paths.length > 0 ? JSON.stringify(paths) : JSON.stringify([]);
}

function undoLastPath() {
paths.pop();
redrawPaths();
updateHiddenInput();
updateHiddenInput();w
}

function clearCanvas() {
Expand All @@ -145,7 +149,9 @@ function resetZoom() {
}

function zoomIn(event) {
if (!coordSystem) return;
if (!coordSystem) {
return;
}
const rect = canvas.getBoundingClientRect();
let mouseX, mouseY;

Expand All @@ -165,7 +171,9 @@ function zoomIn(event) {
}

function zoomOut(event) {
if (!coordSystem) return;
if (!coordSystem) {
return;
}
const rect = canvas.getBoundingClientRect();
let mouseX, mouseY;

Expand Down Expand Up @@ -210,6 +218,12 @@ document.addEventListener('DOMContentLoaded', function() {
const eventCode = form.querySelector('input[name="event_code"]').value;
const matchNumber = form.querySelector('input[name="match_number"]').value;

// Initialize auto_path with empty array if not set
const autoPathInput = form.querySelector('input[name="auto_path"]');
if (!autoPathInput.value) {
autoPathInput.value = JSON.stringify([]);
}

try {
const response = await fetch(`/scouting/check_team?team=${teamNumber}&event=${eventCode}&match=${matchNumber}`);
const data = await response.json();
Expand Down
50 changes: 41 additions & 9 deletions app/static/js/scout.edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,39 @@ function initCanvas() {
if (pathDataInput && pathDataInput.value) {
try {
const rawValue = pathDataInput.value;
const cleanValue = rawValue.replace(/^"(.*)"$/, '$1');
const unescapedValue = cleanValue.replace(/\\"/g, '"');
paths = JSON.parse(unescapedValue);
// First, try parsing directly
try {
paths = JSON.parse(rawValue);
} catch {
// If direct parsing fails, try cleaning the string
const cleanValue = rawValue.replace(/^"(.*)"$/, '$1');
const unescapedValue = cleanValue.replace(/\\"/g, '"');
paths = JSON.parse(unescapedValue);
}

// Ensure paths is an array of arrays
if (!Array.isArray(paths)) {
console.error('Invalid path data format');
paths = [];
paths = [[paths]];
} else if (!Array.isArray(paths[0])) {
paths = [paths];
}

// Validate path structure
paths = paths.map(path => {
if (Array.isArray(path)) {
return path.map(point => {
if (typeof point === 'object' && 'x' in point && 'y' in point) {
return {
x: parseFloat(point.x),
y: parseFloat(point.y)
};
}
return null;
}).filter(point => point !== null);
}
return [];
}).filter(path => path.length > 0);

redrawPaths();
} catch (error) {
console.error('Error parsing path data:', error);
Expand Down Expand Up @@ -95,15 +119,19 @@ function startDrawing(e) {
}

function draw(e) {
if (!isDrawing) return;
if (!isDrawing) {
return;
}
e.preventDefault();
const point = getPointFromEvent(e);
currentPath.push(point);
redrawPaths();
}

function stopDrawing(e) {
if (!isDrawing) return;
if (!isDrawing) {
return;
}
e.preventDefault();
isDrawing = false;
if (currentPath.length > 1) {
Expand Down Expand Up @@ -152,7 +180,9 @@ function resetZoom() {
}

function zoomIn(event) {
if (!coordSystem) return;
if (!coordSystem) {
return;
}
const rect = canvas.getBoundingClientRect();
let mouseX, mouseY;

Expand All @@ -172,7 +202,9 @@ function zoomIn(event) {
}

function zoomOut(event) {
if (!coordSystem) return;
if (!coordSystem) {
return;
}
const rect = canvas.getBoundingClientRect();
let mouseX, mouseY;

Expand Down
16 changes: 12 additions & 4 deletions app/static/js/scout.list.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ function resizeModalCanvas() {
}

function redrawPaths() {
if (!modalCoordSystem || !currentPathData) return;
if (!modalCoordSystem || !currentPathData) {
return;
}

modalCoordSystem.clear();

Expand Down Expand Up @@ -68,7 +70,9 @@ function redrawPaths() {
}

function zoomIn(event) {
if (!modalCoordSystem) return;
if (!modalCoordSystem) {
return;
}
const rect = modalCanvas.getBoundingClientRect();
let mouseX = rect.width / 2;
let mouseY = rect.height / 2;
Expand All @@ -78,7 +82,9 @@ function zoomIn(event) {
}

function zoomOut(event) {
if (!modalCoordSystem) return;
if (!modalCoordSystem) {
return;
}
const rect = modalCanvas.getBoundingClientRect();
let mouseX = rect.width / 2;
let mouseY = rect.height / 2;
Expand All @@ -88,7 +94,9 @@ function zoomOut(event) {
}

function resetZoom() {
if (!modalCoordSystem) return;
if (!modalCoordSystem) {
return;
}
modalCoordSystem.resetView();
redrawPaths();
}
Expand Down
Loading

0 comments on commit 1173fe7

Please sign in to comment.