Skip to content

Commit

Permalink
Fix #31: Create tab menu for the notifications.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Joosten authored and Tim Joosten committed Jun 22, 2017
1 parent e797dc9 commit a689b2d
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 37 deletions.
2 changes: 1 addition & 1 deletion app/Http/Controllers/NotificationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct()
*/
public function index()
{
return view('notifications.index');
return view('notifications.index', compact('notifications'));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/RoleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function destroy($roleId)
{
try {
$role = Role::findOrFail($roleId);
$role->syncPermissions([]);
$role->syncPermissions([]); // Empty relation for clearing the permissions relation.
$role->delete();

flash('We have deleted the permission group');
Expand Down
110 changes: 75 additions & 35 deletions resources/views/notifications/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
<div class="row">
<div class="col-md-3"> {{-- Sidebar --}}
<div class="list-group">
<a href="" class="list-group-item">
<a href="#unread" aria-controls="unread" role="tab" data-toggle="tab" class="list-group-item">
Unread notifications <span class="badge">{{ auth()->user()->unreadNotifications->count() }}</span>
</a>
<a href="" class="list-group-item">
<a href="#all" aria-controls="all" role="tab" data-toggle="tab" class="list-group-item">
All notifications.
</a>
</div>
Expand All @@ -22,39 +22,79 @@
</div> {{-- Sidebar --}}

<div class="col-md-9"> {{-- Content --}}
@if (auth()->user()->unreadNotifications->count() > 0)
<div class="panel panel-default">
<div class="panel-heading"> Notifications </div>

<ul class="list-group">
@foreach (auth()->user()->unreadNotifications as $unread)
<li class="list-group-item" href="test">
<span style="vertical-align: middle; padding-right: 5px; color: #28a745;" class="fa fa-bell"></span>
<span style="vertical-align: middle;">
<a href="{{ $unread->data['url'] }}" class="text-muted">
{{ $unread->data['message'] }}
{{ $unread->markAsRead() }}
</a>
</span>

<div class="pull-right">
<span style="padding-left: 10px; vertical-align: middle;">{{ $unread->created_at->diffForHumans() }}</span>

<a style="vertical-align: middle; padding-left: 15px;" href="{{ route('notifications.mark', $unread) }}">
<span class="text-muted fa fa-check"></span>
</a>
</div>
</li>
@endforeach
</ul>
</div>
@else
<div class="blankslate">
<span class="mega-octicon octicon-bell blankslate-icon"></span>
<h3>No notifications</h3>
<p>You've read all your notifications. Good job!</p>
</div>
@endif
<div class="tab-content">
<div role="tabpanel" class="tab-pane fade in active" id="unread"> {{-- Unread notifications tab --}}
@if (auth()->user()->unreadNotifications->count() > 0)
<div class="panel panel-default">
<div class="panel-heading">Unread notifications </div>

<ul class="list-group">
@foreach (auth()->user()->unreadNotifications as $unread)
<li class="list-group-item" href="test">
<span style="vertical-align: middle; padding-right: 5px; color: #28a745;" class="fa fa-bell"></span>
<span style="vertical-align: middle;">
<a href="{{ $unread->data['url'] }}" class="text-muted">
{{ $unread->data['message'] }}
{{ $unread->markAsRead() }}
</a>
</span>

<div class="pull-right">
<span style="padding-left: 10px; vertical-align: middle;">{{ $unread->created_at->diffForHumans() }}</span>

<a style="vertical-align: middle; padding-left: 15px;" href="{{ route('notifications.mark', $unread) }}">
<span class="text-muted fa fa-check"></span>
</a>
</div>
</li>
@endforeach
</ul>
</div>
@else
<div class="blankslate">
<span class="mega-octicon octicon-bell blankslate-icon"></span>
<h3>No notifications</h3>
<p>You've read all your notifications. Good job!</p>
</div>
@endif
</div> {{-- End unread notifications tab --}}

<div role="tabpanel" class="tab-pane fade in" id="all"> {{-- All notifications tab --}}
@if (auth()->user()->notifications->count() > 0) {{-- There are notifications found. --}}
@php $notifications = auth()->user()->notifications()->simplePaginate(25); @endphp

<div class="panel panel-default">
<div class="panel-heading">All notifications </div>

<ul class="list-group">
@foreach ($notifications as $all)
<li class="list-group-item" href="test">
<span style="vertical-align: middle; padding-right: 5px; color: #28a745;" class="fa fa-bell"></span>
<span style="vertical-align: middle;">
<a href="{{ $all->data['url'] }}" class="text-muted">
{{ $all->data['message'] }}
{{ $all->markAsRead() }}
</a>
</span>

<div class="pull-right">
<span style="padding-left: 10px; vertical-align: middle;">{{ $all->created_at->diffForHumans() }}</span>
</div>
</li>
@endforeach
</ul>
</div>

{!! $notifications->render() !!} {{-- Simple pagination instance --}}
@else {{-- Thuere are no notifications. --}}
<div class="blankslate">
<span class="mega-octicon octicon-bell blankslate-icon"></span>
<h3>Notifications</h3>
<p>You have no notifications in the system.</p>
</div>
@endif
</div> {{-- /Notifications tab. --}}
</div>
</div> {{-- /Content --}}
</div>
@endsection

0 comments on commit a689b2d

Please sign in to comment.