Skip to content

Commit 279d953

Browse files
committed
frontend: ethernet: Refresh interface immediately after write actions
1 parent fc65797 commit 279d953

4 files changed

Lines changed: 44 additions & 12 deletions

File tree

core/frontend/src/components/ethernet/EthernetManager.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@
33
elevation="1"
44
width="400"
55
>
6-
<v-expansion-panels v-if="are_interfaces_available && !updating_interfaces">
6+
<v-expansion-panels v-show="are_interfaces_available && !updating_interfaces">
77
<interface-card
88
v-for="(ethernet_interface, key) in available_interfaces"
99
:key="key"
1010
:adapter="ethernet_interface"
1111
/>
1212
</v-expansion-panels>
13-
<v-container v-else-if="updating_interfaces">
13+
<v-container v-if="updating_interfaces">
1414
<spinning-logo
1515
size="30%"
1616
subtitle="Fetching available ethernet interfaces..."
1717
/>
1818
</v-container>
19-
<v-container v-else>
19+
<v-container v-else-if="!are_interfaces_available">
2020
<div>
2121
No ethernet interfaces available
2222
</div>

core/frontend/src/components/ethernet/EthernetUpdater.vue

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,17 @@ export default Vue.extend({
1212
name: 'EthernetUpdater',
1313
data() {
1414
return {
15-
fetch_available_interfaces_task: new OneMoreTime({ delay: 5000, disposeWith: this }),
15+
fetch_available_interfaces_task: new OneMoreTime({ delay: 5000, disposeWith: this, autostart: false }),
1616
}
1717
},
18-
mounted() {
19-
this.fetch_available_interfaces_task.setAction(this.fetchAvailableEthernetInterfaces)
18+
async mounted() {
19+
try {
20+
await this.fetchAvailableEthernetInterfaces()
21+
} finally {
22+
ethernet.setUpdatingInterfaces(false)
23+
this.fetch_available_interfaces_task.setAction(this.fetchAvailableEthernetInterfaces)
24+
this.fetch_available_interfaces_task.start()
25+
}
2026
},
2127
methods: {
2228
async fetchAvailableEthernetInterfaces(): Promise<void> {

core/frontend/src/components/ethernet/InterfaceCard.vue

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -319,16 +319,12 @@ export default Vue.extend({
319319
await ethernet.deleteAddress({ interface_name: this.adapter.name, ip_address: ip })
320320
},
321321
async triggerForDynamicIP(): Promise<void> {
322-
ethernet.setUpdatingInterfaces(true)
323-
324322
await ethernet.triggerDynamicIP(this.adapter.name)
325323
},
326324
openDHCPServerDialog(): void {
327325
this.show_dhcp_server_dialog = true
328326
},
329327
async removeDHCPServer(): Promise<void> {
330-
ethernet.setUpdatingInterfaces(true)
331-
332328
await ethernet.RemoveDHCPServer(this.adapter.name)
333329
},
334330
async fetchLeases(): Promise<void> {

core/frontend/src/store/ethernet.ts

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ class EthernetStore extends VuexModule {
3232
@Mutation
3333
setInterfaces(ethernet_interfaces: EthernetInterface[]): void {
3434
this.available_interfaces = ethernet_interfaces
35-
this.updating_interfaces = false
3635
}
3736

3837
@Action
@@ -52,6 +51,10 @@ class EthernetStore extends VuexModule {
5251
notifier.pushBackError('ETHERNET_ADDRESS_CREATION_FAIL', error)
5352
throw error
5453
})
54+
.finally(async () => {
55+
await this.context.dispatch('refreshInterfaces')
56+
this.context.commit('setUpdatingInterfaces', false)
57+
})
5558
}
5659

5760
@Action
@@ -71,6 +74,10 @@ class EthernetStore extends VuexModule {
7174
notifier.pushError('ETHERNET_ADDRESS_DELETE_FAIL', error)
7275
throw error
7376
})
77+
.finally(async () => {
78+
await this.context.dispatch('refreshInterfaces')
79+
this.context.commit('setUpdatingInterfaces', false)
80+
})
7481
}
7582

7683
@Action
@@ -91,13 +98,16 @@ class EthernetStore extends VuexModule {
9198
notifier.pushBackError('DHCP_SERVER_ADD_FAIL', error)
9299
throw error
93100
})
94-
.finally(() => {
101+
.finally(async () => {
102+
await this.context.dispatch('refreshInterfaces')
95103
this.context.commit('setUpdatingInterfaces', false)
96104
})
97105
}
98106

99107
@Action
100108
async RemoveDHCPServer(interface_name: string): Promise<void> {
109+
this.context.commit('setUpdatingInterfaces', true)
110+
101111
await back_axios({
102112
method: 'delete',
103113
url: `${this.API_URL}/dhcp`,
@@ -110,6 +120,10 @@ class EthernetStore extends VuexModule {
110120
const message = `Could not remove DHCP server from interface '${interface_name}': ${error.message}.`
111121
notifier.pushError('DHCP_SERVER_REMOVE_FAIL', message)
112122
})
123+
.finally(async () => {
124+
await this.context.dispatch('refreshInterfaces')
125+
this.context.commit('setUpdatingInterfaces', false)
126+
})
113127
}
114128

115129
@Action
@@ -189,6 +203,16 @@ class EthernetStore extends VuexModule {
189203
})
190204
}
191205

206+
@Action
207+
async refreshInterfaces(): Promise<void> {
208+
try {
209+
const response = await this.context.dispatch('getAvailableEthernetInterfaces')
210+
this.context.commit('setInterfaces', response.data)
211+
} catch {
212+
// Errors are already pushed to the notifier by getAvailableEthernetInterfaces.
213+
}
214+
}
215+
192216
@Action
193217
async setInterfacesPriority(interfaces: { name: string, priority: number }[]): Promise<void> {
194218
await back_axios({
@@ -213,6 +237,8 @@ class EthernetStore extends VuexModule {
213237

214238
@Action
215239
async triggerDynamicIP(interface_name: string): Promise<void> {
240+
this.context.commit('setUpdatingInterfaces', true)
241+
216242
await back_axios({
217243
method: 'post',
218244
url: `${this.API_URL}/dynamic_ip`,
@@ -225,6 +251,10 @@ class EthernetStore extends VuexModule {
225251
const message = `Could not trigger for dynamic IP address on '${interface_name}': ${error.message}.`
226252
notifier.pushError('DYNAMIC_IP_TRIGGER_FAIL', message)
227253
})
254+
.finally(async () => {
255+
await this.context.dispatch('refreshInterfaces')
256+
this.context.commit('setUpdatingInterfaces', false)
257+
})
228258
}
229259
}
230260

0 commit comments

Comments
 (0)