mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-12-25 01:05:36 +00:00
Update AdminInstanceController
This commit is contained in:
parent
f5d809c14b
commit
b30c8aade5
1 changed files with 67 additions and 1 deletions
|
@ -6,13 +6,37 @@ use DB, Cache;
|
||||||
use App\{Instance, Profile};
|
use App\{Instance, Profile};
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
|
|
||||||
trait AdminInstanceController
|
trait AdminInstanceController
|
||||||
{
|
{
|
||||||
|
|
||||||
public function instances(Request $request)
|
public function instances(Request $request)
|
||||||
{
|
{
|
||||||
$instances = Instance::orderByDesc('id')->paginate(5);
|
$this->validate($request, [
|
||||||
|
'filter' => [
|
||||||
|
'nullable',
|
||||||
|
'string',
|
||||||
|
'min:1',
|
||||||
|
'max:20',
|
||||||
|
Rule::in(['autocw', 'unlisted', 'banned'])
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
if($request->has('filter') && $request->filled('filter')) {
|
||||||
|
switch ($request->filter) {
|
||||||
|
case 'autocw':
|
||||||
|
$instances = Instance::whereAutoCw(true)->orderByDesc('id')->paginate(5);
|
||||||
|
break;
|
||||||
|
case 'unlisted':
|
||||||
|
$instances = Instance::whereUnlisted(true)->orderByDesc('id')->paginate(5);
|
||||||
|
break;
|
||||||
|
case 'banned':
|
||||||
|
$instances = Instance::whereBanned(true)->orderByDesc('id')->paginate(5);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$instances = Instance::orderByDesc('id')->paginate(5);
|
||||||
|
}
|
||||||
return view('admin.instances.home', compact('instances'));
|
return view('admin.instances.home', compact('instances'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,4 +56,46 @@ trait AdminInstanceController
|
||||||
return redirect()->back();
|
return redirect()->back();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function instanceShow(Request $request, $id)
|
||||||
|
{
|
||||||
|
$instance = Instance::findOrFail($id);
|
||||||
|
return view('admin.instances.show', compact('instance'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function instanceEdit(Request $request, $id)
|
||||||
|
{
|
||||||
|
$this->validate($request, [
|
||||||
|
'action' => [
|
||||||
|
'required',
|
||||||
|
'string',
|
||||||
|
'min:1',
|
||||||
|
'max:20',
|
||||||
|
Rule::in(['autocw', 'unlist', 'ban'])
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$instance = Instance::findOrFail($id);
|
||||||
|
$unlisted = $instance->unlisted;
|
||||||
|
$autocw = $instance->auto_cw;
|
||||||
|
$banned = $instance->banned;
|
||||||
|
|
||||||
|
switch ($request->action) {
|
||||||
|
case 'autocw':
|
||||||
|
$instance->auto_cw = $autocw == true ? false : true;
|
||||||
|
$instance->save();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'unlist':
|
||||||
|
$instance->unlisted = $unlisted == true ? false : true;
|
||||||
|
$instance->save();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'ban':
|
||||||
|
$instance->banned = $banned == true ? false : true;
|
||||||
|
$instance->save();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return response()->json([]);
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue