From 4794eb63392023162cc435de3d57bfc00520b9e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Frias?= Date: Thu, 4 Apr 2024 15:06:03 +0100 Subject: [PATCH 1/5] Add support to upload and visualize onboarding reports - New button on catalogue uploader to upload an onboarding report - normalization goal to place all uploads in the same page - New table that stores information about the onboarding upload files, including a reference to the raw file that was uploaded - New page on the uploader side to visualize the imported files(/OnboardingReport) - Adjust js to place the error/success messages in the last column of the table of the upload history --- .../uploader/file_handler/checks.py | 9 ++- dashboard_viewer/uploader/forms.py | 5 +- .../migrations/0014_onboardingreport.py | 26 +++++++ .../0015_onboardingreport_upload_date.py | 20 +++++ dashboard_viewer/uploader/models.py | 22 ++++++ .../uploader/static/js/uploader.js | 12 +-- .../uploader/templates/onboarding_report.html | 78 +++++++++++++++++++ .../templates/upload_achilles_results.html | 6 +- .../templates/upload_onboarding_report.html | 13 ++++ .../uploader/templates/uploader_base.html | 13 +++- dashboard_viewer/uploader/urls.py | 5 ++ dashboard_viewer/uploader/views.py | 65 ++++++++++++---- 12 files changed, 244 insertions(+), 30 deletions(-) create mode 100644 dashboard_viewer/uploader/migrations/0014_onboardingreport.py create mode 100644 dashboard_viewer/uploader/migrations/0015_onboardingreport_upload_date.py create mode 100644 dashboard_viewer/uploader/templates/onboarding_report.html create mode 100644 dashboard_viewer/uploader/templates/upload_onboarding_report.html diff --git a/dashboard_viewer/uploader/file_handler/checks.py b/dashboard_viewer/uploader/file_handler/checks.py index aa9e49d0..8a83fb95 100644 --- a/dashboard_viewer/uploader/file_handler/checks.py +++ b/dashboard_viewer/uploader/file_handler/checks.py @@ -270,8 +270,10 @@ def _get_upload_attr(analysis, stratum): def check_for_duplicated_files(uploaded_file, data_source_id): + #### Added For Checksum ########################## + try: - # Upload History only stores the succeded files + # Upload History only stores the succesded files pd = UploadHistory.objects.filter(data_source_id=data_source_id).latest() @@ -281,8 +283,8 @@ def check_for_duplicated_files(uploaded_file, data_source_id): .first() ) - if data_source_hash is not None and bool(pd.uploaded_file): - # Go to the path where success files are stored + if data_source_hash is not None: + # Go to the path where sucess filea are stored latest_file_path = os.path.join(settings.MEDIA_ROOT, pd.uploaded_file.path) @@ -315,6 +317,7 @@ def check_for_duplicated_files(uploaded_file, data_source_id): except UploadHistory.DoesNotExist: pass + #### Added For Checksum ########################## def upload_data_to_tmp_table(data_source_id, file_metadata, pending_upload): diff --git a/dashboard_viewer/uploader/forms.py b/dashboard_viewer/uploader/forms.py index 67daaee3..bfa7df06 100644 --- a/dashboard_viewer/uploader/forms.py +++ b/dashboard_viewer/uploader/forms.py @@ -33,4 +33,7 @@ class Meta(SourceForm.Meta): class AchillesResultsForm(forms.Form): - results_file = forms.FileField() + results_file = forms.FileField(required=False, label='Catalogue Export File') + +class OnboardingReportForm(forms.Form): + onboarding_results_file = forms.FileField(required=False, label='Onboarding Report file (Optional)') \ No newline at end of file diff --git a/dashboard_viewer/uploader/migrations/0014_onboardingreport.py b/dashboard_viewer/uploader/migrations/0014_onboardingreport.py new file mode 100644 index 00000000..685386ad --- /dev/null +++ b/dashboard_viewer/uploader/migrations/0014_onboardingreport.py @@ -0,0 +1,26 @@ +# Generated by Django 3.2.13 on 2024-03-27 12:05 + +from django.db import migrations, models +import django.db.models.deletion +import uploader.models + + +class Migration(migrations.Migration): + + dependencies = [ + ('uploader', '0013_auto_20210721_1715'), + ] + + operations = [ + migrations.CreateModel( + name='OnBoardingReport', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('uploaded_file', models.FileField(null=True, upload_to=uploader.models.onboarding_folder)), + ('data_source', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='uploader.datasource')), + ], + options={ + 'db_table': 'onboarding_report', + }, + ), + ] diff --git a/dashboard_viewer/uploader/migrations/0015_onboardingreport_upload_date.py b/dashboard_viewer/uploader/migrations/0015_onboardingreport_upload_date.py new file mode 100644 index 00000000..83021284 --- /dev/null +++ b/dashboard_viewer/uploader/migrations/0015_onboardingreport_upload_date.py @@ -0,0 +1,20 @@ +# Generated by Django 3.2.13 on 2024-03-28 12:35 + +from django.db import migrations, models +import django.utils.timezone + + +class Migration(migrations.Migration): + + dependencies = [ + ('uploader', '0014_onboardingreport'), + ] + + operations = [ + migrations.AddField( + model_name='onboardingreport', + name='upload_date', + field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now), + preserve_default=False, + ), + ] diff --git a/dashboard_viewer/uploader/models.py b/dashboard_viewer/uploader/models.py index fc247d35..149ecc2c 100644 --- a/dashboard_viewer/uploader/models.py +++ b/dashboard_viewer/uploader/models.py @@ -175,6 +175,15 @@ def success_data_source_directory(instance, filename): return datetime.datetime.now().strftime(file_path) +def onboarding_folder(instance, filename): + file_path = os.path.join( + settings.ACHILLES_RESULTS_STORAGE_PATH, + instance.data_source.hash, + "onboarding", + "%Y%m%d%H%M%S%f" + "".join(pathlib.Path(filename).suffixes), + ) + return datetime.datetime.now().strftime(file_path) + class UploadHistory(models.Model): """ @@ -266,3 +275,16 @@ class Meta: p25_value = models.FloatField(null=True) p75_value = models.FloatField(null=True) p90_value = models.FloatField(null=True) + +class OnboardingReport(models.Model): + class Meta: + db_table = "onboarding_report" + + data_source = models.ForeignKey(DataSource, on_delete=models.CASCADE) + upload_date = models.DateTimeField(auto_now_add=True) + uploaded_file = models.FileField( + null=True, upload_to=onboarding_folder + ) + + def get_status(self): + return "Done" \ No newline at end of file diff --git a/dashboard_viewer/uploader/static/js/uploader.js b/dashboard_viewer/uploader/static/js/uploader.js index cb0f8df5..f6ff00f5 100644 --- a/dashboard_viewer/uploader/static/js/uploader.js +++ b/dashboard_viewer/uploader/static/js/uploader.js @@ -26,8 +26,8 @@ document.addEventListener("DOMContentLoaded", () => { const tbody = tbodys[0]; for (const tr of tbody.children) { - const status_td = tr.children[5]; - + const status_td = tr.children[6]; + if (status_td.dataset.failed === "yes") { add_failure_message_popup(status_td, status_td.dataset.failureMsg); } @@ -37,10 +37,10 @@ document.addEventListener("DOMContentLoaded", () => { .then(r => r.json()) .then(r => { if (r.status === "Done") { - tr.children[1].innerText = r.data.r_package_version; - tr.children[2].innerText = r.data.generation_date; - tr.children[3].innerText = r.data.cdm_version; - tr.children[4].innerText = r.data.vocabulary_version; + tr.children[2].innerText = r.data.r_package_version; + tr.children[3].innerText = r.data.generation_date; + tr.children[4].innerText = r.data.cdm_version; + tr.children[5].innerText = r.data.vocabulary_version; update_upload_status(status_td, "Done", "fas fa-check", "status-done"); diff --git a/dashboard_viewer/uploader/templates/onboarding_report.html b/dashboard_viewer/uploader/templates/onboarding_report.html new file mode 100644 index 00000000..f6059e20 --- /dev/null +++ b/dashboard_viewer/uploader/templates/onboarding_report.html @@ -0,0 +1,78 @@ +{% extends 'base.html' %} +{% load static %} +{% load bootstrap4 %} +{% load markdownify %} + +{% block head_tail %} + {{ form.media.css }} + + + +{% endblock %} + + +{% block content %} +
+ {% include "header.html" %} + + {# Achilles resutls file form #} +
+
+

Data Source: {{ obj_data_source.name }}

+
+
+
+

Database type: {{ obj_data_source.database_type }}

+
+
+

Country: {{ obj_data_source.country }}

+
+
+

Release date: {{ obj_data_source.release_date }}

+
+
+ +
+

Onboarding Report

+
+ {% if body|length > 0 %} + + + + {% for header in headers %} + + {% endfor %} + + + + {% for list in body %} + + {% for el in list %} + + {% endfor %} + + {% endfor %} + +
{{ header }}
{{ el }}
+ {% else %} +

Onboarding report is not available.

+ {% endif %} +
+
+
+{% endblock %} +{% block body_before_bootstrap %} + +{% endblock %} \ No newline at end of file diff --git a/dashboard_viewer/uploader/templates/upload_achilles_results.html b/dashboard_viewer/uploader/templates/upload_achilles_results.html index ce14b80b..ce737e79 100644 --- a/dashboard_viewer/uploader/templates/upload_achilles_results.html +++ b/dashboard_viewer/uploader/templates/upload_achilles_results.html @@ -29,7 +29,7 @@

Upload new database characteristics

For more information see the CatalogueExport R-package - +
You can also upload an Onboarding Report {% endblock %} @@ -43,6 +43,7 @@

Upload history

+ @@ -52,8 +53,9 @@

Upload history

- {% for up_hi, status in upload_history %} + {% for up_hi, status, type in upload_history %} + diff --git a/dashboard_viewer/uploader/templates/upload_onboarding_report.html b/dashboard_viewer/uploader/templates/upload_onboarding_report.html new file mode 100644 index 00000000..72cfb028 --- /dev/null +++ b/dashboard_viewer/uploader/templates/upload_onboarding_report.html @@ -0,0 +1,13 @@ +{% extends "uploader_base.html" %} + +{% block onboarding_report %} +
+

Upload Onboarding Report

+ + For more information see the CatalogueExport R-package + + + + It is now also possible to add an Onboarding report. + +{% endblock %} \ No newline at end of file diff --git a/dashboard_viewer/uploader/templates/uploader_base.html b/dashboard_viewer/uploader/templates/uploader_base.html index 59f4e252..5d654a58 100644 --- a/dashboard_viewer/uploader/templates/uploader_base.html +++ b/dashboard_viewer/uploader/templates/uploader_base.html @@ -36,7 +36,18 @@ {% block title %}{% endblock %} - {% bootstrap_form form %} + {% if onboarding_form %} +
+
+ {% bootstrap_form form %} +
+
+ {% bootstrap_form onboarding_form %} +
+
+ {% else %} + {% bootstrap_form form %} + {% endif %} {% buttons %}
Type Upload Date R Package Version Generation Date
{{ type }} {{ up_hi.upload_date }} {% if up_hi.r_package_version %}{{ up_hi.r_package_version }}{% else %}--{% endif %} {% if up_hi.generation_date %}{{ up_hi.generation_date }}{% else %}--{% endif %}
+ {% for header in headers %} @@ -69,6 +70,7 @@

Onboarding Report

margin-right: auto; border-collapse : collapse; } + caption { caption-side:top; } table td, table th { max-width: 100px; diff --git a/dashboard_viewer/uploader/templates/upload_achilles_results.html b/dashboard_viewer/uploader/templates/upload_achilles_results.html index ce737e79..e6b873df 100644 --- a/dashboard_viewer/uploader/templates/upload_achilles_results.html +++ b/dashboard_viewer/uploader/templates/upload_achilles_results.html @@ -43,7 +43,9 @@

Upload history

{{ constance_config.CAPTION_ONBOARDING|markdownify }}
+ {% if constance_config.ALLOW_ONBOARDING_UPLOAD %} + {% endif %} @@ -55,7 +57,9 @@

Upload history

{% for up_hi, status, type in upload_history %} + {% if constance_config.ALLOW_ONBOARDING_UPLOAD %} + {% endif %} diff --git a/dashboard_viewer/uploader/templates/uploader_base.html b/dashboard_viewer/uploader/templates/uploader_base.html index 5d654a58..8efe3ffd 100644 --- a/dashboard_viewer/uploader/templates/uploader_base.html +++ b/dashboard_viewer/uploader/templates/uploader_base.html @@ -36,7 +36,7 @@ {% block title %}{% endblock %} - {% if onboarding_form %} + {% if constance_config.ALLOW_ONBOARDING_UPLOAD and onboarding_form %}
{% bootstrap_form form %} From dad15d39d8a9203ea86d401cebf92b7a19fe984d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Frias?= Date: Fri, 19 Apr 2024 18:12:11 +0100 Subject: [PATCH 4/5] Remove message of onboarding in uploader when config is not set to upload onboarding report, delete not needed file upload_onboarding_report.html --- .../uploader/templates/upload_achilles_results.html | 2 +- .../templates/upload_onboarding_report.html | 13 ------------- 2 files changed, 1 insertion(+), 14 deletions(-) delete mode 100644 dashboard_viewer/uploader/templates/upload_onboarding_report.html diff --git a/dashboard_viewer/uploader/templates/upload_achilles_results.html b/dashboard_viewer/uploader/templates/upload_achilles_results.html index e6b873df..6733e71b 100644 --- a/dashboard_viewer/uploader/templates/upload_achilles_results.html +++ b/dashboard_viewer/uploader/templates/upload_achilles_results.html @@ -29,7 +29,7 @@

Upload new database characteristics

For more information see the CatalogueExport R-package -
You can also upload an Onboarding Report + {%if constance_config.ALLOW_ONBOARDING_UPLOAD %}
You can also upload an Onboarding Report {% endif %} {% endblock %} diff --git a/dashboard_viewer/uploader/templates/upload_onboarding_report.html b/dashboard_viewer/uploader/templates/upload_onboarding_report.html deleted file mode 100644 index 72cfb028..00000000 --- a/dashboard_viewer/uploader/templates/upload_onboarding_report.html +++ /dev/null @@ -1,13 +0,0 @@ -{% extends "uploader_base.html" %} - -{% block onboarding_report %} -
-

Upload Onboarding Report

- - For more information see the CatalogueExport R-package - - - - It is now also possible to add an Onboarding report. - -{% endblock %} \ No newline at end of file From 2330255e3cc0918e0366081934e7800670c98332 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Frias?= Date: Mon, 22 Apr 2024 09:40:36 +0100 Subject: [PATCH 5/5] Verify onboarding config also when creating the upload button for achilles --- dashboard_viewer/uploader/forms.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/dashboard_viewer/uploader/forms.py b/dashboard_viewer/uploader/forms.py index bfa7df06..5cef36af 100644 --- a/dashboard_viewer/uploader/forms.py +++ b/dashboard_viewer/uploader/forms.py @@ -33,7 +33,10 @@ class Meta(SourceForm.Meta): class AchillesResultsForm(forms.Form): - results_file = forms.FileField(required=False, label='Catalogue Export File') + if constance.config.ALLOW_ONBOARDING_UPLOAD: + results_file = forms.FileField(required=False, label='Catalogue Export File') + else: + results_file = forms.FileField() class OnboardingReportForm(forms.Form): onboarding_results_file = forms.FileField(required=False, label='Onboarding Report file (Optional)') \ No newline at end of file
TypeUpload Date R Package Version Generation Date
{{ type }}{{ up_hi.upload_date }} {% if up_hi.r_package_version %}{{ up_hi.r_package_version }}{% else %}--{% endif %} {% if up_hi.generation_date %}{{ up_hi.generation_date }}{% else %}--{% endif %}