Skip to content

Commit

Permalink
Add more widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
Baspa committed Aug 26, 2024
1 parent 2323ef9 commit d1b0340
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 5 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ ForecastForStationWidget::make([

![Forecast report](./docs/forecast-report.png)

### Forecast short term

![Forecast short term](./docs/forecast-short-term.png)

### Forecast long term

![Forecast long term](./docs/forecast-long-term.png)

## Testing

```bash
Expand Down
18 changes: 18 additions & 0 deletions resources/views/widgets/forecast-long-term.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<x-filament-widgets::widget>
<x-filament::section>
<div class="p-4 space-y-4">
@if ($forecast)
<h2 class="text-xl font-bold">Long-Term Forecast</h2>
<div class="flex justify-between text-sm text-gray-500">
<span>From: {{ \Carbon\Carbon::parse($forecast['startdate'])->format('d M Y') }}</span>
<span>To: {{ \Carbon\Carbon::parse($forecast['enddate'])->format('d M Y') }}</span>
</div>
<div class="prose max-w-none">
{!! nl2br(new Illuminate\Support\HtmlString($forecast['forecast'])) !!}
</div>
@else
<p>No long-term forecast available.</p>
@endif
</div>
</x-filament::section>
</x-filament-widgets::widget>
2 changes: 1 addition & 1 deletion resources/views/widgets/forecast-report.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{{ \Carbon\Carbon::parse($forecast['published'])->format('d M Y, H:i') }}</p>
<p class="text-lg font-semibold">{{ $forecast['summary'] }}</p>
<div class="prose max-w-none">
{!! nl2br(e($forecast['text'])) !!}
{!! nl2br(new Illuminate\Support\HtmlString($forecast['text'])) !!}
</div>
<div class="mt-4 pt-4 border-t border-gray-200">
<p class="font-semibold">{{ $forecast['author'] }}</p>
Expand Down
18 changes: 18 additions & 0 deletions resources/views/widgets/forecast-short-term.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<x-filament-widgets::widget>
<x-filament::section>
<div class="p-4 space-y-4">
@if ($forecast)
<h2 class="text-xl font-bold">Short-Term Forecast</h2>
<div class="flex justify-between text-sm text-gray-500">
<span>From: {{ \Carbon\Carbon::parse($forecast['startdate'])->format('d M Y') }}</span>
<span>To: {{ \Carbon\Carbon::parse($forecast['enddate'])->format('d M Y') }}</span>
</div>
<div class="prose max-w-none">
{!! nl2br(new Illuminate\Support\HtmlString($forecast['forecast'])) !!}
</div>
@else
<p>No short-term forecast available.</p>
@endif
</div>
</x-filament::section>
</x-filament-widgets::widget>
12 changes: 8 additions & 4 deletions src/FilamentBuienradarWidgetPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

namespace Baspa\FilamentBuienradarWidget;

use Baspa\FilamentBuienradarWidget\Widgets\ForecastForStationWidget;
use Baspa\FilamentBuienradarWidget\Widgets\ForecastReportWidget;
use Filament\Contracts\Plugin;
use Filament\Panel;
use Filament\Contracts\Plugin;
use Baspa\FilamentBuienradarWidget\Widgets\ForecastReportWidget;
use Baspa\FilamentBuienradarWidget\Widgets\ForecastLongTermWidget;
use Baspa\FilamentBuienradarWidget\Widgets\ForecastShortTermWidget;
use Baspa\FilamentBuienradarWidget\Widgets\ForecastForStationWidget;

class FilamentBuienradarWidgetPlugin implements Plugin
{
Expand All @@ -20,6 +22,8 @@ public function register(Panel $panel): void
->widgets([
ForecastForStationWidget::class,
ForecastReportWidget::class,
ForecastShortTermWidget::class,
ForecastLongTermWidget::class,
]);
}

Expand All @@ -40,4 +44,4 @@ public static function get(): static

return $plugin;
}
}
}
37 changes: 37 additions & 0 deletions src/Widgets/ForecastLongTermWidget.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Baspa\FilamentBuienradarWidget\Widgets;

use Baspa\Buienradar\Buienradar;
use Filament\Widgets\Widget;
use Illuminate\Contracts\View\View;

class ForecastLongTermWidget extends Widget
{
public ?array $forecast = null;

protected static string $view = 'filament-buienradar-widget::widgets.forecast-long-term';

protected int | string | array $columnSpan = 'full';

public null | string | array $width = null;

public function getColumnSpan(): int | string | array
{
return $this->width ?? 'full';
}

public function render(): View
{
$this->columnSpan = $this->width ?? 0;

return view(static::$view, $this->getViewData());
}

public function mount(): void
{
$buienradar = new Buienradar;

$this->forecast = $buienradar->forecast()->longTerm();
}
}
37 changes: 37 additions & 0 deletions src/Widgets/ForecastShortTermWidget.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Baspa\FilamentBuienradarWidget\Widgets;

use Baspa\Buienradar\Buienradar;
use Filament\Widgets\Widget;
use Illuminate\Contracts\View\View;

class ForecastShortTermWidget extends Widget
{
public ?array $forecast = null;

protected static string $view = 'filament-buienradar-widget::widgets.forecast-short-term';

protected int | string | array $columnSpan = 'full';

public null | string | array $width = null;

public function getColumnSpan(): int | string | array
{
return $this->width ?? 'full';
}

public function render(): View
{
$this->columnSpan = $this->width ?? 0;

return view(static::$view, $this->getViewData());
}

public function mount(): void
{
$buienradar = new Buienradar;

$this->forecast = $buienradar->forecast()->shortTerm();
}
}

0 comments on commit d1b0340

Please sign in to comment.