Skip to content

Commit

Permalink
Merge branch 'master' into prepare-phpstan
Browse files Browse the repository at this point in the history
  • Loading branch information
szepeviktor authored Oct 25, 2023
2 parents a7703fb + 2508e7a commit 9b34faf
Show file tree
Hide file tree
Showing 37 changed files with 441 additions and 282 deletions.
1 change: 0 additions & 1 deletion public/build/assets/app-584e3628.js

This file was deleted.

1 change: 1 addition & 0 deletions public/build/assets/app-5cfcf402.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import{a as f}from"./app-c6af0dee.js";export{f as default};

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions public/build/assets/dropdown-7dc1f3ea.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import"./app-c6af0dee.js";
1 change: 0 additions & 1 deletion public/build/assets/dropdown-b8b60ec8.js

This file was deleted.

1 change: 1 addition & 0 deletions public/build/assets/editor-7dc1f3ea.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import"./app-c6af0dee.js";
1 change: 0 additions & 1 deletion public/build/assets/editor-b8b60ec8.js

This file was deleted.

1 change: 1 addition & 0 deletions public/build/assets/media-manager-7dc1f3ea.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import"./app-c6af0dee.js";
1 change: 0 additions & 1 deletion public/build/assets/media-manager-b8b60ec8.js

This file was deleted.

1 change: 1 addition & 0 deletions public/build/assets/repeater-7dc1f3ea.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import"./app-c6af0dee.js";
1 change: 0 additions & 1 deletion public/build/assets/repeater-b8b60ec8.js

This file was deleted.

