Skip to content

Commit 4323e51

Browse files
authored
Display channel status
and allow refresh frequency configuration via configuration panel (available in misc section)
1 parent 3c35608 commit 4323e51

File tree

2 files changed

+119
-59
lines changed

2 files changed

+119
-59
lines changed

web/MirthMigrator/js/MirthMigrator.js

Lines changed: 71 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,7 @@ function systemChanged(systemType){
132132
if(!sourceBoxShown && !destBoxShown){
133133
$('#flexBoxButtons').css('visibility', 'hidden');
134134
// and also deactivate status update for channels
135-
if(INTERVAL_ID){
136-
clearInterval(INTERVAL_ID);
137-
INTERVAL_ID = null;
138-
}
135+
deactivateChannelStatusUpdates();
139136
}
140137

141138
// and also all component detail information.
@@ -187,21 +184,12 @@ function populateComponentTables(refresh) {
187184
}
188185
var componentType = $('input[name = "compType"]:checked').val();
189186

187+
// in case of channel groups
190188
if(componentType == 'channelGroup'){
191-
// zzz
192-
193-
// load the status of the channels
194-
// activate the automatic status update for channels
195-
if(!INTERVAL_ID){
196-
INTERVAL_ID = setInterval(requestChannelStatusUpdates, refreshIntervalInSeconds * 1000);
197-
}
198-
189+
activateChannelStatusUpdates();
199190
} else{
200191
// deactivate the automatic status update for code templates
201-
if(INTERVAL_ID){
202-
clearInterval(INTERVAL_ID);
203-
INTERVAL_ID = null;
204-
}
192+
deactivateChannelStatusUpdates();
205193
}
206194

207195
var payload;
@@ -235,8 +223,9 @@ function populateComponentTables(refresh) {
235223
* @param {*} action The function that should be called w/ the response from the server
236224
* @param {*} parameters A json-object containing additional parameters that should be passed to the function defined under action
237225
* @param {*} refreshCache If set, the component metadata at server-side will be reloaded
226+
* @param {*} silentMode If set, the mouse pointer will not be changed to busy mode while the query is executed
238227
*/
239-
function accessResource(command, payload, action, parameters, refreshCache){
228+
function accessResource(command, payload, action, parameters, refreshCache, silentMode){
240229
// make sure all needed parameters are available
241230
if((!command || !action)){
242231
var message = (!command ? 'The webservice url':'The name of the function that should be called after execution') + ' is missing!';
@@ -253,15 +242,18 @@ function accessResource(command, payload, action, parameters, refreshCache){
253242
"payload": payload || {},
254243
"action": action,
255244
"parameters": parameters || '',
256-
"refreshCache": refreshCache || false});
245+
"refreshCache": refreshCache || false,
246+
"silentMode": silentMode || false});
257247

258248
// and open the login dialog
259249
openLogin();
260250
return;
261251
}
262252

263-
// activate mouse busy pointer
264-
indicateActivityStart();
253+
// activate mouse busy pointer if it was not supressed via silent mode flag
254+
if(!silentMode){
255+
indicateActivityStart();
256+
}
265257

266258
// make the ajax call
267259
$.ajax(
@@ -446,18 +438,22 @@ function setSystems(statusCode, response){
446438
}
447439

448440
/**
449-
* Displays the Mirth Migrator version number
441+
* Displays the Mirth Migrator version number and the refresh rate for channel state updates
450442
*/
451-
function setVersion(statusCode, response) {
443+
function setGlobalParameters(statusCode, response) {
452444
// set the version number
453445
$("#versionNumber").html('v' + response.version);
446+
// set the channel state refresh rate
447+
refreshIntervalInSeconds = response.channelStateRefreshRate || refreshIntervalInSeconds;
454448
}
455449

456450
/**
457451
* Displays a login dialog for entering username and password
458452
* @param {*} infoText - a message that will be displayed on the login dialog
459453
*/
460454
function openLogin(infoText) {
455+
// make sure the channel status updates are stopped
456+
deactivateChannelStatusUpdates();
461457
// set the info text
462458
$("#loginInfo").html(infoText);
463459
// display the login dialog
@@ -498,6 +494,9 @@ $(document).ready(function() {
498494

499495
// reprocess all queued requests
500496
requestList.forEach((request) => {
497+
if(request.command == '/getChannelState'){
498+
activateChannelStatusUpdates();
499+
}
501500
// retry sending the original request - this time w/ potentially valid login information
502501
accessResource(request.command, request.payload, request.action, request.parameters, request.refreshCache);
503502
});
@@ -569,7 +568,7 @@ $(document).ready(function() {
569568
});
570569

571570
// display the Mirth Migrator version
572-
accessResource('/getVersion', null, setVersion);
571+
accessResource('/getGlobalParameters', null, setGlobalParameters);
573572
// make an initial call for populating some arreas as soon as the page was loaded
574573
accessResource('/getEnvironments', null, setEnvironments);
575574
// and now load the system select boxes
@@ -956,7 +955,7 @@ function populateTable(statusCode, displayList, parameters){
956955
// get next item
957956
var currentItem = itemList[index];
958957
//create a description icon if a description exists
959-
var itemDescription = currentItem['Description'] ? '<img src="/img/info.png" id="descriptionIcon" tooltip="'+ currentItem['Description'].replace(/"/g, '&quot;') + '">' : '<img src="/img/empty.png" id="noDescriptionIcon">';
958+
var itemDescription = currentItem['Description'] ? '<img src="/img/info.png" id="descriptionIcon" tooltip="'+ currentItem['Description'].replace(/"/g, '&quot;') + '" width="12">' : '<img src="/img/empty.png" id="noDescriptionIcon" width="12">';
960959
// create a warning icon if there are warnings about this item
961960
var itemWarning = '&nbsp;&nbsp;';
962961
// if there are any issues about this item
@@ -983,7 +982,7 @@ function populateTable(statusCode, displayList, parameters){
983982
}
984983
}
985984
// finalize the warning item
986-
itemWarning += '">';
985+
itemWarning += '" width="11">';
987986
} else{
988987
itemWarning += '<img src="/img/empty.png" id="noWarningIcon" width="11">';
989988
}
@@ -998,7 +997,7 @@ function populateTable(statusCode, displayList, parameters){
998997
'" name="' + currentItem['Display name'] +
999998
'"><td>' + currentItem['Display name'] +
1000999
' (' + currentItem["Number of members"] +
1001-
')</td><td class="noBreak">' + itemDescription + itemWarning + '&nbsp;&nbsp;<img src="/img/empty.png" id="noStatusIcon">' + // so far no status icon for grouping elements
1000+
')</td><td class="noBreak">' + itemDescription + itemWarning + '&nbsp;&nbsp;<img src="/img/empty.png" id="noStatusIcon" width="12">' + // so far no status icon for grouping elements
10021001
'</td><td>' + currentItem['Display date'] +
10031002
'</td><td class="right">' + currentItem['Version'] +
10041003
'</td></tr>';
@@ -1009,8 +1008,8 @@ function populateTable(statusCode, displayList, parameters){
10091008
'" itemId="' + currentItem['Id'] +
10101009
'" name="' + (currentItem['Function name'] || currentItem['Display name']) +
10111010
'" style="color:' + ((currentItem['Is disabled']) ? 'LightSlateGray' : 'black') +
1012-
';"><td>' + (currentItem['Function name'] || currentItem['Display name']) +
1013-
'</td><td class="noBreak">' + itemDescription + itemWarning + '&nbsp;&nbsp;<img src="/img/empty.png" id="statusIcon">' +
1011+
';"><td' + (currentItem['Is disabled'] ? ' title="Channel is disabled"' : '') + '>' + (currentItem['Function name'] || currentItem['Display name']) +
1012+
'</td><td class="noBreak">' + itemDescription + itemWarning + '&nbsp;&nbsp;<img src="/img/empty.png" id="statusIcon" width="12">' +
10141013
'</td><td>' + currentItem['Display date'] +
10151014
'</td> <td class="right">' + currentItem['Version'] +
10161015
'</td></tr>';
@@ -2618,15 +2617,45 @@ function encrypt(text) {
26182617
}
26192618

26202619
var INTERVAL_ID;
2621-
const refreshIntervalInSeconds = 5;
2620+
// The frequency in seconds that is used for updating the channel state
2621+
var refreshIntervalInSeconds = 5;
26222622

2623+
/**
2624+
If channels are displayed and the automatic channel status update is not active, it will be activated
2625+
*/
26232626
function activateChannelStatusUpdates(){
2624-
if($('input[name = "compType"]:checked').val().startsWith('channel')){
2625-
requestChannelStatusUpdates()
2627+
// deactivate any already existing update
2628+
deactivateChannelStatusUpdates();
2629+
var componentType = $('input[name = "compType"]:checked');
2630+
// if channels are displayed
2631+
if(componentType.val() && componentType.val().startsWith('channel')){
2632+
// update channel state
2633+
requestChannelStatusUpdates(false);
2634+
// and activate the automatic update
2635+
INTERVAL_ID = setInterval(requestChannelStatusUpdates, refreshIntervalInSeconds * 1000);
26262636
}
26272637
}
26282638

2629-
function requestChannelStatusUpdates(){
2639+
/**
2640+
If the automatic channel status update is active, it will be deactivated
2641+
*/
2642+
function deactivateChannelStatusUpdates(){
2643+
if(INTERVAL_ID){
2644+
clearInterval(INTERVAL_ID);
2645+
INTERVAL_ID = null;
2646+
}
2647+
}
2648+
2649+
/**
2650+
Updates the channel status of all channels of all shown mirth instances
2651+
2652+
@param {boolean} silentMode - This flag can be used to determine if a busy indicator will be shown while the status is updated (default: true)
2653+
*/
2654+
function requestChannelStatusUpdates(silentMode){
2655+
2656+
if(!silentMode){
2657+
silentMode = true;
2658+
}
26302659

26312660
// get the name of the left mirth instance
26322661
var systemLeft = $('#sourceSystem option:selected');
@@ -2643,7 +2672,7 @@ function requestChannelStatusUpdates(){
26432672
parameters.right = systemRight.val();
26442673
}
26452674
if(payload.length){
2646-
accessResource('/getChannelState', payload, setChannelStatus, parameters);
2675+
accessResource('/getChannelState', payload, setChannelStatus, parameters, false, silentMode);
26472676
}
26482677

26492678
}
@@ -2682,13 +2711,15 @@ function setChannelStatus(statusCode, channelStatusList, instances){
26822711
if(statusIcon){
26832712
// determine the channel state. If the channel state is not in the list, the channel is undeployed
26842713
let imageName = channelStates[channelId] && channelStates[channelId].toLowerCase() || 'undeployed';
2685-
// for states that are currently changing, animated gifs are used
2686-
imageName += imageName.endsWith('ing') ? '.gif' : '.png';
2687-
// set the image
2688-
statusIcon.attr('src', '/img/' + imageName);
2714+
var imageSource = '/img/' + imageName + '.png';
2715+
// no need to reset unchanged values - this would only interupt animations
2716+
if(statusIcon.attr('src') != imageSource){
2717+
// set the image
2718+
statusIcon.attr('src', imageSource);
2719+
// and inform the user also via hint about the channel state
2720+
statusIcon.attr('title', 'Channel is ' + imageName);
2721+
}
26892722
}
2690-
});
2691-
2723+
});
26922724
});
2693-
26942725
}

0 commit comments

Comments
 (0)