Skip to content

Commit

Permalink
Merge pull request #4156 from Obi-Wana/add-torrent-immune-button-to-ui
Browse files Browse the repository at this point in the history
(Add) Allow staff to set individual history entries to immune
  • Loading branch information
HDVinnie authored Oct 10, 2024
2 parents 2707081 + 928cb77 commit b886394
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
17 changes: 17 additions & 0 deletions app/Http/Livewire/UserTorrents.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,21 @@ final public function render(): \Illuminate\Contracts\View\Factory|\Illuminate\C
'histories' => $this->history,
]);
}

/**
* Update History Immune.
*/
final public function updateImmune(int $torrentId, bool $immune): void
{
abort_unless(auth()->user()->group->is_modo, 403);

$this->user
->history()
->where('torrent_id', '=', $torrentId)
->update([
'immune' => $immune,
]);

$this->dispatch('success', type: 'success', message: 'Immunity has successfully been updated!');
}
}
37 changes: 35 additions & 2 deletions resources/views/livewire/user-torrents.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ class="user-torrents__status-header"
</thead>
<tbody>
@foreach ($histories as $history)
<tr>
<tr x-data="userHistory" data-history-id="{{ $history->torrent_id }}">
<td>
<a
class="user-torrents__name"
Expand Down Expand Up @@ -664,15 +664,25 @@ class="{{ config('other.font-awesome') }} fa-times text-red"
@endif
</td>
<td class="user-torrents__immune">
@if ($history->immune == 1)
@if ($history->immune)
<i
class="{{ config('other.font-awesome') }} fa-check text-green"
title="Immune"
@if (auth()->user()->group->is_modo)
x-on:click.prevent="updateImmune(false)"
data-b64-deletion-message="{{ base64_encode('Are you sure you want to set this history record to not immune: ' . $history->name . '?') }}"
style="cursor: pointer"
@endif
></i>
@else
<i
class="{{ config('other.font-awesome') }} fa-times text-red"
title="Not immune"
@if (auth()->user()->group->is_modo)
x-on:click.prevent="updateImmune(true)"
data-b64-deletion-message="{{ base64_encode('Are you sure you want to set this history record to immune: ' . $history->name . '?') }}"
style="cursor: pointer"
@endif
></i>
@endif
</td>
Expand Down Expand Up @@ -744,5 +754,28 @@ function ternaryCheckbox() {
},
};
}
document.addEventListener('alpine:init', () => {
Alpine.data('userHistory', () => ({
updateImmune(immune) {
this.confirmAction(() =>
this.$wire.updateImmune(this.$root.dataset.historyId, immune),
);
},
confirmAction(onConfirm) {
Swal.fire({
title: 'Are you sure?',
text: atob(this.$el.dataset.b64DeletionMessage),
icon: 'warning',
showConfirmButton: true,
showCancelButton: true,
}).then((result) => {
if (result.isConfirmed) {
onConfirm();
}
});
},
}));
});
</script>
</div>

0 comments on commit b886394

Please sign in to comment.