Skip to content
Snippets Groups Projects
Commit 4c533c3f authored by buczekp's avatar buczekp
Browse files

[LMS-2145] improved scripts (added actions for yeast parents, strip input)

SVN: 20392
parent aa9d500b
No related branches found
No related tags found
No related merge requests found
......@@ -227,7 +227,7 @@ def configureUI():
"""
Define and add actions with input fields used to:
1. specify attributes of new log entry,
1. specify attributes of new plasmid relationship,
"""
addAction = uiDescription.addTableAction(ADD_ACTION_LABEL)\
.setDescription('Add new plasmid relationship:')
......@@ -246,7 +246,7 @@ def configureUI():
addAction.addInputWidgets(widgets)
"""
2. modify attributes of a selected log entry,
2. modify attributes of a selected plasmid relationship,
"""
editAction = uiDescription.addTableAction(EDIT_ACTION_LABEL)\
.setDescription('Edit selected plasmid relationship:')
......@@ -269,7 +269,7 @@ def configureUI():
editAction.addBinding(ANNOTATION_LABEL, ANNOTATION_LABEL)
"""
3. delete selected log entries.
3. delete selected plasmid relationships.
"""
deleteAction = uiDescription.addTableAction(DELETE_ACTION_LABEL)\
.setDescription('Are you sure you want to delete selected plasmid relationships?')
......@@ -285,31 +285,32 @@ def updateFromUI(action):
"""Implement behaviour of user actions."""
if action.name == ADD_ACTION_LABEL:
"""
For 'add' action create new plasmid entry element with values from input fields
For 'add' action create new plasmid relationship element with values from input fields
and add it to existing elements.
"""
code = action.getInputValue(CODE_LABEL)
relationshipLabel = action.getInputValue(RELATIONSHIP_LABEL)
code = action.getInputValue(CODE_LABEL).strip()
relationshipLabel = action.getInputValue(RELATIONSHIP_LABEL).strip()
relationship = _translateFromLabel(relationshipLabel)
annotation = action.getInputValue(ANNOTATION_LABEL)
annotation = action.getInputValue(ANNOTATION_LABEL).strip()
sampleLink = _createSampleLink(code, relationship, annotation)
elements.append(sampleLink)
elif action.name == EDIT_ACTION_LABEL:
"""
For 'edit' action find the plasmid entry element corresponding to selected row
For 'edit' action find the plasmid relationship element corresponding to selected row
and replace it with an element with values from input fields.
"""
code = action.getInputValue(CODE_LABEL)
relationshipLabel = action.getInputValue(RELATIONSHIP_LABEL)
code = action.getInputValue(CODE_LABEL).strip()
relationshipLabel = action.getInputValue(RELATIONSHIP_LABEL).strip()
relationship = _translateFromLabel(relationshipLabel)
annotation = action.getInputValue(ANNOTATION_LABEL)
annotation = action.getInputValue(ANNOTATION_LABEL).strip()
sampleLink = _createSampleLink(code, relationship, annotation)
selectedRowId = action.getSelectedRows()[0]
elements[selectedRowId] = sampleLink
elif action.name == DELETE_ACTION_LABEL:
"""
For 'delete' action delete the entries that correspond to selected rows.
For 'delete' action delete the relationships that correspond to selected rows.
NOTE: As many rows can be deleted at once it is easier to delete them in reversed order.
"""
rowIds = list(action.getSelectedRows())
......
......@@ -16,6 +16,13 @@ ATR_CODE = "code"
LINK_LABEL = "link"
CODE_LABEL = "code"
"""action labels"""
ADD_ACTION_LABEL = "Add"
EDIT_ACTION_LABEL = "Edit"
DELETE_ACTION_LABEL = "Delete"
"""helper functions"""
def _createSampleLink(code):
"""
......@@ -68,5 +75,84 @@ def configureUI():
"""Specify that the property should be shown in a tab and set the table output."""
property.setOwnTab(True)
uiDesc = property.getUiDescription()
uiDesc.useTableOutput(tableBuilder.getTableModel())
\ No newline at end of file
uiDescription = property.getUiDescription()
uiDescription.useTableOutput(tableBuilder.getTableModel())
"""
Define and add actions with input fields used to:
1. specify attributes of new yeast parent,
"""
addAction = uiDescription.addTableAction(ADD_ACTION_LABEL)\
.setDescription('Add new plasmid relationship:')
widgets = [
inputWidgetFactory().createTextInputField(CODE_LABEL)\
.setMandatory(True)\
.setValue('FRY')\
.setDescription('Code of yeast parent sample, e.g. "FRY1"')
]
addAction.addInputWidgets(widgets)
"""
2. modify attributes of a selected yeast parent,
"""
editAction = uiDescription.addTableAction(EDIT_ACTION_LABEL)\
.setDescription('Edit selected plasmid relationship:')
# Exactly 1 row needs to be selected to enable action.
editAction.setRowSelectionRequiredSingle()
widgets = [
inputWidgetFactory().createTextInputField(CODE_LABEL)\
.setMandatory(True)\
.setDescription('Code of yeast parent sample, e.g. "FRY1"'),
]
editAction.addInputWidgets(widgets)
# Bind field name with column name.
editAction.addBinding(CODE_LABEL, CODE_LABEL)
"""
3. delete selected yeast parents.
"""
deleteAction = uiDescription.addTableAction(DELETE_ACTION_LABEL)\
.setDescription('Are you sure you want to delete selected yeast parent relationships?')
# Delete is enabled when at least 1 row is selected.
deleteAction.setRowSelectionRequired()
def updateFromUI(action):
"""Extract list of elements from old value of the property."""
converter = propertyConverter()
elements = list(converter.convertToElements(property))
"""Implement behaviour of user actions."""
if action.name == ADD_ACTION_LABEL:
"""
For 'add' action create new yeast parent element with values from input fields
and add it to existing elements.
"""
code = action.getInputValue(CODE_LABEL).strip()
sampleLink = _createSampleLink(code)
elements.append(sampleLink)
elif action.name == EDIT_ACTION_LABEL:
"""
For 'edit' action find the yeast parent element corresponding to selected row
and replace it with an element with values from input fields.
"""
code = action.getInputValue(CODE_LABEL).strip()
sampleLink = _createSampleLink(code)
selectedRowId = action.getSelectedRows()[0]
elements[selectedRowId] = sampleLink
elif action.name == DELETE_ACTION_LABEL:
"""
For 'delete' action delete yeast parents that correspond to selected rows.
NOTE: As many rows can be deleted at once it is easier to delete them in reversed order.
"""
rowIds = list(action.getSelectedRows())
rowIds.reverse()
for rowId in rowIds:
elements.pop(rowId)
else:
raise ValidationException('action not supported')
"""Update value of the managed property to XML string created from modified list of elements."""
property.value = converter.convertToString(elements)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment