From 65e3d2056ca90ab6c8c143d3118dd620529f29a4 Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Thu, 27 Apr 2017 16:52:47 +0700 Subject: [PATCH] Added flash messages to cart actions and update .travis.yml --- .travis.yml | 3 +-- app/Http/Controllers/CartController.php | 17 ++++++++++++++--- public/css/app.custom.css | 2 +- resources/lang/id/transaction.php | 7 +++++++ resources/views/layouts/app.blade.php | 3 ++- resources/views/vendor/flash/message.blade.php | 22 ++++++++++++++++++++++ resources/views/vendor/flash/modal.blade.php | 19 +++++++++++++++++++ tests/Feature/TransactionEntryTest.php | 1 + 8 files changed, 67 insertions(+), 7 deletions(-) create mode 100644 resources/views/vendor/flash/message.blade.php create mode 100644 resources/views/vendor/flash/modal.blade.php diff --git a/.travis.yml b/.travis.yml index d547054..6fd0b19 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,6 @@ language: php php: - 7.0 - - 7.1 before_script: - travis_retry composer self-update @@ -11,4 +10,4 @@ before_script: - php artisan key:generate script: - - phpunit + - vendor/bin/phpunit diff --git a/app/Http/Controllers/CartController.php b/app/Http/Controllers/CartController.php index dc46896..f59011c 100644 --- a/app/Http/Controllers/CartController.php +++ b/app/Http/Controllers/CartController.php @@ -29,8 +29,10 @@ class CartController extends Controller public function show(Request $request, $draftKey) { $draft = $this->cart->get($draftKey); - if (is_null($draft)) + if (is_null($draft)) { + flash(trans('transaction.draft_not_found'), 'danger'); return redirect()->route('cart.index'); + } $query = $request->get('query'); $queriedProducts = []; @@ -97,6 +99,7 @@ class CartController extends Controller public function destroy() { $this->cart->destroy(); + flash(trans('transaction.draft_destroyed'), 'warning'); return redirect()->route('cart.index'); } @@ -109,7 +112,14 @@ class CartController extends Controller 'payment' => 'required|numeric', 'notes' => 'nullable|string|max:100', ]); - $this->cart->updateDraftAttributes($draftKey, $request->only('customer','notes','payment')); + $draft = $this->cart->updateDraftAttributes($draftKey, $request->only('customer','notes','payment')); + + if ($draft->getItemsCount() == 0) { + flash(trans('transaction.item_list_empty'), 'warning')->important(); + return redirect()->route('cart.show', [$draftKey]); + } + + flash(trans('transaction.confirm_instruction', ['back_link' => link_to_route('cart.show', trans('app.back'), $draftKey)]), 'warning')->important(); return redirect()->route('cart.show', [$draftKey, 'action' => 'confirm']); } @@ -119,8 +129,9 @@ class CartController extends Controller if (is_null($draft)) return redirect()->route('cart.index'); - $draft->store(); + $transaction = $draft->store(); $draft->destroy(); + flash(trans('transaction.created', ['invoice_no' => $transaction->invoice_no]), 'success')->important(); return redirect()->route('cart.index'); } } diff --git a/public/css/app.custom.css b/public/css/app.custom.css index 33da1f2..952ed1f 100644 --- a/public/css/app.custom.css +++ b/public/css/app.custom.css @@ -15,7 +15,7 @@ body { font-family: "Trebuchet MS", serif; } /* Layout */ .page-header { margin-top: 0px; } h3.page-header { padding-bottom: 15px; } -div.notifier { z-index: 100; position: absolute; top: 30px; left: 50%; transform: translate(-50%,-50%); } +div.notifier { z-index: 1001; position: absolute; top: 40px; left: 50%; transform: translate(-50%,-50%); } /* End of Layout */ /* Form */ diff --git a/resources/lang/id/transaction.php b/resources/lang/id/transaction.php index ecf26b7..a23041d 100644 --- a/resources/lang/id/transaction.php +++ b/resources/lang/id/transaction.php @@ -14,10 +14,17 @@ return [ 'discount_total' => 'Total Diskon', 'total' => 'Total', 'exchange' => 'Kembalian', + 'draft_added' => 'Draft transaksi :type telah ditambahkan.', + 'draft_removed' => 'Draft transaksi telah dihapus.', + 'draft_destroyed' => 'Seluruh Draft transaksi telah dihapus.', + 'draft_not_found' => 'Draft transaksi tidak ditemukan.', // Actions 'proccess' => 'Proses Transaksi', + 'confirm_instruction' => 'Silakan periksa rincian belanja dibawah ini, jika belum sesuai, silakan :back_link', + 'item_list_empty' => 'Masukkan setidaknya 1 item produk.', 'save' => 'Simpan Transaksi', + 'created' => 'Transaksi berhasil disimpan, No. Invoice: :invoice_no', // Attributes 'customer' => 'Customer', diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php index 7a0f42c..7702b87 100644 --- a/resources/views/layouts/app.blade.php +++ b/resources/views/layouts/app.blade.php @@ -26,8 +26,9 @@ @include('layouts.partials.top-nav')
+ @include('flash::message') @yield('content') - {{-- @include('flash::message') --}} +
diff --git a/resources/views/vendor/flash/message.blade.php b/resources/views/vendor/flash/message.blade.php new file mode 100644 index 0000000..d76736e --- /dev/null +++ b/resources/views/vendor/flash/message.blade.php @@ -0,0 +1,22 @@ +@if (session()->has('flash_notification.message')) + @if (session()->has('flash_notification.overlay')) + @include('flash::modal', [ + 'modalClass' => 'flash-modal', + 'title' => session('flash_notification.title'), + 'body' => session('flash_notification.message') + ]) + @else +
+ + + {!! session('flash_notification.message') !!} +
+ @endif +@endif diff --git a/resources/views/vendor/flash/modal.blade.php b/resources/views/vendor/flash/modal.blade.php new file mode 100644 index 0000000..41b821c --- /dev/null +++ b/resources/views/vendor/flash/modal.blade.php @@ -0,0 +1,19 @@ + diff --git a/tests/Feature/TransactionEntryTest.php b/tests/Feature/TransactionEntryTest.php index 69d602b..dde497f 100644 --- a/tests/Feature/TransactionEntryTest.php +++ b/tests/Feature/TransactionEntryTest.php @@ -235,6 +235,7 @@ class TransactionEntryTest extends BrowserKitTestCase $this->press(trans('transaction.save')); $this->seePageIs(route('cart.index')); + $this->see(trans('transaction.created', ['invoice_no' => date('ym') . '0001'])); $this->seeInDatabase('transactions', [ 'invoice_no' => date('ym') . '0001',