12 changes: 6 additions & 6 deletions public/build/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,44 @@
"css": [
"assets/app-4d04387c.css"
],
"file": "assets/app-ef45e7b6.js",
"file": "assets/app-c6af0dee.js",
"isEntry": true,
"src": "resources/js/app.js"
},
"resources/js/dropdown.js": {
"file": "assets/dropdown-b8b60ec8.js",
"file": "assets/dropdown-7dc1f3ea.js",
"imports": [
"resources/js/app.js"
],
"isEntry": true,
"src": "resources/js/dropdown.js"
},
"resources/js/editor.js": {
"file": "assets/editor-b8b60ec8.js",
"file": "assets/editor-7dc1f3ea.js",
"imports": [
"resources/js/app.js"
],
"isEntry": true,
"src": "resources/js/editor.js"
},
"resources/js/media-manager.js": {
"file": "assets/media-manager-b8b60ec8.js",
"file": "assets/media-manager-7dc1f3ea.js",
"imports": [
"resources/js/app.js"
],
"isEntry": true,
"src": "resources/js/media-manager.js"
},
"resources/js/repeater.js": {
"file": "assets/repeater-b8b60ec8.js",
"file": "assets/repeater-7dc1f3ea.js",
"imports": [
"resources/js/app.js"
],
"isEntry": true,
"src": "resources/js/repeater.js"
},
"resources/sass/app.scss": {
"file": "assets/app-584e3628.js",
"file": "assets/app-5cfcf402.js",
"imports": [
"resources/js/app.js"
],
Expand Down
2 changes: 1 addition & 1 deletion resources/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ window.$http = Axios.create({
});

// Cookie
window.$cookie = new Cookie();
window.$cookie = new Cookie('__root_');
4 changes: 2 additions & 2 deletions resources/js/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ document.addEventListener('alpine:init', () => {
window.Alpine.data('theme', () => {
return {
systemMode: window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light',
theme: window.$cookie.get('__root_theme', 'system'),
theme: window.$cookie.get('theme', 'system'),
init() {
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', (event) => {
if (this.theme === 'system') {
Expand All @@ -23,7 +23,7 @@ document.addEventListener('alpine:init', () => {
change(theme) {
document.documentElement.classList.add('no-transition');

window.$cookie.set('__root_theme', theme);
window.$cookie.set('theme', theme);

this.theme = theme;

Expand Down
7 changes: 0 additions & 7 deletions routes/api.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
<?php

use Cone\Root\Http\Controllers\NotificationsController;
use Cone\Root\Http\Controllers\ResourceFieldController;
use Illuminate\Support\Facades\Route;

// Notifications
Route::apiResource('notifications', NotificationsController::class)->except(['store']);

// Resource Fields
Route::any('/{resource}/fields/{field}', ResourceFieldController::class)->where('field', '.*');

// Actions
// Action Fields
52 changes: 27 additions & 25 deletions src/Actions/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@
namespace Cone\Root\Actions;

use Cone\Root\Fields\Field;
use Cone\Root\Http\Controllers\ActionController;
use Cone\Root\Interfaces\Form;
use Cone\Root\Support\Alert;
use Cone\Root\Traits\AsForm;
use Cone\Root\Traits\Authorizable;
use Cone\Root\Traits\Makeable;
use Cone\Root\Traits\RegistersRoutes;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Concerns\HasAttributes;
use Illuminate\Http\Request;
use Illuminate\Routing\Router;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\MessageBag;
use Illuminate\Support\Str;
Expand All @@ -25,6 +28,9 @@ abstract class Action implements Arrayable, Form, JsonSerializable
use Authorizable;
use HasAttributes;
use Makeable;
use RegistersRoutes {
RegistersRoutes::registerRoutes as __registerRoutes;
}

/**
* The Blade template.
Expand All @@ -46,11 +52,6 @@ abstract class Action implements Arrayable, Form, JsonSerializable
*/
protected ?Builder $query = null;

/**
* The API URI.
*/
protected ?string $apiUri = null;

/**
* Handle the action.
*/
Expand Down Expand Up @@ -96,24 +97,6 @@ public function getTemplate(): string
return $this->template;
}

/**
* Set the API URI.
*/
public function setApiUri(string $apiUri): static
{
$this->apiUri = $apiUri;

return $this;
}

/**
* Get the API URI.
*/
public function getApiUri(): ?string
{
return $this->apiUri;
}

/**
* Set the Eloquent query.
*/
Expand All @@ -129,7 +112,6 @@ public function setQuery(Builder $query): static
*/
protected function resolveField(Request $request, Field $field): void
{
$field->setApiUri(sprintf('/%s/fields/%s', $this->getApiUri(), $field->getUriKey()));
$field->setAttribute('form', $this->getKey());
$field->resolveErrorsUsing(function (Request $request): MessageBag {
return $this->errors($request);
Expand Down Expand Up @@ -190,6 +172,26 @@ public function perform(Request $request): Response
);
}

/**
* Register the routes using the given router.
*/
public function registerRoutes(Request $request, Router $router): void
{
$this->__registerRoutes($request, $router);

$router->prefix($this->getUriKey())->group(function (Router $router) use ($request): void {
$this->resolveFields($request)->registerRoutes($request, $router);
});
}

/**
* The routes that should be registered.
*/
public function routes(Router $router): void
{
$router->post('/', ActionController::class);
}

/**
* Convert the element to a JSON serializable format.
*/
Expand All @@ -210,7 +212,7 @@ public function toArray(): array
'modalKey' => $this->getModalKey(),
'name' => $this->getName(),
'template' => $this->getTemplate(),
'url' => $this->getApiUri(),
'url' => $this->getUri(),
];
}

Expand Down
16 changes: 16 additions & 0 deletions src/Actions/Actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Cone\Root\Actions;

use Cone\Root\Traits\RegistersRoutes;
use Illuminate\Http\Request;
use Illuminate\Routing\Router;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;

Expand All @@ -27,4 +29,18 @@ public function mapToTableComponents(Request $request): array
{
return $this->map->toTableComponent($request)->all();
}

/**
* Register the action routes.
*/
public function registerRoutes(Request $request, Router $router): void
{
$router->prefix('actions')->group(function (Router $router) use ($request): void {
$this->each(static function (Action $action) use ($request, $router): void {
if (in_array(RegistersRoutes::class, class_uses_recursive($action))) {
$action->registerRoutes($request, $router);
}
});
});
}
}
14 changes: 9 additions & 5 deletions src/Fields/BelongsToMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public function __construct(string $label, string $modelAttribute = null, Closur
parent::__construct($label, $modelAttribute, $relation);

$this->setAttribute('multiple', true);
$this->name($this->modelAttribute.'[]');
}

/**
Expand All @@ -49,10 +48,8 @@ public function getRelation(Model $model): EloquentRelation
*/
protected function resolveField(Request $request, Field $field): void
{
if (! is_null($this->apiUri)) {
$field->setApiUri(sprintf('%s/%s', $this->apiUri, $field->getUriKey()));
}

$field->setAttribute('form', $this->getAttribute('form'));
$field->resolveErrorsUsing($this->errorsResolver);
$field->setModelAttribute(
sprintf('%s.*.%s', $this->getModelAttribute(), $field->getModelAttribute())
);
Expand Down Expand Up @@ -105,6 +102,13 @@ public function toOption(Request $request, Model $model, Model $related): array

$option = parent::toOption($request, $model, $related);

$option['attrs']['name'] = sprintf(
'%s[%s][%s]',
$this->getAttribute('name'),
$related->getKey(),
$this->getRelation($model)->getRelatedPivotKeyName()
);

$option['fields'] = is_null($this->pivotFieldsResolver)
? new Fields()
: call_user_func_array($this->pivotFieldsResolver, [$request, $model, $related]);
Expand Down
31 changes: 22 additions & 9 deletions src/Fields/Editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@

use Closure;
use Cone\Root\Models\Medium;
use Cone\Root\Traits\RegistersRoutes;
use Cone\Root\Traits\ResolvesFields;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphToMany;
use Illuminate\Http\Request;
use Illuminate\Routing\Router;
use Illuminate\Support\Facades\Config;

class Editor extends Field
{
use RegistersRoutes {
RegistersRoutes::registerRoutes as __registerRoutes;
}
use ResolvesFields;

/**
Expand Down Expand Up @@ -41,17 +46,11 @@ public function __construct(string $label, string $modelAttribute = null)
}

/**
* {@inheritdoc}
* Get the URI key.
*/
public function setApiUri(string $apiUri): static
public function getUriKey(): string
{
if (! is_null($this->media)) {
$this->media->setApiUri(
sprintf('%s/%s', $apiUri, $this->media->getUriKey())
);
}

return parent::setApiUri($apiUri);
return str_replace('.', '-', $this->getRequestKey());
}

/**
Expand Down Expand Up @@ -142,6 +141,20 @@ public function __construct(string $modelAttribute)
};
}

/**
* Register the routes using the given router.
*/
public function registerRoutes(Request $request, Router $router): void
{
$this->__registerRoutes($request, $router);

if (! is_null($this->media)) {
$router->prefix($this->getUriKey())->group(function (Router $router) use ($request): void {
$this->media->registerRoutes($request, $router);
});
}
}

/**
* {@inheritdoc}
*/
Expand Down
Loading

0 comments on commit 9b34faf

Please sign in to comment.