diff --git a/.claude/settings.local.json b/.claude/settings.local.json index 6a368d3..524d740 100644 --- a/.claude/settings.local.json +++ b/.claude/settings.local.json @@ -3,7 +3,8 @@ "allow": [ "Bash(Get-ChildItem \"d:\\\\Projects\\\\LT_Janitorial_Quality_Control\\\\migrations\\\\versions\\\\\" -Name)", "PowerShell(Remove-Item \"d:\\\\Projects\\\\LT_Janitorial_Quality_Control\\\\app\\\\templates\\\\issues\\\\issues_view.html\" -Confirm:$false)", - "PowerShell(Remove-Item \"d:\\\\Projects\\\\LT_Janitorial_Quality_Control\\\\app\\\\templates\\\\issues\\\\issues_list.html\" -Confirm:$false)" + "PowerShell(Remove-Item \"d:\\\\Projects\\\\LT_Janitorial_Quality_Control\\\\app\\\\templates\\\\issues\\\\issues_list.html\" -Confirm:$false)", + "Bash(Get-ChildItem -Path \"d:\\\\Projects\\\\LT_Janitorial_Quality_Control\\\\app\\\\templates\\\\inspections\\\\\" -Name)" ] } } diff --git a/app/routes/inspections.py b/app/routes/inspections.py index e346c88..fe8d047 100644 --- a/app/routes/inspections.py +++ b/app/routes/inspections.py @@ -499,6 +499,33 @@ def save_draft_ajax(inspection_id): return jsonify({'ok': True}) +# ── AJAX: upload a single inspection photo ──────────────────────────────────── + +@bp.route('//upload-photo', methods=['POST']) +@login_required +def upload_photo_ajax(inspection_id): + inspection = db.session.get(Inspection, inspection_id) + if inspection is None: + return jsonify({'ok': False, 'error': 'Not found'}), 404 + + if current_user.role == 'inspector' and inspection.inspector_id != current_user.id: + return jsonify({'ok': False, 'error': 'Access denied'}), 403 + + if inspection.status == 'completed': + return jsonify({'ok': False, 'error': 'Inspection already completed'}), 400 + + file_obj = request.files.get('photo') + path = _save_photo(file_obj, subfolder='inspection_photos') + if not path: + return jsonify({'ok': False, 'error': 'Invalid file or unsupported format'}), 400 + + current_app.logger.info( + 'INSPECTION PHOTO UPLOADED (AJAX) | inspection_id=%s | path=%s | by=%s', + inspection_id, path, current_user.username + ) + return jsonify({'ok': True, 'path': path}) + + # ── View ────────────────────────────────────────────────────────────────────── @bp.route('/') diff --git a/app/templates/inspections/execute.html b/app/templates/inspections/execute.html index 93349db..958fe51 100644 --- a/app/templates/inspections/execute.html +++ b/app/templates/inspections/execute.html @@ -413,13 +413,17 @@ {% elif field.type == 'image' %} {# Single