Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modular Views #2069

Merged
merged 5 commits into from
Aug 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ php:
- 5.6
- 7.0
- 7.1
- hhvm

sudo: false

before_install:
- cp .env.example .env
- if [[ $TRAVIS_PHP_VERSION != 'hhvm' && $TRAVIS_PHP_VERSION != 7.1 ]] ; then phpenv config-rm xdebug.ini; fi
- if [[ $TRAVIS_PHP_VERSION != 7.1 ]] ; then phpenv config-rm xdebug.ini; fi

install: travis_retry composer install --no-interaction --no-scripts --prefer-source
install: travis_retry composer install --no-interaction --no-scripts --prefer-source --no-suggest

script: vendor/bin/phpunit
71 changes: 71 additions & 0 deletions app/Composers/ModuleComposer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

/*
* This file is part of Cachet.
*
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace CachetHQ\Cachet\Composers;

use CachetHQ\Cachet\Services\Modules\Manager;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\View\View;

class ModuleComposer
{
/**
* The application instance.
*
* @var \Illuminate\Contracts\Foundation\Application
*/
protected $app;

/**
* The modules manager instance.
*
* @var \CachetHQ\Cachet\Services\Modules\Manager
*/
protected $manager;

/**
* Create a new modules composer.
*
* @param \Illuminate\Contracts\Foundation\Application $app
* @param \CachetHQ\Cachet\Services\Modules\Manager $manager
*
* @return void
*/
public function __construct(Application $app, Manager $manager)
{
$this->app = $app;
$this->manager = $manager;
}

