Browse Source

Add project status icon and color list, refactor dashboard view

pull/1/head
Nafies Luthfi 8 years ago
parent
commit
b2f2a82ea7
  1. 28
      app/Entities/Pages/PagesRepository.php
  2. 35
      app/Entities/Projects/Status.php
  3. 13
      app/Entities/ReferenceAbstract.php
  4. 9
      app/Exceptions/ReferenceKeyNotFoundException.php
  5. 24
      app/Http/Controllers/PagesController.php
  6. 2
      app/Http/Middleware/GlobalViewVariables.php
  7. 116
      resources/views/pages/home.blade.php
  8. 10
      resources/views/view-components/dashboard-panel.blade.php
  9. 8
      resources/views/view-components/sidebar-project-list-links.blade.php
  10. 28
      tests/Unit/References/ProjectStatusTest.php

28
app/Entities/Pages/PagesRepository.php

@ -1,28 +0,0 @@
<?php
namespace App\Entities\Pages;
use App\Entities\BaseRepository;
use App\Entities\Options\Option;
use App\Entities\Payments\Payment;
/**
* Pages Repository Class
*/
class PagesRepository extends BaseRepository
{
public function __construct(Option $model)
{
$this->model = $model;
}
public function getTotalIncome()
{
return Payment::whereType(1)->sum('amount');
}
public function getTotalExpenditure()
{
return Payment::whereType(0)->sum('amount');
}
}

35
app/Entities/Projects/Status.php

@ -3,6 +3,7 @@
namespace App\Entities\Projects;
use App\Entities\ReferenceAbstract;
use App\Exceptions\ReferenceKeyNotFoundException;
class Status extends ReferenceAbstract
{
@ -15,9 +16,36 @@ class Status extends ReferenceAbstract
6 => 'on_hold',
];
protected static $colors = [
1 => 'default',
2 => 'yellow',
3 => 'primary',
4 => 'green',
5 => 'danger',
6 => 'warning',
];
protected static $icons = [
1 => 'paperclip',
2 => 'tasks',
3 => 'thumbs-o-up',
4 => 'money',
5 => 'frown-o',
6 => 'hand-paper-o',
];
public static function getNameById($singleId)
{
return trans('project.'.static::$lists[$singleId]);
return trans('project.'.static::getById($singleId));
}
public static function getIconById($singleId)
{
if ( ! ! static::getById($singleId) && isset(static::$icons[$singleId])) {
return static::$icons[$singleId];
}
throw new ReferenceKeyNotFoundException('Reference key: '.$singleId.' not found for '.get_called_class().'::icons');
}
public static function toArray()
@ -29,9 +57,4 @@ class Status extends ReferenceAbstract
return $lists;
}
public static function all()
{
return collect($this->toArray());
}
}

13
app/Entities/ReferenceAbstract.php

@ -2,6 +2,7 @@
namespace App\Entities;
use App\Exceptions\ReferenceKeyNotFoundException;
use Illuminate\Support\Arr;
abstract class ReferenceAbstract
@ -27,7 +28,11 @@ abstract class ReferenceAbstract
public static function getById($singleId)
{
return static::$lists[$singleId];
if (isset(static::$lists[$singleId])) {
return static::$lists[$singleId];
}
new ReferenceKeyNotFoundException('Reference key: '.$singleId.' not found for '.get_called_class().'::lists');
}
public static function only(array $singleIds)
@ -47,7 +52,11 @@ abstract class ReferenceAbstract
public static function getColorById($colorId)
{
return isset(static::$lists[$colorId]) ? static::$colors[$colorId] : null;
if ( ! ! static::getById($colorId) && isset(static::$colors[$colorId])) {
return static::$colors[$colorId];
}
throw new ReferenceKeyNotFoundException('Reference key: '.$colorId.' not found for '.get_called_class().'::colors');
}
public static function colorsExcept(array $colorIds)

9
app/Exceptions/ReferenceKeyNotFoundException.php

@ -0,0 +1,9 @@
<?php
namespace App\Exceptions;
/**
* Reference Key Not Found Exception
*/
class ReferenceKeyNotFoundException extends \RuntimeException
{}

24
app/Http/Controllers/PagesController.php

@ -2,32 +2,16 @@
namespace App\Http\Controllers;
use App\Entities\Pages\PagesRepository;
use App\Entities\Projects\Project;
use DB;
class PagesController extends Controller {
private $repo;
public function __construct(PagesRepository $repo)
{
$this->repo = $repo;
}
class PagesController extends Controller
{
public function home()
{
$projectsCount = Project::select(DB::raw('status_id, count(id) as count'))
->groupBy('status_id')
->where('owner_id', auth()->id())
->pluck('count','status_id')
->all();
return view('pages.home', compact('projectsCount'));
return view('pages.home');
}
public function about()
{
return view('pages.about');
}
}
}

