-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrenderer.js
466 lines (388 loc) · 16.9 KB
/
renderer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
// This file is required by the index.html file and will
// be executed in the renderer process for that window.
// No Node.js APIs are available in this process because
// `nodeIntegration` is turned off. Use `preload.js` to
// selectively enable features needed in the rendering
// process.
const ipc = require('electron').ipcRenderer
// var outputdata = [];
var stringbuffer = "";
var HOLDFLAG = false;
// form
const form = document.querySelector('form')
// buttons
const check = document.getElementById('connection')
const searchbtn = document.getElementById('searchbtn')
const copymsg = document.getElementById('copymsg')
const clearconsole = document.getElementById('clearconsole')
const alertboxbtn=document.querySelector('#closealert')
// Inputs
const region = document.querySelector("#region")
const profile = document.querySelector("#profile")
const sqsqueue = document.querySelector("#sqsqueue")
const msgno = document.querySelector("#msgno")
const filter = document.querySelector("#filterbox")
const filterhelper = document.querySelector("#filterinfo")
const searchbox = document.querySelector("#searchbox")
const outbox = document.querySelector("#outbox")
const searchresult = document.querySelector("#searchresult")
check.addEventListener('click',checkconnection);
searchbtn.addEventListener('click', searchText);
// when filterinfo is clicked display show a message in alertsection
filterhelper.addEventListener('click', function(){
$("#alertsection").html(
'<div class="alert alert-info alert-dismissible" id="exception"><button type="button" class="close" data-dismiss="alert" id="closealert">×</button><strong>How Filter Works! </strong> <span class="alerttext"></span></div>'
);
$(".alerttext").last().text("Filter is applied on the downloaded messages. \n\n To get all matching messages from the queue, please select -1 in the No of Messages field");
})
function resetByNames(...names){
names.forEach(name => {
name.value = ""
});
}
function checkconnection(c){
c.preventDefault();
// Check the value of region and profile and if anything is empty then throw an alert
if(region.value == '' || profile.value == '')
{
// put the focus back to the empty field
if(region.value == '')
{
region.focus()
// change the color of the border
region.style.boxShadow = "0 0 10px crimson";
}
else
{
profile.focus()
// nod effect
profile.style.boxShadow = "0 0 10px crimson";
}
}
else
{
// Remove the focus and the border color
region.style.boxShadow = "0 0 0px";
profile.style.boxShadow = "0 0 0px";
// clear the output box
outbox.textContent = "";
ipc.send('connectivity', region.value, profile.value)
// hide the connection button
check.setAttribute('hidden', true)
// disable the region and profile fields
region.setAttribute('disabled', true)
profile.setAttribute('disabled', true)
resetByNames(msgno,filter,searchbox,outbox,sqsqueue)
}
}
// list.addEventListener('click',getallqueues);
function getallqueues(q){
const region = document.querySelector("#region").value
const profile = document.querySelector("#profile").value
ipc.send('getqueueslist', region, profile)
////console.log(region,profile)
}
// to search the text in the output box
function searchText(s) {
console.log("Search has come",s)
const search = document.getElementById('searchbox').value;
const outbox = document.getElementById('outbox');
const instance = new Mark(outbox);
instance.unmark(); // remove any previous marks
instance.mark(search);
// no of matches
var matches = document.getElementsByTagName("mark").length
if (matches < 1){
searchresult.innerHTML = "<span style='color: white; background-color: #e76ebc; padding: 1%''>No Matches Found</span>"
}else{
searchresult.innerHTML = "<span style='color: black; background-color: greenyellow; padding: 1%'>Matches Found: "+matches+"</span>"
}
// scroll the output box to the searched text
var element = document.querySelector("mark");
element.scrollIntoView();
}
form.addEventListener('submit',submitform);
function submitform(e){
e.preventDefault();
const msgno = document.querySelector("#msgno").value
const sqsqueue = document.querySelector("#sqsqueue").value
const region = document.querySelector("#region").value
const profile = document.querySelector("#profile").value
const filter = document.querySelector("#filterbox").value
// if the values are empty then highlight the fields with red border shadow
if(msgno == '' || sqsqueue == '' || sqsqueue == 'Select Queue')
{
if(sqsqueue == '' || sqsqueue == 'Select Queue')
{
document.querySelector("#sqsqueue").focus()
// change the color of the border
document.querySelector("#sqsqueue").style.boxShadow = "0 0 10px crimson";
}
// put the focus back to the empty field
else if(msgno == '')
{
document.querySelector("#msgno").focus()
// change the color of the border
document.querySelector("#msgno").style.boxShadow = "0 0 10px crimson";
}
} else if (msgno < 1 || msgno > 10000)
{
if (msgno != -1)
{
document.querySelector("#msgno").focus()
// change the color of the border
document.querySelector("#msgno").style.boxShadow = "0 0 10px crimson";
alert("Please enter a valid number \n\n -1 to list all messages \n or \n any number between 1 to 10000")
} else {
ipc.send('listqueue', msgno, sqsqueue, region, profile, filter)
}
}
else
{
// Remove the focus and the border color
document.querySelector("#msgno").style.boxShadow = "0 0 0px";
document.querySelector("#sqsqueue").style.boxShadow = "0 0 0px";
ipc.send('listqueue', msgno, sqsqueue, region, profile, filter)
}
}
const shell = require('electron').shell;
$(document).on('click', 'a[href^="http"]', function(event) {
event.preventDefault();
shell.openExternal(this.href);
});
function pageScroll() {
window.scrollBy(0,100);
// scrolldelay = setTimeout(pageScroll,10);
}
function resetAll(){
$("#sqsqueue").html('<option selected>Select Queue</option>')
$("#getqueues").attr('hidden', true)
$("#selectqueue").attr('hidden', true)
$("#noofmessages").attr('hidden', true);
$("#actionbtn").attr('hidden', true);
$("#barprogress").attr('hidden', true);
$("#filter").attr('hidden', true);
$("#outbox").html("");
$("#connection").attr('hidden', false)
$("#searchbox").val("");
$("#noofmessages").val("");
$("#filterbox").val("");
$("#msgno").val("");
$("#profile").val("");
// enable the region and profile fields
$("#region").removeAttr('disabled');
$("#profile").removeAttr('disabled');
}
$( document ).ready(function() {
////console.log( "Renderer is ready!" );
const regions=['us-east-1','us-east-2','us-west-1','us-west-2','af-south-1','ap-east-1','ap-south-1','ap-northeast-3','ap-northeast-2','ap-southeast-1','ap-southeast-2','ap-northeast-1','ca-central-1','eu-central-1','eu-west-1','eu-west-2','eu-south-1','eu-west-3','eu-north-1','me-south-1','sa-east-1']
regions.forEach((e,index) => {
$("#region").append(
'<option class="region">Select Queue</option>'
);
$(".region").last().text(e.toString());
});
});
ipc.on('exception',function(event, data){
if(data == "Error: Could not load credentials from any providers")
{
$("#alertsection").html(
'<div class="alert alert-danger alert-dismissible" id="exception"><button type="button" class="close" data-dismiss="alert" id="closealert">×</button><strong>Error!</strong> <span class="alerttext"></span></div>'
);
$(".alerttext").last().text("No profile exists with the given name");
pageScroll()
}
else if(data == "Error: The security token included in the request is invalid.")
{
$("#alertsection").html(
'<div class="alert alert-danger alert-dismissible" id="exception"><button type="button" class="close" data-dismiss="alert" id="closealert">×</button><strong>Error!</strong> <span class="alerttext"></span></div>'
);
$(".alerttext").last().text("Security token in invalid. Please select another Region.");
}
else
{
$("#alertsection").html(
'<div class="alert alert-danger alert-dismissible" id="exception"><button type="button" class="close" data-dismiss="alert" id="closealert">×</button><strong>Error!</strong> <span class="alerttext"></span></div>'
);
$(".alerttext").last().text(data);
}
resetAll()
//$(".alerttext").last().text(data.toString());
})
ipc.on("connectivity", function(event, data){
if(data.httpStatusCode == 200)
{
// $("#getqueues").removeAttr('hidden');
$("#alertsection").html(
'<div class="alert alert-success alert-dismissible" id="exception"><button type="button" class="close" data-dismiss="alert" id="closealert">×</button><strong>Hurray!</strong> <span class="alerttext">sometext</span></div>'
);
$(".alerttext").last().text("Connection Established");
}
// call getallqueues
getallqueues(event);
})
ipc.on("queueinfo", function(event, data){
////console.log("QueueInfo has come",data)
$("#alertsection").html(
'<div class="alert alert-info alert-dismissible" id="exception"><button type="button" class="close" data-dismiss="alert" id="closealert">×</button><strong>Queue Stats!</strong> <span class="alerttext">sometext</span></div>'
);
$(".alerttext").last().text(data);
})
ipc.on("noMessages", function(event, data){
alert(data);
})
ipc.on("barProgress", function(event, data){
////console.log(data);
$("#barprogress").attr('hidden', false);
$("#barprogress").html('<div class="progress-bar progress-bar-striped progress-bar-animated bg-danger" role="progressbar" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100" style="width: 100%"></div>')
$(".progress-bar").attr('style', data);
$(".progress-bar").last().text(data.replace( /^\D+/g, ''));
// disable alert box
$("#alertsection").html("");
})
ipc.on("getqueueslist", function(event, data){
$("#sqsqueue").empty();
if(typeof(data)=='undefined')
{
$("#alertsection").html(
'<div class="alert alert-danger alert-dismissible" id="exception"><button type="button" class="close" data-dismiss="alert" id="closealert">×</button><strong>Error!</strong> <span class="alerttext"></span></div>'
);
$(".alerttext").last().text("There are no Queues to list !!!");
}
else {
$("#sqsqueue").append('<option class="queue">Select Queue</option>');
data.forEach((e,index) => {
$("#sqsqueue").append(
'<option class="queue">Select Queue</option>'
);
$(".queue").last().text(e.slice(e.lastIndexOf("/") + 1).toString());
});
$("#selectqueue").removeAttr('hidden');
$("#noofmessages").removeAttr('hidden');
$("#actionbtn").removeAttr('hidden');
$("#filter").removeAttr('hidden');
}
})
ipc.on("finalList", function(event, data){
//console.log("Final List has come",data)
$("#alertsection").html(
'<div class="alert alert-success alert-dismissible" id="exception"><button type="button" class="close" data-dismiss="alert" id="closealert">×</button><strong>Queue Stats!</strong> <span class="alerttext">sometext</span></div>'
);
$(".alerttext").last().text(data);
})
function applyFilter(dataarray){
var filtered = []
dataarray.forEach((e, index) => {
if (e.Body.includes(filter.value))
{
filtered.push(e)
}
});
return filtered
}
no_of_times_called = 1
ipc.on('listqueue', function(event, response){
var filtered = []
// Initialize the string buffer
stringbuffer = "";
stringbuffer+="\n-----------------------------------"
stringbuffer+="\nQueue Name :"+sqsqueue.value
stringbuffer+="\nRegion :"+region.value
stringbuffer+="\nprofile :"+profile.value
if (filter.value != ""){
stringbuffer+="\nfilter :"+filter.value
response['messages'] = applyFilter(response['messages'])
stringbuffer+="\nMessages Matching Filters: "+response['messages'].length
}
stringbuffer+="\nTotal Messages in the Queue: "+response['stats']['TotalMessages']
stringbuffer+="\nMessages On Transit: "+response['stats']['OnTransit']
stringbuffer+="\nNo of Messages requested: "+document.querySelector("#msgno").value
stringbuffer+="\n-----------------------------------"
resetAll()
if(response['messages'].length === 0 && response['stats']['TotalMessages'] === 0)
{
stringbuffer+="\n The Queue is Empty - No Messages to display"
}
else if (response['messages'].length === 0 && response['stats']['TotalMessages'] > 0 )
{
stringbuffer+="\n Queue has "+response['stats']['TotalMessages']+" messages but no messages matching the filter criteria"
}
else
{
let data = response['messages'];
data.forEach((e, index) => {
msgcount=index+1
//console.log(e);
//console.log("Message Count:"+msgcount)
stringbuffer+="\n-----------------------------------"
stringbuffer+="\nMessage Number => "+msgcount
stringbuffer+="\n-----------------------------------\n"
// outputdata.push(JSON.parse(e.Body).Message);
////console.log(JSON.stringify(outputdata, replacer))
//console.log(typeof(e));
//console.log(e); // it is always a String
if (IsJsonString(e.Body) || typeof(e.Body) == 'object'){
////console.log(JSON.stringify(JSON.parse(e.Body), undefined, 2))
stringbuffer+="\nSender ID: "+e.Attributes.SenderId
stringbuffer+="\nMessage ID: "+e.MessageId
stringbuffer+="\nMessage Body: "+JSON.stringify(JSON.parse(e.Body), undefined, 2)
stringbuffer+="\n-----------------------------------"
stringbuffer+="\n\n"
}
else{
//console.log(e.Body)
stringbuffer+="\nSender ID: "+e.Attributes.SenderId
stringbuffer+="\nMessage ID: "+e.MessageId
stringbuffer+="\nMessage Body: "+e.Body
stringbuffer+="\n-----------------------------------"
stringbuffer+="\n\n"
}
});
}
outbox.textContent=stringbuffer
// oldcontent=outbox.textContent
})
//To validate if Message is a JSON data
function IsJsonString(str) {
try {
JSON.parse(str);
} catch (e) {
return false;
}
return true;
}
function replacer(key, value) {
//console.log(value.toString())
return value.toString()
//return value.toString().replace(/[^\w\s]/gi, '');
}
// //console.log(ipc.sendSync('synchronous-message', 'ping')) // prints "pong"
// ipc.on('asynchronous-reply', (event, arg) => {
// //console.log(arg) // prints "pong"
// })
// ipc.send('asynchronous-message', 'ping')
$('div.alert.close').on('click', function() {
//console.log("clicked")
$(this).parent().alert('close');
});
$('#clearconsole').on('click',function(){
outbox.textContent=""
location.reload()
})
$('#copymsg').on('click',function(){
const copyText = document.getElementById("outbox").textContent;
if(copyText){
const textArea = document.createElement('textarea');
textArea.textContent = copyText;
document.body.append(textArea);
textArea.select();
document.execCommand("copy");
$("#alertsection").html(
'<div class="alert alert-info alert-dismissible" id="exception"><button type="button" class="close" data-dismiss="alert" id="closealert">×</button><strong>Info!</strong> <span class="alerttext"></span></div>'
);
$(".alerttext").last().text("Content Copied to the clipboard");
}
else {
alert("There is no messages to copy right now")
}
})