-
Notifications
You must be signed in to change notification settings - Fork 17
/
AdminSettings.vue
126 lines (117 loc) · 3.5 KB
/
AdminSettings.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<template>
<div id="openproject_prefs" class="section">
<SettingsTitle />
<p class="settings-hint">
{{ t('integration_openproject', 'If you want to allow your Nextcloud users to use OAuth to authenticate to a OpenProject instance, create an application in your OpenProject admin settings and put the Client ID (AppId) and the Client secret below.') }}
<br><br>
<span class="icon icon-details" />
{{ t('integration_openproject', 'Make sure you set the "Redirect URI" to') }}
<b> {{ redirect_uri }} </b>
</p>
<div class="grid-form">
<label for="openproject-oauth-instance">
<a class="icon icon-link" />
{{ t('integration_openproject', 'OpenProject instance address') }}
</label>
<input id="openproject-oauth-instance"
v-model="state.oauth_instance_url"
type="text"
:placeholder="t('integration_openproject', 'OpenProject address')"
@input="onInput">
<label for="openproject-client-id">
<a class="icon icon-category-auth" />
{{ t('integration_openproject', 'Client ID') }}
</label>
<input id="openproject-client-id"
v-model="state.client_id"
type="password"
:readonly="readonly"
:placeholder="t('integration_openproject', 'Client ID of the OAuth app in OpenProject')"
@focus="readonly = false"
@input="onInput">
<label for="openproject-client-secret">
<a class="icon icon-category-auth" />
{{ t('integration_openproject', 'Client secret') }}
</label>
<input id="openproject-client-secret"
v-model="state.client_secret"
type="password"
:readonly="readonly"
:placeholder="t('integration_openproject', 'Client secret of the OAuth app in OpenProject')"
@focus="readonly = false"
@input="onInput">
</div>
</div>
</template>
<script>
import { loadState } from '@nextcloud/initial-state'
import { generateUrl } from '@nextcloud/router'
import axios from '@nextcloud/axios'
import { delay } from '../utils'
import { showSuccess, showError } from '@nextcloud/dialogs'
import '@nextcloud/dialogs/styles/toast.scss'
import SettingsTitle from '../components/settings/SettingsTitle'
export default {
name: 'AdminSettings',
components: {
SettingsTitle,
},
data() {
return {
state: loadState('integration_openproject', 'admin-config'),
// to prevent some browsers to fill fields with remembered passwords
readonly: true,
redirect_uri: window.location.protocol + '//' + window.location.host + generateUrl('/apps/integration_openproject/oauth-redirect'),
}
},
methods: {
onInput() {
const that = this
delay(() => {
that.saveOptions()
}, 2000)()
},
saveOptions() {
const req = {
values: {
client_id: this.state.client_id,
client_secret: this.state.client_secret,
oauth_instance_url: this.state.oauth_instance_url,
},
}
const url = generateUrl('/apps/integration_openproject/admin-config')
axios.put(url, req)
.then((response) => {
showSuccess(t('integration_openproject', 'OpenProject admin options saved'))
})
.catch((error) => {
showError(
t('integration_openproject', 'Failed to save OpenProject admin options')
+ ': ' + error.response.request.responseText
)
})
},
},
}
</script>
<style scoped lang="scss">
.grid-form label {
line-height: 38px;
}
.grid-form input {
width: 100%;
}
.grid-form {
max-width: 500px;
display: grid;
grid-template: 1fr / 1fr 1fr;
margin-left: 30px;
}
#openproject_prefs .icon {
display: inline-block;
width: 32px;
}
#openproject_prefs .grid-form .icon {
margin-bottom: -3px;
}
</style>