mirror of
https://github.com/chenasraf/cospend-nc.git
synced 2026-05-17 17:38:10 +00:00
add admin settings
Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
This commit is contained in:
@@ -27,6 +27,9 @@
|
||||
<job>OCA\Cospend\Cron\RepeatBills</job>
|
||||
<job>OCA\Cospend\Cron\AutoExport</job>
|
||||
</background-jobs>
|
||||
<settings>
|
||||
<admin>OCA\Cospend\Settings\Admin</admin>
|
||||
</settings>
|
||||
<commands>
|
||||
<command>OCA\Cospend\Command\RepeatBills</command>
|
||||
<command>OCA\Cospend\Command\ExportProject</command>
|
||||
|
||||
35
lib/Settings/Admin.php
Normal file
35
lib/Settings/Admin.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace OCA\Cospend\Settings;
|
||||
|
||||
use OCA\Cospend\AppInfo\Application;
|
||||
use OCP\AppFramework\Http\TemplateResponse;
|
||||
use OCP\AppFramework\Services\IInitialState;
|
||||
use OCP\IConfig;
|
||||
use OCP\Settings\ISettings;
|
||||
|
||||
class Admin implements ISettings {
|
||||
public function __construct(
|
||||
private IInitialState $initialStateService,
|
||||
private IConfig $config,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return TemplateResponse
|
||||
*/
|
||||
public function getForm(): TemplateResponse {
|
||||
$federationEnabled = $this->config->getAppValue('cospend', 'federation_enabled', '0') === '1';
|
||||
$this->initialStateService->provideInitialState('federation_enabled', $federationEnabled);
|
||||
|
||||
return new TemplateResponse(Application::APP_ID, 'adminSettings');
|
||||
}
|
||||
|
||||
public function getSection(): string {
|
||||
return 'additional';
|
||||
}
|
||||
|
||||
public function getPriority(): int {
|
||||
return 10;
|
||||
}
|
||||
}
|
||||
17
src/adminSettings.js
Normal file
17
src/adminSettings.js
Normal file
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* Nextcloud - Cospend
|
||||
*
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later. See the COPYING file.
|
||||
*
|
||||
* @author Julien Veyssier <julien-nc@posteo.net>
|
||||
* @copyright Julien Veyssier 2024
|
||||
*/
|
||||
|
||||
import Vue from 'vue'
|
||||
import AdminSettings from './views/AdminSettings.vue'
|
||||
Vue.mixin({ methods: { t, n } })
|
||||
|
||||
const View = Vue.extend(AdminSettings)
|
||||
new View().$mount('#cospend_prefs')
|
||||
81
src/views/AdminSettings.vue
Normal file
81
src/views/AdminSettings.vue
Normal file
@@ -0,0 +1,81 @@
|
||||
<template>
|
||||
<div id="cospend_prefs" class="section">
|
||||
<h2>
|
||||
<CospendIcon class="icon" />
|
||||
{{ t('cospend', 'Cospend') }}
|
||||
</h2>
|
||||
<div id="cospend-content">
|
||||
<div>
|
||||
<NcCheckboxRadioSwitch :checked="isFederationEnabled"
|
||||
:disabled="loading"
|
||||
type="switch"
|
||||
@update:checked="saveFederationEnabled">
|
||||
{{ t('cospend', 'Enable Federation in Cospend') }}
|
||||
</NcCheckboxRadioSwitch>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import CospendIcon from '../components/icons/CospendIcon.vue'
|
||||
|
||||
import NcCheckboxRadioSwitch from '@nextcloud/vue/dist/Components/NcCheckboxRadioSwitch.js'
|
||||
|
||||
import { loadState } from '@nextcloud/initial-state'
|
||||
|
||||
const FEDERATION_ENABLED = loadState('cospend', 'federation_enabled', false)
|
||||
|
||||
export default {
|
||||
name: 'AdminSettings',
|
||||
|
||||
components: {
|
||||
CospendIcon,
|
||||
NcCheckboxRadioSwitch,
|
||||
},
|
||||
|
||||
data() {
|
||||
return {
|
||||
isFederationEnabled: FEDERATION_ENABLED,
|
||||
loading: false,
|
||||
}
|
||||
},
|
||||
|
||||
computed: {
|
||||
},
|
||||
|
||||
created() {
|
||||
},
|
||||
|
||||
mounted() {
|
||||
},
|
||||
|
||||
methods: {
|
||||
saveFederationEnabled(value) {
|
||||
this.loading = true
|
||||
OCP.AppConfig.setValue('cospend', 'federation_enabled', value ? '1' : '0', {
|
||||
success: () => {
|
||||
this.loading = false
|
||||
this.isFederationEnabled = value
|
||||
},
|
||||
})
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
#cospend_prefs {
|
||||
#cospend-content {
|
||||
margin-left: 40px;
|
||||
}
|
||||
|
||||
h2 {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
.icon {
|
||||
margin-right: 8px;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
6
templates/adminSettings.php
Normal file
6
templates/adminSettings.php
Normal file
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
$appId = OCA\Cospend\AppInfo\Application::APP_ID;
|
||||
\OCP\Util::addScript($appId, $appId . '-adminSettings');
|
||||
?>
|
||||
|
||||
<div id="cospend_prefs"></div>
|
||||
@@ -18,6 +18,7 @@ webpackConfig.entry = {
|
||||
main: { import: path.join(__dirname, 'src', 'main.js'), filename: appId + '-main.js' },
|
||||
sharePassword: { import: path.join(__dirname, 'src', 'sharePassword.js'), filename: appId + '-sharePassword.js' },
|
||||
dashboard: { import: path.join(__dirname, 'src', 'dashboard.js'), filename: appId + '-dashboard.js' },
|
||||
adminSettings: { import: path.join(__dirname, 'src', 'adminSettings.js'), filename: appId + '-adminSettings.js' },
|
||||
}
|
||||
|
||||
webpackConfig.plugins.push(
|
||||
|
||||
Reference in New Issue
Block a user