Skip to content

Commit

Permalink
fixed error pages
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdulici committed Dec 26, 2019
1 parent ef95a33 commit 6f7d94e
Show file tree
Hide file tree
Showing 11 changed files with 365 additions and 332 deletions.
56 changes: 28 additions & 28 deletions app/Http/ViewComposers/Header.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace App\Http\ViewComposers;

use Auth;
use App\Utilities\Updater;
use Illuminate\View\View;
use App\Traits\Modules as RemoteModules;
Expand All @@ -21,41 +20,42 @@ public function compose(View $view)
{
$user = user();

$bills = [];
$invoices = [];
$notifications = 0;
$invoices = $bills = [];
$updates = $notifications = 0;
$company = null;

// Get customer company
if ($user->can('read-client-portal')) {
$company = (object) [
'company_name' => setting('company.name'),
'company_email' => setting('company.email'),
'company_address' => setting('company.address'),
'company_logo' => setting('company.logo'),
];
}
if (!empty($user)) {
// Get customer company
if ($user->can('read-client-portal')) {
$company = (object) [
'company_name' => setting('company.name'),
'company_email' => setting('company.email'),
'company_address' => setting('company.address'),
'company_logo' => setting('company.logo'),
];
}

$undereads = $user->unreadNotifications;
$undereads = $user->unreadNotifications;

foreach ($undereads as $underead) {
$data = $underead->getAttribute('data');
foreach ($undereads as $underead) {
$data = $underead->getAttribute('data');

switch ($underead->getAttribute('type')) {
case 'App\Notifications\Expense\Bill':
$bills[$data['bill_id']] = $data['amount'];
$notifications++;
break;
case 'App\Notifications\Income\Invoice':
$invoices[$data['invoice_id']] = $data['amount'];
$notifications++;
break;
switch ($underead->getAttribute('type')) {
case 'App\Notifications\Expense\Bill':
$bills[$data['bill_id']] = $data['amount'];
$notifications++;
break;
case 'App\Notifications\Income\Invoice':
$invoices[$data['invoice_id']] = $data['amount'];
$notifications++;
break;
}
}
}

$updates = count(Updater::all());
$updates = count(Updater::all());

$this->loadSuggestions();
$this->loadSuggestions();
}

$view->with([
'user' => $user,
Expand Down
2 changes: 1 addition & 1 deletion app/Http/ViewComposers/Notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Notifications
public function compose(View $view)
{
// No need to add suggestions in console
if (app()->runningInConsole() || !env('APP_INSTALLED')) {
if (app()->runningInConsole() || !env('APP_INSTALLED') || !user()) {
return;
}

Expand Down
36 changes: 19 additions & 17 deletions app/Http/ViewComposers/Suggestions.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,28 @@ public function compose(View $view)

$modules = false;

$path = Route::current()->uri();

if ($path) {
$suggestions = $this->getSuggestions($path);

if ($suggestions) {
$suggestion_modules = $suggestions->modules;

foreach ($suggestion_modules as $key => $module) {
$installed = Module::where('company_id', '=', session('company_id'))->where('alias', '=', $module->alias)->first();

if ($installed) {
unset($suggestion_modules[$key]);
if (user()) {
$path = Route::current()->uri();

if ($path) {
$suggestions = $this->getSuggestions($path);

if ($suggestions) {
$suggestion_modules = $suggestions->modules;

foreach ($suggestion_modules as $key => $module) {
$installed = Module::where('company_id', session('company_id'))->where('alias', $module->alias)->first();

if ($installed) {
unset($suggestion_modules[$key]);
}
}
}

if ($suggestion_modules) {
shuffle($suggestion_modules);
if ($suggestion_modules) {
shuffle($suggestion_modules);

$modules[] = $suggestion_modules[0];
$modules[] = $suggestion_modules[0];
}
}
}
}
Expand Down
27 changes: 13 additions & 14 deletions resources/lang/en-GB/errors.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,22 @@

return [

'forbidden_access' => 'Forbidden Access',
'error_page' => 'Error Page',
'page_not_found' => 'Page Not Found',
'title' => [
'403' => 'Oops! Forbidden Access',
'404' => 'Oops! Page not found',
'500' => 'Oops! Something went wrong',
],

'body' => [
'forbidden_access' => 'Oops! Forbidden Access.',
'error_page' => 'Oops! Something went wrong.',
'page_not_found' => 'Oops! Page not found.',
'header' => [
'403' => '403 Forbidden',
'404' => '404 Not Found',
'500' => '500 Internal Server Error',
],

'messages' => [
'forbidden_access' => 'You can not access this page.
Meanwhile, you may <a href=":link">return to dashboard</a>.',
'error_page' => 'We will work on fixing that right away.
Meanwhile, you may <a href=":link">return to dashboard</a>.',
'page_not_found' => 'We could not find the page you were looking for.
Meanwhile, you may <a href=":link">return to dashboard</a>.',
'message' => [
'403' => 'You can not access this page.',
'404' => 'We could not find the page you were looking for.',
'500' => 'We will work on fixing that right away.',
],

];
10 changes: 5 additions & 5 deletions resources/views/errors/403.blade.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
@extends('layouts.admin')
@extends('layouts.error')

@section('title', trans('errors.forbidden_access'))
@section('title', trans('errors.title.403'))

@section('content')
<div class="card">
<div class="card-header">
<h2 class="mb-0 text-warning">403 Forbidden</h2>
<h2 class="mb-0 text-danger"><i class="fa fa-exclamation-triangle text-danger"></i>&nbsp;&nbsp;{{ trans('errors.header.403') }}</h2>
</div>
<div class="card-body">
<h3><i class="fa fa-exclamation-triangle text-danger"></i> {{ trans('errors.body.forbidden_access') }}</h3>
<p>{{ trans('errors.message.403') }}</p>

<p>{!! trans('errors.messages.forbidden_access', ['link' => url('/') ]) !!}</p>
<a href="{{ url('/') }}" class="btn btn-success header-button-top"><span class="fa fa-tachometer-alt"></span> &nbsp;{{ trans('general.go_to', ['name' => trans('general.dashboard')]) }}</a>
</div>
</div>
@endsection
10 changes: 5 additions & 5 deletions resources/views/errors/404.blade.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
@extends('layouts.admin')
@extends('layouts.error')

@section('title', trans('errors.page_not_found'))
@section('title', trans('errors.title.404'))

@section('content')
<div class="card">
<div class="card-header">
<h2 class="mb-0 text-yellow">404 Not Found</h2>
<h2 class="mb-0 text-warning"><i class="fa fa-exclamation-triangle text-warning"></i>&nbsp;&nbsp;{{ trans('errors.header.404') }}</h2>
</div>
<div class="card-body">
<h3><i class="fa fa-exclamation-triangle text-yellow"></i> {{ trans('errors.body.page_not_found') }}</h3>
<p>{{ trans('errors.message.404') }}</p>

<p>{!! trans('errors.messages.page_not_found', ['link' => url('/')]) !!}</p>
<a href="{{ url('/') }}" class="btn btn-success header-button-top"><span class="fa fa-tachometer-alt"></span> &nbsp;{{ trans('general.go_to', ['name' => trans('general.dashboard')]) }}</a>
</div>
</div>
@endsection
11 changes: 6 additions & 5 deletions resources/views/errors/500.blade.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
@extends('layouts.admin')
@extends('layouts.error')

@section('title', trans('errors.error_page'))
@section('title', trans('errors.title.500'))

@section('content')
<div class="card">
<div class="card-header">
<h2 class="mb-0 text-danger">500 Internal Server Error</h2>
<h2 class="mb-0 text-danger"><i class="fa fa-exclamation-triangle text-danger"></i>&nbsp;&nbsp;{{ trans('errors.header.500') }}</h2>
</div>
<div class="card-body">
<h3><i class="fa fa-exclamation-triangle text-danger"></i> {{ trans('errors.body.error_page') }}</h3>
<p>{{ trans('errors.message.500') }}</p>

<p>{!! trans('errors.messages.error_page', ['link' => url('/') ]) !!}</p>
<a href="{{ url('/') }}" class="btn btn-success header-button-top"><span class="fa fa-tachometer-alt"></span> &nbsp;{{ trans('general.go_to', ['name' => trans('general.dashboard')]) }}</a>
</div>
</div>
@endsection

31 changes: 31 additions & 0 deletions resources/views/layouts/error.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<html lang="{{ app()->getLocale() }}">

@include('partials.admin.head')

<body class="g-sidenav-show g-sidenav-pinned">
@stack('body_start')

<div class="main-content" id="panel">

<div id="main-body">

@include('partials.admin.header')

<div class="container-fluid content-layout mt--6">

@include('partials.admin.content')

@include('partials.admin.footer')

</div>

</div>

</div>

@stack('body_end')

@include('partials.admin.scripts')
</body>

</html>
44 changes: 22 additions & 22 deletions resources/views/partials/admin/header.blade.php
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
@stack('header_start')
<div id="header" class="header pb-6">
<div class="container-fluid content-layout">
<div class="header-body">
<div class="row py-4 align-items-center">
<div class="col-sm-4 col-md-5 align-items-center">
<h2 class="d-inline-flex mb-0 long-texts">@yield('title')</h2>
@yield('dashboard_action')
</div>
<div class="col-sm-8 col-md-7">
<div class="text-right">
@yield('new_button')
<div id="header" class="header pb-6">
<div class="container-fluid content-layout">
<div class="header-body">
<div class="row py-4 align-items-center">
<div class="col-sm-4 col-md-5 align-items-center">
<h2 class="d-inline-flex mb-0 long-texts">@yield('title')</h2>
@yield('dashboard_action')
</div>
<div class="col-sm-8 col-md-7">
<div class="text-right">
@yield('new_button')

@permission('read-modules-home')
@if (!empty($suggestion_modules))
@foreach($suggestion_modules as $s_module)
<span>
<a href="{{ url($s_module->action_url) . '?' . http_build_query((array) $s_module->action_parameters) }}" class="btn btn-white btn-sm header-button-bottom" target="{{ $s_module->action_target }}"><span class="fa fa-rocket"></span> &nbsp;{{ $s_module->name }}</a>
</span>
@endforeach
@endif
@endpermission
@permission('read-modules-home')
@if (!empty($suggestion_modules))
@foreach($suggestion_modules as $s_module)
<span>
<a href="{{ url($s_module->action_url) . '?' . http_build_query((array) $s_module->action_parameters) }}" class="btn btn-white btn-sm header-button-bottom" target="{{ $s_module->action_target }}"><span class="fa fa-rocket"></span> &nbsp;{{ $s_module->name }}</a>
</span>
@endforeach
@endif
@endpermission

@stack('header_button')
</div>
@stack('header_button')
</div>
</div>
</div>
</div>
</div>
</div>
@stack('header_end')

0 comments on commit 6f7d94e

Please sign in to comment.