Skip to content

🛡️ Warracker is an open source, self-hostable warranty tracker to monitor expirations, store receipts, files. You own the data, your rules!

Fixes and changes

sassanix22d7e6d751e2
diff --git a/Dockerfile b/Dockerfile
index d27fef6..f8bdc4f 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -32,6 +32,9 @@ COPY backend/migrations/ /app/migrations/
COPY frontend/*.html /var/www/html/
COPY frontend/*.js /var/www/html/
COPY frontend/*.css /var/www/html/
+# Add favicon and images
+COPY frontend/favicon.ico /var/www/html/
+COPY frontend/img/ /var/www/html/img/
# Configure nginx site
RUN rm /etc/nginx/sites-enabled/default
diff --git a/backend/app.py b/backend/app.py
index f6fc05f..2fc1622 100644
--- a/backend/app.py
+++ b/backend/app.py
@@ -663,17 +663,41 @@ def request_password_reset():
)
conn.commit()
+
+ # Get email base URL from settings
+ email_base_url = 'http://localhost:8080' # Default fallback
+ try:
+ cur.execute("SELECT value FROM site_settings WHERE key = 'email_base_url'")
+ result = cur.fetchone()
+ if result:
+ email_base_url = result[0]
+ else:
+ logger.warning("email_base_url setting not found for password reset, using default.")
+ except Exception as e:
+ logger.error(f"Error fetching email_base_url from settings for password reset: {e}. Using default.")
- # In a real application, you would send an email with the reset link
- # For now, we'll just return the token in the response (for testing purposes)
- reset_link = f"/reset-password?token={reset_token}"
+ # Ensure base URL doesn't end with a slash
+ email_base_url = email_base_url.rstrip('/')
+
+ # Construct the full reset link
+ reset_link = f"{email_base_url}/reset-password.html?token={reset_token}" # Use base URL and correct page
+ # TODO: Implement actual email sending logic here
logger.info(f"Password reset requested for user {user_id}. Reset link: {reset_link}")
+ # Send email using send_email function (implement this)
+ # subject = "Password Reset Request"
+ # body = f"Click the link to reset your password: {reset_link}"
+ # try:
+ # send_email(email, subject, body) # Placeholder for email sending
+ # except Exception as e:
+ # logger.error(f"Failed to send password reset email to {email}: {e}")
+ # # Still return success to the user, don't leak email failure
return jsonify({
- 'message': 'If your email is registered, you will receive a password reset link.',
- 'reset_link': reset_link # Remove this in production
+ 'message': 'If your email is registered, you will receive a password reset link.'
}), 200
+ # Remove reset_link from response in production
+ # 'reset_link': reset_link
except Exception as e:
logger.error(f"Password reset request error: {e}")
if conn:
@@ -1003,6 +1027,8 @@ def delete_warranty(warranty_id):
@app.route('/api/warranties/<int:warranty_id>', methods=['PUT'])
@token_required
def update_warranty(warranty_id):
+ # --- Log function entry ---
+ logger.info(f"Entering update_warranty function for ID: {warranty_id}")
conn = None
try:
user_id = request.user['id']
@@ -1028,16 +1054,49 @@ def update_warranty(warranty_id):
if not request.form.get('purchase_date'):
return jsonify({"error": "Purchase date is required"}), 400
+ # --- Log received data ---
+ logger.info(f"Received update request for warranty {warranty_id}")
+ logger.info(f"Form data received: is_lifetime={request.form.get('is_lifetime')}, warranty_years={request.form.get('warranty_years')}")
+
+ # --- Added: Get is_lifetime ---
+ is_lifetime = request.form.get('is_lifetime', 'false').lower() == 'true'
+ logger.info(f"Parsed is_lifetime as: {is_lifetime}")
+
+ purchase_date_str = request.form['purchase_date']
try:
- warranty_years = int(request.form.get('warranty_years', '0'))
- if warranty_years <= 0 or warranty_years > 100:
- return jsonify({"error": "Warranty years must be between 1 and 100"}), 400
+ purchase_date = datetime.strptime(purchase_date_str, '%Y-%m-%d').date() # Use .date()
except ValueError:
- return jsonify({"error": "Warranty years must be a valid number"}), 400
-
+ return jsonify({"error": "Invalid date format for purchase date. Use YYYY-MM-DD"}), 400
+
+ warranty_years = None
+ expiration_date = None
+
+ # --- Modified: Conditional validation and calculation ---
+ if not is_lifetime:
+ warranty_years_str = request.form.get('warranty_years')
+ if not warranty_years_str:
+ return jsonify({"error": "Warranty years is required for non-lifetime warranties"}), 400
+ try:
+ warranty_years = int(warranty_years_str)
+ if warranty_years <= 0 or warranty_years > 100:
+ # Allow 0 years if is_lifetime is true? Let's keep validation strict for now.
+ return jsonify({"error": "Warranty years must be between 1 and 100 for non-lifetime warranties"}), 400
+
+ # Calculate expiration date precisely if possible, otherwise approximate
+ try:
+ from dateutil.relativedelta import relativedelta
+ expiration_date = purchase_date + relativedelta(years=warranty_years)
+ except ImportError:
+ # Fallback to approximation if dateutil is not available
+ expiration_date = purchase_date + timedelta(days=warranty_years * 365)
+
+ except ValueError:
+ return jsonify({"error": "Warranty years must be a valid number"}), 400
+ # else: warranty_years and expiration_date remain None for lifetime
+
# Process the data
product_name = request.form['product_name']
- purchase_date_str = request.form['purchase_date']
+ # purchase_date_str = request.form['purchase_date'] # Moved up
serial_numbers = request.form.getlist('serial_numbers')
product_url = request.form.get('product_url', '')
@@ -1061,13 +1120,6 @@ def update_warranty(warranty_id):
except ValueError:
return jsonify({"error": "Purchase price must be a valid number"}), 400
- try:
- purchase_date = datetime.strptime(purchase_date_str, '%Y-%m-%d')
- except ValueError:
- return jsonify({"error": "Invalid date format. Use YYYY-MM-DD"}), 400
-
- expiration_date = purchase_date + timedelta(days=warranty_years * 365)
-
# Handle invoice file upload if new file is provided
db_invoice_path = None
if 'invoice' in request.files:
@@ -1130,11 +1182,13 @@ def update_warranty(warranty_id):
# Update the warranty in database - IMPORTANT: The database set operation needs to be updated
# Create a list of parameters for the UPDATE query
+ # --- Modified: Add is_lifetime, use potentially None values ---
update_params = {
'product_name': product_name,
'purchase_date': purchase_date,
- 'warranty_years': warranty_years,
- 'expiration_date': expiration_date,
+ 'is_lifetime': is_lifetime,
+ 'warranty_years': warranty_years, # Will be None if lifetime
+ 'expiration_date': expiration_date, # Will be None if lifetime
'product_url': product_url,
'purchase_price': purchase_price
}
@@ -1157,6 +1211,9 @@ def update_warranty(warranty_id):
sql_fields.append("manual_path = %s")
sql_values.append(db_manual_path)
+ # --- Add updated_at to the SET clause ---
+ sql_fields.append("updated_at = NOW()") # Use SQL function, no parameter needed
+
# Add the warranty_id at the end
sql_values.append(warranty_id)
@@ -2070,6 +2127,16 @@ def get_site_settings():
('registration_enabled', 'true')
)
conn.commit()
+
+ # Default email base URL if not set
+ if 'email_base_url' not in settings:
+ default_base_url = 'http://localhost:8080' # Default value
+ settings['email_base_url'] = default_base_url
+ cur.execute(
+ 'INSERT INTO site_settings (key, value) VALUES (%s, %s) ON CONFLICT (key) DO NOTHING',
+ ('email_base_url', default_base_url)
+ )
+ conn.commit()
return jsonify(settings), 200
except Exception as e:
@@ -2297,9 +2364,30 @@ def format_expiration_email(user, warranties):
"""
subject = "Warracker: Upcoming Warranty Expirations"
+ # Get email base URL from settings
+ conn = None
+ email_base_url = 'http://localhost:8080' # Default fallback
+ try:
+ conn = get_db_connection()
+ with conn.cursor() as cur:
+ cur.execute("SELECT value FROM site_settings WHERE key = 'email_base_url'")
+ result = cur.fetchone()
+ if result:
+ email_base_url = result[0]
+ else:
+ logger.warning("email_base_url setting not found, using default.")
+ except Exception as e:
+ logger.error(f"Error fetching email_base_url from settings: {e}. Using default.")
+ finally:
+ if conn:
+ release_db_connection(conn)
+
+ # Ensure base URL doesn't end with a slash
+ email_base_url = email_base_url.rstrip('/')
+
# Create both plain text and HTML versions of the email body
- text_body = f"Hello {user['first_name']},\n\n"
- text_body += "The following warranties are expiring soon:\n\n"
+ text_body = f"Hello {user['first_name']},\\n\\n"
+ text_body += "The following warranties are expiring soon:\\n\\n"
html_body = f"""\
<html>
@@ -2318,7 +2406,7 @@ def format_expiration_email(user, warranties):
"""
for warranty in warranties:
- text_body += f"- {warranty['product_name']} (expires on {warranty['expiration_date']})\n"
+ text_body += f"- {warranty['product_name']} (expires on {warranty['expiration_date']})\\n"
html_body += f"""\
<tr>
<td style="padding: 8px;">{warranty['product_name']}</td>
@@ -2326,16 +2414,16 @@ def format_expiration_email(user, warranties):
</tr>
"""
- text_body += "\nLog in to Warracker to view details:\n"
- text_body += "http://localhost:8080\n\n"
- text_body += "Manage your notification settings:\n"
- text_body += "http://localhost:8080/settings.html\n"
+ text_body += "\\nLog in to Warracker to view details:\\n"
+ text_body += f"{email_base_url}\\n\\n" # Use configurable base URL
+ text_body += "Manage your notification settings:\\n"
+ text_body += f"{email_base_url}/settings.html\\n" # Use configurable base URL
html_body += f"""\
</tbody>
</table>
- <p>Log in to <a href="http://localhost:8080">Warracker</a> to view details.</p>
- <p>Manage your notification settings <a href="http://localhost:8080/settings.html">here</a>.</p>
+ <p>Log in to <a href="{email_base_url}">Warracker</a> to view details.</p> # Use configurable base URL
+ <p>Manage your notification settings <a href="{email_base_url}/settings.html">here</a>.</p> # Use configurable base URL
</body>
</html>
"""
diff --git a/backend/migrations/000_create_warranties_table.sql b/backend/migrations/000_create_warranties_table.sql
index 4122853..900f89f 100644
--- a/backend/migrations/000_create_warranties_table.sql
+++ b/backend/migrations/000_create_warranties_table.sql
@@ -12,7 +12,8 @@ CREATE TABLE IF NOT EXISTS warranties (
product_url TEXT,
-- purchase_price is added by migration 002
-- user_id is added by migration 003
- created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
+ created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
+ updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Create indexes if they don't exist
diff --git a/backend/migrations/012_add_updated_at_to_warranties.sql b/backend/migrations/012_add_updated_at_to_warranties.sql
new file mode 100644
index 0000000..ca76012
--- /dev/null
+++ b/backend/migrations/012_add_updated_at_to_warranties.sql
@@ -0,0 +1,26 @@
+-- backend/migrations/012_add_updated_at_to_warranties.sql
+
+-- Add the updated_at column if it doesn't exist
+ALTER TABLE warranties
+ADD COLUMN IF NOT EXISTS updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP;
+
+-- Create or replace a function to automatically update the timestamp on row update
+CREATE OR REPLACE FUNCTION update_modified_column()
+RETURNS TRIGGER AS $$
+BEGIN
+ -- Check if NEW record is distinct from OLD record to avoid unnecessary updates
+ IF NEW IS DISTINCT FROM OLD THEN
+ NEW.updated_at = NOW();
+ END IF;
+ RETURN NEW;
+END;
+$$ language 'plpgsql';
+
+-- Drop the trigger if it already exists to avoid errors on re-run
+DROP TRIGGER IF EXISTS update_warranties_updated_at ON warranties;
+
+-- Create the trigger to call the function before any UPDATE on the warranties table
+CREATE TRIGGER update_warranties_updated_at
+BEFORE UPDATE ON warranties
+FOR EACH ROW
+EXECUTE FUNCTION update_modified_column();
\ No newline at end of file
diff --git a/frontend/about.html b/frontend/about.html
new file mode 100644
index 0000000..c0b619f
--- /dev/null
+++ b/frontend/about.html
@@ -0,0 +1,168 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <!-- Basic Meta Tags -->
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <title>About - Warracker</title>
+
+ <!-- Favicons -->
+ <link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
+ <link rel="icon" type="image/png" sizes="16x16" href="img/favicon-16x16.png?v=2">
+ <link rel="icon" type="image/png" sizes="32x32" href="img/favicon-32x32.png?v=2">
+
+ <!-- Stylesheets -->
+ <link rel="stylesheet" href="style.css"> <!-- Main stylesheet -->
+ <link rel="stylesheet" href="styles.css"> <!-- Additional styles -->
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"> <!-- Font Awesome -->
+ <link rel="stylesheet" href="header-fix.css"> <!-- Header specific styles -->
+
+ <!-- Scripts loaded in head -->
+ <script src="theme-loader.js"></script> <!-- Apply theme early -->
+ <script src="include-auth-new.js"></script> <!-- Handles auth state display -->
+ <script src="fix-auth-buttons-loader.js"></script> <!-- Fixes auth button display timing -->
+
+</head>
+<body>
+ <!-- Standard Header (Copied from index.html) -->
+ <header>
+ <div class="container">
+ <div class="app-title">
+ <i class="fas fa-shield-alt"></i>
+ <h1>Warracker</h1>
+ </div>
+ <div class="nav-links">
+ <a href="index.html" class="nav-link">
+ <i class="fas fa-home"></i> Home
+ </a>
+ <a href="status.html" class="nav-link">
+ <i class="fas fa-chart-pie"></i> Status
+ </a>
+ <!-- Consider adding an 'active' class to an 'About' link if created here -->
+ </div>
+ <div id="authContainer" class="auth-buttons">
+ <a href="login.html" class="auth-btn login-btn">
+ <i class="fas fa-sign-in-alt"></i> Login
+ </a>
+ <a href="register.html" class="auth-btn register-btn">
+ <i class="fas fa-user-plus"></i> Register
+ </a>
+ </div>
+ <div id="userMenu" class="user-menu" style="display: none;">
+ <button id="userBtn" class="user-btn">
+ <i class="fas fa-user-circle"></i>
+ <span id="userDisplayName">User</span>
+ </button>
+ <div id="userMenuDropdown" class="user-menu-dropdown">
+ <div class="user-info">
+ <div id="userName" class="user-name">User Name</div>
+ <div id="userEmail" class="user-email">[email protected]</div>
+ </div>
+ <div class="user-menu-item">
+ <a href="settings-new.html" style="color: inherit; text-decoration: none; display: block;">
+ <i class="fas fa-cog"></i> Settings
+ </a>
+ </div>
+ <div class="user-menu-item">
+ <i class="fas fa-info-circle"></i>
+ <a href="about.html" style="text-decoration: none; color: inherit;">About</a>
+ </div>
+ <div class="user-menu-item" id="logoutMenuItem">
+ <i class="fas fa-sign-out-alt"></i> Logout
+ </div>
+ </div>
+ </div>
+ <!-- Settings Toggle (Optional - Include if needed on About page) -->
+ <div class="settings-container">
+ <button id="settingsBtn" class="settings-btn" aria-label="Settings" type="button">
+ <i class="fas fa-cog"></i>
+ </button>
+ <div id="settingsMenu" class="settings-menu">
+ <div class="settings-item">
+ <span>Dark Mode</span>
+ <label class="toggle-switch" title="Toggle dark mode">
+ <input type="checkbox" id="darkModeToggle">
+ <span class="toggle-slider"></span>
+ </label>
+ </div>
+ <div class="settings-item">
+ <a href="https://github.com/sassanix/Warracker" class="settings-link github-link" target="_blank" rel="noopener noreferrer">
+ <i class="fab fa-github"></i> GitHub
+ </a>
+ </div>
+ </div>
+ </div>
+ </div>
+ </header>
+
+ <!-- Main Content Area -->
+ <div class="container" style="padding: 0;">
+ <div class="main-content" style="display: block;">
+
+ <!-- Existing About Content, now wrapped -->
+ <div class="about-container" style="background-color: var(--card-bg); color: var(--text-color); padding: 20px; border-radius: 8px; margin-top: 20px; box-shadow: 0 2px 5px rgba(0,0,0,0.1); width: 100%; box-sizing: border-box;">
+ <h1 style="color: var(--primary-color); margin-bottom: 20px;">About Warracker</h1>
+
+ <p><strong>Version:</strong> v0.9.9.1</p>
+
+ <p>
+ <strong>GitHub Repository:</strong>
+ <a href="https://github.com/sassanix/Warracker" target="_blank" rel="noopener noreferrer" style="color: var(--link-color);">
+ https://github.com/sassanix/Warracker
+ </a>
+ </p>
+
+ <p>
+ <strong>Release Notes:</strong>
+ <a href="https://github.com/sassanix/Warracker/releases" target="_blank" rel="noopener noreferrer" style="color: var(--link-color);">
+ View Releases
+ </a>
+ </p>
+
+ <p>
+ <strong>Author:</strong>
+ <a href="https://github.com/sassanix" target="_blank" rel="noopener noreferrer" style="color: var(--link-color);">
+ Sassanix
+ </a>
+ </p>
+
+ <p>
+ <strong>License:</strong>
+ <a href="https://github.com/sassanix/Warracker/blob/main/LICENSE" target="_blank" rel="noopener noreferrer" style="color: var(--link-color);">
+ AGPL-3.0
+ </a>
+ </p>
+
+ <p>
+ <strong>Issues & Feature Requests:</strong>
+ <a href="https://github.com/sassanix/Warracker/issues" target="_blank" rel="noopener noreferrer" style="color: var(--link-color);">
+ Report Bugs / Request Features
+ </a>
+ </p>
+
+ <!-- Buy Me A Coffee Button -->
+ <div style="text-align: center; margin-top: 25px;">
+ <script type="text/javascript" src="https://cdnjs.buymeacoffee.com/1.0.0/button.prod.min.js" data-name="bmc-button" data-slug="sassanix" data-color="#FFDD00" data-emoji="" data-font="Poppins" data-text="Buy me a coffee" data-outline-color="#000000" data-font-color="#000000" data-coffee-color="#ffffff" ></script>
+ </div>
+ </div>
+
+ </div>
+ </div>
+
+ <!-- Scripts loaded at the end of body -->
+ <script src="auth.js"></script> <!-- Added for user menu and other auth interactions -->
+ <script src="script.js"></script> <!-- Include main site script, might contain helpers -->
+
+ <!-- Explicitly call setupUIEventListeners for this page -->
+ <script>
+ document.addEventListener('DOMContentLoaded', () => {
+ // Keep theme initialization here if needed for specific timing
+ if (typeof initializeTheme === 'function') {
+ console.log('About page: Calling initializeTheme');
+ initializeTheme(); // Call theme initialization if it exists
+ }
+ });
+ </script>
+
+</body>
+</html>
\ No newline at end of file
diff --git a/frontend/api-test.html b/frontend/api-test.html
index 32e3cbc..38387ed 100644
--- a/frontend/api-test.html
+++ b/frontend/api-test.html
@@ -4,6 +4,11 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>API Connection Test</title>
+ <script src="theme-loader.js"></script> <!-- Apply theme early -->
+ <!-- Favicons -->
+ <link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
+ <link rel="icon" type="image/png" sizes="16x16" href="img/favicon-16x16.png?v=2">
+ <link rel="icon" type="image/png" sizes="32x32" href="img/favicon-32x32.png?v=2">
<link rel="stylesheet" href="style.css">
<!-- Font Awesome for icons -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
@@ -87,4 +92,4 @@
<!-- Load test script -->
<script src="test-api.js"></script>
</body>
-</html>
\ No newline at end of file
+</html>
\ No newline at end of file
diff --git a/frontend/favicon.ico b/frontend/favicon.ico
new file mode 100644
index 0000000..586b6c6
Binary files /dev/null and b/frontend/favicon.ico differ
diff --git a/frontend/img/favicon-16x16.png b/frontend/img/favicon-16x16.png
new file mode 100644
index 0000000..41cd7d3
Binary files /dev/null and b/frontend/img/favicon-16x16.png differ
diff --git a/frontend/img/favicon-32x32.png b/frontend/img/favicon-32x32.png
new file mode 100644
index 0000000..78c41ab
Binary files /dev/null and b/frontend/img/favicon-32x32.png differ
diff --git a/frontend/index.html b/frontend/index.html
index e190a0d..efde320 100644
--- a/frontend/index.html
+++ b/frontend/index.html
@@ -12,8 +12,17 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Warranty Tracker</title>
+ <title>Warracker - Warranty Tracker</title>
+ <!-- Add standard favicon.ico link -->
+ <link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
+ <!-- Replace the old favicon link -->
+ <!-- <link rel="icon" type="image/png" href="img/favicon.png"> -->
+ <!-- Add new favicon links -->
+ <link rel="icon" type="image/png" sizes="16x16" href="img/favicon-16x16.png?v=2">
+ <link rel="icon" type="image/png" sizes="32x32" href="img/favicon-32x32.png?v=2">
<link rel="stylesheet" href="style.css">
+ <script src="theme-loader.js"></script> <!-- Apply theme early -->
+
<!-- Font Awesome for icons -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<!-- Load header fix styles to ensure consistent header styling -->
@@ -207,7 +216,7 @@
<div class="container">
<div class="app-title">
<i class="fas fa-shield-alt"></i>
- <h1>Warranty Tracker</h1>
+ <h1>Warracker</h1>
</div>
<div class="nav-links">
<a href="index.html" class="nav-link active">
@@ -236,9 +245,13 @@
<div id="userEmail" class="user-email">[email protected]</div>
</div>
<div class="user-menu-item">
- <a href="settings-new.html" style="color: inherit; text-decoration: none; display: block;">
- <i class="fas fa-cog"></i> Settings
- </a>
+ <a href="settings-new.html" style="color: inherit; text-decoration: none; display: block;">
+ <i class="fas fa-cog"></i> Settings
+ </a>
+ </div>
+ <div class="user-menu-item">
+ <i class="fas fa-info-circle"></i>
+ <a href="about.html" style="text-decoration: none; color: inherit;">About</a>
</div>
<div class="user-menu-item" id="logoutMenuItem">
<i class="fas fa-sign-out-alt"></i> Logout
@@ -270,211 +283,25 @@
<!-- Main Content -->
<div class="container">
<div class="main-content">
- <!-- Form Panel -->
- <div class="form-panel">
- <h2>Add New Warranty</h2>
- <div class="form-tabs" data-step="0">
- <div class="form-tab active" data-tab="product-info">
- <i class="fas fa-box"></i> Product
- </div>
- <div class="form-tab" data-tab="warranty-details">
- <i class="fas fa-shield-alt"></i> Warranty
- </div>
- <div class="form-tab" data-tab="documents">
- <i class="fas fa-file-alt"></i> Documents
- </div>
- <div class="form-tab" data-tab="tags">
- <i class="fas fa-tags"></i> Tags
- </div>
- <div class="form-tab" data-tab="summary">
- <i class="fas fa-check-circle"></i> Summary
- </div>
- </div>
- <form id="warrantyForm">
- <!-- Product Information Tab -->
- <div class="tab-content active" id="product-info">
- <div class="form-group">
- <label for="productName">Product Name</label>
- <input type="text" id="productName" name="product_name" class="form-control" required>
- </div>
-
- <div class="form-group">
- <label for="productUrl">Product URL (Optional)</label>
- <input type="url" id="productUrl" name="product_url" class="form-control" placeholder="https://example.com/product">
- </div>
-
- <div class="form-group">
- <label>Serial Numbers</label>
- <div id="serialNumbersContainer">
- <!-- Serial number inputs will be added dynamically -->
- </div>
- </div>
- </div>
-
- <!-- Warranty Details Tab -->
- <div class="tab-content" id="warranty-details">
- <div class="form-group">
- <label for="purchaseDate">Purchase Date</label>
- <input type="date" id="purchaseDate" name="purchase_date" class="form-control" required>
- </div>
-
- <!-- Add Lifetime Checkbox -->
- <div class="form-group">
- <label class="lifetime-label">
- <input type="checkbox" id="isLifetime" name="is_lifetime" value="true">
- Lifetime Warranty
- </label>
- </div>
- <!-- End Lifetime Checkbox -->
-
- <div class="form-group" id="warrantyYearsGroup">
- <label for="warrantyYears">Warranty Period (Years)</label>
- <input type="number" id="warrantyYears" name="warranty_years" class="form-control" min="1" max="100" required>
- </div>
-
- <div class="form-group">
- <label for="purchasePrice">Purchase Price (Optional)</label>
- <div class="price-input-wrapper">
- <span class="currency-symbol">$</span>
- <input type="number" id="purchasePrice" name="purchase_price" class="form-control" min="0" step="0.01" placeholder="0.00">
- </div>
- </div>
- </div>
-
- <!-- Documents Tab -->
- <div class="tab-content" id="documents">
- <div class="form-group">
- <label>Invoice/Receipt</label>
- <div class="file-input-wrapper">
- <label for="invoice" class="file-input-label">
- <i class="fas fa-upload"></i> Choose File
- </label>
- <input type="file" id="invoice" name="invoice" class="file-input" accept=".pdf,.png,.jpg,.jpeg">
- </div>
- <div id="fileName" class="file-name"></div>
- </div>
-
- <div class="form-group">
- <label>Product Manual (Optional)</label>
- <div class="file-input-wrapper">
- <label for="manual" class="file-input-label">
- <i class="fas fa-upload"></i> Choose File
- </label>
- <input type="file" id="manual" name="manual" class="file-input" accept=".pdf,.png,.jpg,.jpeg">
- </div>
- <div id="manualFileName" class="file-name"></div>
- </div>
- </div>
-
- <!-- Tags Tab -->
- <div class="tab-content" id="tags">
- <div class="form-group">
- <label>Add Tags</label>
- <p class="text-muted">Tags help you organize and filter your warranties</p>
-
- <div class="tags-container">
- <div class="selected-tags" id="selectedTags">
- <!-- Selected tags will be displayed here -->
- </div>
-
- <div class="tags-dropdown">
- <input type="text" id="tagSearch" class="form-control" placeholder="Search or add new tag...">
- <div class="tags-list" id="tagsList">
- <!-- Tag options will be populated by JavaScript -->
- </div>
- </div>
-
- <div class="mt-10">
- <button type="button" id="manageTagsBtn" class="btn btn-secondary btn-sm">
- <i class="fas fa-cog"></i> Manage Tags
- </button>
- </div>
- </div>
- </div>
- </div>
-
- <!-- Summary Tab -->
- <div class="tab-content" id="summary">
- <div class="summary-container">
- <div class="summary-section">
- <h4><i class="fas fa-box"></i> Product Information</h4>
- <div class="summary-item">
- <span class="summary-label">Product Name:</span>
- <span id="summary-product-name" class="summary-value">-</span>
- </div>
- <div class="summary-item">
- <span class="summary-label">Product URL:</span>
- <span id="summary-product-url" class="summary-value">-</span>
- </div>
- <div class="summary-item">
- <span class="summary-label">Serial Numbers:</span>
- <span id="summary-serial-numbers" class="summary-value">-</span>
- </div>
- </div>
-
- <div class="summary-section">
- <h4><i class="fas fa-shield-alt"></i> Warranty Details</h4>
- <div class="summary-item">
- <span class="summary-label">Purchase Date:</span>
- <span id="summary-purchase-date" class="summary-value">-</span>
- </div>
- <div class="summary-item">
- <span class="summary-label">Warranty Period:</span>
- <span id="summary-warranty-years" class="summary-value">-</span>
- </div>
- <div class="summary-item">
- <span class="summary-label">Purchase Price:</span>
- <span id="summary-purchase-price" class="summary-value">-</span>
- </div>
- </div>
-
- <div class="summary-section">
- <h4><i class="fas fa-file-alt"></i> Documents</h4>
- <div class="summary-item">
- <span class="summary-label">Invoice/Receipt:</span>
- <span id="summary-invoice" class="summary-value">-</span>
- </div>
- <div class="summary-item">
- <span class="summary-label">Product Manual:</span>
- <span id="summary-manual" class="summary-value">-</span>
- </div>
- </div>
-
- <div class="summary-section">
- <h4><i class="fas fa-tags"></i> Tags</h4>
- <div class="summary-item">
- <span class="summary-label">Selected Tags:</span>
- <div id="summary-tags" class="summary-value">-</div>
- </div>
- </div>
- </div>
-
- <div class="form-group">
- <button type="submit" class="btn btn-primary">Add Warranty</button>
+
+ <!-- Warranties List Panel -->
+ <div class="warranties-panel">
+ <!-- Panel Header -->
+ <div class="panel-header">
+ <h2>Your Warranties</h2>
+ <!-- ADD BUTTON CONTAINER AND REFRESH BUTTON WRAPPER HERE -->
+ <div class="panel-header-actions">
+ <div class="add-warranty-button-container">
+ <button id="showAddWarrantyBtn" class="btn btn-primary btn-sm">
+ <i class="fas fa-plus"></i> Add New Warranty
+ </button>
</div>
- </div>
-
- <!-- Tab Navigation -->
- <div class="tab-navigation">
- <button type="button" class="btn btn-secondary prev-tab">
- <i class="fas fa-arrow-left"></i> Previous
- </button>
- <button type="button" class="btn btn-primary next-tab">
- Next <i class="fas fa-arrow-right"></i>
+ <button id="refreshBtn" class="btn btn-secondary btn-sm" title="Refresh List">
+ <i class="fas fa-sync-alt"></i>
</button>
</div>
- </form>
- </div>
-
- <!-- Warranties List Panel -->
- <div class="warranties-panel">
- <h2>
- Your Warranties
- <button id="refreshBtn" class="refresh-btn" title="Refresh list">
- <i class="fas fa-sync-alt"></i>
- </button>
- </h2>
-
+ </div>
+ <!-- Filters and Search -->
<div class="filter-controls">
<div class="search-container">
<div class="search-box">
@@ -554,8 +381,216 @@
</div>
</div>
</div>
- </div>
- </div>
+
+ <!-- MOVE the Form Panel content below -->
+ <!-- Original <div class="form-panel"> should be removed from here -->
+ <div id="addWarrantyModal" class="modal-backdrop">
+ <div class="modal" style="max-width: 700px;"> <!-- Adjusted max-width for the wizard -->
+ <div class="modal-header">
+ <h3 class="modal-title">Add New Warranty</h3>
+ <button class="close-btn" data-dismiss="modal">×</button>
+ </div>
+ <div class="modal-body">
+ <!-- MOVE the entire original .form-panel content HERE -->
+ <div class="form-panel" style="box-shadow: none; padding: 0; background: none;">
+ <!-- Form Tabs -->
+ <div class="form-tabs" data-step="0">
+ <div class="form-tab active" data-tab="product-info">
+ <i class="fas fa-box"></i> Product
+ </div>
+ <div class="form-tab" data-tab="warranty-details">
+ <i class="fas fa-shield-alt"></i> Warranty
+ </div>
+ <div class="form-tab" data-tab="documents">
+ <i class="fas fa-file-alt"></i> Documents
+ </div>
+ <div class="form-tab" data-tab="tags">
+ <i class="fas fa-tags"></i> Tags
+ </div>
+ <div class="form-tab" data-tab="summary">
+ <i class="fas fa-check-circle"></i> Summary
+ </div>
+ </div>
+ <!-- Warranty Form -->
+ <form id="warrantyForm">
+ <!-- Product Information Tab -->
+ <div class="tab-content active" id="product-info">
+ <div class="form-group">
+ <label for="productName">Product Name</label>
+ <input type="text" id="productName" name="product_name" class="form-control" required>
+ </div>
+
+ <div class="form-group">
+ <label for="productUrl">Product URL (Optional)</label>
+ <input type="url" id="productUrl" name="product_url" class="form-control" placeholder="https://example.com/product">
+ </div>
+
+ <div class="form-group">
+ <label>Serial Numbers</label>
+ <div id="serialNumbersContainer">
+ <!-- Serial number inputs will be added dynamically -->
+ </div>
+ </div>
+ </div>
+ <!-- Warranty Details Tab -->
+ <div class="tab-content" id="warranty-details">
+ <div class="form-group">
+ <label for="purchaseDate">Purchase Date</label>
+ <input type="date" id="purchaseDate" name="purchase_date" class="form-control" required>
+ </div>
+
+ <!-- Add Lifetime Checkbox -->
+ <div class="form-group">
+ <label class="lifetime-label">
+ <input type="checkbox" id="isLifetime" name="is_lifetime" value="true">
+ Lifetime Warranty
+ </label>
+ </div>
+ <!-- End Lifetime Checkbox -->
+
+ <div class="form-group" id="warrantyYearsGroup">
+ <label for="warrantyYears">Warranty Period (Years)</label>
+ <input type="number" id="warrantyYears" name="warranty_years" class="form-control" min="1" max="100" required>
+ </div>
+
+ <div class="form-group">
+ <label for="purchasePrice">Purchase Price (Optional)</label>
+ <div class="price-input-wrapper">
+ <span class="currency-symbol">$</span>
+ <input type="number" id="purchasePrice" name="purchase_price" class="form-control" min="0" step="0.01" placeholder="0.00">
+ </div>
+ </div>
+ </div>
+ <!-- Documents Tab -->
+ <div class="tab-content" id="documents">
+ <div class="form-group">
+ <label>Invoice/Receipt</label>
+ <div class="file-input-wrapper">
+ <label for="invoice" class="file-input-label">
+ <i class="fas fa-upload"></i> Choose File
+ </label>
+ <input type="file" id="invoice" name="invoice" class="file-input" accept=".pdf,.png,.jpg,.jpeg">
+ </div>
+ <div id="fileName" class="file-name"></div>
+ </div>
+
+ <div class="form-group">
+ <label>Product Manual (Optional)</label>
+ <div class="file-input-wrapper">
+ <label for="manual" class="file-input-label">
+ <i class="fas fa-upload"></i> Choose File
+ </label>
+ <input type="file" id="manual" name="manual" class="file-input" accept=".pdf,.png,.jpg,.jpeg">
+ </div>
+ <div id="manualFileName" class="file-name"></div>
+ </div>
+ </div>
+ <!-- Tags Tab -->
+ <div class="tab-content" id="tags">
+ <div class="form-group">
+ <label>Add Tags</label>
+ <p class="text-muted">Tags help you organize and filter your warranties</p>
+
+ <div class="tags-container">
+ <div class="selected-tags" id="selectedTags">
+ <!-- Selected tags will be displayed here -->
+ </div>
+
+ <div class="tags-dropdown">
+ <input type="text" id="tagSearch" class="form-control" placeholder="Search or add new tag...">
+ <div class="tags-list" id="tagsList">
+ <!-- Tag options will be populated by JavaScript -->
+ </div>
+ </div>
+
+ <div class="mt-10">
+ <button type="button" id="manageTagsBtn" class="btn btn-secondary btn-sm">
+ <i class="fas fa-cog"></i> Manage Tags
+ </button>
+ </div>
+ </div>
+ </div>
+ </div>
+ <!-- Summary Tab -->
+ <div class="tab-content" id="summary">
+ <div class="summary-container">
+ <div class="summary-section">
+ <h4><i class="fas fa-box"></i> Product Information</h4>
+ <div class="summary-item">
+ <span class="summary-label">Product Name:</span>
+ <span id="summary-product-name" class="summary-value">-</span>
+ </div>
+ <div class="summary-item">
+ <span class="summary-label">Product URL:</span>
+ <span id="summary-product-url" class="summary-value">-</span>
+ </div>
+ <div class="summary-item">
+ <span class="summary-label">Serial Numbers:</span>
+ <span id="summary-serial-numbers" class="summary-value">-</span>
+ </div>
+ </div>
+
+ <div class="summary-section">
+ <h4><i class="fas fa-shield-alt"></i> Warranty Details</h4>
+ <div class="summary-item">
+ <span class="summary-label">Purchase Date:</span>
+ <span id="summary-purchase-date" class="summary-value">-</span>
+ </div>
+ <div class="summary-item">
+ <span class="summary-label">Warranty Period:</span>
+ <span id="summary-warranty-years" class="summary-value">-</span>
+ </div>
+ <div class="summary-item">
+ <span class="summary-label">Purchase Price:</span>
+ <span id="summary-purchase-price" class="summary-value">-</span>
+ </div>
+ </div>
+
+ <div class="summary-section">
+ <h4><i class="fas fa-file-alt"></i> Documents</h4>
+ <div class="summary-item">
+ <span class="summary-label">Invoice/Receipt:</span>
+ <span id="summary-invoice" class="summary-value">-</span>
+ </div>
+ <div class="summary-item">
+ <span class="summary-label">Product Manual:</span>
+ <span id="summary-manual" class="summary-value">-</span>
+ </div>
+ </div>
+
+ <div class="summary-section">
+ <h4><i class="fas fa-tags"></i> Tags</h4>
+ <div class="summary-item">
+ <span class="summary-label">Selected Tags:</span>
+ <div id="summary-tags" class="summary-value">-</div>
+ </div>
+ </div>
+ </div>
+
+ <div class="form-group">
+ <button type="submit" class="btn btn-primary">Add Warranty</button>
+ </div>
+ </div>
+ <!-- Tab Navigation -->
+ <div class="tab-navigation">
+ <button type="button" class="btn btn-secondary prev-tab">
+ <i class="fas fa-arrow-left"></i> Previous
+ </button>
+ <button type="button" class="btn btn-primary next-tab">
+ Next <i class="fas fa-arrow-right"></i>
+ </button>
+ </div>
+ </form>
+ </div> <!-- End form-panel -->
+ </div> <!-- End modal-body -->
+ <!-- Optional: Add a modal footer if you want separate Cancel/Submit buttons -->
+ <!-- <div class="modal-footer">
+ <button class="btn btn-secondary" data-dismiss="modal">Cancel</button>
+ </div> -->
+ </div> <!-- End modal -->
+ </div> <!-- End addWarrantyModal -->
+ </div> <!-- End main-content -->
+ </div> <!-- End container -->
<!-- Edit Warranty Modal -->
<div id="editModal" class="modal-backdrop">
@@ -749,5 +784,6 @@
<script src="auth.js"></script>
<script src="script.js"></script>
+
</body>
-</html>
\ No newline at end of file
+</html>
diff --git a/frontend/login.html b/frontend/login.html
index 82fc024..b507fad 100644
--- a/frontend/login.html
+++ b/frontend/login.html
@@ -6,8 +6,13 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Login - Warranty Tracker</title>
+ <title>Login - Warracker</title>
+ <!-- Favicons -->
+ <link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
+ <link rel="icon" type="image/png" sizes="16x16" href="img/favicon-16x16.png?v=2">
+ <link rel="icon" type="image/png" sizes="32x32" href="img/favicon-32x32.png?v=2">
<link rel="stylesheet" href="style.css">
+ <script src="theme-loader.js"></script> <!-- Apply theme early -->
<!-- Font Awesome for icons -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<!-- Load header fix styles to ensure consistent header styling -->
@@ -99,7 +104,7 @@
<div class="container">
<div class="app-title">
<i class="fas fa-shield-alt"></i>
- <h1>Warranty Tracker</h1>
+ <h1>Warracker</h1>
</div>
</div>
</header>
@@ -224,35 +229,7 @@
authMessage.classList.add(type);
authMessage.style.display = 'block';
}
-
- // Check for dark mode preference
- const darkModeEnabled = localStorage.getItem('darkMode') === 'enabled';
- if (darkModeEnabled) {
- document.body.classList.add('dark-mode');
- }
});
-
- // Theme initialization
- function setTheme(isDark) {
- document.documentElement.setAttribute('data-theme', isDark ? 'dark' : 'light');
- }
-
- function initializeTheme() {
- // Check for saved theme preference
- const savedTheme = localStorage.getItem('darkMode');
-
- if (savedTheme !== null) {
- // Use saved preference
- setTheme(savedTheme === 'true');
- } else {
- // Use system preference as fallback
- const prefersDarkMode = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
- setTheme(prefersDarkMode);
- }
- }
-
- // Initialize theme when page loads
- document.addEventListener('DOMContentLoaded', initializeTheme);
</script>
</body>
</html>
diff --git a/frontend/register.html b/frontend/register.html
index 882b438..655bdfb 100644
--- a/frontend/register.html
+++ b/frontend/register.html
@@ -6,8 +6,13 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Register - Warranty Tracker</title>
+ <title>Register - Warracker</title>
+ <!-- Favicons -->
+ <link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
+ <link rel="icon" type="image/png" sizes="16x16" href="img/favicon-16x16.png?v=2">
+ <link rel="icon" type="image/png" sizes="32x32" href="img/favicon-32x32.png?v=2">
<link rel="stylesheet" href="style.css">
+ <script src="theme-loader.js"></script> <!-- Apply theme early -->
<!-- Font Awesome for icons -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<!-- Load header fix styles to ensure consistent header styling -->
diff --git a/frontend/reset-password-request.html b/frontend/reset-password-request.html
index 4a5dec2..7db34f5 100644
--- a/frontend/reset-password-request.html
+++ b/frontend/reset-password-request.html
@@ -4,7 +4,12 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Reset Password - Warranty Tracker</title>
+ <!-- Favicons -->
+ <link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
+ <link rel="icon" type="image/png" sizes="16x16" href="img/favicon-16x16.png?v=2">
+ <link rel="icon" type="image/png" sizes="32x32" href="img/favicon-32x32.png?v=2">
<link rel="stylesheet" href="style.css">
+ <script src="theme-loader.js"></script> <!-- Apply theme early -->
<!-- Font Awesome for icons -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
diff --git a/frontend/reset-password.html b/frontend/reset-password.html
index 6702e2a..0f77e39 100644
--- a/frontend/reset-password.html
+++ b/frontend/reset-password.html
@@ -4,7 +4,12 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Set New Password - Warranty Tracker</title>
+ <!-- Favicons -->
+ <link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
+ <link rel="icon" type="image/png" sizes="16x16" href="img/favicon-16x16.png?v=2">
+ <link rel="icon" type="image/png" sizes="32x32" href="img/favicon-32x32.png?v=2">
<link rel="stylesheet" href="style.css">
+ <script src="theme-loader.js"></script> <!-- Apply theme early -->
<!-- Font Awesome for icons -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
diff --git a/frontend/script.js b/frontend/script.js
index af9038c..57bcada 100644
--- a/frontend/script.js
+++ b/frontend/script.js
@@ -63,6 +63,10 @@ const editIsLifetimeCheckbox = document.getElementById('editIsLifetime');
const editWarrantyYearsGroup = document.getElementById('editWarrantyYearsGroup');
const editWarrantyYearsInput = document.getElementById('editWarrantyYears');
+// Add near other DOM Element declarations
+const showAddWarrantyBtn = document.getElementById('showAddWarrantyBtn');
+const addWarrantyModal = document.getElementById('addWarrantyModal');
+
/**
* Get current user type (admin or user)
* @returns {string} 'admin' or 'user'
@@ -162,12 +166,17 @@ let expiringSoonDays = 30; // Default value, will be updated from user preferenc
const API_URL = '/api/warranties';
// Form tab navigation variables
-const formTabs = Array.from(document.querySelectorAll('.form-tab'));
-const tabContentsArray = document.querySelectorAll('.tab-content');
-tabContents = Array.from(tabContentsArray); // Convert NodeList to Array
+// Ensure these elements exist before trying to select them
+const formTabsElements = document.querySelectorAll('.form-tab');
+const formTabs = formTabsElements ? Array.from(formTabsElements) : [];
+const tabContentsElements = document.querySelectorAll('.tab-content');
+tabContents = tabContentsElements ? Array.from(tabContentsElements) : [];
const nextButton = document.querySelector('.next-tab');
const prevButton = document.querySelector('.prev-tab');
+// --- Add near other DOM Element declarations ---
+const serialNumbersContainer = document.getElementById('serialNumbersContainer'); // Keep this line
+
// Initialize form tabs
function initFormTabs() {
console.log('Initializing form tabs...');
@@ -562,108 +571,91 @@ async function exportWarranties() {
// Switch view of warranties list
function switchView(viewType) {
- console.log(`Switching to ${viewType} view...`);
-
- // Update currentView
+ console.log(`Switching to view: ${viewType}`);
currentView = viewType;
+
+ // Get the appropriate key prefix based on user type
+ const prefix = getPreferenceKeyPrefix();
+ localStorage.setItem(`${prefix}viewPreference`, viewType);
+ localStorage.setItem('viewPreference', viewType); // Keep for backward compatibility
+
+ // Make sure warrantiesList exists before modifying classes
+ if (warrantiesList) {
+ warrantiesList.classList.remove('grid-view', 'list-view', 'table-view');
+ warrantiesList.classList.add(`${viewType}-view`);
+ }
+
+ // Make sure view buttons exist
+ if (gridViewBtn && listViewBtn && tableViewBtn) {
+ gridViewBtn.classList.remove('active');
+ listViewBtn.classList.remove('active');
+ tableViewBtn.classList.remove('active');
+ }
- // Remove active class from all view buttons
- gridViewBtn.classList.remove('active');
- listViewBtn.classList.remove('active');
- tableViewBtn.classList.remove('active');
-
- // Update the view
- warrantiesList.className = `warranties-list ${viewType}-view`;
-
- // Hide table header if not in table view
+ // Make sure the specific button exists
+ if (viewType === 'grid' && gridViewBtn) gridViewBtn.classList.add('active');
+ if (viewType === 'list' && listViewBtn) listViewBtn.classList.add('active');
+ if (viewType === 'table' && tableViewBtn) tableViewBtn.classList.add('active');
+
+ // Show/hide table header only if it exists
if (tableViewHeader) {
- tableViewHeader.style.display = viewType === 'table' ? 'flex' : 'none';
+ tableViewHeader.classList.toggle('visible', viewType === 'table');
}
-
- // Add active class to the selected view button
- if (viewType === 'grid') {
- gridViewBtn.classList.add('active');
- } else if (viewType === 'list') {
- listViewBtn.classList.add('active');
- } else if (viewType === 'table') {
- tableViewBtn.classList.add('active');
+
+ // Re-render warranties only if warrantiesList exists
+ if (warrantiesList) {
+ renderWarranties(filterWarranties());
}
-
- // Re-render warranties with the new view
- console.log('Applying filters after switching view...');
- applyFilters();
-
- // Get prefix for user-specific preferences
- const prefix = getPreferenceKeyPrefix();
-
- // Save view preference to localStorage with the appropriate prefix
- localStorage.setItem(`${prefix}warrantyView`, viewType);
- localStorage.setItem('warrantyView', viewType); // Keep global setting for backward compatibility
}
-// Load saved view preference
+// Load view preference from localStorage
function loadViewPreference() {
- // Get prefix for user-specific preferences
+ // Get the appropriate key prefix based on user type
const prefix = getPreferenceKeyPrefix();
+ let savedView = localStorage.getItem(`${prefix}viewPreference`);
- // First check for user-specific warrantyView
- const userSavedView = localStorage.getItem(`${prefix}warrantyView`);
-
- if (userSavedView) {
- console.log(`Found user-specific view preference: ${userSavedView}`);
- switchView(userSavedView);
- return;
+ // Fallback to global preference if user-specific one isn't found
+ if (!savedView) {
+ savedView = localStorage.getItem('viewPreference');
}
- // If not found, check for user-specific defaultView
- const userDefaultView = localStorage.getItem(`${prefix}defaultView`);
- if (userDefaultView) {
- console.log(`Found user-specific default view: ${userDefaultView}`);
- switchView(userDefaultView);
- return;
- }
+ // Default to grid view if no preference is saved
+ savedView = savedView || 'grid';
- // If no user-specific preferences found, check global preferences for backward compatibility
- const globalSavedView = localStorage.getItem('warrantyView');
- if (globalSavedView) {
- console.log(`Found global view preference: ${globalSavedView}`);
- switchView(globalSavedView);
- return;
+ console.log(`Found global view preference: ${savedView}`);
+ // Switch view only if view buttons exist (implying it's the main page)
+ if (gridViewBtn || listViewBtn || tableViewBtn) {
+ switchView(savedView);
}
-
- const globalDefaultView = localStorage.getItem('defaultView');
- if (globalDefaultView) {
- console.log(`Found global default view: ${globalDefaultView}`);
- switchView(globalDefaultView);
- return;
- }
-
- // Default to grid view if no preferences found
- console.log('No view preference found, defaulting to grid view');
- switchView('grid');
}
// Dark mode toggle
-darkModeToggle.addEventListener('change', (e) => {
- setTheme(e.target.checked);
-});
-
-const serialNumbersContainer = document.getElementById('serialNumbersContainer');
+if (darkModeToggle) { // Add check for darkModeToggle
+ darkModeToggle.addEventListener('change', (e) => {
+ setTheme(e.target.checked);
+ });
+}
// Add event listener for adding new serial number inputs
-serialNumbersContainer.addEventListener('click', (e) => {
- if (e.target.closest('.add-serial-number')) {
- addSerialNumberInput();
- }
-});
+// Add check for serialNumbersContainer before adding listener
+if (serialNumbersContainer) {
+ serialNumbersContainer.addEventListener('click', (e) => {
+ if (e.target.closest('.add-serial-number')) {
+ addSerialNumberInput();
+ }
+ });
+}
// Add a serial number input field
function addSerialNumberInput(container = serialNumbersContainer) {
- if (!container) return;
-
- // Create a new input group
- const inputGroup = document.createElement('div');
- inputGroup.className = 'serial-number-input';
+ // Check if the container exists before proceeding
+ if (!container) {
+ console.warn('Serial numbers container not found, cannot add input.');
+ return;
+ }
+
+ const div = document.createElement('div');
+ div.className = 'serial-number-input d-flex mb-2';
// Create an input element
const input = document.createElement('input');
@@ -676,7 +668,7 @@ function addSerialNumberInput(container = serialNumbersContainer) {
const isFirstInput = container.querySelectorAll('.serial-number-input').length === 0;
// Append input to the input group
- inputGroup.appendChild(input);
+ div.appendChild(input);
// Only add remove button if this is not the first input
if (!isFirstInput) {
@@ -688,19 +680,19 @@ function addSerialNumberInput(container = serialNumbersContainer) {
// Add event listener to remove button
removeButton.addEventListener('click', function() {
- container.removeChild(inputGroup);
+ container.removeChild(div);
});
// Append remove button to the input group
- inputGroup.appendChild(removeButton);
+ div.appendChild(removeButton);
}
// Insert the new input group before the add button
const addButton = container.querySelector('.add-serial');
if (addButton) {
- container.insertBefore(inputGroup, addButton);
+ container.insertBefore(div, addButton);
} else {
- container.appendChild(inputGroup);
+ container.appendChild(div);
// Create and append an add button if it doesn't exist
const addButton = document.createElement('button');
@@ -1194,36 +1186,41 @@ async function renderWarranties(warrantiesToRender) {
}
function filterWarranties() {
- const searchTerm = searchInput.value.toLowerCase();
-
- // Show or hide the clear search button
- clearSearchBtn.style.display = searchTerm ? 'flex' : 'none';
-
+ const searchTerm = searchInput ? searchInput.value.toLowerCase() : ''; // Add null check for searchInput
+
+ // Show or hide the clear search button if it exists
+ if (clearSearchBtn) {
+ clearSearchBtn.style.display = searchTerm ? 'flex' : 'none';
+ }
+
if (!searchTerm) {
- renderWarranties();
- return;
+ return warranties; // Return the full list if no search term
+ // REMOVED: renderWarranties();
+ // REMOVED: return;
}
-
+
const filtered = warranties.filter(warranty => {
// Check product name
- if (warranty.product_name.toLowerCase().includes(searchTerm)) {
+ if (warranty.product_name && warranty.product_name.toLowerCase().includes(searchTerm)) { // Add null check
return true;
}
-
+
// Check tags
if (warranty.tags && Array.isArray(warranty.tags)) {
- return warranty.tags.some(tag => tag.name.toLowerCase().includes(searchTerm));
+ return warranty.tags.some(tag => tag.name && tag.name.toLowerCase().includes(searchTerm)); // Add null check
}
-
+
return false;
});
-
- // Add visual feedback if no results found
- if (filtered.length === 0) {
- renderEmptyState(`No matches found for "${searchTerm}". Try a different search term.`);
- } else {
- renderWarranties(filtered);
- }
+
+ // REMOVED: Add visual feedback if no results found
+ // REMOVED: if (filtered.length === 0) {
+ // REMOVED: renderEmptyState(`No matches found for "${searchTerm}". Try a different search term.`);
+ // REMOVED: } else {
+ // REMOVED: renderWarranties(filtered);
+ // REMOVED: }
+
+ return filtered; // Return the filtered list
}
function applyFilters() {
@@ -1606,16 +1603,14 @@ function submitForm(event) {
hideLoadingSpinner();
showToast('Warranty added successfully', 'success');
- // Reset form and reload warranties
- resetForm();
-
- // Reset selected tags
- selectedTags = [];
- if (selectedTagsContainer) {
- selectedTagsContainer.innerHTML = '';
+ // --- Close and reset the modal on success ---
+ if (addWarrantyModal) {
+ addWarrantyModal.classList.remove('active');
}
-
- loadWarranties();
+ resetAddWarrantyWizard(); // Reset the wizard form
+ // --- End modification ---
+
+ loadWarranties(); // Reload the list
})
.catch(error => {
hideLoadingSpinner();
@@ -1626,17 +1621,25 @@ function submitForm(event) {
// Initialize page
document.addEventListener('DOMContentLoaded', function() {
- // Initialize the warranty form
- initWarrantyForm();
+ // Initialize the warranty form *only* if the form element exists
+ if (warrantyForm) {
+ initWarrantyForm();
+ }
- // Load warranties
- loadWarranties();
+ // Load warranties (might need checks if warrantiesList doesn't always exist)
+ if (warrantiesList) {
+ loadWarranties();
+ loadViewPreference(); // Load user's preferred view
+ loadTags(); // Load tags for the form
+ initTagFunctionality(); // Initialize tag search/selection
+ }
- // Initialize theme
+ // Initialize theme (should be safe on all pages)
initializeTheme();
- // Set up event listeners for other UI controls
+ // Set up event listeners for other UI controls (should contain checks)
setupUIEventListeners();
+ setupModalTriggers(); // Add the new modal listeners
});
// Add this function to handle edit tab functionality
@@ -2466,9 +2469,11 @@ function saveWarranty() {
return;
}
+ // --- Get form values ---
const productName = document.getElementById('editProductName').value.trim();
const purchaseDate = document.getElementById('editPurchaseDate').value;
- const warrantyYears = document.getElementById('editWarrantyYears').value;
+ const isLifetime = document.getElementById('editIsLifetime').checked;
+ const warrantyYears = document.getElementById('editWarrantyYears').value; // Declare only once
// Basic validation
if (!productName) {
@@ -2481,16 +2486,28 @@ function saveWarranty() {
return;
}
- if (!warrantyYears || warrantyYears <= 0) {
- showToast('Warranty period must be greater than 0', 'error');
- return;
+ // --- Modified Validation ---
+ // Only validate warrantyYears if it's NOT a lifetime warranty
+ if (!isLifetime) {
+ // Use parseInt to ensure it's treated as a number
+ if (!warrantyYears || parseInt(warrantyYears, 10) <= 0) {
+ showToast('Warranty period (years) must be greater than 0 for non-lifetime warranties', 'error');
+ // Optional: focus the years input again
+ const yearsInput = document.getElementById('editWarrantyYears');
+ if (yearsInput) { // Check if element exists
+ yearsInput.focus();
+ yearsInput.classList.add('invalid');
+ }
+ return;
+ }
}
+ // --- End Modified Validation ---
// Create form data
const formData = new FormData();
formData.append('product_name', productName);
formData.append('purchase_date', purchaseDate);
- formData.append('warranty_years', warrantyYears);
+ // formData.append('warranty_years', warrantyYears); // Append conditionally later
// Optional fields
const productUrl = document.getElementById('editProductUrl').value.trim();
@@ -2531,22 +2548,22 @@ function saveWarranty() {
formData.append('manual', manualFile);
}
- // --- Add Lifetime Check ---
- if (!editIsLifetimeCheckbox.checked && !editWarrantyYearsInput.value) {
- showToast('Warranty period (years) is required unless it\'s a lifetime warranty', 'error');
- // Switch to the warranty details tab in the edit modal
- const warrantyTabBtn = document.querySelector('.edit-tab-btn[data-tab="edit-warranty-details"]');
- if (warrantyTabBtn) warrantyTabBtn.click();
- editWarrantyYearsInput.focus();
- editWarrantyYearsInput.classList.add('invalid');
- return;
- }
+ // --- Remove redundant check (already covered by validation) ---
+ // if (!editIsLifetimeCheckbox.checked && !editWarrantyYearsInput.value) {
+ // showToast('Warranty period (years) is required unless it\'s a lifetime warranty', 'error');
+ // // Switch to the warranty details tab in the edit modal
+ // const warrantyTabBtn = document.querySelector('.edit-tab-btn[data-tab="edit-warranty-details"]');
+ // if (warrantyTabBtn) warrantyTabBtn.click();
+ // editWarrantyYearsInput.focus();
+ // editWarrantyYearsInput.classList.add('invalid');
+ // return;
+ // }
// --- Append is_lifetime and warranty_years ---
- const isLifetime = editIsLifetimeCheckbox.checked;
formData.append('is_lifetime', isLifetime.toString());
if (!isLifetime) {
- formData.append('warranty_years', editWarrantyYearsInput.value);
+ // Use the value we already retrieved
+ formData.append('warranty_years', warrantyYears);
}
// Get auth token
@@ -2843,4 +2860,90 @@ function handleEditLifetimeChange(event) {
group.style.display = 'block';
input.required = true;
}
+}
+
+// --- Add this function to reset the wizard ---
+function resetAddWarrantyWizard() {
+ console.log('Resetting Add Warranty Wizard...');
+ // Reset the form fields
+ if (warrantyForm) {
+ warrantyForm.reset();
+ }
+
+ // Reset serial numbers container (remove all but the first input structure)
+ if (serialNumbersContainer) {
+ serialNumbersContainer.innerHTML = ''; // Clear it
+ addSerialNumberInput(); // Add the initial input back
+ }
+
+ // Reset file input displays
+ if (fileName) fileName.textContent = '';
+ if (manualFileName) manualFileName.textContent = '';
+
+ // Reset selected tags
+ selectedTags = [];
+ renderSelectedTags(); // Update the display
+
+ // Reset tabs to the first one
+ // Use the globally defined tabContents if available
+ const tabs = addWarrantyModal?.querySelectorAll('.form-tab');
+ const contents = addWarrantyModal?.querySelectorAll('.tab-content');
+ if (tabs && contents && tabs.length > 0 && contents.length > 0) {
+ currentTabIndex = 0;
+ switchToTab(0); // Use the existing function to switch
+ } else {
+ console.warn("Could not find tabs/contents inside addWarrantyModal to reset.");
+ }
+
+ // Clear any validation states
+ addWarrantyModal?.querySelectorAll('.invalid').forEach(el => el.classList.remove('invalid'));
+ addWarrantyModal?.querySelectorAll('.validation-message').forEach(el => el.remove());
+
+ // Reset lifetime checkbox state if needed (ensure handler runs)
+ if (isLifetimeCheckbox) {
+ isLifetimeCheckbox.checked = false; // Explicitly uncheck
+ handleLifetimeChange({ target: isLifetimeCheckbox }); // Trigger handler to reset visibility/required state
+ }
+}
+
+// --- Modify setupUIEventListeners or add this within DOMContentLoaded ---
+function setupModalTriggers() {
+ // Show Add Warranty Modal
+ if (showAddWarrantyBtn && addWarrantyModal) {
+ showAddWarrantyBtn.addEventListener('click', () => {
+ resetAddWarrantyWizard(); // Reset before showing
+ addWarrantyModal.classList.add('active');
+ // Re-initialize tabs specifically for this modal if needed,
+ // but initFormTabs() in DOMContentLoaded should handle it.
+ // Ensure the first tab content is displayed correctly after reset
+ switchToTab(0);
+ });
+ }
+
+ // Hide Add Warranty Modal (using existing close logic)
+ if (addWarrantyModal) {
+ // Close button inside modal
+ const closeBtn = addWarrantyModal.querySelector('.close-btn');
+ if (closeBtn) {
+ closeBtn.addEventListener('click', () => {
+ addWarrantyModal.classList.remove('active');
+ resetAddWarrantyWizard(); // Reset on close
+ });
+ }
+ // Backdrop click
+ addWarrantyModal.addEventListener('click', (e) => {
+ if (e.target === addWarrantyModal) {
+ addWarrantyModal.classList.remove('active');
+ resetAddWarrantyWizard(); // Reset on close
+ }
+ });
+ // Optional: Cancel button in footer if you add one
+ // const cancelBtn = addWarrantyModal.querySelector('.cancel-btn');
+ // if (cancelBtn) {
+ // cancelBtn.addEventListener('click', () => {
+ // addWarrantyModal.classList.remove('active');
+ // resetAddWarrantyWizard(); // Reset on cancel
+ // });
+ // }
+ }
}
\ No newline at end of file
diff --git a/frontend/settings-new.html b/frontend/settings-new.html
index 8ff6da2..f3b2d78 100644
--- a/frontend/settings-new.html
+++ b/frontend/settings-new.html
@@ -9,13 +9,18 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Settings - Warranty Tracker</title>
+ <title>Settings - Warracker</title>
+ <!-- Favicons -->
+ <link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
+ <link rel="icon" type="image/png" sizes="16x16" href="img/favicon-16x16.png?v=2">
+ <link rel="icon" type="image/png" sizes="32x32" href="img/favicon-32x32.png?v=2">
<!-- Load the main site styles first -->
<link rel="stylesheet" href="style.css">
<!-- Font Awesome for icons -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<!-- Then load settings-specific styles -->
<link rel="stylesheet" href="settings-styles.css">
+ <script src="theme-loader.js"></script> <!-- Apply theme early -->
<!-- Load header fix styles last to override any conflicting styles -->
<link rel="stylesheet" href="header-fix.css">
<!-- Load fix for auth buttons -->
@@ -329,7 +334,7 @@
<div class="container">
<div class="app-title">
<i class="fas fa-shield-alt"></i>
- <h1>Warranty Tracker</h1>
+ <h1>Warracker</h1>
</div>
<div class="nav-links">
<a href="index.html" class="nav-link">
@@ -349,11 +354,17 @@
</button>
<div class="user-menu-dropdown" id="userMenuDropdown">
<div class="user-info">
- <div class="user-name" id="userName">User</div>
- <div class="user-email" id="userEmail">[email protected]</div>
+ <div id="userName" class="user-name">User Name</div>
+ <div id="userEmail" class="user-email">[email protected]</div>
</div>
- <div class="user-menu-item" onclick="window.location.href='settings-new.html'">
- <i class="fas fa-cog"></i> Settings
+ <div class="user-menu-item">
+ <a href="settings-new.html" style="color: inherit; text-decoration: none; display: block;">
+ <i class="fas fa-cog"></i> Settings
+ </a>
+ </div>
+ <div class="user-menu-item">
+ <i class="fas fa-info-circle"></i>
+ <a href="about.html" style="text-decoration: none; color: inherit;">About</a>
</div>
<div class="user-menu-item" id="logoutMenuItem">
<i class="fas fa-sign-out-alt"></i> Logout
@@ -612,7 +623,7 @@
<div class="preference-item">
<div>
<label>Registration Enabled</label>
- <p class="text-muted">Allow new users to register on the site</p>
+ <p class="text-muted">Allow new users to register</p>
</div>
<label class="toggle-switch">
<input type="checkbox" id="registrationEnabled">
@@ -620,6 +631,17 @@
</label>
</div>
</div>
+
+ <!-- Email Base URL Setting -->
+ <div class="form-group">
+ <div class="preference-item">
+ <div>
+ <label for="emailBaseUrl">Email Base URL</label>
+ <p class="text-muted">The base URL (e.g., http://yourdomain.com) used for links in emails. No trailing slash.</p>
+ </div>
+ <input type="text" id="emailBaseUrl" class="form-control" placeholder="http://localhost:8080">
+ </div>
+ </div>
<button type="button" id="saveSiteSettingsBtn" class="btn btn-primary">Save Site Settings</button>
</form>
diff --git a/frontend/settings-new.js b/frontend/settings-new.js
index a79f216..e208b17 100644
--- a/frontend/settings-new.js
+++ b/frontend/settings-new.js
@@ -42,6 +42,7 @@ const testApiBtn = document.getElementById('testApiBtn');
const triggerNotificationsBtn = document.getElementById('triggerNotificationsBtn');
const registrationEnabled = document.getElementById('registrationEnabled');
const saveSiteSettingsBtn = document.getElementById('saveSiteSettingsBtn');
+const emailBaseUrlInput = document.getElementById('emailBaseUrl'); // Added for email base URL
/**
* Initialize dark mode toggle
@@ -2406,31 +2407,48 @@ function closeAllModals() {
* Load site settings
*/
async function loadSiteSettings() {
- showLoading();
-
- try {
+ console.log('Loading site settings...');
+ const adminSection = document.getElementById('adminSection');
+ const registrationToggle = document.getElementById('registrationEnabled');
+ const emailBaseUrlField = document.getElementById('emailBaseUrl'); // Correct variable name
+
+ // // Check if admin section exists
+ // if (!adminSection) {
+ // console.log('Admin section not found, skipping site settings load');
+ // return;
+ // }
+
+ try { // Correct structure: try block starts
+ showLoading();
+
const response = await fetch('/api/admin/settings', {
method: 'GET',
headers: {
- 'Authorization': `Bearer ${window.auth.getToken()}`
+ 'Authorization': 'Bearer ' + localStorage.getItem('auth_token'),
+ 'Content-Type': 'application/json'
}
});
- if (response.ok) {
- const settings = await response.json();
-
- // Update form fields
- if (registrationEnabled) {
- registrationEnabled.checked = settings.registration_enabled === 'true';
- }
- } else {
- const errorData = await response.json();
- console.warn('API error:', errorData.message);
+ if (!response.ok) {
+ throw new Error(`Failed to load site settings: ${response.status} ${response.statusText}`);
}
- } catch (error) {
+
+ const settings = await response.json();
+
+ if (registrationToggle) {
+ registrationToggle.checked = settings.registration_enabled === 'true';
+ }
+
+ if (emailBaseUrlField) { // Use correct variable name
+ emailBaseUrlField.value = settings.email_base_url || 'http://localhost:8080'; // Set the value
+ }
+
+ console.log('Site settings loaded successfully', settings);
+
+ } catch (error) { // Correct structure: catch block follows try
console.error('Error loading site settings:', error);
showToast('Failed to load site settings. Please try again.', 'error');
- } finally {
+ } finally { // Correct structure: finally block follows catch
hideLoading();
}
}
@@ -2439,18 +2457,45 @@ async function loadSiteSettings() {
* Save site settings
*/
async function saveSiteSettings() {
- showLoading();
+ console.log('Saving site settings...');
+ const registrationToggle = document.getElementById('registrationEnabled');
+ const emailBaseUrlField = document.getElementById('emailBaseUrl'); // Get the new field
+
+ const settings = {};
+
+ if (registrationToggle) {
+ settings.registration_enabled = registrationToggle.checked; // Boolean value will be converted to string in backend
+ }
+
+ if (emailBaseUrlField) {
+ let baseUrl = emailBaseUrlField.value.trim();
+ // Basic validation: check if it looks somewhat like a URL
+ if (baseUrl && (baseUrl.startsWith('http://') || baseUrl.startsWith('https://'))) {
+ // Remove trailing slash if present
+ if (baseUrl.endsWith('/')) {
+ baseUrl = baseUrl.slice(0, -1);
+ }
+ settings.email_base_url = baseUrl;
+ } else if (baseUrl) {
+ showToast('Invalid Email Base URL format. It should start with http:// or https://', 'error');
+ return; // Stop saving if format is invalid
+ } else {
+ settings.email_base_url = 'http://localhost:8080'; // Use default if empty
+ emailBaseUrlField.value = settings.email_base_url; // Update field with default
+ }
+ }
+
try {
+ showLoading();
+
const response = await fetch('/api/admin/settings', {
method: 'PUT',
headers: {
'Authorization': `Bearer ${window.auth.getToken()}`,
'Content-Type': 'application/json'
},
- body: JSON.stringify({
- registration_enabled: registrationEnabled ? registrationEnabled.checked : false
- })
+ body: JSON.stringify(settings)
});
if (response.ok) {
diff --git a/frontend/settings-redirect.html b/frontend/settings-redirect.html
index aa8bdf1..353b7d8 100644
--- a/frontend/settings-redirect.html
+++ b/frontend/settings-redirect.html
@@ -5,6 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="refresh" content="0;url=settings-new.html">
<title>Redirecting to Settings</title>
+ <script src="theme-loader.js"></script> <!-- Apply theme early -->
<style>
body {
font-family: Arial, sans-serif;
@@ -47,4 +48,4 @@
window.location.href = "settings-new.html";
</script>
</body>
-</html>
\ No newline at end of file
+</html>
\ No newline at end of file
diff --git a/frontend/settings.html b/frontend/settings.html
index aa8bdf1..9308013 100644
--- a/frontend/settings.html
+++ b/frontend/settings.html
@@ -35,6 +35,10 @@
text-decoration: underline;
}
</style>
+ <link rel="stylesheet" href="settings-styles.css">
+ <script src="theme-loader.js"></script> <!-- Apply theme early -->
+
+ <!-- Font Awesome -->
</head>
<body>
<div class="container">
diff --git a/frontend/status.html b/frontend/status.html
index 38f8bc8..76642ae 100644
--- a/frontend/status.html
+++ b/frontend/status.html
@@ -12,8 +12,13 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Status - Warranty Tracker</title>
+ <title>Status - Warracker</title>
+ <!-- Favicons -->
+ <link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
+ <link rel="icon" type="image/png" sizes="16x16" href="img/favicon-16x16.png?v=2">
+ <link rel="icon" type="image/png" sizes="32x32" href="img/favicon-32x32.png?v=2">
<link rel="stylesheet" href="style.css">
+ <script src="theme-loader.js"></script> <!-- Apply theme early -->
<!-- Font Awesome for icons -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<!-- Load header fix styles to ensure consistent header styling -->
@@ -206,7 +211,7 @@
<div class="container">
<div class="app-title">
<i class="fas fa-shield-alt"></i>
- <h1>Warranty Tracker</h1>
+ <h1>Warracker</h1>
</div>
<div class="nav-links">
<a href="index.html" class="nav-link">
@@ -239,6 +244,10 @@
<i class="fas fa-cog"></i> Settings
</a>
</div>
+ <div class="user-menu-item">
+ <i class="fas fa-info-circle"></i>
+ <a href="about.html" style="text-decoration: none; color: inherit;">About</a>
+ </div>
<div class="user-menu-item" id="logoutMenuItem">
<i class="fas fa-sign-out-alt"></i> Logout
</div>
diff --git a/frontend/status.js b/frontend/status.js
index b161ba5..611c06b 100644
--- a/frontend/status.js
+++ b/frontend/status.js
@@ -81,11 +81,6 @@ document.addEventListener('DOMContentLoaded', () => {
// ... existing code ...
});
-// Dark mode toggle
-darkModeToggle.addEventListener('change', (e) => {
- setTheme(e.target.checked);
-});
-
// Refresh dashboard button
refreshDashboardBtn.addEventListener('click', () => {
refreshDashboard();
@@ -919,21 +914,21 @@ function exportWarrantyData() {
// Set up event listeners for filtering and sorting
function setupEventListeners() {
// Refresh button
- if (refreshDashboardBtn) {
+ if (refreshDashboardBtn) { // Check element exists before adding listener
refreshDashboardBtn.addEventListener('click', refreshDashboard);
}
-
+
// Search input
if (searchWarranties) {
searchWarranties.addEventListener('input', filterAndSortWarranties);
}
-
+
// Status filter
- if (statusFilter) {
+ if (statusFilter) { // Check element exists before adding listener
statusFilter.addEventListener('change', filterAndSortWarranties);
}
-
- // Sortable headers
+
+ // Sortable headers (check if collection exists)
if (sortableHeaders) {
sortableHeaders.forEach(header => {
header.addEventListener('click', () => {
@@ -955,17 +950,17 @@ function setupEventListeners() {
});
});
}
-
+
// Export button
- if (exportBtn) {
+ if (exportBtn) { // Check element exists before adding listener
exportBtn.addEventListener('click', exportWarrantyData);
}
-
- // Dark mode toggle
+
+ // Dark mode toggle (check element exists before adding listener)
if (darkModeToggle) {
darkModeToggle.addEventListener('change', (e) => {
setTheme(e.target.checked);
-
+
// Redraw charts with new theme colors if they exist
if (window.statusChart) {
createStatusChart({
diff --git a/frontend/style.css b/frontend/style.css
index 045537a..4b9cd54 100644
--- a/frontend/style.css
+++ b/frontend/style.css
@@ -61,6 +61,7 @@ body {
background-color: var(--bg-color);
padding: 0;
margin: 0;
+ z-index: 1000;
}
.container {
@@ -281,8 +282,10 @@ input.invalid {
color: var(--primary-color);
margin-bottom: 20px;
font-size: 1.5rem;
- border-bottom: 2px solid var(--medium-gray);
padding-bottom: 10px;
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
}
.form-group {
@@ -403,13 +406,13 @@ input.invalid {
border-radius: var(--border-radius);
box-shadow: var(--shadow);
padding: 25px;
+ grid-column: 1 / -1; /* Make panel span full width */
}
.warranties-panel h2 {
color: var(--primary-color);
margin-bottom: 20px;
font-size: 1.5rem;
- border-bottom: 2px solid var(--medium-gray);
padding-bottom: 10px;
display: flex;
justify-content: space-between;
@@ -685,7 +688,7 @@ input.invalid {
}
.modal-backdrop.active {
- display: flex;
+ display: flex; /* Shown when active */
}
.modal {
@@ -699,7 +702,7 @@ input.invalid {
flex-direction: column;
animation: slide-in 0.3s ease;
position: relative;
- overflow: hidden;
+ overflow: hidden; /* Changed from auto to hidden */
}
@keyframes slide-in {
@@ -770,9 +773,9 @@ input.invalid {
.modal-body {
padding: 1rem;
- overflow-y: auto;
- flex: 1;
- background-color: var(--modal-background, #ffffff);
+ overflow-y: auto; /* Enable vertical scroll */
+ flex-grow: 1; /* Allow body to take available space */
+ background-color: var(--card-bg); /* Ensure background */
}
.modal-footer {
@@ -2969,4 +2972,54 @@ input.invalid {
.table-view .tags-row-cell {
display: table-cell;
vertical-align: middle;
+}
+
+/* Style the new button */
+.add-warranty-button-container {
+ /* grid-column: 1 / -1; /* REMOVED */
+ /* text-align: right; /* REMOVED */
+ /* margin-bottom: 20px; /* REMOVED */
+ /* No longer needs standalone styles here */
+}
+
+/* REMOVE this rule if button size is handled by btn-sm */
+/* #showAddWarrantyBtn {
+ width: auto;
+ padding: 10px 20px;
+} */
+/* REMOVE this rule if icon margin is handled by btn-sm or FontAwesome defaults */
+/* #showAddWarrantyBtn i {
+ margin-right: 8px;
+} */
+
+/* Forms */
+// ... existing code ...
+/* ===== WARRANTIES LIST ===== */
+.warranties-panel {
+// ... existing code ...
+}
+
+/* ADD styles for Panel Header */
+.panel-header {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ margin-bottom: 20px;
+ padding-bottom: 15px;
+ flex-wrap: wrap;
+ gap: 10px;
+}
+
+.panel-header h2 {
+ margin: 0;
+ font-size: 1.4rem;
+ color: var(--primary-color);
+ flex-grow: 1;
+}
+
+.panel-header-actions {
+ display: flex;
+ align-items: center;
+ gap: 10px;
+ flex-shrink: 0;
}
\ No newline at end of file
diff --git a/frontend/theme-loader.js b/frontend/theme-loader.js
new file mode 100644
index 0000000..98399af
--- /dev/null
+++ b/frontend/theme-loader.js
@@ -0,0 +1,29 @@
+// theme-loader.js
+(function() {
+ try {
+ // Function to apply the theme
+ function applyTheme(isDark) {
+ document.documentElement.setAttribute('data-theme', isDark ? 'dark' : 'light');
+ console.log(`Theme applied on load: ${isDark ? 'dark' : 'light'}`);
+ }
+
+ // Check localStorage for saved theme
+ const savedTheme = localStorage.getItem('darkMode');
+
+ if (savedTheme !== null) {
+ // Apply saved theme
+ applyTheme(savedTheme === 'true');
+ } else {
+ // Fallback to system preference if no theme saved
+ const prefersDarkMode = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
+ console.log(`No saved theme found, falling back to system preference: ${prefersDarkMode ? 'dark' : 'light'}`);
+ applyTheme(prefersDarkMode);
+ // Optionally, save the detected system preference as the initial setting
+ // localStorage.setItem('darkMode', prefersDarkMode);
+ }
+ } catch (e) {
+ console.error("Error applying theme from theme-loader.js:", e);
+ // Fallback to light theme in case of error
+ document.documentElement.setAttribute('data-theme', 'light');
+ }
+})();
diff --git a/nginx.conf b/nginx.conf
index c1fa612..6d03947 100644
--- a/nginx.conf
+++ b/nginx.conf
@@ -1,7 +1,8 @@
server {
listen 80;
server_name localhost;
- root /var/www/html;
+ # Point root to the frontend directory where static assets reside
+ root d:/Project/warracker/Warracker Beta/frontend;
index index.html;
# Enable detailed error logging
@@ -28,6 +29,7 @@ server {
image/gif gif;
image/svg+xml svg svgz;
application/pdf pdf;
+ image/x-icon ico;
}
# API requests - proxy to backend (fixed upstream host)
@@ -73,8 +75,18 @@ server {
add_header Cache-Control "no-cache, no-store, must-revalidate";
}
+ # Favicon - specific handling
+ location = /favicon.ico {
+ log_not_found off;
+ access_log off;
+ try_files $uri =404;
+ expires 7d;
+ add_header Cache-Control "public, max-age=604800";
+ }
+
# Static assets (CSS, JS, images)
location ~* \.(css|js|jpg|jpeg|png|gif|ico|svg)$ {
+ try_files $uri =404;
expires 7d;
add_header Cache-Control "public, max-age=604800";
}
@@ -89,4 +101,4 @@ server {
location / {
try_files $uri $uri/ /index.html;
}
-}
\ No newline at end of file
+}