Skip to content
This repository has been archived by the owner on Oct 18, 2022. It is now read-only.

Commit

Permalink
Update with changes previously made on my old fork to version 1.2.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikebronner committed Sep 1, 2020
1 parent 5e1bc47 commit 485d0b7
Show file tree
Hide file tree
Showing 14 changed files with 107 additions and 8,148 deletions.
16 changes: 0 additions & 16 deletions .editorconfig

This file was deleted.

20 changes: 0 additions & 20 deletions .eslintrc

This file was deleted.

6 changes: 0 additions & 6 deletions .prettierrc

This file was deleted.

1 change: 0 additions & 1 deletion .styleci.yml

This file was deleted.

26 changes: 21 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,41 @@
"homepage": "https://github.com/alexbowers/nova-prepopulate-searchable",
"license": "MIT",
"authors": [
{
"name": "Mike Bronner",
"email": "hello@genealabs.com",
"role": "Developer"
},
{
"name": "Alex Bowers",
"email": "bowersbros@gmail.com",
"role": "Developer"
"role": "Original Creator"
}
],
"repositories": [
{
"type": "composer",
"url": "https://nova.laravel.com"
}
],
"require": {
"php": ">=7.1.0",
"laravel/nova": ">=1.0.13"
"php": "^7.3",
"laravel/nova": ">=2.0.7"
},
"require-dev": {
"phpmd/phpmd": "^2.7",
"sebastian/phpcpd": "^5.0",
"squizlabs/php_codesniffer": "^3.4"
},
"autoload": {
"psr-4": {
"AlexBowers\\NovaPrepopulateSearchable\\": "src/"
"GeneaLabs\\NovaPrepopulateSearchable\\": "src/"
}
},
"extra": {
"laravel": {
"providers": [
"AlexBowers\\NovaPrepopulateSearchable\\ToolServiceProvider"
"GeneaLabs\\NovaPrepopulateSearchable\\ToolServiceProvider"
]
}
},
Expand Down
2 changes: 1 addition & 1 deletion dist/js/tool.js

Large diffs are not rendered by default.

20 changes: 5 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,17 @@
"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",
"check-format": "prettier --list-different 'resources/**/*.{css,js,vue}'",
"format": "prettier --write 'resources/**/*.{css,js,vue}'",
"lint": "eslint resources/js --fix --ext js,vue"
"watch-poll": "npm run watch -- --watch-poll",
"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"
},
"devDependencies": {
"cross-env": "^5.0.0",
"eslint": "^4.19.1",
"eslint-config-prettier": "^2.9.0",
"eslint-plugin-vue": "^4.4.0",
"laravel-mix": "^1.0",
"prettier": "^1.14.0"
},
"dependencies": {
"animated-scroll-to": "^1.2.2",
"laravel-nova": "^1.0.3",
"laravel-mix": "^4.0",
"laravel-nova": "^1.0",
"vue": "^2.5.0",
"vue-clickaway": "^2.2.2"
"vue-template-compiler": "^2.6.10"
}
}
11 changes: 11 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="PHP_CodeSniffer" xsi:noNamespaceSchemaLocation="phpcs.xsd">
<description>GeneaLabs coding standards.</description>

<rule ref="PSR1"></rule>
<rule ref="PSR2"></rule>
<rule ref="PSR12">
<exclude name="PSR12.Classes.ClassInstantiation.MissingParentheses"/>
<exclude name="PSR12.Functions.ReturnTypeDeclaration.SpaceBeforeColon"/>
</rule>
</ruleset>
22 changes: 0 additions & 22 deletions phpunit.xml.dist

This file was deleted.

76 changes: 43 additions & 33 deletions resources/js/components/Tool.vue
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<template>
<default-field :field="field">
<default-field :field="field" :errors="errors">
<template slot="field">
<search-input
v-if="isSearchable && !isLocked"
:data-testid="`${field.resourceName}-search-input`"
@input="performSearch"
:data="availableResources"
:error="hasError"
:value="selectedResource"
@clear="clearSelection"
@input="performSearch"
@selected="selectResource"
:error="hasError"
:value='selectedResource'
:data='availableResources'
trackBy='value'
searchBy='display'
class="mb-3"
searchBy="display"
trackBy="value"
v-if="isSearchable && ! isLocked && ! isReadOnly"
>
<div slot="default" v-if="selectedResource" class="flex items-center">
<div v-if="selectedResource.avatar" class="mr-3">
Expand All @@ -31,16 +31,19 @@
</div>
</search-input>

<select
v-if="!isSearchable || isLocked"
<select-control
v-if="!isSearchable || isLocked || isReadOnly"
class="form-control form-select mb-3 w-full"
:class="{ 'border-danger': hasError }"
:data-testid="`${field.resourceName}-select`"
:dusk="field.attribute"
@change="selectResourceFromSelectControl"
:disabled="isLocked"
:disabled="isLocked || isReadOnly"
:options="availableResources"
:selected="selectedResourceId"
label="display"
>
<option value="" disabled selected>{{__('Choose')}} {{ field.name }}</option>
<option value="" selected :disabled="!field.nullable">&mdash;</option>

