Skip to content

Commit 6bd8afd

Browse files
Merge pull request #763 from nextcloud/bugfix/631/allow-changing-the-settings-from-ui
Allow changing the settings from UI
2 parents a4db5f7 + bec4acf commit 6bd8afd

File tree

10 files changed

+128
-75
lines changed

10 files changed

+128
-75
lines changed

js/terms_of_service-admin.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/terms_of_service-admin.js.LICENSE.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@
6565
* @license MIT, https://github.com/focus-trap/tabbable/blob/master/LICENSE
6666
*/
6767

68+
/*! For license information please see NcCheckboxRadioSwitch.js.LICENSE.txt */
69+
6870
/*! For license information please see NcMultiselect.js.LICENSE.txt */
6971

7072
/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */

js/terms_of_service-admin.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/Controller/TermsController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ public function getAdminFormData(): JSONResponse {
105105
'terms' => $this->termsMapper->getTerms(),
106106
'countries' => $this->countryMapper->getCountries(),
107107
'languages' => $this->languageMapper->getLanguages(),
108+
'tos_on_public_shares' => $this->config->getAppValue(Application::APPNAME, 'tos_on_public_shares', '0'),
109+
'tos_for_users' => $this->config->getAppValue(Application::APPNAME, 'tos_for_users', '1'),
108110
];
109111
return new JSONResponse($response);
110112
}

