Skip to content

Commit

Permalink
add list support for comment fields (#1789, #2033)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkonie committed Nov 18, 2024
1 parent 37ecfc1 commit 5116290
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 8 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Added
- Study plugin override via ISA-Tab comments (#1885)
- Token auth support in study plugin IGV XML serving views (#1999, #2021)
- Support for newlines in altamISA error messages (#2033)
- Support for performer and contact field values as list (#1789, #2033)
- Support for comment, performer and contact field values as list (#1789, #2033)
- **Taskflowbackend**
- ``TaskflowAPI.raise_submit_api_exception()`` helper (#1847)

Expand Down
2 changes: 1 addition & 1 deletion docs_manual/source/sodar_release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Release for SODAR Core v1.0 upgrade, iRODS v4.3 upgrade and feature updates.
- Add study plugin override via ISA-Tab comments
- Add session control in Django settings and environment variables
- Add token-based iRODS/IGV basic auth support for OIDC users
- Add support for performer and contact field values as list
- Add support for comment, performer and contact field values as list
- Update minimum supported iRODS version to v4.3.3
- Update REST API versioning
- Update REST API views for OpenAPI support
Expand Down
3 changes: 3 additions & 0 deletions samplesheets/rendering.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,9 @@ def _add_annotation(self, ann, header, header_type, obj):
# TODO: TBD: Should these be added in this function at all?
if isinstance(ann, str):
val = ann
# Comment as a list
elif isinstance(ann, list):
val = ann
# Ontology reference(s) (altamISA v0.1+, SODAR v0.5.2+)
elif isinstance(ann['value'], dict) or (
isinstance(ann['value'], list)
Expand Down
63 changes: 59 additions & 4 deletions samplesheets/tests/test_views_ajax.py
Original file line number Diff line number Diff line change
Expand Up @@ -1315,6 +1315,10 @@ def setUp(self):
)
self.study = self.investigation.studies.first()
self.values = {'updated_cells': []}
self.url = reverse(
'samplesheets:ajax_edit_cell',
kwargs={'project': self.project.sodar_uuid},
)

def test_post_extract_label_string(self):
"""Test SheetCellEditAjaxView POST with extract label and string value"""
Expand All @@ -1337,17 +1341,68 @@ def test_post_extract_label_string(self):
)
with self.login(self.user):
response = self.client.post(
reverse(
'samplesheets:ajax_edit_cell',
kwargs={'project': self.project.sodar_uuid},
),
self.url,
json.dumps(self.values),
content_type='application/json',
)
self.assertEqual(response.status_code, 200)
obj.refresh_from_db()
self.assertEqual(obj.extract_label, label)

def test_post_comment_single(self):
"""Test POST with comment and single value"""
name = 'Replicate'
obj = GenericMaterial.objects.get(
study=self.study, name='0815-N1-Pro1-A-114'
)
self.assertEqual(obj.comments, {name: 'A'})
self.values['updated_cells'].append(
{
'uuid': str(obj.sodar_uuid),
'header_name': name,
'header_type': 'comments',
'obj_cls': 'GenericMaterial',
'value': 'B',
'uuid_ref': str(obj.sodar_uuid),
}
)
with self.login(self.user):
response = self.client.post(
self.url,
json.dumps(self.values),
content_type='application/json',
)
self.assertEqual(response.status_code, 200)
obj.refresh_from_db()
self.assertEqual(obj.comments, {name: 'B'})

def test_post_comment_list(self):
"""Test POST with comment and list value"""
name = 'Replicate'
obj = GenericMaterial.objects.get(
study=self.study, name='0815-N1-Pro1-A-114'
)
self.assertEqual(obj.comments, {name: 'A'})
self.values['updated_cells'].append(
{
'uuid': str(obj.sodar_uuid),
'header_name': name,
'header_type': 'comments',
'obj_cls': 'GenericMaterial',
'value': ['A', 'B'],
'uuid_ref': str(obj.sodar_uuid),
}
)
with self.login(self.user):
response = self.client.post(
self.url,
json.dumps(self.values),
content_type='application/json',
)
self.assertEqual(response.status_code, 200)
obj.refresh_from_db()
self.assertEqual(obj.comments, {name: ['A', 'B']})


class TestSheetRowInsertAjaxView(
RowEditMixin, SheetConfigMixin, SamplesheetsViewTestBase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,7 @@ export default Vue.extend({
if (!this.destroyCalled) {
this.destroyCalled = true // HACK for issue #869
// Convert to list value if applicable
if (this.editValue.includes(';') &&
this.headerInfo.header_type !== 'comments' && (
if (this.editValue.includes(';') && (
this.isValueArray || (
!['integer', 'double'].includes(this.editConfig.format) &&
!this.value.unit))) {
Expand Down

0 comments on commit 5116290

Please sign in to comment.