-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0382e28
commit e091e4b
Showing
17 changed files
with
237 additions
and
30 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
(function() { | ||
'use strict'; | ||
let searchButton = document.querySelector('.global-search'); | ||
|
||
searchButton.addEventListener('click', function() { | ||
let isSearch = document | ||
.querySelector('.main-nav') | ||
.classList.contains('search-mode'); | ||
if (!isSearch) { | ||
document.querySelector('.main-nav').classList.add('search-mode'); | ||
document.querySelector('.main-nav .search-input').focus(); | ||
} else { | ||
document.querySelector('.main-nav').classList.remove('search-mode'); | ||
document.querySelector('.main-nav .search-input').value = null; | ||
} | ||
}); | ||
|
||
document | ||
.querySelector('.main-nav .search-input') | ||
.addEventListener('keydown', function(/** @type {KeyboardEvent}*/ evt) { | ||
if (evt.keyCode === 27 /* esc */) { | ||
document.querySelector('.main-nav').classList.remove('search-mode'); | ||
evt.target.value = null; | ||
} | ||
}); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { getDb } from '../db/utils'; | ||
import { sql } from '../sql-string'; | ||
|
||
export async function getSearchResults(term: string): Promise<any[]> { | ||
let db = await getDb(); | ||
return db.all( | ||
sql` | ||
SELECT * from | ||
(SELECT 'product' as entity, productname as name, productname as the_text, ('' || id) as id FROM Product | ||
UNION | ||
SELECT 'supplier' as entity, companyname as name, companyname as the_text, ('' || id) as id FROM Supplier | ||
UNION | ||
SELECT 'customer' as entity, companyname as name, companyname as the_text, ('' || id) as id FROM Customer | ||
UNION | ||
SELECT 'category' as entity, categoryname as name, categoryname as the_text, ('' || id) as id FROM Category | ||
UNION | ||
SELECT 'employee' as entity, (firstname || ' ' || lastname) as name, (firstname || ' ' || lastname) as the_text, ('' || id) as id FROM Employee | ||
) as a | ||
WHERE lower(a.the_text) LIKE $1`, | ||
`%${term}%` | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export default function entityUrl(entity: string, id: string) { | ||
switch (entity) { | ||
case 'employee': | ||
return `/employees/${id}`; | ||
case 'customer': | ||
return `/customers/${id}`; | ||
case 'supplier': | ||
return `/supplier/${id}`; | ||
case 'product': | ||
return `/product/${id}`; | ||
default: | ||
throw new Error(`No URL-building strategy for ${entity}`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import * as express from 'express'; | ||
import { getSearchResults } from '../data/search'; | ||
import { logger } from '../log'; | ||
|
||
const router = express.Router(); | ||
|
||
router.get('/', async (req, res, next) => { | ||
try { | ||
let results = await getSearchResults(req.param('s').toLowerCase()); | ||
res.render('search', { results }); | ||
} catch (e) { | ||
next(e); | ||
} | ||
}); | ||
|
||
export default router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
declare module 'server-timing'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.