From 0190813012f36d6854a66f9ee5168b818b3865c5 Mon Sep 17 00:00:00 2001 From: James Brooks Date: Tue, 31 May 2016 18:02:10 +0100 Subject: [PATCH 1/3] Dashboard RSS --- .../Providers/AppServiceProvider.php | 16 ++ .../Dashboard/DashboardController.php | 21 ++- app/Integrations/Feed.php | 68 +++++++ resources/views/dashboard/index.blade.php | 175 ++++++++++-------- 4 files changed, 203 insertions(+), 77 deletions(-) create mode 100644 app/Integrations/Feed.php diff --git a/app/Foundation/Providers/AppServiceProvider.php b/app/Foundation/Providers/AppServiceProvider.php index 40c35aa4..8b7c9757 100644 --- a/app/Foundation/Providers/AppServiceProvider.php +++ b/app/Foundation/Providers/AppServiceProvider.php @@ -15,6 +15,7 @@ use AltThree\Bus\Dispatcher; use CachetHQ\Cachet\Bus\Middleware\UseDatabaseTransactions; use CachetHQ\Cachet\Dates\DateFactory; use CachetHQ\Cachet\Integrations\Credits; +use CachetHQ\Cachet\Integrations\Feed; use CachetHQ\Cachet\Integrations\Releases; use Illuminate\Support\ServiceProvider; use Illuminate\Support\Str; @@ -55,6 +56,7 @@ class AppServiceProvider extends ServiceProvider { $this->registerDateFactory(); $this->registerCredits(); + $this->registerFeed(); $this->registerReleases(); } @@ -87,6 +89,20 @@ class AppServiceProvider extends ServiceProvider }); } + /** + * Register the feed class. + * + * @return void + */ + protected function registerFeed() + { + $this->app->singleton(Feed::class, function ($app) { + $cache = $app['cache.store']; + + return new Feed($cache); + }); + } + /** * Register the releases class. * diff --git a/app/Http/Controllers/Dashboard/DashboardController.php b/app/Http/Controllers/Dashboard/DashboardController.php index ec103531..952fb090 100644 --- a/app/Http/Controllers/Dashboard/DashboardController.php +++ b/app/Http/Controllers/Dashboard/DashboardController.php @@ -11,6 +11,7 @@ namespace CachetHQ\Cachet\Http\Controllers\Dashboard; +use CachetHQ\Cachet\Integrations\Feed; use CachetHQ\Cachet\Models\Component; use CachetHQ\Cachet\Models\Incident; use CachetHQ\Cachet\Models\Subscriber; @@ -36,12 +37,22 @@ class DashboardController extends Controller protected $timeZone; /** - * Creates a new dashboard controller. + * The feed integration. + * + * @var \CachetHQ\Cachet\Integrations\Feed + */ + protected $feed; + + /** + * Creates a new dashboard controller instance. + * + * @param \CachetHQ\Cachet\Integrations\Feed $feed * * @return void */ - public function __construct() + public function __construct(Feed $feed) { + $this->feed = $feed; $this->startDate = new Date(); $this->dateTimeZone = Config::get('cachet.timezone'); } @@ -56,12 +67,16 @@ class DashboardController extends Controller $components = Component::orderBy('order')->get(); $incidents = $this->getIncidents(); $subscribers = $this->getSubscribers(); + $feed = $this->feed->entries(); + + dd($feed); return View::make('dashboard.index') ->withPageTitle(trans('dashboard.dashboard')) ->withComponents($components) ->withIncidents($incidents) - ->withSubscribers($subscribers); + ->withSubscribers($subscribers) + ->withFeed($feed); } /** diff --git a/app/Integrations/Feed.php b/app/Integrations/Feed.php new file mode 100644 index 00000000..53136628 --- /dev/null +++ b/app/Integrations/Feed.php @@ -0,0 +1,68 @@ +cache = $cache; + $this->url = $url ?: static::URL; + } + + /** + * Returns the entries. + * + * @return array + */ + public function entries() + { + return $this->cache->remember('feeds', 2880, function () { + return new SimpleXmlElement((new Client())->get($this->url, [ + 'headers' => ['Accept' => 'application/rss+xml', 'User-Agent' => defined('CACHET_VERSION') ? 'cachet/'.constant('CACHET_VERSION') : 'cachet'], + ])->getBody()->getContents()); + }); + } +} diff --git a/resources/views/dashboard/index.blade.php b/resources/views/dashboard/index.blade.php index 1f98adf8..874e4a93 100644 --- a/resources/views/dashboard/index.blade.php +++ b/resources/views/dashboard/index.blade.php @@ -1,86 +1,113 @@ @extends('layout.dashboard') @section('content') -
- - - {{ trans('dashboard.dashboard') }} - +
+ -
-
-
- -
+ + {{ trans('dashboard.dashboard') }} + +
+
+
+
+
-
-
-

