This repository has been archived by the owner on Jan 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
/
ProjectMenu.vue
122 lines (115 loc) · 3.72 KB
/
ProjectMenu.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
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
<template>
<span class="header-notice-opener">
<a-select
class="project-select"
:defaultValue="$t('label.default.view')"
:loading="loading"
:value="($store.getters.project && 'id' in $store.getters.project) ? ($store.getters.project.displaytext || $store.getters.project.name) : $t('label.default.view')"
:disabled="isDisabled()"
:filterOption="filterProject"
@change="changeProject"
@focus="fetchData"
showSearch>
<a-tooltip placement="bottom" slot="suffixIcon">
<template slot="title">
<span>{{ $t('label.projects') }}</span>
</template>
<span style="font-size: 20px; color: #999; margin-top: -5px">
<a-icon v-if="!loading" type="project" />
<a-icon v-else type="loading" />
</span>
</a-tooltip>
<a-select-option v-for="(project, index) in projects" :key="index">
{{ project.displaytext || project.name }}
</a-select-option>
</a-select>
</span>
</template>
<script>
import store from '@/store'
import { api } from '@/api'
import _ from 'lodash'
export default {
name: 'ProjectMenu',
data () {
return {
projects: [],
loading: false
}
},
mounted () {
this.fetchData()
},
methods: {
fetchData () {
if (this.isDisabled()) {
return
}
var page = 1
const projects = []
const getNextPage = () => {
this.loading = true
api('listProjects', { listAll: true, details: 'min', page: page, pageSize: 500 }).then(json => {
if (json && json.listprojectsresponse && json.listprojectsresponse.project) {
projects.push(...json.listprojectsresponse.project)
}
if (projects.length < json.listprojectsresponse.count) {
page++
getNextPage()
}
}).finally(() => {
this.projects = _.orderBy(projects, ['displaytext'], ['asc'])
this.projects.unshift({ name: this.$t('label.default.view') })
this.loading = false
})
}
getNextPage()
},
isDisabled () {
return !Object.prototype.hasOwnProperty.call(store.getters.apis, 'listProjects')
},
changeProject (index) {
const project = this.projects[index]
this.$store.dispatch('ProjectView', project.id)
this.$store.dispatch('SetProject', project)
this.$store.dispatch('ToggleTheme', project.id === undefined ? 'light' : 'dark')
this.$message.success(`Switched to "${project.displaytext}"`)
if (this.$route.name !== 'dashboard') {
this.$router.push({ name: 'dashboard' })
}
},
filterProject (input, option) {
return option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
}
}
}
</script>
<style lang="less" scoped>
.project {
&-select {
width: 40vw;
}
&-icon {
font-size: 20px;
line-height: 1;
padding-top: 5px;
padding-right: 5px;
}
}
</style>