diff --git a/myproject/myapp/templates/_base.html b/myproject/myapp/templates/_base.html index de172c29c435a0d1e8623b2330c7369567155cc8..0a3beef2a505a256e9249d6a27038129b14e0d06 100644 --- a/myproject/myapp/templates/_base.html +++ b/myproject/myapp/templates/_base.html @@ -9,6 +9,13 @@ {% compress css %} <link rel="stylesheet" href="{% static 'src/output.css' %}" /> {% endcompress %} + <style> + /* Ensure the modal body takes up all available space minus a margin, allowing for scrolling */ + .modal-body { + max-height: calc(100vh - 4rem); /* Adjust the 4rem to increase/decrease the top and bottom margin */ + overflow-y: auto; /* Enable vertical scrolling */ + } + </style> </head> <body> diff --git a/myproject/myapp/templates/user_page.html b/myproject/myapp/templates/user_page.html index dffc797078bc996353cbfb8d449b0a24c8708bda..5a36c2d6be558690fef22b8336c3614b7b55543f 100644 --- a/myproject/myapp/templates/user_page.html +++ b/myproject/myapp/templates/user_page.html @@ -206,12 +206,50 @@ class="font-medium text-blue-600 dark:text-blue-500 hover:underline" >{{entry.file}}</a > + {% if entry.description %} + <button + type="button" + class="ml-4 px-2 py-1 bg-blue-500 text-white rounded-md hover:bg-blue-600" + onclick="showModal('{{entry.description|join:'\n'}}')" + > + Show Results + </button> + {% endif %} </td> </tr> {%endfor%} </tbody> </table> </div> + +<!-- Modal --> +<div id="myModal" class="hidden fixed inset-0 flex items-center justify-center bg-black bg-opacity-50 z-50"> + <!-- Modal content with scrolling enabled --> + <div class="modal-body bg-white dark:bg-gray-800 rounded-lg p-4 md:p-6 w-full max-w-2xl"> + <h3 class="text-2xl font-bold mb-4">Predictions:</h3> + <ul id="predictionList" class="space-y-2"></ul> + <button onclick="closeModal()" class="mt-4 px-4 py-2 bg-red-500 text-white rounded-md hover:bg-red-600">Close</button> + </div> +</div> + +<script> +function showModal(predictions) { + var predictionList = document.getElementById('predictionList'); + predictionList.innerHTML = ''; + predictions.split('\n').forEach(function(prediction) { + var li = document.createElement('li'); + li.innerHTML = prediction; + li.className = 'bg-gray-100 dark:bg-gray-700 px-4 py-2 rounded-md'; + predictionList.appendChild(li); + }); + document.getElementById('myModal').classList.remove('hidden'); +} + +function closeModal() { + document.getElementById('myModal').classList.add('hidden'); +} +</script> + {% if 1 %} {% comment %} REPLACE WITH LOGIC TO CHECK PROPER USER {%endcomment %} {% if user_profile.user_type == 2 %} diff --git a/myproject/myapp/views.py b/myproject/myapp/views.py index 40b209f8e69fe66fa21e32fe37ccc974471ac001..b42e991bb1ee45c467616ea2ca3a360a4d405d24 100644 --- a/myproject/myapp/views.py +++ b/myproject/myapp/views.py @@ -66,10 +66,9 @@ def log_fileupload(request): data = json.loads(request.body) status = data.get('status') file = data.get('file') - description = data.get('description') if request.user.is_authenticated: - log_data = get_log_data(Action.UPLOAD_FILE, status, file, description) + log_data = get_log_data(Action.UPLOAD_FILE, status, file) create_log(request.user, log_data) return JsonResponse({'message': 'Log created successfully'}, status=201) @@ -113,7 +112,7 @@ def user_table(request): log = json.loads(row[2]) # Create a dictionary with the date, user, and JSON fields date = row[0].strftime('%Y-%m-%d %H:%M:%S') - entry = {'date': date, 'user': row[1], 'file': log['file'], 'action': log['action'], 'status': log['status']} + entry = {'date': date, 'user': row[1], 'file': log['file'], 'action': log['action'], 'status': log['status'], 'description': log['description']} data.append(entry) # Return the data as a JSON response @@ -183,6 +182,7 @@ def users(request): context['token_count'] = token_count context['user_profile'] = user_profile context['user'] = user + print(context['user_data']) return render(request, 'user_page.html', context) @@ -266,10 +266,6 @@ class InstrumentDetectionView(APIView): if serializer.is_valid(): audio_file = serializer.validated_data['audio_file'] - # Save the uploaded file temporarily - # with open('temp_audio.wav', 'wb') as f: - # f.write(audio_file.read()) - # Preprocess the audio file preprocessed_data = preprocess_audio_for_inference(audio_file)