Commit 40ea1847 authored by Roman Ondráček's avatar Roman Ondráček

Gateway: refactor service control

Signed-off-by: Roman Ondráček's avatarRoman Ondráček <ondracek.roman@centrum.cz>
parent 45a32325
Pipeline #2093 passed with stages
in 14 minutes and 31 seconds
......@@ -46,13 +46,6 @@ class ControlPresenter extends ProtectedPresenter {
parent::__construct();
}
/**
* Starts IQRF Gateway Daemon's service
*/
public function actionStart(): void {
$this->action('start');
}
/**
* Starts, stops or restarts IQRF Gateway Daemon's service
* @param string $action Type of action (start/stop/restart)
......@@ -73,23 +66,57 @@ class ControlPresenter extends ProtectedPresenter {
$this->flashSuccess('service.actions.' . $action . '.message');
} catch (NotSupportedInitSystemException $ex) {
$this->flashError('service.errors.unsupportedInit');
} finally {
$this->redirect('Control:default');
}
$this->readStatus();
}
/**
* Starts IQRF Gateway Daemon's service
*/
public function handleStart(): void {
$this->action('start');
}
/**
* Stops IQRF Gateway Daemon's service
*/
public function actionStop(): void {
public function handleStop(): void {
$this->action('stop');
}
/**
* Restarts IQRF Gateway Daemon's service
*/
public function actionRestart(): void {
public function handleRestart(): void {
$this->action('restart');
}
/**
* Refreshes IQRF Gateway Daemon's service status
*/
public function handleStatus(): void {
$this->readStatus();
}
/**
* Reads IQRF Gateway Daemon's service status
*/
private function readStatus(): void {
try {
$this->template->status = $this->serviceManager->getStatus();
$this->redrawControl('status');
} catch (NotSupportedInitSystemException $ex) {
$this->flashError('gateway.errors.unsupportedInit');
}
}
/**
* Renders IQRF Gateway Daemon's service status
*/
public function renderDefault(): void {
if (!$this->isAjax()) {
$this->readStatus();
}
}
}
<?php
/**
* Copyright 2017 MICRORISC s.r.o.
* Copyright 2017-2019 IQRF Tech s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
declare(strict_types = 1);
namespace App\ServiceModule\Presenters;
use App\CoreModule\Presenters\ProtectedPresenter;
use App\CoreModule\Traits\TPresenterFlashMessage;
use App\ServiceModule\Exceptions\NotSupportedInitSystemException;
use App\ServiceModule\Models\ServiceManager;
/**
* Service status presenter
*/
class StatusPresenter extends ProtectedPresenter {
use TPresenterFlashMessage;
/**
* @var ServiceManager Service manager
*/
private $serviceManager;
/**
* Constructor
* @param ServiceManager $serviceManager Service manager
*/
public function __construct(ServiceManager $serviceManager) {
$this->serviceManager = $serviceManager;
parent::__construct();
}
/**
* Renders IQRF Gateway Daemon's service status
*/
public function renderDefault(): void {
try {
$status = $this->serviceManager->getStatus();
$this->template->status = $status;
} catch (NotSupportedInitSystemException $ex) {
$this->flashError('gateway.errors.unsupportedInit');
$this->redirect('Control:default');
}
}
}
......@@ -17,21 +17,21 @@
{block title}{_service.title}{/block}
{block content}
<div class='list-group'>
<a n:href='Control:start' class='list-group-item'>
<header class='list-group-item-heading'>{_service.actions.start.title}</header>
<p class='list-group-item-text'>{_service.actions.start.description}</p>
</a>
<a n:href='Control:stop' class='list-group-item'>
<header class='list-group-item-heading'>{_service.actions.stop.title}</header>
<p class='list-group-item-text'>{_service.actions.stop.description}</p>
</a>
<a n:href='Control:restart' class='list-group-item'>
<header class='list-group-item-heading'>{_service.actions.restart.title}</header>
<p class='list-group-item-text'>{_service.actions.restart.description}</p>
</a>
<a n:href='Status:default' class='list-group-item'>
<header class='list-group-item-heading'>{_service.actions.status.title}</header>
<p class='list-group-item-text'>{_service.actions.status.description}</p>
</a>
<div class='panel panel-default'>
<div class='panel-body'>
<a class='ajax btn btn-success' n:href='start!' role='button'>
{_service.actions.start.title}
</a>
<a class='ajax btn btn-danger' n:href='stop!' role='button'>
{_service.actions.stop.title}
</a>
<a class='ajax btn btn-primary' n:href='restart!' role='button'>
{_service.actions.restart.title}
</a>
<a class='ajax btn btn-default' n:href='status!' role='button'>
{_service.actions.status.title}
</a>
<br/><br/>
<pre n:snippet='status' class='log'>{$status}</pre>
</div>
</div>
{**
* Copyright 2017 MICRORISC s.r.o.
* Copyright 2017-2019 IQRF Tech s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*}
{block title}{_service.actions.status.title}{/block}
{block content}
<div class='panel panel-default'>
<div class='panel-body'>
{$status|breaklines}
</div>
</div>
......@@ -4,19 +4,15 @@ description: Control IQRF Gateway Daemon's service.
actions:
start:
title: Start
description: Starts IQRF Gateway Daemon's service.
message: IQRF Gateway Daemon has been started.
stop:
title: Stop
description: Stops IQRF Gateway Daemon's service.
message: IQRF Gateway Daemon has been stopped.
restart:
title: Restart
description: Restarts IQRF Gateway Daemon's service.
message: IQRF Gateway Daemon has been restarted.
status:
title: Status
description: Gets status of IQRF Gateway Daemon's service.
title: Refresh status
errors:
unsupportedInit: Not supported init system is used.
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