Skip to content

Commit

Permalink
Merge pull request #21 from suenerds/20-upgrade-to-nova-4
Browse files Browse the repository at this point in the history
20 upgrade to nova 4
  • Loading branch information
michaelklopf authored Jan 24, 2024
2 parents e9cbb26 + c45675f commit 98b6ae2
Show file tree
Hide file tree
Showing 11 changed files with 173 additions and 154 deletions.
60 changes: 31 additions & 29 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
{
"name": "suenerds/nova-searchable-belongs-to-filter",
"description": "Searchable Nova filter for belongsTo relationships.",
"keywords": [
"laravel",
"nova",
"filter",
"belongs-to"
],
"license": "MIT",
"require": {
"php": ">=7.1.0"
},
"autoload": {
"psr-4": {
"Suenerds\\NovaSearchableBelongsToFilter\\": "src/"
}
},
"extra": {
"laravel": {
"providers": [
"Suenerds\\NovaSearchableBelongsToFilter\\FilterServiceProvider"
]
}
},
"config": {
"sort-packages": true
},
"minimum-stability": "dev",
"prefer-stable": true
"name": "suenerds/nova-searchable-belongs-to-filter",
"description": "Searchable Nova filter for belongsTo relationships.",
"keywords": [
"laravel",
"nova",
"filter",
"belongs-to"
],
"license": "MIT",
"require": {
"php": ">=8.0",
"laravel/framework": "^9.0",
"laravel/nova": "^4.0"
},
"autoload": {
"psr-4": {
"Suenerds\\NovaSearchableBelongsToFilter\\": "src/"
}
},
"extra": {
"laravel": {
"providers": [
"Suenerds\\NovaSearchableBelongsToFilter\\FilterServiceProvider"
]
}
},
"config": {
"sort-packages": true
},
"minimum-stability": "dev",
"prefer-stable": true
}
Empty file removed dist/css/filter.css
Empty file.
2 changes: 1 addition & 1 deletion dist/js/filter.js

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions dist/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{
"/js/filter.js": "/js/filter.js",
"/css/filter.css": "/css/filter.css"
}
"/js/filter.js": "/js/filter.js"
}
33 changes: 33 additions & 0 deletions nova.mix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const mix = require("laravel-mix");
const webpack = require("webpack");
const path = require("path");

class NovaExtension {
name() {
return "nova-extension";
}

register(name) {
this.name = name;
}

webpackConfig(webpackConfig) {
webpackConfig.externals = {
vue: "Vue",
};

webpackConfig.resolve.alias = {
...(webpackConfig.resolve.alias || {}),
"performs-searches": path.join(
__dirname,
"vendor/laravel/nova/resources/js/mixins/PerformsSearches.js"
),
};

webpackConfig.output = {
uniqueName: this.name,
};
}
}

mix.extend("nova", new NovaExtension());
36 changes: 18 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
{
"private": true,
"scripts": {
"dev": "npm run development",
"development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
"watch-poll": "npm run watch -- --watch-poll",
"hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
"prod": "npm run production",
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
},
"devDependencies": {
"cross-env": "^5.0.0",
"laravel-mix": "^1.0"
},
"dependencies": {
"laravel-nova": "^1.0.9",
"vue": "^2.5.0"
}
"private": true,
"scripts": {
"dev": "npm run development",
"development": "mix",
"watch": "mix watch",
"watch-poll": "mix watch -- --watch-options-poll=1000",
"hot": "mix watch --hot",
"prod": "npm run production",
"production": "mix --production",
"nova:install": "npm --prefix='../../vendor/laravel/nova' ci"
},
"devDependencies": {
"@vue/compiler-sfc": "^3.2.22",
"laravel-mix": "^6.0.41",
"postcss": "^8.3.11",
"vue-loader": "^16.8.3"
},
"dependencies": {}
}
1 change: 1 addition & 0 deletions resources/css/filter.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* Nova Filter CSS */
169 changes: 74 additions & 95 deletions resources/js/components/Filter.vue
Original file line number Diff line number Diff line change
@@ -1,118 +1,97 @@
<template>
<div>
<h3 class="text-sm uppercase tracking-wide text-80 bg-30 p-3">
{{ filter.name }}
</h3>
<div class="pt-2 pb-3">
<h3 class="px-3 text-xs uppercase font-bold tracking-wide">
{{ filter.name }}
</h3>

