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 == request.user %} +{% include "login/user_nav.html" %} + +
+
+ +
+
+ + +
+
+ Access your data tables: Listed below are tables associated with you, either created by you or by a group you're part of, + which has permission to access the table. This simplifies resource identification and access. + Expect future enhancements for better data management through additional grouping and sorting options. +
+
+ Publish your complete & open peer reviewed data: The displayed categories indicate whether a table has been published and assigned + to a specific topic. The "model_draft" section is where you initially create and review your table. + Once data is uploaded to "model_draft," an open peer review assesses metadata and data quality, performed by a user other than the creator. + Following a successful review, you can publish your table by moving it to one of the suggested topics on the Open Energy Platform. + The "Publish" button becomes visible once all criteria for publishing are met. +
+
+
- {% endif %} +
+
+

Published

+
+
+ {% for table in published_tables %} +
+
+
+
{{ table.name }} - {{ table.schema }}
+ View Table +
+
+
+ {% endfor %} +
+
+ +

Draft

+
+
+ {% for table in draft_tables %} +
+
+
+
{{ table.name }} - {{ table.schema }}
+ View Table + {% if table.is_reviewed and not table.is_publish %} + + {% endif %} +
+
+
+ {% endfor %} +
+
+
+{% endif %} + + {% endblock %} +
{% block main-right-sidebar-content %} @@ -38,7 +92,7 @@

{{ profile_user.name }}

-

+

{% if profile_user.fullname %} {{ profile_user.fullname }} {% endif %} @@ -58,7 +112,7 @@ {{ profile_user.work }}

- {% endif %} + {% endif %}
{% if profile_user.location %}

@@ -67,7 +121,7 @@ {{ profile_user.location }}

- {% endif %} + {% endif %}
{% if profile_user.email %}

@@ -85,7 +139,7 @@ {{ profile_user.linkedin }} - {% endif %} + {% endif %}

{% if profile_user.facebook %} @@ -95,7 +149,7 @@ {{ profile_user.facebook }} - {% endif %} + {% endif %}

{% if profile_user.twitter %} @@ -105,7 +159,7 @@ {{ profile_user.twitter }} - {% endif %} + {% endif %}

@@ -118,8 +172,14 @@ - {% endif %} + {% endif %} - + {% endif %} {% endblock %} + + + + + + diff --git a/login/views.py b/login/views.py index fd1dedabd..ce5f73dd6 100644 --- a/login/views.py +++ b/login/views.py @@ -10,7 +10,8 @@ from django.views.generic.edit import DeleteView, UpdateView import login.models as models -from dataedit.models import PeerReviewManager, Table +from dataedit.models import PeerReviewManager, Table, PeerReview +from dataedit.views import schema_whitelist from .forms import ( ChangeEmailForm, @@ -26,33 +27,44 @@ class TablesView(View): def get(self, request, user_id): - """ - Load the user identified by user_id and is OAuth-token. - If latter does not exist yet, create one. - :param request: A HTTP-request object sent by the Django framework. - :param user_id: An user id - :return: Profile renderer - """ user = get_object_or_404(OepUser, pk=user_id) - - # get all tables and optimize query tables = Table.objects.all().select_related() - # get all tables the user got write perm on - user_tables = [ - table - for table in tables - if user.get_table_permission_level(table) >= models.WRITE_PERM - ] # WRITE_PERM = 4 - # prepare data for template - tables = [{"name": table.name, "schema": table.schema} for table in user_tables] - - # get name of schema form FK object + draft_tables = [] + published_tables = [] + for table in tables: - table["schema"] = table["schema"].name + if user.get_table_permission_level(table) >= models.WRITE_PERM: + table_data = { + "name": table.name, + "schema": table.schema.name, + "is_publish": table.is_publish, + "is_reviewed": table.is_reviewed + } + + # Определение категории таблицы + if table.is_reviewed: + if table.is_publish: + published_tables.append(table_data) + else: + draft_tables.append(table_data) + else: + draft_tables.append(table_data) + + context = { + "profile_user": user, + "draft_tables": draft_tables, + "published_tables": published_tables, + "schema_whitelist": schema_whitelist + } + + # TODO: Fix this is_ajax as it is outdated according to django documentation ... provide better api endpoint for http requests via HTMX + if request.is_ajax(): + return render(request, "login/user_tables.html", context) + return render(request, "login/user_tables.html", context) + + + - return render( - request, "login/user_tables.html", {"tables": tables, "profile_user": user} - ) class ReviewsView(View): diff --git a/versions/changelogs/current.md b/versions/changelogs/current.md index 6e8f4fc8e..d5b6cb93a 100644 --- a/versions/changelogs/current.md +++ b/versions/changelogs/current.md @@ -1,6 +1,7 @@ ### Changes - Update styling of comparison page [(#1477)](https://github.com/OpenEnergyPlatform/oeplatform/pull/1477) +- Improve the profile page for tables by improving the layout, adding descriptive text and introducing sections to categorize the tables into "draft" and "published" according to specific criteria. [(#1440)](https://github.com/OpenEnergyPlatform/oeplatform/pull/1440) ### Features