Skip to content

Commit

Permalink
Add event and pb type presets on my-pbs page
Browse files Browse the repository at this point in the history
  • Loading branch information
big213 committed Apr 20, 2021
1 parent 7a5e28e commit cf1ee31
Show file tree
Hide file tree
Showing 11 changed files with 340 additions and 263 deletions.
4 changes: 4 additions & 0 deletions frontend/components/interface/crud/crudRecordInterface.vue
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@
offset-y
@handle-action-click="openEditDialog"
@handle-expand-click="openExpandDialog(props, ...$event)"
@handle-custom-action-click="handleCustomActionClick"
>
<template v-slot:activator="{ on, attrs }">
<v-btn block text v-bind="attrs" v-on="on"> Actions </v-btn>
Expand All @@ -262,6 +263,7 @@
v-if="headerItem.fieldInfo.component"
:item="props.item"
:field-path="headerItem.path"
@submit="reset({ resetExpanded: false })"
></component>
<span v-else>
{{ getTableRowData(headerItem, props.item) }}
Expand Down Expand Up @@ -293,6 +295,7 @@
offset-x
@handle-action-click="openEditDialog"
@handle-expand-click="toggleItemExpanded(props, ...$event)"
@handle-custom-action-click="handleCustomActionClick"
>
<template v-slot:activator="{ on, attrs }">
<v-icon small v-bind="attrs" v-on="on"
Expand All @@ -307,6 +310,7 @@
v-if="headerItem.fieldInfo.component"
:item="props.item"
:field-path="headerItem.path"
@submit="reset({ resetExpanded: false })"
></component>
<span v-else>
{{ getTableRowData(headerItem, props.item) }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@
offset-y
@handle-action-click="openEditDialog"
@handle-expand-click="openExpandDialog(props, ...$event)"
@handle-custom-action-click="handleCustomActionClick"
>
<template v-slot:activator="{ on, attrs }">
<v-btn block text v-bind="attrs" v-on="on"> Actions </v-btn>
Expand All @@ -266,6 +267,7 @@
v-if="headerItem.fieldInfo.component"
:item="props.item"
:field-path="headerItem.path"
@submit="reset({ resetExpanded: false })"
></component>
<span v-else>
{{ getTableRowData(headerItem, props.item) }}
Expand Down Expand Up @@ -293,11 +295,12 @@
<RecordActionMenu
:record-info="recordInfo"
:item="props.item"
expand-mode="emit"
left
offset-x
expand-mode="emit"
@handle-action-click="openEditDialog"
@handle-expand-click="toggleItemExpanded(props, ...$event)"
@handle-custom-action-click="handleCustomActionClick"
>
<template v-slot:activator="{ on, attrs }">
<v-icon small v-bind="attrs" v-on="on"
Expand All @@ -309,13 +312,13 @@
<span v-else-if="headerItem.value === 'rank'">
{{ renderRank(props.index) }}
</span>

<span v-else>
<component
:is="headerItem.fieldInfo.component"
v-if="headerItem.fieldInfo.component"
:item="props.item"
:field-path="headerItem.path"
@submit="reset({ resetExpanded: false })"
></component>
<span v-else>
{{ getTableRowData(headerItem, props.item) }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
? item.fieldInfo.compoundOptions.pathPrefix
: item.field
"
@submit="$emit('handleSubmit')"
></component>
<span v-else style="white-space: break-spaces">{{
getNestedProperty(currentItem, item.field)
Expand Down
31 changes: 27 additions & 4 deletions frontend/components/menu/recordActionMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,37 @@
</v-list-item-icon>
<v-list-item-title>Delete</v-list-item-title>
</v-list-item>
<template
v-if="recordInfo.customActions && recordInfo.customActions.length > 0"
>
<v-divider></v-divider>
<v-list-item
v-for="(actionObject, i) in recordInfo.customActions"
:key="'ca' + i"
dense
@click="handleCustomActionClick(actionObject)"
>
<v-list-item-icon>
<v-icon>{{ actionObject.icon }}</v-icon>
</v-list-item-icon>
<v-list-item-title>{{ actionObject.text }} </v-list-item-title>
</v-list-item>
</template>

<v-divider v-if="recordInfo.expandTypes.length > 0"></v-divider>
<v-list-item
v-for="(item, i) in recordInfo.expandTypes"
v-for="(expandObject, i) in recordInfo.expandTypes"
:key="i"
dense
@click="openExpandType(item, i)"
@click="openExpandType(expandObject, i)"
>
<v-list-item-icon>
<v-icon>{{ item.icon || item.recordInfo.icon }}</v-icon>
<v-icon>{{
expandObject.icon || expandObject.recordInfo.icon
}}</v-icon>
</v-list-item-icon>
<v-list-item-title
>{{ item.name || item.recordInfo.name }}
>{{ expandObject.name || item.recordInfo.name }}
<v-icon v-if="expandMode === 'openInNew'" small right
>mdi-open-in-new</v-icon
>
Expand Down Expand Up @@ -153,6 +172,10 @@ export default {
)
},
handleCustomActionClick(actionObject) {
this.$emit('handle-custom-action-click', actionObject, this.item)
},
goToPage() {
goToPage(
this,
Expand Down
247 changes: 247 additions & 0 deletions frontend/components/page/preset/pbPagePreset.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,247 @@
<template>
<v-container fluid class="text-center pb-0" style="max-width: 1920px">
<v-progress-circular
v-if="loading.presets"
indeterminate
></v-progress-circular>
<v-row v-else justify="center" class="pt-3">
<v-col :key="-1" cols="12" lg="3" class="pb-0">
<v-autocomplete
v-model="inputs.event"
:items="events"
item-text="name"
item-value="id"
label="Event"
filled
return-object
:clearable="eventClearable"
@change="applyEventPreset"
></v-autocomplete>
</v-col>
<v-col :key="-2" cols="12" lg="3" class="pb-0">
<v-autocomplete
v-model="inputs.pbType"
:items="pbTypes"
item-text="text"
label="PB Type"
clearable
filled
return-object
@change="applyPbPreset"
></v-autocomplete>
</v-col>
</v-row>
</v-container>
</template>

<script>
import { getEvents } from '~/services/dropdown'
import { generateRoute } from '~/services/base'
export default {
props: {
eventClearable: {
type: Boolean,
default: true,
},
},
data() {
return {
inputs: {
event: null,
pbType: null,
},
loading: {
presets: false,
},
events: [],
pbTypes: [
{
text: 'Single',
attributes: {
'pbClass.id': 1,
setSize: 1,
},
},
{
text: 'Mo3',
attributes: {
'pbClass.id': 3,
setSize: 3,
},
},
{
text: 'Ao5',
attributes: {
'pbClass.id': 2,
setSize: 5,
},
},
{
text: 'Ao12',
attributes: {
'pbClass.id': 2,
setSize: 12,
},
},
{
text: 'Ao50',
attributes: {
'pbClass.id': 2,
setSize: 50,
},
},
{
text: 'Ao100',
attributes: {
'pbClass.id': 2,
setSize: 100,
},
},
{
text: 'Ao1000',
attributes: {
'pbClass.id': 2,
setSize: 1000,
},
},
],
}
},
watch: {
'$route.query.pageOptions'() {
this.syncFilters()
},
},
mounted() {
this.loadPresets().then(() => {
this.syncFilters()
})
},
methods: {
applyEventPreset(event) {
// get the original sortBy/sortDesc
const originalPageOptions = this.$route.query.pageOptions
? JSON.parse(atob(decodeURIComponent(this.$route.query.pageOptions)))
: null
// replace event.id filters with new ones
const excludeFilterKeys = ['event.id']
this.$router.push(
generateRoute(this.$route.path, {
...originalPageOptions,
filters: (originalPageOptions?.filters
? originalPageOptions.filters.filter(
(filterObject) =>
!excludeFilterKeys.includes(filterObject.field)
)
: []
).concat(
event
? [
{
field: 'event.id',
operator: 'eq',
value: event.id,
},
]
: []
),
})
)
},
applyPbPreset(pbType) {
// get the original sortBy/sortDesc/filters
const originalPageOptions = this.$route.query.pageOptions
? JSON.parse(atob(decodeURIComponent(this.$route.query.pageOptions)))
: null
// replace event.id/setSize filters with new ones
const excludeFilterKeys = ['pbClass.id', 'setSize']
this.$router.push(
generateRoute(this.$route.path, {
...originalPageOptions,
filters: (originalPageOptions?.filters
? originalPageOptions.filters.filter(
(filterObject) =>
!excludeFilterKeys.includes(filterObject.field)
)
: []
).concat(
pbType
? [
{
field: 'pbClass.id',
operator: 'eq',
value: pbType.attributes['pbClass.id'],
},
{
field: 'setSize',
operator: 'eq',
value: pbType.attributes.setSize,
},
]
: []
),
})
)
},
async loadPresets() {
this.loading.presets = true
this.events = await getEvents(this)
this.loading.presets = false
},
// syncs preset inputs with filters
syncFilters() {
const originalPageOptions = this.$route.query.pageOptions
? JSON.parse(atob(decodeURIComponent(this.$route.query.pageOptions)))
: null
// determine if a preset was applied
if (originalPageOptions.filters) {
const eventFilterObject = originalPageOptions.filters.find(
(filterObject) => filterObject.field === 'event.id'
)
if (eventFilterObject) {
this.inputs.event = this.events.find(
(event) => event.id === eventFilterObject.value
)
console.log(this.inputs.event)
} else {
this.inputs.event = null
}
const setSizeFilterObject = originalPageOptions.filters.find(
(filterObject) => filterObject.field === 'setSize'
)
const pbClassFilterObject = originalPageOptions.filters.find(
(filterObject) => filterObject.field === 'pbClass.id'
)
if (setSizeFilterObject && pbClassFilterObject) {
this.inputs.pbType = this.pbTypes.find(
(pbType) =>
pbType.attributes.setSize === setSizeFilterObject.value &&
pbType.attributes['pbClass.id'] === pbClassFilterObject.value
)
} else {
this.inputs.pbType = null
}
}
},
},
}
</script>
Loading

0 comments on commit cf1ee31

Please sign in to comment.