Skip to content

Commit

Permalink
Grouping projects on dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephen Ball committed Apr 15, 2015
1 parent a49eb8e commit 7dca95f
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 48 deletions.
22 changes: 16 additions & 6 deletions app/Http/Controllers/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,32 @@ class DashboardController extends Controller
public function index(DeploymentRepositoryInterface $deploymentRepository, ProjectRepositoryInterface $projectRepository)

This comment has been minimized.

Copy link
@REBELinBLUE

REBELinBLUE Apr 15, 2015

Owner

PHPCS: Line exceeds 120 characters; contains 125 characters

{
$deployments = $deploymentRepository->getTimeline();
$projects = $projectRepository->getAll();

$grouped_by_date = [];
$deploys_by_date = [];
foreach ($deployments as $deployment) {
$date = $deployment->started_at->format('Y-m-d');

if (!isset($grouped_by_date[$date])) {
$grouped_by_date[$date] = [];
if (!isset($deploys_by_date[$date])) {
$deploys_by_date[$date] = [];
}

$grouped_by_date[$date][] = $deployment;
$deploys_by_date[$date][] = $deployment;
}

$projects_by_group = [];
foreach ($projects as $project) {
if (!isset($projects_by_group[$project->group->name])) {
$projects_by_group[$project->group->name] = [];
}

$projects_by_group[$project->group->name][] = $project;
}

return view('dashboard.index', [
'title' => Lang::get('dashboard.title'),
'latest' => $grouped_by_date,
'projects' => $projectRepository->getAll()
'latest' => $deploys_by_date,
'projects' => $projects_by_group
]);
}
}
4 changes: 3 additions & 1 deletion app/Repositories/EloquentProjectRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public function __construct(Project $model)
*/
public function getAll()
{
return $this->model->orderBy('name')->get();
return $this->model
->orderBy('name')
->get();
}
}
2 changes: 1 addition & 1 deletion resources/lang/en/dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
'title' => 'Dashboard',
'projects' => 'Projects',
'latest' => 'Latest Deployment|Latest Deployments',
'no_projects' => 'You have not yet setup any projects, click the button above to get started!',
'no_projects' => 'You have not yet setup any projects',
'no_deployments' => 'There have not been any deployments yet.',
'status' => 'Status',
'site' => 'View the site',
Expand Down
88 changes: 48 additions & 40 deletions resources/views/dashboard/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,56 @@
@section('content')
<div class="row">
<div class="col-md-7">
<div class="box">
<div class="box-header">
<h3 class="box-title">{{ Lang::get('dashboard.projects') }}</h3>
</div>
@if (!count($projects))
<div class="box-body">
<p>{{ Lang::get('dashboard.no_projects') }}</p>

@if (!count($projects))
<div class="box">
<div class="box-header">
<h3 class="box-title">{{ Lang::get('dashboard.projects') }}</h3>
</div>
<div class="box-body">
<p>{{ Lang::get('dashboard.no_projects') }}</p>
</div>
</div>
@else
<div class="box-body table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th>{{ Lang::get('projects.name') }}</th>
<th>{{ Lang::choice('dashboard.latest', 1) }}</th>
<th>{{ Lang::get('dashboard.status') }}</th>
<th>&nbsp;</th>
</tr>
</thead>
<tbody>
@foreach ($projects as $project)
<tr id="project_{{ $project->id }}">
<td><a href="{{ url('projects', ['id' => $project->id]) }}" title="View Details">{{ $project->name }}</a></td>
<td>{{ $project->last_run ? $project->last_run->format('jS F Y g:i:s A') : 'Never' }}</td>
<td>
<span class="label label-{{ project_css_status($project) }}"><i class="fa fa-{{ project_icon_status($project) }}"></i> {{ project_status($project) }}</span>
</td>
<td>
<div class="btn-group pull-right">
@if(isset($project->url))
<a href="{{ $project->url }}" class="btn btn-default" title="{{ Lang::get('dashboard.site') }}" target="_blank"><i class="fa fa-globe"></i></a>
@endif
<a href="{{ url('projects', ['id' => $project->id]) }}" class="btn btn-default" title="{{ Lang::get('dashboard.view') }}"><i class="fa fa-info-circle"></i></a>
</div>
</td>
</tr>
@endforeach
</tbody>
</table>
@else
@foreach ($projects as $group => $group_projects)
<div class="box">
<div class="box-header">
<h3 class="box-title">{{ $group }}</h3>
</div>
<div class="box-body table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th>{{ Lang::get('projects.name') }}</th>
<th>{{ Lang::choice('dashboard.latest', 1) }}</th>
<th>{{ Lang::get('dashboard.status') }}</th>
<th>&nbsp;</th>
</tr>
</thead>
<tbody>
@foreach ($group_projects as $project)
<tr id="project_{{ $project->id }}">
<td><a href="{{ url('projects', ['id' => $project->id]) }}" title="View Details">{{ $project->name }}</a></td>
<td>{{ $project->last_run ? $project->last_run->format('jS F Y g:i:s A') : 'Never' }}</td>
<td>
<span class="label label-{{ project_css_status($project) }}"><i class="fa fa-{{ project_icon_status($project) }}"></i> {{ project_status($project) }}</span>
</td>
<td>
<div class="btn-group pull-right">
@if(isset($project->url))
<a href="{{ $project->url }}" class="btn btn-default" title="{{ Lang::get('dashboard.site') }}" target="_blank"><i class="fa fa-globe"></i></a>
@endif
<a href="{{ url('projects', ['id' => $project->id]) }}" class="btn btn-default" title="{{ Lang::get('dashboard.view') }}"><i class="fa fa-info-circle"></i></a>
</div>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
@endif
</div>
@endforeach
@endif
</div>

<div class="col-md-5">
Expand Down

0 comments on commit 7dca95f

Please sign in to comment.