Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgergo committed Dec 26, 2023
1 parent c3f434e commit c6176b2
Show file tree
Hide file tree
Showing 33 changed files with 986 additions and 224 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@
"stylelint-config-sass-guidelines": "^10.0.0"
},
"engines": {
"node": "^18.0 || ^19.0 || ^20.0"
"node": "^18.0 || ^19.0 || ^20.0 || ^21.0"
}
}
142 changes: 0 additions & 142 deletions public/build/assets/app-33c235a1.js

This file was deleted.

841 changes: 841 additions & 0 deletions public/build/assets/app-34baaef9.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion public/build/assets/app-8666ab41.js

This file was deleted.

1 change: 1 addition & 0 deletions public/build/assets/app-8c4d86f4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import{a as f}from"./app-34baaef9.js";export{f as default};
1 change: 1 addition & 0 deletions public/build/assets/chart-ca6a94d4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import"./app-34baaef9.js";
1 change: 0 additions & 1 deletion public/build/assets/dropdown-180e6571.js

This file was deleted.

1 change: 1 addition & 0 deletions public/build/assets/dropdown-ca6a94d4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import"./app-34baaef9.js";
1 change: 0 additions & 1 deletion public/build/assets/editor-180e6571.js

This file was deleted.

1 change: 1 addition & 0 deletions public/build/assets/editor-ca6a94d4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import"./app-34baaef9.js";
1 change: 0 additions & 1 deletion public/build/assets/media-manager-180e6571.js

This file was deleted.

1 change: 1 addition & 0 deletions public/build/assets/media-manager-ca6a94d4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import"./app-34baaef9.js";
1 change: 0 additions & 1 deletion public/build/assets/repeater-180e6571.js

This file was deleted.

1 change: 1 addition & 0 deletions public/build/assets/repeater-ca6a94d4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import"./app-34baaef9.js";
1 change: 0 additions & 1 deletion public/build/assets/table-180e6571.js

This file was deleted.