lib/Settings/Admin.php

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<?php
2+
3+
declare(strict_types=1);
4+
25
/**
36
* @copyright Copyright (c) 2017 Lukas Reschke <[email protected]>
47
*
@@ -21,35 +24,15 @@
2124

2225
namespace OCA\TermsOfService\Settings;
2326

24-
use OCA\TermsOfService\Db\Mapper\CountryMapper;
25-
use OCA\TermsOfService\Db\Mapper\LanguageMapper;
2627
use OCP\AppFramework\Http\TemplateResponse;
2728
use OCP\Settings\ISettings;
2829

2930
class Admin implements ISettings {
30-
/** @var CountryMapper */
31-
private $countryMapper;
32-
/** @var LanguageMapper */
33-
private $languageMapper;
34-
35-
public function __construct(CountryMapper $countryMapper,
36-
LanguageMapper $languageMapper) {
37-
$this->countryMapper = $countryMapper;
38-
$this->languageMapper = $languageMapper;
39-
}
40-
4131
/**
4232
* {@inheritdoc}
4333
*/
4434
public function getForm(): TemplateResponse {
45-
return new TemplateResponse(
46-
'terms_of_service',
47-
'settings',
48-
[
49-
'countries' => $this->countryMapper->getCountries(),
50-
'languages' => $this->languageMapper->getLanguages(),
51-
],
52-
''
35+
return new TemplateResponse('terms_of_service', 'settings', [], TemplateResponse::RENDER_AS_BLANK
5336
);
5437
}
5538

lib/Settings/AdminSection.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<?php
2+
3+
declare(strict_types=1);
4+
25
/**
36
* @copyright Copyright (c) 2016 Bjoern Schiessle <[email protected]>
47
*
@@ -19,20 +22,15 @@
1922
*
2023
*/
2124

22-
2325
namespace OCA\TermsOfService\Settings;
2426

25-
2627
use OCP\IL10N;
2728
use OCP\IURLGenerator;
2829
use OCP\Settings\IIconSection;
2930

3031
class AdminSection implements IIconSection {
31-
32-
/** @var IL10N */
33-
private $l;
34-
/** @var IURLGenerator */
35-
private $url;
32+
private IL10N $l;
33+
private IURLGenerator $url;
3634

3735
public function __construct(IL10N $l, IURLGenerator $url) {
3836
$this->l = $l;

package-lock.json

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"@nextcloud/router": "^2.0.0",
2121
"@nextcloud/vue": "^7.0.1",
2222
"vue": "^2.7.13",
23+
"vue-frag": "^1.4.1",
2324
"vue-material-design-icons": "^5.1.2"
2425
},
2526
"browserslist": [

src/App.vue

Lines changed: 85 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -22,58 +22,69 @@
2222
-->
2323

2424
<template>
25-
<NcSettingsSection :title="t('terms_of_service', 'Terms of service')"
26-
:description="t('terms_of_service', 'Require users to accept the terms of service before accessing the service.')">
27-
<p class="settings-hint">
28-
{{ t('terms_of_service', 'For formatting purposes Markdown is supported.') }}
29-
</p>
30-
31-
<span>
32-
<NcMultiselect v-model="country"
33-
:options="countryOptions"
34-
:placeholder="t('terms_of_service', 'Select a region')"
35-
label="label"
36-
track-by="value" />
37-
<NcMultiselect v-model="language"
38-
:options="languageOptions"
39-
:placeholder="t('terms_of_service', 'Select a language')"
40-
label="label"
41-
track-by="value" />
42-
</span>
43-
44-
<textarea v-model="body"
45-
:placeholder="t('terms_of_service', 'By using this service …')"
46-
class="terms__textarea" />
47-
48-
<NcButton :disabled="saveButtonDisabled"
49-
@click="onSubmit">
50-
{{ saveButtonText }}
51-
</NcButton>
52-
53-
<template v-if="hasTerms">
54-
<h2>
55-
{{ t('terms_of_service', 'Existing terms of service') }}
56-
</h2>
25+
<Fragment>
26+
<NcSettingsSection :title="t('terms_of_service', 'Terms of service')"
27+
:description="t('terms_of_service', 'Require users to accept the terms of service before accessing the service.')">
28+
<NcCheckboxRadioSwitch type="switch"
29+
:checked.sync="showForLoggedInUser">
30+
{{ t('terms_of_service', 'Show for logged-in users') }}
31+
</NcCheckboxRadioSwitch>
32+
33+
<NcCheckboxRadioSwitch type="switch"
34+
:checked.sync="showOnPublicShares">
35+
{{ t('terms_of_service', 'Show on public shares') }}
36+
</NcCheckboxRadioSwitch>
37+
38+
<span class="form">
39+
<NcMultiselect v-model="country"
40+
:options="countryOptions"
41+
:placeholder="t('terms_of_service', 'Select a region')"
42+
label="label"
43+
track-by="value" />
44+
<NcMultiselect v-model="language"
45+
:options="languageOptions"
46+
:placeholder="t('terms_of_service', 'Select a language')"
47+
label="label"
48+
track-by="value" />
49+
</span>
50+
51+
<textarea v-model="body"
52+
:placeholder="t('terms_of_service', 'By using this service …')"
53+
class="terms__textarea" />
54+
55+
<p class="settings-hint">
56+
{{ t('terms_of_service', 'For formatting purposes Markdown is supported.') }}
57+
</p>
58+
59+
<NcButton :disabled="saveButtonDisabled"
60+
@click="onSubmit">
61+
{{ saveButtonText }}
62+
</NcButton>
63+
</NcSettingsSection>
5764

65+
<NcSettingsSection v-if="hasTerms"
66+
:title="t('terms_of_service', 'Existing terms of service')">
5867
<NcButton :disabled="resetButtonDisabled"
5968
type="error"
6069
@click="onResetSignatories">
6170
{{ resetButtonText }}
6271
</NcButton>
6372

64-
<ul v-if="hasTerms" id="terms_of_service-countryspecific-list">
73+
<ul v-if="hasTerms">
6574
<Term v-for="term in terms"
6675
:key="term.id"
6776
v-bind="term" />
6877
</ul>
69-
</template>
70-
</NcSettingsSection>
78+
</NcSettingsSection>
79+
</Fragment>
7180
</template>
7281

7382
<script>
83+
import { Fragment } from 'vue-frag'
7484
import Term from './components/Term.vue'
7585
import axios from '@nextcloud/axios'
7686
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
87+
import NcCheckboxRadioSwitch from '@nextcloud/vue/dist/Components/NcCheckboxRadioSwitch.js'
7788
import NcMultiselect from '@nextcloud/vue/dist/Components/NcMultiselect.js'
7889
import NcSettingsSection from '@nextcloud/vue/dist/Components/NcSettingsSection.js'
7990
import { showError, showSuccess } from '@nextcloud/dialogs'
@@ -85,7 +96,9 @@ export default {
8596
8697
components: {
8798
Term,
99+
Fragment,
88100
NcButton,
101+
NcCheckboxRadioSwitch,
89102
NcMultiselect,
90103
NcSettingsSection,
91104
},
@@ -104,6 +117,8 @@ export default {
104117
saveButtonDisabled: true,
105118
resetButtonText: '',
106119
resetButtonDisabled: false,
120+
showOnPublicShares: false,
121+
showForLoggedInUser: true,
107122
}
108123
},
109124
@@ -113,6 +128,27 @@ export default {
113128
},
114129
},
115130
131+
watch: {
132+
showOnPublicShares(value) {
133+
if (!this.saveButtonDisabled) {
134+
OCP.AppConfig.setValue(
135+
'terms_of_service',
136+
'tos_on_public_shares',
137+
value ? '1' : '0'
138+
)
139+
}
140+
},
141+
showForLoggedInUser(value) {
142+
if (!this.saveButtonDisabled) {
143+
OCP.AppConfig.setValue(
144+
'terms_of_service',
145+
'tos_for_users',
146+
value ? '1' : '0'
147+
)
148+
}
149+
},
150+
},
151+
116152
mounted() {
117153
this.saveButtonText = t('terms_of_service', 'Loading …')
118154
this.resetButtonText = t('terms_of_service', 'Reset all signatories')
@@ -124,6 +160,8 @@ export default {
124160
}
125161
this.countries = response.data.countries
126162
this.languages = response.data.languages
163+
this.showOnPublicShares = response.data.tos_on_public_shares === '1'
164+
this.showForLoggedInUser = response.data.tos_for_users === '1'
127165
Object.keys(this.countries).forEach((countryCode) => {
128166
this.countryOptions.push({
129167
value: countryCode,
@@ -138,7 +176,9 @@ export default {
138176
})
139177
140178
this.saveButtonText = t('terms_of_service', 'Save')
141-
this.saveButtonDisabled = false
179+
this.$nextTick(() => {
180+
this.saveButtonDisabled = false
181+
})
142182
})
143183
},
144184
@@ -185,6 +225,15 @@ export default {
185225
display: block;
186226
}
187227
228+
.form {
229+
margin-top: 30px;
230+
display: block;
231+
}
232+
233+
.settings-hint {
234+
margin-top: 0;
235+
}
236+
188237
label span {
189238
display: inline-block;
190239
min-width: 120px;

src/components/Term.vue

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ export default {
7070
7171
computed: {
7272
country() {
73-
return this.$parent.$parent.countries[this.countryCode]
73+
return this.$parent.$parent.$parent.countries[this.countryCode]
7474
},
7575
7676
language() {
77-
return this.$parent.$parent.languages[this.languageCode]
77+
return this.$parent.$parent.$parent.languages[this.languageCode]
7878
},
7979
8080
editButtonLabel() {
@@ -92,23 +92,23 @@ export default {
9292
9393
methods: {
9494
onEdit() {
95-
this.$parent.$parent.country = {
95+
this.$parent.$parent.$parent.country = {
9696
value: this.countryCode,
97-
label: this.$parent.$parent.countries[this.countryCode] + ' (' + this.countryCode + ')',
97+
label: this.$parent.$parent.$parent.countries[this.countryCode] + ' (' + this.countryCode + ')',
9898
}
99-
this.$parent.$parent.language = {
99+
this.$parent.$parent.$parent.language = {
100100
value: this.languageCode,
101-
label: this.$parent.$parent.languages[this.languageCode] + ' (' + this.languageCode + ')',
101+
label: this.$parent.$parent.$parent.languages[this.languageCode] + ' (' + this.languageCode + ')',
102102
}
103-
this.$parent.$parent.body = this.body
103+
this.$parent.$parent.$parent.body = this.body
104104
},
105105
106106
onDelete() {
107107
this.deleteButtonDisabled = true
108108
axios
109109
.delete(generateUrl('/apps/terms_of_service/terms/' + this.id))
110110
.then(() => {
111-
this.$delete(this.$parent.$parent.terms, this.id)
111+
this.$delete(this.$parent.$parent.$parent.terms, this.id)
112112
})
113113
},
114114
},

0 commit comments

Comments
 (0)