Color the background of the connection state to make it more clear
This commit is contained in:
parent
69cdb76a60
commit
466ae39346
40
src/App.vue
40
src/App.vue
@ -7,13 +7,9 @@
|
||||
Hide <code>saltutil.find_job</code> jobs
|
||||
<input type="checkbox" v-model="hideFindJob" />
|
||||
</label>
|
||||
{{
|
||||
!evtSource || evtSource.readyState == evtSource.CLOSED
|
||||
? 'Disconnected'
|
||||
: evtSource.readyState == evtSource.OPEN
|
||||
? 'Connected'
|
||||
: 'Connecting'
|
||||
}}
|
||||
<span class="event-source-state" :class="evtSourceState">
|
||||
{{ evtSourceState }}
|
||||
</span>
|
||||
<Job
|
||||
v-for="(jobEvents, jid) in jobs"
|
||||
:key="jid"
|
||||
@ -43,6 +39,7 @@ export default class App extends Vue {
|
||||
showRawEvents: boolean = false;
|
||||
hideFindJob: boolean = true;
|
||||
evtSourceTimeout: number | null = null;
|
||||
evtSourceState: 'Disconnected' | 'Connecting' | 'Connected' = 'Disconnected';
|
||||
|
||||
mounted(): void {
|
||||
fetch(BASE_URL + 'login', {
|
||||
@ -64,7 +61,7 @@ export default class App extends Vue {
|
||||
|
||||
this.evtSource.onopen = (e) => {
|
||||
console.info('Connected to eventSource.');
|
||||
this.$forceUpdate(); // evtSource.readyState won't be detected otherwise
|
||||
this.updateEvtSourceState();
|
||||
};
|
||||
|
||||
this.evtSource.onmessage = (e) => {
|
||||
@ -83,8 +80,8 @@ export default class App extends Vue {
|
||||
if (!this.evtSourceTimeout) {
|
||||
console.info('Lost eventSource, reconnecting');
|
||||
console.info(e);
|
||||
this.$forceUpdate(); // evtSource.readyState won't be detected otherwise
|
||||
this.evtSource.close();
|
||||
this.updateEvtSourceState();
|
||||
this.evtSource?.close();
|
||||
this.evtSourceTimeout = window.setTimeout(
|
||||
this.connectEventSource,
|
||||
1000,
|
||||
@ -100,5 +97,28 @@ export default class App extends Vue {
|
||||
): event is Extract<salt.SaltEvent, { splitTag: ['salt', T, ...any[]] }> {
|
||||
return event.splitTag[1] === type;
|
||||
}
|
||||
|
||||
updateEvtSourceState(): void {
|
||||
this.evtSourceState =
|
||||
!this.evtSource || this.evtSource.readyState == this.evtSource.CLOSED
|
||||
? 'Disconnected'
|
||||
: this.evtSource.readyState == this.evtSource.OPEN
|
||||
? 'Connected'
|
||||
: 'Connecting';
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
.event-source-state {
|
||||
&.Disconnected {
|
||||
background-color: red;
|
||||
}
|
||||
&.Connecting {
|
||||
background-color: yellow;
|
||||
}
|
||||
&.Connected {
|
||||
background-color: green;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
Loading…
Reference in New Issue
Block a user