<commit_before>var login_url = "http://kbase.us/services/authorization/Sessions/Login/";
var shock_url = "https://kbase.us/services/shock-api";
var upload_url = shock_url + "/node";
var cdmi_url = "http://kbase.us/services/cdmi_api/";

var cdmi_api = new CDMI_API(cdmi_url);
var cdmi_entity_api = new CDMI_EntityAPI(cdmi_url);

var defaultUserData = {
    auth_token: null,
    user_id: null
};
var filecount = 0;

/* BEGIN UTILITY functions */

$(window).load(function(){
		   //clear the default CSS associated with the blockUI loading element so we can insert ours
		   $.blockUI.defaults.css = {};
		   $(document).ajaxStop($.unblockUI);
		   $('#tabs').tab();
		   // Initialize the browsing datagrid when it is shown
		   $('#tabs a[href="#browse"]').on('shown', function (e) {
						       $('#ShockGrid').datagrid( { dataSource: ShockDataSrc });
						       $('#ShockGrid').popover( { selector: '.has-popover',
										  trigger: 'click',
										  content: function() {
										      console.log( this);
										      return("<pre>"+$(this).attr('data-content2')+"</pre>");
										      },
										  html: true,
										  placement: 'bottom',
										  template: '<div class="popover"><div class="popover-inner mypopover-inner"><div class="popover-content"><p></p></div></div></div>'
									    });
						   });
		   $(".form-signin").keypress(function(event) {
						  if (event.which == 13) {
						      event.preventDefault();
						      login($('#kbase_username').val(),$('#kbase_password').val());
						  }
					      });
		   $('#clearform').on('click',clearForm);
		   $("#upload").submit( function(event) {
					    event.preventDefault();
					    var d = new Date();
					    $("#upload_date").val(d.toJSON());
					    var attrs = Object();
					    $("#upload").find(':input').not(':button, :submit').each(function(i){
													 attrs[$(this).attr('id')] = $(this).val()
												     });
					    // Strip out unwanted form fields from attrs that go into Shock
					    [undefined,'datafile','fid','newtag'].map( function(attr) {
											   delete attrs[ attr];
										       });
					    // Read in the fields being managed by pillbox widgets
					    ['tags','related_kbid'].map( function(attr) {
									     field = $('#'+attr);
									     attrs[attr] = field.pillbox('items').map( function(item) { return(item.text) } )
									 });
					    var datafile = $("#datafile")[0];
					    
					    if ($("#datafile")[0].files[0] == undefined) {
						alert("Please choose a file for upload")
					    } else {
						$("#upload_progress").show();
						console.log( attrs);
						upload(datafile,attrs,localStorage['auth_token']);
						clearForm();
					    }
					});
		   $('#related_kbid').val("");
		   $("#fid").keypress(function(event) {
					  if (event.which == 13) {
					      event.preventDefault();
					      var newfid = $("#fid").val();
					      $('#kbid_check').attr("class","label label-info").text("Checking").show();
					      // Is this a Genome or a Gene id?
					      var validator;
					      if (newfid.match(/^kb\|g\.\d+$/)) {
						  validator = isKBaseGenome;
					      } else {
						  validator = isKBaseGene;
					      }
					      validator( newfid,
							 function() {
							     $('#kbidlist').append($('<li>').text(newfid));
							     $("#fid").val("");
							     $('#kbid_check').attr("class","label label-success").text("ID OK").fadeOut(3000);
							 },
							 function(res) {
							     console.log( newfid + " is not a legitimate KBase Genome ID");
							     $('#kbid_check').attr("class","label label-important").text("Bad ID").fadeOut(3000);
							 });
					  }
				      });
		   $("#newtag").keypress(function(event) {
					     if (event.which == 13) {
						 event.preventDefault();
						 var newtag = $("#newtag").val();
						 $('#newtag_check').attr("class","label label-info").text("Checking").show();
						 if ( newtag.match(/^\w[\w\-\:]*$/) ) {
						     $("#taglist").append($('<li>').text(newtag));
						     $("#newtag").val("");
						     $('#newtag_check').attr("class","label label-success").text("Tag OK").fadeOut(3000);
						 } else {
						     $('#newtag_check').attr("class","label label-important").text("Bad Tag").fadeOut(3000);
						 }
					     }
					 });
		   checkLogin();
	       });