{{ trans('dashboard.components.component_statuses') }}

-
-
- @forelse($components as $component) -
-
-
-
-

{{ $component->name }}

-
-
- @foreach(trans('cachet.components.status') as $statusID => $status) -
- -
- @endforeach -
+
+
+
+

{{ trans('dashboard.components.component_statuses') }}

+
+
+ @forelse($components as $component) +
+ +
+
+

{{ $component->name }}

- - -
- @empty - - @endforelse -
-
-
-
- -
-
-
-
- {{ $incidents->map(function($incident) { return count($incident); })->sum() }} - {{ trans('dashboard.incidents.incidents') }} -
-
-
-
-
-
- -
-
- -
-
+
+ @foreach(trans('cachet.components.status') as $statusID => $status) +
+ +
+ @endforeach +
+
+ +
+ @empty + + @endforelse
- @if(Session::get('setup.done')) - @include('dashboard.partials.welcome-modal') - - @endif + +
+
+
+
+ {{ $incidents->map(function($incident) { return count($incident); })->sum() }} + {{ trans('dashboard.incidents.incidents') }} +
+
+
+
+
+
+ +
+
+ +
+
+
+
+
+
+ +
+
+
+
+ Support Cachet + Check out our Patreon page! +
+
+
+ +
+
+
+ Support Cachet + Check out our Patreon page! +
+
+
    + @foreach($feed->entries()['channel']['item'] as $item) + + @endforeach +
