Skip to content

Commit

Permalink
add detail view
Browse files Browse the repository at this point in the history
  • Loading branch information
copelco committed Jan 10, 2025
1 parent ec92b7f commit 74c2f52
Show file tree
Hide file tree
Showing 9 changed files with 166 additions and 18 deletions.
2 changes: 1 addition & 1 deletion apps/odk_publish/nav.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class Link(BaseModel):
label: str
viewname: str
args: list[int | str] = None
args: list[int | str] | None = None
namespace: str = "odk_publish"

def __str__(self):
Expand Down
8 changes: 4 additions & 4 deletions apps/odk_publish/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ class FormTemplateTable(tables.Table):
verbose_name="Latest Version",
)
publish_next_version = tables.LinkColumn(
"odk_publish:form-template-publish-next-version",
"odk_publish:form-template-detail",
args=[tables.A("project_id"), tables.A("pk")],
text="Publish New Version",
text="View",
orderable=False,
verbose_name="Actions",
verbose_name="",
attrs={"a": {"class": "text-primary-600 hover:underline"}},
)

class Meta:
model = FormTemplate
fields = ["title_base", "form_id_base"]
template_name = "patterns/tables/table.html"
attrs = {"th": {"scope": "col", "class": "px-4 py-3 whitespace-nowrap "}}
attrs = {"th": {"scope": "col", "class": "px-4 py-3 whitespace-nowrap"}}
orderable = False
10 changes: 10 additions & 0 deletions apps/odk_publish/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@
views.form_template_list,
name="form-template-list",
),
path(
"<int:odk_project_pk>/form-templates/<int:form_template_id>/",
views.form_template_detail,
name="form-template-detail",
),
path(
"<int:odk_project_pk>/form-templates/<int:form_template_id>/publish/",
views.form_template_publish,
name="form-template-publish",
),
path(
"<int:odk_project_pk>/form-templates/<int:form_template_id>/publish-next-version/",
views.form_template_publish_next_version,
Expand Down
55 changes: 53 additions & 2 deletions apps/odk_publish/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django.db import models, transaction
from django.http import HttpRequest
from django.http import HttpRequest, HttpResponse
from django.shortcuts import get_object_or_404, redirect, render
from django.views.decorators.http import require_http_methods

from .etl.load import generate_and_save_app_user_collect_qrcodes
from .models import FormTemplateVersion, FormTemplate
Expand Down Expand Up @@ -57,12 +58,62 @@ def form_template_list(request: HttpRequest, odk_project_pk):
return render(request, "odk_publish/form_template_list.html", context)


@login_required
def form_template_detail(request: HttpRequest, odk_project_pk: int, form_template_id: int):
form_template: FormTemplate = get_object_or_404(
request.odk_project.form_templates.annotate(
app_user_count=models.Count("app_user_forms"),
).prefetch_related(
models.Prefetch(
"versions",
queryset=FormTemplateVersion.objects.order_by("-modified_at"),
to_attr="latest_version",
)
),
pk=form_template_id,
)
context = {
"form_template": form_template,
"form_template_app_users": form_template.app_user_forms.values_list(
"app_user__name", flat=True
),
"breadcrumbs": Breadcrumbs.from_items(
request=request,
items=[
("Form Templates", "form-template-list"),
(form_template.title_base, "form-template-detail", [form_template.pk]),
],
),
}
return render(request, "odk_publish/form_template_detail.html", context)


@login_required
def form_template_publish(request: HttpRequest, odk_project_pk: int, form_template_id: int):
form_template: FormTemplate = get_object_or_404(
request.odk_project.form_templates, pk=form_template_id
)
context = {
"form_template": form_template,
"breadcrumbs": Breadcrumbs.from_items(
request=request,
items=[
("Form Templates", "form-template-list"),
(form_template.title_base, "form-template-detail", [form_template.pk]),
("Publish", "form-template-publish", [form_template.pk]),
],
),
}
return render(request, "odk_publish/form_template_publish.html", context)


@login_required
@transaction.atomic
@require_http_methods(["POST"])
def form_template_publish_next_version(request: HttpRequest, odk_project_pk, form_template_id):
form_template: FormTemplate = get_object_or_404(
request.odk_project.form_templates, pk=form_template_id
)
version = form_template.create_next_version(user=request.user)
messages.add_message(request, messages.SUCCESS, f"{version} published.")
return redirect("odk_publish:form-template-list", odk_project_pk=odk_project_pk)
return HttpResponse(status=204)
12 changes: 3 additions & 9 deletions config/assets/styles/tailwind-entry.css
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,10 @@
.btn {
@apply font-medium text-center text-sm px-5 py-2.5 rounded-lg cursor-pointer;
}
.btn-primary {
@apply text-white bg-primary hover:bg-primary-500 focus:ring-4 focus:outline-none focus:ring-primary-300;
}
.btn-danger {
@apply text-danger-medium bg-white rounded-lg border border-danger-medium hover:bg-danger-medium hover:text-danger-medium focus:outline-none focus:ring-4 focus:ring-gray-200;
}
.btn-outline {
@apply text-primary bg-white border border-blue-900 hover:bg-primary-500 hover:text-white focus:ring-4 focus:outline-none focus:ring-primary-300;
@apply text-gray-900 focus:outline-none bg-white rounded-lg border border-gray-200 hover:bg-gray-100 hover:text-primary-700 focus:z-10 focus:ring-4 focus:ring-gray-200 dark:focus:ring-gray-700 dark:bg-gray-800 dark:text-gray-400 dark:border-gray-600 dark:hover:text-white dark:hover:bg-gray-700;
}
.btn-active {
@apply text-white bg-primary-500 border border-blue-900 hover:bg-primary-500 hover:text-white focus:ring-4 focus:outline-none focus:ring-primary-300;
.btn-primary {
@apply border-primary-400 bg-gradient-to-r from-primary-100 via-primary-200 to-primary-200 dark:bg-none;
}
}
9 changes: 8 additions & 1 deletion config/templates/includes/breadcrumbs.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,14 @@
viewBox="0 0 24 24">
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m9 5 7 7-7 7" />
</svg>
<span class="ms-1 text-sm font-medium text-gray-500 dark:text-gray-400 md:ms-2">{{ crumb.label }}</span>
{% if not forloop.last %}
<a href="{{ crumb.path }}"
class="ms-1 md:ms-2 text-sm font-medium text-gray-700 hover:text-primary-600 dark:text-gray-400 dark:hover:text-white">
{{ crumb.label }}
</a>
{% else %}
<span class="ms-1 md:ms-2 text-sm font-medium text-gray-400 dark:text-gray-600">{{ crumb.label }}</span>
{% endif %}
</div>
</li>
{% endfor %}
Expand Down
2 changes: 1 addition & 1 deletion config/templates/includes/navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
{% for tab in request.odk_project_tabs %}
<li class="block border-b dark:border-gray-700 md:inline md:border-b-0">
<a href="{{ tab.path }}"
class="block py-3 px-4 hover:text-primary-600 {% if request.path == tab.path %}border-b-2 text-primary-600 dark:text-primary-500 dark:border-primary-500 border-primary-600{% else %} text-gray-500 dark:text-gray-400 hover:border-b-2 dark:hover:text-primary-500 dark:hover:border-primary-500 hover:border-primary-400{% endif %}"
class="block py-3 px-4 hover:text-primary-600 {% if tab.path in request.path %}border-b-2 text-primary-600 dark:text-primary-500 dark:border-primary-500 border-primary-600{% else %} text-gray-500 dark:text-gray-400 hover:border-b-2 dark:hover:text-primary-500 dark:hover:border-primary-500 hover:border-primary-400{% endif %}"
aria-current="page">{{ tab.label }}</a>
</li>
{% endfor %}
Expand Down
79 changes: 79 additions & 0 deletions config/templates/odk_publish/form_template_detail.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{% extends "base.html" %}
{% block extra-css %}
<style>
.spinner {
display:none;
}
.htmx-request .spinner {
display:inline;
}
.htmx-request.spinner {
display:inline;
}
</style>
{% endblock extra-css %}
{% block content %}
<div class="grid gap-4 pr-4 mb-4 sm:mb-5 sm:grid-cols-3 sm:gap-6 md:gap-12">
<!-- Column -->
<div class="sm:col-span-2">
<div class="flex items-center">
<a href="{{ form_template.template_url }}"
target="_blank"
class="btn btn-outline">
<svg class="inline-flex items-center w-4.5 h-4.5 mr-1.5 -ml-1 -mt-0.5 text-gray-800 dark:text-white"
aria-hidden="true"
xmlns="http://www.w3.org/2000/svg"
width="20"
height="20"
fill="currentColor"
viewBox="0 0 24 24">
<path fill-rule="evenodd" d="M12.037 21.998a10.313 10.313 0 0 1-7.168-3.049 9.888 9.888 0 0 1-2.868-7.118 9.947 9.947 0 0 1 3.064-6.949A10.37 10.37 0 0 1 12.212 2h.176a9.935 9.935 0 0 1 6.614 2.564L16.457 6.88a6.187 6.187 0 0 0-4.131-1.566 6.9 6.9 0 0 0-4.794 1.913 6.618 6.618 0 0 0-2.045 4.657 6.608 6.608 0 0 0 1.882 4.723 6.891 6.891 0 0 0 4.725 2.07h.143c1.41.072 2.8-.354 3.917-1.2a5.77 5.77 0 0 0 2.172-3.41l.043-.117H12.22v-3.41h9.678c.075.617.109 1.238.1 1.859-.099 5.741-4.017 9.6-9.746 9.6l-.215-.002Z" clip-rule="evenodd" />
</svg>
Edit Template Spreadsheet
</a>
<a hx-post="{% url 'odk_publish:form-template-publish-next-version' request.odk_project.id form_template.id %}"
hx-indicator=".spinner"
class="btn btn-outline btn-primary ml-4">
<svg class="inline-flex items-center w-4.5 h-4.5 mr-1.5 -ml-1 -mt-0.5 text-gray-800 dark:text-white"
aria-hidden="true"
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
fill="none"
viewBox="0 0 24 24">
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 15v2a3 3 0 0 0 3 3h10a3 3 0 0 0 3-3v-2M12 4v12m0-12 4 4m-4-4L8 8" />
</svg>
Publish
<svg aria-hidden="true"
role="status"
class="spinner inline-flex items-center w-4.5 h-4.5 ml-1.5 -mr-1 -mt-0.5 me-3 text-gray-200 animate-spin dark:text-gray-600"
viewBox="0 0 100 101"
fill="none"
xmlns="http://www.w3.org/2000/svg">
<path d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z" fill="currentColor" />
<path d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z" fill="#1C64F2" />
</svg>
</a>
</div>
</div>
<!-- Column -->
<dl>
<dt class="mb-2 font-semibold leading-none text-gray-900 dark:text-white">Latest version</dt>
<dd class="mb-4 font-light text-gray-500 sm:mb-5 dark:text-gray-400">
{{ form_template.latest_version.0.version }}
</dd>
<dt class="mb-2 font-semibold leading-none text-gray-900 dark:text-white">Latest published by</dt>
<dd class="mb-4 font-light text-gray-500 sm:mb-5 dark:text-gray-400">
{{ form_template.latest_version.0.user.first_name }} {{ form_template.latest_version.0.user.last_name }}
</dd>
<dt class="mb-2 font-semibold leading-none text-gray-900 dark:text-white">XML Form ID</dt>
<dd class="mb-4 font-light text-gray-500 sm:mb-5 dark:text-gray-400">
{{ form_template.form_id_base }}
</dd>
<dt class="mb-2 font-semibold leading-none text-gray-900 dark:text-white">App Users</dt>
<dd class="mb-4 font-light text-gray-500 sm:mb-5 dark:text-gray-400">
{{ form_template_app_users | join:", " }}
</dd>
</dl>
</div>
{% endblock content %}
7 changes: 7 additions & 0 deletions config/templates/odk_publish/form_template_publish.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% extends "base.html" %}
{% load django_tables2 %}
{% block page_header %}
Publish next version of {{ form_template.title_base }}
{% endblock page_header %}
{% block content %}
{% endblock content %}

0 comments on commit 74c2f52

Please sign in to comment.