From 95ec75b8d7dd62e03d7aa42d1c5699a2cd303989 Mon Sep 17 00:00:00 2001 From: Spacelord Date: Thu, 4 May 2023 20:21:10 +0200 Subject: [PATCH] current state --- allowedStaticPaths.json | 4 +- src/frontend/allItems.eta.html | 29 +++++++++++ src/frontend/dashboard.eta.html | 54 ++++++++++++++++++++ src/frontend/demopage.eta.html | 62 ----------------------- src/frontend/errors/404.eta.html | 8 +++ src/frontend/errors/dbError.eta.html | 15 ++++++ src/frontend/imports/csvImport.eta.html | 4 +- src/frontend/index.eta.html | 6 --- src/frontend/partials/controls.eta.html | 67 ++++++++++++++++++------- src/frontend/partials/head.eta.html | 1 - src/frontend/publicInfoPage.eta.html | 8 +-- src/index.ts | 12 +++-- src/routes/frontend/dashboard.ts | 28 +++++++++++ src/routes/frontend/etaTest.ts | 18 ------- src/routes/frontend/import/csvImport.ts | 4 -- src/routes/frontend/index.ts | 12 +++-- src/routes/frontend/listAllItems.ts | 15 ++++++ src/routes/index.ts | 16 +++--- static/css/dashboard.css | 14 +++--- static/js/searchBox.js | 15 +++++- 20 files changed, 255 insertions(+), 137 deletions(-) create mode 100644 src/frontend/allItems.eta.html create mode 100644 src/frontend/dashboard.eta.html delete mode 100644 src/frontend/demopage.eta.html create mode 100644 src/frontend/errors/404.eta.html create mode 100644 src/frontend/errors/dbError.eta.html delete mode 100644 src/frontend/index.eta.html create mode 100644 src/routes/frontend/dashboard.ts delete mode 100644 src/routes/frontend/etaTest.ts create mode 100644 src/routes/frontend/listAllItems.ts diff --git a/allowedStaticPaths.json b/allowedStaticPaths.json index 70d6c5e..90f1a70 100644 --- a/allowedStaticPaths.json +++ b/allowedStaticPaths.json @@ -7,7 +7,9 @@ "/darkreader/darkreader.js", "/bootstrap-icons/font/fonts/bootstrap-icons.woff2", "/bootstrap/dist/css/bootstrap.min.css.map", - "/@popperjs/core/dist/umd/popper.min.js" + "/@popperjs/core/dist/umd/popper.min.js", + "/@popperjs/core/dist/umd/popper.min.js.map", + "/bootstrap/dist/js/bootstrap.bundle.min.js.map" ], "debugMode": false } diff --git a/src/frontend/allItems.eta.html b/src/frontend/allItems.eta.html new file mode 100644 index 0000000..7caac5f --- /dev/null +++ b/src/frontend/allItems.eta.html @@ -0,0 +1,29 @@ +<%~ E.includeFile("partials/head.eta.html", {"title": "Dashboard"}) %> <%~ E.includeFile("partials/controls.eta.html", {"active": "AllItems"}) %> + +

All items

+
+ + + + + + + + + + + + <% it.items.forEach(function(user){ %> + + + + + + + + <% }) %> + +
#NameStatusSKUActions
<%= user.id %><%= user.name %><%= user.status %><%= user.SKU %>Edit
+
+ +<%~ E.includeFile("partials/controlsFoot.eta.html") %> <%~ E.includeFile("partials/foot.eta.html") %> diff --git a/src/frontend/dashboard.eta.html b/src/frontend/dashboard.eta.html new file mode 100644 index 0000000..ace5fa2 --- /dev/null +++ b/src/frontend/dashboard.eta.html @@ -0,0 +1,54 @@ +<%~ E.includeFile("partials/head.eta.html", {"title": "Dashboard"}) %> <%~ E.includeFile("partials/controls.eta.html", {"active": "Dashboard"}) %> + +

Good evening, ${user}

+
+
+
+
+
+10
+

New Stock

+
+
+
+
+
<%= it.stats.total %>
+

Items in total

+
+
+
+
+
Everything ok
+

Instance Status

+
+
+
+
+ + +

Recent items

+
+ + + + + + + + + + + + <% it.recents.forEach(function(user){ %> + + + + + + + + <% }) %> + +
#NameStatusSKUActions
<%= user.id %><%= user.name %><%= user.status %><%= user.SKU %>Edit
+
+ +<%~ E.includeFile("partials/controlsFoot.eta.html") %> <%~ E.includeFile("partials/foot.eta.html") %> diff --git a/src/frontend/demopage.eta.html b/src/frontend/demopage.eta.html deleted file mode 100644 index 7d1a223..0000000 --- a/src/frontend/demopage.eta.html +++ /dev/null @@ -1,62 +0,0 @@ -<%~ E.includeFile("partials/head.eta.html", {"title": "Bootstrap Demo Page"}) %> -<%~ E.includeFile("partials/controls.eta.html", {"active": "Orders"}) %> - - -

