Skip to content

Commit e54d73c

Browse files
committed
fix issue with navigation when using this package
1 parent b988c1d commit e54d73c

File tree

10 files changed

+153
-127
lines changed

10 files changed

+153
-127
lines changed

dist/js/card.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js/card.js.LICENSE

Lines changed: 0 additions & 6 deletions
This file was deleted.

dist/js/card.js.LICENSE.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*!
2+
* Determine if an object is a Buffer
3+
*
4+
* @author Feross Aboukhadijeh <https://feross.org>
5+
* @license MIT
6+
*/
7+
8+
/**
9+
* @license
10+
* Lodash <https://lodash.com/>
11+
* Copyright JS Foundation and other contributors <https://js.foundation/>
12+
* Released under MIT license <https://lodash.com/license>
13+
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
14+
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
15+
*/
16+
17+
/**
18+
* @license
19+
* Lodash <https://lodash.com/>
20+
* Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
21+
* Released under MIT license <https://lodash.com/license>
22+
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
23+
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
24+
*/

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/js/card.js

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,8 @@
1-
import { default as MegaFilter } from './components/MegaFilter.vue'
1+
import MegaFilter from './components/MegaFilter.vue'
22
import MegaFilterPlaceholder from './components/MegaFilterPlaceholder.vue'
3-
import ProxyIndex from './components/ProxyIndex.vue'
43

