mirror of
https://github.com/h44z/wg-portal.git
synced 2025-09-15 15:21:14 +00:00
fix self provisioning feature (#272)
This commit is contained in:
@@ -12,6 +12,8 @@ export const profileStore = defineStore({
|
||||
id: 'profile',
|
||||
state: () => ({
|
||||
peers: [],
|
||||
interfaces: [],
|
||||
selectedInterfaceId: "",
|
||||
stats: {},
|
||||
statsEnabled: false,
|
||||
user: {},
|
||||
@@ -71,6 +73,7 @@ export const profileStore = defineStore({
|
||||
return (id) => state.statsEnabled && (id in state.stats) ? state.stats[id] : freshStats()
|
||||
},
|
||||
hasStatistics: (state) => state.statsEnabled,
|
||||
CountInterfaces: (state) => state.interfaces.length,
|
||||
},
|
||||
actions: {
|
||||
afterPageSizeChange() {
|
||||
@@ -116,6 +119,11 @@ export const profileStore = defineStore({
|
||||
this.stats = statsResponse.Stats
|
||||
this.statsEnabled = statsResponse.Enabled
|
||||
},
|
||||
setInterfaces(interfaces) {
|
||||
this.interfaces = interfaces
|
||||
this.selectedInterfaceId = interfaces.length > 0 ? interfaces[0].Identifier : ""
|
||||
this.fetching = false
|
||||
},
|
||||
async enableApi() {
|
||||
this.fetching = true
|
||||
let currentUser = authStore().user.Identifier
|
||||
@@ -186,5 +194,19 @@ export const profileStore = defineStore({
|
||||
})
|
||||
})
|
||||
},
|
||||
async LoadInterfaces() {
|
||||
this.fetching = true
|
||||
let currentUser = authStore().user.Identifier
|
||||
return apiWrapper.get(`${baseUrl}/${base64_url_encode(currentUser)}/interfaces`)
|
||||
.then(this.setInterfaces)
|
||||
.catch(error => {
|
||||
this.setInterfaces([])
|
||||
console.log("Failed to load interfaces for ", currentUser, ": ", error)
|
||||
notify({
|
||||
title: "Backend Connection Failure",
|
||||
text: "Failed to load interfaces!",
|
||||
})
|
||||
})
|
||||
},
|
||||
}
|
||||
})
|
||||
|
Reference in New Issue
Block a user