diff --git a/dataedit/fixtures/topics.json b/dataedit/fixtures/topics.json new file mode 100644 index 000000000..8c2e2b858 --- /dev/null +++ b/dataedit/fixtures/topics.json @@ -0,0 +1,93 @@ +[ + { + "model": "dataedit.schema", + "pk": 2, + "fields": { + "name": "boundaries" + } + }, + { + "model": "dataedit.schema", + "pk": 3, + "fields": { + "name": "climate" + } + }, + { + "model": "dataedit.schema", + "pk": 4, + "fields": { + "name": "demand" + } + }, + { + "model": "dataedit.schema", + "pk": 5, + "fields": { + "name": "economy" + } + }, + { + "model": "dataedit.schema", + "pk": 6, + "fields": { + "name": "emission" + } + }, + { + "model": "dataedit.schema", + "pk": 7, + "fields": { + "name": "environment" + } + }, + { + "model": "dataedit.schema", + "pk": 8, + "fields": { + "name": "grid" + } + }, + { + "model": "dataedit.schema", + "pk": 9, + "fields": { + "name": "openstreetmap" + } + }, + { + "model": "dataedit.schema", + "pk": 10, + "fields": { + "name": "policy" + } + }, + { + "model": "dataedit.schema", + "pk": 11, + "fields": { + "name": "reference" + } + }, + { + "model": "dataedit.schema", + "pk": 12, + "fields": { + "name": "scenario" + } + }, + { + "model": "dataedit.schema", + "pk": 13, + "fields": { + "name": "society" + } + }, + { + "model": "dataedit.schema", + "pk": 14, + "fields": { + "name": "supply" + } + } +] \ No newline at end of file diff --git a/dataedit/management/commands/create_topics.py b/dataedit/management/commands/create_topics.py new file mode 100644 index 000000000..206d6622d --- /dev/null +++ b/dataedit/management/commands/create_topics.py @@ -0,0 +1,13 @@ +from django.core.management.base import BaseCommand +from django.core.management import call_command + + +class Command(BaseCommand): + help = "Seed the database with topics" + + def handle(self, *args, **options): + # Call the loaddata command to load the fixture + call_command("loaddata", "dataedit/fixtures/topics.json") + self.stdout.write( + self.style.SUCCESS("Successfully seeded the database with topics") + ) diff --git a/dataedit/migrations/0030_peerreview_is_publish.py b/dataedit/migrations/0030_peerreview_is_publish.py new file mode 100644 index 000000000..e768313e6 --- /dev/null +++ b/dataedit/migrations/0030_peerreview_is_publish.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.19 on 2023-12-04 12:22 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('dataedit', '0029_alter_peerreviewmanager_current_reviewer'), + ] + + operations = [ + migrations.AddField( + model_name='peerreview', + name='is_publish', + field=models.BooleanField(default=True), + ), + ] diff --git a/dataedit/migrations/0031_auto_20231204_1451.py b/dataedit/migrations/0031_auto_20231204_1451.py new file mode 100644 index 000000000..970f04d1b --- /dev/null +++ b/dataedit/migrations/0031_auto_20231204_1451.py @@ -0,0 +1,22 @@ +# Generated by Django 3.2.19 on 2023-12-04 13:51 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('dataedit', '0030_peerreview_is_publish'), + ] + + operations = [ + migrations.RemoveField( + model_name='peerreview', + name='is_publish', + ), + migrations.AddField( + model_name='table', + name='is_publish', + field=models.BooleanField(default=True), + ), + ] diff --git a/dataedit/migrations/0032_alter_table_is_publish.py b/dataedit/migrations/0032_alter_table_is_publish.py new file mode 100644 index 000000000..c8cfe672a --- /dev/null +++ b/dataedit/migrations/0032_alter_table_is_publish.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.22 on 2023-12-05 18:35 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('dataedit', '0031_auto_20231204_1451'), + ] + + operations = [ + migrations.AlterField( + model_name='table', + name='is_publish', + field=models.BooleanField(default=False), + ), + ] diff --git a/dataedit/models.py b/dataedit/models.py index 691d23f02..4309f85a9 100644 --- a/dataedit/models.py +++ b/dataedit/models.py @@ -67,6 +67,7 @@ class Table(Tagable): # due to oem string (json) parsing like when reading the oem form comment on table oemetadata = JSONField(null=True) is_reviewed = BooleanField(default=False, null=False) + is_publish = BooleanField(null=False, default=False) @classmethod def load(cls, schema, table): @@ -97,6 +98,22 @@ def set_is_reviewed(self): self.is_reviewed = True self.save() + # TODO: Use function when implementing the publish button + def set_is_published(self): + """ + Mark the table as published (ready for destination schema & public) and save the change to the database. + """ + self.is_publish = True + self.save() + + # TODO: Use function when implementing the publish button. It should be possible to unpublish a table. This button should be next to the tables listed in Published on the profile page. + def set_not_published(self): + """ + Mark the table as not published (making it a draft table again) and save the change to the database. + """ + self.is_publish = False + self.save() + class Meta: unique_together = (("name",),) diff --git a/dataedit/static/peer_review/opr_reviewer.js b/dataedit/static/peer_review/opr_reviewer.js index 49e072fc8..b1bba895e 100644 --- a/dataedit/static/peer_review/opr_reviewer.js +++ b/dataedit/static/peer_review/opr_reviewer.js @@ -140,6 +140,7 @@ function peerReview(config) { selectNextField(); renderSummaryPageFields(); updateTabProgressIndicatorClasses(); + // updatePercentageDisplay(); if (state_dict) { check_if_review_finished(); } @@ -527,6 +528,7 @@ function renderSummaryPageFields() { updateSummaryTable(); updateTabProgressIndicatorClasses(); + // updatePercentageDisplay(); } @@ -695,6 +697,7 @@ function saveEntrances() { renderSummaryPageFields(); updateTabProgressIndicatorClasses(); + // updatePercentageDisplay(); } function getFieldState(fieldKey) { @@ -870,7 +873,35 @@ function updateTabClasses() { } } } -window.addEventListener('DOMContentLoaded', updateTabClasses); +window.addEventListener('DOMContentLoaded', function() { + updateTabClasses(); + // updatePercentageDisplay() ; +}); + +function getTotalFieldCount() { + var allFields = makeFieldList(); + return allFields.length; +} + + +function calculateOkPercentage(stateDict) { + let totalCount = getTotalFieldCount(); + let okCount = 0; + + for (let key in stateDict) { + if (stateDict[key] === "ok") { + okCount++; + } + } + + let percentage = (okCount / totalCount) * 100; + return percentage.toFixed(2); +} + +function updatePercentageDisplay() { + document.getElementById("percentageDisplay").textContent = calculateOkPercentage(state_dict); +} + function updateTabProgressIndicatorClasses() { const tabNames = ['general', 'spatiotemporal', 'source', 'license', 'contributor', 'resource']; diff --git a/dataedit/views.py b/dataedit/views.py index 84dc0b66e..32306d218 100644 --- a/dataedit/views.py +++ b/dataedit/views.py @@ -73,7 +73,6 @@ schema_sandbox = "sandbox" - def admin_constraints(request): """ Way to apply changes @@ -285,7 +284,6 @@ def listschemas(request): # sort by name schemas = sorted(schemas, key=lambda x: x[0]) - return render( request, "dataedit/dataedit_schemalist.html", @@ -2149,7 +2147,6 @@ def get(self, request, schema, table, review_id=None): "table": table, "review_finished": review_finished, } - context_meta = { # need this here as json.dumps breaks the template syntax access # like {{ config.table }} now you can use {{ table }} diff --git a/login/static/peer_review/user_tables.js b/login/static/peer_review/user_tables.js new file mode 100644 index 000000000..e69de29bb diff --git a/login/templates/login/user_tables.html b/login/templates/login/user_tables.html index e815cd63d..90d4386fc 100644 --- a/login/templates/login/user_tables.html +++ b/login/templates/login/user_tables.html @@ -2,22 +2,76 @@ {% load django_bootstrap5 %} {% load static %} {% block main-content-body %} - {% if profile_user == request.user %} - {% include "login/user_nav.html" %} -
+
{% if profile_user.fullname %} {{ profile_user.fullname }} {% endif %} @@ -58,7 +112,7 @@ {{ profile_user.work }}
- {% endif %} + {% endif %}