Skip to content

Commit

Permalink
implement some ui
Browse files Browse the repository at this point in the history
  • Loading branch information
nicokant committed Jun 11, 2024
1 parent f9db248 commit 27123e5
Show file tree
Hide file tree
Showing 26 changed files with 569 additions and 52 deletions.
2 changes: 1 addition & 1 deletion src/apps/core/templates/core/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
{% block head_javascript %}
{% endblock head_javascript %}
</head>
<body class="flex h-screen overflow-hidden">
<body class="flex h-screen overflow-hidden bg-slate-50">
{% block body %}
<div class="relative flex flex-1 flex-col overflow-y-auto overflow-x-hidden">
{% include 'core/partials/navigation.html' %}
Expand Down
Empty file.
17 changes: 17 additions & 0 deletions src/apps/core/templatetags/core.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from django import template

register = template.Library()


@register.filter
def verbose_name(instance):
return instance._meta.verbose_name


@register.filter
def get_fields(instance, fields=None):
return (
(field, field.value_to_string(instance))
for field in instance._meta.fields
if not fields or field.name in fields.split(" ")
)
2 changes: 2 additions & 0 deletions src/config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,3 +349,5 @@
CORS_ALLOW_CREDENTIALS = True

TAILWIND_APP_NAME = "theme"

DJANGO_TABLES2_TEMPLATE = "django_tables2/tailwind.html"
42 changes: 41 additions & 1 deletion src/genlab_bestilling/forms.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,46 @@
from django import forms
from formset.collection import FormCollection
from formset.renderers.tailwind import FormRenderer
from formset.widgets import DualSortableSelector, Selectize

from .models import AnalysisOrder, EquimentOrderQuantity, EquipmentOrder, Sample
from .models import (
AnalysisOrder,
EquimentOrderQuantity,
EquipmentOrder,
Project,
Sample,
)


class ProjectForm(forms.ModelForm):
class Meta:
model = Project
fields = (
"number",
"name",
"area",
"species",
"sample_types",
"analysis_types",
"expected_total_samples",
# "analysis_timerange",
)
widgets = {
"area": Selectize(search_lookup="name_icontains"),
"species": DualSortableSelector(search_lookup="name_icontains"),
"sample_types": DualSortableSelector(search_lookup="name_icontains"),
"analysis_types": DualSortableSelector(search_lookup="name_icontains"),
}


class EquipmentForm(forms.ModelForm):
class Meta:
model = EquipmentOrder
fields = ("name", "use_guid", "species", "sample_types", "notes", "tags")
widgets = {
"species": DualSortableSelector(search_lookup="name_icontains"),
"sample_types": DualSortableSelector(search_lookup="name_icontains"),
}


class EquipmentOrderQuantityForm(forms.ModelForm):
Expand All @@ -17,6 +49,9 @@ class EquipmentOrderQuantityForm(forms.ModelForm):
class Meta:
model = EquimentOrderQuantity
fields = ("id", "equipment", "quantity")
widgets = {
"equipment": Selectize(search_lookup="name_icontains"),
}


class EquipmentQuantityCollection(FormCollection):
Expand Down Expand Up @@ -56,6 +91,11 @@ class Meta:
"markers",
"return_samples",
)
widgets = {
"species": DualSortableSelector(search_lookup="name_icontains"),
"sample_types": DualSortableSelector(search_lookup="name_icontains"),
"markers": DualSortableSelector(search_lookup="name_icontains"),
}


class SampleForm(forms.ModelForm):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Generated by Django 5.0.6 on 2024-06-11 06:20

import django.db.models.deletion
import taggit.managers
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("genlab_bestilling", "0003_alter_order_notes"),
(
"taggit",
"0006_rename_taggeditem_content_type_object_id_taggit_tagg_content_8fc721_idx",
),
]

operations = [
migrations.AlterField(
model_name="equimentorderquantity",
name="equipment",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="orders",
to="genlab_bestilling.equipmenttype",
),
),
migrations.AlterField(
model_name="equimentorderquantity",
name="order",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="equipments",
to="genlab_bestilling.equipmentorder",
),
),
migrations.AlterField(
model_name="order",
name="tags",
field=taggit.managers.TaggableManager(
blank=True,
help_text="A comma-separated list of tags.",
through="taggit.TaggedItem",
to="taggit.Tag",
verbose_name="Tags",
),
),
]
12 changes: 12 additions & 0 deletions src/genlab_bestilling/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ class Project(models.Model):
def __str__(self):
return self.name

