Browse Source

Add long running job trigger button

pull/1/head
Nafies Luthfi 5 years ago
parent
commit
fd61deea8a
  1. 21
      app/Helpers/functions.php
  2. 2
      app/Providers/AppServiceProvider.php
  3. 2
      resources/views/home.blade.php
  4. 27
      resources/views/layouts/app.blade.php
  5. 24
      resources/views/welcome.blade.php
  6. 8
      routes/web.php

21
app/Helpers/functions.php

@ -0,0 +1,21 @@
<?php
/**
* Function helper to add flash notification.
*
* @param null|string $message The flashed message.
* @param string $level Level/type of message
* @return void
*/
function flash($message = null, $level = 'info')
{
$session = app('session');
if ($level == 'info') {
$level = 'information';
}
if (!is_null($message)) {
$session->flash('flash_notification.message', $message);
$session->flash('flash_notification.level', $level);
}
}

2
app/Providers/AppServiceProvider.php

@ -23,6 +23,6 @@ class AppServiceProvider extends ServiceProvider
*/
public function boot()
{
//
require_once app_path().'/Helpers/functions.php';
}
}

2
resources/views/home.blade.php

@ -15,6 +15,8 @@
@endif
{{ __('You are logged in!') }}
<hr>
<a href="{{ route('long-run-job') }}" class="btn btn-success">Run a long job</a>
</div>
</div>
</div>

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

@ -9,9 +9,6 @@
<title>{{ config('app.name', 'Laravel') }}</title>
<!-- Scripts -->
<script src="{{ asset('js/app.js') }}" defer></script>
<!-- Fonts -->
<link rel="dns-prefetch" href="//fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css?family=Nunito" rel="stylesheet">
@ -76,5 +73,29 @@
@yield('content')
</main>
</div>
<script src="{{ asset('js/app.js') }}"></script>
<script src="{{ asset('js/jquery-3.5.1.min.js') }}"></script>
<script src="{{ asset('js/plugins/noty.js') }}"></script>
<script>
Echo.channel('queue-notifier')
.listen('LongRunJobDone', (e) => {
noty({
type: 'success',
layout: 'bottomRight',
text: e.message,
timeout: false
});
});
</script>
@if (Session::has('flash_notification.message'))
<script>
noty({
type: '{{ Session::get('flash_notification.level') }}',
layout: 'bottomRight',
text: '{{ Session::get('flash_notification.message') }}',
timeout: 5000
});
</script>
@endif
</body>
</html>

24
resources/views/welcome.blade.php

@ -97,28 +97,4 @@
</div>
</div>
</body>
<script src="{{ asset('js/app.js') }}"></script>
<script src="{{ asset('js/jquery-3.5.1.min.js') }}"></script>
<script src="{{ asset('js/plugins/noty.js') }}"></script>
<script>
Echo.channel('queue-notifier')
.listen('LongRunJobDone', (e) => {
noty({
type: 'success',
layout: 'bottomRight',
text: e.message,
timeout: false
});
});
</script>
@if (Session::has('flash_notification.message'))
<script>
noty({
type: 'success',
layout: 'bottomRight',
text: '{{ Session::get('flash_notification.message') }}',
timeout: 5000
});
</script>
@endif
</html>

8
routes/web.php

@ -15,10 +15,16 @@ use Illuminate\Support\Facades\Route;
*/
Route::get('/', function () {
dispatch(new LongRunJob());
return view('welcome');
});
Route::get('/long-run-job', function () {
dispatch(new LongRunJob());
flash('Please wait, your request is processing...');
return redirect()->home();
})->name('long-run-job');
Auth::routes();
Route::get('/home', 'HomeController@index')->name('home');
Loading…
Cancel
Save