Skip to content

Commit 3bbd884

Browse files
artongeAndyScherzinger
authored andcommitted
feat(Settings): Add section to select preset
Signed-off-by: Louis Chemineau <louis@chmn.me>
1 parent a963504 commit 3bbd884

15 files changed

Lines changed: 512 additions & 4 deletions

File tree

REUSE.toml

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

apps/settings/appinfo/info.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
<settings>
3030
<admin>OCA\Settings\Settings\Admin\Mail</admin>
3131
<admin>OCA\Settings\Settings\Admin\Overview</admin>
32+
<admin>OCA\Settings\Settings\Admin\Presets</admin>
3233
<admin>OCA\Settings\Settings\Admin\ArtificialIntelligence</admin>
3334
<admin>OCA\Settings\Settings\Admin\Server</admin>
3435
<admin>OCA\Settings\Settings\Admin\Sharing</admin>
@@ -39,6 +40,7 @@
3940
<admin-section>OCA\Settings\Sections\Admin\Delegation</admin-section>
4041
<admin-section>OCA\Settings\Sections\Admin\Groupware</admin-section>
4142
<admin-section>OCA\Settings\Sections\Admin\Overview</admin-section>
43+
<admin-section>OCA\Settings\Sections\Admin\Presets</admin-section>
4244
<admin-section>OCA\Settings\Sections\Admin\ArtificialIntelligence</admin-section>
4345
<admin-section>OCA\Settings\Sections\Admin\Security</admin-section>
4446
<admin-section>OCA\Settings\Sections\Admin\Server</admin-section>

apps/settings/composer/composer/autoload_classmap.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
'OCA\\Settings\\Sections\\Admin\\Delegation' => $baseDir . '/../lib/Sections/Admin/Delegation.php',
5656
'OCA\\Settings\\Sections\\Admin\\Groupware' => $baseDir . '/../lib/Sections/Admin/Groupware.php',
5757
'OCA\\Settings\\Sections\\Admin\\Overview' => $baseDir . '/../lib/Sections/Admin/Overview.php',
58+
'OCA\\Settings\\Sections\\Admin\\Presets' => $baseDir . '/../lib/Sections/Admin/Presets.php',
5859
'OCA\\Settings\\Sections\\Admin\\Security' => $baseDir . '/../lib/Sections/Admin/Security.php',
5960
'OCA\\Settings\\Sections\\Admin\\Server' => $baseDir . '/../lib/Sections/Admin/Server.php',
6061
'OCA\\Settings\\Sections\\Admin\\Sharing' => $baseDir . '/../lib/Sections/Admin/Sharing.php',
@@ -71,6 +72,7 @@
7172
'OCA\\Settings\\Settings\\Admin\\Mail' => $baseDir . '/../lib/Settings/Admin/Mail.php',
7273
'OCA\\Settings\\Settings\\Admin\\MailProvider' => $baseDir . '/../lib/Settings/Admin/MailProvider.php',
7374
'OCA\\Settings\\Settings\\Admin\\Overview' => $baseDir . '/../lib/Settings/Admin/Overview.php',
75+
'OCA\\Settings\\Settings\\Admin\\Presets' => $baseDir . '/../lib/Settings/Admin/Presets.php',
7476
'OCA\\Settings\\Settings\\Admin\\Security' => $baseDir . '/../lib/Settings/Admin/Security.php',
7577
'OCA\\Settings\\Settings\\Admin\\Server' => $baseDir . '/../lib/Settings/Admin/Server.php',
7678
'OCA\\Settings\\Settings\\Admin\\Sharing' => $baseDir . '/../lib/Settings/Admin/Sharing.php',

