|
11 | 11 | type="warning" |
12 | 12 | show-icon |
13 | 13 | title="This session terminated abnormally">{{session.error}}</el-alert> |
14 | | - <el-alert v-for="warning in session.warnings" |
| 14 | + <el-alert v-for="warning in session?.warnings || []" |
15 | 15 | v-bind:key="warning.details" |
16 | 16 | :title="'Warning: ' + warning.details" |
17 | 17 | type="warning" |
|
41 | 41 | </div> |
42 | 42 | </template> |
43 | 43 | <script lang="ts"> |
44 | | - import { Component, Vue, Prop, Watch, toNative } from "vue-facing-decorator"; |
| 44 | + import { Component, Vue, Prop, Watch, toNative, Inject } from "vue-facing-decorator"; |
45 | 45 |
|
46 | 46 | import SessionsController from "../ApiClient/SessionsController"; |
47 | 47 | import SessionSummary from "../ApiClient/SessionSummary"; |
48 | 48 | import Session from "../ApiClient/Session"; |
49 | 49 | import TextView from "@/components/textview.vue"; |
| 50 | + import HubConnectionManager from "../HubConnectionManager"; |
50 | 51 |
|
51 | 52 | @Component({ |
52 | 53 | components: { |
|
57 | 58 |
|
58 | 59 | @Prop({}) |
59 | 60 | sessionSummary: SessionSummary | null = null; |
| 61 | + |
| 62 | + @Inject({ default: null }) |
| 63 | + connection!: HubConnectionManager | null; |
| 64 | + |
60 | 65 | session: Session | null = null; |
61 | 66 | log: string | null = null; |
62 | 67 |
|
63 | 68 | error: Error | null = null; |
64 | 69 | loading = false; |
| 70 | + |
| 71 | + private pollInterval: number | null = null; |
65 | 72 |
|
66 | 73 | @Watch("sessionSummary") |
67 | 74 | async onMessageChanged( |
68 | 75 | value: SessionSummary | null, |
69 | 76 | oldValue: SessionSummary | null |
70 | 77 | ) { |
71 | 78 | await this.loadSession(); |
| 79 | + this.setupPolling(); |
72 | 80 | } |
73 | 81 |
|
74 | 82 | async loadMessage() { |
|
104 | 112 | this.loading = false; |
105 | 113 | } |
106 | 114 | } |
| 115 | + |
| 116 | + async refreshLog() { |
| 117 | + if (this.sessionSummary != null && !this.sessionSummary.endDate) { |
| 118 | + try { |
| 119 | + const newSession = await new SessionsController().getSession( |
| 120 | + this.sessionSummary.id |
| 121 | + ); |
| 122 | + const newLog = await new SessionsController().getSessionLog( |
| 123 | + this.sessionSummary.id |
| 124 | + ); |
| 125 | + |
| 126 | + // Only update if content has changed |
| 127 | + if (this.log !== newLog) { |
| 128 | + this.log = newLog; |
| 129 | + } |
| 130 | + |
| 131 | + // Update session properties if they've changed |
| 132 | + if (JSON.stringify(this.session) !== JSON.stringify(newSession)) { |
| 133 | + this.session = newSession; |
| 134 | + } |
| 135 | + |
| 136 | + // If session has ended, stop polling |
| 137 | + if (newSession) { |
| 138 | + // Session ended, need to update the summary as well |
| 139 | + this.stopPolling(); |
| 140 | + } |
| 141 | + } catch (e: any) { |
| 142 | + // Silently ignore errors during polling |
| 143 | + console.warn('Failed to refresh session log:', e); |
| 144 | + } |
| 145 | + } |
| 146 | + } |
| 147 | + |
| 148 | + setupPolling() { |
| 149 | + this.stopPolling(); |
| 150 | + |
| 151 | + // Only poll if session is active (no end date) |
| 152 | + if (this.sessionSummary && !this.sessionSummary.endDate) { |
| 153 | + this.pollInterval = window.setInterval(() => { |
| 154 | + this.refreshLog(); |
| 155 | + }, 1000); // Poll every second |
| 156 | + } |
| 157 | + } |
| 158 | + |
| 159 | + stopPolling() { |
| 160 | + if (this.pollInterval !== null) { |
| 161 | + clearInterval(this.pollInterval); |
| 162 | + this.pollInterval = null; |
| 163 | + } |
| 164 | + } |
| 165 | + |
| 166 | + onSessionUpdated(sessionId: string) { |
| 167 | + if (this.sessionSummary && this.sessionSummary.id === sessionId) { |
| 168 | + this.refreshLog(); |
| 169 | + } |
| 170 | + } |
107 | 171 |
|
108 | | - async created() { } |
| 172 | + async created() { |
| 173 | + if (this.connection) { |
| 174 | + this.connection.on("sessionupdated", this.onSessionUpdated.bind(this)); |
| 175 | + } |
| 176 | + } |
109 | 177 |
|
110 | | - async destroyed() { } |
| 178 | + async unmounted() { |
| 179 | + this.stopPolling(); |
| 180 | + } |
111 | 181 | } |
112 | 182 |
|
113 | 183 |
|
|
0 commit comments