diff --git a/krill/consumables/forms.py b/krill/consumables/forms.py
index ed0710a..5b3754a 100644
--- a/krill/consumables/forms.py
+++ b/krill/consumables/forms.py
@@ -3,6 +3,8 @@
from .models.consumable_type import ConsumableType
from .models.location import ConsumableRoom, ConsumableLocation
from .models.vendor import Vendor
+from sample.widgets import mark_comboboxes
+from sample.widgets import mark_comboboxes
class ConsumableForm(forms.ModelForm):
@@ -37,6 +39,12 @@ def __init__(self, *args, **kwargs):
self.fields['access_level'].required = False
self.fields['vendor'].required = False
self.fields['location'].required = False
+ # A location is named "Room / Name"; load the room with it instead of one query per option
+ self.fields['location'].queryset = ConsumableLocation.objects.select_related('room')
+ mark_comboboxes(self)
+ # A location is named "Room / Name"; load the room with it instead of one query per option
+ self.fields['location'].queryset = ConsumableLocation.objects.select_related('room')
+ mark_comboboxes(self)
ctype = self._resolve_type(args, kwargs)
self.spec_field_names = []
@@ -124,6 +132,14 @@ class Meta:
'icon': 'Material icon name (e.g. biotech, science)',
}
+ def __init__(self, *args, **kwargs):
+ super().__init__(*args, **kwargs)
+ mark_comboboxes(self)
+
+ def __init__(self, *args, **kwargs):
+ super().__init__(*args, **kwargs)
+ mark_comboboxes(self)
+
class VendorForm(forms.ModelForm):
class Meta:
@@ -164,3 +180,11 @@ class Meta:
'name': 'Location name (e.g. Cabinet B, Shelf 3)',
'kind': 'Type of storage location',
}
+
+ def __init__(self, *args, **kwargs):
+ super().__init__(*args, **kwargs)
+ mark_comboboxes(self)
+
+ def __init__(self, *args, **kwargs):
+ super().__init__(*args, **kwargs)
+ mark_comboboxes(self)
diff --git a/krill/sample/templatetags/sample_tags.py b/krill/sample/templatetags/sample_tags.py
index c2999fb..7544ff9 100644
--- a/krill/sample/templatetags/sample_tags.py
+++ b/krill/sample/templatetags/sample_tags.py
@@ -27,3 +27,34 @@ def is_samples_list_active(context):
if 'detail/sample/' in path:
return True
return False
+
+
+_IRREGULAR_SINGULARS = {'shelves': 'shelf'}
+
+
+@register.filter
+def singular(value):
+ """'Boxes' -> 'Box', 'Shelves' -> 'Shelf', 'Aliquot Types' -> 'Aliquot Type', 'Categories' -> 'Category'.
+
+ Only the last word changes. Chopping the final letter turns 'Boxes' into 'Boxe', so use this instead.
+ """
+ text = str(value or '').strip()
+ if not text:
+ return ''
+ head, _, word = text.rpartition(' ')
+ lower = word.lower()
+ if lower in _IRREGULAR_SINGULARS:
+ result = _IRREGULAR_SINGULARS[lower]
+ elif lower.endswith('ies') and len(lower) > 3:
+ result = lower[:-3] + 'y'
+ elif lower.endswith(('xes', 'ches', 'shes', 'sses', 'zes')):
+ result = lower[:-2]
+ elif lower.endswith('s') and not lower.endswith(('ss', 'us', 'is')):
+ result = lower[:-1]
+ else:
+ result = lower
+ if word.isupper() and len(word) > 1:
+ result = result.upper()
+ elif word[:1].isupper():
+ result = result.capitalize()
+ return f'{head} {result}' if head else result
diff --git a/krill/sample/tests/test_combobox.py b/krill/sample/tests/test_combobox.py
index ff427fc..a2f26b3 100644
--- a/krill/sample/tests/test_combobox.py
+++ b/krill/sample/tests/test_combobox.py
@@ -223,3 +223,10 @@ def test_the_layout_loads_the_script_and_the_file_exists(self):
def test_the_box_clearing_script_notifies_the_combobox(self):
html = self.client.get(reverse('sample:sample_create'), {'type': 'aliquot'}).content.decode()
self.assertIn("field.dispatchEvent(new Event('change'", html)
+
+ def test_the_text_box_takes_the_selects_classes_and_modals_do_not_clip_the_list(self):
+ source = open(finders.find('js/combobox.js')).read()
+ self.assertIn('var originalClasses = select.className;', source)
+ self.assertIn("input.className = ('combobox-input ' + originalClasses).trim();", source)
+ css = open(finders.find('style.css') or finders.find('krill/style.css')).read()
+ self.assertIn('.modal-body:has(.combobox)', css)
diff --git a/krill/static/krill/js/combobox.js b/krill/static/krill/js/combobox.js
index cf5cab5..fec2dd2 100644
--- a/krill/static/krill/js/combobox.js
+++ b/krill/static/krill/js/combobox.js
@@ -53,6 +53,7 @@
var searchUrl = select.getAttribute('data-search-url');
if (!searchUrl && select.options.length - 1 < MIN_OPTIONS) { return; }
select.dataset.comboboxReady = '1';
+ var originalClasses = select.className; // the text box takes the select's look (for example form-control)
var id = 'combobox-' + (++counter);
var wrapper = document.createElement('div');
@@ -66,7 +67,7 @@
var input = document.createElement('input');
input.type = 'text';
input.id = id + '-input';
- input.className = 'combobox-input';
+ input.className = ('combobox-input ' + originalClasses).trim();
input.autocomplete = 'off';
input.spellcheck = false;
input.disabled = select.disabled;
diff --git a/krill/static/krill/style.css b/krill/static/krill/style.css
index ec2f5cb..a744ffa 100644
--- a/krill/static/krill/style.css
+++ b/krill/static/krill/style.css
@@ -2677,6 +2677,12 @@ main table tbody tr:last-child td{
position: relative;
}
+/* A modal body scrolls and would clip the open list, so let it show in full */
+.modal-body:has(.combobox) {
+ max-height: none;
+ overflow: visible;
+}
+
/* Keep the real ', start)]
+ self.assertIn('data-combobox="1"', select)
+ self.assertIn(f'data-search-url="{reverse("sample:aliquot_options")}"', select)
+ self.assertEqual(select.count('