def get_absolute_url(self):
return reverse(
"project-detail",
kwargs={"pk": self.pk},
)


class Order(PolymorphicModel):
name = models.CharField(null=True, blank=True)
Expand Down Expand Up @@ -133,6 +139,12 @@ class AnalysisOrder(Order):
markers = models.ManyToManyField("Marker", blank=True)
return_samples = models.BooleanField() # TODO: default?

def get_absolute_url(self):
return reverse(
"project-analysis-detail",
kwargs={"pk": self.pk, "project_id": self.project_id},
)


class Sample(models.Model):
order = models.ForeignKey("AnalysisOrder", on_delete=models.CASCADE)
Expand Down
31 changes: 29 additions & 2 deletions src/genlab_bestilling/tables.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,36 @@
import django_tables2 as tables

from .models import Order
from .models import Order, Project


class OrderTable(tables.Table):
polymorphic_ctype = tables.Column(verbose_name="Type")
name = tables.Column(linkify=True)

class Meta:
model = Order
fields = ("name", "species", "sample_types")
fields = ("name", "species", "sample_types", "polymorphic_ctype")

empty_text = "No Orders"

def render_polymorphic_ctype(self, value):
return value.name


class ProjectTable(tables.Table):
number = tables.Column(linkify=True)

class Meta:
model = Project
fields = (
"number",
"name",
"area",
"species",
"sample_types",
"analysis_types",
"expected_total_samples",
"analysis_timerange",
)

empty_text = "No Projects"
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{% extends "base.html" %}
{% load neapolitan %}
{% load i18n %}


{% block content %}

<h3 class="text-4xl mb-5">Order #{{ object.id }} - {{ object.name }}</h3>
<div class="flex gap-5 mb-5">
<a class="btn bg-primary" href="{% url 'project-order-list' project_id=project.id %}"><i class="fas fa-arrow-left"></i> back</a>
</div>

{% object-detail object=object %}


<h5 class="text-2xl mb-5">Samples</h5>

<div class="flex gap-5">
<a class="btn bg-primary" href="{% url 'project-analysis-update' project_id=object.project_id pk=object.id %}">Edit</a>
<button class="btn bg-secondary">Confirm Order</button>
</div>
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{% extends "base.html" %}
{% load core %}

{% block content %}
<h3 class="text-4xl mb-5">{% if object.id %}{{ object }}{% else %}Create {{ object|verbose_name }}{% endif %}</h3>

<div class="flex gap-5 mb-5">
{% if object.id %}
<a class="btn bg-primary" href="{% url 'project-analysis-detail' project_id=project.id pk=object.id %}"><i class="fas fa-arrow-left"></i> back</a>
{% else %}
<a class="btn bg-primary" href="{% url 'project-order-list' project_id=project.id %}"><i class="fas fa-arrow-left"></i> back</a>
{% endif %}
</div>
{% formset endpoint=request.path csrf_token=csrf_token form_collection=form_collection %}

