Fix image display and add AR fields management route

Fixes:
1. Image display - Images now properly display on tenant landing page and edit forms by prepending tenant ID to image paths (/tenant/images/... instead of /images/...)
2. AR fields route - Added /tenant/ar_fields route (without /admin/ prefix) for managing custom AR content fields
3. Template updates - Updated all image src attributes to include tenant prefix for proper routing
4. Navigation - Updated AR fields back button to return to settings page instead of non-existent admin index

Images are now visible in:
- Product list on tenant landing page
- Product edit forms showing current images
- Admin index (if accessed)
This commit is contained in:
2025-10-20 17:17:58 -04:00
parent f781cdf602
commit ccac3134f3
6 changed files with 17 additions and 8 deletions

View File

@@ -295,7 +295,7 @@ def serve_barcode(tenant_id, filename):
# Import product management routes # Import product management routes
from routes.admin import (add_product, edit_product, delete_product, from routes.admin import (add_product, edit_product, delete_product,
generate_barcode, generate_barcode_page) generate_barcode, generate_barcode_page, manage_ar_fields)
# Register product management routes (remove /admin/ from paths) # Register product management routes (remove /admin/ from paths)
app.add_url_rule('/<tenant:tenant_id>/add', 'admin.add_product', add_product, methods=['GET', 'POST']) app.add_url_rule('/<tenant:tenant_id>/add', 'admin.add_product', add_product, methods=['GET', 'POST'])
@@ -303,6 +303,7 @@ app.add_url_rule('/<tenant:tenant_id>/edit/<product_id>', 'admin.edit_product',
app.add_url_rule('/<tenant:tenant_id>/delete/<product_id>', 'admin.delete_product', delete_product, methods=['POST']) app.add_url_rule('/<tenant:tenant_id>/delete/<product_id>', 'admin.delete_product', delete_product, methods=['POST'])
app.add_url_rule('/<tenant:tenant_id>/generate_barcode/<product_id>/<code_type>', 'admin.generate_barcode', generate_barcode) app.add_url_rule('/<tenant:tenant_id>/generate_barcode/<product_id>/<code_type>', 'admin.generate_barcode', generate_barcode)
app.add_url_rule('/<tenant:tenant_id>/generate_barcode_page/<product_id>', 'admin.generate_barcode_page', generate_barcode_page) app.add_url_rule('/<tenant:tenant_id>/generate_barcode_page/<product_id>', 'admin.generate_barcode_page', generate_barcode_page)
app.add_url_rule('/<tenant:tenant_id>/ar_fields', 'admin.manage_ar_fields', manage_ar_fields, methods=['GET', 'POST'])
# Register API routes with tenant prefix # Register API routes with tenant prefix
from routes.api import api_index from routes.api import api_index

View File

@@ -8,7 +8,7 @@
<h1>Manage AR Content Fields</h1> <h1>Manage AR Content Fields</h1>
<p>Configure the fields that will be returned by the /arcontentfields and /arinfo endpoints.</p> <p>Configure the fields that will be returned by the /arcontentfields and /arinfo endpoints.</p>
</div> </div>
<a href="{{ url_for('admin.index', tenant_id=tenant_id) }}" class="btn btn-secondary">Back to Admin</a> <a href="/{{ tenant_id }}/settings" class="btn btn-secondary">Back to Settings</a>
</div> </div>
<div class="card mb-4"> <div class="card mb-4">

View File

@@ -34,7 +34,7 @@
<div class="mt-3"> <div class="mt-3">
<label class="form-label">Current Image:</label> <label class="form-label">Current Image:</label>
<div> <div>
<img src="{{ current_value }}" alt="Current image" class="image-preview" style="max-width: 200px;"> <img src="/{{ tenant_id }}{{ current_value }}" alt="Current image" class="image-preview" style="max-width: 200px;">
</div> </div>
</div> </div>
{% endif %} {% endif %}

View File

@@ -43,7 +43,7 @@
{% if custom_field.fieldType == 'IMAGE_URI' %} {% if custom_field.fieldType == 'IMAGE_URI' %}
{% if field.value %} {% if field.value %}
<div class="product-image-container"> <div class="product-image-container">
<img src="{{ field.value }}" alt="{{ custom_field.label }}" class="product-image"> <img src="/{{ tenant.id }}{{ field.value }}" alt="{{ custom_field.label }}" class="product-image">
</div> </div>
{% endif %} {% endif %}
{% else %} {% else %}

View File

@@ -30,7 +30,7 @@
<tr> <tr>
<th>Product ID</th> <th>Product ID</th>
{% for custom_field in custom_fields %} {% for custom_field in custom_fields %}
{% if custom_field.fieldName != '_id' and custom_field.fieldType != 'IMAGE_URI' %} {% if custom_field.fieldName != '_id' %}
<th>{{ custom_field.label }}</th> <th>{{ custom_field.label }}</th>
{% endif %} {% endif %}
{% endfor %} {% endfor %}
@@ -42,10 +42,18 @@
<tr> <tr>
<td>{{ product_id }}</td> <td>{{ product_id }}</td>
{% for custom_field in custom_fields %} {% for custom_field in custom_fields %}
{% if custom_field.fieldName != '_id' and custom_field.fieldType != 'IMAGE_URI' %} {% if custom_field.fieldName != '_id' %}
<td> <td>
{% set matching_fields = product_data|selectattr('fieldName', 'equalto', custom_field.fieldName)|list %} {% set matching_fields = product_data|selectattr('fieldName', 'equalto', custom_field.fieldName)|list %}
{{ matching_fields[0].value if matching_fields else '' }} {% if custom_field.fieldType == 'IMAGE_URI' %}
{% if matching_fields and matching_fields[0].value %}
<div class="product-image-container">
<img src="/{{ tenant.id }}{{ matching_fields[0].value }}" alt="{{ custom_field.label }}" class="product-image">
</div>
{% endif %}
{% else %}
{{ matching_fields[0].value if matching_fields else '' }}
{% endif %}
</td> </td>
{% endif %} {% endif %}
{% endfor %} {% endfor %}

View File

@@ -49,7 +49,7 @@
</div> </div>
<div class="card-body"> <div class="card-body">
<p class="text-muted">Manage the fields that are returned in the AR content API.</p> <p class="text-muted">Manage the fields that are returned in the AR content API.</p>
<a href="/{{ tenant.id }}/admin/ar_fields" class="btn btn-primary"> <a href="/{{ tenant.id }}/ar_fields" class="btn btn-primary">
<i class="bi bi-gear"></i> Manage AR Fields <i class="bi bi-gear"></i> Manage AR Fields
</a> </a>