Skip to content

Commit dfccf93

Browse files
committed
Add notes to trash handling, fix some issues (#11)
1 parent 26391ca commit dfccf93

File tree

7 files changed

+82
-7
lines changed

7 files changed

+82
-7
lines changed

app/Http/Controllers/App/TrashController.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use App\Http\Controllers\Controller;
66
use App\Models\Category;
77
use App\Models\Link;
8+
use App\Models\Note;
89
use App\Models\Tag;
910
use Illuminate\Http\Request;
1011

@@ -29,10 +30,15 @@ public function index()
2930
->byUser(auth()->id())
3031
->get();
3132

33+
$notes = Note::onlyTrashed()
34+
->byUser(auth()->id())
35+
->get();
36+
3237
return view('actions.trash.index', [
3338
'links' => $links,
3439
'categories' => $categories,
3540
'tags' => $tags,
41+
'notes' => $notes,
3642
]);
3743
}
3844

@@ -63,6 +69,11 @@ public function clearTrash(Request $reques, $model)
6369
->byUser(auth()->id())
6470
->get();
6571
break;
72+
case 'notes':
73+
$entries = Note::onlyTrashed()
74+
->byUser(auth()->id())
75+
->get();
76+
break;
6677
}
6778

6879
if (empty($entries)) {
@@ -72,6 +83,7 @@ public function clearTrash(Request $reques, $model)
7283

7384
foreach ($entries as $entry) {
7485
$entry->forceDelete();
86+
$entry->flushCache();
7587
}
7688

7789
alert(trans('trash.delete_success.' . $model), 'success');
@@ -101,6 +113,9 @@ public function restoreEntry(Request $request, $model, $id)
101113
case 'tag':
102114
$entry = Tag::withTrashed()->find($id);
103115
break;
116+
case 'note':
117+
$entry = Note::withTrashed()->find($id);
118+
break;
104119
}
105120

106121
if (empty($entry)) {
@@ -112,8 +127,9 @@ public function restoreEntry(Request $request, $model, $id)
112127
}
113128

114129
$entry->restore();
130+
$entry->flushCache();
115131

116-
alert(trans('trash.delete_success.' . $model), 'success');
132+
alert(trans('trash.delete_restore.' . $model), 'success');
117133

118134
return redirect()->route('get-trash');
119135
}

resources/lang/en/trash.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
'deleted_links' => 'Trashed links',
88
'deleted_categories' => 'Trashed categories',
99
'deleted_tags' => 'Trashed tags',
10+
'deleted_notes' => 'Trashed notes',
1011

1112
'restore' => 'Restore entry',
1213

@@ -17,9 +18,11 @@
1718
'delete_success.links' => 'Permanently deleted all links.',
1819
'delete_success.categories' => 'Permanently deleted all categories.',
1920
'delete_success.tags' => 'Permanently deleted all tags.',
21+
'delete_success.notes' => 'Permanently deleted all notes.',
2022

21-
'delete_restore.links' => 'Restored the link from trash.',
22-
'delete_restore.categories' => 'Restored the category from trash.',
23-
'delete_restore.tags' => 'Restored the tag from trash.',
23+
'delete_restore.link' => 'Restored the link from trash.',
24+
'delete_restore.category' => 'Restored the category from trash.',
25+
'delete_restore.tag' => 'Restored the tag from trash.',
26+
'delete_restore.note' => 'Restored the note from trash.',
2427

2528
];

resources/views/actions/trash/index.blade.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,23 @@ class="btn btn-sm btn-danger" title="@lang('trash.clear_trash')">
6565
</div>
6666
</div>
6767

68+
<div class="card mt-4">
69+
<div class="card-header d-flex align-items-center">
70+
<div>
71+
@lang('trash.deleted_notes')
72+
</div>
73+
<div class="ml-auto">
74+
<a href="{{ route('clear-trash', ['notes']) }}"
75+
class="btn btn-sm btn-danger" title="@lang('trash.clear_trash')">
76+
<i class="fa fa-recycle"></i> @lang('trash.clear_trash')
77+
</a>
78+
</div>
79+
</div>
80+
<div class="card-body">
81+
82+
@include('actions.trash.partials.note-table', ['notes' => $notes])
83+
84+
</div>
85+
</div>
86+
6887
@endsection

resources/views/actions/trash/partials/category-table.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div class="table-responsive">
2-
<table class="table table-bordered table-hover mb-0">
2+
<table class="table table-sm table-bordered table-hover mb-0">
33
<thead>
44
<tr>
55
<th>@lang('category.name')</th>

resources/views/actions/trash/partials/link-table.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div class="table-responsive">
2-
<table class="table table-bordered table-hover mb-0">
2+
<table class="table table-sm table-bordered table-hover mb-0">
33
<thead>
44
<tr>
55
<th>@lang('link.url')</th>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<div class="table-responsive">
2+
<table class="table table-sm table-bordered table-hover mb-0">
3+
<thead>
4+
<tr>
5+
<th>@lang('link.link')</th>
6+
<th>@lang('note.note_content')</th>
7+
<th>@lang('linkace.added_at')</th>
8+
<th></th>
9+
</tr>
10+
</thead>
11+
<tbody>
12+
13+
@foreach($notes as $note)
14+
<tr>
15+
<td>
16+
<a href="{{ $note->link->url }}" title="{{ $note->link->title }}" target="_blank">
17+
{{ $note->link->title }}
18+
</a>
19+
</td>
20+
<td>
21+
{{ $note->note }}
22+
</td>
23+
<td>
24+
{{ formatDateTime($note->created_at) }}
25+
</td>
26+
<td class="text-right">
27+
<a href="{{ route('trash-restore', ['note', $note->id]) }}"
28+
class="btn btn-sm btn-outline-primary" title="@lang('trash.restore')">
29+
<i class="fa fa-reply"></i>
30+
</a>
31+
</td>
32+
</tr>
33+
@endforeach
34+
35+
</tbody>
36+
</table>
37+
</div>

resources/views/actions/trash/partials/tag-table.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div class="table-responsive">
2-
<table class="table table-bordered table-hover mb-0">
2+
<table class="table table-sm table-bordered table-hover mb-0">
33
<thead>
44
<tr>
55
<th>@lang('tag.name')</th>

0 commit comments

Comments
 (0)