Skip to content

Commit

Permalink
Merge pull request #1505 from NicoPennec/fix/filtering
Browse files Browse the repository at this point in the history
Improve entity filtering
  • Loading branch information
NicoPennec authored Aug 5, 2024
2 parents ce784b2 + fd89bda commit 5bbbcba
Show file tree
Hide file tree
Showing 32 changed files with 184 additions and 136 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/components/cells/MetadataInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ export default {
components: {
ComboboxTag
},
props: {
entity: {
type: Object,
Expand All @@ -154,8 +155,10 @@ export default {
required: true
}
},
computed: {
...mapGetters(['isCurrentUserManager', 'isCurrentUserSupervisor', 'user']),
isEditable() {
return (
this.isCurrentUserManager ||
Expand Down
22 changes: 21 additions & 1 deletion src/components/mixins/descriptors.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ import { mapGetters } from 'vuex'

export const descriptorMixin = {
computed: {
...mapGetters(['selectedAssets', 'selectedShots', 'selectedEdits']),
...mapGetters([
'isCurrentUserSupervisor',
'selectedAssets',
'selectedShots',
'selectedEdits',
'user'
]),

descriptorLength() {
if (this.shotMetadataDescriptors.length !== undefined) {
return this.shotMetadataDescriptors.length
Expand Down Expand Up @@ -185,6 +192,19 @@ export const descriptorMixin = {
return values
},

isSupervisorInDepartments(departments = []) {
if (!Array.isArray(departments)) {
departments = [departments]
}
return (
this.isCurrentUserSupervisor &&
(this.user.departments.length === 0 ||
this.user.departments.some(department =>
departments.includes(department)
))
)
},

/*
* Determine what is the next input by building a reference key and
* retrieve it from the main reference array.
Expand Down
13 changes: 0 additions & 13 deletions src/components/mixins/entity_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,19 +437,6 @@ export const entityListMixin = {
return false
},

isSupervisorInDepartments(departments = []) {
if (!Array.isArray(departments)) {
departments = [departments]
}
return (
this.isCurrentUserSupervisor &&
(this.user.departments.length === 0 ||
this.user.departments.some(department =>
departments.includes(department)
))
)
},

isValidResolution(shot) {
if (!shot) return true
const res = this.getMetadataFieldValue({ field_name: 'resolution' }, shot)
Expand Down
23 changes: 9 additions & 14 deletions src/components/modals/AddMetadataModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -148,29 +148,29 @@ import { descriptorMixin } from '@/components/mixins/descriptors'
import { remove } from '@/lib/models'
import ButtonSimple from '@/components/widgets/ButtonSimple.vue'
import Checklist from '@/components/widgets/Checklist.vue'
import Combobox from '@/components/widgets/Combobox.vue'
import ComboboxBoolean from '@/components/widgets/ComboboxBoolean.vue'
import ModalFooter from '@/components/modals/ModalFooter.vue'
import TextField from '@/components/widgets/TextField.vue'
import ComboboxDepartment from '@/components/widgets/ComboboxDepartment.vue'
import DepartmentName from '@/components/widgets/DepartmentName.vue'
import ButtonSimple from '@/components/widgets/ButtonSimple.vue'
import Checklist from '@/components/widgets/Checklist.vue'
import ModalFooter from '@/components/modals/ModalFooter.vue'
import TextField from '@/components/widgets/TextField.vue'
export default {
name: 'add-metadata-modal',
mixins: [descriptorMixin, modalMixin],
components: {
ButtonSimple,
Checklist,
Combobox,
ComboboxBoolean,
ComboboxDepartment,
DepartmentName,
ModalFooter,
TextField,
ButtonSimple,
Checklist
TextField
},
props: {
Expand All @@ -190,10 +190,6 @@ export default {
type: Boolean,
default: false
},
errorText: {
type: String,
default: ''
},
entityType: {
type: String,
default: 'Asset'
Expand Down Expand Up @@ -247,11 +243,10 @@ export default {
computed: {
...mapGetters([
'departments',
'departmentMap',
'currentProduction',
'taskTypeMap',
'departmentMap',
'isCurrentUserSupervisor',
'taskTypeMap',
'user'
]),
Expand Down
84 changes: 56 additions & 28 deletions src/components/modals/BuildFilterModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

<div
class="flexrow task-type-filter"
:key="'task-type-' + i"
:key="`task-type-${i}`"
v-for="(taskTypeFilter, i) in taskTypeFilters.values"
>
<combobox-task-type
Expand All @@ -62,7 +62,7 @@
<div class="flexrow-item flexrow value-column">
<combobox-status
class="flexrow-item"
:key="'task-type-value-' + index"
:key="`task-type-value-${index}`"
:task-status-list="taskStatuses"
v-model="taskTypeFilter.values[index]"
v-for="(statusId, index) in taskTypeFilter.values"
Expand Down Expand Up @@ -91,7 +91,7 @@

<div
class="flexrow descriptor-filter"
:key="'desc-' + i"
:key="`descriptor-${i}`"
v-for="(descriptorFilter, i) in metadataDescriptorFilters.values"
>
<combobox
Expand All @@ -100,35 +100,49 @@
@input="onDescriptorChanged(descriptorFilter)"
v-model="descriptorFilter.id"
/>

<combobox
class="flexrow-item"
:options="general.operatorOptions"
:options="general.checklistOptions"
locale-key-prefix="entities.build_filter."
v-model="descriptorFilter.operator"
v-if="!descriptorFilter.is_checklist"
@input="operator => onOperatorChanged(operator, descriptorFilter)"
v-model="descriptorFilter.values[0].checked"
v-if="descriptorFilter.is_checklist"
/>

<combobox
class="flexrow-item"
:options="general.checklistOptions"
:options="general.booleanOptions"
locale-key-prefix="entities.build_filter."
v-model="descriptorFilter.values[0].checked"
v-model="descriptorFilter.values[0]"
v-else-if="
getDescriptor(descriptorFilter.id).data_type === 'boolean'
"
/>
<combobox
class="flexrow-item"
:options="general.operatorOptions"
locale-key-prefix="entities.build_filter."
@input="operator => onOperatorChanged(operator, descriptorFilter)"
v-model="descriptorFilter.operator"
v-else
/>

<div class="flexrow-item flexrow value-column">
<div
class="flexrow-item flexrow value-column"
v-if="getDescriptor(descriptorFilter.id).data_type !== 'boolean'"
>
<template v-for="(value, index) in descriptorFilter.values">
<text-field
:key="'descriptor-value-' + index"
<metadata-field
class="flexrow-item"
input-class=" thin"
label=""
:key="`descriptor-value-${index}`"
:descriptor="getDescriptor(descriptorFilter.id)"
:entity="{}"
v-model="descriptorFilter.values[index]"
v-if="getDescriptor(descriptorFilter.id).choices.length === 0"
/>
<combobox
class="flexrow-item"
:key="'descriptor-list-value-' + index"
:key="`descriptor-value-${index}`"
:options="
getDescriptorChoiceOptions(
descriptorFilter.id,
Expand Down Expand Up @@ -286,9 +300,9 @@ import Combobox from '@/components/widgets/Combobox.vue'
import ComboboxStatus from '@/components/widgets/ComboboxStatus.vue'
import ComboboxStyled from '@/components/widgets/ComboboxStyled.vue'
import ComboboxTaskType from '@/components/widgets/ComboboxTaskType.vue'
import MetadataField from '@/components/widgets/MetadataField.vue'
import ModalFooter from '@/components/modals/ModalFooter.vue'
import PeopleField from '@/components/widgets/PeopleField.vue'
import TextField from '@/components/widgets/TextField.vue'
export default {
name: 'build-filter-modal',
Expand All @@ -301,9 +315,9 @@ export default {
ComboboxStatus,
ComboboxStyled,
ComboboxTaskType,
MetadataField,
ModalFooter,
PeopleField,
TextField
PeopleField
},
props: {
Expand Down Expand Up @@ -341,6 +355,10 @@ export default {
{ label: 'not_equal', value: '=-' },
{ label: 'in', value: 'in' }
],
booleanOptions: [
{ label: 'checked', value: 'true' },
{ label: 'not_checked', value: '-true' }
],
checklistOptions: [
{ label: 'checked', value: true },
{ label: 'not_checked', value: false }
Expand Down Expand Up @@ -562,8 +580,8 @@ export default {
if (descriptorFilter.operator === '=-') operator = '=[-'
value = descriptorFilter.values.join(',')
}
const desc = this.getDescriptor(descriptorFilter.id)
query += ` [${desc.name}]${operator}${value}]`
const descriptor = this.getDescriptor(descriptorFilter.id)
query += ` [${descriptor.name}]${operator}${value}]`
})
return query
},
Expand Down Expand Up @@ -672,30 +690,34 @@ export default {
} else {
descriptorFilter.values = [descriptor.choices[0]]
}
} else if (descriptor.data_type === 'boolean') {
descriptorFilter.values = ['-true']
} else {
descriptorFilter.values = ['']
}
},
addDescriptorFilter() {
const desc = this.getDescriptor(this.descriptorOptions[0].value)
const descriptor = this.getDescriptor(this.descriptorOptions[0].value)
const values = []
let isChecklist = false
if (desc.choices.length > 0) {
const checklistValues = this.getDescriptorChecklistValues(desc)
if (descriptor.choices.length > 0) {
const checklistValues = this.getDescriptorChecklistValues(descriptor)
if (checklistValues.length > 0) {
isChecklist = true
values.push(checklistValues[0])
} else {
values.push(desc.choices[0])
values.push(descriptor.choices[0])
}
} else if (descriptor.data_type === 'boolean') {
values.push('-true')
} else {
values.push('')
}
const filter = {
id: this.descriptorOptions[0].value,
operator: '=',
values: values,
values,
is_checklist: isChecklist
}
this.metadataDescriptorFilters.values.push(filter)
Expand Down Expand Up @@ -814,12 +836,18 @@ export default {
checked: false
}
]
} else if (filter.excluding) operator = '=-'
} else if (filter.excluding) {
if (filter.descriptor.data_type === 'boolean') {
values = [`-${filter.values[0]}`]
} else {
operator = '=-'
}
}
}
this.metadataDescriptorFilters.values.push({
id: filter.descriptor.id,
operator,
values: values,
values,
is_checklist: isChecklist
})
},
Expand Down Expand Up @@ -849,7 +877,7 @@ export default {
setFiltersFromPriorityQuery(filter) {
this.priority.taskTypeId = filter.taskTypeId
this.priority.value = filter.value + ''
this.priority.value = String(filter.value)
},
setFiltersFromReadyForQuery(filter) {
Expand Down
16 changes: 10 additions & 6 deletions src/components/pages/Assets.vue
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,7 @@ export default {
.then(form => {
this.loading.edit = false
this.modals.isNewDisplayed = false
this.onSearchChange()
})
.catch(err => {
console.error(err)
Expand Down Expand Up @@ -961,24 +962,27 @@ export default {
this.changeAssetSort(sortInfo)
},
onFieldChanged({ entry, fieldName, value }) {
async onFieldChanged({ entry, fieldName, value }) {
const data = { id: entry.id }
data[fieldName] = value
this.editAsset(data)
await this.editAsset(data)
this.onSearchChange()
},
onMetadataChanged({ entry, descriptor, value }) {
async onMetadataChanged({ entry, descriptor, value }) {
const metadata = {}
metadata[descriptor.field_name] = value
const data = {
id: entry.id,
data: metadata
}
this.editAsset(data)
await this.editAsset(data)
this.onSearchChange()
},
onAssetChanged(asset) {
this.editAsset(asset)
async onAssetChanged(asset) {
await this.editAsset(asset)
this.onSearchChange()
},
reset() {
Expand Down
Loading

0 comments on commit 5bbbcba

Please sign in to comment.