apps/settings/composer/composer/autoload_static.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class ComposerStaticInitSettings
7070
'OCA\\Settings\\Sections\\Admin\\Delegation' => __DIR__ . '/..' . '/../lib/Sections/Admin/Delegation.php',
7171
'OCA\\Settings\\Sections\\Admin\\Groupware' => __DIR__ . '/..' . '/../lib/Sections/Admin/Groupware.php',
7272
'OCA\\Settings\\Sections\\Admin\\Overview' => __DIR__ . '/..' . '/../lib/Sections/Admin/Overview.php',
73+
'OCA\\Settings\\Sections\\Admin\\Presets' => __DIR__ . '/..' . '/../lib/Sections/Admin/Presets.php',
7374
'OCA\\Settings\\Sections\\Admin\\Security' => __DIR__ . '/..' . '/../lib/Sections/Admin/Security.php',
7475
'OCA\\Settings\\Sections\\Admin\\Server' => __DIR__ . '/..' . '/../lib/Sections/Admin/Server.php',
7576
'OCA\\Settings\\Sections\\Admin\\Sharing' => __DIR__ . '/..' . '/../lib/Sections/Admin/Sharing.php',
@@ -86,6 +87,7 @@ class ComposerStaticInitSettings
8687
'OCA\\Settings\\Settings\\Admin\\Mail' => __DIR__ . '/..' . '/../lib/Settings/Admin/Mail.php',
8788
'OCA\\Settings\\Settings\\Admin\\MailProvider' => __DIR__ . '/..' . '/../lib/Settings/Admin/MailProvider.php',
8889
'OCA\\Settings\\Settings\\Admin\\Overview' => __DIR__ . '/..' . '/../lib/Settings/Admin/Overview.php',
90+
'OCA\\Settings\\Settings\\Admin\\Presets' => __DIR__ . '/..' . '/../lib/Settings/Admin/Presets.php',
8991
'OCA\\Settings\\Settings\\Admin\\Security' => __DIR__ . '/..' . '/../lib/Settings/Admin/Security.php',
9092
'OCA\\Settings\\Settings\\Admin\\Server' => __DIR__ . '/..' . '/../lib/Settings/Admin/Server.php',
9193
'OCA\\Settings\\Settings\\Admin\\Sharing' => __DIR__ . '/..' . '/../lib/Settings/Admin/Sharing.php',
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
namespace OCA\Settings\Sections\Admin;
10+
11+
use OCP\IL10N;
12+
use OCP\IURLGenerator;
13+
use OCP\Settings\IIconSection;
14+
15+
class Presets implements IIconSection {
16+
17+
public function __construct(
18+
private IL10N $l,
19+
private IURLGenerator $urlGenerator,
20+
) {
21+
}
22+
23+
public function getIcon(): string {
24+
return $this->urlGenerator->imagePath('settings', 'library_add_check.svg');
25+
}
26+
27+
public function getID(): string {
28+
return 'presets';
29+
}
30+
31+
public function getName(): string {
32+
return $this->l->t('Settings presets');
33+
}
34+
35+
public function getPriority(): int {
36+
return 0;
37+
}
38+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
/**
4+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
5+
* SPDX-License-Identifier: AGPL-3.0-or-later
6+
*/
7+
namespace OCA\Settings\Settings\Admin;
8+
9+
use OC\Config\PresetManager;
10+
use OCP\AppFramework\Http\TemplateResponse;
11+
use OCP\AppFramework\Services\IInitialState;
12+
use OCP\IConfig;
13+
use OCP\IL10N;
14+
use OCP\ServerVersion;
15+
use OCP\Settings\ISettings;
16+
17+
class Presets implements ISettings {
18+
public function __construct(
19+
private ServerVersion $serverVersion,
20+
private IConfig $config,
21+
private IL10N $l,
22+
private readonly PresetManager $presetManager,
23+
private IInitialState $initialState,
24+
) {
25+
}
26+
27+
public function getForm() {
28+
$presets = $this->presetManager->retrieveLexiconPreset();
29+
$selectedPreset = $this->presetManager->getLexiconPreset();
30+
$presetsApps = $this->presetManager->retrieveLexiconPresetApps();
31+
32+
$this->initialState->provideInitialState('settings-selected-preset', $selectedPreset->name);
33+
$this->initialState->provideInitialState('settings-presets', $presets);
34+
$this->initialState->provideInitialState('settings-presets-apps', $presetsApps);
35+
36+
return new TemplateResponse('settings', 'settings/admin/presets', [], '');
37+
}
38+
39+
public function getSection() {
40+
return 'presets';
41+
}
42+
43+
public function getPriority() {
44+
return 0;
45+
}
46+
47+
public function getName(): ?string {
48+
return $this->l->t('Settings presets');
49+
}
50+
51+
public function getAuthorizedAppConfig(): array {
52+
return [];
53+
}
54+
}
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
<!--
2+
- SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
3+
- SPDX-License-Identifier: AGPL-3.0-or-later
4+
-->
5+
6+
<script setup lang="ts">
7+
import { computed } from 'vue'
8+
9+
import { t } from '@nextcloud/l10n'
10+
import { loadState } from '@nextcloud/initial-state'
11+
import NcCheckboxRadioSwitch from '@nextcloud/vue/components/NcCheckboxRadioSwitch'
12+
13+
import type { PresetAppConfig, PresetAppConfigs, PresetAppsStates, PresetIds } from './models.ts'
14+
15+
const applicationsStates = loadState('settings', 'settings-presets-apps', {}) as PresetAppsStates
16+
17+
const props = defineProps({
18+
presets: {
19+
type: Object as () => PresetAppConfigs,
20+
required: true,
21+
},
22+
selectedPreset: {
23+
type: String as () => PresetIds,
24+
default: 'NONE',
25+
},
26+
})
27+
28+
const appsConfigPresets = Object.entries(props.presets)
29+
.map(([appId, presets]) => [appId, presets.filter(configPreset => configPreset.config === 'app')])
30+
.filter(([, presets]) => presets.length > 0) as [string, PresetAppConfig[]][]
31+
const userConfigPresets = Object.entries(props.presets)
32+
.map(([appId, presets]) => [appId, presets.filter(configPreset => configPreset.config === 'user')])
33+
.filter(([, presets]) => presets.length > 0) as [string, PresetAppConfig[]][]
34+
35+
const hasApplicationsPreset = computed(() => applicationsStates[props.selectedPreset].enabled.length > 0 || applicationsStates[props.selectedPreset].disabled.length > 0)
36+
</script>
37+
38+
<template>
39+
<div class="presets">
40+
<h3 class="presets__title">
41+
{{ t('settings', 'Default config values') }}
42+
</h3>
43+
44+
<div v-if="appsConfigPresets.length > 0" class="presets__config-list">
45+
<h4 class="presets__config-list__subtitle">
46+
{{ t('settings', 'Applications config') }}
47+
</h4>
48+
<template v-for="[appId, appConfigPresets] in appsConfigPresets">
49+
<div v-for="configPreset in appConfigPresets"
50+
:key="appId + '-' + configPreset.entry.key"
51+
class="presets__config-list__item">
52+
<span>
53+
<div>{{ configPreset.entry.definition }}</div>
54+
<code class="presets__config-list__item__key">{{ configPreset.entry.key }}</code>
55+
</span>
56+
<span>
57+
<NcCheckboxRadioSwitch v-if="configPreset.entry.type === 'BOOL'"
58+
:model-value="configPreset.defaults[selectedPreset] === '1'"
59+
:disabled="true" />
60+
<code v-else>{{ configPreset.defaults[selectedPreset] }}</code>
61+
</span>
62+
</div>
63+
</template>
64+
</div>
65+
66+
<div v-if="userConfigPresets.length > 0" class="presets__config-list">
67+
<h4 class="presets__config-list__subtitle">
68+
{{ t('settings', 'User config') }}
69+
</h4>
70+
<template v-for="[appId, userPresets] in userConfigPresets">
71+
<div v-for="configPreset in userPresets"
72+
:key="appId + '-' + configPreset.entry.key"
73+
class="presets__config-list__item">
74+
<span>
75+
<div>{{ configPreset.entry.definition }}</div>
76+
<code class="presets__config-list__item__key">{{ configPreset.entry.key }}</code>
77+
</span>
78+
<span>
79+
<NcCheckboxRadioSwitch v-if="configPreset.entry.type === 'BOOL'"
80+
:model-value="configPreset.defaults[selectedPreset] === '1'"
81+
:disabled="true" />
82+
<code v-else>{{ configPreset.defaults[selectedPreset] }}</code>
83+
</span>
84+
</div>
85+
</template>
86+
</div>
87+
88+
<template v-if="hasApplicationsPreset">
89+
<h3 class="presets__title">
90+
{{ t('settings', 'Bundled applications') }}
91+
</h3>
92+
93+
<div class="presets__app-list">
94+
<div class="presets__app-list__enabled">
95+
<h4 class="presets__app-list__title">
96+
{{ t('settings', 'Enabled applications') }}
97+
</h4>
98+
<ul>
99+
<li v-for="applicationId in applicationsStates[selectedPreset].enabled"
100+
:key="applicationId">
101+
{{ applicationId }}
102+
</li>
103+
</ul>
104+
</div>
105+
<div class="presets__app-list__disabled">
106+
<h4 class="presets__app-list__title">
107+
{{ t('settings', 'Disabled applications') }}
108+
</h4>
109+
<ul>
110+
<li v-for="applicationId in applicationsStates[selectedPreset].disabled"
111+
:key="applicationId">
112+
{{ applicationId }}
113+
</li>
114+
</ul>
115+
</div>
116+
</div>
117+
</template>
118+
</div>
119+
</template>
120+
121+
<style lang="scss" scoped>
122+
.presets {
123+
margin-top: 16px;
124+
125+
&__title {
126+
font-size: 16px;
127+
margin-bottom: 0;
128+
}
129+
130+
&__config-list {
131+
margin-top: 8px;
132+
width: 55%;
133+
134+
&__subtitle {
135+
font-size: 14px;
136+
}
137+
138+
&__item {
139+
display: flex;
140+
justify-content: space-between;
141+
align-items: center;
142+
padding: 2px 0;
143+
144+
&__key {
145+
font-size: 12px;
146+
color: var(--color-text-maxcontrast);
147+
}
148+
}
149+
}
150+
151+
&__app-list {
152+
display: flex;
153+
gap: 32px;
154+
155+
&__title {
156+
font-size: 14px;
157+
}
158+
}
159+
}
160+
</style>

0 commit comments

Comments
 (0)