2
app/Http/Middleware/GlobalViewVariables.php

@ -22,7 +22,7 @@ class GlobalViewVariables
->pluck('count', 'status_id')
->all();
view()->share('sidebarProjectStats', $projectsCount);
view()->share('projectStatusStats', $projectsCount);
return $next($request);
}

116
resources/views/pages/home.blade.php

@ -7,59 +7,71 @@
@section('content-dashboard')
<div class="row">
<div class="col-lg-3 col-md-6">
@include('view-components.dashboard-panel', [
'class' => 'default',
'icon' => 'paperclip',
'number' => array_key_exists(1, $projectsCount) ? $projectsCount[1] : 0,
'text' => $projectStatuses::getNameById(1),
'linkRoute' => route('projects.index', ['status' => 1]),
])
<div class="col-md-6">
<legend style="border-bottom: none" class="text-center">Project Status Stats</legend>
<div class="row">
@foreach($projectStatuses::all() as $statusId => $status)
@if ($statusId == 4)
<div class="row">
@endif
<div class="col-md-4">
@include('view-components.dashboard-panel', [
'class' => $projectStatuses->getColorById($statusId),
'icon' => $projectStatuses->getIconById($statusId),
'number' => array_key_exists($statusId, $projectStatusStats) ? $projectStatusStats[$statusId] : 0,
'text' => $projectStatuses::getNameById($statusId),
'linkRoute' => route('projects.index', ['status' => $statusId]),
])
</div>
@if ($statusId == 3)
</div>
@endif
@endforeach
</div>
</div>
<div class="col-lg-3 col-md-6">
@include('view-components.dashboard-panel', [
'class' => 'yellow',
'icon' => 'tasks',
'number' => array_key_exists(2, $projectsCount) ? $projectsCount[2] : 0,
'text' => $projectStatuses::getNameById(2),
'linkRoute' => route('projects.index', ['status' => 2]),
])
</div>
<div class="col-lg-3 col-md-6">
@include('view-components.dashboard-panel', [
'class' => 'primary',
'icon' => 'thumbs-o-up',
'number' => array_key_exists(3, $projectsCount) ? $projectsCount[3] : 0,
'text' => $projectStatuses::getNameById(3),
'linkRoute' => route('projects.index', ['status' => 3]),
])
</div>
<div class="col-lg-3 col-md-6">
@include('view-components.dashboard-panel', [
'class' => 'green',
'icon' => 'money',
'number' => array_key_exists(4, $projectsCount) ? $projectsCount[4] : 0,
'text' => $projectStatuses::getNameById(4),
'linkRoute' => route('projects.index', ['status' => 4]),
])
</div>
<div class="col-lg-3 col-md-6 col-lg-offset-3">
@include('view-components.dashboard-panel', [
'class' => 'danger',
'icon' => 'frown-o',
'number' => array_key_exists(5, $projectsCount) ? $projectsCount[5] : 0,
'text' => $projectStatuses::getNameById(5),
'linkRoute' => route('projects.index', ['status' => 5]),
])
</div>
<div class="col-lg-3 col-md-6">
@include('view-components.dashboard-panel', [
'class' => 'warning',
'icon' => 'hand-paper-o',
'number' => array_key_exists(6, $projectsCount) ? $projectsCount[6] : 0,
'text' => $projectStatuses::getNameById(6),
'linkRoute' => route('projects.index', ['status' => 6]),
])
<div class="col-md-6">
<legend style="border-bottom: none" class="text-center">Earnings Stats</legend>
<div class="panel panel-default table-responsive hidden-xs">
<table class="table table-condensed table-bordered">
<tr>
<td class="col-xs-2 text-center">Yearly Earnings (2017)</td>
<td class="col-xs-2 text-center">Finished Project (2017)</td>
<td class="col-xs-2 text-center">Receiveable Earnings</td>
</tr>
<tr>
<td class="text-center lead" style="border-top: none;">{{ formatRp(1000000) }}</td>
<td class="text-center lead" style="border-top: none;">0 Projects</td>
<td class="text-center lead" style="border-top: none;">{{ formatRp(1000000) }}</td>
</tr>
</table>
</div>
<ul class="list-group visible-xs">
<li class="list-group-item">Earnings (2017) <span class="pull-right">{{ formatRp(1000000) }}</span></li>
<li class="list-group-item">Finished Project (2017) <span class="pull-right">0 Projects</span></li>
<li class="list-group-item">Receiveable Earnings <span class="pull-right">{{ formatRp(1000000) }}</span></li>
</ul>
<legend style="border-bottom: none" class="text-center">Upcoming Subscriptions Due Dates</legend>
<div class="panel panel-default">
<table class="table table-condensed">
<tr>
<th class="col-xs-2">Project</th>
<th class="col-xs-3">Items</th>
<th class="col-xs-2 text-right">Tagihan</th>
<th class="col-xs-2 text-center">Due Date</th>
</tr>
@foreach(range(1, 4) as $subscription)
<tr>
<td>Project {{ $subscription }}</td>
<td>Hosting &amp; Domain</td>
<td class="text-right">{{ formatRp(rand(1, 3).'000000') }}</td>
<td class="text-center">2017-12-01</td>
</tr>
@endforeach
</table>
</div>
</div>
</div>
@endsection

