-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathServers.vue
More file actions
169 lines (161 loc) · 4.4 KB
/
Copy pathServers.vue
File metadata and controls
169 lines (161 loc) · 4.4 KB
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<template>
<div class="mainContent__inner">
<div class="flex flex-col sm:flex-row justify-between">
<h1>Edge Servers</h1>
<router-link
v-if="servers.length"
:to="{ name: 'ServerDeploy' }"
class="button button--success button--small h-full mb-5 sm:mb-0"
>
Deploy Server
</router-link>
</div>
<!-- Search Component -->
<Search @search="handleSearch" />
<div v-if="!loaded" class="flex items-center">
<span>Loading servers</span>
<div class="ml-2"><LoadingSpinner /></div>
</div>
<ul v-else-if="servers.length" role="list" class="serverList">
<div class="float-right mb-2">
<ListSortingMenu
:fields="sortFields"
:query="sortQuery"
@update-sort="updateSortQuery"
/>
</div>
<ServerListItem
v-for="server in servers"
:key="server._key"
:regions=regions
:server=server
/>
<Pagination
:currentPage=currentPage
:limit=limit
:totalCount="metadata.totalCount"
@change-page=changePage
/>
</ul>
<div v-else class="box">
<div class="flex flex-col space-y-4 items-center justify-center py-4">
<p>You haven't deployed any servers yet. Once you deploy your first server it will be available here.</p>
<router-link
:to="{ name: 'ServerDeploy' }"
class="button button--success button--small"
>
Deploy Server
</router-link>
</div>
</div>
</div>
</template>
<script>
/* global process */
import * as utils from '@edge/account-utils'
import ListSortingMenu from '@/components/ListSortingMenu'
import LoadingSpinner from '@/components/icons/LoadingSpinner'
import Pagination from '@/components/Pagination'
import ServerListItem from '@/components/server/ServerListItem'
import Search from '../../components/Search.vue'
import { mapState } from 'vuex'
const sortFields = [
{ label: 'Name', param: 'settings.name'},
{ label: 'Created', param: 'created'},
{ label: 'OS', param: 'settings.os.version'},
{ label: 'vCPUs', param: 'spec.cpus'},
{ label: 'Disk', param: 'spec.disk'},
{ label: 'RAM', param: 'spec.ram'},
{ label: 'Bandwidth', param: 'spec.bandwidth'},
{ label: 'Zone', param: 'region'},
{ label: 'Status', param: 'status' }
]
export default {
name: 'Servers',
title() {
return 'Edge Account Portal » Servers'
},
components: {
ListSortingMenu,
LoadingSpinner,
Pagination,
ServerListItem,
Search
},
data() {
return {
iServers: null,
limit: 10,
loaded: false,
metadata: { totalCount: 0 },
pageHistory: [1],
regions: [],
servers: [],
sortFields: sortFields,
sortQuery: '',
searchQuery: ''
}
},
computed: {
...mapState(['account', 'session']),
currentPage() {
return this.pageHistory[this.pageHistory.length - 1]
}
},
methods: {
changePage(newPage) {
this.pageHistory = [...this.pageHistory, newPage]
},
async updateRegions() {
const { results } = await utils.getRegions(process.env.VUE_APP_ACCOUNT_API_URL, this.session._key)
this.regions = results
},
async updateServers() {
const params = { limit: this.limit, page: this.currentPage, search: this.searchQuery }
if (this.sortQuery) params.sort = [this.sortQuery, '-created']
try{
const { results, metadata } = await utils.getServers(process.env.VUE_APP_ACCOUNT_API_URL, this.session._key, params)
this.servers = results
this.metadata = metadata
this.loaded = true
} catch (error) {
console.error("Failed to fetch servers:", error)
this.loaded = true // Ensure loading state is properly set
}
},
updateSortQuery (newQuery) {
this.sortQuery = newQuery
},
handleSearch(query) {
this.searchQuery = query
this.updateServers()
}
},
async mounted() {
await this.updateRegions()
await this.updateServers()
this.iServers = setInterval(() => {
this.updateServers()
}, 10000)
},
unmounted() {
clearInterval(this.iServers)
},
watch: {
pageHistory() {
this.updateServers()
},
sortQuery() {
this.updateServers()
},
searchQuery() {
this.updateServers() // Update servers when searchQuery changes
}
}
}
</script>
<style scoped>
.serverList {
@apply space-y-2;
}
</style>