@@ -21,6 +21,9 @@ import thingUpdatesHTML from './thingUpdates.html';
2121import * as Things from './things.js' ;
2222import * as ThingsSSE from './thingsSSE.js' ;
2323
24+ const BASE_CONTEXT_FIELDS = '_context/topic,_context/path,_context/value' ;
25+ const EXTRA_FIELDS = 'thingId,policyId,definition,attributes,features,_revision,_created,_modified,_metadata' ;
26+
2427const MAX_MESSAGES = 5000 ;
2528
2629enum ThingUpdateContent {
@@ -53,6 +56,7 @@ type DomElements = {
5356 inputHistoricalRqlFilter : HTMLInputElement ,
5457 buttonFetchHistorical : HTMLButtonElement ,
5558 buttonStopHistorical : HTMLButtonElement ,
59+ checkboxIncludeHeaders : HTMLInputElement ,
5660 selectThingUpdateContent : HTMLSelectElement ,
5761 tbodyThingUpdates : HTMLTableElement ,
5862 tableFilterThingUpdates : TableFilter ,
@@ -81,6 +85,7 @@ let dom: DomElements = {
8185 inputHistoricalRqlFilter : null ,
8286 buttonFetchHistorical : null ,
8387 buttonStopHistorical : null ,
88+ checkboxIncludeHeaders : null ,
8489 selectThingUpdateContent : null ,
8590 tbodyThingUpdates : null ,
8691 tableFilterThingUpdates : null ,
@@ -119,6 +124,7 @@ export function ready() {
119124 dom . tableFilterThingUpdates . addEventListener ( 'filterChange' , onFilterChange ) ;
120125 dom . tableFilterThingUpdates . filterOptions = createFilterOptions ( ) ;
121126
127+ dom . checkboxIncludeHeaders . onchange = onIncludeHeadersChange ;
122128 dom . thingUpdatesModeLive . onchange = onModeChange ;
123129 dom . thingUpdatesModeHistorical . onchange = onModeChange ;
124130 dom . historicalRangeModeRevision . onchange = onRangeModeChange ;
@@ -159,6 +165,23 @@ export function ready() {
159165 } ;
160166}
161167
168+ /**
169+ * Returns the SSE fields parameter string, optionally including context headers.
170+ * In historical mode only `_context/headers/historical-headers` is useful;
171+ * in live mode the full `_context/headers` is requested.
172+ */
173+ export function buildFieldsParam ( historical = false ) : string {
174+ const headerField = historical ? '_context/headers/historical-headers' : '_context/headers' ;
175+ const contextFields = dom . checkboxIncludeHeaders ?. checked
176+ ? `${ BASE_CONTEXT_FIELDS } ,${ headerField } `
177+ : BASE_CONTEXT_FIELDS ;
178+ return `fields=${ EXTRA_FIELDS } ,${ contextFields } &extraFields=${ EXTRA_FIELDS } ` ;
179+ }
180+
181+ function onIncludeHeadersChange ( ) {
182+ ThingsSSE . reconnectSelectedThing ( buildFieldsParam ( ) ) ;
183+ }
184+
162185function onEnvironmentChanged ( modifiedField ) {
163186 if ( ! [ 'pinnedThings' , 'filterList' , 'messageTemplates' , 'recentPolicyIds' ] . includes ( modifiedField ) ) {
164187 cancelActiveProbe ( ) ;
@@ -436,8 +459,7 @@ function onFetchHistorical() {
436459 lastReceivedRevision = null ;
437460 requestedToRevision = null ;
438461
439- const fields = 'fields=thingId,policyId,definition,attributes,features,_revision,_created,_modified,_metadata,_context/topic,_context/path,_context/value' +
440- '&extraFields=thingId,policyId,definition,attributes,features,_revision,_created,_modified,_metadata' ;
462+ const fields = buildFieldsParam ( true ) ;
441463
442464 let rangeParams = '' ;
443465 if ( dom . historicalRangeModeRevision . checked ) {
0 commit comments