From 120b249e11d3360d30d0355423c3ee9217709b31 Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Thu, 2 Nov 2017 09:22:52 +0800 Subject: [PATCH] Add project Status ref object and GlobalViewVariables middleware --- app/Entities/Projects/Status.php | 37 ++++++++++ app/Entities/ReferenceAbstract.php | 62 ++++++++++++++++ app/Http/Kernel.php | 11 +-- app/Http/Middleware/GlobalViewVariables.php | 29 ++++++++ resources/lang/id/project.php | 82 ++++++++++++---------- resources/views/layouts/partials/sidebar.blade.php | 49 ++----------- resources/views/pages/home.blade.php | 28 ++++---- .../sidebar-project-list-links.blade.php | 14 ++++ tests/Unit/References/ProjectStatusTest.php | 37 ++++++++++ 9 files changed, 249 insertions(+), 100 deletions(-) create mode 100644 app/Entities/Projects/Status.php create mode 100644 app/Entities/ReferenceAbstract.php create mode 100644 app/Http/Middleware/GlobalViewVariables.php create mode 100644 resources/views/view-components/sidebar-project-list-links.blade.php create mode 100644 tests/Unit/References/ProjectStatusTest.php diff --git a/app/Entities/Projects/Status.php b/app/Entities/Projects/Status.php new file mode 100644 index 0000000..0b31ea0 --- /dev/null +++ b/app/Entities/Projects/Status.php @@ -0,0 +1,37 @@ + 'planned', + 2 => 'progress', + 3 => 'done', + 4 => 'closed', + 5 => 'canceled', + 6 => 'on_hold', + ]; + + public static function getNameById($singleId) + { + return trans('project.'.static::$lists[$singleId]); + } + + public static function toArray() + { + $lists = []; + foreach (static::$lists as $key => $value) { + $lists[$key] = trans('project.'.$value); + } + + return $lists; + } + + public static function all() + { + return collect($this->toArray()); + } +} diff --git a/app/Entities/ReferenceAbstract.php b/app/Entities/ReferenceAbstract.php new file mode 100644 index 0000000..a5202dc --- /dev/null +++ b/app/Entities/ReferenceAbstract.php @@ -0,0 +1,62 @@ + \Illuminate\Auth\Middleware\Authenticate::class, + 'auth' => \Illuminate\Auth\Middleware\Authenticate::class, 'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class, - 'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class, - 'can' => \Illuminate\Auth\Middleware\Authorize::class, - 'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, - 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, + 'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class, + 'can' => \Illuminate\Auth\Middleware\Authorize::class, + 'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, + 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, ]; } diff --git a/app/Http/Middleware/GlobalViewVariables.php b/app/Http/Middleware/GlobalViewVariables.php new file mode 100644 index 0000000..d7e477b --- /dev/null +++ b/app/Http/Middleware/GlobalViewVariables.php @@ -0,0 +1,29 @@ +groupBy('status_id') + ->pluck('count', 'status_id') + ->all(); + + view()->share('sidebarProjectStats', $projectsCount); + + return $next($request); + } +} diff --git a/resources/lang/id/project.php b/resources/lang/id/project.php index 9e715e4..336c8a8 100644 --- a/resources/lang/id/project.php +++ b/resources/lang/id/project.php @@ -2,50 +2,58 @@ return [ // Labels - 'project' => 'Project', - 'projects' => 'Daftar Project', - 'work_duration' => 'Durasi', - 'cash_in_total' => 'Total Pemasukan', - 'cash_out_total' => 'Total Pengeluaran', - 'search' => 'Cari Project', - 'found' => 'Project ditemukan', - 'not_found' => 'Project tidak ditemukan', - 'empty' => 'Belum ada Project', - 'back_to_index' => 'Kembali ke daftar Project', + 'project' => 'Project', + 'projects' => 'Daftar Project', + 'work_duration' => 'Durasi', + 'cash_in_total' => 'Total Pemasukan', + 'cash_out_total' => 'Total Pengeluaran', + 'search' => 'Cari Project', + 'found' => 'Project ditemukan', + 'not_found' => 'Project tidak ditemukan', + 'empty' => 'Belum ada Project', + 'back_to_index' => 'Kembali ke daftar Project', // Actions - 'create' => 'Input Project Baru', - 'created' => 'Input Project baru telah berhasil.', - 'show' => 'Detail Project', - 'edit' => 'Edit Project', - 'update' => 'Update Project', - 'updated' => 'Update data Project telah berhasil.', - 'delete' => 'Hapus Project', - 'deleted' => 'Hapus data Project telah berhasil.', - 'undeleted' => 'Data Project gagal dihapus.', - 'show_features' => 'Lihat Fitur', + 'create' => 'Input Project Baru', + 'created' => 'Input Project baru telah berhasil.', + 'show' => 'Detail Project', + 'edit' => 'Edit Project', + 'update' => 'Update Project', + 'updated' => 'Update data Project telah berhasil.', + 'delete' => 'Hapus Project', + 'deleted' => 'Hapus data Project telah berhasil.', + 'undeleted' => 'Data Project gagal dihapus.', + 'show_features' => 'Lihat Fitur', 'features_export_html' => 'Export HTML', 'features_export_excel' => 'Export Excel', 'features_export_progress_excel' => 'Export Progress', // Attributes - 'name' => 'Nama Project', - 'description' => 'Deskripsi Project', - 'start_date' => 'Tanggal Mulai', - 'end_date' => 'Tanggal Selesai', - 'proposal_date' => 'Tanggal Proposal', - 'project_value' => 'Nilai Project', - 'proposal_value' => 'Nilai Proposal', + 'name' => 'Nama Project', + 'description' => 'Deskripsi Project', + 'start_date' => 'Tanggal Mulai', + 'end_date' => 'Tanggal Selesai', + 'proposal_date' => 'Tanggal Proposal', + 'project_value' => 'Nilai Project', + 'proposal_value' => 'Nilai Proposal', // Relations - 'files' => 'List Dokumen', - 'features' => 'Daftar Item Pekerjaan', - 'cost_proposal' => 'Pengajuan Biaya', - 'invoices' => 'List Invoice', - 'customer' => 'Customer', - 'worker' => 'Pekerja', - 'subscriptions' => 'Langganan', - 'status' => 'Status Project', - 'payments' => 'Pembayaran', -]; \ No newline at end of file + 'files' => 'List Dokumen', + 'features' => 'Daftar Item Pekerjaan', + 'cost_proposal' => 'Pengajuan Biaya', + 'invoices' => 'List Invoice', + 'customer' => 'Customer', + 'worker' => 'Pekerja', + 'subscriptions' => 'Langganan', + 'status' => 'Status Project', + 'payments' => 'Pembayaran', + + // Statuses + 'planned' => 'Planned', + 'progress' => 'Progress', + 'done' => 'Done', + 'closed' => 'Closed', + 'canceled' => 'Canceled', + 'on_hold' => 'On Hold', +]; diff --git a/resources/views/layouts/partials/sidebar.blade.php b/resources/views/layouts/partials/sidebar.blade.php index 80b89e1..3512380 100755 --- a/resources/views/layouts/partials/sidebar.blade.php +++ b/resources/views/layouts/partials/sidebar.blade.php @@ -6,6 +6,7 @@ + - diff --git a/resources/views/pages/home.blade.php b/resources/views/pages/home.blade.php index e17b806..4d9e585 100755 --- a/resources/views/pages/home.blade.php +++ b/resources/views/pages/home.blade.php @@ -1,3 +1,5 @@ +@inject('projectStatuses', 'App\Entities\Projects\Status') + @extends('layouts.dashboard') @section('title', trans('nav_menu.dashboard')) @@ -10,8 +12,8 @@ 'class' => 'default', 'icon' => 'paperclip', 'number' => array_key_exists(1, $projectsCount) ? $projectsCount[1] : 0, - 'text' => getProjectStatusesList(1), - 'linkRoute' => route('projects.index',['status' => 1]), + 'text' => $projectStatuses::getNameById(1), + 'linkRoute' => route('projects.index', ['status' => 1]), ])
@@ -19,8 +21,8 @@ 'class' => 'yellow', 'icon' => 'tasks', 'number' => array_key_exists(2, $projectsCount) ? $projectsCount[2] : 0, - 'text' => getProjectStatusesList(2), - 'linkRoute' => route('projects.index',['status' => 2]), + 'text' => $projectStatuses::getNameById(2), + 'linkRoute' => route('projects.index', ['status' => 2]), ])
@@ -28,8 +30,8 @@ 'class' => 'primary', 'icon' => 'thumbs-o-up', 'number' => array_key_exists(3, $projectsCount) ? $projectsCount[3] : 0, - 'text' => getProjectStatusesList(3), - 'linkRoute' => route('projects.index',['status' => 3]), + 'text' => $projectStatuses::getNameById(3), + 'linkRoute' => route('projects.index', ['status' => 3]), ])
@@ -37,17 +39,17 @@ 'class' => 'green', 'icon' => 'money', 'number' => array_key_exists(4, $projectsCount) ? $projectsCount[4] : 0, - 'text' => getProjectStatusesList(4), - 'linkRoute' => route('projects.index',['status' => 4]), + 'text' => $projectStatuses::getNameById(4), + 'linkRoute' => route('projects.index', ['status' => 4]), ])
@include('view-components.dashboard-panel', [ 'class' => 'danger', - 'icon' => 'fa-smile-o', + 'icon' => 'frown-o', 'number' => array_key_exists(5, $projectsCount) ? $projectsCount[5] : 0, - 'text' => getProjectStatusesList(5), - 'linkRoute' => route('projects.index',['status' => 5]), + 'text' => $projectStatuses::getNameById(5), + 'linkRoute' => route('projects.index', ['status' => 5]), ])
@@ -55,8 +57,8 @@ 'class' => 'warning', 'icon' => 'hand-paper-o', 'number' => array_key_exists(6, $projectsCount) ? $projectsCount[6] : 0, - 'text' => getProjectStatusesList(6), - 'linkRoute' => route('projects.index',['status' => 6]), + 'text' => $projectStatuses::getNameById(6), + 'linkRoute' => route('projects.index', ['status' => 6]), ])
diff --git a/resources/views/view-components/sidebar-project-list-links.blade.php b/resources/views/view-components/sidebar-project-list-links.blade.php new file mode 100644 index 0000000..27e8f14 --- /dev/null +++ b/resources/views/view-components/sidebar-project-list-links.blade.php @@ -0,0 +1,14 @@ +@inject('projectStatuses', 'App\Entities\Projects\Status') + + diff --git a/tests/Unit/References/ProjectStatusTest.php b/tests/Unit/References/ProjectStatusTest.php new file mode 100644 index 0000000..1bb24f9 --- /dev/null +++ b/tests/Unit/References/ProjectStatusTest.php @@ -0,0 +1,37 @@ +assertEquals([ + 1 => trans('project.planned'), + 2 => trans('project.progress'), + 3 => trans('project.done'), + 4 => trans('project.closed'), + 5 => trans('project.canceled'), + 6 => trans('project.on_hold'), + ], $projectStatus->toArray()); + } + + /** @test */ + public function retrieve_project_status_by_id() + { + $projectStatus = new Status; + + $this->assertEquals(trans('project.planned'), $projectStatus->getNameById(1)); + $this->assertEquals(trans('project.progress'), $projectStatus->getNameById(2)); + $this->assertEquals(trans('project.done'), $projectStatus->getNameById(3)); + $this->assertEquals(trans('project.closed'), $projectStatus->getNameById(4)); + $this->assertEquals(trans('project.canceled'), $projectStatus->getNameById(5)); + $this->assertEquals(trans('project.on_hold'), $projectStatus->getNameById(6)); + } +}