Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
robmpreston committed Jan 14, 2020
1 parent d64b3b3 commit 036c698
Show file tree
Hide file tree
Showing 7 changed files with 1,201 additions and 1,230 deletions.
2 changes: 1 addition & 1 deletion dist/js/field.js

Large diffs are not rendered by default.

17 changes: 9 additions & 8 deletions nova-imports/BelongsToFieldStorage.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
export default {
fetchAvailableResources(resourceName, fieldAttribute, params) {
return Nova.request().get(
`/nova-api/${resourceName}/associatable/${fieldAttribute}`,
params
)
return Nova.request().get(
`/nova-r64-tags/${resourceName}/associatable/${fieldAttribute}`,
params
);
},

determineIfSoftDeletes(resourceName) {
return Nova.request().get(`/nova-api/${resourceName}/soft-deletes`)
},
}
return Nova.request().get(`/nova-api/${resourceName}/soft-deletes`);
}
};

10 changes: 6 additions & 4 deletions resources/js/components/DisplayCommaSeparated.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
export default {
created() {
const values = this.field.value.map(
field => (this.field.labelKey ? field[this.field.labelKey] : field)
);
this.$set(this.field, 'value', values.join(', '));
if (this.field.value) {
const values = this.field.value.map(
field => (this.field.labelKey ? field[this.field.labelKey] : field)
)
this.$set(this.field, 'value', values.join(', '))
}
}
};
6 changes: 6 additions & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

use Illuminate\Support\Facades\Route;

// Associatable Resources...
Route::get('/{resource}/associatable/{field}', 'AssociatableController@index');
21 changes: 21 additions & 0 deletions src/FieldServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Laravel\Nova\Nova;
use Laravel\Nova\Events\ServingNova;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\ServiceProvider;

class FieldServiceProvider extends ServiceProvider
Expand All @@ -19,6 +20,10 @@ public function boot()
Nova::script('nova-fields-tags', __DIR__.'/../dist/js/field.js');
Nova::style('nova-fields-tags', __DIR__.'/../dist/css/field.css');
});

Route::group($this->routeConfiguration(), function () {
$this->loadRoutesFrom(__DIR__.'/../routes/api.php');
});
}

/**
Expand All @@ -30,4 +35,20 @@ public function register()
{
//
}

/**
* Get the Nova route group configuration array.
*
* @return array
*/
protected function routeConfiguration()
{
return [
'namespace' => 'R64\Tags\Http\Controllers',
'domain' => config('nova.domain', null),
'as' => 'nova.r64.tags.',
'prefix' => 'nova-r64-tags',
'middleware' => 'nova',
];
}
}
44 changes: 44 additions & 0 deletions src/Http/Controllers/AssociatableController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace R64\Tags\Http\Controllers;

use Laravel\Nova\Http\Requests\NovaRequest;
use Laravel\Nova\Http\Controllers\AssociatableController as Controller;

class AssociatableController extends Controller
{
/**
* List the available related resources for a given resource.
*
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @return \Illuminate\Http\Response
*/
public function index(NovaRequest $request)
{
$fields = $request->newResource()
->availableFields($request);

$field = $fields->firstWhere('attribute', $request->field);

if(!$field) {
$rowField = $fields->firstWhere('component', 'nova-fields-tags');
$fields = collect($rowField->meta['fields']);
$field = $fields->firstWhere('attribute', $request->field);
}

$withTrashed = $this->shouldIncludeTrashed(
$request, $associatedResource = $field->resourceClass
);

return [
'resources' => $field->buildAssociatableQuery($request, $withTrashed)->get()
->mapInto($field->resourceClass)
->filter->authorizedToAdd($request, $request->model())
->map(function ($resource) use ($request, $field) {
return $field->formatAssociatableResource($request, $resource);
})->sortBy('display')->values(),
'softDeletes' => $associatedResource::softDeletes(),
'withTrashed' => $withTrashed,
];
}
}
Loading

0 comments on commit 036c698

Please sign in to comment.