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",
|
"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",
|
||||||
|
|
|
||||||
|
|
@ -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,10 +577,29 @@ 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.
|
||||||
*/
|
*/
|
||||||
const cartManager = new CartManager();
|
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();
|
||||||
|
|
@ -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"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue