-
+
+
<%= it.name %>
Category: <%= it.category%>
Amount: <%= it.Amount %>
SKU: <%= it.SKU %>
@@ -9,4 +9,4 @@
-<%~ E.includeFile("foot.eta.html") %>
\ No newline at end of file
+<%~ E.includeFile("partials/foot.eta.html") %>
\ No newline at end of file
diff --git a/src/index.ts b/src/index.ts
index ed18f3d..26f0358 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -43,13 +43,19 @@ export const prisma = new PrismaClient({
});
export const app = express();
-app.engine("html", eta.renderFile)
+app.set('x-powered-by', false);
+app.set('strict routing', true);
+app.engine('html', eta.renderFile);
app.use(fileUpload());
// Configure static https://expressjs.com/de/starter/static-files.html
// app.use('/static', express.static('public'));
-app.use(express.static(__path + '/static'));
-routes(app);
+app.use(express.static(__path + '/static'));
+/* app.use((req, res, next) => {
+ res.status(404).send("Sorry can't find that!");
+}); */
+//routes(app);
+app.use(routes);
app.listen(config.global.http_port, config.global.http_listen_address, () => {
log.web.info(`Listening at http://${config.global.http_listen_address}:${config.global.http_port}`);
diff --git a/src/routes/frontend/dashboard.ts b/src/routes/frontend/dashboard.ts
new file mode 100644
index 0000000..4666853
--- /dev/null
+++ b/src/routes/frontend/dashboard.ts
@@ -0,0 +1,28 @@
+import express, { Request, Response } from 'express';
+import { prisma, __path } from '../../index.js';
+
+export default (req: Request, res: Response) => {
+ // TODO: Fix it? Express behaves like fucking shit with routers and /. Do not ask about it or touch it. EVER! (But if you can fix it a PR is welcome!)
+ if (req.originalUrl !== '/') {
+ res.status(404).render(__path + '/src/frontend/errors/404.eta.html', { url: req.originalUrl });
+ } else {
+ prisma.item
+ .findMany({
+ orderBy: {
+ updatedAt: 'desc'
+ },
+ // Limit to 10 items
+ take: 10
+ })
+ .then((items) => {
+ // Count amount of total items
+ prisma.item.count().then((count) => {
+ res.render(__path + '/src/frontend/dashboard.eta.html', { recents: items, stats: { total: count } });
+ });
+ })
+ .catch((err) => {
+ console.error(err);
+ res.status(500).render(__path + '/src/frontend/errors/dbError.eta.html', { error: err });
+ });
+ }
+};
diff --git a/src/routes/frontend/etaTest.ts b/src/routes/frontend/etaTest.ts
deleted file mode 100644
index 9d8f614..0000000
--- a/src/routes/frontend/etaTest.ts
+++ /dev/null
@@ -1,18 +0,0 @@
-import express, { Request, Response } from 'express';
-import { prisma, __path } from '../../index.js';
-
-export default (req: Request, res: Response) => {
- prisma.item.findMany({
- orderBy: {
- updatedAt: 'desc'
- },
- // Limit to 10 items
- take: 10
- }).then((items) => {
- // Count amount of total items
- prisma.item.count().then((count) => {
- res.render(__path + '/src/frontend/demopage.eta.html', { recents: items, stats: { total: count } });
- });
- });
- // res.render(__path + '/src/frontend/demopage.eta.html');
-};
\ No newline at end of file
diff --git a/src/routes/frontend/import/csvImport.ts b/src/routes/frontend/import/csvImport.ts
index 8118577..853f840 100644
--- a/src/routes/frontend/import/csvImport.ts
+++ b/src/routes/frontend/import/csvImport.ts
@@ -36,8 +36,6 @@ export default (req: Request, res: Response) => {
values.forEach((value) => {
categories.delete(value.name);
});
- // Log categories
- log.web.debug(categories);
const categoryPromises: PrismaPromise
[] = [];
categories.forEach((category: string) => {
@@ -71,8 +69,6 @@ export default (req: Request, res: Response) => {
}
});
listOfPromises.push(promise);
-
-
}
Promise.all(listOfPromises).then((values) => {
console.log(values);
diff --git a/src/routes/frontend/index.ts b/src/routes/frontend/index.ts
index f20cfe3..885f74e 100644
--- a/src/routes/frontend/index.ts
+++ b/src/routes/frontend/index.ts
@@ -3,16 +3,18 @@ import express from 'express';
// Route imports
import skuRoute from './:id.js';
import testRoute from './test.js';
-import etaTestRoute from './etaTest.js';
+import dashboardRoute from './dashboard.js';
import csvImportRoute from './import/csvImport.js';
+import listAllItems from './listAllItems.js';
// Router base is '/'
-const Router = express.Router();
+const Router = express.Router({ strict: false });
+
-Router.use('/etaTest', etaTestRoute);
-Router.use('/:id(\\w{8})', skuRoute);
Router.use('/test', testRoute);
+Router.use('/allItems', listAllItems)
Router.use('/import/csv', csvImportRoute);
-
+Router.use('/:id(\\w{8})', skuRoute);
+Router.use('/', dashboardRoute);
export default Router;
diff --git a/src/routes/frontend/listAllItems.ts b/src/routes/frontend/listAllItems.ts
new file mode 100644
index 0000000..18964d3
--- /dev/null
+++ b/src/routes/frontend/listAllItems.ts
@@ -0,0 +1,15 @@
+import express, { Request, Response } from 'express';
+import { prisma, __path } from '../../index.js';
+
+export default (req: Request, res: Response) => {
+ prisma.item
+ .findMany({})
+ .then((items) => {
+ // Count amount of total items
+ res.render(__path + '/src/frontend/allItems.eta.html', { items: items });
+ })
+ .catch((err) => {
+ console.error(err);
+ res.status(500).render(__path + '/src/frontend/errors/dbError.eta.html', { error: err });
+ });
+};
diff --git a/src/routes/index.ts b/src/routes/index.ts
index a7c0c97..69bc8b3 100644
--- a/src/routes/index.ts
+++ b/src/routes/index.ts
@@ -1,4 +1,4 @@
-import { Express } from 'express';
+import express, { Express } from 'express';
// Route imports
import frontend_routes from './frontend/index.js';
@@ -6,9 +6,11 @@ import static_routes from './static/index.js';
import api_routes from './api/index.js';
import dev_routes from './dev/index.js';
-export default (app: Express) => {
- app.use('/', frontend_routes);
- app.use('/static', static_routes);
- app.use('/api', api_routes);
- app.use('/dev', dev_routes); // This is just for development. ToDo: Add check if we are in devmode.
-};
+const Router = express.Router({ strict: false });
+
+Router.use('/static', static_routes);
+Router.use('/api', api_routes);
+Router.use('/dev', dev_routes); // This is just for development. ToDo: Add check if we are in devmode.
+Router.use('/', frontend_routes);
+
+export default Router;
\ No newline at end of file
diff --git a/static/css/dashboard.css b/static/css/dashboard.css
index 6c940b3..6f02918 100644
--- a/static/css/dashboard.css
+++ b/static/css/dashboard.css
@@ -2,12 +2,6 @@ body {
font-size: 0.875rem;
}
-.feather {
- width: 16px;
- height: 16px;
- vertical-align: text-bottom;
-}
-
/*
* Sidebar
*/
@@ -98,3 +92,11 @@ body {
border-color: transparent;
box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.25);
}
+
+.autocomplete-items {
+ position: absolute;
+ z-index: 99;
+ top: 100%;
+ left: 0;
+ right: 0;
+}
diff --git a/static/js/searchBox.js b/static/js/searchBox.js
index 4a821e4..a504f1d 100644
--- a/static/js/searchBox.js
+++ b/static/js/searchBox.js
@@ -1,11 +1,24 @@
document.getElementById("SearchBox").addEventListener("keyup", handleSearchChange);
+const autocompleteBox = document.getElementById("autocomplete-items");
+autocompleteBox.style.display = "none";
function handleSearchChange(e) {
console.log(e.target.value);
// Check if known prefix is used (either > or #)
+ if(e.target.value != "" ) {
+ autocompleteBox.style.display = "block";
+ autocompleteBox.innerHTML = "Search results will show up here soon
Trust me
Results";
+ } else {
+ autocompleteBox.style.display = "none";
+ }
+
if (e.target.value[0] == ">") {
- // Search for commands
+ autocompleteBox.innerHTML = "Start typing to search for commands
>goto items";
+ if(e.target.value == ">goto items") {
+ autocompleteBox.innerHTML = "Goto Items";
+ }
} else if (e.target.value[0] == "#") {
// Search for SKU
+ autocompleteBox.innerHTML = "Start typing to search for items by SKU";
} else {
// Search for name
}