Add/apply prettier

This commit is contained in:
Adam Goldsmith 2024-07-23 00:01:29 -04:00
parent 5f920825cc
commit b60d9f6644
16 changed files with 173 additions and 126 deletions

View File

@ -1,5 +1,5 @@
name: Ruff name: Ruff
on: [ push, pull_request ] on: [push, pull_request]
jobs: jobs:
ruff: ruff:
runs-on: ubuntu-latest runs-on: ubuntu-latest

View File

@ -1,5 +1,5 @@
name: Test name: Test
on: [ push, pull_request ] on: [push, pull_request]
env: env:
DJANGO_CONFIGURATION: CI DJANGO_CONFIGURATION: CI
@ -14,7 +14,14 @@ jobs:
env: env:
MARIADB_ROOT_PASSWORD: whatever MARIADB_ROOT_PASSWORD: whatever
healthcheck: healthcheck:
test: ["CMD", "healthcheck.sh", "--su-mysql", "--connect", "--innodb_initialized"] test:
[
"CMD",
"healthcheck.sh",
"--su-mysql",
"--connect",
"--innodb_initialized",
]
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: Setup PDM - name: Setup PDM

6
.prettierignore Normal file
View File

@ -0,0 +1,6 @@
*.dj.html
pnpm-lock.yaml
.mypy_cache/
.venv/
.pytest_cache/

0
.prettierrc Normal file
View File

View File

@ -1,7 +1,8 @@
import { Tooltip } from "bootstrap"; import { Tooltip } from "bootstrap";
const tooltipTriggerList = document.querySelectorAll( const tooltipTriggerList = document.querySelectorAll(
'[data-bs-toggle="tooltip"]', '[data-bs-toggle="tooltip"]',
); );
for (let tooltipTriggerEl of tooltipTriggerList) { for (const tooltipTriggerElement of tooltipTriggerList) {
new Tooltip(tooltipTriggerEl); new Tooltip(tooltipTriggerElement);
} }

View File

@ -1,3 +1,3 @@
import 'bootstrap/scss/bootstrap.scss'; import "bootstrap/scss/bootstrap.scss";
import 'bootstrap-icons/font/bootstrap-icons.css'; import "bootstrap-icons/font/bootstrap-icons.css";
import 'bootstrap'; import "bootstrap";

View File

@ -70,13 +70,13 @@ p {
} }
.d-md-block { .d-md-block {
display: block !important; display: block !important;
} }
.col-md-7 { .col-md-7 {
flex: 0 0 auto; flex: 0 0 auto;
width: 58.33333333%; width: 58.33333333%;
} }
.col-md-4 { .col-md-4 {
flex: 0 0 auto; flex: 0 0 auto;
width: 33.33333333%; width: 33.33333333%;
} }

View File

@ -1,7 +1,8 @@
@page { @page {
background-image:url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' version='1.1' width='75' height='75' viewBox='0 0 75 75'><text style='font-size:13px;fill:lightgrey' x='-49' y='58' id='text1' transform='rotate(-45)'>PREVIEW</text></svg>"); background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' version='1.1' width='75' height='75' viewBox='0 0 75 75'><text style='font-size:13px;fill:lightgrey' x='-49' y='58' id='text1' transform='rotate(-45)'>PREVIEW</text></svg>");
} }
body, table * { body,
background: transparent !important; table * {
background: transparent !important;
} }

View File