- Good evening, ${user} -

-
-
-
-
-
+10
-

New Stock

-
-
-
-
-
<%= it.stats.total %>
-

Items in total

-
-
-
-
-
Everything ok
-

Instance Status

-
-
-
-
- - -

Recent items

-
- - - - - - - - - - - - - <% it.recents.forEach(function(user){ %> - - - - - - - - <% }) %> - -
#NameStatusSKUActions
<%= user.id %><%= user.name %><%= user.status %><%= user.SKU %>Edit
-
- -<%~ E.includeFile("partials/controlsFoot.eta.html") %> -<%~ E.includeFile("partials/foot.eta.html") %> diff --git a/src/frontend/errors/404.eta.html b/src/frontend/errors/404.eta.html new file mode 100644 index 0000000..cab6212 --- /dev/null +++ b/src/frontend/errors/404.eta.html @@ -0,0 +1,8 @@ +<%~ E.includeFile("../partials/head.eta.html", {"title": "Error 404"}) %> <%~ E.includeFile("../partials/controls.eta.html", {"active": "error_404"}) %> + +
+ +

The thing you were looking for cannot be found

+
+ +<%~ E.includeFile("../partials/controlsFoot.eta.html") %> <%~ E.includeFile("../partials/foot.eta.html") %> diff --git a/src/frontend/errors/dbError.eta.html b/src/frontend/errors/dbError.eta.html new file mode 100644 index 0000000..dfc6594 --- /dev/null +++ b/src/frontend/errors/dbError.eta.html @@ -0,0 +1,15 @@ +<%~ E.includeFile("../partials/head.eta.html", {"title": "Error - Database failure"}) %> +
+ +

There seems to be an error with the database

+

+ +

+
+
+
<%= error %>
+
+
+
+ +<%~ E.includeFile("../partials/foot.eta.html") %> diff --git a/src/frontend/imports/csvImport.eta.html b/src/frontend/imports/csvImport.eta.html index 82e58c5..123eb0f 100644 --- a/src/frontend/imports/csvImport.eta.html +++ b/src/frontend/imports/csvImport.eta.html @@ -1,5 +1,5 @@ -<%~ E.includeFile("../partials/head.eta.html", {"title": "Bootstrap Demo Page" }) %> - <%~ E.includeFile("../partials/controls.eta.html", {"active": "Orders" }) %> +<%~ E.includeFile("../partials/head.eta.html", {"title": "Importer - CSV" }) %> + <%~ E.includeFile("../partials/controls.eta.html", {"active": "CSV_import" }) %>

Import A CSV File

Upload a CSV file to import into the database. The CSV file must have the following columns: diff --git a/src/frontend/index.eta.html b/src/frontend/index.eta.html deleted file mode 100644 index c33e103..0000000 --- a/src/frontend/index.eta.html +++ /dev/null @@ -1,6 +0,0 @@ -<%~ E.includeFile("partials/head.eta.html", {"title": "Bootstrap Demo Page"}) %> -<%~ E.includeFile("partials/controls.eta.html") %> - - - -<%~ E.includeFile("partials/foot.eta.html") %> diff --git a/src/frontend/partials/controls.eta.html b/src/frontend/partials/controls.eta.html index 7ff996b..c10a1b9 100644 --- a/src/frontend/partials/controls.eta.html +++ b/src/frontend/partials/controls.eta.html @@ -10,57 +10,90 @@ aria-label="Toggle navigation"> + +
+ +
+ + + + +
+ +
+ +
+
-
\ No newline at end of file +
\ No newline at end of file diff --git a/src/frontend/partials/head.eta.html b/src/frontend/partials/head.eta.html index ce9578c..d95ed1b 100644 --- a/src/frontend/partials/head.eta.html +++ b/src/frontend/partials/head.eta.html @@ -6,7 +6,6 @@ AssetFlow - <%= it.title %> - diff --git a/src/frontend/publicInfoPage.eta.html b/src/frontend/publicInfoPage.eta.html index 04df85d..fd7ba12 100644 --- a/src/frontend/publicInfoPage.eta.html +++ b/src/frontend/publicInfoPage.eta.html @@ -1,7 +1,7 @@ -<%~ E.includeFile("head.eta.html", {"title": "Item Info"}) %> +<%~ E.includeFile("partials/head.eta.html", {"title": "Item Info"}) %> -
-

<%= it.name %>

+
+

<%= 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 }