2020-12-23 22:54:11 +08:00
|
|
|
var ProbeResults;
|
2017-10-28 11:52:08 +08:00
|
|
|
|
|
|
|
function probe( url_e ) {
|
2020-12-23 22:54:11 +08:00
|
|
|
$j.getJSON(thisUrl + '?view=request&request=add_monitors&action=probe&url=' + url_e.value)
|
|
|
|
.done(getProbeResponse)
|
|
|
|
.fail(logAjaxFail);
|
2017-10-28 11:52:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function getProbeResponse( respObj, respText ) {
|
2017-11-17 09:39:48 +08:00
|
|
|
if ( checkStreamForErrors( "getProbeResponse", respObj ) ) {
|
2017-10-28 11:52:08 +08:00
|
|
|
return;
|
2017-11-17 09:39:48 +08:00
|
|
|
}
|
2017-10-28 11:52:08 +08:00
|
|
|
|
2018-01-26 01:14:21 +08:00
|
|
|
if ( respObj.Streams && respObj.Streams.length ) {
|
2017-10-28 11:52:08 +08:00
|
|
|
parseStreams( respObj.Streams );
|
2018-02-09 22:08:24 +08:00
|
|
|
} else {
|
|
|
|
var results_div = $j('#results')[0];
|
|
|
|
if ( ! results_div ) {
|
|
|
|
console.log("No results div found.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
results_div.innerHTML = 'No streams found.';
|
2019-01-19 23:32:40 +08:00
|
|
|
//console.log("No streams: " + respText);
|
2017-10-28 11:52:08 +08:00
|
|
|
}
|
|
|
|
} // end function getProbeResponse
|
|
|
|
|
|
|
|
function parseStreams( Streams ) {
|
2019-01-19 23:32:40 +08:00
|
|
|
ProbeResults = Array();
|
2017-10-28 11:52:08 +08:00
|
|
|
|
2019-01-19 23:32:40 +08:00
|
|
|
var results_div = $j('#results')[0];
|
|
|
|
if ( ! results_div ) {
|
|
|
|
console.log("No results div found.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
results_div.innerHTML = '';
|
|
|
|
var html = '';
|
2019-01-18 23:00:55 +08:00
|
|
|
|
2019-01-19 23:32:40 +08:00
|
|
|
for ( i in Streams ) {
|
|
|
|
var stream = Streams[i];
|
|
|
|
if ( stream.url ) {
|
|
|
|
html += '<p>'+stream.Monitor.Name + ' at ' + stream.url;
|
|
|
|
if ( stream.Monitor.Id ) {
|
|
|
|
html += ' is already entered into the system by Monitor ' + stream.Monitor.Id + ' ' + stream.Monitor.Name + '<br/>';
|
|
|
|
html += '<input type="button" value="Edit" onclick="addMonitor(\''+stream.url+'\');"/>';
|
2017-10-28 11:52:08 +08:00
|
|
|
} else {
|
2019-01-19 23:32:40 +08:00
|
|
|
html += '<input type="button" value="Add" onclick="addMonitor(\''+stream.url+'\');"/>';
|
2017-10-28 11:52:08 +08:00
|
|
|
}
|
2019-01-19 23:32:40 +08:00
|
|
|
html += '</p>';
|
|
|
|
ProbeResults[stream.url] = stream;
|
|
|
|
} else {
|
|
|
|
//console.log(stream);
|
|
|
|
}
|
|
|
|
} // end for eah Stream
|
2019-01-18 23:00:55 +08:00
|
|
|
|
2019-01-19 23:32:40 +08:00
|
|
|
results_div.innerHTML = html;
|
2017-10-28 11:52:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function addMonitor(url) {
|
|
|
|
if ( ! ProbeResults[url] ) {
|
|
|
|
alert("Monitor for url " + url + " not found in probe results." );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var Stream = ProbeResults[url];
|
|
|
|
var Monitor = Stream.Monitor;
|
|
|
|
|
2018-02-09 22:08:24 +08:00
|
|
|
var mid = Monitor.Id ? Monitor.Id : '';
|
2020-09-30 23:40:13 +08:00
|
|
|
urlString = '?view=monitor&mid='+mid+'&newMonitor[Path]='+url;
|
2017-10-28 11:52:08 +08:00
|
|
|
keys = Object.keys( Monitor );
|
|
|
|
for ( i in Monitor ) {
|
2019-01-19 23:32:40 +08:00
|
|
|
if ( ! Monitor[i] ) {
|
2017-10-28 11:52:08 +08:00
|
|
|
continue;
|
2019-01-19 23:32:40 +08:00
|
|
|
}
|
|
|
|
if ( Monitor[i] == 'null' ) {
|
2017-10-28 11:52:08 +08:00
|
|
|
Monitor[i]='';
|
2019-01-19 23:32:40 +08:00
|
|
|
}
|
2020-09-30 23:40:13 +08:00
|
|
|
urlString += '&newMonitor['+i+']='+Monitor[i];
|
2017-10-28 11:52:08 +08:00
|
|
|
}
|
2020-09-30 23:40:13 +08:00
|
|
|
window.location.assign( urlString );
|
2017-10-28 11:52:08 +08:00
|
|
|
}
|
2019-01-18 23:00:55 +08:00
|
|
|
|
2017-10-28 11:52:08 +08:00
|
|
|
function import_csv( form ) {
|
|
|
|
var formData = new FormData( form );
|
|
|
|
console.log(formData);
|
|
|
|
|
|
|
|
$j.ajax({
|
2019-01-19 23:32:40 +08:00
|
|
|
url: thisUrl+"?request=add_monitors&action=import",
|
|
|
|
type: 'POST',
|
|
|
|
data: formData,
|
|
|
|
processData: false, // tell jQuery not to process the data
|
|
|
|
contentType: false, // tell jQuery not to set contentType
|
2020-12-23 22:54:11 +08:00
|
|
|
done: function(data) {
|
2019-01-19 23:32:40 +08:00
|
|
|
var json = JSON.parse(data);
|
|
|
|
parseStreams( json.Streams );
|
|
|
|
}
|
2017-10-28 11:52:08 +08:00
|
|
|
});
|
|
|
|
}
|
2020-12-23 22:54:11 +08:00
|
|
|
|
2018-02-09 22:08:24 +08:00
|
|
|
function initPage() {
|
2020-12-23 22:54:11 +08:00
|
|
|
var url = $j('#Url')[0];
|
|
|
|
|
2018-02-09 22:08:24 +08:00
|
|
|
if ( url.value ) {
|
|
|
|
probe(url);
|
|
|
|
}
|
|
|
|
}
|
2020-12-23 22:54:11 +08:00
|
|
|
|
|
|
|
$j(document).ready(initPage);
|