@ -11,6 +11,7 @@
"devDependencies": { "devDependencies": {
"@types/bootstrap": "^5.2.10", "@types/bootstrap": "^5.2.10",
"@types/tabulator-tables": "^6.2.3", "@types/tabulator-tables": "^6.2.3",
"prettier": "^3.3.3",
"sass": "^1.77.8", "sass": "^1.77.8",
"typescript": "^5.5.4", "typescript": "^5.5.4",
"vite": "^5.3.4" "vite": "^5.3.4"

View File

@ -4,7 +4,7 @@ import {
FilterModule, FilterModule,
HtmlTableImportModule, HtmlTableImportModule,
ResponsiveLayoutModule, ResponsiveLayoutModule,
FilterType, type FilterType,
} from "tabulator-tables"; } from "tabulator-tables";
import "tabulator-tables/src/scss/themes/bootstrap/tabulator_bootstrap5.scss"; import "tabulator-tables/src/scss/themes/bootstrap/tabulator_bootstrap5.scss";
@ -16,14 +16,16 @@ Tabulator.registerModule([
]); ]);
Tabulator.extendModule("filter", "filters", { Tabulator.extendModule("filter", "filters", {
"!includes": function(headerValue: string, rowValue: string){ "!includes"(headerValue: string, rowValue: string) {
return !rowValue.includes(headerValue); return !rowValue.includes(headerValue);
} },
}); });
const certification_table_el = document.querySelector("table.certifications"); const certification_table_element = document.querySelector(
if (certification_table_el instanceof HTMLTableElement) { "table.certifications",
const certification_table = new Tabulator(certification_table_el, { );
if (certification_table_element instanceof HTMLTableElement) {
const certification_table = new Tabulator(certification_table_element, {
layout: "fitDataFill", layout: "fitDataFill",
responsiveLayout: "collapse", responsiveLayout: "collapse",
pagination: true, pagination: true,
@ -31,7 +33,7 @@ if (certification_table_el instanceof HTMLTableElement) {
columnDefaults: { columnDefaults: {
headerFilter: true, headerFilter: true,
}, },
rowFormatter: function (row) { rowFormatter(row) {
const data = row.getData(); const data = row.getData();
if (data.version.includes("[OUTDATED]")) { if (data.version.includes("[OUTDATED]")) {
row.getElement().classList.add("table-warning"); row.getElement().classList.add("table-warning");
@ -80,19 +82,27 @@ if (certification_table_el instanceof HTMLTableElement) {
function setOutdatedFilter(showOutdated: boolean) { function setOutdatedFilter(showOutdated: boolean) {
if (showOutdated) { if (showOutdated) {
certification_table.removeFilter("version", "!includes" as FilterType, "[OUTDATED]"); certification_table.removeFilter(
"version",
"!includes" as FilterType,
"[OUTDATED]",
);
} else { } else {
certification_table.addFilter("version", "!includes" as FilterType, "[OUTDATED]"); certification_table.addFilter(
"version",
"!includes" as FilterType,
"[OUTDATED]",
);
} }
} }
certification_table.on("tableBuilt", () => { certification_table.on("tableBuilt", () => {
const outdatedToggle = document.getElementById("showOutdated"); const outdatedToggle = document.querySelector("#showOutdated");
if (outdatedToggle instanceof HTMLInputElement) { if (outdatedToggle instanceof HTMLInputElement) {
setOutdatedFilter(outdatedToggle.checked); setOutdatedFilter(outdatedToggle.checked);
outdatedToggle.addEventListener("change", () => outdatedToggle.addEventListener("change", () => {
setOutdatedFilter(outdatedToggle.checked), setOutdatedFilter(outdatedToggle.checked);
); });
} }
}); });
} }

View File

@ -1,10 +1,15 @@
window.addEventListener('load', function() { window.addEventListener("load", function () {
// Bind on certification_definition field change // Bind on certification_definition field change
django.jQuery(':input[name$=certification_definition]').on('change', function() { django
// Get the field prefix, ie. if this comes from a formset form .jQuery(":input[name$=certification_definition]")
var prefix = django.jQuery(this).getFormPrefix(); .on("change", function () {
// Get the field prefix, ie. if this comes from a formset form
const prefix = django.jQuery(this).getFormPrefix();
// Clear the autocomplete with the same prefix // Clear the autocomplete with the same prefix
django.jQuery(':input[name=' + prefix + 'certification_version]').val(null).trigger('change'); django
.jQuery(":input[name=" + prefix + "certification_version]")
.val(null)
.trigger("change");
}); });
}); });

View File

@ -1,88 +1,94 @@
#cert-data { #cert-data {
string-set: certname attr(data-name), string-set:
certversion attr(data-version), certname attr(data-name),
certapprovaldate attr(data-approvaldate); certversion attr(data-version),
/* Can't be `display: none;`, as it breaks string-set */ certapprovaldate attr(data-approvaldate);
visibility: hidden; /* Can't be `display: none;`, as it breaks string-set */
position: absolute; visibility: hidden;
bottom: 0px; position: absolute;
bottom: 0px;
} }
.checklist li::marker { .checklist li::marker {
content: "□\00A0"; content: "□\00A0";
padding-right: 1em; padding-right: 1em;
} }
.no-break { .no-break {
break-inside: avoid; break-inside: avoid;
} }
@media print { @media print {
body, p, li { body,
font-size: 10pt !important; p,
line-height: 1.2 !important; li {
font-size: 10pt !important;
line-height: 1.2 !important;
}
.no-print,
.print-warning,
.toc,
body > :not(.mw-page-container),
#content > :not(#bodyContent),
#bodyContent > :not(#mw-content-text),
#mw-content-text > :not(.mw-parser-output) {
display: none !important;
}
h1,
h2,
h3,
h4 {
padding-top: 0em !important;
margin-top: 0em !important;
break-before: auto !important;
}
.qrlite-result img {
width: 1.5in;
}
/* Turn off mediawiki's added text for mailto links */
a[href^="mailto:"]::after {
content: none !important;
}
/* Add link target as text, except mailto links */
a:not([href^="mailto:"])::after {
content: " [" attr(href) "]";
color: initial;
text-decoration: none;
}
@page {
size: letter portrait;
margin: 1in;
@top-left {
content: string(certname);
font-size: 1.2em;
color: #444;
vertical-align: bottom;
padding-bottom: 0.2em;
} }
.no-print, @top-right {
.print-warning, content: "";
.toc, background-image: url("https://claremontmakerspace.org/wp-content/uploads/2018/06/cms_logo.png");
body > :not(.mw-page-container), background-repeat: no-repeat;
#content > :not(#bodyContent), background-position: bottom;
#bodyContent > :not(#mw-content-text), background-size: 100%;
#mw-content-text > :not(.mw-parser-output) { width: 7em;
display: none !important;
} }
h1, h2, h3, h4 { @bottom-left {
padding-top: 0em !important; content: string(certversion) " - " string(certapprovaldate);
margin-top: 0em !important; color: #444;
break-before: auto !important;
} }
.qrlite-result img { @bottom-right-corner {
width: 1.5in; content: counter(page);
}
/* Turn off mediawiki's added text for mailto links */
a[href^="mailto:"]::after {
content: none !important;
}
/* Add link target as text, except mailto links */
a:not([href^="mailto:"])::after {
content: " [" attr(href) "]";
color: initial;
text-decoration: none;
}
@page {
size: letter portrait;
margin: 1in;
@top-left {
content: string(certname);
font-size: 1.2em;
color: #444;
vertical-align: bottom;
padding-bottom: 0.2em;
}
@top-right {
content: '';
background-image: url("https://claremontmakerspace.org/wp-content/uploads/2018/06/cms_logo.png");
background-repeat: no-repeat;
background-position: bottom;
background-size: 100%;
width: 7em;
}
@bottom-left {
content: string(certversion) " - " string(certapprovaldate);
color: #444;
}
@bottom-right-corner {
content: counter(page);
}
} }
}
} }

View File

@ -27,6 +27,9 @@ importers:
'@types/tabulator-tables': '@types/tabulator-tables':
specifier: ^6.2.3 specifier: ^6.2.3
version: 6.2.3 version: 6.2.3
prettier:
specifier: ^3.3.3
version: 3.3.3
sass: sass:
specifier: ^1.77.8 specifier: ^1.77.8
version: 1.77.8 version: 1.77.8
@ -350,6 +353,11 @@ packages:
resolution: {integrity: sha512-0vzE+lAiG7hZl1/9I8yzKLx3aR9Xbof3fBHKunvMfOCYAtMhrsnccJY2iTURb9EZd5+pLuiNV9/c/GZJOHsgIw==} resolution: {integrity: sha512-0vzE+lAiG7hZl1/9I8yzKLx3aR9Xbof3fBHKunvMfOCYAtMhrsnccJY2iTURb9EZd5+pLuiNV9/c/GZJOHsgIw==}
engines: {node: ^10 || ^12 || >=14} engines: {node: ^10 || ^12 || >=14}
prettier@3.3.3:
resolution: {integrity: sha512-i2tDNA0O5IrMO757lfrdQZCc2jPNDVntV0m/+4whiDfWaTKfMNgR7Qz0NAeGz/nRqF4m5/6CLzbP4/liHt12Ew==}
engines: {node: '>=14'}
hasBin: true
readdirp@3.6.0: readdirp@3.6.0:
resolution: {integrity: sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==} resolution: {integrity: sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==}
engines: {node: '>=8.10.0'} engines: {node: '>=8.10.0'}
@ -631,6 +639,8 @@ snapshots:
picocolors: 1.0.1 picocolors: 1.0.1
source-map-js: 1.2.0 source-map-js: 1.2.0
prettier@3.3.3: {}
readdirp@3.6.0: readdirp@3.6.0:
dependencies: dependencies:
picomatch: 2.3.1 picomatch: 2.3.1

View File

@ -1,6 +1,4 @@
{ {
"$schema": "https://docs.renovatebot.com/renovate-schema.json", "$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [ "extends": ["config:recommended"]
"config:recommended"
]
} }

View File

@ -27,9 +27,9 @@
theme === "auto" && theme === "auto" &&
window.matchMedia("(prefers-color-scheme: dark)").matches window.matchMedia("(prefers-color-scheme: dark)").matches
) { ) {
document.documentElement.setAttribute("data-bs-theme", "dark"); document.documentElement.dataset.bsTheme = "dark";
} else { } else {
document.documentElement.setAttribute("data-bs-theme", theme); document.documentElement.dataset.bsTheme = theme;
} }
}; };
@ -44,25 +44,27 @@
const themeSwitcherText = document.querySelector("#bd-theme-text"); const themeSwitcherText = document.querySelector("#bd-theme-text");
const activeThemeIcon = document.querySelector(".theme-icon-active"); const activeThemeIcon = document.querySelector(".theme-icon-active");
const btnToActive = document.querySelector( const buttonToActive = document.querySelector(
`[data-bs-theme-value="${theme}"]`, `[data-bs-theme-value="${theme}"]`,
); );
const activeIcon = [ const activeIcon = [
...btnToActive.querySelector(".theme-icon").classList, ...buttonToActive.querySelector(".theme-icon").classList,
].find((c) => c.startsWith("bi-")); ].find((c) => c.startsWith("bi-"));
document.querySelectorAll("[data-bs-theme-value]").forEach((element) => { for (const element of document.querySelectorAll("[data-bs-theme-value]")) {
element.classList.remove("active"); element.classList.remove("active");
element.setAttribute("aria-pressed", "false"); element.setAttribute("aria-pressed", "false");
}); }
btnToActive.classList.add("active"); buttonToActive.classList.add("active");
btnToActive.setAttribute("aria-pressed", "true"); buttonToActive.setAttribute("aria-pressed", "true");
[...activeThemeIcon.classList] for (const icon of activeThemeIcon.classList) {
.filter((c) => c.startsWith("bi-")) if (icon.startsWith("bi-")) {
.forEach((icon) => activeThemeIcon.classList.remove(icon)); activeThemeIcon.classList.remove(icon);
}
}
activeThemeIcon.classList.add(activeIcon); activeThemeIcon.classList.add(activeIcon);
const themeSwitcherLabel = `${themeSwitcherText.textContent} (${btnToActive.dataset.bsThemeValue})`; const themeSwitcherLabel = `${themeSwitcherText.textContent} (${buttonToActive.dataset.bsThemeValue})`;
themeSwitcher.setAttribute("aria-label", themeSwitcherLabel); themeSwitcher.setAttribute("aria-label", themeSwitcherLabel);
if (focus) { if (focus) {
@ -80,16 +82,16 @@
}); });
window.addEventListener("DOMContentLoaded", () => { window.addEventListener("DOMContentLoaded", () => {
console.log(getPreferredTheme()); console.log(getPreferredTheme());
showActiveTheme(getPreferredTheme()); showActiveTheme(getPreferredTheme());
document.querySelectorAll("[data-bs-theme-value]").forEach((toggle) => { for (const toggle of document.querySelectorAll("[data-bs-theme-value]")) {
toggle.addEventListener("click", () => { toggle.addEventListener("click", () => {
const theme = toggle.getAttribute("data-bs-theme-value"); const theme = toggle.dataset.bsThemeValue;
setStoredTheme(theme); setStoredTheme(theme);
setTheme(theme); setTheme(theme);
showActiveTheme(theme, true); showActiveTheme(theme, true);
}); });
}); }
}); });
})(); })();

View File

@ -1,5 +1,5 @@
import { resolve, join } from "node:path";
import { defineConfig } from "vite"; import { defineConfig } from "vite";
import { resolve, join } from "path";
export default defineConfig({ export default defineConfig({
base: "/static/", base: "/static/",