Skip to content

Commit

Permalink
fix sheet editor row insert process name handling (wip) (#1904)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkonie committed Mar 7, 2024
1 parent 5b9c817 commit 15c1486
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 42 deletions.
52 changes: 30 additions & 22 deletions samplesheets/vueapp/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,11 @@ export default {
newInit = false
value.newInit = false
processActive = true
// TODO: Update named process if suffix is auto-filled?
// TODO: Or, disable name suffix autofill from process names?
// TODO: (Is that kind of "auto-pooling" even a thing?)
rowNode.setDataValue(nextColId, value)
console.debug('newInit=false')
} else value.value = '' // HACK: Reset default value if not filled
value.editable = true // Process name should always be editable
} else {
Expand All @@ -859,14 +864,13 @@ export default {
},
handleNodeUpdate (
firstCellValue, column, rowNode, gridOptions, gridUuid, createNew
nameCellValue, column, rowNode, gridOptions, gridUuid, createNew
) {
// console.log('handleNodeUpdate() called; colId=' + column.colId) // DEBUG
const gridApi = gridOptions.api
const columnApi = gridOptions.columnApi
const firstColId = column.colId // ID of the identifying node column
const nameColId = column.colId // ID of the identifying node column
let assayMode = false
if (gridUuid in this.sodarContext.studies[this.currentStudyUuid].assays) {
assayMode = true
}
Expand All @@ -878,23 +882,22 @@ export default {
const studyCols = studyOptions.columnApi.getColumns()
let studyCopyRow = null
const sampleColId = this.sampleColId
// Get sample row from study table
studyApi.forEachNode(function (rowNode) {
if (!studyCopyRow &&
rowNode.data[sampleColId].uuid === firstCellValue.uuid_ref) {
rowNode.data[sampleColId].uuid === nameCellValue.uuid_ref) {
studyCopyRow = rowNode
}
})
// Fill in preceeding nodes
// Fill in preceeding nodes for sample
for (let i = 1; i < this.sampleIdx; i++) {
// TODO: Create a generic helper for copying
const copyColId = studyCols[i].colId
const copyData = Object.assign(studyCopyRow.data[copyColId])
copyData.newRow = true
copyData.newInit = false
copyData.editable = columnApi.getColumn(copyColId).colDef.cellRendererParams.fieldEditable
copyData.editable = columnApi.getColumn(
copyColId).colDef.cellRendererParams.fieldEditable
rowNode.setDataValue(copyColId, copyData)
}
}
Expand All @@ -908,55 +911,64 @@ export default {
let groupId = parent.groupId
if (groupId === '1' && this.sourceColSpan > 1) groupId = '2'
let startIdx
for (let i = 1; i < cols.length - 1; i++) {
if (cols[i].colId === firstColId) {
if (cols[i].colId === nameColId) {
startIdx = i + 1
break
}
}
for (let i = startIdx; i < cols.length - 1; i++) {
const col = cols[i]
// NOTE: Must use originalParent to work with hidden columns
if (col.originalParent.groupId === groupId) {
nodeCols.push(col)
} else if (col.colId !== firstColId &&
} else if (col.colId !== nameColId &&
col.originalParent.groupId !== groupId) {
nextNodeStartIdx = i
break
}
}
// IF node is new THEN fill out other cells with default/empty values
// If the node is new, fill out other cells with default/empty values
if (createNew) {
for (let i = 0; i < nodeCols.length; i++) {
const newColId = nodeCols[i].colId
const value = this.getDefaultValue(nodeCols[i].colId, gridOptions)
rowNode.setDataValue(newColId, value)
}
} else { // ELSE set UUIDs and update cell values (only in the same table)
} else { // Else set UUIDs and update cell values (only in the same table)
let copyRowNode = null
gridApi.forEachNode(function (rowNode) {
if (!copyRowNode && rowNode.data[firstColId].value === firstCellValue.value) {
if (!copyRowNode &&
rowNode.data[nameColId].value === nameCellValue.value) {
copyRowNode = rowNode
}
})
for (let i = 0; i < nodeCols.length; i++) {
const copyColId = nodeCols[i].colId
const copyData = Object.assign(copyRowNode.data[copyColId])
copyData.newInit = false
copyData.editable = columnApi.getColumn(copyColId).colDef.cellRendererParams.fieldEditable
copyData.editable = columnApi.getColumn(
copyColId).colDef.cellRendererParams.fieldEditable
rowNode.setDataValue(copyColId, copyData)
}
}
// When updating protocol name column, update preceeding protocol UUID
if (startIdx > 2) {
const headerType = column.colDef.cellEditorParams.headerInfo.header_type
const prevCol = cols[startIdx - 2]
const prevHeaderType = prevCol.colDef.cellEditorParams.headerInfo.header_type
if (headerType === 'process_name' &&
prevHeaderType === 'protocol' &&
cols[startIdx - 2].originalParent.groupId === groupId) {
rowNode.data[prevCol.colId].uuid = rowNode.data[nameColId].uuid
}
}
// Enable the next node(s), if we are initializing node for the 1st time
if (nextNodeStartIdx) {
this.enableNextNodes(rowNode, gridOptions, gridUuid, nextNodeStartIdx)
}
// Redraw row node for all changes to be displayed
gridApi.redrawRows({ rows: [rowNode] })
},
Expand Down Expand Up @@ -1031,7 +1043,6 @@ export default {
if (this.sourceColSpan > 1) lastSourceGroupIdx = 2 // 2nd source group
const lastSourceGroupId = cols[lastSourceGroupIdx].originalParent.groupId
let groupId = cols[1].originalParent.groupId
// Modify starting index and group id for assay table updating
if (assayMode) {
startIdx = this.sampleIdx
Expand All @@ -1046,13 +1057,11 @@ export default {
value.newInit = false
value.editable = cols[i].colDef.cellRendererParams.fieldEditable
rowNode.setDataValue(cols[i].colId, value)
// Save sample info if new sample was added in study
if (!assayMode && cols[i].colId === this.sampleColId) {
sampleUuid = data.node_uuids[nodeIdx]
sampleName = rowNode.data[cols[i].colId].value
}
if (i < cols.length - 2 &&
groupId !== cols[i + 1].originalParent.groupId &&
cols[i + 1].originalParent.groupId !== lastSourceGroupId) {
Expand Down Expand Up @@ -1090,7 +1099,6 @@ export default {
console.log('Row insert status: ' + data.detail) // DEBUG
this.showNotification('Insert Failed', 'danger', 1000)
}
finishCallback()
this.updatingRow = false
}
Expand Down
30 changes: 10 additions & 20 deletions samplesheets/vueapp/src/components/editors/DataCellEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ export default Vue.extend({
}
// Special setup for the name column
if (this.headerInfo.header_type === 'name') {
if (['name', 'process_name'].includes(this.headerInfo.header_type)) {
if (this.value.newRow) this.containerTitle = 'Enter name of new or existing node'
else this.containerTitle = 'Rename node'
// If name, get other current values for comparison in validation
Expand Down Expand Up @@ -360,20 +360,6 @@ export default Vue.extend({
this.value.value[i] = this.value.value[i].trim()
}
}
// Check if we're in a named process without a protocol
let namedProcess = false
if (this.headerInfo.header_type === 'process_name') {
namedProcess = true
const groupId = this.params.column.originalParent.groupId
const cols = this.gridOptions.columnApi.getColumns()
for (let i = 1; i < cols.length - 1; i++) {
if (cols[i].originalParent.groupId === groupId &&
cols[i].colDef.cellEditorParams.headerInfo.header_type === 'protocol') {
namedProcess = false
break
}
}
}
// Reject invalid value
if (!this.valid) {
Expand All @@ -384,8 +370,12 @@ export default Vue.extend({
return
}
// Check if this is a process name column
let processName = false
if (this.headerInfo.header_type === 'process_name') processName = true
// Confirm renaming node into an existing node and overwriting values
if ((this.headerInfo.header_type === 'name' || namedProcess) &&
if ((this.headerInfo.header_type === 'name' || processName) &&
this.value.newRow &&
this.ogEditValue &&
this.nameValues.includes(this.editValue)) {
Expand All @@ -402,12 +392,12 @@ export default Vue.extend({
}
// Proceed with setting values and saving
if ((this.headerInfo.header_type === 'name' || namedProcess) &&
if ((this.headerInfo.header_type === 'name' || processName) &&
(!this.value.uuid || this.value.newRow)) {
// Set UUID if we are referring to an existing node (only if material)
if (!namedProcess && this.nameValues.includes(this.value.value)) {
if (this.nameValues.includes(this.value.value)) {
this.value.uuid = this.nameUuids[this.value.value]
} else if (!namedProcess) {
} else {
// Clear UUID in case user switched from existing to new while editing
this.value.uuid = null
}
Expand All @@ -419,6 +409,7 @@ export default Vue.extend({
else this.value.unit = this.editUnit
// Handle updating/initiating node
// TODO: Ensure this works also if setting process name value to empty
this.app.handleNodeUpdate(
this.value,
this.params.column,
Expand All @@ -434,7 +425,6 @@ export default Vue.extend({
// Update cell (only if we already have the UUID!)
if (this.value.uuid) {
this.app.handleCellEdit(this.getUpdateData(), true)
// If a sample has been renamed, update sample list for assay
if (this.headerInfo.header_type === 'name' &&
this.params.colDef.field === this.sampleColId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,8 @@ export default Vue.extend({
}
// Add cells for new nodes, only the first node for existing ones
// TODO: This fails for process nodes (at least named ones), fix!
// TODO: We end up with all of the columns instead of just the 1st
if (nodeClass === 'Process' ||
fieldIdx === 0 ||
(!this.rowNode.data[cols[i].colId].uuid &&
Expand Down

0 comments on commit 15c1486

Please sign in to comment.