<commit_before>/*global document,$,alert,window,JSON */

// Global experiment data
var current_experiment = {};

// Supported input file types
var POLY_FILES  = [ "vcf", "gcvf" ];
var ALIGN_FILES = [ "bam" ];
var SEQ_FILES   = [ "fastq", "fq", "sra" ];
var QUANT_FILES = [ "csv", "tsv", "bed", "wig", "bw", "gff", "gtf" ];
var SUPPORTED_FILE_TYPES = Array.prototype.concat.call(QUANT_FILES, ALIGN_FILES, SEQ_FILES, POLY_FILES);

function create_source() {
    var name = $('#edit_source_name').val();
    var desc = $('#edit_source_desc').val();
    var link = $('#edit_source_link').val();
    $.ajax({
        data: {
            fname: 'create_source',
            name: name,
            desc: desc,
            link: link,
        },
        success : function(name) {
            $('#create_new_source_dialog').dialog('close');
            if (name) {
                $('#edit_source').val(name);
            }
        }
    });
}

function search_genomes (search_term) {
	if (!search_term || search_term.length < 3)
		return;
	
	var edit_genome = $("#edit_genome");
	edit_genome.autocomplete("close");
	var spinner = $('#edit_genome_busy');
	spinner.show();
	
	coge.services.search_genomes(search_term, { fast: true, sort: true })
		.done(function(response) { // success
			if (response && response.genomes) {
				var results = response.genomes.map(function(obj) {
					var label = obj.info.replace(/&#x1f512;/g, "\uD83D\uDD12"); // Lock symbol // TODO make client-side like certified & favorite
					if (obj.certified)
					    label = '\u2705 ' + label;
                    if (obj.favorited)
					    label = '\u2B50 ' + label;
					return { label: label, value: obj.id };
				});
				edit_genome
					.autocomplete({source: results})
					.autocomplete("search");
			}
			spinner.hide();
		})
		.fail(function() { // error
			//TODO
		});
}

function search_users (search_term) {
	coge.services.search_users(search_term)
		.done(function(result) {
			if (result && result.users) {
				var transformed = result.users.map(function(obj) {
					return obj.user_name;
				});
				$("#edit_user")
					.autocomplete({source: transformed})
					.autocomplete("search");
			}
		})
		.fail(function() {
			//TODO
		});
}

function search_notebooks (search_term) {
	coge.services.search_notebooks(search_term)
		.done(function(data) { 
			if (data.notebooks) {
				var items = [];
				data.notebooks.forEach(function(notebook) {
					items.push({label:notebook.name,value:notebook.id});
			    });
			    $("#edit_notebook")
			    	.autocomplete({source: items})
			    	.autocomplete("search");
			}
		})
		.fail(function() {
			//TODO
		});
}

function activate_on_input(elements, target) {
	if (elements) {
		elements.forEach(function(e) {
			if ($('#'+e).val())
				$('#'+target).removeClass('ui-state-disabled');
		});
	}
}

function render_template(template, container) {
    container.empty()
    .hide()
    .append(template)
    .show();//.slideDown();
}

function ExperimentDescriptionView(opts) {
    this.experiment = opts.experiment;
    this.metadata = opts.metadata;
    //this.gid = opts.gid;
    this.onError = opts.onError;
    this.sources = undefined;
    this.title = "Describe experiment";
    this.initialize();
}

$.extend(ExperimentDescriptionView.prototype, {
    initialize: function() {
        this.el = $($("#description-template").html());
        this.edit_source = this.el.find("#edit_source");
        this.edit_genome = this.el.find("#edit_genome");
        this.get_sources();
    },<commit_msg>Captialize "Describe experiment"<commit_after>/*global document,$,alert,window,JSON */

// Global experiment data
var current_experiment = {};

// Supported input file types
var POLY_FILES  = [ "vcf", "gcvf" ];
var ALIGN_FILES = [ "bam" ];
var SEQ_FILES   = [ "fastq", "fq", "sra" ];
var QUANT_FILES = [ "csv", "tsv", "bed", "wig", "bw", "gff", "gtf" ];
var SUPPORTED_FILE_TYPES = Array.prototype.concat.call(QUANT_FILES, ALIGN_FILES, SEQ_FILES, POLY_FILES);

function create_source() {
    var name = $('#edit_source_name').val();
    var desc = $('#edit_source_desc').val();
    var link = $('#edit_source_link').val();
    $.ajax({
        data: {
            fname: 'create_source',
            name: name,
            desc: desc,
            link: link,
        },
        success : function(name) {
            $('#create_new_source_dialog').dialog('close');
            if (name) {
                $('#edit_source').val(name);
            }
        }
    });
}

function search_genomes (search_term) {
	if (!search_term || search_term.length < 3)
		return;
	
	var edit_genome = $("#edit_genome");
	edit_genome.autocomplete("close");
	var spinner = $('#edit_genome_busy');
	spinner.show();
	
	coge.services.search_genomes(search_term, { fast: true, sort: true })
		.done(function(response) { // success
			if (response && response.genomes) {
				var results = response.genomes.map(function(obj) {
					var label = obj.info.replace(/&#x1f512;/g, "\uD83D\uDD12"); // Lock symbol // TODO make client-side like certified & favorite
					if (obj.certified)
					    label = '\u2705 ' + label;
                    if (obj.favorited)
					    label = '\u2B50 ' + label;
					return { label: label, value: obj.id };
				});
				edit_genome
					.autocomplete({source: results})
					.autocomplete("search");
			}
			spinner.hide();
		})
		.fail(function() { // error
			//TODO
		});
}

function search_users (search_term) {
	coge.services.search_users(search_term)
		.done(function(result) {
			if (result && result.users) {
				var transformed = result.users.map(function(obj) {
					return obj.user_name;
				});
				$("#edit_user")
					.autocomplete({source: transformed})
					.autocomplete("search");
			}
		})
		.fail(function() {
			//TODO
		});
}

function search_notebooks (search_term) {
	coge.services.search_notebooks(search_term)
		.done(function(data) { 
			if (data.notebooks) {
				var items = [];
				data.notebooks.forEach(function(notebook) {
					items.push({label:notebook.name,value:notebook.id});
			    });
			    $("#edit_notebook")
			    	.autocomplete({source: items})
			    	.autocomplete("search");
			}
		})
		.fail(function() {
			//TODO
		});
}

function activate_on_input(elements, target) {
	if (elements) {
		elements.forEach(function(e) {
			if ($('#'+e).val())
				$('#'+target).removeClass('ui-state-disabled');
		});
	}
}

function render_template(template, container) {
    container.empty()
    .hide()
    .append(template)
    .show();//.slideDown();
}

function ExperimentDescriptionView(opts) {
    this.experiment = opts.experiment;
    this.metadata = opts.metadata;
    //this.gid = opts.gid;
    this.onError = opts.onError;
    this.sources = undefined;
    this.title = "Describe Experiment";
    this.initialize();
}

$.extend(ExperimentDescriptionView.prototype, {
    initialize: function() {
        this.el = $($("#description-template").html());
        this.edit_source = this.el.find("#edit_source");
        this.edit_genome = this.el.find("#edit_genome");
        this.get_sources();
    },
{'fraction_non_alphanumeric': 0.1716302046577276, 'fraction_numerical': 0.004516584333098095, 'mean_word_length': 2.9127553837658753, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '5502867', 'n_tokens_mistral': 2651, 'n_tokens_neox': 2336, 'n_words': 416}