From 03237a72ca9573f4ac4fddadf6d502c0eb3e12a9 Mon Sep 17 00:00:00 2001 From: Wilson Gaturu Date: Tue, 17 Oct 2023 21:03:04 +0300 Subject: [PATCH] adds topic tree to taxonomy task detail view --- indigo_app/js/components/TaxonomyTOC.vue | 4 +- .../indigo_api/_task_filter_form.html | 11 + .../indigo_app/tasks/available_tasks.html | 190 +++++++++--------- .../indigo_app/tasks/tabbed_layout.html | 12 +- .../tasks/taxonomy_project_detail.html | 47 ----- .../tasks/taxonomy_task_detail.html | 57 ++++++ ...ject_list.html => taxonomy_task_list.html} | 12 +- indigo_app/urls.py | 4 +- indigo_app/views/tasks.py | 34 +++- 9 files changed, 203 insertions(+), 168 deletions(-) delete mode 100644 indigo_app/templates/indigo_app/tasks/taxonomy_project_detail.html create mode 100644 indigo_app/templates/indigo_app/tasks/taxonomy_task_detail.html rename indigo_app/templates/indigo_app/tasks/{taxonomy_project_list.html => taxonomy_task_list.html} (50%) diff --git a/indigo_app/js/components/TaxonomyTOC.vue b/indigo_app/js/components/TaxonomyTOC.vue index 9788e0eda1..afa3120195 100644 --- a/indigo_app/js/components/TaxonomyTOC.vue +++ b/indigo_app/js/components/TaxonomyTOC.vue @@ -20,7 +20,7 @@ export default { // Set expanded state of current item and its parents function formatItem (x) { const children = (x.children || []).map(y => formatItem(y)); - x.expanded = x.data.slug === current || children.some(y => y.expanded); + x.expanded = x.selected || x.data.slug === current || children.some(y => y.expanded); return x; } taxonomy.map(x => formatItem(x)); @@ -35,7 +35,7 @@ export default { toc[0].addEventListener('itemRendered', (e) => { const tocItem = e.target; if (!tocItem) return; - if (this.current === tocItem.item.data?.slug) { + if (tocItem.item.selected || this.current === tocItem.item.data?.slug) { tocItem.querySelector('.content__action__title').classList.add('active'); } }); diff --git a/indigo_app/templates/indigo_api/_task_filter_form.html b/indigo_app/templates/indigo_api/_task_filter_form.html index e9330f9ac6..d3aae37a17 100644 --- a/indigo_app/templates/indigo_api/_task_filter_form.html +++ b/indigo_app/templates/indigo_api/_task_filter_form.html @@ -66,6 +66,17 @@ {% endif %} + + {% if show_country %} +
+ +
+ {% endif %} {% if format %} diff --git a/indigo_app/templates/indigo_app/tasks/available_tasks.html b/indigo_app/templates/indigo_app/tasks/available_tasks.html index bc0f0b266d..37063ad251 100644 --- a/indigo_app/templates/indigo_app/tasks/available_tasks.html +++ b/indigo_app/templates/indigo_app/tasks/available_tasks.html @@ -7,120 +7,118 @@
-
-
-
-
- {{ taxonomy_toc|json_script:"taxonomy_toc" }} +
+
+
+
+ {{ taxonomy_toc|json_script:"taxonomy_toc" }} +
-
- -
- {% if priority_workflows %} -

{% trans "Priority projects" %}

- -
- {% for workflow in priority_workflows %} -
-
-
-
- {{ workflow.title }} - {% trans "Priority" %} -
+
+ {% if priority_workflows %} +

{% trans "Priority projects" %}

+
+ {% for workflow in priority_workflows %} +
+
+
+
+ {{ workflow.title }} + {% trans "Priority" %} +
-
- {{ workflow.country.name }}{% if workflow.locality %} › {{ workflow.locality.name }}{% endif %} - {% if workflow.due_date %} - {% trans "Due" %} {{ workflow.due_date|date:"Y-m-d" }} - {% if workflow.overdue %} - {% trans "Overdue" %} +
+ {{ workflow.country.name }}{% if workflow.locality %} › {{ workflow.locality.name }}{% endif %} + {% if workflow.due_date %} + {% trans "Due" %} {{ workflow.due_date|date:"Y-m-d" }} + {% if workflow.overdue %} + {% trans "Overdue" %} + {% endif %} {% endif %} - {% endif %} -
+
-
-
-
+
+
+
-
- {% for state, count, label in workflow.task_counts %} - {% if count %} -
- - {{ count }} {{ label }} -
- {% endif %} - {% endfor %} +
+ {% for state, count, label in workflow.task_counts %} + {% if count %} +
+ + {{ count }} {{ label }} +
+ {% endif %} + {% endfor %} +
-
- {% endfor %} -
- {% endif %} + {% endfor %} +
+ {% endif %} -

{% trans "Available tasks" %} {{ paginator.count }}

+

{% trans "Available tasks" %} {{ paginator.count }}

-
-
-
-
+
+
+ +
-
- - - +
+ + + +
+ +
- - + +
+ + {% if tasks %} + {% include 'indigo_api/_task_list.html' with tasks=tasks selectable=False place=True %} + {% else %} +
+

{% trans "No tasks found." %}

- + {% endif %}
- {% if tasks %} - {% include 'indigo_api/_task_list.html' with tasks=tasks selectable=False place=True %} - {% else %} -
-

{% trans "No tasks found." %}

-
+ {% if is_paginated %} + {% endif %}
- - {% if is_paginated %} - - {% endif %} -
{% endblock %} diff --git a/indigo_app/templates/indigo_app/tasks/tabbed_layout.html b/indigo_app/templates/indigo_app/tasks/tabbed_layout.html index ce5fa564ad..36735f643f 100644 --- a/indigo_app/templates/indigo_app/tasks/tabbed_layout.html +++ b/indigo_app/templates/indigo_app/tasks/tabbed_layout.html @@ -6,12 +6,6 @@ diff --git a/indigo_app/templates/indigo_app/tasks/taxonomy_project_detail.html b/indigo_app/templates/indigo_app/tasks/taxonomy_project_detail.html deleted file mode 100644 index 5af8cdc709..0000000000 --- a/indigo_app/templates/indigo_app/tasks/taxonomy_project_detail.html +++ /dev/null @@ -1,47 +0,0 @@ -{% extends "indigo_app/tasks/tabbed_layout.html" %} -{% load i18n %} - -{% block title %}{% trans "Projects" %}{% endblock %} - -{% block content %} -
-
-
{{ project.name }}
-
- -
-
-
-
- {% if project.description %} - {{ project.description|safe }} - {% endif %} -
-
-
-
-
-
-
-
-
- {% blocktrans trimmed with n_done=project.n_done count n_tasks=project.n_tasks %} - {{ n_done }} of {{ n_tasks }} task - {% plural %} - {{ n_done }} of {{ n_tasks }} tasks - {% endblocktrans %} -
-
- -
-
-
-
- {% include 'indigo_api/_task_filter_form.html' with form=form formats=False status=False %} -
- {% if tasks %} - {% include 'indigo_api/_task_cards.html' with task_groups=task_groups assign_button=False %} - {% endif %} -
-
-{% endblock %} diff --git a/indigo_app/templates/indigo_app/tasks/taxonomy_task_detail.html b/indigo_app/templates/indigo_app/tasks/taxonomy_task_detail.html new file mode 100644 index 0000000000..5056962dbb --- /dev/null +++ b/indigo_app/templates/indigo_app/tasks/taxonomy_task_detail.html @@ -0,0 +1,57 @@ +{% extends "indigo_app/tasks/tabbed_layout.html" %} +{% load i18n %} + +{% block title %}{% trans "Projects" %}{% endblock %} + +{% block content %} +
+
+
+
+
+
+ {{ taxonomy_toc|json_script:"taxonomy_toc" }} +
+
+
+
+
+
{{ topic.name }}
+
+
+
+
+
+ {% if topic.description %} + {{ topic.description|safe }} + {% endif %} +
+
+
+
+
+
+
+
+
+ {% blocktrans trimmed with n_done=topic.n_done count n_tasks=topic.n_tasks %} + {{ n_done }} of {{ n_tasks }} task + {% plural %} + {{ n_done }} of {{ n_tasks }} tasks + {% endblocktrans %} +
+
+
+
+
+
+ {% include 'indigo_api/_task_filter_form.html' with form=form show_country=True %} +
+ {% if tasks %} + {% include 'indigo_api/_task_cards.html' with task_groups=task_groups assign_button=False %} + {% endif %} +
+
+
+
+{% endblock %} diff --git a/indigo_app/templates/indigo_app/tasks/taxonomy_project_list.html b/indigo_app/templates/indigo_app/tasks/taxonomy_task_list.html similarity index 50% rename from indigo_app/templates/indigo_app/tasks/taxonomy_project_list.html rename to indigo_app/templates/indigo_app/tasks/taxonomy_task_list.html index 2d916cf828..e6e4c16215 100644 --- a/indigo_app/templates/indigo_app/tasks/taxonomy_project_list.html +++ b/indigo_app/templates/indigo_app/tasks/taxonomy_task_list.html @@ -5,11 +5,11 @@ {% block content %}
-
-
-
- {{ taxonomy_toc|json_script:"taxonomy_toc" }} -
-
+
+
+
+ {{ taxonomy_toc|json_script:"taxonomy_toc" }} +
+
{% endblock %} diff --git a/indigo_app/urls.py b/indigo_app/urls.py index 6f15bdf15b..10310629c9 100644 --- a/indigo_app/urls.py +++ b/indigo_app/urls.py @@ -87,8 +87,8 @@ path('documents//popup', documents.DocumentPopupView.as_view(), name='document_popup'), path('tasks/', tasks.UserTasksView.as_view(), name='my_tasks'), - path('tasks/project/', tasks.TaxonomyProjectListView.as_view(), name='taxonomy_project_list'), - path('tasks/project//', tasks.TaxonomyProjectDetailView.as_view(), name='taxonomy_project_detail'), + path('tasks/project/', tasks.TaxonomyTopicTaskListView.as_view(), name='taxonomy_task_list'), + path('tasks/project//', tasks.TaxonomyTopicTaskDetailView.as_view(), name='taxonomy_task_detail'), path('tasks/available/', tasks.AvailableTasksView.as_view(), name='available_tasks'), path('tasks/priority/', tasks.AvailableTasksView.as_view(priority=True, tab='priority_tasks'), name='priority_tasks'), diff --git a/indigo_app/views/tasks.py b/indigo_app/views/tasks.py index 70a9a2e4a8..708a11c94e 100644 --- a/indigo_app/views/tasks.py +++ b/indigo_app/views/tasks.py @@ -646,12 +646,12 @@ def post(self, request, *args, **kwargs): }) -class TaxonomyProjectListView(AbstractAuthedIndigoView, TemplateView): +class TaxonomyTopicTaskListView(AbstractAuthedIndigoView, TemplateView): authentication_required = True - template_name = 'indigo_app/tasks/taxonomy_project_list.html' - tab = 'projects' + template_name = 'indigo_app/tasks/taxonomy_task_list.html' + tab = 'topics' permission_required = ('indigo_api.view_task',) - context_object_name = 'projects' + context_object_name = 'topics' def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) @@ -662,7 +662,7 @@ def get_tree(self): tree = TaxonomyTopic.dump_bulk() def fix_up(item): item["title"] = item["data"]["name"] - item["href"] = reverse('taxonomy_project_detail', kwargs={'slug': item["data"]["slug"]}) + item["href"] = reverse('taxonomy_task_detail', kwargs={'slug': item["data"]["slug"]}) for kid in item.get("children", []): fix_up(kid) @@ -672,12 +672,12 @@ def fix_up(item): return tree -class TaxonomyProjectDetailView(AbstractAuthedIndigoView, DetailView): +class TaxonomyTopicTaskDetailView(AbstractAuthedIndigoView, DetailView): authentication_required = True - template_name = 'indigo_app/tasks/taxonomy_project_detail.html' - tab = 'projects' + template_name = 'indigo_app/tasks/taxonomy_task_detail.html' + tab = 'topics' permission_required = ('indigo_api.view_task',) - context_object_name = 'project' + context_object_name = 'topic' model = TaxonomyTopic slug_field = 'slug' slug_url_kwarg = 'slug' @@ -701,4 +701,20 @@ def get_context_data(self, **kwargs): context['form'] = self.form context['tasks'] = tasks = self.get_tasks() context['task_groups'] = Task.task_columns(['open', 'pending_review', 'assigned'], tasks) + context['taxonomy_toc'] = self.get_tree() return context + + def get_tree(self): + tree = TaxonomyTopic.dump_bulk() + + def fix_up(item): + item["title"] = item["data"]["name"] + item["href"] = reverse('taxonomy_task_detail', kwargs={'slug': item["data"]["slug"]}) + item["selected"] = item["data"]["slug"] == self.object.slug + for kid in item.get("children", []): + fix_up(kid) + + for item in tree: + fix_up(item) + + return tree