update vm ticket
This commit is contained in:
@@ -102,6 +102,75 @@ class PostCategoryController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
public function trashed(Request $request): JsonResponse
|
||||
{
|
||||
$perPage = min((int) $request->get('per_page', 15), 100);
|
||||
|
||||
$paginator = PostCategory::onlyTrashed()
|
||||
->withCount('posts')
|
||||
->when(
|
||||
$request->filled('keyword'),
|
||||
fn ($q) => $q->where('name', 'like', '%' . $request->string('keyword')->toString() . '%')
|
||||
)
|
||||
->orderByDesc('deleted_at')
|
||||
->paginate($perPage);
|
||||
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'data' => [
|
||||
'items' => PostCategoryResource::collection($paginator->items()),
|
||||
'total' => $paginator->total(),
|
||||
'per_page' => $paginator->perPage(),
|
||||
'current_page' => $paginator->currentPage(),
|
||||
'last_page' => $paginator->lastPage(),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function restore(int $id): JsonResponse
|
||||
{
|
||||
$category = PostCategory::onlyTrashed()->find($id);
|
||||
|
||||
if (!$category) {
|
||||
return response()->json(['error' => true, 'message' => 'Không tìm thấy danh mục.'], 404);
|
||||
}
|
||||
|
||||
$category->restore();
|
||||
$this->revalidation->revalidateDocs();
|
||||
|
||||
return response()->json(['error' => false, 'message' => 'Khôi phục danh mục thành công.']);
|
||||
}
|
||||
|
||||
public function forceDelete(int $id): JsonResponse
|
||||
{
|
||||
$category = PostCategory::onlyTrashed()->find($id);
|
||||
|
||||
if (!$category) {
|
||||
return response()->json(['error' => true, 'message' => 'Không tìm thấy danh mục.'], 404);
|
||||
}
|
||||
|
||||
$category->forceDelete();
|
||||
|
||||
return response()->json(['error' => false, 'message' => 'Xoá vĩnh viễn danh mục thành công.']);
|
||||
}
|
||||
|
||||
public function bulkRestore(Request $request): JsonResponse
|
||||
{
|
||||
$request->validate(['ids' => 'required|array|min:1', 'ids.*' => 'integer']);
|
||||
$count = PostCategory::onlyTrashed()->whereIn('id', $request->ids)->restore();
|
||||
$this->revalidation->revalidateDocs();
|
||||
|
||||
return response()->json(['error' => false, 'message' => "Đã khôi phục {$count} danh mục."]);
|
||||
}
|
||||
|
||||
public function bulkForceDelete(Request $request): JsonResponse
|
||||
{
|
||||
$request->validate(['ids' => 'required|array|min:1', 'ids.*' => 'integer']);
|
||||
$count = PostCategory::onlyTrashed()->whereIn('id', $request->ids)->forceDelete();
|
||||
|
||||
return response()->json(['error' => false, 'message' => "Đã xoá vĩnh viễn {$count} danh mục."]);
|
||||
}
|
||||
|
||||
public function destroy(int $id): JsonResponse
|
||||
{
|
||||
$category = PostCategory::withCount('posts')->find($id);
|
||||
|
||||
@@ -136,6 +136,97 @@ class PostController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
public function trashed(Request $request): JsonResponse
|
||||
{
|
||||
$perPage = min((int) $request->get('per_page', 15), 100);
|
||||
|
||||
$paginator = Post::onlyTrashed()
|
||||
->with('category')
|
||||
->when(
|
||||
$request->filled('keyword'),
|
||||
fn ($q) => $q->where('title', 'like', '%' . $request->string('keyword')->toString() . '%')
|
||||
)
|
||||
->orderByDesc('deleted_at')
|
||||
->paginate($perPage);
|
||||
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'data' => [
|
||||
'items' => PostResource::collection($paginator->items()),
|
||||
'total' => $paginator->total(),
|
||||
'per_page' => $paginator->perPage(),
|
||||
'current_page' => $paginator->currentPage(),
|
||||
'last_page' => $paginator->lastPage(),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function restore(int $id): JsonResponse
|
||||
{
|
||||
$post = Post::onlyTrashed()->find($id);
|
||||
|
||||
if (!$post) {
|
||||
return response()->json(['error' => true, 'message' => 'Không tìm thấy bài viết.'], 404);
|
||||
}
|
||||
|
||||
$post->restore();
|
||||
$this->revalidation->revalidateDocs();
|
||||
|
||||
return response()->json(['error' => false, 'message' => 'Khôi phục bài viết thành công.']);
|
||||
}
|
||||
|
||||
public function forceDelete(int $id): JsonResponse
|
||||
{
|
||||
$post = Post::onlyTrashed()->find($id);
|
||||
|
||||
if (!$post) {
|
||||
return response()->json(['error' => true, 'message' => 'Không tìm thấy bài viết.'], 404);
|
||||
}
|
||||
|
||||
$post->forceDelete();
|
||||
|
||||
return response()->json(['error' => false, 'message' => 'Xoá vĩnh viễn bài viết thành công.']);
|
||||
}
|
||||
|
||||
public function bulkRestore(Request $request): JsonResponse
|
||||
{
|
||||
$request->validate(['ids' => 'required|array|min:1', 'ids.*' => 'integer']);
|
||||
$count = Post::onlyTrashed()->whereIn('id', $request->ids)->restore();
|
||||
$this->revalidation->revalidateDocs();
|
||||
|
||||
return response()->json(['error' => false, 'message' => "Đã khôi phục {$count} bài viết."]);
|
||||
}
|
||||
|
||||
public function bulkForceDelete(Request $request): JsonResponse
|
||||
{
|
||||
$request->validate(['ids' => 'required|array|min:1', 'ids.*' => 'integer']);
|
||||
$count = Post::onlyTrashed()->whereIn('id', $request->ids)->forceDelete();
|
||||
|
||||
return response()->json(['error' => false, 'message' => "Đã xoá vĩnh viễn {$count} bài viết."]);
|
||||
}
|
||||
|
||||
public function bulkDelete(Request $request): JsonResponse
|
||||
{
|
||||
$request->validate(['ids' => 'required|array|min:1', 'ids.*' => 'integer']);
|
||||
$count = Post::whereIn('id', $request->ids)->delete();
|
||||
$this->revalidation->revalidateDocs();
|
||||
|
||||
return response()->json(['error' => false, 'message' => "Đã xoá {$count} bài viết."]);
|
||||
}
|
||||
|
||||
public function bulkUpdateStatus(Request $request): JsonResponse
|
||||
{
|
||||
$request->validate([
|
||||
'ids' => 'required|array|min:1',
|
||||
'ids.*' => 'integer',
|
||||
'status' => 'required|in:draft,published,hidden',
|
||||
]);
|
||||
$count = Post::whereIn('id', $request->ids)->update(['status' => $request->status]);
|
||||
$this->revalidation->revalidateDocs();
|
||||
|
||||
return response()->json(['error' => false, 'message' => "Đã cập nhật trạng thái {$count} bài viết."]);
|
||||
}
|
||||
|
||||
public function syncWordpress(Request $request): JsonResponse
|
||||
{
|
||||
$validated = $request->validate([
|
||||
|
||||
@@ -110,7 +110,7 @@ class TicketController extends Controller
|
||||
public function reply(Request $request, string $ticket_num)
|
||||
{
|
||||
$request->validate([
|
||||
'message' => ['required', 'string', 'max:2000'],
|
||||
'message' => ['required', 'string'],
|
||||
]);
|
||||
|
||||
$admin = auth('admin')->user();
|
||||
|
||||
@@ -93,6 +93,7 @@ class VCenterController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public function storeNode(Request $request, string $type): JsonResponse
|
||||
{
|
||||
$rules = match ($type) {
|
||||
@@ -187,9 +188,9 @@ class VCenterController extends Controller
|
||||
$allHosts = ModuleHost::with(['datastore', 'network'])->get()->groupBy('module_datacenter_id');
|
||||
$allFolders = ModuleFolder::all()->groupBy('module_datacenter_id');
|
||||
// VMs with a host assignment — grouped by host DB id
|
||||
$allVMs = VirtualMachines::whereNotNull('host_id')->get()->groupBy('host_id');
|
||||
$allVMs = VirtualMachines::with('vmware')->whereNotNull('host_id')->get()->groupBy('host_id');
|
||||
// VMs without a host assignment (synced before host_id was tracked) — grouped by datacenter DB id
|
||||
$orphanVMs = VirtualMachines::whereNull('host_id')->get()->groupBy('datacenter_id');
|
||||
$orphanVMs = VirtualMachines::with('vmware')->whereNull('host_id')->get()->groupBy('datacenter_id');
|
||||
|
||||
$tree = $vcenters->map(function ($vc) use ($allHosts, $allFolders, $allVMs, $orphanVMs) {
|
||||
$dcGroups = ($vc->datacenters ?? collect())->groupBy('datacenter_id');
|
||||
@@ -227,8 +228,8 @@ class VCenterController extends Controller
|
||||
'uuid' => $vm->uuid,
|
||||
'vm_id' => $vm->vm_id,
|
||||
'ip' => $vm->ip,
|
||||
'username' => $vm->username,
|
||||
'password' => $vm->password,
|
||||
'username' => $vm->vmware?->user,
|
||||
'password' => $vm->vmware?->plain_password,
|
||||
'power_state' => $vm->power_state,
|
||||
'folder' => $vm->folder,
|
||||
'cpu' => $vm->cpu,
|
||||
@@ -304,6 +305,8 @@ class VCenterController extends Controller
|
||||
'uuid' => $vm->uuid,
|
||||
'vm_id' => $vm->vm_id,
|
||||
'ip' => $vm->ip,
|
||||
'username' => $vm->vmware?->user,
|
||||
'password' => $vm->vmware?->plain_password,
|
||||
'power_state' => $vm->power_state,
|
||||
'folder' => $vm->folder,
|
||||
'cpu' => $vm->cpu,
|
||||
|
||||
Reference in New Issue
Block a user