fix: always show missing conf message

pull/129/head
sualko 2021-02-24 14:59:56 +01:00
parent b28469ada4
commit cc566608b2
5 changed files with 62 additions and 35 deletions

View File

@ -2,19 +2,18 @@
namespace OCA\BigBlueButton\Controller; namespace OCA\BigBlueButton\Controller;
use OCA\BigBlueButton\TemplateProvider;
use OCP\AppFramework\Controller; use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\IConfig;
use OCP\IRequest; use OCP\IRequest;
class PageController extends Controller { class PageController extends Controller {
/** @var IConfig */ /** @var TemplateProvider */
private $config; private $templateProvider;
public function __construct(string $appName, IRequest $request, IConfig $config) { public function __construct(string $appName, IRequest $request, TemplateProvider $templateProvider) {
parent::__construct($appName, $request); parent::__construct($appName, $request);
$this->config = $config; $this->templateProvider = $templateProvider;
} }
/** /**
@ -22,8 +21,6 @@ class PageController extends Controller {
* @NoCSRFRequired * @NoCSRFRequired
*/ */
public function index() { public function index() {
return new TemplateResponse($this->appName, 'manager', [ return $this->templateProvider->getManager();
'shortener' => $this->config->getAppValue('bbb', 'app.shortener', ''),
]);
} }
} }

View File

@ -2,42 +2,29 @@
namespace OCA\BigBlueButton\Settings; namespace OCA\BigBlueButton\Settings;
use \OCP\IL10N; use OCA\BigBlueButton\TemplateProvider;
use OCP\AppFramework\Http\TemplateResponse; use OCP\AppFramework\Http\TemplateResponse;
use OCP\IConfig; use OCP\IConfig;
use OCP\Settings\ISettings; use OCP\Settings\ISettings;
class Personal implements ISettings { class Personal implements ISettings {
/** @var IConfig */ /** @var TemplateProvider */
private $config; private $templateProvider;
/** @var IL10N */
private $l;
/** /**
* Admin constructor. * Admin constructor.
* *
* @param IConfig $config * @param IConfig $config
*/ */
public function __construct(IConfig $config, IL10N $l) { public function __construct(TemplateProvider $templateProvider) {
$this->config = $config; $this->templateProvider = $templateProvider;
$this->l = $l;
} }
/** /**
* @return TemplateResponse * @return TemplateResponse
*/ */
public function getForm() { public function getForm() {
$warning = ''; return $this->templateProvider->getManager();
if (empty($this->config->getAppValue('bbb', 'api.url')) || empty($this->config->getAppValue('bbb', 'api.secret'))) {
$warning = $this->l->t('API URL or secret not configured. Please contact your administrator.');
}
return new TemplateResponse('bbb', 'manager', [
'warning' => $warning,
'shortener' => $this->config->getAppValue('bbb', 'app.shortener', ''),
]);
} }
/** /**

41
lib/TemplateProvider.php Normal file
View File

@ -0,0 +1,41 @@
<?php
namespace OCA\BigBlueButton;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\IConfig;
use OCP\IL10N;
class TemplateProvider {
/** @var IConfig */
private $config;
/** @var IL10N */
private $l;
/**
* Admin constructor.
*
* @param IConfig $config
*/
public function __construct(IConfig $config, IL10N $l) {
$this->config = $config;
$this->l = $l;
}
/**
* @return TemplateResponse
*/
public function getManager(): TemplateResponse {
$warning = '';
if (empty($this->config->getAppValue('bbb', 'api.url')) || empty($this->config->getAppValue('bbb', 'api.secret'))) {
$warning = $this->l->t('API URL or secret not configured. Please contact your administrator.');
}
return new TemplateResponse('bbb', 'manager', [
'warning' => $warning,
'shortener' => $this->config->getAppValue('bbb', 'app.shortener', ''),
]);
}
}

View File

@ -2,6 +2,7 @@
script('bbb', 'manager'); script('bbb', 'manager');
?> ?>
<div id="bbb-app">
<div id="bbb-root" data-shortener="<?php p($_['shortener']); ?>"></div> <div id="bbb-root" data-shortener="<?php p($_['shortener']); ?>"></div>
<?php if (!empty($_['warning'])): ?> <?php if (!empty($_['warning'])): ?>
@ -9,3 +10,4 @@ script('bbb', 'manager');
<span class="icon icon-error-color icon-visible"></span> <?php p($_['warning']); ?> <span class="icon icon-error-color icon-visible"></span> <?php p($_['warning']); ?>
</div> </div>
<?php endif; ?> <?php endif; ?>
</div>

View File

@ -35,7 +35,7 @@
opacity: 0.6; opacity: 0.6;
} }
#bbb-root { #bbb-root, #bbb-app {
width: 100%; width: 100%;
} }