Skip to content

Commit

Permalink
Merge pull request #1176 from nextcloud/fix/993
Browse files Browse the repository at this point in the history
fix: ensure default values show as filled
  • Loading branch information
juliusknorr authored Aug 6, 2024
2 parents 22598ae + df649c4 commit 852bfd0
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 46 deletions.
23 changes: 3 additions & 20 deletions src/modules/modals/CreateRow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { showError, showSuccess } from '@nextcloud/dialogs'
import '@nextcloud/dialogs/dist/index.css'
import ColumnFormComponent from '../main/partials/ColumnFormComponent.vue'
import { translate as t } from '@nextcloud/l10n'
import rowHelper from '../../shared/components/ncTable/mixins/rowHelper.js'
export default {
name: 'CreateRow',
Expand All @@ -49,6 +50,7 @@ export default {
NcNoteCard,
NcButton,
},
mixins: [rowHelper],
props: {
showModal: {
type: Boolean,
Expand Down Expand Up @@ -79,14 +81,7 @@ export default {
return this.columns.filter(col => col.id >= 0)
},
hasEmptyMandatoryRows() {
let mandatoryFieldsEmpty = false
this.columns.forEach(col => {
if (col.mandatory) {
const validValue = this.isValueValidForColumn(this.row[col.id], col)
mandatoryFieldsEmpty = mandatoryFieldsEmpty || !validValue
}
})
return mandatoryFieldsEmpty
return this.checkMandatoryFields(this.row)
},
},
watch: {
Expand All @@ -103,18 +98,6 @@ export default {
this.addNewAfterSave = false
this.$emit('close')
},
isValueValidForColumn(value, column) {
if (column.type === 'selection') {
if (
(value instanceof Array && value.length > 0)
|| (value === parseInt(value))
) {
return true
}
return false
}
return !!value || value === 0
},
async actionConfirm() {
this.localLoading = true
await this.sendNewRowToBE()
Expand Down
29 changes: 3 additions & 26 deletions src/modules/modals/EditRow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import { translate as t } from '@nextcloud/l10n'
import '@nextcloud/dialogs/dist/index.css'
import ColumnFormComponent from '../main/partials/ColumnFormComponent.vue'
import permissionsMixin from '../../shared/components/ncTable/mixins/permissionsMixin.js'
import rowHelper from '../../shared/components/ncTable/mixins/rowHelper.js'
export default {
name: 'EditRow',
Expand All @@ -61,7 +62,7 @@ export default {
ColumnFormComponent,
NcNoteCard,
},
mixins: [permissionsMixin],
mixins: [permissionsMixin, rowHelper],
props: {
showModal: {
type: Boolean,
Expand Down Expand Up @@ -99,14 +100,7 @@ export default {
return this.columns.filter(col => col.id >= 0)
},
hasEmptyMandatoryRows() {
let mandatoryFieldsEmpty = false
this.columns.forEach(col => {
if (col.mandatory) {
const validValue = this.isValueValidForColumn(this.localRow[col.id], col)
mandatoryFieldsEmpty = mandatoryFieldsEmpty || !validValue
}
})
return mandatoryFieldsEmpty
return this.checkMandatoryFields(this.localRow)
},
},
watch: {
Expand Down Expand Up @@ -140,18 +134,6 @@ export default {
this.reset()
this.$emit('close')
},
isValueValidForColumn(value, column) {
if (column.type === 'selection') {
if (
(value instanceof Array && value.length > 0)
|| (value === parseInt(value))
) {
return true
}
return false
}
return !!value || value === 0
},
async actionConfirm() {
this.localLoading = true
await this.sendRowToBE()
Expand Down Expand Up @@ -253,11 +235,6 @@ export default {
display: inline-block;
}
:where(.fix-col-4) {
display: flex;
justify-content: space-between;
}
:where(.slot.fix-col-4 input, .slot.fix-col-4 .row) {
min-width: 100% !important;
}
Expand Down
35 changes: 35 additions & 0 deletions src/shared/components/ncTable/mixins/rowHelper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { ColumnTypes } from './columnHandler.js'
export default {
methods: {
isValueValidForColumn(value, column) {
const type = column?.type?.split('-')[0]
const columnTypeDefault = type + 'Default'
if (column.type === ColumnTypes.Selection) {
if (
(value instanceof Array && value.length > 0)
|| (value === parseInt(value))
) {
return true
}
return columnTypeDefault in column && !(['', 'null'].includes(column[columnTypeDefault]))
}
let hasDefaultValue = columnTypeDefault in column && !(['', null].includes(column[columnTypeDefault]))
if (column.type === ColumnTypes.SelectionMulti) {
hasDefaultValue = columnTypeDefault in column && column[columnTypeDefault] !== '[]'
return (value instanceof Array && value.length > 0) || hasDefaultValue
}
return (!!value || value === 0) || hasDefaultValue
},

checkMandatoryFields(row) {
let mandatoryFieldsEmpty = false
this.columns.forEach(col => {
if (col.mandatory) {
const validValue = this.isValueValidForColumn(row[col.id], col)
mandatoryFieldsEmpty = mandatoryFieldsEmpty || !validValue
}
})
return mandatoryFieldsEmpty
},
},
}

0 comments on commit 852bfd0

Please sign in to comment.