54
Nova.booting((Vue, router, store) => {
65

7-
router.beforeEach((from, to, next) => {
8-
9-
if (from.name === 'index') {
10-
11-
return next({ ...from, name: 'index-mega-filter', replace: true })
12-
13-
}
14-
15-
next()
16-
17-
})
18-
19-
router.addRoutes([
20-
{
21-
name: 'index-mega-filter',
22-
path: '/resources/:resourceName',
23-
component: ProxyIndex,
24-
props: true
25-
}
26-
])
27-
286
Vue.component('mega-filter', MegaFilter)
297
Vue.component('mega-filter-placeholder', MegaFilterPlaceholder)
308

resources/js/components/MegaFilter.vue

Lines changed: 89 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,19 @@
88

99
<div>
1010

11-
<Button v-if="hasColumns"
12-
@click.native="toggleSection('columns')"
13-
:state="sections.columns">
11+
<Button v-if="hasColumns" @click.native="toggleSection('columns')" :state="sections.columns">
1412

1513
{{ settings.columnsLabel }}
1614

1715
</Button>
1816

19-
<Button v-if="hasFilters"
20-
@click.native="toggleSection('filters')"
21-
:state="sections.filters">
17+
<Button v-if="hasFilters" @click.native="toggleSection('filters')" :state="sections.filters">
2218

2319
{{ settings.filtersLabel }}
2420

2521
</Button>
2622

27-
<Button v-if="hasActions"
28-
@click.native="toggleSection('actions')"
29-
:state="sections.actions">
23+
<Button v-if="hasActions" @click.native="toggleSection('actions')" :state="sections.actions">
3024

3125
{{ settings.actionsLabel }}
3226

@@ -168,26 +162,25 @@
168162
<script>
169163
170164
import { CollapseTransition, FadeTransition } from 'vue2-transitions'
171-
import { Filterable } from 'laravel-nova'
165+
import { Filterable, mapProps } from 'laravel-nova'
172166
import Section from './elements/Section'
173167
import Button from './elements/Button'
174168
import HandlesActions from '~~nova~~/mixins/HandlesActions'
175169
import { escapeUnicode } from '~~nova~~/util/escapeUnicode'
170+
import _ from 'lodash'
176171
177172
export default {
178173
name: 'MegaFilter',
179174
mixins: [ Filterable, HandlesActions ],
180175
components: { Button, FadeTransition, CollapseTransition, Section },
181-
props: [
182-
'card',
183-
// 'resource',
184-
// 'resourceId',
185-
'resourceName'
186-
],
187-
created() {
188-
189-
Nova.$emit('useMegaFilter', true)
190-
176+
props: {
177+
card: { type: Object },
178+
...mapProps([
179+
'resourceName',
180+
'viaResource',
181+
'viaResourceId',
182+
'viaRelationship'
183+
])
191184
},
192185
data() {
193186
@@ -198,6 +191,7 @@
198191
message: null,
199192
fieldsModel: {},
200193
actionMessages: [],
194+
filterKey: 'DigitalCreative\\MegaFilter\\MegaFilterColumns',
201195
sections: sections || {
202196
columns: this.card.settings.columnsActive,
203197
filters: this.card.settings.filtersActive,
@@ -214,17 +208,22 @@
214208
215209
}
216210
217-
const encodedFilter = this.$route.query.megaFilter || this.resolveEncodedFiltersFromCache()
211+
const filter = this.$store.getters[ `${ this.resourceName }/getFilter` ](this.filterKey)
218212
219213
this.initializeFieldsUsingObject(
220-
encodedFilter ? this.decodeObject(encodedFilter) : {}
214+
filter.currentValue || this.decodeObject(this.resolveEncodedFiltersFromCache())
221215
)
222216
223-
Nova.$emit('megaFilterEncodedQuery', encodedFilter)
224-
Nova.$emit('reloadIndexResources')
225-
226217
},
227218
computed: {
219+
/**
220+
* Get the name of the page query string variable.
221+
*/
222+
pageParameter() {
223+
return this.viaRelationship
224+
? this.viaRelationship + '_page'
225+
: this.resourceName + '_page'
226+
},
228227
hasColumns() {
229228
230229
return this.columns.length > 0
@@ -254,6 +253,12 @@
254253
255254
return this.card.filters.filter(filter => {
256255
256+
if (filter.class === this.filterKey) {
257+
258+
return false
259+
260+
}
261+
257262
if (filter.hasOwnProperty('megaFilterFieldAttribute')) {
258263
259264
return this.fieldsModel[ filter.megaFilterFieldAttribute ]
@@ -347,6 +352,7 @@
347352
},
348353
methods: {
349354
getCache(property) {
355+
350356
try {
351357
352358
return JSON.parse(localStorage.getItem(this.card.cacheKey))[ property ]
@@ -356,6 +362,7 @@
356362
return null
357363
358364
}
365+
359366
},
360367
getSectionsFromCache() {
361368
@@ -376,7 +383,7 @@
376383
},
377384
updateQueryString(value) {
378385
379-
this.$router.push({ name: 'index-mega-filter', query: { ...this.$route.query, ...value } })
386+
this.$router.replace({ query: { ...this.$route.query, ...value } })
380387
381388
},
382389
actionFormData() {
@@ -454,6 +461,42 @@
454461
455462
this.updateCache()
456463
464+
},
465+
async clearSelectedFilters(lens) {
466+
467+
if (lens) {
468+
469+
await this.$store.dispatch(`${ this.resourceName }/resetFilterState`, {
470+
resourceName: this.resourceName,
471+
lens
472+
})
473+
474+
} else {
475+
476+
_.each(this.$store.getters[ `${ this.resourceName }/originalFilters` ], filter => {
477+
478+
if (filter.class !== this.filterKey) {
479+
480+
this.$store.commit(`${ this.resourceName }/updateFilterState`, {
481+
filterClass: filter.class,
482+
value: filter.currentValue
483+
})
484+
485+
} else {
486+
487+
this.updateColumnsFilter()
488+
489+
}
490+
491+
})
492+
493+
}
494+
495+
this.updateQueryString({
496+
[ this.pageParameter ]: 1,
497+
[ this.filterParameter ]: ''
498+
})
499+
457500
},
458501
updateFilters() {
459502
@@ -476,7 +519,15 @@
476519
},
477520
decodeObject(encodedFilters) {
478521
479-
return JSON.parse(atob(encodedFilters))
522+
try {
523+
524+
return JSON.parse(atob(encodedFilters))
525+
526+
} catch (e) {
527+
528+
return {}
529+
530+
}
480531
481532
},
482533
encodeObject(data) {
@@ -491,19 +542,23 @@
491542
},
492543
refreshResourceTable() {
493544
494-
const encodedQuery = this.getEncodedQueryString()
495-
496-
Nova.$emit('megaFilterEncodedQuery', encodedQuery)
497-
498-
this.updateQueryString({ megaFilter: encodedQuery })
499-
this.updateFilters()
545+
this.updateColumnsFilter()
546+
this.filterChanged()
500547
this.updateCache()
501548
502-
this.$nextTick(() => Nova.$emit('reloadIndexResources'))
549+
},
550+
updateColumnsFilter() {
551+
552+
this.$store.commit(`${ this.resourceName }/updateFilterState`, {
553+
filterClass: this.filterKey,
554+
value: this.fieldsModel
555+
})
503556
504557
}
505558
}
559+
506560
}
561+
507562
</script>
508563

509564
<style lang="scss">

resources/js/components/ProxyIndex.vue

Lines changed: 0 additions & 56 deletions
This file was deleted.

src/HasMegaFilterTrait.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Illuminate\Support\Collection;
66
use Laravel\Nova\Fields\Field;
7+
use Laravel\Nova\FilterDecoder;
78
use Laravel\Nova\Http\Controllers\ActionController;
89
use Laravel\Nova\Http\Controllers\FilterController;
910
use Laravel\Nova\Http\Controllers\ResourceCountController;
@@ -118,17 +119,19 @@ private function getMegaFilterCard(NovaRequest $request): ?MegaFilter
118119
private function getFilterState(NovaRequest $request, MegaFilter $card): Collection
119120
{
120121

121-
$query = collect(json_decode(base64_decode($request->query('megaFilter')), true));
122+
$filterDecoder = (new FilterDecoder($request->get('filters')))->decodeFromBase64String();
122123

123-
$attributes = $card->columns()->filter(static function (Column $column) use ($query) {
124+
$value = collect($filterDecoder)->firstWhere('class', MegaFilterColumns::class)[ 'value' ];
125+
126+
$attributes = $card->columns()->filter(static function (Column $column) use ($value) {
124127

125128
if ($column->permanent) {
126129

127130
return true;
128131

129132
}
130133

131-
if ((is_bool($value = $query->get($column->attribute)))) {
134+
if ((is_bool($value = $value[ $column->attribute ] ?? true))) {
132135

133136
return $value;
134137

0 commit comments

Comments
 (0)