diff --git a/.gitignore b/.gitignore index b7ec88f..42b08bd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ recticel/ .venv/ __pycache__/ +app/__pycache__/ diff --git a/py_app/app/__pycache__/order_labels.cpython-312.pyc b/py_app/app/__pycache__/order_labels.cpython-312.pyc index 2d88b53..07c1241 100644 Binary files a/py_app/app/__pycache__/order_labels.cpython-312.pyc and b/py_app/app/__pycache__/order_labels.cpython-312.pyc differ diff --git a/py_app/app/__pycache__/routes.cpython-312.pyc b/py_app/app/__pycache__/routes.cpython-312.pyc index 702debe..b71b5fb 100644 Binary files a/py_app/app/__pycache__/routes.cpython-312.pyc and b/py_app/app/__pycache__/routes.cpython-312.pyc differ diff --git a/py_app/app/routes.py b/py_app/app/routes.py index 1fc519b..d45cf74 100644 --- a/py_app/app/routes.py +++ b/py_app/app/routes.py @@ -939,6 +939,130 @@ def label_templates(): def create_template(): return render_template('create_template.html') +@bp.route('/get_database_tables', methods=['GET']) +def get_database_tables(): + """Get list of database tables for template creation""" + if 'role' not in session or session['role'] not in ['superadmin', 'warehouse_manager', 'etichete']: + return jsonify({'error': 'Access denied'}), 403 + + try: + # Get database connection using the same method as other functions + settings_file = current_app.instance_path + '/external_server.conf' + settings = {} + with open(settings_file, 'r') as f: + for line in f: + key, value = line.strip().split('=', 1) + settings[key] = value + + connection = mariadb.connect( + user=settings['username'], + password=settings['password'], + host=settings['server_domain'], + port=int(settings['port']), + database=settings['database_name'] + ) + + cursor = connection.cursor() + + # Get all tables in the database + cursor.execute("SHOW TABLES") + all_tables = [table[0] for table in cursor.fetchall()] + + # Filter to show relevant tables (prioritize order_for_labels) + relevant_tables = [] + if 'order_for_labels' in all_tables: + relevant_tables.append('order_for_labels') + + # Add other potentially relevant tables + for table in all_tables: + if table not in relevant_tables and any(keyword in table.lower() for keyword in ['order', 'label', 'product', 'customer']): + relevant_tables.append(table) + + connection.close() + + return jsonify({ + 'success': True, + 'tables': relevant_tables, + 'recommended': 'order_for_labels' + }) + + except Exception as e: + return jsonify({'error': f'Database error: {str(e)}'}), 500 + +@bp.route('/get_table_columns/', methods=['GET']) +def get_table_columns(table_name): + """Get column names and descriptions for a specific table""" + if 'role' not in session or session['role'] not in ['superadmin', 'warehouse_manager', 'etichete']: + return jsonify({'error': 'Access denied'}), 403 + + try: + # Get database connection + settings_file = current_app.instance_path + '/external_server.conf' + settings = {} + with open(settings_file, 'r') as f: + for line in f: + key, value = line.strip().split('=', 1) + settings[key] = value + + connection = mariadb.connect( + user=settings['username'], + password=settings['password'], + host=settings['server_domain'], + port=int(settings['port']), + database=settings['database_name'] + ) + + cursor = connection.cursor() + + # Verify table exists + cursor.execute("SHOW TABLES LIKE %s", (table_name,)) + if not cursor.fetchone(): + return jsonify({'error': f'Table {table_name} not found'}), 404 + + # Get column information + cursor.execute(f"DESCRIBE {table_name}") + columns_info = cursor.fetchall() + + columns = [] + for col_info in columns_info: + column_name = col_info[0] + column_type = col_info[1] + is_nullable = col_info[2] == 'YES' + column_default = col_info[4] + + # Get column comment if available + cursor.execute(f""" + SELECT COLUMN_COMMENT + FROM INFORMATION_SCHEMA.COLUMNS + WHERE TABLE_NAME = %s AND COLUMN_NAME = %s AND TABLE_SCHEMA = DATABASE() + """, (table_name, column_name)) + + comment_result = cursor.fetchone() + column_comment = comment_result[0] if comment_result and comment_result[0] else '' + + # Create user-friendly description + description = column_comment or column_name.replace('_', ' ').title() + + columns.append({ + 'name': column_name, + 'type': column_type, + 'nullable': is_nullable, + 'default': column_default, + 'description': description, + 'field_id': f"db_{column_name}" # Unique ID for template fields + }) + + connection.close() + + return jsonify({ + 'success': True, + 'table': table_name, + 'columns': columns + }) + + except Exception as e: + return jsonify({'error': f'Database error: {str(e)}'}), 500 + @bp.route('/edit_template/') def edit_template(template_id): # Logic for editing a template will go here diff --git a/py_app/app/templates/create_template copy.html b/py_app/app/templates/create_template copy.html new file mode 100644 index 0000000..7df0164 --- /dev/null +++ b/py_app/app/templates/create_template copy.html @@ -0,0 +1,440 @@ +{% extends "base.html" %} + +{% block title %}Create Template{% endblock %} + +{% block head %} + +{% endblock %} + +{% block content %} +
+ +
+
+

