From f9786482deb979382a4a5a9592346e3631dfea30 Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Sun, 12 Nov 2017 22:43:01 +0800 Subject: [PATCH] Change projectStatusList from global function to reference class --- app/Entities/Projects/ProjectPresenter.php | 3 ++- app/Entities/Projects/ProjectsRepository.php | 15 ++++++++------- app/Http/Controllers/Projects/ProjectsController.php | 3 +-- app/helpers.php | 15 --------------- config/app.php | 1 + resources/views/projects/edit.blade.php | 2 +- resources/views/projects/index.blade.php | 2 +- resources/views/projects/show.blade.php | 2 +- resources/views/reports/payments/monthly.blade.php | 1 + resources/views/reports/payments/yearly.blade.php | 1 + resources/views/subscriptions/create.blade.php | 3 +-- resources/views/subscriptions/edit.blade.php | 3 +-- 12 files changed, 19 insertions(+), 32 deletions(-) diff --git a/app/Entities/Projects/ProjectPresenter.php b/app/Entities/Projects/ProjectPresenter.php index 0d47c60..fbd3e9f 100644 --- a/app/Entities/Projects/ProjectPresenter.php +++ b/app/Entities/Projects/ProjectPresenter.php @@ -3,6 +3,7 @@ namespace App\Entities\Projects; use Laracasts\Presenter\Presenter; +use ProjectStatus; class ProjectPresenter extends Presenter { @@ -18,7 +19,7 @@ class ProjectPresenter extends Presenter public function status() { - return getProjectStatusesList($this->entity->status_id); + return ProjectStatus::getNameById($this->entity->status_id); } public function workDuration() diff --git a/app/Entities/Projects/ProjectsRepository.php b/app/Entities/Projects/ProjectsRepository.php index cf7419c..4066797 100755 --- a/app/Entities/Projects/ProjectsRepository.php +++ b/app/Entities/Projects/ProjectsRepository.php @@ -5,6 +5,7 @@ namespace App\Entities\Projects; use App\Entities\BaseRepository; use App\Entities\Partners\Customer; use DB; +use ProjectStatus; /** * Projects Repository Class @@ -20,7 +21,7 @@ class ProjectsRepository extends BaseRepository public function getProjects($q, $statusId) { - $statusIds = array_keys(getProjectStatusesList()); + $statusIds = array_keys(ProjectStatus::toArray()); return $this->model->latest() ->where(function ($query) use ($q, $statusId, $statusIds) { @@ -41,7 +42,7 @@ class ProjectsRepository extends BaseRepository DB::beginTransaction(); if (isset($projectData['customer_id']) == false || $projectData['customer_id'] == '') { - $customer = $this->createNewCustomer($projectData['customer_name'], $projectData['customer_email']); + $customer = $this->createNewCustomer($projectData['customer_name'], $projectData['customer_email']); $projectData['customer_id'] = $customer->id; } unset($projectData['customer_name']); @@ -59,9 +60,9 @@ class ProjectsRepository extends BaseRepository public function createNewCustomer($customerName, $customerEmail) { - $newCustomer = new Customer; - $newCustomer->name = $customerName; - $newCustomer->email = $customerEmail; + $newCustomer = new Customer; + $newCustomer->name = $customerName; + $newCustomer->email = $customerEmail; $newCustomer->save(); return $newCustomer; @@ -103,7 +104,7 @@ class ProjectsRepository extends BaseRepository public function updateStatus($statusId, $projectId) { - $project = $this->requireById($projectId); + $project = $this->requireById($projectId); $project->status_id = $statusId; $project->save(); @@ -114,7 +115,7 @@ class ProjectsRepository extends BaseRepository { $featureOrder = explode(',', $sortedData); foreach ($featureOrder as $order => $featureId) { - $feature = $this->requireFeatureById($featureId); + $feature = $this->requireFeatureById($featureId); $feature->position = $order + 1; $feature->save(); } diff --git a/app/Http/Controllers/Projects/ProjectsController.php b/app/Http/Controllers/Projects/ProjectsController.php index 503a521..84e7a33 100755 --- a/app/Http/Controllers/Projects/ProjectsController.php +++ b/app/Http/Controllers/Projects/ProjectsController.php @@ -52,9 +52,8 @@ class ProjectsController extends Controller public function edit($projectId) { $project = $this->repo->requireById($projectId); - $statuses = getProjectStatusesList(); $customers = $this->repo->getCustomersList(); - return view('projects.edit', compact('project', 'statuses', 'customers')); + return view('projects.edit', compact('project', 'customers')); } public function update(UpdateRequest $request, $projectId) diff --git a/app/helpers.php b/app/helpers.php index f4e72e6..f2c9702 100755 --- a/app/helpers.php +++ b/app/helpers.php @@ -194,21 +194,6 @@ function html_link_to_route($name, $title = null, $parameters = [], $attributes return app('html')->decode(link_to_route($name, $title, $parameters, $attributes)); } -function getProjectStatusesList($statusId = null) -{ - $statuses = [1 => 'Planned', 'On Progress', 'Done', 'Closed', 'Canceled', 'On Hold']; - - if (is_null($statusId)) { - return $statuses; - } - - if (array_key_exists($statusId, $statuses)) { - return $statuses[$statusId]; - } - - return null; -} - function dateDifference($date1, $date2, $differenceFormat = '%a') { $datetime1 = date_create($date1); diff --git a/config/app.php b/config/app.php index 38033dd..8045828 100644 --- a/config/app.php +++ b/config/app.php @@ -215,6 +215,7 @@ return [ // Reference Facades 'PaymentType' => App\Entities\Payments\Type::class, 'SubscriptionType' => App\Entities\Subscriptions\Type::class, + 'ProjectStatus' => App\Entities\Projects\Status::class, ], ]; diff --git a/resources/views/projects/edit.blade.php b/resources/views/projects/edit.blade.php index 58a93ca..cc35319 100755 --- a/resources/views/projects/edit.blade.php +++ b/resources/views/projects/edit.blade.php @@ -35,7 +35,7 @@
- {!! FormField::select('status_id', $statuses, ['label' => trans('app.status')]) !!} + {!! FormField::select('status_id', ProjectStatus::toArray(), ['label' => trans('app.status')]) !!}
{!! FormField::select('customer_id', $customers, ['label' => trans('project.customer')]) !!} diff --git a/resources/views/projects/index.blade.php b/resources/views/projects/index.blade.php index c40910c..268d086 100755 --- a/resources/views/projects/index.blade.php +++ b/resources/views/projects/index.blade.php @@ -10,7 +10,7 @@
{!! Form::open(['method'=>'get','class'=>'form-inline']) !!} - {!! FormField::select('status', getProjectStatusesList(), ['value' => Request::get('status'), 'placeholder'=> 'Semua Project']) !!} + {!! FormField::select('status', ProjectStatus::toArray(), ['value' => Request::get('status'), 'placeholder'=> 'Semua Project']) !!} {!! Form::text('q', Request::get('q'), ['class'=>'form-control index-search-field','placeholder'=>trans('project.search'),'style' => 'width:100%;max-width:350px']) !!} {!! Form::submit(trans('project.search'), ['class' => 'btn btn-info btn-sm']) !!} {!! link_to_route('projects.index','Reset',[],['class' => 'btn btn-default btn-sm']) !!} diff --git a/resources/views/projects/show.blade.php b/resources/views/projects/show.blade.php index 362e447..302cf38 100755 --- a/resources/views/projects/show.blade.php +++ b/resources/views/projects/show.blade.php @@ -22,7 +22,7 @@
@include('projects.partials.project-stats') {!! Form::model($project, ['route' => ['projects.status-update', $project->id], 'method' => 'patch','class' => 'well well-sm form-inline']) !!} - {!! FormField::select('status_id', getProjectStatusesList(), ['label' => trans('project.status')]) !!} + {!! FormField::select('status_id', ProjectStatus::toArray(), ['label' => trans('project.status')]) !!} {!! Form::submit('Update Project Status', ['class' => 'btn btn-info']) !!} {!! Form::close() !!}
diff --git a/resources/views/reports/payments/monthly.blade.php b/resources/views/reports/payments/monthly.blade.php index 901484b..76d20b6 100755 --- a/resources/views/reports/payments/monthly.blade.php +++ b/resources/views/reports/payments/monthly.blade.php @@ -107,6 +107,7 @@ goals: [0], goalLineColors : ['red'], smooth: false, + lineWidth: 2, }); })(); diff --git a/resources/views/reports/payments/yearly.blade.php b/resources/views/reports/payments/yearly.blade.php index 2ac8641..ff2c1b1 100755 --- a/resources/views/reports/payments/yearly.blade.php +++ b/resources/views/reports/payments/yearly.blade.php @@ -97,6 +97,7 @@ goals: [0], goalLineColors : ['red'], smooth: false, + lineWidth: 2, }); })(); diff --git a/resources/views/subscriptions/create.blade.php b/resources/views/subscriptions/create.blade.php index 35b3ffe..cb9b997 100755 --- a/resources/views/subscriptions/create.blade.php +++ b/resources/views/subscriptions/create.blade.php @@ -3,7 +3,6 @@ @section('title', trans('subscription.create')) @section('content') -@inject('subscriptionTypes', 'App\Entities\Subscriptions\Type')
{!! FormField::select('project_id', $projects, ['label' => trans('subscription.project'), 'value' => Request::get('project_id')]) !!} {!! FormField::select('vendor_id', $vendors, ['label' => trans('subscription.vendor'), 'value' => Request::get('vendor_id')]) !!} - {!! FormField::radios('type_id', $subscriptionTypes::toArray(), ['label' => trans('subscription.type'), 'value' => Request::get('type_id')]) !!} + {!! FormField::radios('type_id', SubscriptionType::toArray(), ['label' => trans('subscription.type'), 'value' => Request::get('type_id')]) !!} {!! FormField::textarea('notes', ['label' => trans('subscription.notes')]) !!}
diff --git a/resources/views/subscriptions/edit.blade.php b/resources/views/subscriptions/edit.blade.php index 9295654..fdc6cb0 100755 --- a/resources/views/subscriptions/edit.blade.php +++ b/resources/views/subscriptions/edit.blade.php @@ -3,7 +3,6 @@ @section('title', $pageTitle) @section('content') -@inject('subscriptionTypes', 'App\Entities\Subscriptions\Type') @include('subscriptions.partials.breadcrumb', ['title' => $pageTitle]) @includeWhen(request('action') == 'delete', 'subscriptions.partials.delete') @@ -16,7 +15,7 @@

{{ $pageTitle }}

-
{!! FormField::radios('type_id', $subscriptionTypes::toArray(), ['label' => trans('subscription.type'), 'value' => Request::get('type_id')]) !!}
+
{!! FormField::radios('type_id', SubscriptionType::toArray(), ['label' => trans('subscription.type'), 'value' => Request::get('type_id')]) !!}
{!! FormField::radios('status_id', [trans('app.in_active'), trans('app.active')],['label' => trans('app.status')]) !!}