Skip to content

Commit

Permalink
Fix using ownedBy in record list filter
Browse files Browse the repository at this point in the history
  • Loading branch information
Fajfa committed Feb 12, 2025
1 parent 9add267 commit d1be75e
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 56 deletions.
7 changes: 4 additions & 3 deletions client/web/compose/src/components/Common/FilterToolbox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,10 @@ export default {
methods: {
getField (name = '') {
const field = name
? this.mock.module.fields.find((f) => f.name === name)
: undefined
const field = name ? (
this.mock.module.fields.find(f => f.name === name) ||
this.mock.module.systemFields().find(f => f.name === name)
) : undefined
return field ? { ...field } : undefined
},
Expand Down
38 changes: 18 additions & 20 deletions client/web/compose/src/components/Common/RecordListFilter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -178,25 +178,20 @@ export default {
created () {
// Change all module fields to single value to keep multi value fields and single value
const module = JSON.parse(JSON.stringify(this.module || {}))
module.fields = [
...[...module.fields].map(f => {
f.multi = f.isMulti
f.isMulti = false
// Disable edge case options
if (f.kind === 'DateTime') {
f.options.onlyFutureValues = false
f.options.onlyPastValues = false
}
return f
}),
...this.module.systemFields().map(sf => {
return { ...sf, label: this.$t(`field:system.${sf.name}`) }
}),
]
const module = new compose.Module(this.module)
module.fields = module.fields.map(f => {
f.multi = f.isMulti
f.isMulti = false
// Disable edge case options
if (f.kind === 'DateTime') {
f.options.onlyFutureValues = false
f.options.onlyPastValues = false
}
return f
})
this.mock = {
namespace: this.namespace,
Expand Down Expand Up @@ -225,7 +220,10 @@ export default {
},
getField (name = '') {
const field = name ? this.mock.module.fields.find(f => f.name === name) : undefined
const field = name ? (
this.mock.module.fields.find(f => f.name === name) ||
this.mock.module.systemFields().find(f => f.name === name)
) : undefined
return field ? { ...field } : undefined
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,7 @@ export default {
},
created () {
// Prefill value with current user
const isNewRecord = this.record && this.record.recordID === NoID
if ((!this.value || this.value.length === 0) && (this.field.options.presetWithAuthenticated || (isNewRecord && this.field.name === 'ownedBy'))) {
if ((!this.value || this.value.length === 0) && (this.field.options.presetWithAuthenticated)) {
this.updateValue(this.$auth.user)
}
Expand Down
11 changes: 0 additions & 11 deletions client/web/compose/src/components/ModuleFields/Viewer/User.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,5 @@ export default {
return f(this.value) || this.$t('kind.user.na')
},
},
created () {
// Prefill value with current user only when creating a new record and field is ownedBy (since BE prefills it anyway if its undefined)
const isNewRecord = this.record && this.record.recordID === NoID
if (isNewRecord && this.field.name === 'ownedBy') {
const { userID } = this.$auth.user
this.record.ownedBy = userID
}
},
}
</script>
33 changes: 17 additions & 16 deletions client/web/compose/src/components/PageBlocks/RecordListBase.vue
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@
<div
v-if="options.showDeletedRecordsOption"
class="d-flex align-items-center ml-auto"
style="min-height: 39.61px;"
>
<b-button
variant="outline-extra-light"
Expand Down Expand Up @@ -1970,19 +1969,26 @@ export default {
const fields = [...this.recordListModule.fields, ...this.recordListModule.systemFields()]
const moduleField = (fields.find(({ name }) => name === field.name) || {})
const record = !this.isBetweenOperator(operator)
? { recordID: '0', values: { [moduleField.name]: value } }
: [
{ recordID: '0', values: { [moduleField.name]: value.start } },
{ recordID: '0', values: { [moduleField.name]: value.end } },
let record = new compose.Record(this.recordListModule)
if (this.isBetweenOperator(operator)) {
record = [
new compose.Record(this.recordListModule),
new compose.Record(this.recordListModule),
]
if (moduleField.isSystem) {
if (!this.isBetweenOperator(operator)) {
record[moduleField.name] = value
} else {
if (moduleField.isSystem) {
record[0][moduleField.name] = value.start
record[1][moduleField.name] = value.end
} else {
record[0].values[moduleField.name] = value.start
record[1].values[moduleField.name] = value.end
}
} else {
if (moduleField.isSystem) {
record[moduleField.name] = value
} else {
record.values[moduleField.name] = value
}
}
Expand All @@ -1994,12 +2000,7 @@ export default {
kind: moduleField.kind,
label: moduleField.label || moduleField.name,
field: moduleField,
record: !this.isBetweenOperator(operator)
? new compose.Record(this.recordListModule, { ...record })
: [
new compose.Record(this.recordListModule, { ...record[0] }),
new compose.Record(this.recordListModule, { ...record[1] }),
],
record,
}
},
Expand Down
4 changes: 3 additions & 1 deletion client/web/compose/src/views/Admin/Modules/Records/View.vue
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,9 @@ export default {
}
})
} else {
this.record = new compose.Record(module, { values: this.values })
const { userID } = this.$auth.user
// Prefill ownedBy field with current user
this.record = new compose.Record(module, { ownedBy: userID, values: this.values })
this.initialRecordState = undefined
}
},
Expand Down
5 changes: 4 additions & 1 deletion client/web/compose/src/views/Public/Pages/Records/View.vue
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,10 @@ export default {
})
}
return new compose.Record(module, { values: this.values })
const { userID } = this.$auth.user
// Prefill ownedBy field with current user
return new compose.Record(module, { ownedBy: userID, values: this.values })
}
}
},
Expand Down

0 comments on commit d1be75e

Please sign in to comment.