Skip to content

Commit

Permalink
Added a pending deployments and running deployments menu to the top n…
Browse files Browse the repository at this point in the history
…avigation bar
  • Loading branch information
REBELinBLUE committed May 24, 2015
1 parent 02af0e8 commit 8d307fe
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 3 deletions.
41 changes: 41 additions & 0 deletions app/Http/Composers/HeaderComposer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php namespace App\Http\Composers;

use Illuminate\Contracts\View\View;
use App\Repositories\Contracts\DeploymentRepositoryInterface;

/**
* View composer for the header bar
*/
class HeaderComposer
{
private $deploymentRepository;

/**
* Class constructor
*
* @param DeploymentRepositoryInterface $user
*/
public function __construct(DeploymentRepositoryInterface $deploymentRepository)
{
$this->deploymentRepository = $deploymentRepository;
}

/**
* Generates the pending and deploying projects for the view
*
* @param \Illuminate\Contracts\View\View $view
* @return void
*/
public function compose(View $view)
{
$pending = $this->deploymentRepository->getPending();

$view->with('pending', $pending);
$view->with('pending_count', count($pending));

$deploying = $this->deploymentRepository->getRunning();

$view->with('deploying', $deploying);
$view->with('deploying_count', count($deploying));
}
}
1 change: 1 addition & 0 deletions app/Providers/ViewServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public function register()
*/
private function composeNavigation()
{
view()->composer('_partials.nav', 'App\Http\Composers\HeaderComposer');
view()->composer('_partials.sidebar', 'App\Http\Composers\NavigationComposer');
}
}
35 changes: 35 additions & 0 deletions app/Repositories/EloquentDeploymentRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,26 @@ public function getTimeline()
->get();
}

/**
* Gets pending deployments

This comment has been minimized.

Copy link
@REBELinBLUE

REBELinBLUE May 24, 2015

Author Owner

PHPCS: Whitespace found at end of line

*
* @return array
*/
public function getPending()
{
return $this->getStatus(Deployment::PENDING);
}

/**
* Gets running deployments

This comment has been minimized.

Copy link
@REBELinBLUE

REBELinBLUE May 24, 2015

Author Owner

PHPCS: Whitespace found at end of line

*
* @return array
*/
public function getRunning()
{
return $this->getStatus(Deployment::DEPLOYING);
}

/**
* Gets the number of times a project has been deployed today
*
Expand Down Expand Up @@ -81,4 +101,19 @@ private function getBetweenDates(Project $project, Carbon $startDate, Carbon $en
->where('started_at', '<=', $endDate->format('Y-m-d') . ' 23:59:59')
->count();
}

/**
* Gets deployments with a supplied status
*
* @param int $status
* @return array
*/
public function getStatus($status)
{
$raw_sql = 'project_id IN (SELECT id FROM projects WHERE deleted_at IS NULL)';
return Deployment::whereRaw($raw_sql) // FIXME: Surely there is a nicer way to do this?
->where('status', $status)
->orderBy('started_at', 'DESC')
->get();
}
}
7 changes: 7 additions & 0 deletions resources/assets/css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,11 @@ input[type=text].deployment-source {
height: 500px;
max-height: 500px;
overflow-y: scroll;
}

#deploying_menu li a p,
#deploying_menu li a h4,
#pending_menu li a p,
#pending_menu li a h4 {
margin-left: 0;
}
5 changes: 4 additions & 1 deletion resources/lang/en/dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
'title' => 'Dashboard',
'projects' => 'Projects',
'latest' => 'Latest Deployment|Latest Deployments',
'pending' => ':count pending deployment|:count pending deployments',
'running' => ':count running deployment|:count running deployments',
'no_projects' => 'You have not yet setup any projects',
'no_deployments' => 'There have not been any deployments yet.',
'status' => 'Status',
'site' => 'View the site',
'view' => 'View the deployment details',
'deployment_num' => 'Deployment #:id'
'deployment_num' => 'Deployment #:id',
'started' => 'Started at'

];
2 changes: 1 addition & 1 deletion resources/lang/en/notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
'webhook' => 'Webhook URL',
'test_message' => 'This is a test to ensure the notification is setup correctly, if you ' .
'can see this it means it is! :+1:',
'success_message' => 'Deployment %s successful! :smile:',
'success_message' => 'Deployment %s successful! :smile:', // FIXME: Shouldn't this use the Lang :deployment tokens instead of sprintf?
'failed_message' => 'Deployment %s failed! :cry:',
'branch' => 'Branch',
'project' => 'Project',
Expand Down
50 changes: 50 additions & 0 deletions resources/views/_partials/nav.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,62 @@
</a>
<div class="navbar-custom-menu">
<ul class="nav navbar-nav">

@if ($pending_count > 0)
<li class="dropdown messages-menu" id="pending_menu">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
<i class="fa fa-clock-o"></i>
<span class="label label-info">{{ $pending_count }}</span>
</a>
<ul class="dropdown-menu">
<li class="header">{{ Lang::choice('dashboard.pending', $pending_count, ['count' => $pending_count]) }}</li>
<li>
<ul class="menu">
@foreach ($pending as $deployment)
<li>
<a href="{{ route('deployment', ['id' => $deployment->id]) }}">
<h4>{{ $deployment->project->name }} <small class="pull-right">{{ Lang::get('dashboard.started') }}: {{ $deployment->started_at->format('g:i:s A') }}</small></h4>
<p>{{ Lang::get('deployments.branch') }}: {{ $deployment->branch }}</p>
</a>
</li>
@endforeach
</ul>
</li>
</ul>
</li>
@endif

@if ($deploying_count > 0)
<li class="dropdown messages-menu" id="deploying_menu">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
<i class="fa fa-spinner"></i>
<span class="label label-warning">{{ $deploying_count }}</span>
</a>
<ul class="dropdown-menu">
<li class="header">{{ Lang::choice('dashboard.running', $deploying_count, ['count' => $deploying_count]) }}</li>
<li>
<ul class="menu">
@foreach ($deploying as $deployment)
<li>
<a href="{{ route('deployment', ['id' => $deployment->id]) }}">
<h4>{{ $deployment->project->name }} <small class="pull-right">{{ Lang::get('dashboard.started') }}: {{ $deployment->started_at->format('g:i:s A') }}</small></h4>
<p>{{ Lang::get('deployments.branch') }}: {{ $deployment->branch }}</p>
</a>
</li>
@endforeach
</ul>
</li>
</ul>
</li>
@endif

<li class="dropdown user user-menu">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
<img src="{{ Gravatar::get(Auth::user()->email) }}" class="user-image" />
<span class="hidden-xs">{{ Auth::user()->name }}</span>
</a>
<ul class="dropdown-menu">

<li class="user-header">
<img src="{{ Gravatar::get(Auth::user()->email) }}" class="img-circle" />
<p>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/layout.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<body class="skin-green">
<div class="wrapper">

@include('._partials.nav')
@include('_partials.nav')

@include('_partials.sidebar')

Expand Down

0 comments on commit 8d307fe

Please sign in to comment.