Skip to content

Commit 0448bd5

Browse files
author
minjk-bl
committed
Fix Instance app to work well on showing option
1 parent dada394 commit 0448bd5

File tree

2 files changed

+80
-136
lines changed

2 files changed

+80
-136
lines changed

visualpython/js/com/component/InstanceEditor.js

Lines changed: 73 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,6 @@ define([
289289

290290
// open option popup
291291
$(document).on('click', this.wrapSelector('.vp-ins-opt-button:not(.disabled)'), function(event) {
292-
// TODO: pdIdt_head to general
293292
if (that.optionPopup) {
294293
that.optionPopup.open();
295294
}
@@ -322,9 +321,80 @@ define([
322321
this.isFirstPage = false;
323322
this.renderPage();
324323
}
324+
var splitList = [];
325+
if (variable != '') {
326+
splitList = variable.split('.');
327+
}
328+
var hasOption = false;
329+
// get parameter
330+
if (splitList && splitList.length > 0) {
331+
var lastSplit = splitList[splitList.length - 1];
332+
// get target code
333+
var methodName = lastSplit.match(/[a-zA-Z_]+/i)[0];
334+
var targetCode = splitList.slice(0, splitList.length - 1).join('.');
335+
if ((prevVarType in instanceLibrary.INSTANCE_MATCHING_LIBRARY) && (methodName in instanceLibrary.INSTANCE_MATCHING_LIBRARY[prevVarType])) {
336+
// get target library
337+
var targetLib = instanceLibrary.INSTANCE_MATCHING_LIBRARY[prevVarType][methodName];
338+
var targetId = targetLib.target;
339+
var popupState = {
340+
config: {
341+
name: methodName, category: 'Instance',
342+
id: targetLib.id,
343+
saveOnly: true,
344+
noOutput: true
345+
}
346+
}
347+
// add targetid as state if exists
348+
if (targetId) {
349+
popupState[targetId] = targetCode;
350+
}
351+
that.optionPopup = new LibraryComponent(popupState,
352+
{
353+
pageThis: that,
354+
useInputVariable: true,
355+
targetSelector: that.pageThis.wrapSelector('#' + that.targetId),
325356

326-
var code = com_util.formatString('_vp_print(_vp_load_instance("{0}"))', variable);
357+
finish: function(code) {
358+
// set parameter
359+
let lastSplit = code?.split('.')?.pop();
360+
// if bracket is at the end of code
361+
let matchList = lastSplit.match(/\(.*?\)$/gi);
362+
if (matchList != null && matchList.length > 0) {
363+
let lastBracket = matchList[matchList.length - 1];
364+
// remove first/last brackets
365+
let parameter = lastBracket.substr(1, lastBracket.length - 2);
366+
$(that.wrapSelector('.' + VP_INS_PARAMETER)).val(parameter);
367+
}
368+
369+
$(that.pageThis.wrapSelector('#' + that.targetId)).trigger({
370+
type: "instance_editor_replaced",
371+
originCode: that.state.code,
372+
newCode: code
373+
});
374+
}
375+
}
376+
);
377+
hasOption = true;
378+
} else {
379+
that.optionPopup = null;
380+
}
327381

382+
if (hasOption) {
383+
if ($(that.wrapSelector('.vp-ins-opt-button')).hasClass('disabled')) {
384+
$(that.wrapSelector('.vp-ins-opt-button')).removeClass('disabled');
385+
}
386+
} else {
387+
if (!$(that.wrapSelector('.vp-ins-opt-button')).hasClass('disabled')) {
388+
$(that.wrapSelector('.vp-ins-opt-button')).addClass('disabled');
389+
}
390+
}
391+
} else {
392+
if (!$(that.wrapSelector('.vp-ins-opt-button')).hasClass('disabled')) {
393+
$(that.wrapSelector('.vp-ins-opt-button')).addClass('disabled');
394+
}
395+
}
396+
397+
var code = com_util.formatString('_vp_print(_vp_load_instance("{0}"))', variable);
328398
vpKernel.execute(code).then(function (resultObj) {
329399
let { result } = resultObj;
330400
var varObj = {
@@ -434,50 +504,8 @@ define([
434504
});
435505

436506
// get parameter
437-
var splitList = variable.split('.');
438-
// var hasOption = false;
439-
440507
if (splitList && splitList.length > 0) {
441508
var lastSplit = splitList[splitList.length - 1];
442-
// // get target code
443-
// var methodName = lastSplit.match(/[a-zA-Z_]+/i)[0];
444-
// var targetCode = splitList.slice(0, splitList.length - 1).join('.');
445-
// if ((prevVarType in instanceLibrary.INSTANCE_MATCHING_LIBRARY) && (methodName in instanceLibrary.INSTANCE_MATCHING_LIBRARY[prevVarType])) {
446-
// // get target library
447-
// var targetLib = instanceLibrary.INSTANCE_MATCHING_LIBRARY[prevVarType][methodName];
448-
// var targetId = targetLib.target;
449-
// var popupState = {
450-
// config: {
451-
// name: methodName, category: 'Instance',
452-
// id: targetLib.id,
453-
// saveOnly: true,
454-
// noOutput: true
455-
// }
456-
// }
457-
// // add targetid as state if exists
458-
// if (targetId) {
459-
// popupState[targetId] = targetCode;
460-
// }
461-
// that.optionPopup = new LibraryComponent(popupState,
462-
// {
463-
// pageThis: that,
464-
// useInputVariable: true,
465-
// targetSelector: that.pageThis.wrapSelector('#' + that.targetId),
466-
467-
// finish: function(code) {
468-
// // TODO: save state
469-
470-
// $(that.pageThis.wrapSelector('#' + that.targetId)).trigger({
471-
// type: "instance_editor_replaced",
472-
// originCode: that.state.code,
473-
// newCode: code
474-
// });
475-
// }
476-
// });
477-
// hasOption = true;
478-
// } else {
479-
// that.optionPopup = null;
480-
// }
481509

482510
// if bracket is at the end of code
483511
var matchList = lastSplit.match(/\(.*?\)$/gi);
@@ -487,110 +515,25 @@ define([
487515
var parameter = lastBracket.substr(1, lastBracket.length - 2);
488516
$(that.wrapSelector('.' + VP_INS_PARAMETER)).val(parameter);
489517
$(that.wrapSelector('.' + VP_INS_PARAMETER)).prop('disabled', false);
490-
// if (hasOption) {
491-
// if ($(that.wrapSelector('.vp-ins-opt-button')).hasClass('disabled')) {
492-
// $(that.wrapSelector('.vp-ins-opt-button')).removeClass('disabled');
493-
// }
494-
// } else {
495-
// if (!$(that.wrapSelector('.vp-ins-opt-button')).hasClass('disabled')) {
496-
// $(that.wrapSelector('.vp-ins-opt-button')).addClass('disabled');
497-
// }
498-
// }
499518
} else {
500519
$(that.wrapSelector('.' + VP_INS_PARAMETER)).val('');
501520
$(that.wrapSelector('.' + VP_INS_PARAMETER)).prop('disabled', true);
502-
// if (!$(that.wrapSelector('.vp-ins-opt-button')).hasClass('disabled')) {
503-
// $(that.wrapSelector('.vp-ins-opt-button')).addClass('disabled');
504-
// }
505521
}
506522
} else {
507523
$(that.wrapSelector('.' + VP_INS_PARAMETER)).prop('disabled', true);
508-
// if (!$(that.wrapSelector('.vp-ins-opt-button')).hasClass('disabled')) {
509-
// $(that.wrapSelector('.vp-ins-opt-button')).addClass('disabled');
510-
// }
511524
}
512525
}
513-
514-
// callback
515-
if (callback) {
516-
callback(varObj);
517-
}
518526
}).catch(function(resultObj) {
519527
let { result } = resultObj;
520528
// show alert if this is visible
521529
if (that.pageThis.isHidden() == false && that.config.showAlert == true) {
522530
com_util.renderAlertModal(result.ename + ': ' + result.evalue);
523531
}
524-
// hide
525-
if (!$(that.wrapSelector('.vp-ins-opt-button')).hasClass('disabled')) {
526-
$(that.wrapSelector('.vp-ins-opt-button')).addClass('disabled');
527-
}
532+
}).finally(function() {
528533
// callback
529534
if (callback) {
530535
callback('');
531536
}
532-
}).finally(function() {
533-
534-
// get parameter
535-
var splitList = variable.split('.');
536-
var hasOption = false;
537-
538-
if (splitList && splitList.length > 0) {
539-
var lastSplit = splitList[splitList.length - 1];
540-
// get target code
541-
var methodName = lastSplit.match(/[a-zA-Z_]+/i)[0];
542-
var targetCode = splitList.slice(0, splitList.length - 1).join('.');
543-
if ((prevVarType in instanceLibrary.INSTANCE_MATCHING_LIBRARY) && (methodName in instanceLibrary.INSTANCE_MATCHING_LIBRARY[prevVarType])) {
544-
// get target library
545-
var targetLib = instanceLibrary.INSTANCE_MATCHING_LIBRARY[prevVarType][methodName];
546-
var targetId = targetLib.target;
547-
var popupState = {
548-
config: {
549-
name: methodName, category: 'Instance',
550-
id: targetLib.id,
551-
saveOnly: true,
552-
noOutput: true
553-
}
554-
}
555-
// add targetid as state if exists
556-
if (targetId) {
557-
popupState[targetId] = targetCode;
558-
}
559-
that.optionPopup = new LibraryComponent(popupState,
560-
{
561-
pageThis: that,
562-
useInputVariable: true,
563-
targetSelector: that.pageThis.wrapSelector('#' + that.targetId),
564-
565-
finish: function(code) {
566-
// TODO: save state
567-
568-
$(that.pageThis.wrapSelector('#' + that.targetId)).trigger({
569-
type: "instance_editor_replaced",
570-
originCode: that.state.code,
571-
newCode: code
572-
});
573-
}
574-
});
575-
hasOption = true;
576-
} else {
577-
that.optionPopup = null;
578-
}
579-
580-
if (hasOption) {
581-
if ($(that.wrapSelector('.vp-ins-opt-button')).hasClass('disabled')) {
582-
$(that.wrapSelector('.vp-ins-opt-button')).removeClass('disabled');
583-
}
584-
} else {
585-
if (!$(that.wrapSelector('.vp-ins-opt-button')).hasClass('disabled')) {
586-
$(that.wrapSelector('.vp-ins-opt-button')).addClass('disabled');
587-
}
588-
}
589-
} else {
590-
if (!$(that.wrapSelector('.vp-ins-opt-button')).hasClass('disabled')) {
591-
$(that.wrapSelector('.vp-ins-opt-button')).addClass('disabled');
592-
}
593-
}
594537
});
595538

596539

visualpython/js/m_apps/Instance.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ define([
6060
$(this.wrapSelector('#vp_instanceTarget')).on('change', function(event) {
6161
let value = $(this).val();
6262
that.updateValue(value);
63-
that.reloadInsEditor('variable');
63+
that.reloadInsEditor();
6464
});
6565
// clear
6666
$(this.wrapSelector('#vp_instanceClear')).on('click', function(event) {
@@ -148,7 +148,7 @@ define([
148148
var selectedVariable = event.varName;
149149
let fullCode = nowCode + selectedVariable;
150150
that.updateValue(fullCode);
151-
that.reloadInsEditor('variable');
151+
that.reloadInsEditor();
152152
});
153153

154154
// instance_editor_replaced - variable
@@ -157,7 +157,7 @@ define([
157157

158158
var newCode = event.newCode;
159159
that.updateValue(newCode);
160-
that.reloadInsEditor('variable');
160+
that.reloadInsEditor();
161161
});
162162

163163
// co-op with Subset
@@ -192,15 +192,16 @@ define([
192192
let targetSelector = new DataSelector({
193193
pageThis: this, id: 'vp_instanceTarget', placeholder: 'Select variable',
194194
allowDataType: [
195-
'DataFrame', 'Series', 'dict', 'list', 'int'
195+
'module', 'DataFrame', 'Series', 'dict', 'list', 'int'
196196
],
197+
allowModule: true,
197198
finish: function(value, dtype) {
198199
$(that.wrapSelector('#vp_instanceTarget')).trigger({type: 'change', value: value});
199200
},
200201
select: function(value, dtype) {
201202
$(that.wrapSelector('#vp_instanceTarget')).trigger({type: 'change', value: value});
202203
// that.updateValue(value);
203-
// that.reloadInsEditor('variable');
204+
// that.reloadInsEditor();
204205
}
205206
});
206207
$(page).find('#vp_instanceTarget').replaceWith(targetSelector.toTagString());
@@ -369,7 +370,7 @@ define([
369370
return lastValue;
370371
}
371372

372-
reloadInsEditor(type='') {
373+
reloadInsEditor() {
373374
var that = this;
374375
var tempPointer = this.pointer;
375376
var callbackFunction = function (varObj) {

0 commit comments

Comments
 (0)