<commit_before>/**
 * Just a simple example widget to display an expression series
 *
 */
/*global
 define
 */
/*jslint
 browser: true,
 white: true
 */
define([
    'jquery',
    'bluebird',
    'kb_common/html',
    'kb_common/utils',
    'kb_service/client/workspace',
    'kb_service/workspaceClient',
    'kbaseUI/widget/legacy/widget',
    'kbaseUI/widget/legacy/tabs',

    'datatables_bootstrap'
], function ($, Promise, html, Utils, Workspace, workspaceClient) {
    'use strict';
    $.KBWidget({
        name: 'kbaseExpressionSeries',
        parent: 'kbaseWidget',
        version: '1.0.0',
        options: {
            color: 'black'
        },
        init: function (options) {
            this._super(options);
            var workspace = new Workspace(this.runtime.getConfig('services.workspace.url'), {
                    token: this.runtime.service('session').getAuthToken()
                }),
                wsClient = Object.create(workspaceClient).init({
                    url: this.runtime.getConfig('services.workspace.url'),
                    authToken: this.runtime.service('session').getAuthToken()
                }),
                name = options.name,
                container = this.$elem;

            container.html(html.loading());

            function buildTable(data, refhash) {
                return Promise.try(function () {
                    container.empty();
                    var tabs = container.kbTabs({
                            tabs: [
                                { name: 'Overview', active: true },
                                { name: 'ExpressionSeries', content: html.loading() }
                            ]
                        }),
                        // Code to displaying overview data
                        keys = [
                            { key: 'wsid' },
                            { key: 'ws' },
                            { key: 'kbid' },
                            { key: 'source' },
                            { key: 'genome' },
                            { key: 'type' },
                            { key: 'errors' },
                            { key: 'owner' },
                            { key: 'date' }
                        ],
                        wsObj = data[0][0],
                        genome = Object.keys(wsObj.data.genome_expression_sample_ids_map)[0],
                        phenooverdata = {
                            wsid: wsObj.info[1],
                            ws: wsObj.info[7],
                            kbid: wsObj.data.regulome_id,
                            source: wsObj.data.source,
                            genome: genome,
                            type: wsObj.data.type,
                            errors: wsObj.data.importErrors,
                            owner: wsObj.creator,
                            date: wsObj.created
                        },
                        labels = [
                            'Name',
                            'Workspace',
                            'KBID',
                            'Source',
                            'Genome',
                            'Type',
                            'Errors',
                            'Owner',
                            'Creation date'
                        ],
                        table = Utils.objTable({ obj: phenooverdata, keys: keys, labels: labels }),
                        series = wsObj.data.genome_expression_sample_ids_map[genome],
                        sample_refs = [];

                    tabs.tabContent('Overview').append(table);

                    for (var i = 0; i < series.length; i++) {
                        sample_refs.push({ ref: series[i] });
                    }
                    return Promise.resolve(workspace.get_objects(sample_refs)).then(function (sample_data) {
                        // container.rmLoading();
                        //container.empty();
                        //container.append(pcTable);
                        // create a table from the sample names
                        var pcTable = $('<table class="table table-bordered table-striped" style="width: 100%;">');
                        tabs.setContent({ name: 'ExpressionSeries', content: pcTable });
                        var tableSettings = {
                            sPaginationType: 'full_numbers',
                            iDisplayLength: 10,
                            aaData: sample_data,
                            aaSorting: [[0, 'asc']],
                            aoColumns: [
                                {
                                    sTitle: 'Gene Expression Samples',
                                    mData: function (d) {
                                        return d.data.id;
                                    }
                                }
                            ],
                            oLanguage: {
                                sEmptyTable: 'No objects in workspace',
                                sSearch: 'Search: '
                            }
                        };
                        pcTable.dataTable(tableSettings);
                        // container.html(tabs);
                    });
                });
            }

            workspace
                .get_objects([{ workspace: options.ws, name: options.name }])
                .then(function (data) {
                    var reflist = data[0].refs;
                    return new Promise.all([data, wsClient.translateRefs(reflist)]);
                })
                .then(function (data, refhash) {
                    return buildTable(data, refhash);
                })
                .catch(function (e) {
                    // container.rmLoading();
                    console.error(e);
                    container.append('<div class="alert alert-danger">' + e.error.message + '</div>');
                });

            return this;
        }
    });
});<commit_msg>repair file, mark html() usage as safe, make error message safe [UFI-5] however, I can't find an expression series object suppored in the narrative so can't test<commit_after>define([
    'jquery',
    'bluebird',
    'kb_common/html',
    'kb_common/utils',
    'kb_service/client/workspace',
    'kb_service/workspaceClient',
    'lib/domUtils',

    // For effect
    'kbaseUI/widget/legacy/widget',
    'kbaseUI/widget/legacy/tabs',
    'datatables_bootstrap'
], ($, Promise, html, Utils, Workspace, workspaceClient, {domSafeText}) => {
    $.KBWidget({
        name: 'kbaseExpressionSeries',
        parent: 'kbaseWidget',
        version: '1.0.0',
        options: {
            color: 'black'
        },
        init(options) {
            this._super(options);
            const workspace = new Workspace(this.runtime.getConfig('services.workspace.url'), {
                    token: this.runtime.service('session').getAuthToken()
                }),
                wsClient = Object.create(workspaceClient).init({
                    url: this.runtime.getConfig('services.workspace.url'),
                    authToken: this.runtime.service('session').getAuthToken()
                }),
                container = this.$elem;

            // safe
            container.html(html.loading());

            function buildTable(data) {
                return Promise.try(() => {
                    container.empty();
                    const tabs = container.kbTabs({
                            tabs: [
                                {name: 'Overview', active: true},
                                {name: 'ExpressionSeries', content: html.loading()}
                            ]
                        }),
                        // Code to displaying overview data
                        keys = [
                            {key: 'wsid'},
                            {key: 'ws'},
                            {key: 'kbid'},
                            {key: 'source'},
                            {key: 'genome'},
                            {key: 'type'},
                            {key: 'errors'},
                            {key: 'owner'},
                            {key: 'date'}
                        ],
                        wsObj = data[0][0],
                        genome = Object.keys(wsObj.data.genome_expression_sample_ids_map)[0],
                        phenooverdata = {
                            wsid: wsObj.info[1],
                            ws: wsObj.info[7],
                            kbid: wsObj.data.regulome_id,
                            source: wsObj.data.source,
                            genome,
                            type: wsObj.data.type,
                            errors: wsObj.data.importErrors,
                            owner: wsObj.creator,
                            date: wsObj.created
                        },
                        labels = [
                            'Name',
                            'Workspace',
                            'KBID',
                            'Source',
                            'Genome',
                            'Type',
                            'Errors',
                            'Owner',
                            'Creation date'
                        ],
                        table = Utils.objTable({obj: phenooverdata, keys, labels}),
                        series = wsObj.data.genome_expression_sample_ids_map[genome],
                        sample_refs = [];

                    tabs.tabContent('Overview').append(table);

                    for (let i = 0; i < series.length; i++) {
                        sample_refs.push({ref: series[i]});
                    }
                    return Promise.resolve(workspace.get_objects(sample_refs)).then((sample_data) => {
                        // container.rmLoading();
                        //container.empty();
                        //container.append(pcTable);
                        // create a table from the sample names
                        const pcTable = $('<table class="table table-bordered table-striped" style="width: 100%;">');
                        tabs.setContent({name: 'ExpressionSeries', content: pcTable});
                        const tableSettings = {
                            sPaginationType: 'full_numbers',
                            iDisplayLength: 10,
                            aaData: sample_data,
                            aaSorting: [[0, 'asc']],
                            aoColumns: [
                                {
                                    sTitle: 'Gene Expression Samples',
                                    mData(d) {
                                        return d.data.id;
                                    }
                                }
                            ],
                            oLanguage: {
                                sEmptyTable: 'No objects in workspace',
                                sSearch: 'Search: '
                            }
                        };
                        pcTable.dataTable(tableSettings);
                    });
                });
            }

            workspace
                .get_objects([{workspace: options.ws, name: options.name}])
                .then((data) => {
                    const reflist = data[0].refs;
                    return new Promise.all([data, wsClient.translateRefs(reflist)]);
                })
                .then((data, refhash) => {
                    return buildTable(data, refhash);
                })
                .catch((e) => {
                    console.error(e);
                    container.append(`<div class="alert alert-danger">${domSafeText(e.error.message)}</div>`);
                });

            return this;
        }
    });
});
{'fraction_non_alphanumeric': 0.10578707609245824, 'fraction_numerical': 0.0027838704234857434, 'mean_word_length': 0.8946779606840339, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2499462', 'n_tokens_mistral': 2819, 'n_tokens_neox': 2598, 'n_words': 496}