Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Merge pull request #9 from nemrutco/adding-new-abilities
Browse files Browse the repository at this point in the history
add ability to request and response filters from Global Filter
  • Loading branch information
MuzafferDede authored Jun 1, 2020
2 parents 2d8ad3f + a197ce7 commit 2f9d329
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 9 deletions.
37 changes: 34 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ new NovaGlobalFilter([
```

To listen `Global Filter` on any `Custom Card`s:

```js
...
created() {
Expand All @@ -122,6 +121,39 @@ created() {
...
```

To request all filter states from `Global Filter` on any `Custom Card`s:
```js
...
created() {
Nova.$on("global-filter-request");
},
...
```

To request spesific filters state from `Global Filter` on any `Custom Card`s:
```js
...
created() {
Nova.$on("global-filter-request", [
"App\\Nova\\Filters\\DateFilter",
"App\\Nova\\Filters\\CountryFilter"
]);
},
...
```

To receive filters state from `Global Filter` on any `Custom Card`s:
```js
...
created() {
Nova.$on("global-filter-response", filters => {
// Do your thing with the filters
console.log(filters);
});
},
...
```

## Good to know

- Basic functionality of this package is that it listens all the asigned filters. Once a value of a filter is changed, it emits as `Nova.$on('global-filter-changed', [changed filter and value])`. So any card that listens to this event will recieve the filter and its value.
Expand All @@ -132,8 +164,7 @@ created() {

Cheers

## Credits

- [Nemrut Creative Studio]('https://nemrut.co)
- [Muzaffer Dede](https://github.com/muzafferdede)
- [All Contributors](../../contributors)

Expand Down
2 changes: 1 addition & 1 deletion dist/js/card.js

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions resources/js/components/FilterBehavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ export default {
}
this.fetch();
});
Nova.$on("global-filter-reset", filters => {
this.$router.go(this.$router.currentRoute)
});
},

methods: {
Expand Down
16 changes: 14 additions & 2 deletions resources/js/components/GlobalFilter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,18 @@ export default {
this.$parent.$el.classList.remove("w-5/6");
this.$parent.$el.classList.add("w-full");
},
created() {
Nova.$on("global-filter-request", filterClasses => {
let filters = this.card.filters !== undefined ? this.card.filters : [];
if (filterClasses && filterClasses.length) {
filters = filters.filter(filter =>
filterClasses.includes(filter.class)
);
}
Nova.$emit("global-filter-response", filters);
});
},
methods: {
handleChange(filter, event) {
let value = event;
Expand All @@ -103,8 +115,8 @@ export default {
filter.currentValue = value;
Nova.$emit("global-filter-changed", filter);
},
resetFilters(filters) {
Nova.$emit("global-filter-reset", filters);
resetFilters() {
this.$router.go(this.$router.currentRoute);
}
}
};
Expand Down

0 comments on commit 2f9d329

Please sign in to comment.