Commit a969061e authored by ba yaye-awa's avatar ba yaye-awa
Browse files

add connection to samp hub and launch jupyter url linked to the fitspath

parent 7926e75c
/*
** A set of classes and function definitions utilized by the
** differents flavours of SAMP.
**
** Author : Y. A. BA
** Date : 18th Septemner 2019
*/
/*
** Convert VOTABLE to HTML Format
*/
var DisplayVotable = function(xml){
var vDocEl = xml.documentElement;
var vTableEl = vDocEl.getElementsByTagName("TABLE")[0];
var vFieldEls = vTableEl.getElementsByTagName("FIELD");
var vTrEls = vTableEl.getElementsByTagName("TR");
var ncol = vFieldEls.length;
var nrow = vTrEls.length;
var ic;
var ir;
var tableHtml = '';
tableHtml += '<table border="1"><thead><tr>';
for(ic=0; ic< ncol; ic++){
tableHtml += "<th> <strong> " +vFieldEls[ic].getAttribute("name") +"</strong></th>" ;
}
tableHtml += "</tr></thead><tbody>";
var vTdEls;
for (ir = 0; ir < nrow; ir++) {
vTdEls = vTrEls[ir].getElementsByTagName("TD");
tableHtml += "<tr>";
for (ic = 0; ic < ncol; ic++) {
tableHtml += "<td>"+getTextContent(vTdEls[ic])+"</td>";
}
tableHtml += "</tr>";
}
tableHtml += "</tbody></table>";
return tableHtml;
};
var getTextContent = function(node) {
var txt = "";
var n;
for (n = node.firstChild; n; n = n.nextSibling) {
if (n.nodeType === 3 || // text
n.nodeType === 4) { // CDATA section
txt = txt + n.data;
}
}
return txt;
};
/*Retrieve list of Ra/Dec from Votable*/
var GetRaDecCoord = function(xml){
var vDocEl = xml.documentElement;
var vTableEl = vDocEl.getElementsByTagName("TABLE")[0];
var vFieldEls = vTableEl.getElementsByTagName("FIELD");
var vTrEls = vTableEl.getElementsByTagName("TR");
var ncol = vFieldEls.length;
var nrow = vTrEls.length;
var ic;
var ir;
var result = [];
var radec = {};
var numRa;
var numDec;
for(ic=0; ic< ncol; ic++){
if(vFieldEls[ic].getAttribute("ucd") == "pos.eq.ra")
numRa = ic;
else if(vFieldEls[ic].getAttribute("ucd") == "pos.eq.dec")
numDec = ic;
}
var vTdEls;
for (ir = 0; ir < nrow; ir++) {
vTdEls = vTrEls[ir].getElementsByTagName("TD");
radec.RAInDD = getTextContent(vTdEls[numRa]);
radec.DECInDD = getTextContent(vTdEls[numDec]);
result.push(radec);
}
return result;
}
......@@ -25,6 +25,7 @@
<!-- Conditional code generation -->
<%if(useSAMP){%>
<script src="../javascript/samp.js"></script>
<script src="../javascript/samp_utils.js"></script>
<%}%>
<!-- End of conditional code generation -->
......@@ -155,6 +156,7 @@
<div id="loading"></div>
<div id="FITSHDR" class="overlay" style="overflow:scroll"></div>
<div class="pos-f-t">
<div class="collapse" id="sampRegistry"></div>
<div class="collapse" id="navbarToggleExternalContent">
<div class="bg-dark p-4">
<% if (renderingCapabilities) { %>
......@@ -198,6 +200,8 @@
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarToggleExternalContent" aria-controls="navbarToggleExternalContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<img src="../samphub.png" style="width:30px; height:30px" data-toggle="collapse" data-target="#sampRegistry" aria-controls="sampRegistry" aria-expanded="false" aria-label="Toggle navigation"/>
<div><a id="jupyter" href="#" target="_blank"><img src="../jupyter.png" style="width:30px; height:30px" title="jupyter"/></a></div>
<div><a href="http://artemix.obspm.fr/fits/browse" target="_blank">See more FITS files...</a></div>
<div id="cubeInfos" style="font-size:15px; color: white"></div>
</nav>
......@@ -2279,7 +2283,7 @@ var SAMPPNGPublishControl = (function (Control) {
<%}%>
$( document ).ready(function() {
console.log("$( document ).ready(function() {: entering");
$("a#jupyter").attr("href", "https://romeo.obspm.fr:8500/user/partemix/notebooks/openURL.ipynb?kernel_name=python3&?Variable1="+relFITSFilePath+"&?kernel_name=python3");
/*
** Set up everything required to fill and display the FITS header.
*/
......@@ -2302,8 +2306,86 @@ var SAMPPNGPublishControl = (function (Control) {
var publishSpectrumDiv = "#publish_spectrum";
var publishSummedpixelsspectrumDiv ="#publish_summedpixelsspectrum";
var publishPngDiv = "div.samp-publish-png";
// Adjusts page content depending on whether the hub exists or not.
var configureSampEnabled = function(isHubRunning) {
document.getElementById("sampModal").hidden = !isHubRunning;
document.getElementById("sampModalAladin").hidden = !isHubRunning;
};
var cc = new samp.ClientTracker();
var callHandler = cc.callHandler;
callHandler["samp.app.ping"] = function(senderId, message, isCall) {
if (isCall) {
return {text: "ping to you, " + cc.getName(senderId)};
}
};
//receive a votable
callHandler["table.load.votable"] = function(senderId, message, isCall) {
var params = message["samp.params"];
var origUrl = params["url"];
var proxyUrl = cc.connection.translateUrl(origUrl);
var xhr = samp.XmlRpcClient.createXHR();
var e;
xhr.open("GET", proxyUrl);
xhr.onload = function() {
var xml = xhr.responseXML;
if (xml) {
try {
var data = {};
data.content = DisplayVotable(xml);
console.log('success '+data.content);
/*$.ajax({
type: 'POST',
data: JSON.stringify(data),
contentType: 'application/json',
url: 'http://localhost:3022/samp',
crossDomain: true,
success: function(data) {
console.log('success');
$('#resultTable').html( data.content);
}
});*/
}
catch (e) {
console.log("error "+ e);
}
}
else {
console.log("No XML response");
}
};
xhr.onerror = function(err) {
console.log("Error getting table " + origUrl + "\n" +
"(" + err + ")");
};
xhr.send(null);
};
var subs = cc.calculateSubscriptions();
//register in the hub
var meta = {
"samp.name": "Artemix:"+relFITSFilePath,
"samp.description":"Artemix is an ALMA data mining experiment prototype. its aim is to provide astronomers with a webservice that enables to quickly explore the ALMA scientific Archive.",
};
var connector = new samp.Connector("Artemix", meta, cc, subs);
$('#sampRegistry').append(connector.createRegButtons());
window.onload = function() {
connector.onHubAvailability(configureSampEnabled, 2000);
};
window.onbeforeunload = function() {
connector.unregister();
};
sAMPPublisher = new SAMPPublisher(header, publishSpectrumDiv, publishSummedpixelsspectrumDiv, connector );
sAMPPublisher.display();
/*var configureSampEnabled = function(isHubRunning) {
$(publishSpectrumDiv).click(function() {
console.log("click on publish spectrum button");
if(!isHubRunning){
......@@ -2340,7 +2422,7 @@ var SAMPPNGPublishControl = (function (Control) {
};
sAMPPublisher = new SAMPPublisher(header, publishSpectrumDiv, publishSummedpixelsspectrumDiv, connector );
sAMPPublisher.display();
sAMPPublisher.display();*/
<%}%>
document.getElementById('loading').style.display='block';
......
......@@ -23,6 +23,7 @@
<!-- Conditional code generation -->
<%if(useSAMP){%>
<script src="../javascript/samp.js"></script>
<script src="../javascript/samp_utils.js"></script>
<%}%>
<!-- End of conditional code generation -->
......@@ -113,6 +114,7 @@ th, td {
<div id="FITSHDR" class="overlay" style="overflow:scroll"></div>
<div class="pos-f-t">
<div class="collapse" id="sampRegistry"></div>
<div class="collapse" id="navbarToggleExternalContent">
<div class="bg-dark p-4">
<% if (renderingCapabilities) { %>
......@@ -161,6 +163,8 @@ th, td {
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarToggleExternalContent" aria-controls="navbarToggleExternalContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<img src="../samphub.png" style="width:30px; height:30px" data-toggle="collapse" data-target="#sampRegistry" aria-controls="sampRegistry" aria-expanded="false" aria-label="Toggle navigation"/>
<div><a id="jupyter" href="#" target="_blank"><img src="../jupyter.png" style="width:30px; height:30px" title="jupyter"></a></div>
<div><a href="http://artemix.obspm.fr/fits/browse" target="_blank">See more FITS files...</a></div>
<div id="cubeInfos" style="font-size:15px; color: white"></div>
</nav>
......@@ -955,6 +959,7 @@ var SAMPPublisher = function ( FITSHeader, connector) {
$( document ).ready(function() {
console.log("$( document ).ready(function() {: entering");
$("a#jupyter").attr("href", "https://romeo.obspm.fr:8500/user/partemix/notebooks/openURL.ipynb?kernel_name=python3&?Variable1="+relFITSFilePath+"&?kernel_name=python3");
<%if(useSAMP){%>
console.log("Yes we use SAMP");
<%}%>
......@@ -970,9 +975,89 @@ $( document ).ready(function() {
// Conditional code generation for SAMP publisher.
<%if(useSAMP){%>
var configureSampEnabled = function(isHubRunning) {
};
var configureSampEnabled = function(isHubRunning) {
};
var cc = new samp.ClientTracker();
var callHandler = cc.callHandler;
callHandler["samp.app.ping"] = function(senderId, message, isCall) {
if (isCall) {
return {text: "ping to you, " + cc.getName(senderId)};
}
};
//receive a votable
callHandler["table.load.votable"] = function(senderId, message, isCall) {
var params = message["samp.params"];
var origUrl = params["url"];
var proxyUrl = cc.connection.translateUrl(origUrl);
var xhr = samp.XmlRpcClient.createXHR();
var e;
xhr.open("GET", proxyUrl);
xhr.onload = function() {
var xml = xhr.responseXML;
if (xml) {
try {
//console.log(xml);
var arrayOfMarkers = GetRaDecCoord(xml);
let _marker_source_1 = new ol.source.Vector({wrapX: false});
let _marker_draw_1 = new ol.interaction.Draw({source: _marker_source_1, type:'Point'});
let _marker_index_1 = sliceViewer.getAllMarkers().length;
for(i=0;i<arrayOfMarkers.length;i++){
_marker_draw_1.on("drawend", event => {
let coord = arrayOfMarkers[i];
let withFlux = false;
_marker_index_1 += 1;
event.feature.set('label', 'M_'+_marker_index_1);
appendMarkerTA(DecDeg2HMS(coord["RAInDD"]), DecDeg2DMS(coord["DECInDD"]), 'm_'+_marker_index_1, coord["RAInDD"], coord["DECInDD"], null, false, header);
});
}
/*$.ajax({
type: 'POST',
data: JSON.stringify(data),
contentType: 'application/json',
url: 'http://localhost:3022/samp',
crossDomain: true,
success: function(data) {
console.log('success');
$('#resultTable').html( data.content);
}
});*/
}
catch (e) {
console.log("error "+ e);
}
}
else {
console.log("No XML response");
}
};
xhr.onerror = function(err) {
console.log("Error getting table " + origUrl + "\n" +
"(" + err + ")");
};
xhr.send(null);
};
var subs = cc.calculateSubscriptions();
//register in the hub
var meta = {
"samp.name": "Artemix:"+relFITSFilePath,
"samp.description":"Artemix is an ALMA data mining experiment prototype. its aim is to provide astronomers with a webservice that enables to quickly explore the ALMA scientific Archive.",
};
var connector = new samp.Connector("Artemix", meta, cc, subs);
$('#sampRegistry').append(connector.createRegButtons());
window.onload = function() {
connector.onHubAvailability(configureSampEnabled, 2000);
};
window.onbeforeunload = function() {
connector.unregister();
};
/*
var connector = new samp.Connector("Artemix");
onload = function() {
connector.onHubAvailability(configureSampEnabled, 2000);
......@@ -980,7 +1065,13 @@ $( document ).ready(function() {
onunload = function() {
connector.unregister();
};
};*/onload = function() {
connector.onHubAvailability(configureSampEnabled, 2000);
}
onunload = function() {
connector.unregister();
};
sAMPPublisher = new SAMPPublisher(header, connector );
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment