Skip to content

Commit 6c49d8e

Browse files
committed
Start Migration to Vue
Signed-off-by: Gary Kim <gary@garykim.dev>
1 parent 7fdb0ea commit 6c49d8e

15 files changed

Lines changed: 235 additions & 95 deletions

.editorconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@ indent_style = space
1515
[*.json]
1616
indent_size = 4
1717
indent_style = space
18+
19+
[*.vue]
20+
indent_size = 4
21+
indent_style = space

lib/AppInfo/Application.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ class Application extends App {
4747
'show_labs_settings' => 'true',
4848
'set_custom_permalink' => 'false',
4949
'sso_immediate_redirect' => 'false',
50+
51+
// Default is set in the OCA\RiotChat\Settings\ShareAdmin class
5052
'share_domain' => '',
5153
'share_prefix' => '',
5254
'share_suffix' => '',
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
use OCP\IUserSession;
3131
use OCP\Settings\ISettings;
3232

33-
class ElementAdmin implements ISettings {
33+
class Admin implements ISettings {
3434

3535
/** @var IConfig */
3636
private $config;
@@ -58,6 +58,7 @@ public function __construct(IConfig $config, IUserSession $user, IInitialStateSe
5858
*/
5959
public function getForm() {
6060
foreach (Application::AvailableSettings as $key => $default) {
61+
// TODO: Don't send non-Element related settings here
6162
$data = $this->config->getAppValue(Application::APP_ID, $key, $default);
6263
$this->initialStateService->provideInitialState(Application::APP_ID, $key, $data);
6364
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
use OCP\IURLGenerator;
2828
use OCP\Settings\IIconSection;
2929

30-
class ElementAdminSection implements IIconSection {
30+
class AdminSection implements IIconSection {
3131

3232
/** @var IURLGenerator */
3333
private $urlGenerator;

lib/Settings/Personal.php

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,16 @@
2222

2323
namespace OCA\RiotChat\Settings;
2424

25+
use OCA\RiotChat\AppInfo\Application;
2526
use OCP\AppFramework\Http\TemplateResponse;
2627
use OCP\IConfig;
2728
use OCP\Settings\ISettings;
2829

2930
class Personal implements ISettings {
30-
private $config;
31-
protected $appName;
3231

33-
public function __construct(
34-
string $appName,
35-
IConfig $config
36-
) {
37-
$this->appName = $appName;
38-
$this->config = $config;
39-
}
4032

4133
public function getForm() {
42-
$parameters = [
43-
'appName' => $this->appName,
44-
];
45-
return new TemplateResponse($this->appName, 'settings/personal', $parameters, '');
34+
return new TemplateResponse(Application::APP_ID, 'settings/personal');
4635
}
4736

4837
public function getSection() {

lib/Settings/ShareAdmin.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public function getForm() {
5252
$this->initialStateService->provideInitialState(Application::APP_ID, 'share_domain', $this->getAppValue('share_domain', $this->config->getSystemValue('trusted_domains')[0]));
5353
$this->initialStateService->provideInitialState(Application::APP_ID, 'share_prefix', $this->getAppValue('share_prefix'));
5454
$this->initialStateService->provideInitialState(Application::APP_ID, 'share_suffix', $this->getAppValue('share_suffix'));
55+
5556
return new TemplateResponse(Application::APP_ID, 'settings/share-admin');
5657
}
5758

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*/
2222

2323
import Vue from 'vue';
24-
import ElementAdminSettings from "./components/settings/ElementAdminSettings";
24+
import AdminSettings from "./components/settings/AdminSettings";
2525

2626
document.addEventListener('DOMContentLoaded', main);
2727

@@ -31,7 +31,7 @@ function main () {
3131
Vue.prototype.OC = window.OC;
3232
Vue.prototype.OCA = window.OCA;
3333

34-
const View = Vue.extend(ElementAdminSettings);
34+
const View = Vue.extend(AdminSettings);
3535
const view = new View();
36-
view.$mount('#riotchat-element-admin-settings');
36+
view.$mount('#riotchat-admin-settings');
3737
}
File renamed without changes.
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
<!--
2+
- @copyright Copyright (c) 2021 Sorunome <mail@sorunome.de>
3+
- @copyright Copyright (c) 2020-2021 Gary Kim <gary@garykim.dev>
4+
- @copyright Copyright (c) 2020 Samuel Llamzon
5+
-
6+
- @author Sorunome <mail@sorunome.de>
7+
-
8+
- @license GNU AGPL version 3 or any later version
9+
-
10+
- This program is free software: you can redistribute it and/or modify
11+
- it under the terms of the GNU Affero General Public License as
12+
- published by the Free Software Foundation, either version 3 of the
13+
- License, or (at your option) any later version.
14+
-
15+
- This program is distributed in the hope that it will be useful,
16+
- but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
- GNU Affero General Public License for more details.
19+
-
20+
- You should have received a copy of the GNU Affero General Public License
21+
- along with this program. If not, see <http://www.gnu.org/licenses/>.
22+
-
23+
-->
24+
25+
<template>
26+
<div class="section">
27+
<SettingsSection
28+
:title="t('riotchat', 'Matrix Login')"
29+
:description="t('riotchat', 'Log in to your Matrix Account')"
30+
>
31+
<form @submit="login">
32+
<label
33+
ref="matrix_username"
34+
for="matrix_username"
35+
>{{ t('riotchat', 'Matrix Username:') }}</label>
36+
<input
37+
id="matrix_username"
38+
v-model="matrix_username"
39+
type="text"
40+
>
41+
<br>
42+
<label
43+
ref="matrix_password"
44+
for="matrix_password"
45+
>{{ t('riotchat', 'Matrix Password:') }}</label>
46+
<input
47+
id="matrix_password"
48+
v-model="matrix_password"
49+
type="text"
50+
>
51+
<input type="submit" value="login">
52+
<br>
53+
</form>
54+
<template v-if="loggedIn">
55+
<p>{{ currentlyLoggedInMessage }}</p>
56+
<input type="button" @submit="logout">
57+
</template>
58+
</SettingsSection>
59+
</div>
60+
</template>
61+
62+
<script>
63+
import Axios from '@nextcloud/axios';
64+
import { showError, showSuccess } from '@nextcloud/dialogs';
65+
import { generateUrl } from '@nextcloud/router';
66+
import { loadState } from '@nextcloud/initial-state';
67+
import { SettingsSection, Tooltip } from '@nextcloud/vue';
68+
69+
export default {
70+
name: "PersonalSettings",
71+
components: {
72+
SettingsSection,
73+
},
74+
directives: {
75+
Tooltip,
76+
},
77+
data() {
78+
return {
79+
// Form inputs
80+
"matrix_username": "",
81+
"matrix_password": "",
82+
83+
// Data
84+
"loggedIn": false,
85+
"currentUsername": "",
86+
};
87+
},
88+
computed: {
89+
currentlyLoggedInMessage() {
90+
return this.t('riotchat', 'Currently logged in as {username}', {
91+
username: this.currentUsername,
92+
});
93+
}
94+
},
95+
methods: {
96+
login () {
97+
const url = generateUrl('apps/riotchat/share/login');
98+
Axios.post(
99+
url,
100+
{
101+
username: this.username,
102+
password: this.password,
103+
}
104+
).then(() => {
105+
showSuccess(t('riotchat', 'Successfully logged into Matrix account'));
106+
this.whoAmI();
107+
}).catch(() => {
108+
showSuccess(t('riotchat', 'Failed to login to Matrix account. Are your account details correct?'));
109+
});
110+
},
111+
logout () {
112+
const url = generateUrl('apps/riotchat/share/logout');
113+
Axios.post(url).then(this.whoAmI).catch(() => {
114+
showError(t('riotchat', 'Failed to logout of Matrix account.'));
115+
});
116+
},
117+
whoAmI () {
118+
const url = generateUrl('apps/riotchat/share/whoami');
119+
Axios.get(url).then((res) => {
120+
this.loggedIn = res.data.logged_in;
121+
this.currentUsername = res.data.user_id;
122+
}).catch(() => {
123+
showError(t('riotchat', 'Could not load user info. Please reload the page.'));
124+
});
125+
}
126+
},
127+
mounted () {
128+
this.whoAmI();
129+
},
130+
}
131+
</script>

src/components/settings/ShareAdminSettings.vue

Lines changed: 43 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!--
22
- @copyright Copyright (c) 2021 Sorunome <mail@sorunome.de>
3-
- @copyright Copyright (c) 2020 Gary Kim <gary@garykim.dev>
3+
- @copyright Copyright (c) 2020-2021 Gary Kim <gary@garykim.dev>
44
- @copyright Copyright (c) 2020 Samuel Llamzon
55
-
66
- @author Sorunome <mail@sorunome.de>
@@ -24,43 +24,43 @@
2424

2525
<template>
2626
<div>
27-
<SettingsSection
28-
:title="t('roitchat', 'Matrix Sharing')"
29-
:description="t('riotchat', 'Configure how to share things into matrix.')"
30-
>
31-
<label
32-
ref="share_domain"
33-
for="share_domain"
34-
>{{ t('riotchat', 'Domain:') }}</label>
35-
<input
36-
id="share_domain"
37-
v-model="share_domain"
38-
type="text"
39-
@change="updateSetting('share_domain')"
40-
>
41-
<br>
42-
<label
43-
ref="share_prefix"
44-
for="share_prefix"
45-
>{{ t('riotchat', 'Prefix:') }}</label>
46-
<input
47-
id="share_prefix"
48-
v-model="share_prefix"
49-
type="text"
50-
@change="updateSetting('share_prefix')"
51-
>
52-
<br>
53-
<label
54-
ref="share_suffix"
55-
for="share_suffix"
56-
>{{ t('riotchat', 'Suffix:') }}</label>
57-
<input
58-
id="share_suffix"
59-
v-model="share_suffix"
60-
type="text"
61-
@change="updateSetting('share_suffix')"
62-
>
63-
</SettingsSection>
27+
<SettingsSection
28+
:title="t('riotchat', 'Matrix Sharing')"
29+
:description="t('riotchat', 'Configure how to share things into matrix.')"
30+
>
31+
<label
32+
ref="share_domain"
33+
for="share_domain"
34+
>{{ t('riotchat', 'Domain:') }}</label>
35+
<input
36+
id="share_domain"
37+
v-model="share_domain"
38+
type="text"
39+
@change="updateSetting('share_domain')"
40+
>
41+
<br>
42+
<label
43+
ref="share_prefix"
44+
for="share_prefix"
45+
>{{ t('riotchat', 'Prefix:') }}</label>
46+
<input
47+
id="share_prefix"
48+
v-model="share_prefix"
49+
type="text"
50+
@change="updateSetting('share_prefix')"
51+
>
52+
<br>
53+
<label
54+
ref="share_suffix"
55+
for="share_suffix"
56+
>{{ t('riotchat', 'Suffix:') }}</label>
57+
<input
58+
id="share_suffix"
59+
v-model="share_suffix"
60+
type="text"
61+
@change="updateSetting('share_suffix')"
62+
>
63+
</SettingsSection>
6464
</div>
6565
</template>
6666

@@ -81,9 +81,9 @@ export default {
8181
},
8282
data() {
8383
return {
84-
"share_domain": loadState('riotchat', 'share_domain'),
85-
"share_prefix": loadState('riotchat', 'share_prefix'),
86-
"share_suffix": loadState('riotchat', 'share_suffix'),
84+
"share_domain": loadState('riotchat', 'share_domain'),
85+
"share_prefix": loadState('riotchat', 'share_prefix'),
86+
"share_suffix": loadState('riotchat', 'share_suffix'),
8787
};
8888
},
8989
methods: {
@@ -98,17 +98,9 @@ export default {
9898
Axios.put(generateUrl(`apps/riotchat/settings/${setting}`), {
9999
value,
100100
}).then(() => {
101-
if (settingName === 'custom_json') {
102-
showSuccess(t('riotchat', 'Custom config has been set'));
103-
} else {
104-
showSuccess(t('riotchat', '{settingName} has been set to {value}', { settingName, value }));
105-
}
101+
showSuccess(t('riotchat', '{settingName} has been set to {value}', { settingName, value }));
106102
}).catch(() => {
107-
if (settingName === 'custom_json') {
108-
showSuccess(t('riotchat', 'Custom config could not be set. Try reloading the page.'));
109-
} else {
110-
showError(t('riotchat', '{settingName} could not be set. Try reloading the page.', { settingName }));
111-
}
103+
showError(t('riotchat', '{settingName} could not be set. Try reloading the page.', { settingName }));
112104
});
113105
},
114106

0 commit comments

Comments
 (0)