/* * Project Name : Visual Python * Description : GUI-based Python code generator * File Name : Import.js * Author : Black Logic * Note : Apps > Import * License : GNU GPLv3 with Visual Python special exception * Date : 2021. 11. 18 * Change Date : */ //============================================================================ // [CLASS] Import //============================================================================ define([ __VP_CSS_LOADER__('vp_base/css/m_apps/import'), // INTEGRATION: unified version of css loader 'vp_base/js/com/com_util', 'vp_base/js/com/com_Const', 'vp_base/js/com/com_String', 'vp_base/js/com/component/PopupComponent' ], function(importCss, com_util, com_Const, com_String, PopupComponent) { const importTemplates = { 'data-analysis': [ { i0: 'numpy', i1: 'np', type: 'module', checked: 'checked'}, { i0: 'pandas', i1: 'pd', type: 'module', checked: 'checked'}, { i0: 'matplotlib.pyplot', i1: 'plt', type: 'module' , include: [ '%matplotlib inline' ], checked: 'checked' }, { i0: 'seaborn', i1: 'sns', type: 'module', checked: 'checked'}, { i0: 'plotly.express', i1: 'px', type: 'module' , include: [ 'from plotly.offline import init_notebook_mode', 'init_notebook_mode(connected=True)' ], checked: '' }, { i0: 'pyarrow', i1: 'pa', type: 'module', checked: ''}, ], 'machine-learning': [ { i0: 'sklearn.model_selection', i1: 'train_test_split', type: 'function', checked: 'checked' }, { i0: 'sklearn', i1: 'metrics', type: 'function', checked: 'checked' } ] } /** * Import */ class Import extends PopupComponent { _init() { super._init(); /** Write codes executed before rendering */ this.config.dataview = false; this.config.sizeLevel = 1; let savedData = vpConfig.getDataSimple('', 'vpimport'); // Reset abnormal data if (savedData == undefined || savedData.tabType == undefined) { savedData = {}; vpConfig.setData(null, 'vpimport'); } this.state = { tabType: 'data-analysis', importMeta: [], ...savedData, ...this.state } this.importTemplatesCopy = JSON.parse(JSON.stringify(importTemplates)); if (!this.state.importMeta || this.state.importMeta.length <= 0) { this.state.importMeta = JSON.parse(JSON.stringify(this.importTemplatesCopy[this.state.tabType])); } } _bindEvent() { super._bindEvent(); let that = this; // select tab $(this.wrapSelector('.vp-tab-button')).on('click', function() { let tabType = $(this).data('tab'); // set button selected that.state.tabType = tabType; $(that.wrapSelector('.vp-tab-button')).removeClass('vp-tab-selected'); $(this).addClass('vp-tab-selected'); // replace libraries that.state.importMeta = that.importTemplatesCopy[tabType]; $(that.wrapSelector('#vp_tblImport')).replaceWith(function() { return that.templateTable(that.state.importMeta); }); }); // delete lib $(this.wrapSelector()).on("click", '.vp-remove-option', function() { $(this).closest('tr').remove(); that.checkAll(); }); // check/uncheck all $(this.wrapSelector()).on('change', '#vp_libraryCheckAll', function() { var checked = $(this).prop('checked'); $(that.wrapSelector('.vp-item-check')).prop('checked', checked); }); // check item $(this.wrapSelector()).on('change', '.vp-item-check', function() { var checked = $(this).prop('checked'); // if unchecked at least one item, uncheck check-all if (!checked) { $(that.wrapSelector('.vp-check-all')).prop('checked', false); } else { // if all checked, check check-all that.checkAll(); } }); // add module $(this.wrapSelector('#vp_addModule')).click(function() { var libsLength = $(that.wrapSelector("#vp_tblImport tbody tr")).length; var tagTr = $(that.templateForModule(libsLength, '', '')); $(that.wrapSelector("#vp_tblImport tr:last")).after(tagTr); }); // add function $(this.wrapSelector('#vp_addFunction')).click(function() { var libsLength = $(that.wrapSelector("#vp_tblImport tbody tr")).length; var tagTr = $(that.templateForFunction(libsLength, '', '')); $(that.wrapSelector("#vp_tblImport tr:last")).after(tagTr); }); } checkAll() { // check if all checked // if all checked, check check-all var allLength = $(this.wrapSelector('.vp-item-check')).length; var checkedLength = $(this.wrapSelector('.vp-item-check:checked')).length; if (allLength == checkedLength) { $(this.wrapSelector('.vp-check-all')).prop('checked', true); } else { $(this.wrapSelector('.vp-check-all')).prop('checked', false); } } templateForBody() { /** Implement generating template */ var page = new com_String(); // tab buttons page.appendLine('
| ', 'vp_libraryCheckAll'); page.appendLine(' | '); page.appendLine(' |
|---|