mirror of
https://github.com/cloudmaker97/DurstRechner.git
synced 2025-12-06 07:58:39 +00:00
Compare commits
5 commits
c9796b8431
...
89f495c0fd
| Author | SHA1 | Date | |
|---|---|---|---|
| 89f495c0fd | |||
| d346e05f45 | |||
| edc52a2caa | |||
| 4e74cab1cc | |||
| 8f77253c00 |
3 changed files with 55 additions and 8 deletions
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "Der Durstrechner",
|
||||
"short_name": "Durstrechner",
|
||||
"start_url": "./",
|
||||
"start_url": "/",
|
||||
"display": "standalone",
|
||||
"background_color": "#ffffff",
|
||||
"theme_color": "#2196f3",
|
||||
|
|
|
|||
|
|
@ -57,6 +57,14 @@ class Element {
|
|||
static getCartButton() {
|
||||
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) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const img = new Image();
|
||||
|
|
@ -244,6 +257,16 @@ class ProductManager {
|
|||
this.setExportFieldJsonValue();
|
||||
this.registerSettingsFormEvents();
|
||||
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() {
|
||||
Element.getCartButton().addEventListener('click', () => {
|
||||
CartHistoryManager.addToTotal(this.cartLines.reduce((acc, cartLine) => {
|
||||
return acc + (cartLine.product.price * cartLine.quantity);
|
||||
}, 0));
|
||||
this.cartLines = [];
|
||||
this.renderCart();
|
||||
});
|
||||
|
|
@ -495,11 +521,12 @@ class TabManager {
|
|||
*/
|
||||
static toggleTab() {
|
||||
if(!TabManager.isSettingsTabActive) {
|
||||
TabManager.isSettingsTabActive = true;
|
||||
this.switchTab('settings');
|
||||
} else {
|
||||
this.switchTab('products');
|
||||
TabManager.isSettingsTabActive = false;
|
||||
}
|
||||
TabManager.isSettingsTabActive = !TabManager.isSettingsTabActive;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -507,6 +534,9 @@ class TabManager {
|
|||
* @param tab {string} The tab to switch to
|
||||
*/
|
||||
static switchTab(tab) {
|
||||
if(tab !== 'settings') {
|
||||
TabManager.isSettingsTabActive = false;
|
||||
}
|
||||
const tabs = document.querySelectorAll('[data-tab]');
|
||||
tabs.forEach(e => {
|
||||
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.
|
||||
*/
|
||||
|
|
@ -554,3 +602,4 @@ const cartManager = new CartManager();
|
|||
const productManager = new ProductManager();
|
||||
const tabManager = new TabManager();
|
||||
const themeManager = new ThemeManager();
|
||||
const cartHistoryManager = new CartHistoryManager();
|
||||
|
|
@ -1,12 +1,10 @@
|
|||
{
|
||||
"name": "durst-rechner",
|
||||
"version": "1.0.0",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"scripts": {},
|
||||
"keywords": ["calculator", "feuerwehr", "firefighter", "pos", "thirst"],
|
||||
"author": "Dennis Heinrich",
|
||||
"license": "proprietary",
|
||||
"license": "BSD-3-Clause",
|
||||
"dependencies": {
|
||||
"bootstrap": "5.3.5",
|
||||
"bootstrap-icons": "^1.11.3"
|
||||
|
|
|
|||
Loading…
Reference in a new issue