Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 5.2.3 on 2025-07-07 06:40
# Generated by Django 5.2.3 on 2025-07-07 09:53

from django.db import migrations, models

Expand Down
17 changes: 17 additions & 0 deletions src/genlab_bestilling/migrations/0022_sample_internal_note.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 5.2.3 on 2025-07-07 13:25

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("genlab_bestilling", "0021_order_is_prioritized_order_is_seen"),
]

operations = [
migrations.AddField(
model_name="sample",
name="internal_note",
field=models.TextField(blank=True, null=True),
),
]
3 changes: 3 additions & 0 deletions src/genlab_bestilling/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,9 @@ class Sample(models.Model):
species = models.ForeignKey(f"{an}.Species", on_delete=models.PROTECT)
year = models.IntegerField()
notes = models.TextField(null=True, blank=True)

# "Merknad" in the Excel sheet.
internal_note = models.TextField(null=True, blank=True)
pop_id = models.CharField(max_length=150, null=True, blank=True)
location = models.ForeignKey(
f"{an}.Location", on_delete=models.PROTECT, null=True, blank=True
Expand Down
7 changes: 6 additions & 1 deletion src/staff/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,14 @@ class CustomSampleTable(tables.Table):
default=False,
)

internal_note = tables.TemplateColumn(
template_name="staff/note_input_column.html", orderable=False
)

class Meta:
model = Sample
fields = ["checked", "genlab_id"] + list(base_fields)
fields = ["checked", "genlab_id", "internal_note"] + list(base_fields)
sequence = ["checked", "genlab_id"] + list(base_fields) + ["internal_note"]

return CustomSampleTable

Expand Down
7 changes: 7 additions & 0 deletions src/staff/templates/staff/note_input_column.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<textarea
id="internal_note-input-{{ record.pk }}"
class="internal_note-input w-52 px-2.5 py-1.5 text-sm border border-gray-300 rounded-lg resize-none placeholder:text-gray-400 placeholder:italic"
data-sample-id="{{ record.pk }}"
placeholder="Write a note..."
>{{ record.internal_note|default:'' }}
</textarea>
40 changes: 30 additions & 10 deletions src/staff/templates/staff/sample_lab.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,37 @@ <h3 class="text-4xl mb-5">{% block page-title %}{% if order %}{{ order }} - Samp

{% block body_javascript %}
<script>
document.addEventListener('DOMContentLoaded', function() {
document.addEventListener("DOMContentLoaded", function () {
const selectAll = document.getElementById('select-all-checkbox');
if(selectAll) {
selectAll.addEventListener('input', function() {
const checkboxes = document.querySelectorAll('input[type="checkbox"]');
checkboxes.forEach(cb => {
cb.checked = selectAll.checked;
})
const noteInputs = document.querySelectorAll('.internal_note-input');

selectAll?.addEventListener('change', function() {
const checkboxes = document.querySelectorAll('input[type="checkbox"]');
checkboxes.forEach((cb) => {
cb.checked = selectAll.checked;
})
});

let debounceTimeout;
noteInputs.forEach(function (noteInput) {
noteInput.addEventListener("input", function (event) {
const sampleId = event.target.dataset.sampleId;
const value = event.target.value;
const formData = new FormData();
formData.append("sample_id", sampleId);
formData.append("field_name", "internal_note-input");
formData.append("field_value", value);
formData.append("csrfmiddlewaretoken", "{{ csrf_token }}");

clearTimeout(debounceTimeout);
debounceTimeout = setTimeout(function () {
fetch("{% url 'staff:update-sample' %}", {
method: "POST",
body: formData
});
}, 500);
});
}
});
});
</script>

{% endblock body_javascript %}
{% endblock body_javascript%}
6 changes: 6 additions & 0 deletions src/staff/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
SampleLabView,
SampleReplicaActionView,
SamplesListView,
UpdateLabViewFields,
)

app_name = "staff"
Expand Down Expand Up @@ -93,6 +94,11 @@
GenerateGenlabIDsView.as_view(),
name="generate-genlab-ids",
),
path(
"orders/samples/update/",
UpdateLabViewFields.as_view(),
name="update-sample",
),
path(
"orders/analysis/<int:pk>/samples/",
OrderAnalysisSamplesListView.as_view(),
Expand Down
23 changes: 22 additions & 1 deletion src/staff/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from django.db import models
from django.db.models import Count
from django.forms import Form
from django.http import HttpRequest, HttpResponse, HttpResponseRedirect
from django.http import HttpRequest, HttpResponse, HttpResponseRedirect, JsonResponse
from django.shortcuts import get_object_or_404
from django.urls import reverse, reverse_lazy
from django.utils.timezone import now
Expand Down Expand Up @@ -377,6 +377,27 @@ def post(self, request: HttpRequest, *args, **kwargs) -> HttpResponse:
return HttpResponseRedirect(self.get_success_url())


class UpdateLabViewFields(StaffMixin, ActionView):
def post(self, request: HttpRequest, *args, **kwargs) -> JsonResponse:
sample_id = request.POST.get("sample_id")
field_name = request.POST.get("field_name")
field_value = request.POST.get("field_value")

if not sample_id or not field_name or field_value is None:
return JsonResponse({"error": "Invalid input"}, status=400)

try:
sample = Sample.objects.get(id=sample_id)

if field_name == "internal_note-input":
sample.internal_note = field_value
sample.save()

return JsonResponse({"success": True})
except Sample.DoesNotExist:
return JsonResponse({"error": "Sample not found"}, status=404)


class ManaullyCheckedOrderActionView(SingleObjectMixin, ActionView):
model = ExtractionOrder

Expand Down