-
Notifications
You must be signed in to change notification settings - Fork 1
Add urgent, new and assigned orders to dashboard #178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| {% load django_tables2 %} | ||
|
|
||
| <div class="rounded-md border bg-white p-4"> | ||
| <h4 class="text-2xl mb-4">{{ title }} ({{ count }})</h4> | ||
| {% render_table table %} | ||
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,82 +1,34 @@ | ||
| {% extends 'staff/base.html' %} | ||
|
|
||
| {% load i18n %} | ||
| {% load static %} | ||
| {% load tz %} | ||
|
|
||
| {% block head_javascript %} | ||
| <script type="module" src="{% static 'js/staff/dashboard.js' %}"></script> | ||
| {% endblock %} | ||
| {% load order_tags %} | ||
|
|
||
| {% block content %} | ||
| <div class="flex items-center mb-5 gap-2"> | ||
| <div class="flex items-center bg-white rounded-xl border"> | ||
| <a data-active="{% if not request.GET.area %}true{% endif %}" href="{% url 'staff:dashboard' %}" class="px-4 py-2 rounded-xl data-[active='true']:bg-blue-400/40">All</a> | ||
| {% for area in areas %} | ||
| <a data-active="{% if request.GET.area == area.pk|stringformat:'s' %}true{% endif %}" href="{% url 'staff:dashboard' %}?area={{ area.pk }}" class="px-4 py-2 rounded-xl data-[active='true']:bg-blue-400/40">{{ area.name }}</a> | ||
| {% endfor %} | ||
| </div> | ||
|
|
||
| <p class="flex items-center gap-2 ml-auto"> | ||
| <span>{{ now|date:'F j, Y' }}</span> | ||
| <span>|</span> | ||
| <span>Week {{ now|date:'W' }}</span> | ||
| </p> | ||
| </div> | ||
|
|
||
| {% if delivered_orders|length > 0 %} | ||
| <div class="rounded-md border bg-white p-4"> | ||
| <p class="text-2xl mb-4">Delivered Orders</p> | ||
|
|
||
| {% for order in delivered_orders %} | ||
| {% if order.polymorphic_ctype.model == 'analysisorder' %} | ||
| <a class="hover:underline" href="{% url 'staff:order-analysis-detail' order.pk %}"><p>{{ order }} - {{ order.name }}</p></a> | ||
| {% elif order.polymorphic_ctype.model == 'equipmentorder' %} | ||
| <a class="hover:underline" href="{% url 'staff:order-equipment-detail' order.pk %}"><p>{{ order }} - {{ order.name }}</p></a> | ||
| {% elif order.polymorphic_ctype.model == 'extractionorder' %} | ||
| <a class="hover:underline" href="{% url 'staff:order-extraction-detail' order.pk %}"><p>{{ order }} - {{ order.name }}</p></a> | ||
| {% else %} | ||
| <p>{{ order }} - {{ order.name }}</p> | ||
| {% endif %} | ||
| {% endfor %} | ||
| <div class="grid grid-cols-2 gap-4"> | ||
| <div class="flex flex-col gap-8"> | ||
| {% urgent_orders_table area=area %} | ||
| {% new_orders_table area=area %} | ||
| </div> | ||
| {% endif %} | ||
|
|
||
| {% if urgent_orders|length > 0 %} | ||
| <div class="rounded-md border bg-white p-4"> | ||
| <h4 class="text-2xl mb-4">Urgent orders</h4> | ||
|
|
||
| {% for order in urgent_orders %} | ||
| {% if order.polymorphic_ctype.model == 'analysisorder' %} | ||
| <a class="hover:underline" href="{% url 'staff:order-analysis-detail' order.pk %}"><p>{{ order }} - {{ order.name }} - Deadline: {{ order.expected_delivery_date|default:'-' }} - Status: {{ order.status|default:'-' }}</p></a> | ||
| {% elif order.polymorphic_ctype.model == 'equipmentorder' %} | ||
| <a class="hover:underline" href="{% url 'staff:order-equipment-detail' order.pk %}"><p>{{ order }} - {{ order.name }} - Deadline: {{ order.expected_delivery_date|default:'-' }} - Status: {{ order.status|default:'-' }}</p></a> | ||
| {% elif order.polymorphic_ctype.model == 'extractionorder' %} | ||
| <a class="hover:underline" href="{% url 'staff:order-extraction-detail' order.pk %}"><p>{{ order }} - {{ order.name }} - Deadline: {{ order.expected_delivery_date|default:'-' }} - Status: {{ order.status|default:'-' }}</p></a> | ||
| {% else %} | ||
| <p>{{ order }} - {{ order.name }}</p> | ||
| {% endif %} | ||
| {% endfor %} | ||
| </div> | ||
| {% else %} | ||
| <div class="rounded-md border bg-white p-4"> | ||
| <h4 class="text-2xl mb-4">Urgent orders</h4> | ||
| <p>No urgent orders found.</p> | ||
| </div> | ||
| {% endif %} | ||
|
|
||
| {% if assigned_orders|length > 0 %} | ||
| <div class="rounded-md border bg-white p-4"> | ||
| <h4 class="text-2xl mb-4">My orders ({{ assigned_orders|length }})</h4> | ||
|
|
||
| {% for order in assigned_orders %} | ||
| {% if order.polymorphic_ctype.model == 'analysisorder' %} | ||
| <a class="hover:underline" href="{% url 'staff:order-analysis-detail' order.pk %}"><p>{{ order }} - {{ order.name }}</p></a> | ||
| {% elif order.polymorphic_ctype.model == 'equipmentorder' %} | ||
| <a class="hover:underline" href="{% url 'staff:order-equipment-detail' order.pk %}"><p>{{ order }} - {{ order.name }}</p></a> | ||
| {% elif order.polymorphic_ctype.model == 'extractionorder' %} | ||
| <a class="hover:underline" href="{% url 'staff:order-extraction-detail' order.pk %}"><p>{{ order }} - {{ order.name }}</p></a> | ||
| {% else %} | ||
| <p>{{ order }} - {{ order.name }}</p> | ||
| {% endif %} | ||
| {% endfor %} | ||
| <div class="flex flex-col gap-8"> | ||
| {% assigned_orders_table %} | ||
| </div> | ||
| {% else %} | ||
| <div class="rounded-md border bg-white p-4"> | ||
| <h4 class="text-2xl mb-4">Assigned orders</h4> | ||
| <p>No assigned orders found.</p> | ||
| </div> | ||
| {% endif %} | ||
| </div> | ||
| {% endblock %} |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| from django import template | ||
| from django.db import models | ||
|
|
||
| from genlab_bestilling.models import Area, Order | ||
|
|
||
| from ..tables import AssignedOrderTable, NewOrderTable, UrgentOrderTable | ||
|
|
||
| register = template.Library() | ||
|
|
||
|
|
||
| @register.inclusion_tag("staff/components/order_table.html", takes_context=True) | ||
| def urgent_orders_table(context: dict, area: Area | None = None) -> dict: | ||
| urgent_orders = Order.objects.filter( | ||
| is_urgent=True, | ||
| status__in=[Order.OrderStatus.PROCESSING, Order.OrderStatus.DELIVERED], | ||
| ).select_related("genrequest") | ||
|
|
||
| if area: | ||
| urgent_orders = urgent_orders.filter(genrequest__area=area) | ||
|
|
||
| urgent_orders = urgent_orders.only( | ||
| "id", "genrequest__name", "genrequest__expected_samples_delivery_date", "status" | ||
| ).order_by( | ||
| models.Case( | ||
| models.When(status=Order.OrderStatus.PROCESSING, then=0), | ||
| models.When(status=Order.OrderStatus.DELIVERED, then=1), | ||
| models.When(status=Order.OrderStatus.COMPLETED, then=2), | ||
| default=3, | ||
| output_field=models.IntegerField(), | ||
| ), | ||
| "-created_at", | ||
| ) | ||
|
|
||
| return { | ||
| "title": "Urgent orders", | ||
| "table": UrgentOrderTable(urgent_orders), | ||
| "count": urgent_orders.count(), | ||
| "request": context.get("request"), | ||
| } | ||
|
|
||
|
|
||
| @register.inclusion_tag("staff/components/order_table.html", takes_context=True) | ||
| def new_orders_table(context: dict, area: Area | None = None) -> dict: | ||
| new_orders = ( | ||
| Order.objects.filter(status=Order.OrderStatus.DELIVERED) | ||
| .select_related("genrequest") | ||
| .annotate(sample_count=models.Count("extractionorder__samples")) | ||
| .only( | ||
| "id", | ||
| "genrequest__name", | ||
| "genrequest__expected_samples_delivery_date", | ||
| "status", | ||
| ) | ||
| .order_by("status") | ||
| ) | ||
aastabk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if area: | ||
| new_orders = new_orders.filter(genrequest__area=area) | ||
|
|
||
| new_orders = new_orders.order_by("-created_at") | ||
|
|
||
| return { | ||
| "title": "New orders", | ||
| "table": NewOrderTable(new_orders), | ||
| "count": new_orders.count(), | ||
| "request": context.get("request"), | ||
| } | ||
|
|
||
|
|
||
| @register.inclusion_tag("staff/components/order_table.html", takes_context=True) | ||
| def assigned_orders_table(context: dict) -> dict: | ||
| assigned_orders = ( | ||
| Order.objects.filter( | ||
| status__in=[ | ||
| Order.OrderStatus.PROCESSING, | ||
| Order.OrderStatus.DELIVERED, | ||
| Order.OrderStatus.COMPLETED, | ||
| ] | ||
| ) | ||
| .select_related("genrequest") | ||
| .annotate( | ||
| sample_count=models.Count("extractionorder__samples"), | ||
| ) | ||
| .only( | ||
| "id", | ||
| "genrequest__name", | ||
| "genrequest__expected_samples_delivery_date", | ||
| "status", | ||
| ) | ||
| .order_by( | ||
| models.Case( | ||
| models.When(status=Order.OrderStatus.PROCESSING, then=0), | ||
| models.When(status=Order.OrderStatus.DELIVERED, then=1), | ||
| models.When(status=Order.OrderStatus.COMPLETED, then=2), | ||
| default=3, | ||
| output_field=models.IntegerField(), | ||
| ), | ||
| "-created_at", | ||
| ) | ||
| ) | ||
|
|
||
| return { | ||
| "title": "My orders", | ||
| "table": AssignedOrderTable(assigned_orders), | ||
| "count": assigned_orders.count(), | ||
| "request": context.get("request"), | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.