Browse Source

Added flash messages to cart actions and update .travis.yml

pull/3/head
Nafies Luthfi 9 years ago
parent
commit
65e3d2056c
  1. 3
      .travis.yml
  2. 17
      app/Http/Controllers/CartController.php
  3. 2
      public/css/app.custom.css
  4. 7
      resources/lang/id/transaction.php
  5. 3
      resources/views/layouts/app.blade.php
  6. 22
      resources/views/vendor/flash/message.blade.php
  7. 19
      resources/views/vendor/flash/modal.blade.php
  8. 1
      tests/Feature/TransactionEntryTest.php

3
.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

17
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');
}
}

2
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 */

7
resources/lang/id/transaction.php

@ -14,10 +14,17 @@ return [
'discount_total' => 'Total Diskon',
'total' => 'Total',
'exchange' => 'Kembalian',
'draft_added' => 'Draft transaksi <strong>:type</strong> 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: <strong>:invoice_no</strong>',
// Attributes
'customer' => 'Customer',

3
resources/views/layouts/app.blade.php

@ -26,8 +26,9 @@
<body>
@include('layouts.partials.top-nav')
<div class="container">
@include('flash::message')
@yield('content')
{{-- @include('flash::message') --}}
<br>
</div>
<!-- Scripts -->

22
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
<div class="alert
alert-{{ session('flash_notification.level') }}
{{ session()->has('flash_notification.important') ? 'alert-important' : 'notifier' }}"
>
<button type="button"
class="close"
data-dismiss="alert"
aria-hidden="true"
>&times;</button>
{!! session('flash_notification.message') !!}
</div>
@endif
@endif

19
resources/views/vendor/flash/modal.blade.php

@ -0,0 +1,19 @@
<div id="flash-overlay-modal" class="modal fade {{ $modalClass or '' }}">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title">{{ $title }}</h4>
</div>
<div class="modal-body">
<p>{!! $body !!}</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>

1
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',

Loading…
Cancel
Save