10
resources/views/view-components/dashboard-panel.blade.php

@ -9,16 +9,16 @@ $linkRoute = isset($linkRoute) ? $linkRoute : '#';
<a href="{{ $linkRoute }}">
<div class="panel panel-{{ $class }}">
<div class="panel-heading">
<div class="panel-heading" style="padding:6px 10px">
<div class="row">
<div class="col-xs-3"><i class="fa fa-{{ $icon }} fa-5x"></i></div>
<div class="col-xs-9 text-right">
<div class="huge">{{ $number }}</div>
<div class="col-xs-3"><i class="fa fa-{{ $icon }} fa-3x"></i></div>
<div class="col-xs-9 text-center">
<div style="font-size: 35px; line-height: 40px;">{{ $number }}</div>
<div class="lead">{{ $text }}</div>
</div>
</div>
</div>
<div class="panel-footer">
<div class="panel-footer" style="padding:6px 10px">
{{ $linkText }} <span class="pull-right"><i class="fa fa-arrow-circle-right"></i></span>
</div>
</div>

8
resources/views/view-components/sidebar-project-list-links.blade.php

@ -1,12 +1,12 @@
@inject('projectStatuses', 'App\Entities\Projects\Status')
<ul class="nav nav-second-level">
@foreach($projectStatuses::get() as $statusId => $status)
@foreach($projectStatuses::toArray() as $statusId => $status)
<?php
$projectCount = array_key_exists($statusId, $sidebarProjectStats) ? $sidebarProjectStats[$statusId] : 0;
$status .= '<span class="badge pull-right">'.$projectCount.'</span>';
?>
$projectCount = array_key_exists($statusId, $projectStatusStats) ? $projectStatusStats[$statusId] : 0;
$status .= '<span class="badge pull-right">'.$projectCount.'</span>';
?>
<li>{!! html_link_to_route('projects.index', $status, ['status' => $statusId]) !!}</li>

28
tests/Unit/References/ProjectStatusTest.php

@ -23,7 +23,7 @@ class ProjectStatusTest extends TestCase
}
/** @test */
public function retrieve_project_status_by_id()
public function retrieve_project_status_name_by_id()
{
$projectStatus = new Status;
@ -34,4 +34,30 @@ class ProjectStatusTest extends TestCase
$this->assertEquals(trans('project.canceled'), $projectStatus->getNameById(5));
$this->assertEquals(trans('project.on_hold'), $projectStatus->getNameById(6));
}
/** @test */
public function retrieve_project_status_icon_by_id()
{
$projectStatus = new Status;
$this->assertEquals('paperclip', $projectStatus->getIconById(1));
$this->assertEquals('tasks', $projectStatus->getIconById(2));
$this->assertEquals('thumbs-o-up', $projectStatus->getIconById(3));
$this->assertEquals('money', $projectStatus->getIconById(4));
$this->assertEquals('frown-o', $projectStatus->getIconById(5));
$this->assertEquals('hand-paper-o', $projectStatus->getIconById(6));
}
/** @test */
public function retrieve_project_status_color_class_by_id()
{
$projectStatus = new Status;
$this->assertEquals('default', $projectStatus->getColorById(1));
$this->assertEquals('yellow', $projectStatus->getColorById(2));
$this->assertEquals('primary', $projectStatus->getColorById(3));
$this->assertEquals('green', $projectStatus->getColorById(4));
$this->assertEquals('danger', $projectStatus->getColorById(5));
$this->assertEquals('warning', $projectStatus->getColorById(6));
}
}
Loading…
Cancel
Save