Skip to content

Commit a8ce269

Browse files
committed
Remake website property saving with Vue
Signed-off-by: Christopher Ng <[email protected]>
1 parent 38d0419 commit a8ce269

File tree

9 files changed

+87
-51
lines changed

9 files changed

+87
-51
lines changed

apps/settings/js/federationsettingsview.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@
131131
field === 'avatar' ||
132132
field === 'email' ||
133133
field === 'displayname' ||
134-
field === 'twitter'
134+
field === 'twitter' ||
135+
field === 'website'
135136
) {
136137
return;
137138
}

apps/settings/lib/Settings/Personal/PersonalInfo.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,6 @@ public function getForm(): TemplateResponse {
151151
'phoneScope' => $account->getProperty(IAccountManager::PROPERTY_PHONE)->getScope(),
152152
'address' => $account->getProperty(IAccountManager::PROPERTY_ADDRESS)->getValue(),
153153
'addressScope' => $account->getProperty(IAccountManager::PROPERTY_ADDRESS)->getScope(),
154-
'website' => $account->getProperty(IAccountManager::PROPERTY_WEBSITE)->getValue(),
155-
'websiteScope' => $account->getProperty(IAccountManager::PROPERTY_WEBSITE)->getScope(),
156-
'websiteVerification' => $account->getProperty(IAccountManager::PROPERTY_WEBSITE)->getVerified(),
157154
'groups' => $this->getGroups($user),
158155
'isFairUseOfFreePushService' => $this->isFairUseOfFreePushService(),
159156
'profileEnabledGlobally' => $this->profileManager->isProfileEnabled(),
@@ -162,6 +159,7 @@ public function getForm(): TemplateResponse {
162159
$personalInfoParameters = [
163160
'userId' => $uid,
164161
'displayName' => $this->getProperty($account, IAccountManager::PROPERTY_DISPLAYNAME),
162+
'website' => $this->getProperty($account, IAccountManager::PROPERTY_WEBSITE),
165163
'twitter' => $this->getProperty($account, IAccountManager::PROPERTY_TWITTER),
166164
'emailMap' => $this->getEmailMap($account),
167165
'languageMap' => $this->getLanguageMap($user),
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<!--
2+
- @copyright 2022 Christopher Ng <[email protected]>
3+
-
4+
- @author Christopher Ng <[email protected]>
5+
-
6+
- @license AGPL-3.0-or-later
7+
-
8+
- This program is free software: you can redistribute it and/or modify
9+
- it under the terms of the GNU Affero General Public License as
10+
- published by the Free Software Foundation, either version 3 of the
11+
- License, or (at your option) any later version.
12+
-
13+
- This program is distributed in the hope that it will be useful,
14+
- but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
- GNU Affero General Public License for more details.
17+
-
18+
- You should have received a copy of the GNU Affero General Public License
19+
- along with this program. If not, see <http://www.gnu.org/licenses/>.
20+
-
21+
-->
22+
23+
<template>
24+
<AccountPropertySection v-bind.sync="website"
25+
:placeholder="t('settings', 'Your website')"
26+
type="url"
27+
:on-validate="onValidate" />
28+
</template>
29+
30+
<script>
31+
import { loadState } from '@nextcloud/initial-state'
32+
33+
import AccountPropertySection from './shared/AccountPropertySection.vue'
34+
35+
import { NAME_READABLE_ENUM } from '../../constants/AccountPropertyConstants.js'
36+
import { validateUrl } from '../../utils/validate.js'
37+
38+
const { website } = loadState('settings', 'personalInfoParameters', {})
39+
40+
export default {
41+
name: 'WebsiteSection',
42+
43+
components: {
44+
AccountPropertySection,
45+
},
46+
47+
data() {
48+
return {
49+
website: { ...website, readable: NAME_READABLE_ENUM[website.name] },
50+
}
51+
},
52+
53+
methods: {
54+
onValidate(value) {
55+
return validateUrl(value)
56+
},
57+
},
58+
}
59+
</script>

apps/settings/src/main-personal-info.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import '@nextcloud/dialogs/styles/toast.scss'
2828

2929
import DisplayNameSection from './components/PersonalInfo/DisplayNameSection.vue'
3030
import EmailSection from './components/PersonalInfo/EmailSection/EmailSection.vue'
31+
import WebsiteSection from './components/PersonalInfo/WebsiteSection.vue'
3132
import TwitterSection from './components/PersonalInfo/TwitterSection.vue'
3233
import LanguageSection from './components/PersonalInfo/LanguageSection/LanguageSection.vue'
3334
import ProfileSection from './components/PersonalInfo/ProfileSection/ProfileSection.vue'
@@ -49,11 +50,13 @@ Vue.mixin({
4950

5051
const DisplayNameView = Vue.extend(DisplayNameSection)
5152
const EmailView = Vue.extend(EmailSection)
53+
const WebsiteView = Vue.extend(WebsiteSection)
5254
const TwitterView = Vue.extend(TwitterSection)
5355
const LanguageView = Vue.extend(LanguageSection)
5456

5557
new DisplayNameView().$mount('#vue-displayname-section')
5658
new EmailView().$mount('#vue-email-section')
59+
new WebsiteView().$mount('#vue-website-section')
5760
new TwitterView().$mount('#vue-twitter-section')
5861
new LanguageView().$mount('#vue-language-section')
5962

apps/settings/src/utils/validate.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* TODO add nice validation errors for Profile page settings modal
2727
*/
2828

29-
import { VALIDATE_EMAIL_REGEX } from '../constants/AccountPropertyConstants'
29+
import { VALIDATE_EMAIL_REGEX } from '../constants/AccountPropertyConstants.js'
3030

3131
/**
3232
* Validate the email input
@@ -46,6 +46,22 @@ export function validateEmail(input) {
4646
&& encodeURIComponent(input).replace(/%../g, 'x').length <= 320
4747
}
4848

49+
/**
50+
* Validate the URL input
51+
*
52+
* @param {string} input the input
53+
* @return {boolean}
54+
*/
55+
export function validateUrl(input) {
56+
try {
57+
// eslint-disable-next-line no-new
58+
new URL(input)
59+
return true
60+
} catch (e) {
61+
return false
62+
}
63+
}
64+
4965
/**
5066
* Validate the language input
5167
*

apps/settings/templates/settings/personal/personal.info.php

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -152,48 +152,7 @@
152152
</form>
153153
</div>
154154
<div class="personal-settings-setting-box">
155-
<form id="websiteform" class="section">
156-
<h3>
157-
<label for="website"><?php p($l->t('Website')); ?></label>
158-
<a href="#" class="federation-menu" aria-label="<?php p($l->t('Change privacy level of website')); ?>">
159-
<span class="icon-federation-menu icon-password">
160-
<span class="icon-triangle-s"></span>
161-
</span>
162-
</a>
163-
</h3>
164-
<?php if ($_['lookupServerUploadEnabled']) { ?>
165-
<div class="verify <?php if ($_['website'] === '' || $_['websiteScope'] !== 'public') {
166-
p('hidden');
167-
} ?>">
168-
<img id="verify-website" title="<?php p($_['websiteMessage']); ?>" data-status="<?php p($_['websiteVerification']) ?>" src="
169-
<?php
170-
switch ($_['websiteVerification']) {
171-
case \OC\Accounts\AccountManager::VERIFICATION_IN_PROGRESS:
172-
p(image_path('core', 'actions/verifying.svg'));
173-
break;
174-
case \OC\Accounts\AccountManager::VERIFIED:
175-
p(image_path('core', 'actions/verified.svg'));
176-
break;
177-
default:
178-
p(image_path('core', 'actions/verify.svg'));
179-
}
180-
?>" <?php if ($_['websiteVerification'] === \OC\Accounts\AccountManager::VERIFICATION_IN_PROGRESS || $_['websiteVerification'] === \OC\Accounts\AccountManager::NOT_VERIFIED) {
181-
print_unescaped(' class="verify-action"');
182-
} ?>>
183-
<div class="verification-dialog popovermenu bubble menu">
184-
<div class="verification-dialog-content">
185-
<p class="explainVerification"></p>
186-
<p class="verificationCode"></p>
187-
<p><?php p($l->t('It can take up to 24 hours before the account is displayed as verified.')); ?></p>
188-
</div>
189-
</div>
190-
</div>
191-
<?php } ?>
192-
<input type="url" name="website" id="website" value="<?php p($_['website']); ?>" placeholder="<?php p($l->t('Link https://…')); ?>" autocomplete="on" autocapitalize="none" autocorrect="off" />
193-
<span class="icon-checkmark hidden"></span>
194-
<span class="icon-error hidden"></span>
195-
<input type="hidden" id="websitescope" value="<?php p($_['websiteScope']) ?>">
196-
</form>
155+
<div id="vue-website-section"></div>
197156
</div>
198157
<div class="personal-settings-setting-box">
199158
<div id="vue-twitter-section"></div>

dist/settings-vue-settings-admin-basic-settings.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.

dist/settings-vue-settings-personal-info.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.

dist/settings-vue-settings-personal-info.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.

0 commit comments

Comments
 (0)