/**
* Bind data to the view.
*
* @param \Illuminate\Contracts\View\View $view
*
* @return void
*/
public function compose(View $view)
{
$key = $view->getName();

$view->with('view', $key);

$modules = "view.modules: {$key}";
$groups = "view.groups: {$key}";

$modules = $this->app->bound($modules) ? $this->app[$modules] : [];
$groups = $this->app->bound($groups) ? $this->app[$groups] : [];

$modules = $this->manager->groupModules($modules, $groups);

$view->withModules($modules);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,20 @@
* file that was distributed with this source code.
*/

namespace CachetHQ\Cachet\Composers;
namespace CachetHQ\Cachet\Composers\Modules;

use CachetHQ\Cachet\Integrations\Core\System;
use CachetHQ\Cachet\Models\Component;
use CachetHQ\Cachet\Models\ComponentGroup;
use CachetHQ\Cachet\Models\Incident;
use Illuminate\Contracts\View\View;

/**
* This is the status page composer.
*
* @author James Brooks <[email protected]>
* @author Connor S. Parks <[email protected]>
*/
class StatusPageComposer
class ComponentsComposer
{
/**
* The system instance.
*
* @var \CachetHQ\Cachet\Integrations\Contracts\System
*/
protected $system;

/**
* Create a new status page composer instance.
*
* @param \CachetHQ\Cachet\Integrations\Contracts\System $system
*
* @return void
*/
public function __construct(System $system)
{
$this->system = $system;
}

/**
* Index page view composer.
*
Expand All @@ -52,19 +32,12 @@ public function __construct(System $system)
*/
public function compose(View $view)
{
$status = $this->system->getStatus();

// Scheduled maintenance code.
$scheduledMaintenance = Incident::scheduled()->orderBy('scheduled_at')->get();

// Component & Component Group lists.
$usedComponentGroups = Component::enabled()->where('group_id', '>', 0)->groupBy('group_id')->pluck('group_id');
$componentGroups = ComponentGroup::whereIn('id', $usedComponentGroups)->orderBy('order')->get();
$ungroupedComponents = Component::enabled()->where('group_id', 0)->orderBy('order')->orderBy('created_at')->get();

$view->with($status)
->withComponentGroups($componentGroups)
->withUngroupedComponents($ungroupedComponents)
->withScheduledMaintenance($scheduledMaintenance);
$view->withComponentGroups($componentGroups)
->withUngroupedComponents($ungroupedComponents);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/

namespace CachetHQ\Cachet\Composers;
namespace CachetHQ\Cachet\Composers\Modules;

use CachetHQ\Cachet\Models\Metric;
use Illuminate\Contracts\Config\Repository;
Expand Down
38 changes: 38 additions & 0 deletions app/Composers/Modules/ScheduledComposer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

/*
* This file is part of Cachet.
*
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace CachetHQ\Cachet\Composers\Modules;

use CachetHQ\Cachet\Models\Incident;
use Illuminate\Contracts\View\View;

/**
* This is the status page composer.
*
* @author James Brooks <[email protected]>
* @author Connor S. Parks <[email protected]>
*/
class ScheduledComposer
{
/**
* Index page view composer.
*
* @param \Illuminate\Contracts\View\View $view
*
* @return void
*/
public function compose(View $view)
{
$scheduledMaintenance = Incident::scheduled()->orderBy('scheduled_at')->get();

$view->withScheduledMaintenance($scheduledMaintenance);
}
}
55 changes: 55 additions & 0 deletions app/Composers/Modules/StatusComposer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

/*
* This file is part of Cachet.
*
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace CachetHQ\Cachet\Composers\Modules;

use CachetHQ\Cachet\Integrations\Contracts\System;
use Illuminate\Contracts\View\View;

/**
* This is the status page composer.
*
* @author James Brooks <[email protected]>
* @author Connor S. Parks <[email protected]>
*/
class StatusComposer
{
/**
* The system instance.
*
* @var \CachetHQ\Cachet\Integrations\Contracts\System
*/
protected $system;

/**
* Create a new status page composer instance.
*
* @param \CachetHQ\Cachet\Integrations\Contracts\System $system
*
* @return void
*/
public function __construct(System $system)
{
$this->system = $system;
}

/**
* Index page view composer.
*
* @param \Illuminate\Contracts\View\View $view
*
* @return void
*/
public function compose(View $view)
{
$view->with($this->system->getStatus());
}
}
35 changes: 35 additions & 0 deletions app/Composers/Modules/TimelineComposer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

/*
* This file is part of Cachet.
*
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace CachetHQ\Cachet\Composers\Modules;

use Illuminate\Contracts\View\View;

/**
* This is the status page composer.
*
* @author James Brooks <[email protected]>
* @author Connor S. Parks <[email protected]>
*/
class TimelineComposer
{
/**
* Index page view composer.
*
* @param \Illuminate\Contracts\View\View $view
*
* @return void
*/
public function compose(View $view)
{
// ...
}
}
17 changes: 13 additions & 4 deletions app/Foundation/Providers/ComposerServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@
use CachetHQ\Cachet\Composers\AppComposer;
use CachetHQ\Cachet\Composers\CurrentUserComposer;
use CachetHQ\Cachet\Composers\DashboardComposer;
use CachetHQ\Cachet\Composers\MetricsComposer;
use CachetHQ\Cachet\Composers\StatusPageComposer;
use CachetHQ\Cachet\Composers\ModuleComposer;
use CachetHQ\Cachet\Composers\Modules\ComponentsComposer as ComponentsModuleComposer;
use CachetHQ\Cachet\Composers\Modules\MetricsComposer as MetricsModuleComposer;
use CachetHQ\Cachet\Composers\Modules\ScheduledComposer as ScheduledModuleComposer;
use CachetHQ\Cachet\Composers\Modules\StatusComposer as StatusModuleComposer;
use CachetHQ\Cachet\Composers\Modules\TimelineComposer as TimelineModuleComposer;
use CachetHQ\Cachet\Composers\ThemeComposer;
use CachetHQ\Cachet\Composers\TimezoneLocaleComposer;
use Illuminate\Contracts\View\Factory;
Expand All @@ -32,11 +36,16 @@ public function boot(Factory $factory)
{
$factory->composer('*', AppComposer::class);
$factory->composer('*', CurrentUserComposer::class);
$factory->composer(['index'], MetricsComposer::class);
$factory->composer(['index', 'single-incident', 'subscribe', 'signup'], StatusPageComposer::class);
$factory->composer(['index', 'single-incident', 'subscribe.*', 'signup', 'dashboard.settings.theme', 'emails.*'], ThemeComposer::class);
$factory->composer('dashboard.*', DashboardComposer::class);
$factory->composer(['setup', 'dashboard.settings.localization'], TimezoneLocaleComposer::class);

$factory->composer('*', ModuleComposer::class);
$factory->composer('partials.modules.components', ComponentsModuleComposer::class);
$factory->composer('partials.modules.metrics', MetricsModuleComposer::class);
$factory->composer('partials.modules.scheduled', ScheduledModuleComposer::class);
$factory->composer('partials.modules.status', StatusModuleComposer::class);
$factory->composer('partials.modules.timeline', TimelineModuleComposer::class);
}

/**
Expand Down
Loading