-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathPersonalSettings.vue
155 lines (148 loc) · 4.59 KB
/
PersonalSettings.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<template>
<div class="openproject-prefs section">
<SettingsTitle />
<div v-if="connected" class="openproject-prefs--connected">
<label>
<CheckIcon :size="20" />
{{ t('integration_openproject', 'Connected as {user}', { user: state.user_name }) }}
</label>
<NcButton class="openproject-prefs--disconnect" @click="disconnectFromOP()">
<template #icon>
<CloseIcon :size="23" />
</template>
{{ t('integration_openproject', 'Disconnect from OpenProject') }}
</NcButton>
</div>
<br>
<div v-if="connected" class="openproject-prefs--form">
<CheckBox v-model="state.navigation_enabled"
input-id="openproject-prefs--link"
:label="t('integration_openproject', 'Enable navigation link')" />
<CheckBox v-model="state.search_enabled"
input-id="openproject-prefs--u-search"
:label="t('integration_openproject', 'Enable unified search for tickets')">
<template #hint>
<p v-if="state.search_enabled" class="openproject-prefs--hint">
<InformationVariant />
{{ t('integration_openproject', 'Warning, everything you type in the search bar will be sent to your OpenProject instance.') }}
</p>
<br v-else>
</template>
</CheckBox>
</div>
<OAuthConnectButton v-else :is-admin-config-ok="state.admin_config_ok" />
</div>
</template>
<script>
import { loadState } from '@nextcloud/initial-state'
import { generateUrl } from '@nextcloud/router'
import axios from '@nextcloud/axios'
import CloseIcon from 'vue-material-design-icons/Close.vue'
import CheckIcon from 'vue-material-design-icons/Check.vue'
import InformationVariant from 'vue-material-design-icons/InformationVariant.vue'
import { showSuccess, showError } from '@nextcloud/dialogs'
import SettingsTitle from '../components/settings/SettingsTitle.vue'
import OAuthConnectButton from './OAuthConnectButton.vue'
import CheckBox from './settings/CheckBox.vue'
import { translate as t } from '@nextcloud/l10n'
import { checkOauthConnectionResult } from '../utils.js'
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
export default {
name: 'PersonalSettings',
components: {
SettingsTitle, OAuthConnectButton, NcButton, CloseIcon, CheckIcon, InformationVariant, CheckBox,
},
data() {
return {
loading: false,
state: loadState('integration_openproject', 'user-config'),
oauthConnectionErrorMessage: loadState('integration_openproject', 'oauth-connection-error-message'),
oauthConnectionResult: loadState('integration_openproject', 'oauth-connection-result'),
}
},
computed: {
connected() {
if (!this.state.admin_config_ok) return false
return this.state.token && this.state.token !== ''
&& this.state.user_name && this.state.user_name !== ''
},
},
watch: {
'state.search_enabled'(newVal) {
this.saveOptions({
search_enabled: newVal ? '1' : '0',
})
},
'state.navigation_enabled'(newVal) {
this.saveOptions({
navigation_enabled: newVal ? '1' : '0',
})
},
},
mounted() {
checkOauthConnectionResult(this.oauthConnectionResult, this.oauthConnectionErrorMessage)
},
methods: {
disconnectFromOP() {
this.state.token = ''
this.saveOptions({ token: this.state.token, token_type: '' })
},
saveOptions(values) {
const req = {
values,
}
const url = generateUrl('/apps/integration_openproject/config')
axios.put(url, req)
.then((response) => {
showSuccess(t('integration_openproject', 'OpenProject options saved'))
if (response.data.user_name !== undefined) {
this.state.user_name = response.data.user_name
if (this.state.token && response.data.user_name === '') {
showError(t('integration_openproject', 'Incorrect access token'))
}
}
})
.catch((error) => {
console.debug(error.response)
const msg = error.response?.data?.errorMessage === 'Invalid token'
? t('integration_openproject', 'Invalid token')
: error.response?.data?.errorMessage === 'Not found'
? t('integration_openproject', 'OpenProject instance not found')
: error.response?.request?.responseText
showError(
t('integration_openproject', 'Failed to save OpenProject options')
+ ': ' + msg
)
})
.finally(() => {
this.loading = false
})
},
},
}
</script>
<style scoped lang="scss">
.openproject-prefs {
&--connected {
padding-block: 1rem;
label {
display: flex;
align-items: center;
padding-bottom: .5rem;
}
.check-icon {
padding-right: .2rem;
color: var(--color-success);
}
}
&--hint {
display: flex;
align-items: center;
padding-top: 1rem;
}
.oauth-connect--message {
text-align: left;
padding: 0;
}
}
</style>