From 2ccaaddfcd6056b8c20d2be60c2e55fa4ace6207 Mon Sep 17 00:00:00 2001 From: Nabeel Shahzad Date: Wed, 10 Jan 2018 16:02:33 -0600 Subject: [PATCH] add latest news item as widget to dashboard #52 --- app/Widgets/BaseWidget.php | 2 ++ app/Widgets/LatestNews.php | 25 +++++++++++++++++++ .../layouts/default/dashboard/index.blade.php | 12 +-------- .../default/widgets/latest_news.blade.php | 20 +++++++++++++++ 4 files changed, 48 insertions(+), 11 deletions(-) create mode 100644 app/Widgets/LatestNews.php create mode 100644 resources/views/layouts/default/widgets/latest_news.blade.php diff --git a/app/Widgets/BaseWidget.php b/app/Widgets/BaseWidget.php index f039f748..57436b4c 100644 --- a/app/Widgets/BaseWidget.php +++ b/app/Widgets/BaseWidget.php @@ -12,6 +12,8 @@ use Arrilot\Widgets\AbstractWidget; class BaseWidget extends AbstractWidget { + public $cacheTime = 0; + public function view(string $template, array $vars = []) { $tpl = 'layouts/' . config('phpvms.skin') . '/' . $template; diff --git a/app/Widgets/LatestNews.php b/app/Widgets/LatestNews.php new file mode 100644 index 00000000..74ef9123 --- /dev/null +++ b/app/Widgets/LatestNews.php @@ -0,0 +1,25 @@ + 5, + ]; + + /** + * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View + */ + public function run() + { + $newsRepo = app(NewsRepository::class); + + return $this->view('widgets.latest_news', [ + 'config' => $this->config, + 'news' => $newsRepo->recent($this->config['count']), + ]); + } +} diff --git a/resources/views/layouts/default/dashboard/index.blade.php b/resources/views/layouts/default/dashboard/index.blade.php index 9a98ca6f..6a7c2462 100644 --- a/resources/views/layouts/default/dashboard/index.blade.php +++ b/resources/views/layouts/default/dashboard/index.blade.php @@ -57,17 +57,7 @@ @include('layouts.default.pireps.pirep_card', ['pirep' => $last_pirep]) @endif -
- -
- -
- News goes here! -
-
-
+ {{ Widget::latestNews(['count' => 1]) }}
diff --git a/resources/views/layouts/default/widgets/latest_news.blade.php b/resources/views/layouts/default/widgets/latest_news.blade.php new file mode 100644 index 00000000..0d9c0757 --- /dev/null +++ b/resources/views/layouts/default/widgets/latest_news.blade.php @@ -0,0 +1,20 @@ + +
+
+ @if($news->count() === 0) +
+ no news items +
+ @endif + + @foreach($news as $item) +

{!! $item->subject !!}

+

{!! $item->user->name !!} + - {!! show_datetime($item->created_at) !!}

+ + {!! $item->body !!} + @endforeach +
+