function clearForm() {
    $(':input','#upload').not(':button, :submit, :hidden, :reset, [readonly]')
	.val('')
	.removeAttr('checked')
	.removeAttr('selected');
    $('#related_kbid').empty();
    $('#taglist').empty();
    $('#kbid_check').css('visibility','hidden');
    $('#tag_check').css('visibility','hidden');
    
}


// fileInputElement is the form field where the user selected the file
// attributes is a hash containing the metadata attributes
// authToken is a legit OAuth authentication token
function upload(fileInputElement,attributes,authToken) {
    var xhr = new XMLHttpRequest();
    xhr.open('POST', upload_url, true); // Here we would use the Shock node ID
    xhr.setRequestHeader('Authorization', 'OAuth ' + authToken);

    // Append a new row for this upload to the upload progress table
    uptable = $('#uploads').find('tbody');
    ++filecount;
    fileName = fileInputElement.files[0].name;
    uptable.append($('<tr>')
		   .append($('<td><h6>'+fileName+'</h6></td>'))
		   .append($('<td>')
			   .append($('<progress min="0" max="100" style="width: 300px;">')
				   .attr('id','progressBar'+filecount)))
		   .append($('<td>')
			   .append($('<h6>Uploading</h6>').attr('id','upload_status'+filecount)))
		   .append($('<td>')
			   .append($('<button class="btn">Cancel</button>').attr('id','cancel'+filecount)))
		  );
    $("#cancel"+filecount).on('click',function(e) {
				  $("#cancel"+filecount).hide();
				  xhr.abort();
			      });

    xhr.onload = function(e) {
	if (this.status == 200) {
	    console.log(this.response);
	    response = JSON.parse( this.response);
	    $("#upload_status"+filecount).text("Shock ID = " + response.D.id);
	    $("#cancel"+filecount).hide();
	}
    };
    var progressBar = $("#progressBar"+filecount);
    xhr.upload.onprogress = function(e) {
	if (e.lengthComputable) {
	    progressBar.val(e.loaded /e.total * 100);
	    $("#upload_status"+filecount).text(e.loaded+" of "+e.total+" bytes");
	}
    };
    xhr.addEventListener("error", function(evt) { 
			     $('#upload_status'+filecount).text('Error during upload');
			 }, false);
    xhr.addEventListener("abort", function(evt) { 
			     $('#upload_status'+filecount).text('Upload aborted');
			 }, false);
    
    var fd = new FormData();
    fd.append("upload", fileInputElement.files[0]);
    var attrFileBody = JSON.stringify(attributes); // the body of the new file...
    var attrBlob = new Blob([attrFileBody], { type: "application/json" });
    fd.append('attributes', attrBlob, fileInputElement.files[0].name + ".attributes" );
    xhr.send(fd);
    $("#progress_display").scrollTop($("#progress_display")[0].scrollHeight);
}

// Datasource for FuelUX datagrid
var ShockDataSrc = new Object();

// Mapping function from column names to how to field values
ShockDataSrc._colmap = {
    'Shock ID' : function (item) { return(item.id); },
    'Actions' : function (item) {
	var info = JSON.stringify( item, undefined, 2);
	var html='<i rel=\"popover\" data-content2=\'' + info + '\' class="icon-search has-popover"/>' +
	         '<i id=\"trash-' + item.id + '\" class="icon-trash"/>';
	return( html );
    },
    'Filename' : function (item) { return(item.file.name); },
    'Size' : function (item) { return( item.file.size); },
    'Description' : function (item) { return( item.attributes.Description ); },
    'Owner' : function (item) { return( item.attributes.owner);},
    'Related KBaseIDs' : function(item) { return( item.attributes.related_kbid ? item.attributes.related_kbid.join(', ') : ''); },
    'Tags' : function(item) { return( item.attributes.tags ? item.attributes.tags.join(', ') : ''); }
}

ShockDataSrc._results = Object();
<commit_msg>    Scrubbed off the parens and curly braces from the popover info.<commit_after>var login_url = "http://kbase.us/services/authorization/Sessions/Login/";
var shock_url = "https://kbase.us/services/shock-api";
var upload_url = shock_url + "/node";
var cdmi_url = "http://kbase.us/services/cdmi_api/";

