mirror of
https://github.com/sp-tarkov/forge.git
synced 2025-02-13 04:30:41 -05:00
update models and allow disabling modVersions
This commit is contained in:
parent
ffa00e34d0
commit
d4136bfb92
@ -2,28 +2,27 @@
|
|||||||
|
|
||||||
namespace App\Livewire\Mod;
|
namespace App\Livewire\Mod;
|
||||||
|
|
||||||
use App\Models\Mod;
|
use App\Models\ModeratedModel;
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
|
|
||||||
class ModerationOptions extends Component
|
class ModerationOptions extends Component
|
||||||
{
|
{
|
||||||
public Mod $mod;
|
public ModeratedModel $moderatedObject;
|
||||||
|
|
||||||
public function render()
|
public function render()
|
||||||
{
|
{
|
||||||
return view('livewire.mod.moderation-options');
|
return view('livewire.mod.moderation-options');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function deleteMod(): void
|
public function delete(): void
|
||||||
{
|
{
|
||||||
$this->mod->delete();
|
$this->moderatedObject->delete();
|
||||||
$this->js('window.location.reload()');
|
$this->js('window.location.reload()');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function toggleDisabled(): void
|
public function toggleDisabled(): void
|
||||||
{
|
{
|
||||||
$this->mod->disabled = ! $this->mod->disabled;
|
$this->moderatedObject->toggleDisabled();
|
||||||
$this->mod->save();
|
|
||||||
$this->js('window.location.reload()');
|
$this->js('window.location.reload()');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ use Illuminate\Support\Facades\Storage;
|
|||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use Laravel\Scout\Searchable;
|
use Laravel\Scout\Searchable;
|
||||||
|
|
||||||
class Mod extends Model
|
class Mod extends ModeratedModel
|
||||||
{
|
{
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
use Searchable;
|
use Searchable;
|
||||||
@ -257,4 +257,9 @@ class Mod extends Model
|
|||||||
set: fn (string $value) => Str::slug($value),
|
set: fn (string $value) => Str::slug($value),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getFriendlyName(): string
|
||||||
|
{
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
|
|||||||
use Illuminate\Database\Eloquent\Relations\HasOneThrough;
|
use Illuminate\Database\Eloquent\Relations\HasOneThrough;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
|
|
||||||
class ModVersion extends Model
|
class ModVersion extends ModeratedModel
|
||||||
{
|
{
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
use SoftDeletes;
|
use SoftDeletes;
|
||||||
@ -168,4 +168,9 @@ class ModVersion extends Model
|
|||||||
'published_at' => 'datetime',
|
'published_at' => 'datetime',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getFriendlyName(): string
|
||||||
|
{
|
||||||
|
return $this->version;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
16
app/Models/ModeratedModel.php
Normal file
16
app/Models/ModeratedModel.php
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
abstract class ModeratedModel extends Model
|
||||||
|
{
|
||||||
|
abstract public function getFriendlyName(): string;
|
||||||
|
|
||||||
|
public function toggleDisabled(): void
|
||||||
|
{
|
||||||
|
$this->disabled = ! $this->disabled;
|
||||||
|
$this->save();
|
||||||
|
}
|
||||||
|
}
|
@ -2,7 +2,7 @@
|
|||||||
<x-dropdown alignment="right" contentClasses="py-1 rounded-full bg-gray-200 dark:bg-gray-800">
|
<x-dropdown alignment="right" contentClasses="py-1 rounded-full bg-gray-200 dark:bg-gray-800">
|
||||||
<x-slot name="trigger">
|
<x-slot name="trigger">
|
||||||
{{-- wire:click.prevent here to stop from following mod card links --}}
|
{{-- wire:click.prevent here to stop from following mod card links --}}
|
||||||
<button class="relative text-blue-400 dark:text-blue-500 hover:text-blue-600 dark:hover:text-blue-700" wire:click.prevent="">
|
<button class="relative text-blue-400 dark:text-blue-500 hover:text-blue-600 dark:hover:text-blue-700">
|
||||||
{{-- Icon (shield with keyhole) --}}
|
{{-- Icon (shield with keyhole) --}}
|
||||||
<svg width="24" height="24" fill="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
|
<svg width="24" height="24" fill="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
|
||||||
<path d="M3 5.75V11c0 5.001 2.958 8.676 8.725 10.948a.75.75 0 0 0 .55 0C18.042 19.676 21 16 21 11V5.75a.75.75 0 0 0-.75-.75c-2.663 0-5.258-.943-7.8-2.85a.75.75 0 0 0-.9 0C9.008 4.057 6.413 5 3.75 5a.75.75 0 0 0-.75.75ZM13.995 11a2 2 0 0 1-1.245 1.852v2.398a.75.75 0 0 1-1.5 0v-2.394A2 2 0 1 1 13.995 11Z"/>
|
<path d="M3 5.75V11c0 5.001 2.958 8.676 8.725 10.948a.75.75 0 0 0 .55 0C18.042 19.676 21 16 21 11V5.75a.75.75 0 0 0-.75-.75c-2.663 0-5.258-.943-7.8-2.85a.75.75 0 0 0-.9 0C9.008 4.057 6.413 5 3.75 5a.75.75 0 0 0-.75.75ZM13.995 11a2 2 0 0 1-1.245 1.852v2.398a.75.75 0 0 1-1.5 0v-2.394A2 2 0 1 1 13.995 11Z"/>
|
||||||
@ -12,10 +12,10 @@
|
|||||||
|
|
||||||
<x-slot name="content">
|
<x-slot name="content">
|
||||||
<div>
|
<div>
|
||||||
<button wire:click.prevent="toggleDisabled" wire:confirm="{{$this->mod->disabled ? __('Enable') : __('Disable') }} the mod '{{$this->mod->name}}'?" class="p-2 h-full w-full text-blue-500 dark:text-blue-500 bg-gray-200 dark:bg-gray-800 hover:text-blue-400 dark:hover:text-blue-400">
|
<button wire:click.prevent="toggleDisabled" wire:confirm="{{$this->moderatedObject->disabled ? __('Enable') : __('Disable') }} '{{$this->moderatedObject->getFriendlyName()}}'?" class="p-2 h-full w-full text-blue-500 dark:text-blue-500 bg-gray-200 dark:bg-gray-800 hover:text-blue-400 dark:hover:text-blue-400">
|
||||||
<div class="flex">
|
<div class="flex">
|
||||||
<span class="pr-2">
|
<span class="pr-2">
|
||||||
@if ($this->mod->disabled)
|
@if ($this->moderatedObject->disabled)
|
||||||
{{-- Icon (circle with checkmark) --}}
|
{{-- Icon (circle with checkmark) --}}
|
||||||
<svg width="24" height="24" fill="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
|
<svg width="24" height="24" fill="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
|
||||||
<path d="M12 2c5.523 0 10 4.477 10 10s-4.477 10-10 10S2 17.523 2 12 6.477 2 12 2Zm3.22 6.97-4.47 4.47-1.97-1.97a.75.75 0 0 0-1.06 1.06l2.5 2.5a.75.75 0 0 0 1.06 0l5-5a.75.75 0 1 0-1.06-1.06Z" />
|
<path d="M12 2c5.523 0 10 4.477 10 10s-4.477 10-10 10S2 17.523 2 12 6.477 2 12 2Zm3.22 6.97-4.47 4.47-1.97-1.97a.75.75 0 0 0-1.06 1.06l2.5 2.5a.75.75 0 0 0 1.06 0l5-5a.75.75 0 1 0-1.06-1.06Z" />
|
||||||
@ -27,13 +27,13 @@
|
|||||||
</svg>
|
</svg>
|
||||||
@endif
|
@endif
|
||||||
</span>
|
</span>
|
||||||
{{$this->mod->disabled ? __('Enable') : __('Disable') }}
|
{{$this->moderatedObject->disabled ? __('Enable') : __('Disable') }}
|
||||||
</div>
|
</div>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
@if(auth()->user()->isAdmin())
|
@if(auth()->user()->isAdmin())
|
||||||
<div>
|
<div>
|
||||||
<button wire:click.prevent="deleteMod" wire:confirm="Delete the mod '{{$this->mod->name}}'?" class="p-2 h-full w-full text-red-500 dark:text-red-500 bg-gray-200 dark:bg-gray-800 hover:text-red-400 dark:hover:text-red-400">
|
<button wire:click.prevent="delete" wire:confirm="Delete '{{$this->moderatedObject->getFriendlyName()}}'?" class="p-2 h-full w-full text-red-500 dark:text-red-500 bg-gray-200 dark:bg-gray-800 hover:text-red-400 dark:hover:text-red-400">
|
||||||
<div class="flex">
|
<div class="flex">
|
||||||
<span class="pr-2">
|
<span class="pr-2">
|
||||||
{{-- Icon (trash can) --}}
|
{{-- Icon (trash can) --}}
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
<div class="relative p-4 sm:p-6 text-center sm:text-left bg-white dark:bg-gray-950 rounded-xl shadow-md dark:shadow-gray-950 drop-shadow-2xl">
|
<div class="relative p-4 sm:p-6 text-center sm:text-left bg-white dark:bg-gray-950 rounded-xl shadow-md dark:shadow-gray-950 drop-shadow-2xl">
|
||||||
@if (auth()->check() && auth()->user()->isModOrAdmin())
|
@if (auth()->check() && auth()->user()->isModOrAdmin())
|
||||||
<div class="absolute top-0 right-0 z-50 m-2">
|
<div class="absolute top-0 right-0 z-50 m-2">
|
||||||
<livewire:mod.moderation-options :mod="$mod" />
|
<livewire:mod.moderation-options :moderatedObject="$mod" lazy />
|
||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
@if ($mod->featured && !$mod->disabled)
|
@if ($mod->featured && !$mod->disabled)
|
||||||
@ -106,7 +106,15 @@
|
|||||||
<div x-show="selectedTab === 'versions'">
|
<div x-show="selectedTab === 'versions'">
|
||||||
@foreach ($mod->versions as $version)
|
@foreach ($mod->versions as $version)
|
||||||
<div class="p-4 mb-4 sm:p-6 bg-white dark:bg-gray-950 rounded-xl shadow-md dark:shadow-gray-950 drop-shadow-2xl">
|
<div class="p-4 mb-4 sm:p-6 bg-white dark:bg-gray-950 rounded-xl shadow-md dark:shadow-gray-950 drop-shadow-2xl">
|
||||||
|
@if($version->disabled)
|
||||||
|
<div class="ribbon-red z-10">{{ __('Disabled') }}</div>
|
||||||
|
@endif
|
||||||
<div class="pb-6 border-b-2 border-gray-200 dark:border-gray-800">
|
<div class="pb-6 border-b-2 border-gray-200 dark:border-gray-800">
|
||||||
|
@if (auth()->check() && auth()->user()->isModOrAdmin())
|
||||||
|
<div class="absolute top-0 right-0 z-50 m-2">
|
||||||
|
<livewire:mod.moderation-options :moderatedObject="$version" lazy />
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
<div class="flex items-center justify-between">
|
<div class="flex items-center justify-between">
|
||||||
<a class="text-2xl font-extrabold" href="{{ $version->downloadUrl() }}">
|
<a class="text-2xl font-extrabold" href="{{ $version->downloadUrl() }}">
|
||||||
{{ __('Version') }} {{ $version->version }}
|
{{ __('Version') }} {{ $version->version }}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user