<commit_before>'use strict';

define(['kbwidget', 'jquery', 'bootstrap', 'kbaseAuthenticatedWidget', 'kbaseTabTableTabs'],
function(KBWidget, $, bootstrap, kbaseAuthenticatedWidget, kbaseTabTableTabs) {
return KBWidget({
    name: "kbaseTabTable",
    parent : kbaseAuthenticatedWidget,
    version: "1.0.0",
    options: {
    },

    init: function(input) {

        this._super(input);
        var self = this;
        var $tableContainer = $('<div>');
        this.$elem.append($tableContainer);

        // root url path for landing pages
        var DATAVIEW_URL = '/functional-site/#/dataview/';

        var type = input.type;

        // tab widget
        var tabs;

        var kbModeling = new KBModeling( self.authToken() );

        // kbase api helper
        this.kbapi = kbModeling.kbapi;

        //
        // 1) Use type (periods replaced with underscores) to instantiate a modeling object
        //
        this.obj = new kbModeling[type.replace(/\./g, '_')](self);

        //
        // 2) add the tabs (at page load)
        //
        var tabList = this.obj.tabList;

        var uiTabs = [];
        for (var i = 0; i < tabList.length; i++) {
            var tab = tabList[i];

            // add loading status
            var placeholder = $('<div>')
            placeholder.loading();

            uiTabs.push({name: tabList[i].name, content: placeholder});
        }

        uiTabs[0].active = true;
        //tabs = self.$elem.kbaseTabTableTabs({tabs: uiTabs});
        tabs = new kbaseTabTableTabs($tableContainer, {tabs : uiTabs});


        //
        // 3) get meta data, add any metadata tables
        //
        if (isNaN(input.ws) && isNaN(input.obj) )
            var param = {workspace: input.ws, name: input.obj};
        else if (!isNaN(input.ws) && !isNaN(input.obj) )
            var param = {ref: input.ws+'/'+input.obj};

        self.kbapi('ws', 'get_object_info_new', {objects: [param], includeMetadata: 1})
          .done(function(res) {
              self.obj.setMetadata(res[0]);

              for (var i = 0; i < tabList.length; i++) {
                  var spec = tabList[i];

                  if (spec.type == 'verticaltbl') {
                      var key = spec.key,
                          data = self.obj[key],
                          tabPane = tabs.tabContent(spec.name);

                      var table = self.verticalTable({rows: spec.rows, data: data});
                      tabPane.rmLoading();
                      tabPane.append(table)
                  }
              }
          })

        //
        // 4) get object data, create tabs
        //
        if (isNaN(input.ws) && isNaN(input.obj) )
            var param = {workspace: input.ws, name: input.obj};
        else if (!isNaN(input.ws) && !isNaN(input.obj) )
            var param = {ref: input.ws+'/'+input.obj};

        self.kbapi('ws', 'get_objects', [param])
          .done(function(data){
              var setMethod = self.obj.setData(data[0].data, tabs);

              // see if setData method returns promise or not
              if (setMethod && 'done' in setMethod) {
                  setMethod.done(function() {
                      buildContent()
                  })
              } else {
                  buildContent();
              }
        })

        var refLookup = {};
        function preProcessDataTable(tabSpec,tabPane) {
            // get refs
            var refs = [];
            var cols = tabSpec.columns;
            cols.forEach(function(col){
                if ((col.type === 'tabLink' || col.type === 'wstype') && col.linkformat === 'dispWSRef') {
                    self.obj[tabSpec.key].forEach(function(item) {
                        if (refs.indexOf(item[col.key]) === -1) {
                        	refs.push( {ref: item[col.key]} );
                        }
                    })
                }
            })

            if (!refs.length)
                return;

            // get human readable info from workspaces
            return self.kbapi('ws', 'get_object_info_new', {objects: refs})
                       .then(function(data) {
                            refs.forEach(function(ref, i){
                                // if (ref in referenceLookup) return
                                refLookup[ref.ref] = {name: data[i][1],
                                                      ws: data[i][7],
                                                      type: data[i][2].split('-')[0],
                                                      //link: data[i][2].split('-')[0]+'/'+data[i][7]+'/'+data[i][1]
                                                      link: data[i][7]+'/'+data[i][1]};
                            })
                            createDataTable(tabSpec, tabPane);
                       })
        }

        function buildContent(data) {

            //5) Iterates over the entries in the spec and instantiate things
            for (var i = 0; i < tabList.length; i++) {
                var tabSpec = tabList[i];
                var tabPane = tabs.tabContent(tabSpec.name);

                // skip any vertical tables for now
                if (tabSpec.type == 'verticaltbl') continue;

                // if widget, invoke widget with arguments
                if (tabSpec.widget) {
                    tabPane[tabSpec.widget]( tabSpec.getParams() );
                    continue;
                }

                // preprocess data to get workspace info on any references in class
                var prom = preProcessDataTable(tabSpec,tabPane);
                if (!prom) {
                    createDataTable(tabSpec, tabPane);
                }

            }
        }

        // creates a datatable on a tabPane
        function createDataTable(tabSpec, tabPane) {
            var settings = self.getTableSettings(tabSpec, self.obj.data);
            tabPane.rmLoading();

            // note: must add table first
            tabPane.append('<table class="table table-bordered table-striped" style="margin-left: auto; margin-right: auto;">');
            tabPane.find('table').dataTable(settings)

            // add any events
            newTabEvents(tabSpec.name);
        }

        // takes table spec and prepared data, returns datatables settings object
        this.getTableSettings = function(tab, data) {
            var tableColumns = getColSettings(tab);
<commit_msg>removed jquery deprecation warning<commit_after>'use strict';

define(['kbwidget', 'jquery', 'bootstrap', 'kbaseAuthenticatedWidget', 'kbaseTabTableTabs', 'kbasePathways'],
function(KBWidget, $, bootstrap, kbaseAuthenticatedWidget, kbaseTabTableTabs, kbasePathways) {
return KBWidget({
    name: "kbaseTabTable",
    parent : kbaseAuthenticatedWidget,
    version: "1.0.0",
    options: {
    },

    init: function(input) {

        this._super(input);
        var self = this;
        var $tableContainer = $('<div>');
        this.$elem.append($tableContainer);

        // root url path for landing pages
        var DATAVIEW_URL = '/functional-site/#/dataview/';

        var type = input.type;

        // tab widget
        var tabs;

        var kbModeling = new KBModeling( self.authToken() );

        // kbase api helper
        this.kbapi = kbModeling.kbapi;

        //
        // 1) Use type (periods replaced with underscores) to instantiate a modeling object
        //
        this.obj = new kbModeling[type.replace(/\./g, '_')](self);

        //
        // 2) add the tabs (at page load)
        //
        var tabList = this.obj.tabList;

        var uiTabs = [];
        for (var i = 0; i < tabList.length; i++) {
            var tab = tabList[i];

            // add loading status
            var placeholder = $('<div>')
            placeholder.loading();

            uiTabs.push({name: tabList[i].name, content: placeholder});
        }

        uiTabs[0].active = true;
        //tabs = self.$elem.kbaseTabTableTabs({tabs: uiTabs});
        tabs = new kbaseTabTableTabs($tableContainer, {tabs : uiTabs});


        //
        // 3) get meta data, add any metadata tables
        //
        if (isNaN(input.ws) && isNaN(input.obj) )
            var param = {workspace: input.ws, name: input.obj};
        else if (!isNaN(input.ws) && !isNaN(input.obj) )
            var param = {ref: input.ws+'/'+input.obj};

        self.kbapi('ws', 'get_object_info_new', {objects: [param], includeMetadata: 1})
          .done(function(res) {
              self.obj.setMetadata(res[0]);

              for (var i = 0; i < tabList.length; i++) {
                  var spec = tabList[i];

                  if (spec.type == 'verticaltbl') {
                      var key = spec.key,
                          data = self.obj[key],
                          tabPane = tabs.tabContent(spec.name);

                      var table = self.verticalTable({rows: spec.rows, data: data});
                      tabPane.rmLoading();
                      tabPane.append(table)
                  }
              }
          })

        //
        // 4) get object data, create tabs
        //
        if (isNaN(input.ws) && isNaN(input.obj) )
            var param = {workspace: input.ws, name: input.obj};
        else if (!isNaN(input.ws) && !isNaN(input.obj) )
            var param = {ref: input.ws+'/'+input.obj};

        self.kbapi('ws', 'get_objects', [param])
          .done(function(data){
              var setMethod = self.obj.setData(data[0].data, tabs);

              // see if setData method returns promise or not
              if (setMethod && 'done' in setMethod) {
                  setMethod.done(function() {
                      buildContent()
                  })
              } else {
                  buildContent();
              }
        })

        var refLookup = {};
        function preProcessDataTable(tabSpec,tabPane) {
            // get refs
            var refs = [];
            var cols = tabSpec.columns;
            cols.forEach(function(col){
                if ((col.type === 'tabLink' || col.type === 'wstype') && col.linkformat === 'dispWSRef') {
                    self.obj[tabSpec.key].forEach(function(item) {
                        if (refs.indexOf(item[col.key]) === -1) {
                        	refs.push( {ref: item[col.key]} );
                        }
                    })
                }
            })

            if (!refs.length)
                return;

            // get human readable info from workspaces
            return self.kbapi('ws', 'get_object_info_new', {objects: refs})
                       .then(function(data) {
                            refs.forEach(function(ref, i){
                                // if (ref in referenceLookup) return
                                refLookup[ref.ref] = {name: data[i][1],
                                                      ws: data[i][7],
                                                      type: data[i][2].split('-')[0],
                                                      //link: data[i][2].split('-')[0]+'/'+data[i][7]+'/'+data[i][1]
                                                      link: data[i][7]+'/'+data[i][1]};
                            })
                            createDataTable(tabSpec, tabPane);
                       })
        }

        function buildContent(data) {

            //5) Iterates over the entries in the spec and instantiate things
            for (var i = 0; i < tabList.length; i++) {
                var tabSpec = tabList[i];
                var tabPane = tabs.tabContent(tabSpec.name);

                // skip any vertical tables for now
                if (tabSpec.type == 'verticaltbl') continue;

                // if widget, invoke widget with arguments
                
                if (tabSpec.widget) {
                  
                    new tabSpec.widget(tabPane, tabSpec.getParams() );
                    continue;
                }

                // preprocess data to get workspace info on any references in class
                var prom = preProcessDataTable(tabSpec,tabPane);
                if (!prom) {
                    createDataTable(tabSpec, tabPane);
                }

            }
        }

        // creates a datatable on a tabPane
        function createDataTable(tabSpec, tabPane) {
            var settings = self.getTableSettings(tabSpec, self.obj.data);
            tabPane.rmLoading();

            // note: must add table first
            tabPane.append('<table class="table table-bordered table-striped" style="margin-left: auto; margin-right: auto;">');
            tabPane.find('table').dataTable(settings)

            // add any events
            newTabEvents(tabSpec.name);
        }

        // takes table spec and prepared data, returns datatables settings object
        this.getTableSettings = function(tab, data) {
            var tableColumns = getColSettings(tab);

{'fraction_non_alphanumeric': 0.12552139657036923, 'fraction_numerical': 0.004016684690251815, 'mean_word_length': 1.3682092555331993, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '262450', 'n_tokens_mistral': 3588, 'n_tokens_neox': 3369, 'n_words': 802}