Template Settings

+

Set the dimensions and retrieve database headers for the label template:

+ + +
+

Dimensions

+
+
+ + +
+
+ + +
+ +
+
+ +
+ + +
+

Add Fields

+ + .big-card { + box-shadow: 0 4px 12px rgba(0,0,0,0.12); + border-radius: 10px; + padding: 30px 24px; + min-height: 600px; + background: #f5faff; + } + .small-card { + box-shadow: 0 2px 6px rgba(0,0,0,0.10); + border-radius: 10px; + padding: 18px 12px; + min-height: 300px; + background: #fff; + } + + + +
+ +
+

Get Database Headers

+

Retrieve column names from a selected database table:

+ +
+ +
+
+ +
+
+ +
+ + +
+
+ + +
+
+

Interactive Label Preview

+

Drag and drop fields to design your label:

+
+
+ +
+
+ +
+
+
+ + + +{% endblock %} \ No newline at end of file diff --git a/py_app/app/templates/create_template.html b/py_app/app/templates/create_template.html deleted file mode 100644 index 0802da5..0000000 --- a/py_app/app/templates/create_template.html +++ /dev/null @@ -1,78 +0,0 @@ -{% extends "base.html" %} - -{% block title %}Create Template{% endblock %} - -{% block content %} -
- -
-
-

Template Settings

-

Set the dimensions and retrieve database headers for the label template:

- - -
-

Dimensions

-
-
- - -
-
- - -
- -
-
- -
- - -
-

Add Fields

- - - - -
- -
-

Get Database Headers

-

Retrieve column names from a selected database table:

- -
- -
-
- -
-
- -
- - -
-
- - -
-
-

Interactive Label Preview

-

Drag and drop fields to design your label:

-
-
- -
-
- -
-
-
- - - -{% endblock %} \ No newline at end of file diff --git a/py_app/app/templates/import_locations_csv.html b/py_app/app/templates/import_locations_csv.html deleted file mode 100644 index 1d287d8..0000000 --- a/py_app/app/templates/import_locations_csv.html +++ /dev/null @@ -1,99 +0,0 @@ -{% extends "base.html" %} -{% block title %}Import Warehouse Locations from CSV{% endblock %} -{% block content %} -
- -
-

Import Locations from CSV

-
- - {% if not locations %} -
- - {% else %} -
- - {% endif %} - -
-

CSV File Format

- - - - - - - - - - - - - - - - -
Location CodeSizeDescription
EX123100Zona depozitare A
-
-
- - - -
- -
-

Preview Table

- - - - - - - - - - {% if locations %} - {% for loc in locations %} - - - - - - {% endfor %} - {% else %} - - {% endif %} - -
Location CodeSizeDescription
{{ loc[0] }}{{ loc[1] }}{{ loc[2] }}
No CSV file uploaded yet.
-
- {% if report %} -
-

Import Report

-

{{ report }}

-
- {% endif %} -
-{% endblock %} diff --git a/py_app/app/templates/label_templates.html b/py_app/app/templates/label_templates.html deleted file mode 100644 index 0a167f4..0000000 --- a/py_app/app/templates/label_templates.html +++ /dev/null @@ -1,21 +0,0 @@ -{% extends "base.html" %} - -{% block title %}Label Templates{% endblock %} - -{% block content %} -
-
-

List of Label Templates

-
    - {% for template in templates %} -
  • - {{ template.name }} - - -
  • - {% endfor %} -
- -
-
-{% endblock %} \ No newline at end of file diff --git a/py_app/app/templates/main_page_etichete.html b/py_app/app/templates/main_page_etichete.html index 311e1fd..cdfd254 100644 --- a/py_app/app/templates/main_page_etichete.html +++ b/py_app/app/templates/main_page_etichete.html @@ -24,11 +24,6 @@ -
-

Manage Label Templates

-

Manage and configure label templates.

- Manage Templates -
{% endblock %} \ No newline at end of file