Skip to content

Commit

Permalink
refs #19 widget title is now configurable
Browse files Browse the repository at this point in the history
Signed-off-by: Julien Veyssier <[email protected]>
  • Loading branch information
Julien Veyssier committed Nov 18, 2021
1 parent d1fb4a7 commit 732204a
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 23 deletions.
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<bugs>https://github.com/eneiluj/welcome/issues</bugs>
<screenshot>https://github.com/eneiluj/welcome/raw/master/img/screenshot1.jpg</screenshot>
<dependencies>
<nextcloud min-version="20" max-version="24"/>
<nextcloud min-version="22" max-version="24"/>
</dependencies>
<settings>
<admin>OCA\Welcome\Settings\Admin</admin>
Expand Down
30 changes: 22 additions & 8 deletions lib/Dashboard/WelcomeWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,32 @@
namespace OCA\Welcome\Dashboard;

use OCP\Dashboard\IWidget;
use OCP\IConfig;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\Util;

use OCA\Welcome\AppInfo\Application;

class WelcomeWidget implements IWidget {

/** @var IL10N */
private $l10n;
/**
* @var IConfig
*/
private $config;
/**
* @var IURLGenerator
*/
private $url;

public function __construct(
IL10N $l10n
) {
public function __construct(IL10N $l10n,
IURLGenerator $url,
IConfig $config) {
$this->l10n = $l10n;
$this->config = $config;
$this->url = $url;
}

/**
Expand All @@ -50,8 +63,9 @@ public function getId(): string {
* @inheritDoc
*/
public function getTitle(): string {
return $this->l10n->t('Welcome');
}
$widgetTitle = $this->config->getAppValue(Application::APP_ID, 'widgetTitle', $this->l10n->t('Welcome'));
return $widgetTitle ?: $this->l10n->t('Welcome');
}

/**
* @inheritDoc
Expand All @@ -71,14 +85,14 @@ public function getIconClass(): string {
* @inheritDoc
*/
public function getUrl(): ?string {
return \OC::$server->getURLGenerator()->linkToRoute('settings.AdminSettings.index', ['section' => 'theming']);
return $this->url->linkToRoute('settings.AdminSettings.index', ['section' => 'theming']);
}

/**
* @inheritDoc
*/
public function load(): void {
\OC_Util::addScript(Application::APP_ID, Application::APP_ID . '-dashboard');
\OC_Util::addStyle(Application::APP_ID, 'dashboard');
Util::addScript(Application::APP_ID, Application::APP_ID . '-dashboard');
Util::addStyle(Application::APP_ID, 'dashboard');
}
}
18 changes: 7 additions & 11 deletions lib/Settings/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,25 @@
use OCP\IL10N;
use OCP\IConfig;
use OCP\Settings\ISettings;
use OCP\Util;
use OCP\IURLGenerator;
use OCP\IInitialStateService;
use OCP\AppFramework\Services\IInitialState;

use OCA\Welcome\AppInfo\Application;

class Admin implements ISettings {

private $request;
private $config;
private $dataDirPath;
private $urlGenerator;
private $l;

public function __construct(string $appName,
IL10N $l,
IL10N $l10n,
IRequest $request,
IConfig $config,
IURLGenerator $urlGenerator,
IInitialStateService $initialStateService,
IInitialState $initialStateService,
$userId) {
$this->appName = $appName;
$this->urlGenerator = $urlGenerator;
$this->request = $request;
$this->l = $l;
$this->l10n = $l10n;
$this->config = $config;
$this->initialStateService = $initialStateService;
$this->userId = $userId;
Expand All @@ -46,6 +40,7 @@ public function getForm(): TemplateResponse {
$supportUserId = $this->config->getAppValue(Application::APP_ID, 'supportUserId', '');
$supportUserName = $this->config->getAppValue(Application::APP_ID, 'supportUserName', '');
$supportText = $this->config->getAppValue(Application::APP_ID, 'supportText', '');
$widgetTitle = $this->config->getAppValue(Application::APP_ID, 'widgetTitle', '');

$adminConfig = [
'filePath' => $filePath,
Expand All @@ -54,8 +49,9 @@ public function getForm(): TemplateResponse {
'supportUserId' => $supportUserId,
'supportUserName' => $supportUserName,
'supportText' => $supportText,
'widgetTitle' => $widgetTitle,
];
$this->initialStateService->provideInitialState($this->appName, 'admin-config', $adminConfig);
$this->initialStateService->provideInitialState('admin-config', $adminConfig);
return new TemplateResponse(Application::APP_ID, 'adminSettings');
}

Expand Down
19 changes: 16 additions & 3 deletions src/components/AdminSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@
<br>
<div v-if="state.filePath"
class="grid-form">
<label for="welcome-widget-title">
<span class="icon icon-file" />
{{ t('welcome', 'Widget title') }}
</label>
<input id="welcome-widget-title"
v-model="state.widgetTitle"
type="text"
:class="{ 'icon-loading-small': saving }"
:placeholder="t('welcome', 'Welcome')"
@input="onTextChange">
<label for="welcome-support">
<span class="icon icon-user" />
{{ t('welcome', 'Support contact') }}
Expand Down Expand Up @@ -92,7 +102,7 @@
type="text"
:class="{ 'icon-loading-small': saving }"
:placeholder="t('welcome', 'Example: Call {name} to get help.')"
@input="onSupportTextChange">
@input="onTextChange">
<div />
<span class="settings-hint">
<span class="icon icon-details" />
Expand Down Expand Up @@ -264,9 +274,12 @@ export default {
supportUserName: '',
})
},
onSupportTextChange() {
onTextChange() {
delay(() => {
this.saveOptions({ supportText: this.state.supportText })
this.saveOptions({
supportText: this.state.supportText,
widgetTitle: this.state.widgetTitle,
})
}, 2000)()
},
},
Expand Down

0 comments on commit 732204a

Please sign in to comment.