Skip to content

Commit 75e5776

Browse files
authored
Merge pull request #57163 from nextcloud/refactor/themeing-vue3-ts
refactor(theming): migrate to Typescript and Vue 3
2 parents 1053986 + b820518 commit 75e5776

File tree

338 files changed

+3948
-5374
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

338 files changed

+3948
-5374
lines changed

apps/theming/lib/Controller/ThemingController.php

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,13 @@ public function updateStylesheet($setting, $value) {
8181
if (strlen($value) > 500) {
8282
$error = $this->l10n->t('The given web address is too long');
8383
}
84-
if (!$this->isValidUrl($value)) {
84+
if ($value !== '' && !$this->isValidUrl($value)) {
8585
$error = $this->l10n->t('The given web address is not a valid URL');
8686
}
8787
break;
88+
case 'legalNoticeUrl':
89+
$setting = 'imprintUrl';
90+
// no break
8891
case 'imprintUrl':
8992
if (strlen($value) > 500) {
9093
$error = $this->l10n->t('The given legal notice address is too long');
@@ -93,6 +96,9 @@ public function updateStylesheet($setting, $value) {
9396
$error = $this->l10n->t('The given legal notice address is not a valid URL');
9497
}
9598
break;
99+
case 'privacyPolicyUrl':
100+
$setting = 'privacyUrl';
101+
// no break
96102
case 'privacyUrl':
97103
if (strlen($value) > 500) {
98104
$error = $this->l10n->t('The given privacy policy address is too long');
@@ -106,30 +112,38 @@ public function updateStylesheet($setting, $value) {
106112
$error = $this->l10n->t('The given slogan is too long');
107113
}
108114
break;
115+
case 'primaryColor':
116+
$setting = 'primary_color';
117+
// no break
109118
case 'primary_color':
110119
if (!preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $value)) {
111120
$error = $this->l10n->t('The given color is invalid');
112-
} else {
113-
$this->appConfig->setAppValueString('primary_color', $value);
114-
$saved = true;
115121
}
116122
break;
123+
case 'backgroundColor':
124+
$setting = 'background_color';
125+
// no break
117126
case 'background_color':
118127
if (!preg_match('/^\#([0-9a-f]{3}|[0-9a-f]{6})$/i', $value)) {
119128
$error = $this->l10n->t('The given color is invalid');
120-
} else {
121-
$this->appConfig->setAppValueString('background_color', $value);
122-
$saved = true;
123129
}
124130
break;
131+
case 'disableUserTheming':
125132
case 'disable-user-theming':
126133
if (!in_array($value, ['yes', 'true', 'no', 'false'])) {
127-
$error = $this->l10n->t('Disable-user-theming should be true or false');
134+
$error = $this->l10n->t('%1$s should be true or false', ['disable-user-theming']);
128135
} else {
129136
$this->appConfig->setAppValueBool('disable-user-theming', $value === 'yes' || $value === 'true');
130137
$saved = true;
131138
}
132139
break;
140+
case 'backgroundMime':
141+
if ($value !== 'backgroundColor') {
142+
$error = $this->l10n->t('%1$s can only be set to %2$s through the API', ['backgroundMime', 'backgroundColor']);
143+
}
144+
break;
145+
default:
146+
$error = $this->l10n->t('Invalid setting key');
133147
}
134148
if ($error !== null) {
135149
return new DataResponse([
@@ -291,6 +305,11 @@ public function uploadImage(): DataResponse {
291305
*/
292306
#[AuthorizedAdminSetting(settings: Admin::class)]
293307
public function undo(string $setting): DataResponse {
308+
$setting = match ($setting) {
309+
'primaryColor' => 'primary_color',
310+
'backgroundColor' => 'background_color',
311+
default => $setting,
312+
};
294313
$value = $this->themingDefaults->undo($setting);
295314

296315
return new DataResponse(

apps/theming/lib/Settings/Admin.php

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
class Admin implements IDelegatedSettings {
2424

2525
public function __construct(
26-
private string $appName,
2726
private IConfig $config,
2827
private IL10N $l,
2928
private ThemingDefaults $themingDefaults,
@@ -38,11 +37,11 @@ public function __construct(
3837
* @return TemplateResponse
3938
*/
4039
public function getForm(): TemplateResponse {
41-
$themable = true;
40+
$themeable = true;
4241
$errorMessage = '';
4342
$theme = $this->config->getSystemValue('theme', '');
4443
if ($theme !== '') {
45-
$themable = false;
44+
$themeable = false;
4645
$errorMessage = $this->l->t('You are already using a custom theme. Theming app settings might be overwritten by that.');
4746
}
4847

@@ -51,9 +50,17 @@ public function getForm(): TemplateResponse {
5150
return $carry;
5251
}, []);
5352

53+
$this->initialState->provideInitialState('adminThemingInfo', [
54+
'isThemeable' => $themeable,
55+
'notThemeableErrorMessage' => $errorMessage,
56+
'defaultBackgroundURL' => $this->urlGenerator->linkTo(Application::APP_ID, 'img/background/' . BackgroundService::DEFAULT_BACKGROUND_IMAGE),
57+
'defaultBackgroundColor' => BackgroundService::DEFAULT_BACKGROUND_COLOR,
58+
'docUrl' => $this->urlGenerator->linkToDocs('admin-theming'),
59+
'docUrlIcons' => $this->urlGenerator->linkToDocs('admin-theming-icons'),
60+
'canThemeIcons' => $this->imageManager->shouldReplaceIcons(),
61+
]);
62+
5463
$this->initialState->provideInitialState('adminThemingParameters', [
55-
'isThemable' => $themable,
56-
'notThemableErrorMessage' => $errorMessage,
5764
'name' => $this->themingDefaults->getEntity(),
5865
'url' => $this->themingDefaults->getBaseUrl(),
5966
'slogan' => $this->themingDefaults->getSlogan(),
@@ -62,30 +69,25 @@ public function getForm(): TemplateResponse {
6269
'logoMime' => $this->config->getAppValue(Application::APP_ID, 'logoMime', ''),
6370
'allowedMimeTypes' => $allowedMimeTypes,
6471
'backgroundURL' => $this->imageManager->getImageUrl('background'),
65-
'defaultBackgroundURL' => $this->urlGenerator->linkTo(Application::APP_ID, 'img/background/' . BackgroundService::DEFAULT_BACKGROUND_IMAGE),
66-
'defaultBackgroundColor' => BackgroundService::DEFAULT_BACKGROUND_COLOR,
6772
'backgroundMime' => $this->config->getAppValue(Application::APP_ID, 'backgroundMime', ''),
6873
'logoheaderMime' => $this->config->getAppValue(Application::APP_ID, 'logoheaderMime', ''),
6974
'faviconMime' => $this->config->getAppValue(Application::APP_ID, 'faviconMime', ''),
7075
'legalNoticeUrl' => $this->themingDefaults->getImprintUrl(),
7176
'privacyPolicyUrl' => $this->themingDefaults->getPrivacyUrl(),
72-
'docUrl' => $this->urlGenerator->linkToDocs('admin-theming'),
73-
'docUrlIcons' => $this->urlGenerator->linkToDocs('admin-theming-icons'),
74-
'canThemeIcons' => $this->imageManager->shouldReplaceIcons(),
75-
'userThemingDisabled' => $this->themingDefaults->isUserThemingDisabled(),
77+
'disableUserTheming' => $this->themingDefaults->isUserThemingDisabled(),
7678
'defaultApps' => $this->navigationManager->getDefaultEntryIds(),
7779
]);
7880

79-
Util::addScript($this->appName, 'admin-theming');
80-
81-
return new TemplateResponse($this->appName, 'settings-admin');
81+
Util::addStyle(Application::APP_ID, 'settings-admin');
82+
Util::addScript(Application::APP_ID, 'settings-admin');
83+
return new TemplateResponse(Application::APP_ID, 'settings-admin');
8284
}
8385

8486
/**
8587
* @return string the section ID, e.g. 'sharing'
8688
*/
8789
public function getSection(): string {
88-
return $this->appName;
90+
return Application::APP_ID;
8991
}
9092

9193
/**
@@ -105,7 +107,7 @@ public function getName(): ?string {
105107

106108
public function getAuthorizedAppConfig(): array {
107109
return [
108-
$this->appName => '/.*/',
110+
Application::APP_ID => '/.*/',
109111
];
110112
}
111113
}

apps/theming/lib/Settings/Personal.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77
namespace OCA\Theming\Settings;
88

9+
use OCA\Theming\AppInfo\Application;
910
use OCA\Theming\ITheme;
1011
use OCA\Theming\Service\BackgroundService;
1112
use OCA\Theming\Service\ThemesService;
@@ -20,7 +21,6 @@
2021
class Personal implements ISettings {
2122

2223
public function __construct(
23-
protected string $appName,
2424
private string $userId,
2525
private IConfig $config,
2626
private ThemesService $themesService,
@@ -82,17 +82,17 @@ public function getForm(): TemplateResponse {
8282
'enforcedDefaultApp' => $forcedDefaultEntry
8383
]);
8484

85-
Util::addScript($this->appName, 'personal-theming');
86-
87-
return new TemplateResponse($this->appName, 'settings-personal');
85+
Util::addStyle(Application::APP_ID, 'settings-personal');
86+
Util::addScript(Application::APP_ID, 'settings-personal');
87+
return new TemplateResponse(Application::APP_ID, 'settings-personal');
8888
}
8989

9090
/**
9191
* @return string the section ID, e.g. 'sharing'
9292
* @since 9.1
9393
*/
9494
public function getSection(): string {
95-
return $this->appName;
95+
return Application::APP_ID;
9696
}
9797

9898
/**

apps/theming/lib/Settings/PersonalSection.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77
namespace OCA\Theming\Settings;
88

9+
use OCA\Theming\AppInfo\Application;
910
use OCP\IL10N;
1011
use OCP\IURLGenerator;
1112
use OCP\Settings\IIconSection;
@@ -20,7 +21,6 @@ class PersonalSection implements IIconSection {
2021
* @param IL10N $l
2122
*/
2223
public function __construct(
23-
protected string $appName,
2424
private IURLGenerator $urlGenerator,
2525
private IL10N $l,
2626
) {
@@ -34,7 +34,7 @@ public function __construct(
3434
* @since 13.0.0
3535
*/
3636
public function getIcon() {
37-
return $this->urlGenerator->imagePath($this->appName, 'accessibility-dark.svg');
37+
return $this->urlGenerator->imagePath(Application::APP_ID, 'accessibility-dark.svg');
3838
}
3939

4040
/**
@@ -45,7 +45,7 @@ public function getIcon() {
4545
* @since 9.1
4646
*/
4747
public function getID() {
48-
return $this->appName;
48+
return Application::APP_ID;
4949
}
5050

5151
/**

0 commit comments

Comments
 (0)