Files
pdga-rating/views/partials/course-layouts.ejs
T
Samuel Enocsson 9cb78c9c98 fix: address code-review findings from pass 1 + 2 (#8)
- Fix saveCourseToDB returning 0 on conflict by falling back to SELECT
- Fix inactive layouts showing 'Never played' when last_played exists
- Add .icon-btn.spinning to courses.css for refresh button feedback
- Remove duplicate .btn-primary from courses.css (use shared.css version)
- Tokenize rating tier colors into --rating-tier-{high,mid,low} CSS vars
- Convert var to const/let throughout courses.js
- Fix logger.error calls to use {err} object form (pino convention)
- Extract RATING_TIER_HIGH/MID constants in course-layouts.ejs scriptlet
- Remove dead href='#' View all link from courses.ejs (deferred)
- Pass total prop explicitly from course-table.ejs to course-cards.ejs
- Remove dead #search-results-info selector from mobile.css
- Remove redundant .replace(/"/g, '"') from data attributes in course-table.ejs
2026-05-25 09:54:15 +02:00

68 lines
2.5 KiB
Plaintext

<% if (!layouts || layouts.length === 0) { %>
<div class="no-layouts">No layouts found. Click the refresh button to scrape layouts.</div>
<% } else {
var oneYearAgo = new Date();
oneYearAgo.setDate(oneYearAgo.getDate() - 365);
var activeLayouts = [];
var inactiveLayouts = [];
layouts.forEach(function(l) {
if (l.last_played && new Date(l.last_played) >= oneYearAgo) {
activeLayouts.push(l);
} else {
inactiveLayouts.push(l);
}
});
var RATING_TIER_HIGH = 970;
var RATING_TIER_MID = 940;
function ratingTier(r) {
if (r == null) return null;
if (r >= RATING_TIER_HIGH) return 'green';
if (r >= RATING_TIER_MID) return 'amber';
return 'orange';
}
%>
<div class="layouts-header">
<span class="layouts-kicker">LAYOUTS</span>
<span class="layouts-count"><%= activeLayouts.length %> active &middot; <%= inactiveLayouts.length %> inactive</span>
</div>
<ul class="layout-list">
<% activeLayouts.forEach(function(l) { var tier = ratingTier(l.mean_rating); %>
<li class="layout-card layout-card--active">
<div class="layout-info">
<span class="layout-name"><%= l.name %></span>
<span class="layout-last-played">Last played: <%= l.last_played %></span>
</div>
<div class="layout-chips">
<span class="chip chip-par">Par <%= l.par %></span>
<% if (tier) { %><span class="chip chip-rating chip-rating--<%= tier %>">Rating: <%= Math.round(l.mean_rating) %></span><% } %>
</div>
</li>
<% }); %>
</ul>
<% if (inactiveLayouts.length > 0) { %>
<div class="inactive-layouts">
<button class="inactive-toggle" type="button" onclick="toggleInactiveLayouts(this)" aria-expanded="false">
<span>Inactive layouts (<%= inactiveLayouts.length %>) — Not played in last year</span>
<i class="icon-chev">&#9662;</i>
</button>
<ul class="layout-list inactive-layouts-body" hidden>
<% inactiveLayouts.forEach(function(l) { %>
<li class="layout-card layout-card--inactive">
<div class="layout-info">
<span class="layout-name"><%= l.name %></span>
<% if (l.last_played) { %>
<span class="layout-last-played">Last played: <%= l.last_played %></span>
<% } else { %>
<span class="layout-never-played">Never played</span>
<% } %>
</div>
<div class="layout-chips">
<span class="chip chip-par">Par <%= l.par %></span>
</div>
</li>
<% }); %>
</ul>
</div>
<% } %>
<% } %>