<div class="p-2">
<search-input
@input="performSearch"
@clear="clearSelection"
@selected="handleChange"
:value="value"
:data="availableResources"
:clearable="false"
trackBy="value"
searchBy="display"
>
<div
slot="default"
v-if="value"
class="flex items-center"
>
<div
v-if="value.avatar"
class="mr-3"
>
<img
:src="value.avatar"
class="w-8 h-8 rounded-full block"
/>
</div>
<div class="mt-1 px-3">
<SearchInput
@input="performSearch"
@clear="clearSelection"
@selected="handleChange"
:value="value"
:data="availableResources"
:clearable="false"
trackBy="value"
searchBy="display"
>
<div v-if="value" class="flex items-center">
<div v-if="value.avatar" class="mr-3">
<img :src="value.avatar" class="w-8 h-8 rounded-full block" />
</div>

{{ value.display }}
</div>

<div
slot="option"
slot-scope="{ option, selected }"
class="flex items-center"
>
<div
v-if="option.avatar"
class="mr-3"
>
<img
:src="option.avatar"
class="w-8 h-8 rounded-full block"
/>
</div>
{{ value.display }}
</div>

{{ option.display }}
</div>
</search-input>
<template #option="{ selected, option }">
<div class="flex items-center">
<div v-if="option.avatar" class="mr-3">
<img :src="option.avatar" class="w-8 h-8 rounded-full block" />
</div>

</div>
{{ option.display }}
</div>
</template>
</SearchInput>
</div>
</div>
</template>

<script>
import { PerformsSearches } from "laravel-nova"
import storage from '../storage/BelongsToFieldStorage'
import PerformsSearches from "performs-searches";
import storage from "../storage/BelongsToFieldStorage";
export default {
mixins: [PerformsSearches],
mixins: [PerformsSearches],
props: {
resourceName: {
type: String,
required: true,
},
filterKey: {
type: String,
required: true,
},
props: {
resourceName: {
type: String,
required: true,
},
filterKey: {
type: String,
required: true,
},
},
methods: {
getAvailableResources() {
return storage.fetchAvailableResources(
this.resourceName,
this.fieldAttribute,
{
params: {
search: this.search,
},
}
).then(({ data: { resources } }) => {
this.availableResources = resources;
});
},
methods: {
getAvailableResources() {
return storage
.fetchAvailableResources(this.resourceName, this.fieldAttribute, {
params: {
search: this.search,
},
})
.then(({ data: { resources } }) => {
this.availableResources = resources;
});
},
handleChange(resource) {
this.$store.commit(`${this.resourceName}/updateFilterState`, {
filterClass: this.filterKey,
value: resource
});
handleChange(resource) {
this.$store.commit(`${this.resourceName}/updateFilterState`, {
filterClass: this.filterKey,
value: resource,
});
this.$emit("change");
},
this.$emit("change");
},
},
computed: {
filter() {
return this.$store.getters[`${this.resourceName}/getFilter`](
this.filterKey
);
},
computed: {
filter() {
return this.$store.getters[`${this.resourceName}/getFilter`](
this.filterKey
);
},
fieldAttribute() {
return this.filter.fieldAttribute;
},
fieldAttribute() {
return this.filter.fieldAttribute;
},
value() {
return this.filter.currentValue;
},
value() {
return this.filter.currentValue;
},
},
};
</script>
9 changes: 6 additions & 3 deletions resources/js/filter.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
Nova.booting((Vue, router, store) => {
Vue.component('nova-searchable-belongs-to-filter', require('./components/Filter'))
})
Nova.booting((Vue) => {
Vue.component(
"nova-searchable-belongs-to-filter",
require("./components/Filter").default
);
});
1 change: 0 additions & 1 deletion resources/sass/filter.scss

This file was deleted.

11 changes: 7 additions & 4 deletions webpack.mix.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
let mix = require('laravel-mix')
let mix = require("laravel-mix");

require("./nova.mix");

mix
.setPublicPath('dist')
.js('resources/js/filter.js', 'js')
.sass('resources/sass/filter.scss', 'css')
.setPublicPath("dist")
.js("resources/js/filter.js", "js")
.vue({ version: 3 })
.nova("suenerds/nova-searchable-belongs-to-filter");

0 comments on commit 98b6ae2

Please sign in to comment.