Compare commits

..

5 commits

Author SHA1 Message Date
89f495c0fd Startpfad für Manifest geändert
Some checks are pending
Deploy static content to Pages / deploy (push) Waiting to run
2025-04-06 21:56:39 +02:00
d346e05f45 Lizenz und Keywords angepasst 2025-04-06 21:46:42 +02:00
edc52a2caa Tab-States zurücksetzen 2025-04-06 21:43:24 +02:00
4e74cab1cc Setzen des TabStates bei Klick auf die Navbar Brand 2025-04-06 16:38:02 +02:00
8f77253c00 Verlinkung in der Navbar führt zurück zu Produkten 2025-04-06 16:32:00 +02:00
3 changed files with 55 additions and 8 deletions

View file

@ -1,7 +1,7 @@
{ {
"name": "Der Durstrechner", "name": "Der Durstrechner",
"short_name": "Durstrechner", "short_name": "Durstrechner",
"start_url": "./", "start_url": "/",
"display": "standalone", "display": "standalone",
"background_color": "#ffffff", "background_color": "#ffffff",
"theme_color": "#2196f3", "theme_color": "#2196f3",

View file

@ -57,6 +57,14 @@ class Element {
static getCartButton() { static getCartButton() {
return document.querySelector('button.cart-value'); return document.querySelector('button.cart-value');
} }
/**
* Get the navbar brand element
* @returns {Element}
*/
static getNavbarBrand() {
return document.querySelector('nav a.navbar-brand');
}
} }
/** /**
@ -200,6 +208,11 @@ class Base64Image {
}); });
} }
/**
* Resize an image from a base64 string to a smaller size
* @param base64
* @returns {Promise<unknown>}
*/
static imageResize(base64) { static imageResize(base64) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const img = new Image(); const img = new Image();
@ -244,6 +257,16 @@ class ProductManager {
this.setExportFieldJsonValue(); this.setExportFieldJsonValue();
this.registerSettingsFormEvents(); this.registerSettingsFormEvents();
this.registerImportFormEvents(); this.registerImportFormEvents();
this.registerNavbarBrandToProductEvent();
}
/**
* Register the event for the navbar brand to switch to the products tab when clicked.
*/
registerNavbarBrandToProductEvent() {
Element.getNavbarBrand().addEventListener('click', () => {
TabManager.switchTab('products');
})
} }
/** /**
@ -376,6 +399,9 @@ class CartManager {
*/ */
registerCartResetEvent() { registerCartResetEvent() {
Element.getCartButton().addEventListener('click', () => { Element.getCartButton().addEventListener('click', () => {
CartHistoryManager.addToTotal(this.cartLines.reduce((acc, cartLine) => {
return acc + (cartLine.product.price * cartLine.quantity);
}, 0));
this.cartLines = []; this.cartLines = [];
this.renderCart(); this.renderCart();
}); });
@ -495,11 +521,12 @@ class TabManager {
*/ */
static toggleTab() { static toggleTab() {
if(!TabManager.isSettingsTabActive) { if(!TabManager.isSettingsTabActive) {
TabManager.isSettingsTabActive = true;
this.switchTab('settings'); this.switchTab('settings');
} else { } else {
this.switchTab('products'); this.switchTab('products');
TabManager.isSettingsTabActive = false;
} }
TabManager.isSettingsTabActive = !TabManager.isSettingsTabActive;
} }
/** /**
@ -507,6 +534,9 @@ class TabManager {
* @param tab {string} The tab to switch to * @param tab {string} The tab to switch to
*/ */
static switchTab(tab) { static switchTab(tab) {
if(tab !== 'settings') {
TabManager.isSettingsTabActive = false;
}
const tabs = document.querySelectorAll('[data-tab]'); const tabs = document.querySelectorAll('[data-tab]');
tabs.forEach(e => { tabs.forEach(e => {
e.classList.add('d-none'); e.classList.add('d-none');
@ -547,6 +577,24 @@ class ThemeManager {
} }
} }
/**
* Define the CartHistoryManager class to manage the cart history.
*/
class CartHistoryManager {
static getTotal() {
return localStorage.getItem('cart-total-value') || 0;
}
static setTotal(value) {
localStorage.setItem('cart-total-value', value);
}
static addToTotal(value) {
const total = parseFloat(CartHistoryManager.getTotal()) + value;
CartHistoryManager.setTotal(total);
}
}
/** /**
* Main function to initialize the application. * Main function to initialize the application.
*/ */
@ -554,3 +602,4 @@ const cartManager = new CartManager();
const productManager = new ProductManager(); const productManager = new ProductManager();
const tabManager = new TabManager(); const tabManager = new TabManager();
const themeManager = new ThemeManager(); const themeManager = new ThemeManager();
const cartHistoryManager = new CartHistoryManager();

View file

@ -1,12 +1,10 @@
{ {
"name": "durst-rechner", "name": "durst-rechner",
"version": "1.0.0", "version": "1.0.0",
"scripts": { "scripts": {},
"test": "echo \"Error: no test specified\" && exit 1" "keywords": ["calculator", "feuerwehr", "firefighter", "pos", "thirst"],
},
"keywords": [],
"author": "Dennis Heinrich", "author": "Dennis Heinrich",
"license": "proprietary", "license": "BSD-3-Clause",
"dependencies": { "dependencies": {
"bootstrap": "5.3.5", "bootstrap": "5.3.5",
"bootstrap-icons": "^1.11.3" "bootstrap-icons": "^1.11.3"