1 change: 1 addition & 0 deletions public/build/assets/table-ca6a94d4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import"./app-34baaef9.js";
22 changes: 15 additions & 7 deletions public/build/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,52 +7,60 @@
"css": [
"assets/app-d00ef1bd.css"
],
"file": "assets/app-33c235a1.js",
"file": "assets/app-34baaef9.js",
"isEntry": true,
"src": "resources/js/app.js"
},
"resources/js/chart.js": {
"file": "assets/chart-ca6a94d4.js",
"imports": [
"resources/js/app.js"
],
"isEntry": true,
"src": "resources/js/chart.js"
},
"resources/js/dropdown.js": {
"file": "assets/dropdown-180e6571.js",
"file": "assets/dropdown-ca6a94d4.js",
"imports": [
"resources/js/app.js"
],
"isEntry": true,
"src": "resources/js/dropdown.js"
},
"resources/js/editor.js": {
"file": "assets/editor-180e6571.js",
"file": "assets/editor-ca6a94d4.js",
"imports": [
"resources/js/app.js"
],
"isEntry": true,
"src": "resources/js/editor.js"
},
"resources/js/media-manager.js": {
"file": "assets/media-manager-180e6571.js",
"file": "assets/media-manager-ca6a94d4.js",
"imports": [
"resources/js/app.js"
],
"isEntry": true,
"src": "resources/js/media-manager.js"
},
"resources/js/repeater.js": {
"file": "assets/repeater-180e6571.js",
"file": "assets/repeater-ca6a94d4.js",
"imports": [
"resources/js/app.js"
],
"isEntry": true,
"src": "resources/js/repeater.js"
},
"resources/js/table.js": {
"file": "assets/table-180e6571.js",
"file": "assets/table-ca6a94d4.js",
"imports": [
"resources/js/app.js"
],
"isEntry": true,
"src": "resources/js/table.js"
},
"resources/sass/app.scss": {
"file": "assets/app-8666ab41.js",
"file": "assets/app-8c4d86f4.js",
"imports": [
"resources/js/app.js"
],
Expand Down
16 changes: 7 additions & 9 deletions resources/js/chart.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import ApexCharts from 'apexcharts';

document.addEventListener('alpine:init', () => {
window.Alpine.data('chart', (config) => {
return {
init() {
const chart = new ApexCharts(this.$el, config);
Alpine.data('chart', (config) => {
return {
init() {
const chart = new ApexCharts(this.$el, config);

chart.render();
},
};
});
chart.render();
},
};
});
12 changes: 12 additions & 0 deletions resources/views/components/chart.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@if(! empty($config))
<div x-data="chart({{ json_encode($config) }})"></div>
@endif

{{-- Script --}}
@pushOnce('scripts')
{{
Vite::withEntryPoints('resources/js/chart.js')
->useBuildDirectory('vendor/root/build')
->useHotFile(public_path('vendor/root/hot'))
}}
@endpushOnce
2 changes: 0 additions & 2 deletions resources/views/fields/editor.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ class="form-group--row form-group--row:vertical-start"
@endif
</div>

{{-- Modal --}}

{{-- Script --}}
@pushOnce('scripts')
{{
Expand Down
2 changes: 1 addition & 1 deletion resources/views/resources/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
@if(! empty($widgets))
<div class="l-row l-row--column:sm:2 l-row--column:lg:3">
@foreach($widgets as $widget)
@include('root::widgets.pending-widget', $widget)
@include($widget['template'], $widget)
@endforeach
</div>
@endif
Expand Down
17 changes: 0 additions & 17 deletions resources/views/widgets/pending-trend-widget.blade.php

This file was deleted.

8 changes: 0 additions & 8 deletions resources/views/widgets/pending-widget.blade.php

This file was deleted.

8 changes: 5 additions & 3 deletions resources/views/widgets/trend.blade.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<turbo-frame id="widget-{{ $key }}">
<turbo-frame id="widget-{{ $key }}" @if(! $isTurbo) src="{{ $url }}" @endif>
<div {{ $attrs }}>
<div class="app-widget__column">
<h2 class="app-widget__title">
{{ $name }}
</h2>
<p class="app-widget__data">65</p>
@if(! is_null($data['value']))
<p class="app-widget__data">{{ $value }}</p>
@endif
</div>
<div class="app-widget__chart">
<div x-data="trend({{ json_encode($config) }})"></div>
<x-root::chart :config="$data['chart']" />
</div>
</div>
</turbo-frame>
26 changes: 14 additions & 12 deletions resources/views/widgets/value.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<turbo-frame id="widget-{{ $key }}">
<turbo-frame id="widget-{{ $key }}" @if(! $isTurbo) src="{{ $url }}" @endif>
<div {{ $attrs }}>
@if(! is_null($icon))
<div class="app-widget__icon">
Expand All @@ -9,17 +9,19 @@
<h2 class="app-widget__title">
{{ $name }}
</h2>
<p class="app-widget__data">{{ $data['current'] }}</p>
@if($data['trend'] < 0)
<div class="trending trending--down app-widget__trending">
<span class="trending__caption">{{ $data['trend'] }}%</span>
<x-root::icon name="trending-down" class="trending__icon" />
</div>
@elseif($data['trend'] > 0)
<div class="trending trending--up app-widget__trending">
<span class="trending__caption">+{{ $data['trend'] }}%</span>
<x-root::icon name="trending-up" class="trending__icon" />
</div>
@if(! empty($data))
<p class="app-widget__data">{{ $data['current'] }}</p>
@if($data['trend'] < 0)
<div class="trending trending--down app-widget__trending">
<span class="trending__caption">{{ $data['trend'] }}%</span>
<x-root::icon name="trending-down" class="trending__icon" />
</div>
@elseif($data['trend'] > 0)
<div class="trending trending--up app-widget__trending">
<span class="trending__caption">+{{ $data['trend'] }}%</span>
<x-root::icon name="trending-up" class="trending__icon" />
</div>
@endif
@endif
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/widgets/widget.blade.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<turbo-frame id="widget-{{ $key }}">
<turbo-frame id="widget-{{ $key }}" @if(! $isTurbo) src="{{ $url }}" @endif>
<div {{ $attrs }}></div>
</turbo-frame>
4 changes: 2 additions & 2 deletions src/Resources/Resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ public function toIndex(Request $request): array
'widgets' => $this->resolveWidgets($request)
->authorized($request)
->visible('index')
->toArray(),
->mapToDisplay($request),
'perPageOptions' => $this->getPerPageOptions(),
'perPageKey' => $this->getPerPageKey(),
'sortKey' => $this->getSortKey(),
Expand Down Expand Up @@ -490,7 +490,7 @@ public function toShow(Request $request, Model $model): array
'widgets' => $this->resolveWidgets($request)
->authorized($request, $model)
->visible('show')
->toArray(),
->mapToDisplay($request),
'relations' => $this->resolveFields($request)
->subResource()
->authorized($request, $model)
Expand Down
32 changes: 32 additions & 0 deletions src/View/Components/Chart.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Cone\Root\View\Components;

use Illuminate\View\Component;
use Illuminate\View\View;

class Chart extends Component
{
/**
* The icon name.
*/
protected array $config = [];

/**
* Create a new component instance.
*/
public function __construct(array $config = [])
{
$this->config = $config;
}

/**
* Get the view / view contents that represent the component.
*/
public function render(): View
{
return $this->view('root::components.chart', [
'config' => $this->config,
]);
}
}
12 changes: 11 additions & 1 deletion src/Widgets/Metric.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public function data(Request $request): array
{
return array_merge(parent::data($request), [
'ranges' => $this->ranges(),
'data' => $this->calculate($request)->toArray(),
'data' => $request->hasHeader('Turbo-Frame') ? $this->calculate($request)->toArray() : [],
]);
}

Expand Down Expand Up @@ -206,4 +206,14 @@ public function calculate(Request $request): Result
{
return $this->count($request, $this->resolveQuery($request));
}

/**
* {@inheritdoc}
*/
public function toArray(): array
{
return array_merge(parent::toArray(), [
'data' => [],
]);
}
}
13 changes: 12 additions & 1 deletion src/Widgets/Results/TrendResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ public function __construct(array $data)
*/
public function toArray(): array
{
return $this->data;
return [
'current' => array_sum($this->data),
'chart' => [
'series' => [
[
'name' => __('Value'),
'data' => array_values($this->data),
],
],
'labels' => array_keys($this->data),
],
];
}
}
24 changes: 14 additions & 10 deletions src/Widgets/Trend.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,20 @@ protected function format(string $interval): string
};
}

/**
* Get the data.
*/
public function data(Request $request): array
{
return array_replace_recursive([
'ranges' => $this->ranges(),
'data' => [
'chart' => $request->hasHeader('Turbo-Frame') ? $this->config : [],
'value' => null,
],
], parent::data($request));
}

/**
* Convert the query to result.
*/
Expand All @@ -217,14 +231,4 @@ public function toResult(Request $request, Builder $query): TrendResult
array_replace($dates, $data)
);
}

/**
* {@inheritdoc}
*/
public function toArray(): array
{
return array_merge(parent::toArray(), [
'config' => $this->config,
]);
}
}
4 changes: 3 additions & 1 deletion src/Widgets/Widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ public function render(): View
*/
public function data(Request $request): array
{
return $this->toArray();
return array_merge($this->toArray(), [
'isTurbo' => $request->hasHeader('Turbo-Frame'),
]);
}

/**
Expand Down
8 changes: 8 additions & 0 deletions src/Widgets/Widgets.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ public function visible(string|array $context): static
return $this->filter->visible($context)->values();
}

/**
* Map the widgets to display.
*/
public function mapToDisplay(Request $request): array
{
return $this->map->data($request)->all();
}

/**
* Register the widget routes.
*/
Expand Down

0 comments on commit c6176b2

Please sign in to comment.