2016-01-04 23:59:45 -05:00
|
|
|
<?php
|
2016-12-07 22:46:38 +00:00
|
|
|
|
2024-03-12 22:39:16 -04:00
|
|
|
namespace App\Http\Controllers\Admin;
|
2016-01-04 23:59:45 -05:00
|
|
|
|
2022-10-14 10:59:20 -06:00
|
|
|
use Illuminate\View\View;
|
2024-03-12 22:39:16 -04:00
|
|
|
use App\Models\Node;
|
2022-10-14 10:59:20 -06:00
|
|
|
use Illuminate\Http\RedirectResponse;
|
2017-08-05 17:26:30 -05:00
|
|
|
use Prologue\Alerts\AlertsMessageBag;
|
2022-10-14 10:59:20 -06:00
|
|
|
use Illuminate\View\Factory as ViewFactory;
|
2024-03-12 22:39:16 -04:00
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
|
use App\Services\Nodes\NodeUpdateService;
|
2017-08-30 21:14:20 -05:00
|
|
|
use Illuminate\Cache\Repository as CacheRepository;
|
2024-03-12 22:39:16 -04:00
|
|
|
use App\Services\Nodes\NodeCreationService;
|
|
|
|
|
use App\Services\Nodes\NodeDeletionService;
|
|
|
|
|
use App\Services\Helpers\SoftwareVersionService;
|
|
|
|
|
use App\Http\Requests\Admin\Node\NodeFormRequest;
|
2016-01-04 23:59:45 -05:00
|
|
|
|
|
|
|
|
class NodesController extends Controller
|
|
|
|
|
{
|
2017-08-05 21:10:32 -05:00
|
|
|
/**
|
|
|
|
|
* NodesController constructor.
|
|
|
|
|
*/
|
2017-08-05 17:20:07 -05:00
|
|
|
public function __construct(
|
2022-10-14 10:59:20 -06:00
|
|
|
protected AlertsMessageBag $alert,
|
|
|
|
|
protected CacheRepository $cache,
|
|
|
|
|
protected NodeCreationService $creationService,
|
|
|
|
|
protected NodeDeletionService $deletionService,
|
|
|
|
|
protected NodeUpdateService $updateService,
|
|
|
|
|
protected SoftwareVersionService $versionService,
|
|
|
|
|
protected ViewFactory $view
|
2017-08-05 17:20:07 -05:00
|
|
|
) {
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-03 23:37:41 -05:00
|
|
|
/**
|
|
|
|
|
* Displays create new node page.
|
|
|
|
|
*/
|
2022-10-14 10:59:20 -06:00
|
|
|
public function create(): View|RedirectResponse
|
2016-01-04 23:59:45 -05:00
|
|
|
{
|
2024-03-16 23:23:07 -04:00
|
|
|
return view('admin.nodes.new');
|
2016-01-04 23:59:45 -05:00
|
|
|
}
|
|
|
|
|
|
2017-03-03 23:14:23 -05:00
|
|
|
/**
|
|
|
|
|
* Updates settings for a node.
|
|
|
|
|
*
|
2024-03-12 22:39:16 -04:00
|
|
|
* @throws \App\Exceptions\DisplayException
|
|
|
|
|
* @throws \App\Exceptions\Model\DataValidationException
|
2017-03-03 23:14:23 -05:00
|
|
|
*/
|
2022-10-14 10:59:20 -06:00
|
|
|
public function updateSettings(NodeFormRequest $request, Node $node): RedirectResponse
|
2016-01-05 18:31:25 -05:00
|
|
|
{
|
2018-12-02 13:38:59 -08:00
|
|
|
$this->updateService->handle($node, $request->normalize(), $request->input('reset_secret') === 'on');
|
2017-08-08 21:21:10 -05:00
|
|
|
$this->alert->success(trans('admin/node.notices.node_updated'))->flash();
|
2016-12-07 22:46:38 +00:00
|
|
|
|
2017-08-05 17:20:07 -05:00
|
|
|
return redirect()->route('admin.nodes.view.settings', $node->id)->withInput();
|
2016-01-05 18:31:25 -05:00
|
|
|
}
|
|
|
|
|
|
2017-03-03 23:14:23 -05:00
|
|
|
/**
|
|
|
|
|
* Deletes a node from the system.
|
|
|
|
|
*
|
2024-03-12 22:39:16 -04:00
|
|
|
* @throws \App\Exceptions\DisplayException
|
2017-03-03 23:14:23 -05:00
|
|
|
*/
|
2022-10-14 10:59:20 -06:00
|
|
|
public function delete(int|Node $node): RedirectResponse
|
2017-03-03 17:30:39 -05:00
|
|
|
{
|
2017-08-05 17:20:07 -05:00
|
|
|
$this->deletionService->handle($node);
|
2017-08-08 21:21:10 -05:00
|
|
|
$this->alert->success(trans('admin/node.notices.node_deleted'))->flash();
|
2016-12-07 22:46:38 +00:00
|
|
|
|
2017-08-05 17:20:07 -05:00
|
|
|
return redirect()->route('admin.nodes');
|
2016-01-10 16:59:19 -05:00
|
|
|
}
|
2016-01-04 23:59:45 -05:00
|
|
|
}
|