Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgergo committed Dec 18, 2024
1 parent 5893279 commit 1d832fd
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion resources/views/dashboard.blade.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@extends('root::app')

{{-- Title --}}
@section('title', 'Dashboard')
@section('title', __('Dashboard'))

{{-- Content --}}
@section('content')
Expand Down
12 changes: 12 additions & 0 deletions src/Resources/Resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
use Cone\Root\Traits\ResolvesFilters;
use Cone\Root\Traits\ResolvesWidgets;
use Cone\Root\Traits\Translatable;
use Cone\Root\Widgets\Metric;
use Cone\Root\Widgets\Widget;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Contracts\Support\MessageBag;
Expand Down Expand Up @@ -422,6 +424,16 @@ protected function resolveAction(Request $request, Action $action): void
$action->withQuery(fn (): Builder => $this->resolveFilteredQuery($request));
}

/**
* Handle the callback for the widget resolution.
*/
protected function resolveWidget(Request $request, Widget $widget): void
{
if ($widget instanceof Metric) {
$widget->withQuery(fn (): Builder => $this->resolveQuery($request));
}
}

/**
* Get the per page options.
*/
Expand Down
14 changes: 4 additions & 10 deletions src/Widgets/Metric.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Cone\Root\Widgets;

use Closure;
use Cone\Root\Exceptions\QueryResolutionException;
use DateInterval;
use DatePeriod;
use DateTime;
Expand All @@ -27,23 +28,16 @@ abstract class Metric extends Widget
*/
protected ?Closure $queryResolver = null;

/**
* Create a new Eloquent query.
*/
abstract public function query(): Builder;

/**
* Resolve the query.
*/
public function resolveQuery(Request $request): Builder
{
$query = $this->query();

if (! is_null($this->queryResolver)) {
call_user_func_array($this->queryResolver, [$request, $query]);
if (is_null($this->queryResolver)) {
throw new QueryResolutionException;
}

return $query;
return call_user_func_array($this->queryResolver, [$request]);
}

/**
Expand Down
1 change: 1 addition & 0 deletions stubs/Trend.stub
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace {{ namespace }};

use Cone\Root\Widgets\Trend;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Http\Request;

class {{ class }} extends Trend
Expand Down
1 change: 1 addition & 0 deletions stubs/Value.stub
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace {{ namespace }};

use Cone\Root\Widgets\Value;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Http\Request;

class {{ class }} extends Value
Expand Down

0 comments on commit 1d832fd

Please sign in to comment.