var cdmi_api = new CDMI_API(cdmi_url);
var cdmi_entity_api = new CDMI_EntityAPI(cdmi_url);

var defaultUserData = {
    auth_token: null,
    user_id: null
};
var filecount = 0;

/* BEGIN UTILITY functions */

$(window).load(function(){
		   //clear the default CSS associated with the blockUI loading element so we can insert ours
		   $.blockUI.defaults.css = {};
		   $(document).ajaxStop($.unblockUI);
		   $('#tabs').tab();
		   // Initialize the browsing datagrid when it is shown
		   $('#tabs a[href="#browse"]').on('shown', function (e) {
						       $('#ShockGrid').datagrid( { dataSource: ShockDataSrc });
						       $('#ShockGrid').popover( { selector: '.has-popover',
										  trigger: 'click',
										  content: function() {
										      console.log( this);
										      return("<pre>"+$(this).attr('data-content2')+"</pre>");
										      },
										  html: true,
										  placement: 'bottom',
										  template: '<div class="popover"><div class="popover-inner mypopover-inner"><div class="popover-content"><p></p></div></div></div>'
										});
						   });
		   $(".form-signin").keypress(function(event) {
						  if (event.which == 13) {
						      event.preventDefault();
						      login($('#kbase_username').val(),$('#kbase_password').val());
						  }
					      });
		   $('#clearform').on('click',clearForm);
		   $("#upload").submit( function(event) {
					    event.preventDefault();
					    var d = new Date();
					    $("#upload_date").val(d.toJSON());
					    var attrs = Object();
					    $("#upload").find(':input').not(':button, :submit').each(function(i){
													 attrs[$(this).attr('id')] = $(this).val()
												     });
					    // Strip out unwanted form fields from attrs that go into Shock
					    [undefined,'datafile','fid','newtag'].map( function(attr) {
											   delete attrs[ attr];
										       });
					    // Read in the fields being managed by pillbox widgets
					    ['tags','related_kbid'].map( function(attr) {
									     field = $('#'+attr);
									     attrs[attr] = field.pillbox('items').map( function(item) { return(item.text) } )
									 });
					    var datafile = $("#datafile")[0];
					    
					    if ($("#datafile")[0].files[0] == undefined) {
						alert("Please choose a file for upload")
					    } else {
						$("#upload_progress").show();
						console.log( attrs);
						upload(datafile,attrs,localStorage['auth_token']);
						clearForm();
					    }
					});
		   $('#related_kbid').val("");
		   $("#fid").keypress(function(event) {
					  if (event.which == 13) {
					      event.preventDefault();
					      var newfid = $("#fid").val();
					      $('#kbid_check').attr("class","label label-info").text("Checking").show();
					      // Is this a Genome or a Gene id?
					      var validator;
					      if (newfid.match(/^kb\|g\.\d+$/)) {
						  validator = isKBaseGenome;
					      } else {
						  validator = isKBaseGene;
					      }
					      validator( newfid,
							 function() {
							     $('#kbidlist').append($('<li>').text(newfid));
							     $("#fid").val("");
							     $('#kbid_check').attr("class","label label-success").text("ID OK").fadeOut(3000);
							 },
							 function(res) {
							     console.log( newfid + " is not a legitimate KBase Genome ID");
							     $('#kbid_check').attr("class","label label-important").text("Bad ID").fadeOut(3000);
							 });
					  }
				      });
		   $("#newtag").keypress(function(event) {
					     if (event.which == 13) {
						 event.preventDefault();
						 var newtag = $("#newtag").val();
						 $('#newtag_check').attr("class","label label-info").text("Checking").show();
						 if ( newtag.match(/^\w[\w\-\:]*$/) ) {
						     $("#taglist").append($('<li>').text(newtag));
						     $("#newtag").val("");
						     $('#newtag_check').attr("class","label label-success").text("Tag OK").fadeOut(3000);
						 } else {
						     $('#newtag_check').attr("class","label label-important").text("Bad Tag").fadeOut(3000);
						 }
					     }
					 });
		   checkLogin();
	       });

