-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathWorkPackagePickerElement.vue
151 lines (144 loc) · 3.93 KB
/
WorkPackagePickerElement.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
<!--
- @copyright Copyright (c) 2023 Swikriti Tripathi <swikriti@jakaritech.com>
-
- @author 2023 Swikriti Tripathi <swikriti@jakaritech.com>
-
- @license GNU AGPL version 3 or any later version
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as
- published by the Free Software Foundation, either version 3 of the
- License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<template>
<div id="work-package-smart-picker" class="work-package-picker">
<h2 class="work-package-picker__header">
{{ t('integration_openproject', 'OpenProject work package picker') }}
</h2>
<SearchInput
ref="linkPicker"
:is-smart-picker="true"
:file-info="fileInfo"
:is-disabled="isLoading || !isAdminConfigOk || !isStateOk"
:linked-work-packages="linkedWorkPackages"
@submit="onSubmit" />
<div id="openproject-empty-content">
<NcLoadingIcon v-if="isLoading" class="loading-spinner" :size="90" />
<EmptyContent
v-else
:state="state"
:file-info="fileInfo"
:is-smart-picker="true"
:is-admin-config-ok="isAdminConfigOk" />
</div>
</div>
</template>
<script>
import SearchInput from '../components/tab/SearchInput.vue'
import EmptyContent from '../components/tab/EmptyContent.vue'
import { STATE } from '../utils.js'
import { loadState } from '@nextcloud/initial-state'
import { generateUrl } from '@nextcloud/router'
import axios from '@nextcloud/axios'
import NcLoadingIcon from '@nextcloud/vue/dist/Components/NcLoadingIcon.js'
export default {
name: 'WorkPackagePickerElement',
components: {
EmptyContent,
SearchInput,
NcLoadingIcon,
},
props: {
providerId: {
type: String,
required: true,
},
accessible: {
type: Boolean,
default: false,
},
},
data() {
return {
fileInfo: {},
linkedWorkPackages: [],
state: STATE.LOADING,
isAdminConfigOk: loadState('integration_openproject', 'admin-config-status'),
}
},
computed: {
isStateOk() {
return this.state === STATE.OK
},
isLoading() {
return this.state === STATE.LOADING
},
},
mounted() {
this.checkIfOpenProjectIsAvailable()
},
methods: {
onSubmit(data) {
this.$emit('submit', data)
},
async checkIfOpenProjectIsAvailable() {
if (!this.isAdminConfigOk) {
this.state = STATE.ERROR
return
}
const configurationUrl = generateUrl('/apps/integration_openproject/configuration')
let response = null
try {
// send an axios request to fetch configuration to see if the connection is there
response = await axios.get(configurationUrl)
if (response.data) {
this.state = STATE.OK
if (this.$refs.linkPicker?.$refs?.workPackageSelect) {
this.$nextTick(() => {
document.getElementById(`${this.$refs.linkPicker?.$refs?.workPackageSelect?.inputId}`).focus()
})
}
} else {
this.state = STATE.ERROR
}
} catch (error) {
document.activeElement?.blur()
if (error.response && (error.response.status === 404 || error.response.status === 503)) {
this.state = STATE.CONNECTION_ERROR
} else if (error.response && error.response.status === 401) {
this.state = STATE.NO_TOKEN
} else {
this.state = STATE.ERROR
}
}
},
},
}
</script>
<style scoped lang="scss">
.work-package-picker {
width: 100%;
display: flex;
flex-direction: column;
margin-top: 44px;
h2 {
display: flex;
align-items: center;
align-self: center;
}
#openproject-empty-content {
height: 400px !important;
}
.loading-spinner {
margin-top: 150px;
}
}
</style>