Update source into github

This commit is contained in:
pbao9
2025-07-24 16:18:27 +07:00
parent 41419358dd
commit 69851ac7bc
2642 changed files with 284095 additions and 0 deletions
@@ -0,0 +1,118 @@
<?php
namespace App\Http\Controllers\admin\package;
use App\Http\Controllers\Controller;
use App\Http\Requests\Package\DatacenterRequest;
use App\Jobs\VirtualMachine\Sync\SyncDatacenter;
use App\Repositories\Module\Datacenter\DatacenterRepositoryInterface;
use App\Repositories\vCenter\vCenterRepositoryInterface;
use Exception;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class Datacenter extends Controller
{
public function __construct(
public DatacenterRepositoryInterface $datacenterRepository,
public vCenterRepositoryInterface $vCenterRepository
) {
parent::__construct();
}
public function index(Request $request)
{
$datacenter = $this->datacenterRepository->filter(
[
'page' => $request->get('page') ?? 1
],
['vCenter']
);
$title = 'List all datacenter';
return view('admin.package.datacenter.index', compact('datacenter', 'title'));
}
public function create()
{
$title = 'Add datacenter';
return view('admin.package.datacenter.add', compact('title'));
}
public function store(DatacenterRequest $request)
{
$request->validated();
$vcenter = $this->vCenterRepository->find($request->get('vcenter_id'));
if (! $vcenter) {
return back()->withErrors('Invalid request.');
}
$isCreated = $this->datacenterRepository->findBy('datacenter_id', $request->get('datacenter_id'));
if ($isCreated) {
return back()->withErrors('The Datacenter ID already exists.');
}
DB::beginTransaction();
try {
$this->datacenterRepository->create($request->all());
DB::commit();
} catch (Exception $error) {
DB::rollBack();
return back()->withErrors($error->getMessage());
}
return redirect()->route('package.datacenter.index')->with('success', 'Add new datacenter successfully!');
}
public function edit(int $id = 0)
{
$datacenter = $this->datacenterRepository->find($id);
if (! $datacenter) {
return back()->withErrors('Invalid request.');
}
$title = 'Edit Datacenter';
return view('admin.package.datacenter.edit', compact('title', 'datacenter'));
}
public function update(int $id = 0, DatacenterRequest $request)
{
$datacenter = $this->datacenterRepository->find($id);
if (! $datacenter) {
return back()->withErrors('Invalid request.');
}
$request->validated();
if ($request->get('datacenter_id') !== $datacenter->datacenter_id) {
$isCreated = $this->datacenterRepository->findBy('datacenter_id', $request->get('datacenter_id'));
if ($isCreated) {
return back()->withErrors('The Datacenter ID already exists.');
}
}
DB::beginTransaction();
try {
$this->datacenterRepository->update($id, $request->all());
DB::commit();
} catch (Exception $error) {
DB::rollBack();
return back()->withErrors($error->getMessage());
}
return redirect()->route('package.datacenter.index')->with('success', 'Update datacenter successfully!');
}
public function destroy(int $id = 0)
{
$datacenter = $this->datacenterRepository->find($id);
if (! $datacenter) {
return back()->withErrors('Invalid request.');
}
DB::beginTransaction();
try {
$this->datacenterRepository->delete($id);
DB::commit();
} catch (Exception $error) {
DB::rollBack();
return back()->withErrors($error->getMessage());
}
return redirect()->route('package.datacenter.index')->with('success', 'Deleted datacenter successfully!');
}
public function sync(SyncDatacenter $syncDatacenter)
{
dispatch($syncDatacenter)->delay(now()->addSeconds(5));
return back()->with('success', 'The process is being established, please wait');
}
}
@@ -0,0 +1,127 @@
<?php
namespace App\Http\Controllers\admin\package;
use App\Http\Controllers\Controller;
use App\Http\Requests\Package\DatastoreRequest;
use App\Jobs\VirtualMachine\Sync\SyncDatastore;
use App\Models\ModuleDatastore;
use App\Repositories\Module\Datastore\DatastoreRepositoryInterface;
use App\Repositories\Module\Host\HostRepositoryInterface;
use Exception;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class Datastore extends Controller
{
public function __construct(
public DatastoreRepositoryInterface $datastoreRepository,
public HostRepositoryInterface $hostRepository
) {}
//
public function index(Request $request)
{
$datastore = $this->datastoreRepository->filter(
[
'page' => $request->get('page') ?? 1
],
[
'host.datacenter.vCenter'
]
);
$title = 'List all datastore';
return view('admin.package.datastore.index', compact('title', 'datastore'));
}
public function sync(SyncDatastore $syncDatastore)
{
dispatch($syncDatastore)->delay(now()->addSeconds(5));
return back()->with('success', 'The process is being established, please wait');
}
public function create()
{
$title = 'Add Datastore';
return view('admin.package.datastore.add', compact('title'));
}
public function store(DatastoreRequest $request)
{
$request->validated();
$host = $this->hostRepository->find($request->get('module_host_id'));
if (! $host) {
return back()->withErrors('Invalid Request');
}
$isCreated = $this->datastoreRepository->findBy('datastore', $request->get('datastore'));
if ($isCreated) {
return back()->withErrors('The Datastore ID already exists');
}
DB::beginTransaction();
try {
$this->datastoreRepository->create($request->all());
DB::commit();
} catch (Exception $error) {
DB::rollBack();
return back()->withErrors($error->getMessage());
}
return redirect()->route('package.datastore.index')->with('success', 'Add new datastore successfully');
}
public function edit(int $id = 0)
{
$datastore = $this->datastoreRepository->findWithRelationships($id, ['host.datacenter']);
if (! $datastore) {
return back()->withErrors('Invalid Request');
}
$title = 'Edit Datastore';
return view('admin.package.datastore.edit', compact('title', 'datastore'));
}
public function update(int $id, DatastoreRequest $request)
{
$datastore = $this->datastoreRepository->find($id);
if (! $datastore) {
return redirect()->route('package.datastore.index')->withErrors('Invalid request.');
}
$request->validated();
$host = $this->hostRepository->find($request->get('module_host_id'));
if (! $host) {
return back()->withErrors('Invalid Request');
}
if ($request->get('datastore') !== $datastore->datastore) {
$isCreated = $this->datastoreRepository->findBy('datastore', $request->get('datastore'));
if ($isCreated) {
return back()->withErrors('The Datastore ID already exists');
}
}
DB::beginTransaction();
try {
$this->datastoreRepository->update($id, $request->all());
DB::commit();
} catch (Exception $error) {
DB::rollBack();
return back()->withErrors($error->getMessage());
}
return redirect()->route('package.datastore.index')->with('success', 'Updated successfully');
}
public function destroy(int $id = 0)
{
$datastore = $this->datastoreRepository->find($id);
if (! $datastore) {
return back()->withErrors('Invalid request.');
}
DB::beginTransaction();
try {
$this->datastoreRepository->delete($id);
DB::commit();
} catch (Exception $error) {
DB::rollBack();
return back()->withErrors($error->getMessage());
}
return redirect()->route('package.datastore.index')->with('success', 'Deleted datacenter successfully!');
}
}
@@ -0,0 +1,121 @@
<?php
namespace App\Http\Controllers\admin\package;
use App\Http\Controllers\Controller;
use App\Http\Requests\Package\FolderRequest;
use App\Jobs\VirtualMachine\Sync\SyncFolder;
use App\Models\ModuleFolder;
use App\Repositories\Module\Datacenter\DatacenterRepositoryInterface;
use App\Repositories\Module\Folder\FolderRepositoryInterface;
use Exception;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class Folder extends Controller
{
public function __construct(
public FolderRepositoryInterface $folderRepository,
public DatacenterRepositoryInterface $datacenterRepository
) {}
public function index(Request $request)
{
$folders = $this->folderRepository->filter([
'page' => $request->get('page') ?? 1
], ['datacenter.vCenter']);
$title = 'List all folder';
return view('admin.package.folder.index', compact('folders', 'title'));
}
public function sync(SyncFolder $syncFolder)
{
dispatch($syncFolder)->delay(now()->addSeconds(5));
return back()->with('success', 'The process is being established, please wait');
}
public function create()
{
$title = 'Add Folder';
return view('admin.package.folder.add', compact('title'));
}
public function store(FolderRequest $request)
{
$request->validated();
$datacenter = $this->datacenterRepository->find($request->get('module_datacenter_id'));
if (! $datacenter) {
return back()->withErrors('Invalid Request');
}
$isCreated = $this->folderRepository->findBy('folder', $request->get('folder'));
if ($isCreated) {
return back()->withErrors('The Folder ID already exists');
}
DB::beginTransaction();
try {
$this->folderRepository->create($request->all());
DB::commit();
} catch (Exception $error) {
DB::rollBack();
return back()->withErrors($error->getMessage());
}
return redirect()->route('package.folder.index')->with('success', 'Add new Folder successfully');
}
public function edit(int $id = 0)
{
$folder = $this->folderRepository->findWithRelationships($id, ['datacenter']);
if (! $folder) {
return back()->withErrors('Invalid Request');
}
$title = 'Edit Folder';
return view('admin.package.folder.edit', compact('title', 'folder'));
}
public function update(int $id, FolderRequest $request)
{
$folder = $this->folderRepository->find($id);
if (! $folder) {
return redirect()->route('package.folder.index')->withErrors('Invalid request.');
}
$request->validated();
$datacenter = $this->datacenterRepository->find($request->get('module_datacenter_id'));
if (! $datacenter) {
return back()->withErrors('Invalid Request');
}
if ($request->get('folder') !== $folder->folder) {
$isCreated = $this->folderRepository->findBy('folder', $request->get('folder'));
if ($isCreated) {
return back()->withErrors('The Folder ID already exists');
}
}
DB::beginTransaction();
try {
$this->folderRepository->update($id, $request->all());
DB::commit();
} catch (Exception $error) {
DB::rollBack();
return back()->withErrors($error->getMessage());
}
return redirect()->route('package.folder.index')->with('success', 'Updated successfully');
}
public function destroy(int $id = 0)
{
$datastore = $this->folderRepository->find($id);
if (! $datastore) {
return back()->withErrors('Invalid request.');
}
DB::beginTransaction();
try {
$this->folderRepository->delete($id);
DB::commit();
} catch (Exception $error) {
DB::rollBack();
return back()->withErrors($error->getMessage());
}
return redirect()->route('package.folder.index')->with('success', 'Deleted successfully!');
}
}
@@ -0,0 +1,137 @@
<?php
namespace App\Http\Controllers\admin\package;
use App\Http\Controllers\Controller;
use App\Http\Requests\Package\OsGroupRequest;
use App\Http\Services\Upload;
use App\Imports\GroupImport;
use App\Models\ModuleDatastore;
use App\Models\ModuleHost;
use Illuminate\Http\Request;
use App\Models\OsGroup;
use App\Repositories\OsGroup\OsGroupRepositoryInterface;
use Exception;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\Validator;
use Maatwebsite\Excel\Facades\Excel;
class Group extends Controller
{
public function __construct(
public OsGroupRepositoryInterface $osGroupRepository
) {}
//
public function index(Request $request)
{
$group = $this->osGroupRepository->filter(
[
'page' => $request->get('page') ?? 1
],
['host']
);
$title = 'List all group Os for all datastore';
return view('admin.package.group.index', compact('group', 'title'));
}
public function import(Request $request)
{
if (! $request->file) {
return back()->withErrors("Please choose your file");
}
$data = Excel::toArray([], $request->file);
if (count($data) > 0) {
$data = array_slice($data[0], 1);
$allData = [];
foreach ($data as $row) {
if (isset($row[1]) && isset($row[2]) && isset($row[3]) && !empty($row[1]) && !empty($row[1]) && !empty($row[1])) {
$allData[] = [
'name' => $row[1],
'thumbnail' => $row[2],
'module_host_id' => $row[3]
];
}
}
}
if (! isset($allData) || (isset($allData) && count($allData) < 1)) {
return back()->withErrors('No data imported');
}
DB::beginTransaction();
try {
$this->osGroupRepository->insert($allData);
DB::commit();
} catch (Exception $error) {
DB::rollBack();
return back()->withErrors($error->getMessage());
}
return back()->with('success', 'Imported successfully');
}
public function create()
{
$title = 'Add new Group OS';
return view('admin.package.group.add', compact('title'));
}
public function store(OsGroupRequest $request)
{
$request->validated();
DB::beginTransaction();
try {
$this->osGroupRepository->create($request->all());
DB::commit();
} catch (\Exception $error) {
DB::rollBack();
return back()->withErrors($error->getMessage());
}
return redirect()->route('package.group.index')->with('success', 'Add new Os Group successfully');
}
public function edit(int $id = 0)
{
$group = $this->osGroupRepository->findWithRelationships($id, ['host.datacenter']);
if (! $group) {
return back()->withErrors('Can\'t find your group by id ' . $id);
}
$title = 'Edit Group OS';
return view('admin.package.group.edit', compact('title', 'group'));
}
public function update(int $id = 0, OsGroupRequest $request)
{
$group = $this->osGroupRepository->find($id);
if (! $group) {
return redirect()->route('package.group.index')->withErrors('Invalid Request');
}
$request->validated();
DB::beginTransaction();
try {
$this->osGroupRepository->update($id, $request->all());
DB::commit();
} catch (\Exception $error) {
DB::rollBack();
return back()->withErrors($error->getMessage());
}
return redirect()->route('package.group.index')->with('success', 'Update successfully');
}
public function destroy(int $id = 0)
{
$group = $this->osGroupRepository->find($id);
if (! $group) {
return redirect()->route('package.group.index')->withErrors('Invalid Request');
}
DB::beginTransaction();
try {
$this->osGroupRepository->delete($id);
DB::commit();
} catch (Exception $error) {
DB::rollBack();
return back()->withErrors($error->getMessage());
}
return redirect()->route('package.group.index')->with('success', 'Delete Group success');
}
}
+117
View File
@@ -0,0 +1,117 @@
<?php
namespace App\Http\Controllers\admin\package;
use App\Http\Controllers\Controller;
use App\Http\Requests\Package\HostRequest;
use App\Jobs\VirtualMachine\Sync\SyncHost;
use App\Models\ModuleDatacenter;
use App\Models\ModuleHost;
use App\Models\vCenter;
use App\Repositories\Module\Datacenter\DatacenterRepositoryInterface;
use App\Repositories\Module\Host\HostRepositoryInterface;
use Exception;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Validator;
class Host extends Controller
{
public function __construct(
public HostRepositoryInterface $hostRepository,
public DatacenterRepositoryInterface $datacenterRepository
) {}
public function index(Request $request)
{
$hosts = $this->hostRepository->filter([
'page' => $request->get('page') ?? 1
], ['datacenter.vCenter']);
$title = 'List all Host';
return view("admin.package.host.index", compact('hosts', 'title'));
}
public function sync(SyncHost $syncHost)
{
dispatch($syncHost)->delay(now()->addSeconds(5));
return back()->with('success', 'The process is being established, please wait');
}
public function create()
{
$title = 'Add host';
return view('admin.package.host.add', compact('title'));
}
public function store(HostRequest $request)
{
$request->validated();
$datacenter = $this->datacenterRepository->find($request->get('module_datacenter_id'));
if (! $datacenter) {
return back()->withErrors('Invalid Request');
}
$isCreated = $this->hostRepository->findBy('host_id', $request->get('host_id'));
if ($isCreated) {
return back()->withErrors('The Host ID already exists');
}
DB::beginTransaction();
try {
$this->hostRepository->create($request->all());
DB::commit();
} catch (Exception $error) {
DB::rollBack();
return back()->withErrors($error->getMessage());
}
return redirect()->route('package.host.index')->with('success', 'Add new host successfully');
}
public function edit(int $id = 0)
{
$host = $this->hostRepository->findWithRelationships($id, ['datacenter']);
if (! $host) {
return back()->withErrors('Invalid Request');
}
$title = "View Host Information";
return view('admin.package.host.edit', compact('host', 'title'));
}
public function update(int $id = 0, HostRequest $request)
{
$request->validated();
$host = $this->hostRepository->find($id);
if (! $host) {
return redirect()->route('package.host.index')->withErrors('Invalid Request');
}
if ($request->get('host_id') !== $host->host_id) {
$isCreated = $this->hostRepository->findBy('host_id', $request->get('host_id'));
if ($isCreated) {
return back()->withErrors('The Host ID already exists');
}
}
try {
DB::beginTransaction();
$this->hostRepository->update($id, $request->all());
DB::commit();
} catch (Exception $exception) {
DB::rollBack();
return back()->withErrors($exception->getMessage());
}
return redirect()->route('package.host.index')->with('success', 'Update successfully');
}
public function destroy(int $id = 0)
{
$host = $this->hostRepository->find($id);
if (! $host) {
return back()->withErrors('Invalid request.');
}
DB::beginTransaction();
try {
$this->hostRepository->delete($id);
DB::commit();
} catch (Exception $error) {
DB::rollBack();
return back()->withErrors($error->getMessage());
}
return redirect()->route('package.host.index')->with('success', 'Deleted successfully!');
}
}
@@ -0,0 +1,161 @@
<?php
namespace App\Http\Controllers\admin\package;
use App\Http\Controllers\Controller;
use App\Http\Requests\Package\IPRequest;
use App\Models\ModuleDatacenter;
use App\Models\ModuleHost;
use App\Models\ModuleIpAddress;
use App\Models\ModuleNetwork;
use App\Models\vCenter;
use App\Repositories\Module\IpAddress\IpAddressRepositoryInterface;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Validator;
class IPMapping extends Controller
{
public function __construct(
public IpAddressRepositoryInterface $ipAddressRepository
) {}
public function index(Request $request)
{
$listIP = $this->ipAddressRepository->filter(
[
'page' => $request->get('page') ?? 1
],
['host.datacenter']
);
$title = 'List All IP Address';
return view('admin.package.ipaddress.index', compact('listIP', 'title'));
}
public function create()
{
$title = 'Add new IP Address';
return view('admin.package.ipaddress.add', compact('title'));
}
public function store(IPRequest $request)
{
$request->validated();
$model_data = [];
if ((int) $request->option_selected === 1) {
if (empty($request->get('list-ip'))) {
return back()->withErrors('IP Address can\'t empty!');
}
$list = explode("\r\n", $request->get('list-ip'));
if (count($list) > 0) {
foreach ($list as $item) {
$model_data[] = [
'module_network_id' => $request->module_network_id,
'module_host_id' => $request->module_host_id,
'gateway' => $request->gateway,
'dns' => $request->dns,
'netmask' => $request->netmask,
'ip' => $item
];
}
}
} else {
if (empty($request->get('from'))) {
return back()->withErrors('IP Address From can\'t empty!');
}
if (empty($request->get('to'))) {
return back()->withErrors('IP Address To can\'t empty!');
}
$ipaddress = explode(".", $request->from);
$from = $ipaddress[3];
$to = explode(".", $request->to)[3];
for ($from; $from <= $to; $from++) {
$ipaddress[3] = $from;
$model_data[] = [
'module_network_id' => $request->module_network_id,
'module_host_id' => $request->module_host_id,
'gateway' => $request->gateway,
'dns' => $request->dns,
'netmask' => $request->netmask,
'ip' => implode('.', $ipaddress)
];
}
}
DB::beginTransaction();
try {
$this->ipAddressRepository->insert($model_data);
DB::commit();
} catch (\Exception $error) {
DB::rollBack();
return back()->withErrors($error->getMessage());
}
return redirect()->route('package.ipaddress.index')->with('success', 'Add new ipaddress successfully');
}
public function edit(int $id = 0)
{
$ipaddress = $this->ipAddressRepository->findWithRelationships($id, ['host.datacenter.vCenter']);
if (! $ipaddress) {
return back()->withErrors('Can\'t find IP Address by ID #' . $id);
}
$title = "View IP Address";
return view('admin.package.ipaddress.edit', compact('title', 'ipaddress'));
}
public function update(int $id = 0, IPRequest $request)
{
$ipaddress = $this->ipAddressRepository->find($id);
if (! $ipaddress) {
return back()->withErrors('Can\'t find IP Address by ID #' . $id);
}
$request->validated();
if ($request->get('ip') !== $ipaddress->ip) {
$ip = $this->ipAddressRepository->findBy('ip', $request->get('ip'));
if ($ip) {
return back()->withErrors('IP address already exists');
}
}
DB::beginTransaction();
try {
$this->ipAddressRepository->update($id, $request->all());
DB::commit();
} catch (\Exception $error) {
DB::rollBack();
return back()->withErrors($error->getMessage());
}
return redirect()->route('package.ipaddress.index')->with('success', 'Update new information for IP Address success');
}
public function destroy(int $id = 0)
{
$ipaddress = $this->ipAddressRepository->find($id);
if (! $ipaddress) {
return back()->withErrors('Can\'t find IP Address by ID #' . $id);
}
DB::beginTransaction();
try {
$this->ipAddressRepository->delete($id);
DB::commit();
} catch (\Exception $error) {
DB::rollBack();
return back()->withErrors($error->getMessage());
}
return back()->with('success', 'Deleted Successfully');
}
}
@@ -0,0 +1,118 @@
<?php
namespace App\Http\Controllers\admin\package;
use App\Http\Controllers\Controller;
use App\Http\Requests\Package\NetworkRequest;
use App\Jobs\VirtualMachine\Sync\SyncNetwork;
use App\Models\ModuleNetwork;
use App\Repositories\Module\Host\HostRepositoryInterface;
use App\Repositories\Module\Network\NetworkRepositoryInterface;
use Exception;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class Network extends Controller
{
//
public function __construct(
public NetworkRepositoryInterface $networkRepository,
public HostRepositoryInterface $hostRepository
){}
public function index(Request $request)
{
$networks = $this->networkRepository->filter(
[
'page' => $request->get('page') ?? 1
],['host.datacenter.vCenter']
);
$title = 'List all network';
return view('admin.package.network.index',compact('networks','title'));
}
public function sync(SyncNetwork $syncNetwork)
{
dispatch($syncNetwork)->delay(now()->addSeconds(5));
return back()->with('success','The process is being established, please wait');
}
public function create()
{
$title = 'Add Network';
return view('admin.package.network.add', compact('title'));
}
public function store(NetworkRequest $request)
{
$request->validated();
$host = $this->hostRepository->find($request->get('module_host_id'));
if (! $host) {
return back()->withErrors('Invalid Request');
}
$isCreated = $this->networkRepository->findBy('network', $request->get('network'));
if ($isCreated) {
return back()->withErrors('The Network ID already exists');
}
DB::beginTransaction();
try {
$this->networkRepository->create($request->all());
DB::commit();
} catch (Exception $error) {
DB::rollBack();
return back()->withErrors($error->getMessage());
}
return redirect()->route('package.network.index')->with('success', 'Add new Network successfully');
}
public function edit(int $id = 0)
{
$network = $this->networkRepository->findWithRelationships($id, ['host.datacenter']);
if (! $network) {
return back()->withErrors('Invalid Request');
}
$title = "View Network Information";
return view('admin.package.network.edit', compact('network', 'title'));
}
public function update(int $id = 0, NetworkRequest $request)
{
$request->validated();
$host = $this->networkRepository->find($id);
if (! $host) {
return redirect()->route('package.network.index')->withErrors('Invalid Request');
}
if ($request->get('network') !== $host->network) {
$isCreated = $this->networkRepository->findBy('network', $request->get('network'));
if ($isCreated) {
return back()->withErrors('The Network ID already exists');
}
}
try {
DB::beginTransaction();
$this->networkRepository->update($id, $request->all());
DB::commit();
} catch (Exception $exception) {
DB::rollBack();
return back()->withErrors($exception->getMessage());
}
return redirect()->route('package.network.index')->with('success', 'Update successfully');
}
public function destroy(int $id = 0)
{
$host = $this->networkRepository->find($id);
if (! $host) {
return back()->withErrors('Invalid request.');
}
DB::beginTransaction();
try {
$this->networkRepository->delete($id);
DB::commit();
} catch (Exception $error) {
DB::rollBack();
return back()->withErrors($error->getMessage());
}
return redirect()->route('package.network.index')->with('success', 'Deleted successfully!');
}
}
@@ -0,0 +1,99 @@
<?php
namespace App\Http\Controllers\admin\package;
use App\Http\Controllers\Controller;
use App\Http\Requests\Package\OsVersionRequest;
use App\Models\ModuleDatacenter;
use App\Models\ModuleDatastore;
use App\Models\ModuleHost;
use App\Models\Os;
use App\Models\OsGroup;
use App\Models\vCenter;
use App\Http\Services\vCenter as ServiceVCenter;
use App\Repositories\Os\OsRepositoryInterface;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Validator;
class OsVersion extends Controller
{
public function __construct(
public OsRepositoryInterface $osRepository
) {}
public function index(Request $request)
{
$versions = $this->osRepository->filter([
'page' => $request->get('page') ?? 1
], ['osGroup.host']);
$title = 'List all Version OS';
return view('admin.package.version.index', compact('versions', 'title'));
}
public function create()
{
$title = 'Add new Version Os';
return view('admin.package.version.add', compact('title'));
}
public function store(OsVersionRequest $request)
{
$request->validated();
DB::beginTransaction();
try {
$this->osRepository->create($request->all());
DB::commit();
} catch (\Exception $error) {
DB::rollBack();
return back()->withErrors($error->getMessage());
}
return redirect()->route('package.version.index')->with('success', 'Add Os Version successfully');
}
public function edit(int $id = 0)
{
$version = $this->osRepository->findWithRelationships($id, ['osGroup.host.datacenter.vCenter']);
if (! $version) {
return back()->withErrors('Can\'t find version os by ID #' . $id);
}
$title = "Edit version OS";
return view('admin.package.version.edit', compact('title', 'version'));
}
public function update(int $id = 0, OsVersionRequest $request)
{
$version = $this->osRepository->find($id);
if (! $version) {
return back()->withErrors('Can\'t find version os by ID #' . $id);
}
DB::beginTransaction();
try {
$this->osRepository->update($id,$request->all());
DB::commit();
} catch (\Exception $error) {
DB::rollBack();
return back()->withErrors($error->getMessage());
}
return redirect()->route('package.version.index')->with('success', 'Update successfully');
}
public function destroy(Request $request)
{
$validator = Validator::make($request->all(), [
'oid' => 'numeric'
]);
if ($validator->fails()) {
return back()->withErrors($validator->getMessageBag());
}
$version = Os::find($request->oid);
if (! $version) {
return back()->withErrors('Can\'t find version os by ID #' . $request->oid);
}
$version->delete();
return back()->with('success', 'Delete success');
}
}
@@ -0,0 +1,17 @@
<?php
namespace App\Http\Controllers\admin\package;
use App\Http\Controllers\Controller;
use App\Jobs\VirtualMachine\Sync\SyncAllPackage;
class SyncController extends Controller
{
//
public function index()
{
$job = new SyncAllPackage();
dispatch($job)->delay(now()->addSeconds(5));
return back()->with('success','Please wait job run in background');
}
}