<option
v-for="resource in availableResources"
Expand All @@ -50,22 +53,18 @@
>
{{ resource.display}}
</option>
</select>
</select-control>

<!-- Trashed State -->
<div v-if="softDeletes && !isLocked">
<label class="flex items-center" @input="toggleWithTrashed" @keydown.prevent.space.enter="toggleWithTrashed">
<checkbox :dusk="field.resourceName + '-with-trashed-checkbox'" :checked="withTrashed" />

<span class="ml-2">
{{__('With Trashed')}}
</span>
</label>
<checkbox-with-label
:dusk="`${field.resourceName}-with-trashed-checkbox`"
:checked="withTrashed"
@change="toggleWithTrashed"
>
{{ __('With Trashed') }}
</checkbox-with-label>
</div>

<p v-if="hasError" class="my-2 text-danger">
{{ firstError }}
</p>
</template>
</default-field>
</template>
Expand All @@ -74,12 +73,12 @@
import _ from 'lodash'
import storage from '@/storage/BelongsToFieldStorage'
import { TogglesTrashed, PerformsSearches, HandlesValidationErrors } from 'laravel-nova'
import { mixin as clickaway } from 'vue-clickaway'
export default {
mixins: [TogglesTrashed, PerformsSearches, HandlesValidationErrors],
props: {
resourceName: String,
resourceId: {},
field: Object,
viaResource: {},
viaResourceId: {},
Expand Down Expand Up @@ -142,11 +141,11 @@ export default {
this.getAvailableResources()
}
if (this.isSearchable && this.shouldPrepopulate) {
if (this.isSearchable && this.shouldPrepopulate) {
if (this.field.prepopulate_query) {
this.search = this.field.prepopulate_query;
}
this.hasPerformedPrepopulation = true;
this.getAvailableResources()
this.search = '';
Expand All @@ -169,10 +168,12 @@ export default {
* Fill the forms formData with details from this field
*/
fill(formData) {
if (this.selectedResource) {
formData.append(this.field.attribute, this.selectedResource.value)
formData.append(this.field.attribute + '_trashed', this.withTrashed)
}
formData.append(
this.field.attribute,
this.selectedResource ? this.selectedResource.value : ''
)
formData.append(this.field.attribute + '_trashed', this.withTrashed)
},
/**
Expand Down Expand Up @@ -244,7 +245,11 @@ export default {
* Determine if we are creating a new resource via a parent relation
*/
creatingViaRelatedResource() {
return this.viaResource == this.field.resourceName && this.viaResourceId
return (
this.viaResource == this.field.resourceName &&
this.field.reverse &&
this.viaResourceId
)
},
/**
Expand Down Expand Up @@ -275,12 +280,17 @@ export default {
first: this.initializingWithExistingResource,
search: this.search,
withTrashed: this.withTrashed,
resourceId: this.resourceId,
},
}
},
isLocked() {
return this.viaResource == this.field.resourceName
return this.viaResource == this.field.resourceName && this.field.reverse
},
isReadonly() {
return this.field.readonly || _.get(this.field, 'extraAttributes.readonly')
},
},
}
Expand Down
12 changes: 12 additions & 0 deletions resources/js/storage/BelongsToFieldStorage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export default {
fetchAvailableResources(resourceName, fieldAttribute, params) {
return Nova.request().get(
`/nova-api/${resourceName}/associatable/${fieldAttribute}`,
params
)
},

determineIfSoftDeletes(resourceName) {
return Nova.request().get(`/nova-api/${resourceName}/soft-deletes`)
},
}
13 changes: 4 additions & 9 deletions src/ToolServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
<?php

namespace AlexBowers\NovaPrepopulateSearchable;
namespace GeneaLabs\NovaPrepopulateSearchable;

use Laravel\Nova\Nova;
use Laravel\Nova\Events\ServingNova;
use Illuminate\Support\ServiceProvider;
use Laravel\Nova\Events\ServingNova;
use Laravel\Nova\Fields\BelongsTo;
use Laravel\Nova\Nova;

class ToolServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
public function boot() : void
{
Nova::serving(function (ServingNova $event) {
BelongsTo::macro('prepopulate', function ($query = null) {
Expand Down
17 changes: 10 additions & 7 deletions webpack.mix.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
let mix = require('laravel-mix')
let mix = require('laravel-mix');

mix.js('resources/js/tool.js', 'dist/js').webpackConfig({
resolve: {
alias: {
'@': path.resolve(__dirname, 'vendor/laravel/nova/resources/js/'),
mix
.js('resources/js/tool.js', 'dist/js')
.webpackConfig({
resolve: {
alias: {
'@': path.resolve(__dirname, 'vendor/laravel/nova/resources/js/'),
},
},
},
});
})
;
Loading

0 comments on commit 485d0b7

Please sign in to comment.