Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion app/Http/Controllers/App/BookmarkletController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@ public function getLinkAddForm(Request $request)

session(['bookmarklet.create' => true]);

$existingLink = Link::withTrashed()->whereUrl($newUrl)->first();

return view('app.bookmarklet.create', [
'existing_link' => Link::withTrashed()->whereUrl($newUrl)->first() ?: false,
'existing_link' => $existingLink ?: false,
'existing_deleted' => $existingLink?->trashed() ?? false,
'bookmark_url' => $newUrl,
'bookmark_title' => $newTitle,
'bookmark_description' => $newDescription,
Expand Down
13 changes: 12 additions & 1 deletion app/Http/Controllers/App/TrashController.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,20 @@ public function clearTrash(TrashClearRequest $request): RedirectResponse

public function restoreEntry(TrashRestoreRequest $request): RedirectResponse
{
TrashRepository::restore($request->input('model'), $request->input('id'));
$model = TrashRepository::restore($request->input('model'), $request->input('id'));

flash(trans('trash.restore.' . $request->input('model')), 'success');

if ($request->boolean('redirect_to_model')) {
return match ($request->input('model')) {
'link' => redirect()->route('links.show', ['link' => $model]),
'list' => redirect()->route('lists.show', ['list' => $model]),
'tag' => redirect()->route('tags.show', ['tag' => $model]),
'note' => redirect()->route('links.show', ['note' => $model->link()->first()]),
default => redirect()->route('get-trash'),
};
}

return redirect()->route('get-trash');
}
}
5 changes: 4 additions & 1 deletion app/Http/Controllers/FetchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,17 @@ public function searchExistingUrls(Request $request): JsonResponse
}

$link = Link::query()
->withTrashed()
->visibleForUser()
->where('url', trim($query))
->where('id', '!=', $request->input('ignore_id', 0))
->first();

return response()->json([
'linkFound' => $link !== null,
'linkFound' => $link,
'linkDeleted' => $link?->trashed(),
'editLink' => $link ? route('links.edit', ['link' => $link]) : null,
'restoreLink' => route('trash-restore'),
]);
}

Expand Down
2 changes: 2 additions & 0 deletions app/Http/Controllers/Models/LinkController.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public function create(): View
return view('models.links.create', [
'pageTitle' => trans('link.add'),
'existing_link' => null,
'existing_deleted' => false,
'all_tags' => Tag::visibleForUser()->with('user:id,name')->get(['name', 'id', 'user_id']),
'all_lists' => LinkList::visibleForUser()->with('user:id,name')->get(['name', 'id', 'user_id']),
]);
Expand Down Expand Up @@ -130,6 +131,7 @@ public function edit(Link $link): View
'pageTitle' => trans('link.edit') . ': ' . $link->shortTitle(),
'link' => $link,
'existing_link' => null,
'existing_deleted' => null,
'all_tags' => Tag::visibleForUser()->with('user:id,name')->get(['name', 'id', 'user_id']),
'all_lists' => LinkList::visibleForUser()->with('user:id,name')->get(['name', 'id', 'user_id']),
]);
Expand Down
4 changes: 4 additions & 0 deletions app/Http/Requests/TrashRestoreRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ public function rules(): array
'required',
'numeric',
],
'redirect_to_model' => [
'nullable',
'boolean'
]
];
}
}
9 changes: 4 additions & 5 deletions app/Repositories/LinkRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use App\Models\LinkList;
use App\Models\Tag;
use Exception;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Log;
Expand Down Expand Up @@ -223,9 +222,9 @@ protected static function processTaxonomy(string $model, array $entries): Collec
{
$newEntries = collect();

$privateSetting = match ($model) {
Tag::class => usersettings('tags_private_default') === '1',
LinkList::class => usersettings('lists_private_default') === '1',
$visibilitySetting = match ($model) {
Tag::class => usersettings('tags_default_visibility'),
LinkList::class => usersettings('lists_default_visibility'),
};

foreach ($entries as $entry) {
Expand All @@ -238,7 +237,7 @@ protected static function processTaxonomy(string $model, array $entries): Collec
], [
'user_id' => auth()->id(),
'name' => trim($entry),
'is_private' => $privateSetting,
'visibility' => $visibilitySetting,
]);
}

Expand Down
7 changes: 4 additions & 3 deletions app/Repositories/TrashRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Models\LinkList;
use App\Models\Note;
use App\Models\Tag;
use Illuminate\Database\Eloquent\Model;

class TrashRepository
{
Expand Down Expand Up @@ -47,9 +48,9 @@ public static function delete(string $model): bool
*
* @param string $model
* @param int $id
* @return bool
* @return Link|Tag|LinkList|Note|null
*/
public static function restore(string $model, int $id): bool
public static function restore(string $model, int $id): Link|Tag|LinkList|Note|null
{
$entry = match ($model) {
'link' => Link::withTrashed()->byUser()->findOrFail($id),
Expand All @@ -61,6 +62,6 @@ public static function restore(string $model, int $id): bool

$entry?->restore();

return true;
return $entry;
}
}
Loading
Loading