{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,33 @@


{% block content %}

{% fragment as table_header %}
{% #table-cell header=True %}Equipment{% /table-cell %}
{% #table-cell header=True %}Unit{% /table-cell %}
{% #table-cell header=True %}Qty{% /table-cell %}
{% endfragment %}

<h3 class="text-3xl">Order #{{ object.id }} - {{ object.name }}</h3>
<h3 class="text-4xl mb-5">Order #{{ object.id }} - {{ object.name }}</h3>
<div class="flex gap-5 mb-5">
<a class="btn bg-primary" href="{% url 'project-order-list' project_id=project.id %}"><i class="fas fa-arrow-left"></i> back</a>
</div>

{% object-detail object=object %}


<h5 class="text-2xl">Equipment</h5>
<h5 class="text-2xl my-5">Equipment</h5>
{% #table headers=table_header %}
{% for oq in object.equipmentorderquantity_set.all %}
{% for oq in object.equipments.all %}
<tr>
{% #table-cell %}{{ oq.equipment }}{% /table-cell %}
{% #table-cell %}{{ oq.unit }}{% /table-cell %}
{% #table-cell %}{{ oq.quantity }}{% /table-cell %}
</tr>
{% endfor %}
{% /table %}

<div class="flex gap-10">
<button>Edit</button>
<button>Send Order</button>
<div class="flex gap-5 my-5">
<a class="btn bg-primary" href="{% url 'project-equipment-update' project_id=object.project_id pk=object.id %}">Edit</a>
<button class="btn bg-secondary">Confirm Order</button>
</div>
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{% extends "base.html" %}
{% load core %}

{% block content %}
<h3 class="text-4xl mb-5">{% if object.id %}{{ object }}{% else %}Create {{ object|verbose_name }}{% endif %}</h3>
<div class="flex gap-5 mb-5">
{% if object.id %}
<a class="btn bg-primary" href="{% url 'project-equipment-detail' project_id=project.id pk=object.id %}"><i class="fas fa-arrow-left"></i> back</a>
{% else %}
<a class="btn bg-primary" href="{% url 'project-order-list' project_id=project.id %}"><i class="fas fa-arrow-left"></i> back</a>
{% endif %} </div>
{% formset endpoint=request.path csrf_token=csrf_token form_collection=form_collection %}

{% endblock %}
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
{% extends "base.html" %}
{% load static %}
{% block content %}
<h3 class="text-2xl">{{ title }}</h3>
{% load core %}

{% load formsetify %}
{% block content %}
<h3 class="text-2xl">{% if object.id %}{{ object }}{% else %}Create {{ object|verbose_name }}{% endif %}</h3>

<django-formset endpoint="{{ request.path }}" csrf-token="{{ csrf_token }}">
{{ form_collection }}
<button type="button" df-click="disable -> submit -> proceed !~ scrollToError">Submit</button>
<button type="button" df-click="reset">Reset to initial</button>
</django-formset>
{% formset endpoint=request.path csrf_token=csrf_token form_collection=form_collection %}

<link href="{% static 'formset/css/collections.css' %}" rel="stylesheet">
<script type="module" src="{% static 'formset/js/django-formset.js' %}"></script>
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
{% load render_table from django_tables2 %}

{% block content %}
<h3 class="text-2xl">Orders relative to {{ project.name }} - {{project.number }}</h3>
<h3 class="text-4xl mb-5">Orders relative to {{ project.name }} - {{project.number }}</h3>
<div class="flex gap-5 mb-5">
<a class="btn bg-primary" href="{% url 'project-detail' pk=project.id %}"><i class="fas fa-arrow-left"></i> back</a>
<a class="btn bg-primary" href="{% url 'project-equipment-create' project_id=project.id %}"><i class="fas fa-plus"></i> Equipment order</a>
<a class="btn bg-primary" href="{% url 'project-analysis-create' project_id=project.id %}"><i class="fas fa-plus"></i> Analysis order</a>
</div>

{% render_table object_list %}
{% render_table table %}
{% endblock %}
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
{% extends "base.html" %}
{% load neapolitan %}
{% load core %}
{% load i18n %}

{% block content %}
<h3 class="text-2xl">{{ object.name }} - {{ object.number }}</h3>
<h3 class="text-4xl mb-5">{{ object.name }} - {{ object.number }}</h3>

{% object_detail object view.fields %}

<div class="flex">
<a href="{% url 'project-equipment-create' project_id=object.id %}"><i class="fas fa-plus"></i> {% translate 'Equipment order' %}</a>
{% object-detail object=object fields="name verified area expected_total_samples analysis_timerange" %}

<div class="flex gap-5 my-5">
<a class="btn bg-primary" href="{% url 'project-list' %}"><i class="fas fa-arrow-left"></i> back</a>
<a class="btn bg-primary" href="{% url 'project-update' pk=project.id %}"><i class="fas fa-edit"></i> Edit</a>
<a class="btn bg-primary" href="{% url 'project-order-list' project_id=project.id %}"><i class="fas fa-eye"></i> Orders</a>
<a class="btn bg-primary" href="{% url 'project-equipment-create' project_id=project.id %}"><i class="fas fa-plus"></i> Equipment order</a>
<a class="btn bg-primary" href="{% url 'project-analysis-create' project_id=project.id %}"><i class="fas fa-plus"></i> Analysis order</a>
</div>
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{% extends "base.html" %}
{% load core %}

{% block content %}
<h3 class="text-4xl mb-5">{% if object.id %}{{ object }}{% else %}Create {{ object|verbose_name }}{% endif %}</h3>
<div class="flex gap-5 mb-5">
{% if object.id %}
<a class="btn bg-primary" href="{% url 'project-detail' pk=object.id %}"><i class="fas fa-arrow-left"></i> back</a>
{% else %}
<a class="btn bg-primary" href="{% url 'project-list' %}"><i class="fas fa-arrow-left"></i> back</a>
{% endif %}
</div>
{% formset endpoint=request.path csrf_token=csrf_token form=form request=request %}

{% endblock %}
Loading

0 comments on commit 27123e5

Please sign in to comment.