From 7baa484d5045a8fafdd13fe4a838bdfc387f7e74 Mon Sep 17 00:00:00 2001
From: candifloss <candifloss@candifloss.cc>
Date: Fri, 4 Apr 2025 12:00:45 +0530
Subject: [PATCH] Add: File upload page style

Add bootstrap css and layout to "csv upload" page for import/update
---
 templates/header.html |   4 +-
 templates/upload.html | 136 ++++++++++++++++++++++++++++++++----------
 2 files changed, 108 insertions(+), 32 deletions(-)

diff --git a/templates/header.html b/templates/header.html
index 89efb40..63675cd 100644
--- a/templates/header.html
+++ b/templates/header.html
@@ -17,10 +17,10 @@
                 Add New Item
             </a>
             <a href="/import_from_csv" class="btn btn-sm btn-outline-light" title="Bulk-add new items from a CSV file">
-                Import CSV
+                Import from CSV
             </a>
             <a href="/edit_using_csv" class="btn btn-sm btn-outline-light" title="Bulk-update existing items using a CSV file">
-                Edit CSV
+                Update with CSV
             </a>
             <form action="/export_csv" method="POST" class="d-inline">
                 <button type="submit" class="btn btn-sm btn-outline-light" title="Download all data as a CSV file">
diff --git a/templates/upload.html b/templates/upload.html
index c69d337..e637b2d 100644
--- a/templates/upload.html
+++ b/templates/upload.html
@@ -6,42 +6,118 @@
     <title>Upload CSV File</title>
     {% include 'favicon.html' %}
     <link href="{{ url_for('static', filename='css/bootstrap.min.css') }}" rel="stylesheet">
+    <style>
+        .upload-container {
+            max-width: 800px;
+            margin: 0 auto;
+        }
+        .error-details {
+            background-color: #f8d7da;
+            border-left: 4px solid #dc3545;
+        }
+    </style>
 </head>
 <body>
     {% include 'header.html' %}
-    <main class="container mt-5 pt-3">
-        <h1>Upload CSV File</h1>
+    
+    <main class="container mt-5 pt-4">
+        <div class="upload-container">
+            <div class="d-flex justify-content-between align-items-center mb-4">
+                <h1 class="h2">
+                    {% if mode == "import" %} 
+                        <i class="bi bi-upload me-2"></i>Import Items From CSV 
+                    {% elif mode == "edit" %} 
+                        <i class="bi bi-pencil-square me-2"></i>Update Items Using CSV 
+                    {% endif %}
+                </h1>
+            </div>
 
-    <!-- Display flash messages (only errors) -->
-    {% with messages = get_flashed_messages(category_filter=["error"]) %}
-        {% if messages %}
-            <details>
-                <summary>Errors found during submission (click to expand):</summary>
-                <ul>
-                    {% for message in messages %}
-                        <li>{{ message }}</li>
-                    {% endfor %}
-                </ul>
-            </details>
-        {% endif %}
-    {% endwith %}
+            <!-- Flash messages (errors only) -->
+            {% with messages = get_flashed_messages(category_filter=["error"]) %}
+                {% if messages %}
+                    <div class="alert alert-danger error-details mb-4">
+                        <h2 class="h5 mb-3">Errors found during submission:</h2>
+                        <ul class="mb-0">
+                            {% for message in messages %}
+                                <li>{{ message }}</li>
+                            {% endfor %}
+                        </ul>
+                    </div>
+                {% endif %}
+            {% endwith %}
 
-    <!-- Upload form -->
-    <form method="POST" enctype="multipart/form-data"
-        {% if mode == "import" %}
-            action="/import_from_csv"
-        {% elif mode == "edit" %}
-            action="/edit_using_csv"
-        {% endif %}
-    >
-        <label for="file">Choose a CSV file:</label>
-        <input type="file" id="file" name="file" accept=".csv" required>
-        <br><br>
-        <button type="submit">Upload</button>
-        <button type="button" onclick="window.location.href='/'">Cancel</button>
-    </form>
+            <!-- Upload form card -->
+            <div class="card shadow-sm">
+                <div class="card-body">
+                    <form method="POST" enctype="multipart/form-data" 
+                        {% if mode == "import" %}
+                            action="/import_from_csv"
+                        {% elif mode == "edit" %}
+                            action="/edit_using_csv"
+                        {% endif %}>
+                        
+                        <div class="mb-4">
+                            <label for="file" class="form-label fw-bold">Select CSV File:</label>
+                            <input class="form-control form-control-lg" 
+                                   type="file" 
+                                   id="file" 
+                                   name="file" 
+                                   accept=".csv" 
+                                   required>
+                            <div class="form-text">
+                                Please upload a properly formatted CSV file
+                            </div>
+                        </div>
+
+                        <div class="d-flex justify-content-end gap-3">
+                            <a href="/" class="btn btn-outline-secondary">Cancel</a>
+                            <button type="submit" class="btn btn-primary px-4">
+                                Upload
+                            </button>
+                        </div>
+                    </form>
+                </div>
+            </div>
+            
+            <!-- Optional help section -->
+            <div class="mt-4">
+                <div class="accordion" id="helpAccordion">
+                    <div class="accordion-item">
+                        <h2 class="accordion-header">
+                            <button class="accordion-button collapsed" 
+                                    type="button" 
+                                    data-bs-toggle="collapse" 
+                                    data-bs-target="#helpContent">
+                                <i class="bi bi-question-circle me-2"></i>
+                                CSV Format Help
+                            </button>
+                        </h2>
+                        <div id="helpContent" 
+                             class="accordion-collapse collapse" 
+                             data-bs-parent="#helpAccordion">
+                            <div class="accordion-body">
+                                <!-- Add your CSV format instructions here -->
+                                <p>Your CSV should include the following columns:</p>
+                                <ul>
+                                    <li><code>id</code> - Required for edits</li>
+                                    <li><code>name</code> - Item name</li>
+                                    <!-- Add more columns as needed -->
+                                </ul>
+                                <a href="/sample.csv" class="btn btn-sm btn-outline-primary">
+                                    Download Sample CSV
+                                </a>
+                            </div>
+                        </div>
+                    </div>
+                </div>
+            </div>
+        </div>
     </main>
-    <!-- Bootstrap JS (for dropdowns) -->
+
+    <!-- Bootstrap Icons (optional) -->
+    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css">
+    
+    <!-- Bootstrap JS -->
     <script src="{{ url_for('static', filename='js/bootstrap.bundle.min.js') }}"></script>
 </body>
 </html>
\ No newline at end of file