Skip to content

Commit

Permalink
fix search; squash migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderGi committed Apr 28, 2024
1 parent 059b3e3 commit e7121aa
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 78 deletions.
4 changes: 2 additions & 2 deletions migrations/0002_modify_businesses.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Automatically created by 'sqlite auto migrator (SAM)' on 2024-04-28T18:51:38.159Z
// Automatically created by 'sqlite auto migrator (SAM)' on 2024-04-28T21:24:47.850Z

import { Database } from 'sqlite-auto-migrator';

Expand All @@ -12,7 +12,7 @@ export const PRAGMAS = {"analysis_limit":0,"application_id":0,"auto_vacuum":0,"a
* @param {Database} db database instance to run SQL commands on
*/
export async function up(db) {
await db.run("ALTER TABLE \"businesses\" ADD COLUMN \"absentemail\" INTEGER DEFAULT 1");
await db.run("ALTER TABLE \"businesses\" ADD COLUMN \"absentemail\" INTEGER NOT NULL DEFAULT 1");
}

/**
Expand Down
31 changes: 0 additions & 31 deletions migrations/0003_modify_businesses.mjs

This file was deleted.

50 changes: 8 additions & 42 deletions public/components/DataTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,48 +309,14 @@ export class DataTable extends Component {
search.type = 'search';
search.placeholder = 'Search NAME';
th.replaceChildren(search);
search.oninput = e => {
let switching = true;
while (switching) {
let i;
switching = false;
let shouldSwitch = false;
let rows = this.shadowRoot.getElementById('table').querySelectorAll('tr');
/* Loop through all table rows (except the
first, which contains table headers): */
for (i = 1; i < rows.length - 1; i++) {
/* Start by saying there should be no switching: */
shouldSwitch = false;
/* Get the two elements you want to compare,
one from current row and one from the next: */
let x = rows[i].querySelectorAll('td')[1];
let y = rows[i + 1].querySelectorAll('td')[1];
/* Check if the two rows should switch place,
based on the direction, asc or desc: */
if (e.target.value) {
if (
calcSimilarity(x.textContent, e.target.value) <
calcSimilarity(y.textContent, e.target.value)
) {
/* If so, mark as a switch and break the loop: */
shouldSwitch = true;
break;
}
} else {
if (x.textContent.toLowerCase() > y.textContent.toLowerCase()) {
/* If so, mark as a switch and break the loop: */
shouldSwitch = true;
break;
}
}
}
if (shouldSwitch) {
/* If a switch has been marked, make the switch
and mark the switch as done: */
rows[i].parentNode.insertBefore(rows[i + 1], rows[i]);
switching = true;
}
}
search.oninput = () => {
const searchValue = search.value;
this.rows.sort((a, b) => {
const valA = a[header];
const valB = b[header];
return calcSimilarity(valB, searchValue) - calcSimilarity(valA, searchValue);
});
this.showPage(1);
};
}

Expand Down
6 changes: 3 additions & 3 deletions public/util/Component.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Creates a template element from an html string.
* @param {string} html string representing any number of sibling elements
* @returns a template element with html is its innerHTML.
* @returns a template element with html as its innerHTML.
*/
function htmlToTemplate(html) {
const template = document.createElement('template');
Expand All @@ -20,7 +20,7 @@ export function htmlToElements(html) {

/**
* Utility class to make Web Component creation simpler.
* @Important Each component must be defined in its own file. Safari does not support multiple components registered in the same file.
* @Important Each component must be defined in its own file.
* @link Web Components: https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_custom_elements#high-level_view
* @link Web Component Lifecycle: https://bignerdranch.com/blog/learn-the-lifecycle-of-a-web-component-by-building-a-custom-element/
* @abstract
Expand All @@ -40,7 +40,7 @@ export class Component extends HTMLElement {

/**
* Creates a basic web component.
* @params sharedTemplate true if all instances should share the same HTML template (default), false otherwise)
* @params sharedTemplate true if all instances should share the same HTML template (default), false otherwise
*/
constructor(sharedTemplate = true) {
super(); // initialize component (should always be called first)
Expand Down

0 comments on commit e7121aa

Please sign in to comment.