From c03f01ca44903fbdca77b4bd35fe0c8c27a8da69 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sun, 29 May 2016 18:14:40 +0100 Subject: [PATCH] Added credits --- .../Providers/AppServiceProvider.php | 25 +++++-- .../Controllers/Dashboard/ApiController.php | 4 +- .../Dashboard/SettingsController.php | 30 +++++++++ app/Http/Middleware/Timezone.php | 2 +- app/Http/Routes/DashboardRoutes.php | 5 ++ app/Integrations/Credits.php | 67 +++++++++++++++++++ .../Release.php => Integrations/Releases.php} | 35 +++++++--- resources/lang/en/dashboard.php | 7 ++ .../dashboard/settings/credits.blade.php | 51 ++++++++++++++ .../Providers/AppServiceProviderTest.php | 12 +++- 10 files changed, 217 insertions(+), 21 deletions(-) create mode 100644 app/Integrations/Credits.php rename app/{GitHub/Release.php => Integrations/Releases.php} (60%) create mode 100644 resources/views/dashboard/settings/credits.blade.php diff --git a/app/Foundation/Providers/AppServiceProvider.php b/app/Foundation/Providers/AppServiceProvider.php index 97fbc414a..8de3c5ff2 100644 --- a/app/Foundation/Providers/AppServiceProvider.php +++ b/app/Foundation/Providers/AppServiceProvider.php @@ -14,7 +14,8 @@ namespace CachetHQ\Cachet\Foundation\Providers; use AltThree\Bus\Dispatcher; use CachetHQ\Cachet\Bus\Middleware\UseDatabaseTransactions; use CachetHQ\Cachet\Dates\DateFactory; -use CachetHQ\Cachet\GitHub\Release; +use CachetHQ\Cachet\Integrations\Credits; +use CachetHQ\Cachet\Integrations\Releases; use Illuminate\Support\ServiceProvider; use Illuminate\Support\Str; @@ -53,7 +54,8 @@ class AppServiceProvider extends ServiceProvider public function register() { $this->registerDateFactory(); - $this->registerRelease(); + $this->registerCredits(); + $this->registerReleases(); } /** @@ -71,18 +73,31 @@ class AppServiceProvider extends ServiceProvider }); } + /** + * Register the credits class. + * + * @return void + */ + protected function registerCredits() + { + $this->app->singleton(Credits::class, function ($app) { + $cache = $app['cache.store']; + + return new Credits($cache); + }); + } /** * Register the releases class. * * @return void */ - protected function registerRelease() + protected function registerReleases() { - $this->app->singleton(Release::class, function ($app) { + $this->app->singleton(Releases::class, function ($app) { $cache = $app['cache.store']; $token = $app['config']->get('services.github.token'); - return new Release($cache, $token); + return new Releases($cache, $token); }); } } diff --git a/app/Http/Controllers/Dashboard/ApiController.php b/app/Http/Controllers/Dashboard/ApiController.php index 7450e65c1..8cea8f8aa 100644 --- a/app/Http/Controllers/Dashboard/ApiController.php +++ b/app/Http/Controllers/Dashboard/ApiController.php @@ -11,7 +11,7 @@ namespace CachetHQ\Cachet\Http\Controllers\Dashboard; -use CachetHQ\Cachet\GitHub\Release; +use CachetHQ\Cachet\Integrations\Releases; use CachetHQ\Cachet\Models\Component; use CachetHQ\Cachet\Models\ComponentGroup; use CachetHQ\Cachet\Models\IncidentTemplate; @@ -99,7 +99,7 @@ class ApiController extends Controller */ public function checkVersion() { - $latest = app(Release::class)->latest(); + $latest = app(Releases::class)->latest(); return Response::json([ 'cachet_version' => CACHET_VERSION, diff --git a/app/Http/Controllers/Dashboard/SettingsController.php b/app/Http/Controllers/Dashboard/SettingsController.php index 65d1c61b8..66578b5d3 100644 --- a/app/Http/Controllers/Dashboard/SettingsController.php +++ b/app/Http/Controllers/Dashboard/SettingsController.php @@ -82,6 +82,12 @@ class SettingsController extends Controller 'icon' => 'ion-stats-bars', 'active' => false, ], + 'credits' => [ + 'title' => trans('dashboard.settings.credits.credits'), + 'url' => route('dashboard.settings.credits'), + 'icon' => 'ion-ios-list', + 'active' => false, + ], 'about' => [ 'title' => CACHET_VERSION, 'url' => 'javascript: void(0);', @@ -212,6 +218,30 @@ class SettingsController extends Controller ->withSubMenu($this->subMenu); } + /** + * Show the credits view. + * + * @return \Illuminate\View\View + */ + public function showCreditsView() + { + $this->subMenu['credits']['active'] = true; + + $credits = app(Credits::class)->latest(); + + $backers = $credits['backers']; + $contributors = $credits['contributors']; + + shuffle($backers); + shuffle($contributors); + + return View::make('dashboard.settings.credits') + ->withPageTitle(trans('dashboard.settings.credits.credits').' - '.trans('dashboard.dashboard')) + ->withBackers($backers) + ->withContributors($contributors) + ->withSubMenu($this->subMenu); + } + /** * Updates the status page settings. * diff --git a/app/Http/Middleware/Timezone.php b/app/Http/Middleware/Timezone.php index 3eef6362d..8b56ddbbd 100644 --- a/app/Http/Middleware/Timezone.php +++ b/app/Http/Middleware/Timezone.php @@ -25,7 +25,7 @@ class Timezone protected $config; /** - * Creates a new release instance. + * Creates a new timezone middleware instance. * * @param \Illuminate\Contracts\Config\Repository $config * diff --git a/app/Http/Routes/DashboardRoutes.php b/app/Http/Routes/DashboardRoutes.php index 56a78646f..8c7a0e927 100644 --- a/app/Http/Routes/DashboardRoutes.php +++ b/app/Http/Routes/DashboardRoutes.php @@ -11,6 +11,7 @@ namespace CachetHQ\Cachet\Http\Routes; +use CachetHQ\Cachet\Integrations\Credits; use Illuminate\Contracts\Routing\Registrar; /** @@ -211,6 +212,10 @@ class DashboardRoutes 'as' => 'customization', 'uses' => 'SettingsController@showCustomizationView', ]); + $router->get('credits', [ + 'as' => 'credits', + 'uses' => 'SettingsController@showCreditsView', + ]); $router->post('/', 'SettingsController@postSettings'); }); diff --git a/app/Integrations/Credits.php b/app/Integrations/Credits.php new file mode 100644 index 000000000..3bbd7332c --- /dev/null +++ b/app/Integrations/Credits.php @@ -0,0 +1,67 @@ +cache = $cache; + $this->url = $url ?: static::URL; + } + + /** + * Returns the latest credits. + * + * @return array + */ + public function latest() + { + return $this->cache->remember('version', 2880, function () { + return json_decode((new Client())->get($this->url, [ + 'headers' => ['Accept' => 'application/json'], + ])->getBody(), true); + }); + } +} diff --git a/app/GitHub/Release.php b/app/Integrations/Releases.php similarity index 60% rename from app/GitHub/Release.php rename to app/Integrations/Releases.php index 583bb26fc..3d0649b78 100644 --- a/app/GitHub/Release.php +++ b/app/Integrations/Releases.php @@ -9,13 +9,20 @@ * file that was distributed with this source code. */ -namespace CachetHQ\Cachet\GitHub; +namespace CachetHQ\Cachet\Integrations; use GuzzleHttp\Client; -use Illuminate\Contracts\Cache\Repository as CacheRepository; +use Illuminate\Contracts\Cache\Repository; -class Release +class Releases { + /** + * The default url. + * + * @var string + */ + const URL = 'https://api.github.com/repos/cachethq/cachet/releases/latest'; + /** * The cache repository instance. * @@ -26,26 +33,35 @@ class Release /** * The github authentication token. * - * @var string + * @var string|null */ protected $token; /** - * Creates a new release instance. + * The url to use. + * + * @var string|null + */ + protected $url; + + /** + * Creates a new releases instance. * * @param \Illuminate\Contracts\Cache\Repository $cache - * @param string $token + * @param string|null $token + * @param string|null $url * * @return void */ - public function __construct(CacheRepository $cache, $token) + public function __construct(Repository $cache, $token = null, $url = null) { $this->cache = $cache; $this->token = $token; + $this->url = $url ?: static::URL; } /** - * Returns the latest GitHub release. + * Returns the latest release. * * @return string */ @@ -54,12 +70,11 @@ class Release $release = $this->cache->remember('version', 720, function () { $headers = ['Accept' => 'application/vnd.github.v3+json']; - // We can re-use the Emoji token here, if we have it. if ($this->token) { $headers['OAUTH-TOKEN'] = $this->token; } - return json_decode((new Client())->get('https://api.github.com/repos/cachethq/cachet/releases/latest', [ + return json_decode((new Client())->get($this->url, [ 'headers' => $headers, ])->getBody(), true); }); diff --git a/resources/lang/en/dashboard.php b/resources/lang/en/dashboard.php index 7adcbe9ba..a7f818cfc 100755 --- a/resources/lang/en/dashboard.php +++ b/resources/lang/en/dashboard.php @@ -219,6 +219,13 @@ return [ 'success' => 'Settings saved.', 'failure' => 'Settings could not be saved.', ], + 'credits' => [ + 'credits' => 'Credits', + 'license' => 'Cachet is a BSD-3-licensed open source project, released by Alt Three Services Limited.', + 'backers-title' => 'Backers & Sponsors', + 'backers' => 'If you\'d like to support future development, check out the Cachet Patreon campaign.', + 'thank-you' => 'Thank you to each and every one of the :count contributors.', + ], ], // Login diff --git a/resources/views/dashboard/settings/credits.blade.php b/resources/views/dashboard/settings/credits.blade.php new file mode 100644 index 000000000..2eda4ce78 --- /dev/null +++ b/resources/views/dashboard/settings/credits.blade.php @@ -0,0 +1,51 @@ +@extends('layout.dashboard') + +@section('content') +
+ @if(isset($sub_menu)) + @include('dashboard.partials.sub-sidebar') + @endif +
+
+ + {{ trans('dashboard.settings.credits.credits') }} + +
+
+
+

Cachet

+ +

{!! trans('dashboard.settings.credits.license') !!}

+ +
+ +

{{ trans('dashboard.settings.credits.backers-title') }}

+ +

{!! trans('dashboard.settings.credits.backers') !!}

+ +
    + @foreach($backers as $backer) +
  • {{ $backer['name'] }}
  • + @endforeach +
+ +
+ +

{{ trans('dashboard.settings.credits.contributors') }}

+ +

{{ trans('dashboard.settings.credits.thank-you', ['count' => count($contributors)]) }}

+ +
    + @foreach($contributors as $contributor) +
  • + +
  • + @endforeach +
+ +
+
+
+
+
+@stop diff --git a/tests/Foundation/Providers/AppServiceProviderTest.php b/tests/Foundation/Providers/AppServiceProviderTest.php index 4b6a6e583..cfb68eefb 100644 --- a/tests/Foundation/Providers/AppServiceProviderTest.php +++ b/tests/Foundation/Providers/AppServiceProviderTest.php @@ -13,7 +13,8 @@ namespace CachetHQ\Tests\Cachet\Foundation\Providers; use AltThree\TestBench\ServiceProviderTrait; use CachetHQ\Cachet\Dates\DateFactory; -use CachetHQ\Cachet\GitHub\Release; +use CachetHQ\Cachet\Integrations\Credits; +use CachetHQ\Cachet\Integrations\Releases; use CachetHQ\Tests\Cachet\AbstractTestCase; /** @@ -30,8 +31,13 @@ class AppServiceProviderTest extends AbstractTestCase $this->assertIsInjectable(DateFactory::class); } - public function testReleaseIsInjectable() + public function testCreditsIsInjectable() { - $this->assertIsInjectable(Release::class); + $this->assertIsInjectable(Credits::class); + } + + public function testReleasesIsInjectable() + { + $this->assertIsInjectable(Releases::class); } }