Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgergo committed Jan 1, 2024
1 parent b0b2813 commit 4526d92
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 25 deletions.
6 changes: 2 additions & 4 deletions src/Fields/Relation.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Cone\Root\Interfaces\Form;
use Cone\Root\Root;
use Cone\Root\Traits\AsForm;
use Cone\Root\Traits\InteractsWithTurbo;
use Cone\Root\Traits\RegistersRoutes;
use Cone\Root\Traits\ResolvesActions;
use Cone\Root\Traits\ResolvesFields;
Expand All @@ -29,7 +28,6 @@
abstract class Relation extends Field implements Form
{
use AsForm;
use InteractsWithTurbo;
use RegistersRoutes {
RegistersRoutes::registerRoutes as __registerRoutes;
}
Expand Down Expand Up @@ -497,7 +495,7 @@ public function paginate(Request $request, Model $model): LengthAwarePaginator
->with($this->with)
->withCount($this->withCount)
->latest()
->paginate($request->input($this->getPerPageKey(), $this->isTurboFrameRequest($request) ? 5 : $relation->getRelated()->getPerPage()))
->paginate($request->input($this->getPerPageKey(), $request->isTurboFrameRequest() ? 5 : $relation->getRelated()->getPerPage()))
->withQueryString();
}

Expand Down Expand Up @@ -662,7 +660,7 @@ public function toSubResource(Request $request, Model $model): array
public function toIndex(Request $request, Model $model): array
{
return array_merge($this->toSubResource($request, $model), [
'template' => $this->isTurboFrameRequest($request) ? 'root::resources.relation' : 'root::resources.index',
'template' => $request->isTurboFrameRequest() ? 'root::resources.relation' : 'root::resources.index',
'title' => $this->label,
'model' => $this->getRelation($model)->make(),
'modelName' => $this->getRelatedName(),
Expand Down
4 changes: 4 additions & 0 deletions src/RootServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ public function register(): void
$this->app->booted(static function (Application $app): void {
$app->make(Root::class)->boot();
});

$this->app['request']->macro('isTurboFrameRequest', function (): bool {
return $this->hasHeader('Turbo-Frame');
});
}

/**
Expand Down
16 changes: 0 additions & 16 deletions src/Traits/InteractsWithTurbo.php

This file was deleted.

2 changes: 1 addition & 1 deletion src/Widgets/Metric.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public function data(Request $request): array
{
return array_merge(parent::data($request), [
'ranges' => $this->ranges(),
'data' => ! $this->async || $this->isTurboFrameRequest($request) ? $this->calculate($request) : [],
'data' => ! $this->async || $request->isTurboFrameRequest() ? $this->calculate($request) : [],
]);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Widgets/Trend.php
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ public function data(Request $request): array
{
return array_replace_recursive([
'data' => [
'chart' => $this->isTurboFrameRequest($request) ? $this->config : [],
'chart' => $request->isTurboFrameRequest() ? $this->config : [],
'current' => null,
],
], parent::data($request));
Expand Down
4 changes: 1 addition & 3 deletions src/Widgets/Widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Cone\Root\Http\Controllers\WidgetController;
use Cone\Root\Traits\Authorizable;
use Cone\Root\Traits\HasAttributes;
use Cone\Root\Traits\InteractsWithTurbo;
use Cone\Root\Traits\Makeable;
use Cone\Root\Traits\RegistersRoutes;
use Cone\Root\Traits\ResolvesVisibility;
Expand All @@ -18,7 +17,6 @@ abstract class Widget implements Arrayable
{
use Authorizable;
use HasAttributes;
use InteractsWithTurbo;
use Makeable;
use RegistersRoutes;
use ResolvesVisibility;
Expand Down Expand Up @@ -71,7 +69,7 @@ public function getUriKey(): string
public function data(Request $request): array
{
return array_merge($this->toArray(), [
'isTurbo' => $this->isTurboFrameRequest($request),
'isTurbo' => $request->isTurboFrameRequest(),
]);
}

Expand Down
78 changes: 78 additions & 0 deletions tests/Fields/RelationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

namespace Cone\Root\Tests\Fields;

use Cone\Root\Fields\HasMany;
use Cone\Root\Tests\TestCase;

class RelationTest extends TestCase
{
protected HasMany $field;

public function setUp(): void
{
parent::setUp();

$this->field = new HasMany('User');
}

public function test_a_relation_resolves_model_relation(): void
{
$this->assertTrue(true);
}

public function test_a_relation_resolves_relatable_query(): void
{
$this->assertTrue(true);
}

public function test_a_relation_can_be_a_subresource(): void
{
$this->assertTrue(true);
}

public function test_a_relation_can_be_nullable(): void
{
$this->assertTrue(true);
}

public function test_a_relation_can_be_searchable(): void
{
$this->assertTrue(true);
}

public function test_a_relation_can_be_sortable(): void
{
$this->assertTrue(true);
}

public function test_a_relation_displays_relatable(): void
{
$this->assertTrue(true);
}

public function test_a_relation_gets_relation_value(): void
{
$this->assertTrue(true);
}

public function test_a_relation_resolves_format(): void
{
$this->assertTrue(true);
}

public function test_a_relation_resolves_filters(): void
{
$this->assertTrue(true);
}

public function test_a_relation_resolves_fields(): void
{
$this->assertTrue(true);
}

public function test_a_relation_resolves_actions(): void
{
$this->assertTrue(true);
}
}

0 comments on commit 4526d92

Please sign in to comment.