From 6dc276a2925d45fa0bb7be8201605632e9af8115 Mon Sep 17 00:00:00 2001 From: Matt Hills Date: Wed, 25 Jun 2025 18:11:12 -0400 Subject: [PATCH] fixing missing barcodes --- src/app.py | 49 +++++++++- src/templates/admin/generate_barcode.html | 4 +- src/templates/index.html | 89 ++++++++++++------ src/templates/tenant_settings.html | 104 ++++++++++++++++++++++ 4 files changed, 216 insertions(+), 30 deletions(-) create mode 100644 src/templates/tenant_settings.html diff --git a/src/app.py b/src/app.py index af741a4..2842682 100644 --- a/src/app.py +++ b/src/app.py @@ -70,7 +70,46 @@ def tenant_index(tenant_id): if tenant is None: # Reserved tenant ID or invalid return jsonify({"error": f"'{tenant_id}' is a reserved name and cannot be used as a tenant ID"}), 404 - return render_template('index.html', tenant=tenant) + + # Load products for this tenant + products = load_products(tenant_id) + + return render_template('index.html', tenant=tenant, products=products) + +@app.route('//settings') +def tenant_settings(tenant_id): + # Get tenant + tenant = database.get_or_create_tenant(tenant_id) + if tenant is None: + return jsonify({"error": f"'{tenant_id}' is a reserved name and cannot be used as a tenant ID"}), 404 + + # Get custom AR fields for this tenant + custom_fields = database.get_custom_ar_fields(tenant_id) + + # Get server URL for API endpoint display + server_url = database.get_server_url() + + return render_template('tenant_settings.html', tenant=tenant, custom_fields=custom_fields, server_url=server_url) + +@app.route('//settings/credentials', methods=['POST']) +def update_tenant_credentials(tenant_id): + # Get tenant + tenant = database.get_tenant(tenant_id) + if tenant is None: + return jsonify({"error": "Tenant not found"}), 404 + + username = request.form.get('username', '').strip() + password = request.form.get('password', '').strip() + + if not username: + flash('Username is required.', 'error') + return redirect(f'/{tenant_id}/settings') + + # Update credentials + database.update_tenant_credentials(tenant_id, username, password if password else None) + + flash('Credentials updated successfully.', 'success') + return redirect(f'/{tenant_id}/settings') def check_basic_auth(auth_header, tenant_id): """Validate Basic authentication credentials for a tenant""" @@ -119,10 +158,14 @@ def get_ar_info(tenant_id): def filter_and_process_fields(product_fields): # Filter to only include fields defined in custom AR fields filtered_fields = [] + + # Get field types for all custom fields + field_types = {f['fieldName']: f['fieldType'] for f in custom_fields} + for field in product_fields: if field['fieldName'] in custom_field_names: - # Create absolute URL for image fields - if field['fieldName'] == '_image' and field['value']: + # Create absolute URL for IMAGE_URI fields + if field_types.get(field['fieldName']) == 'IMAGE_URI' and field['value']: # If it's already an absolute URL, leave it as is if not field['value'].startswith('http'): # Build absolute URL using request host with tenant diff --git a/src/templates/admin/generate_barcode.html b/src/templates/admin/generate_barcode.html index 0615bf5..19a0d8c 100644 --- a/src/templates/admin/generate_barcode.html +++ b/src/templates/admin/generate_barcode.html @@ -86,8 +86,8 @@ diff --git a/src/templates/index.html b/src/templates/index.html index b20730a..43ccb8f 100644 --- a/src/templates/index.html +++ b/src/templates/index.html @@ -5,37 +5,76 @@ {% block content %}
-
+
+

KCAP Demo Server{% if tenant %} - {{ tenant.name }}{% endif %}

Manage your product catalog and AR content for barcode scanning applications.


-

Quick Actions

-
-
-
-
-
Product Management
-

Add, edit, and manage your product catalog with custom fields.

- {% if tenant %} - Manage Products - {% endif %} -
-
-
-
-
-
-
AR Field Configuration
-

Customize the fields returned by AR content endpoints.

- {% if tenant %} - Configure AR Fields - {% endif %} -
-
-
+ + + {% if products %} +
+ + + + + + + + + + + {% for product_id, product_data in products.items() %} + + + + + + + {% endfor %} + +
Product IDNamePriceActions
{{ product_id }} + {% for field in product_data %} + {% if field.fieldName == '_name' %} + {{ field.value }} + {% endif %} + {% endfor %} + + {% for field in product_data %} + {% if field.fieldName == '_price' %} + {{ field.value }} + {% endif %} + {% endfor %} + + + Edit + + + Barcodes + +
+
+ + {% else %} +
+ No products available yet. Click "Add New Product" to get started. +
+ {% endif %}
diff --git a/src/templates/tenant_settings.html b/src/templates/tenant_settings.html new file mode 100644 index 0000000..d6270ef --- /dev/null +++ b/src/templates/tenant_settings.html @@ -0,0 +1,104 @@ +{% extends "layout.html" %} + +{% block title %}Settings - {{ tenant.name }} - KCAP Demo Server{% endblock %} + +{% block content %} +
+
+
+

Settings - {{ tenant.name }}

+ + Back to Dashboard + +
+ +
+ +
+
+
+
Device Authentication
+
+
+

Configure the username and password for device authentication.

+
+
+ + +
+
+ + +
Leave blank to keep current password
+
+ +
+
+
+
+ + +
+
+
+
Custom AR Content Fields
+
+
+

Manage the fields that are returned in the AR content API.

+ + Manage AR Fields + + + {% if custom_fields %} +
+
Current Fields:
+
    + {% for field in custom_fields %} +
  • +
    + {{ field.label }} + ({{ field.fieldName }}) +
    + {{ field.fieldType }} +
  • + {% endfor %} +
+
+ {% endif %} +
+
+
+
+ + +
+
+
+
+
Tenant Information
+
+
+
+
Tenant ID:
+
{{ tenant.id }}
+ +
Tenant Name:
+
{{ tenant.name }}
+ +
API Endpoint:
+
{{ server_url }}/{{ tenant.id }}/arinfo
+ +
Created:
+
{{ tenant.created_at }}
+
+
+
+
+
+
+
+{% endblock %} \ No newline at end of file