function clearForm() {
    $(':input','#upload').not(':button, :submit, :hidden, :reset, [readonly]')
	.val('')
	.removeAttr('checked')
	.removeAttr('selected');
    $('#related_kbid').empty();
    $('#taglist').empty();
    $('#kbid_check').css('visibility','hidden');
    $('#tag_check').css('visibility','hidden');
    
}


// fileInputElement is the form field where the user selected the file
// attributes is a hash containing the metadata attributes
// authToken is a legit OAuth authentication token
function upload(fileInputElement,attributes,authToken) {
    var xhr = new XMLHttpRequest();
    xhr.open('POST', upload_url, true); // Here we would use the Shock node ID
    xhr.setRequestHeader('Authorization', 'OAuth ' + authToken);

    // Append a new row for this upload to the upload progress table
    uptable = $('#uploads').find('tbody');
    ++filecount;
    fileName = fileInputElement.files[0].name;
    uptable.append($('<tr>')
		   .append($('<td><h6>'+fileName+'</h6></td>'))
		   .append($('<td>')
			   .append($('<progress min="0" max="100" style="width: 300px;">')
				   .attr('id','progressBar'+filecount)))
		   .append($('<td>')
			   .append($('<h6>Uploading</h6>').attr('id','upload_status'+filecount)))
		   .append($('<td>')
			   .append($('<button class="btn">Cancel</button>').attr('id','cancel'+filecount)))
		  );
    $("#cancel"+filecount).on('click',function(e) {
				  $("#cancel"+filecount).hide();
				  xhr.abort();
			      });

    xhr.onload = function(e) {
	if (this.status == 200) {
	    console.log(this.response);
	    response = JSON.parse( this.response);
	    $("#upload_status"+filecount).text("Shock ID = " + response.D.id);
	    $("#cancel"+filecount).hide();
	}
    };
    var progressBar = $("#progressBar"+filecount);
    xhr.upload.onprogress = function(e) {
	if (e.lengthComputable) {
	    progressBar.val(e.loaded /e.total * 100);
	    $("#upload_status"+filecount).text(e.loaded+" of "+e.total+" bytes");
	}
    };
    xhr.addEventListener("error", function(evt) { 
			     $('#upload_status'+filecount).text('Error during upload');
			 }, false);
    xhr.addEventListener("abort", function(evt) { 
			     $('#upload_status'+filecount).text('Upload aborted');
			 }, false);
    
    var fd = new FormData();
    fd.append("upload", fileInputElement.files[0]);
    var attrFileBody = JSON.stringify(attributes); // the body of the new file...
    var attrBlob = new Blob([attrFileBody], { type: "application/json" });
    fd.append('attributes', attrBlob, fileInputElement.files[0].name + ".attributes" );
    xhr.send(fd);
    $("#progress_display").scrollTop($("#progress_display")[0].scrollHeight);
}

// Datasource for FuelUX datagrid
var ShockDataSrc = new Object();

// Mapping function from column names to field values
ShockDataSrc._colmap = {
    'Shock ID' : function (item) { return(item.id); },
    'Actions' : function (item) {
	var info = JSON.stringify( item, undefined, 2).replace(/\n?\s*[\{\}\[\]],?/g,'');
	var html='<i rel=\"popover\" data-content2=\'' + info + '\' class="icon-search has-popover"/>' +
	         '<i id=\"trash-' + item.id + '\" class="icon-trash"/>';
	return( html );
    },
    'Filename' : function (item) {return(item.file.name);},
    'Size' : function (item) { return( item.file.size); },
    'Description' : function (item) { return( item.attributes.Description ); },
    'Owner' : function (item) { return( item.attributes.owner);},
    'Related KBaseIDs' : function(item) { return( item.attributes.related_kbid ? item.attributes.related_kbid.join(', ') : ''); },
    'Tags' : function(item) { return( item.attributes.tags ? item.attributes.tags.join(', ') : ''); }
}

ShockDataSrc._results = Object();

{'fraction_non_alphanumeric': 0.20290661719233147, 'fraction_numerical': 0.006184291898577613, 'mean_word_length': 2.8121169259783123, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 57, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3605755', 'n_tokens_mistral': 6120, 'n_tokens_neox': 4935, 'n_words': 945}