From 259063862911e5f8b82e0f82ba43490351186801 Mon Sep 17 00:00:00 2001 From: Luke Emery-Fertitta Date: Thu, 15 Feb 2024 08:40:25 -0800 Subject: [PATCH] Use led_colors --- climbdex/db.py | 8 ++++++++ climbdex/static/js/bluetooth.js | 3 +-- climbdex/static/js/climbCreation.js | 6 +----- climbdex/static/js/results.js | 15 ++++++--------- climbdex/templates/climbCreation.html.j2 | 1 + climbdex/templates/results.html.j2 | 1 + climbdex/views.py | 10 ++++++++++ 7 files changed, 28 insertions(+), 16 deletions(-) diff --git a/climbdex/db.py b/climbdex/db.py index cb8ecdf..4c41a8f 100644 --- a/climbdex/db.py +++ b/climbdex/db.py @@ -75,6 +75,14 @@ INNER JOIN leds ON placements.hole_id = leds.hole_id WHERE placements.layout_id = $layout_id AND leds.product_size_id = $size_id""", + "led_colors": """ + SELECT + placement_roles.id, + placement_roles.led_color + FROM placement_roles + JOIN layouts + ON layouts.product_id = placement_roles.product_id + WHERE layouts.id = $layout_id""", "image_filename": """ SELECT image_filename diff --git a/climbdex/static/js/bluetooth.js b/climbdex/static/js/bluetooth.js index a709b32..35ca568 100644 --- a/climbdex/static/js/bluetooth.js +++ b/climbdex/static/js/bluetooth.js @@ -40,8 +40,7 @@ function encodePosition(position) { return [position1, position2]; } -function encodeColor(hexColorString) { - const color = hexColorString.substring(1); +function encodeColor(color) { const substring = color.substring(0, 2); const substring2 = color.substring(2, 4); diff --git a/climbdex/static/js/climbCreation.js b/climbdex/static/js/climbCreation.js index ff8d15d..995126a 100644 --- a/climbdex/static/js/climbCreation.js +++ b/climbdex/static/js/climbCreation.js @@ -30,15 +30,11 @@ function getFrames() { document .getElementById("button-illuminate") .addEventListener("click", function () { - const colorMap = colors.reduce((acc, colorRow) => { - acc[colorRow[0]] = colorRow[1]; - return acc; - }, {}); const frames = getFrames(); let bluetoothPacket = getBluetoothPacket( frames, placementPositions, - colorMap + ledColors ); const urlParams = new URLSearchParams(window.location.search); diff --git a/climbdex/static/js/results.js b/climbdex/static/js/results.js index 8b4b5cc..621bd65 100644 --- a/climbdex/static/js/results.js +++ b/climbdex/static/js/results.js @@ -3,7 +3,6 @@ const colorMap = colors.reduce((acc, colorRow) => { return acc; }, {}); - function drawClimb( uuid, name, @@ -68,11 +67,10 @@ function drawClimb( betaAnchor.href = `/${board}/beta/${uuid}/`; document.getElementById("button-illuminate").onclick = function () { - console.log(frames, placementPositions, colorMap); const bluetoothPacket = getBluetoothPacket( frames, placementPositions, - colorMap + ledColors ); illuminateClimb(board, bluetoothPacket); }; @@ -115,10 +113,7 @@ function clickClimbButton(index, pageSize, resultsCount) { function getTickPath() { const path = document.createElementNS("http://www.w3.org/2000/svg", "path"); - path.setAttribute( - "d", - "M 30,180 90,240 240,30" - ); + path.setAttribute("d", "M 30,180 90,240 240,30"); path.setAttribute("style", "stroke:#000; stroke-width:25; fill:none"); return path; } @@ -131,7 +126,10 @@ function getTickSvg(tickType) { const upwardShift = 30; const centerX = viewBoxSize / 2; - tickSvg.setAttribute("viewBox", `0 +${upwardShift} ${viewBoxSize} ${viewBoxSize - upwardShift}`); + tickSvg.setAttribute( + "viewBox", + `0 +${upwardShift} ${viewBoxSize} ${viewBoxSize - upwardShift}` + ); tickSvg.setAttribute("height", `${tickSize}px`); tickSvg.setAttribute("width", `${tickSize}px`); @@ -245,4 +243,3 @@ fetchResultsCount().then((resultsCount) => { drawResultsPage(results, 0, 10, resultsCount); }); }); - diff --git a/climbdex/templates/climbCreation.html.j2 b/climbdex/templates/climbCreation.html.j2 index 4bb61af..6a8c0fc 100644 --- a/climbdex/templates/climbCreation.html.j2 +++ b/climbdex/templates/climbCreation.html.j2 @@ -39,6 +39,7 @@