+
+
+
+
+
+@if(Session::get('setup.done')) +@include('dashboard.partials.welcome-modal') + +@endif @stop From f53075ec4fade183084c575201855b6958ef7bbc Mon Sep 17 00:00:00 2001 From: James Brooks Date: Tue, 31 May 2016 19:12:23 +0100 Subject: [PATCH 2/3] Add Patreon link and latest Cachet blog posts to dashboard --- .../Dashboard/DashboardController.php | 4 ++-- app/Integrations/Feed.php | 11 ++++++++-- resources/assets/sass/modules/_stats.scss | 22 +++++++++++++++++++ resources/lang/en/dashboard.php | 8 +++++++ resources/views/dashboard/index.blade.php | 18 +++++++-------- 5 files changed, 50 insertions(+), 13 deletions(-) diff --git a/app/Http/Controllers/Dashboard/DashboardController.php b/app/Http/Controllers/Dashboard/DashboardController.php index 952fb090..dcb60c92 100644 --- a/app/Http/Controllers/Dashboard/DashboardController.php +++ b/app/Http/Controllers/Dashboard/DashboardController.php @@ -69,14 +69,14 @@ class DashboardController extends Controller $subscribers = $this->getSubscribers(); $feed = $this->feed->entries(); - dd($feed); + $entries = array_slice($feed->channel->item, 0, 5); return View::make('dashboard.index') ->withPageTitle(trans('dashboard.dashboard')) ->withComponents($components) ->withIncidents($incidents) ->withSubscribers($subscribers) - ->withFeed($feed); + ->withEntries($entries); } /** diff --git a/app/Integrations/Feed.php b/app/Integrations/Feed.php index 53136628..474ca522 100644 --- a/app/Integrations/Feed.php +++ b/app/Integrations/Feed.php @@ -15,6 +15,11 @@ use GuzzleHttp\Client; use Illuminate\Contracts\Cache\Repository; use SimpleXmlElement; +/** + * This is the feed class. + * + * @author James Brooks + */ class Feed { /** @@ -60,9 +65,11 @@ class Feed public function entries() { return $this->cache->remember('feeds', 2880, function () { - return new SimpleXmlElement((new Client())->get($this->url, [ + $xml = simplexml_load_string((new Client())->get($this->url, [ 'headers' => ['Accept' => 'application/rss+xml', 'User-Agent' => defined('CACHET_VERSION') ? 'cachet/'.constant('CACHET_VERSION') : 'cachet'], - ])->getBody()->getContents()); + ])->getBody()->getContents(), null, LIBXML_NOCDATA); + + return json_decode(json_encode($xml)); }); } } diff --git a/resources/assets/sass/modules/_stats.scss b/resources/assets/sass/modules/_stats.scss index 160ddf56..da60616f 100644 --- a/resources/assets/sass/modules/_stats.scss +++ b/resources/assets/sass/modules/_stats.scss @@ -40,6 +40,28 @@ padding-top: 10px; } + .stats-body { + margin-top: -20px; + padding-top: 10px; + + .list-group { + border: none; + padding-bottom: 0; + margin-bottom: 0; + + .list-group-item { + border-right: none; + border-left: none; + + border-color: #eee; + + &:last-child { + border-bottom: none; + } + } + } + } + .stats-bottom { border-top: #eee 1px solid; color: #777; diff --git a/resources/lang/en/dashboard.php b/resources/lang/en/dashboard.php index 54270b24..0078d64f 100755 --- a/resources/lang/en/dashboard.php +++ b/resources/lang/en/dashboard.php @@ -249,6 +249,14 @@ return [ 'whoops' => 'Whoops.', ], + // Widgets + 'widgets' => [ + 'support' => 'Support Cachet', + 'support_subtitle' => 'Check out our Patreon page!', + 'news' => 'Latest News', + 'news_subtitle' => 'Get the latest updates', + ], + // Welcome modal 'welcome' => [ 'welcome' => 'Welcome to your new status page!', diff --git a/resources/views/dashboard/index.blade.php b/resources/views/dashboard/index.blade.php index 874e4a93..cbc07663 100644 --- a/resources/views/dashboard/index.blade.php +++ b/resources/views/dashboard/index.blade.php @@ -79,8 +79,8 @@
- Support Cachet - Check out our Patreon page! + {{ trans('dashboard.widgets.support') }} + {!! trans('dashboard.widgets.support_subtitle') !!}
@@ -88,15 +88,15 @@
- Support Cachet - Check out our Patreon page! + {{ trans('dashboard.widgets.news') }} + {{ trans('dashboard.widgets.news_subtitle') }}
-
- +
From 2adc9d032a1f2ef3692d14ba1e0935a37c8df0ed Mon Sep 17 00:00:00 2001 From: James Brooks Date: Tue, 31 May 2016 14:12:32 -0400 Subject: [PATCH 3/3] Applied fixes from StyleCI [ci skip] --- app/Integrations/Feed.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/Integrations/Feed.php b/app/Integrations/Feed.php index 474ca522..9be9c474 100644 --- a/app/Integrations/Feed.php +++ b/app/Integrations/Feed.php @@ -13,7 +13,6 @@ namespace CachetHQ\Cachet\Integrations; use GuzzleHttp\Client; use Illuminate\Contracts\Cache\Repository; -use SimpleXmlElement; /** * This is the feed class.