Commit 8d3193cc authored by Roman Ondráček's avatar Roman Ondráček

Gateway: refactor gateway mode control panel (fix #210)

Signed-off-by: Roman Ondráček's avatarRoman Ondráček <ondracek.roman@centrum.cz>
parent 26560e62
Pipeline #2094 passed with stages
in 13 minutes and 11 seconds
......@@ -29,7 +29,7 @@ use App\IqrfNetModule\Models\GwModeManager;
use Nette\Utils\JsonException;
/**
* Change IQRF Gateway Daemon's operational mode presenter
* Change IQRF Gateway Daemon's gateway mode presenter
*/
class ChangeModePresenter extends ProtectedPresenter {
......@@ -49,16 +49,6 @@ class ChangeModePresenter extends ProtectedPresenter {
parent::__construct();
}
/**
* Changes IQRF Gateway's mode to Forwarding mode
* @throws EmptyResponseException
* @throws InvalidOperationModeException
* @throws JsonException
*/
public function actionForwarding(): void {
$this->changeMode('forwarding');
}
/**
* Changes IQRF Gateway Daemon's mode
* @param string $mode New IQRF Gateway's mode
......@@ -70,20 +60,29 @@ class ChangeModePresenter extends ProtectedPresenter {
$this->setView('default');
try {
$this->manager->set($mode);
$this->flashInfo('gateway.mode.modes.' . $mode . '.message');
$this->redirect('ChangeMode:default');
$this->flashSuccess('gateway.mode.modes.' . $mode . '.message');
} catch (EmptyResponseException | DpaErrorException $e) {
$this->flashError('iqrfnet.webSocketClient.messages.emptyResponse');
}
}
/**
* Changes IQRF Gateway's mode to Forwarding mode
* @throws EmptyResponseException
* @throws InvalidOperationModeException
* @throws JsonException
*/
public function handleForwarding(): void {
$this->changeMode('forwarding');
}
/**
* Changes IQRF Gateway's mode to Operational mode
* @throws EmptyResponseException
* @throws InvalidOperationModeException
* @throws JsonException
*/
public function actionOperational(): void {
public function handleOperational(): void {
$this->changeMode('operational');
}
......@@ -93,8 +92,20 @@ class ChangeModePresenter extends ProtectedPresenter {
* @throws InvalidOperationModeException
* @throws JsonException
*/
public function actionService(): void {
public function handleService(): void {
$this->changeMode('service');
}
/**
* Renders gateway mode control panel
*/
public function renderDefault(): void {
try {
$this->template->gwMode = $this->manager->get();
$this->redrawControl('mode');
} catch (DpaErrorException | EmptyResponseException $e) {
$this->template->gwMode = 'unknown';
}
}
}
......@@ -17,17 +17,24 @@
{block title}{_gateway.mode.title}{/block}
{block content}
<div class='list-group'>
<a n:href='ChangeMode:operational' class='list-group-item'>
<header class='list-group-item-heading'>{_gateway.mode.modes.operational.title}</header>
<p class='list-group-item-text'>{_gateway.mode.modes.operational.description}</p>
</a>
<a n:href='ChangeMode:service' class='list-group-item'>
<header class='list-group-item-heading'>{_gateway.mode.modes.service.title}</header>
<p class='list-group-item-text'>{_gateway.mode.modes.service.description}</p>
</a>
<a n:href='ChangeMode:forwarding' class='list-group-item'>
<header class='list-group-item-heading'>{_gateway.mode.modes.forwarding.title}</header>
<p class='list-group-item-text'>{_gateway.mode.modes.forwarding.description}</p>
</a>
<div class='panel panel-default'>
<div n:snippet='mode' class='panel-body'>
<table class='table table-striped'>
<tr>
<th>{_gateway.info.gwMode}</th>
<td>{_gateway.info.gwModes.$gwMode}</td>
</tr>
</table>
{if $gwMode !== 'unknown'}
<a class='ajax btn btn-primary' n:href='operational!' role='button'>
{_gateway.mode.modes.operational.title}
</a>
<a class='ajax btn btn-primary' n:href='service!' role='button'>
{_gateway.mode.modes.service.title}
</a>
<a class='ajax btn btn-primary' n:href='forwarding!' role='button'>
{_gateway.mode.modes.forwarding.title}
</a>
{/if}
</div>
</div>
......@@ -55,15 +55,12 @@ mode:
modes:
operational:
title: Operational mode
description: Change IQRF Gateway Daemon's mode to operational mode.
message: IQRF Gateway Daemon's mode has been changed to operational mode.
service:
title: Service mode
description: Change IQRF Gateway Daemon's mode to service mode.
message: IQRF Gateway Daemon's mode has been changed to service mode.
forwarding:
title: Forwarding mode
description: Change IQRF Gateway Daemon's mode to forwarding mode.
message: IQRF Gateway Daemon's mode has been changed to forwarding mode.
power:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment