Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Options #222

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
753 changes: 377 additions & 376 deletions composer.lock

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions database/factories/OptionFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Cone\Root\Database\Factories;

use Cone\Root\Models\Option;
use Illuminate\Database\Eloquent\Factories\Factory;

class OptionFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var class-string<\Cone\Root\Models\Option>
*/
protected $model = Option::class;

/**
* Define the model's default state.
*/
public function definition(): array
{
return [
//
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class() extends Migration
return new class extends Migration
{
/**
* Run the migrations.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class() extends Migration
return new class extends Migration
{
/**
* Run the migrations.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class() extends Migration
return new class extends Migration
{
/**
* Run the migrations.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class() extends Migration
return new class extends Migration
{
/**
* Run the migrations.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class() extends Migration
return new class extends Migration
{
/**
* Run the migrations.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('root_options', static function (Blueprint $table): void {
$table->id();
$table->string('key')->unique()->index();
$table->text('value')->nullable();
$table->timestamps();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('root_options');
}
};
4 changes: 4 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use Cone\Root\Http\Controllers\DashboardController;
use Cone\Root\Http\Controllers\DownloadController;
use Cone\Root\Http\Controllers\OptionController;
use Cone\Root\Http\Controllers\ResourceController;
use Illuminate\Support\Facades\Route;

Expand All @@ -11,6 +12,9 @@
// Download
Route::get('/download/{medium:uuid}', DownloadController::class)->name('download');

// Options
Route::get('/options/{group}', [OptionController::class, 'index'])->name('options.index');

// Resource
Route::get('/{resource}', [ResourceController::class, 'index'])->name('resource.index');
Route::get('/{resource}/create', [ResourceController::class, 'create'])->name('resource.create');
Expand Down
27 changes: 21 additions & 6 deletions src/Actions/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Closure;
use Cone\Root\Exceptions\QueryResolutionException;
use Cone\Root\Exceptions\SaveFormDataException;
use Cone\Root\Fields\Field;
use Cone\Root\Fields\Relation;
use Cone\Root\Http\Controllers\ActionController;
Expand All @@ -23,11 +24,13 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
use Illuminate\Routing\Router;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\MessageBag;
use Illuminate\Support\Str;
use JsonSerializable;
use Symfony\Component\HttpFoundation\Response;
use Throwable;

abstract class Action implements Arrayable, Form, JsonSerializable
{
Expand Down Expand Up @@ -108,7 +111,7 @@
public function resolveQuery(Request $request): Builder
{
if (is_null($this->queryResolver)) {
throw new QueryResolutionException();
throw new QueryResolutionException;
}

return call_user_func_array($this->queryResolver, [$request]);
Expand All @@ -132,7 +135,7 @@
$field->setAttribute('form', $this->getKey());
$field->id($this->getKey().'-'.$field->getAttribute('id'));
$field->resolveErrorsUsing(function (Request $request): MessageBag {
return $this->errors($request);

Check failure on line 138 in src/Actions/Action.php

View workflow job for this annotation

GitHub Actions / 3️⃣ Static Analysis

Anonymous function should return Illuminate\Support\MessageBag but returns Illuminate\Contracts\Support\MessageBag.
});

if ($field instanceof Relation) {
Expand Down Expand Up @@ -213,7 +216,7 @@

if (in_array(HasRootEvents::class, class_uses_recursive($model))) {
$models->each(static function (Model $model) use ($request): void {
$model->recordRootEvent(

Check failure on line 219 in src/Actions/Action.php

View workflow job for this annotation

GitHub Actions / 3️⃣ Static Analysis

Call to an undefined method Illuminate\Database\Eloquent\Model::recordRootEvent().
Str::of(static::class)->classBasename()->headline()->value(),
$request->user()
);
Expand All @@ -226,12 +229,24 @@
*/
public function perform(Request $request): Response
{
$this->handleFormRequest($request, $this->resolveQuery($request)->getModel());
try {
DB::beginTransaction();

return Redirect::back()->with(
sprintf('alerts.action-%s', $this->getKey()),
Alert::info(__(':action was successful!', ['action' => $this->getName()]))
);
$this->handleFormRequest($request, $this->resolveQuery($request)->getModel());

return Redirect::back()->with(
sprintf('alerts.action-%s', $this->getKey()),
Alert::info(__(':action was successful!', ['action' => $this->getName()]))
);

DB::commit();

Check failure on line 242 in src/Actions/Action.php

View workflow job for this annotation

GitHub Actions / 3️⃣ Static Analysis

Unreachable statement - code above always terminates.
} catch (Throwable $exception) {
report($exception);

DB::rollBack();

throw new SaveFormDataException($exception->getMessage());
}
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/Breadcrumbs/Registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
namespace Cone\Root\Breadcrumbs;

use Closure;
use Cone\Root\Interfaces\Breadcrumbs\Registry as Contract;
use Illuminate\Http\Request;
use Illuminate\Routing\Route;

class Registry
class Registry implements Contract
{
/**
* The registered patterns.
Expand Down
2 changes: 1 addition & 1 deletion src/Fields/BelongsToMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
$this->withFields($callback);

$this->pivotFieldsResolver = function (Request $request, Model $model, Model $related) use ($callback): Fields {
$fields = new Fields();
$fields = new Fields;

$fields->register(Arr::wrap(call_user_func_array($callback, [$request])));

Expand Down Expand Up @@ -221,7 +221,7 @@
*/
public function resolveRouteBinding(Request $request, string $id): Model
{
$relation = $this->getRelation($request->route()->parentOfParameter($this->getRouteKeyName()));

Check failure on line 224 in src/Fields/BelongsToMany.php

View workflow job for this annotation

GitHub Actions / 3️⃣ Static Analysis

Parameter #1 $model of method Cone\Root\Fields\BelongsToMany<TRelation of Illuminate\Database\Eloquent\Relations\BelongsToMany>::getRelation() expects Illuminate\Database\Eloquent\Model, string|null given.

$related = $relation->wherePivot($relation->newPivot()->getQualifiedKeyName(), $id)->firstOrFail();

Expand Down
4 changes: 2 additions & 2 deletions src/Fields/Editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function getConfig(): array
public function withMedia(?Closure $callback = null): static
{
if (is_null($this->fields)) {
$this->fields = new Fields();
$this->fields = new Fields;
}

if (is_null($this->media)) {
Expand Down Expand Up @@ -122,7 +122,7 @@ public function __construct(string $modelAttribute)
parent::__construct(__('Media'), $modelAttribute.'-media', static function (): MorphToMany {
return new MorphToMany(
Medium::proxy()->newQuery(),
new class() extends Model
new class extends Model
{
//
},
Expand Down
2 changes: 1 addition & 1 deletion src/Fields/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ public function resolveErrorsUsing(Closure $callback): static
public function resolveErrors(Request $request): MessageBag
{
return is_null($this->errorsResolver)
? $request->session()->get('errors', new ViewErrorBag())->getBag('default')
? $request->session()->get('errors', new ViewErrorBag)->getBag('default')
: call_user_func_array($this->errorsResolver, [$request]);
}

Expand Down
6 changes: 3 additions & 3 deletions src/Fields/Media.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function multiple(bool $value = true): static
*/
public function getModel(): Model
{
return $this->model ?: new class() extends Model
return $this->model ?: new class extends Model
{
use HasMedia;
};
Expand All @@ -80,7 +80,7 @@ public function fields(Request $request): array
public function filters(Request $request): array
{
return [
new MediaSearch(),
new MediaSearch,
];
}

Expand Down Expand Up @@ -147,7 +147,7 @@ public function store(Request $request, Model $model, UploadedFile $file): array
$disk->append($file->getClientOriginalName(), $file->get());

if ($request->header('X-Chunk-Index') !== $request->header('X-Chunk-Total')) {
return array_merge($this->toOption($request, $model, new Medium()), [
return array_merge($this->toOption($request, $model, new Medium), [
'processing' => true,
'fileName' => null,
]);
Expand Down
4 changes: 2 additions & 2 deletions src/Fields/Repeater.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public function withFields(Closure $callback): static
public function resolveOptionFields(Request $request, Model $model, Model $tmpModel): Fields
{
return is_null($this->optionFieldsResolver)
? new Fields()
? new Fields
: call_user_func_array($this->optionFieldsResolver, [$request, $model, $tmpModel]);
}

Expand All @@ -167,7 +167,7 @@ public function resolveOptionFields(Request $request, Model $model, Model $tmpMo
*/
public function newTemporaryModel(array $attributes = []): Model
{
$model = new class() extends Model
$model = new class extends Model
{
//
};
Expand Down
2 changes: 1 addition & 1 deletion src/Filters/MediaSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function __construct(array $attributes = ['file_name'])
{
$this->attributes = $attributes;

parent::__construct(new Fields());
parent::__construct(new Fields);
}

/**
Expand Down
19 changes: 19 additions & 0 deletions src/Http/Controllers/OptionController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Cone\Root\Http\Controllers;

class OptionController extends Controller
{
/**
* Create a new controller instance.
*/
public function __construct()
{
//
}

public function index()
{
//
}
}
24 changes: 24 additions & 0 deletions src/Interfaces/Breadcrumbs/Registry.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Cone\Root\Interfaces\Breadcrumbs;

use Closure;
use Illuminate\Http\Request;

interface Registry
{
/**
* Register a set of patterns.
*/
public function patterns(array $patterns): void;

/**
* Register a pattern.
*/
public function pattern(string $pattern, Closure|string $label): void;

/**
* Resolve the breadcrumbs using the given request.
*/
public function resolve(Request $request): array;
}
8 changes: 8 additions & 0 deletions src/Interfaces/Models/Option.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Cone\Root\Interfaces\Models;

interface Option
{
//
}
18 changes: 18 additions & 0 deletions src/Interfaces/Navigation/Registry.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Cone\Root\Interfaces\Navigation;

use Cone\Root\Navigation\Location;

interface Registry
{
/**
* Get or register a new the location.
*/
public function location(string $name): Location;

/**
* Get the registered. locations
*/
public function locations(): array;
}
18 changes: 18 additions & 0 deletions src/Interfaces/Options/Registry.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Cone\Root\Interfaces\Options;

use Cone\Root\Options\Group;

interface Registry
{
/**
* Get or create a new group.
*/
public function group(string $name): Group;

/**
* Get the option groups.
*/
public function groups(): array;
}
Loading
Loading