Skip to content

Commit b6f3344

Browse files
committed
FrameEditor update - replace operation
1 parent cd2f7b7 commit b6f3344

1 file changed

Lines changed: 83 additions & 19 deletions

File tree

src/common/vpFrameEditor.js

Lines changed: 83 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,10 @@ define([
163163
axis: 0,
164164
lines: TABLE_LINES,
165165
steps: [],
166-
popup: FRAME_EDIT_TYPE.NONE
166+
popup: {
167+
type: FRAME_EDIT_TYPE.NONE,
168+
replace: { index: 0 }
169+
}
167170
}
168171

169172
this.codepreview = undefined;
@@ -311,8 +314,8 @@ define([
311314
page.appendFormatLine('<div class="{0} {1}" data-type="{2}" data-axis="{3}">{4}</div>'
312315
, VP_FE_MENU_ITEM, 'vp-fe-menu-reset-index', FRAME_EDIT_TYPE.RESET_IDX, 'row', 'Reset Index');
313316
// menu 7. replace
314-
page.appendFormatLine('<div class="{0} {1}" data-type="{2}">{3}</div>'
315-
, VP_FE_MENU_ITEM, 'vp-fe-menu-replace', FRAME_EDIT_TYPE.REPLACE, 'Replace');
317+
page.appendFormatLine('<div class="{0} {1}" data-type="{2}" data-axis="{3}">{4}</div>'
318+
, VP_FE_MENU_ITEM, 'vp-fe-menu-replace', FRAME_EDIT_TYPE.REPLACE, 'col', 'Replace');
316319
page.appendLine('</div>'); // End of Menus
317320
return page.toString();
318321
}
@@ -426,12 +429,26 @@ define([
426429

427430
FrameEditor.prototype.renderReplacePage = function() {
428431
var content = new sb.StringBuilder();
429-
content.appendLine('<table>');
432+
content.appendFormatLine('<table class="{0}">', 'vp-popup-replace-table');
433+
content.appendLine(this.renderReplaceInput(0));
434+
content.appendFormatLine('<tr><td colspan="3"><button class="{0} {1}">{2}</button></td></tr>', 'vp-button', 'vp-popup-replace-add', '+ Add Key');
435+
content.appendLine('</table>');
436+
return content.toString();
437+
}
438+
439+
FrameEditor.prototype.renderReplaceInput = function(index) {
440+
var content = new sb.StringBuilder();
430441
content.appendLine('<tr>');
431-
content.appendFormatLine('<td><input type="text" class="{0}" placeholder="{1}"/></td>', 'vp-popup-input0', 'origin');
432-
content.appendFormatLine('<td><input type="text" class="{0}" placeholder="{1}"/></td>', 'vp-popup-replace0', 'replace');
442+
content.appendLine('<td>');
443+
content.appendFormatLine('<input type="text" class="{0}" placeholder="{1}"/>', 'vp-popup-origin' + index, 'origin');
444+
content.appendFormatLine('<label><input type="checkbox" class="{0}" checked/><span>{1}</span></label>', 'vp-popup-origin-istext' + index, 'Text');
445+
content.appendLine('</td>');
446+
content.appendLine('<td>');
447+
content.appendFormatLine('<input type="text" class="{0}" placeholder="{1}"/>', 'vp-popup-replace' + index, 'replace');
448+
content.appendFormatLine('<label><input type="checkbox" class="{0}" checked/><span>{1}</span></label>', 'vp-popup-replace-istext' + index, 'Text');
449+
content.appendLine('</td>');
450+
content.appendFormatLine('<td><i class="{0} {1} {2}"></i></td>', 'vp-popup-delete', 'fa fa-close', 'vp-cursor');
433451
content.appendLine('</tr>');
434-
content.appendLine('</table>');
435452
return content.toString();
436453
}
437454

@@ -455,12 +472,13 @@ define([
455472
case FRAME_EDIT_TYPE.REPLACE:
456473
title = 'Replace';
457474
content = this.renderReplacePage();
475+
break;
458476
default:
459477
type = FRAME_EDIT_TYPE.NONE;
460478
break;
461479
}
462480

463-
this.state.popup = type;
481+
this.state.popup.type = type;
464482

465483
// set title
466484
$(this.wrapSelector('.' + VP_FE_POPUP_BOX + ' .' + VP_FE_TITLE)).text(title);
@@ -472,7 +490,7 @@ define([
472490
}
473491

474492
FrameEditor.prototype.getPopupContent = function() {
475-
var type = this.state.popup;
493+
var type = this.state.popup.type;
476494
var content = {};
477495
switch (parseInt(type)) {
478496
case FRAME_EDIT_TYPE.ADD_COL:
@@ -499,7 +517,21 @@ define([
499517
});
500518
break;
501519
case FRAME_EDIT_TYPE.REPLACE:
502-
// TODO:
520+
var idx = 0;
521+
for (var i=0; i <= this.state.popup.replace.index; i++) {
522+
var origin = $(this.wrapSelector('.vp-popup-origin' + i)).val();
523+
var origintext = $(this.wrapSelector('.vp-popup-origin-istext'+idx)).prop('checked');
524+
var replace = $(this.wrapSelector('.vp-popup-replace' + i)).val();
525+
var replacetext = $(this.wrapSelector('.vp-popup-replace-istext'+idx)).prop('checked');
526+
if (origin && replace) {
527+
content[idx++] = {
528+
origin: origin,
529+
origintext: origintext,
530+
replace: replace,
531+
replacetext: replacetext
532+
}
533+
}
534+
}
503535
break;
504536
default:
505537
break;
@@ -548,7 +580,7 @@ define([
548580
// get selected columns/indexes
549581
var selected = [];
550582
$(this.wrapSelector('.' + VP_FE_TABLE + ' th.selected')).each((idx, tag) => {
551-
var name = $(tag).attr('data-label');
583+
var name = $(tag).data('label');
552584
selected.push(name);
553585
});
554586
this.state.selected = selected;
@@ -685,14 +717,33 @@ define([
685717
}
686718
break;
687719
case FRAME_EDIT_TYPE.REPLACE:
688-
code.appendFormat("{0}.replace({1}, inplace=True)", tempObj, JSON.stringify(content).replaceAll('"', "'"));
720+
var replaceStr = new sb.StringBuilder();
721+
Object.keys(content).forEach((key, idx) => {
722+
if (idx == 0) {
723+
replaceStr.appendFormat("{0}: {1}"
724+
, convertToStr(content[key].origin, content[key].origintext)
725+
, convertToStr(content[key].replace, content[key].replacetext));
726+
} else {
727+
replaceStr.appendFormat(", {0}: {1}"
728+
, convertToStr(content[key].origin, content[key].origintext)
729+
, convertToStr(content[key].replace, content[key].replacetext));
730+
}
731+
});
732+
733+
// var locObj = '';
734+
// if (axis == 0) {
735+
// locObj = vpCommon.formatString('.loc[[{0}],:]', selectedName);
736+
// } else {
737+
// locObj = vpCommon.formatString('.loc[:,[{0}]]', selectedName);
738+
// }
739+
code.appendFormat("{0}[[{1}]] = {2}[[{3}]].replace({{4}})", tempObj, selectedName, tempObj, selectedName, replaceStr);
689740
break;
690741
case FRAME_EDIT_TYPE.ADD_COL:
691742
var name = convertToStr(content.name, content.nameastext);
692743
var value = convertToStr(content.value, content.valueastext);
693744
code.appendFormat("{0}[{1}] = {2}", tempObj, name, value);
694745
break;
695-
case FRAME_EDIT_TYPE.ADD_ROW:
746+
case FRAME_EDIT_TYPE.ADD_ROW:
696747
var name = convertToStr(content.name, content.nameastext);
697748
var value = convertToStr(content.value, content.valueastext);
698749
code.appendFormat("{0}.loc[{1}] = {2}", tempObj, name, value);
@@ -858,7 +909,7 @@ define([
858909
// select col/idx
859910
if (!hasSelected) {
860911
$(this).addClass('selected');
861-
var newAxis = $(this).attr('data-axis');
912+
var newAxis = $(this).data('axis');
862913
that.state.axis = newAxis;
863914
}
864915

@@ -878,7 +929,7 @@ define([
878929
// select col/idx
879930
if (!hasSelected) {
880931
$(this).addClass('selected');
881-
var newAxis = $(this).attr('data-axis');
932+
var newAxis = $(this).data('axis');
882933
that.state.axis = newAxis;
883934
}
884935

@@ -910,7 +961,7 @@ define([
910961
$(that.wrapSelector('.' + VP_FE_TABLE + ' .' + VP_FE_TABLE_ROW)).removeClass('selected');
911962
if (!hasSelected) {
912963
$(this).addClass('selected');
913-
var newAxis = $(this).attr('data-axis');
964+
var newAxis = $(this).data('axis');
914965
that.state.axis = newAxis;
915966
} else {
916967
$(this).removeClass('selected');
@@ -925,7 +976,7 @@ define([
925976
$(that.wrapSelector('.' + VP_FE_TABLE + ' .' + VP_FE_TABLE_COLUMN)).removeClass('selected');
926977
if (!hasSelected) {
927978
$(this).addClass('selected');
928-
var newAxis = $(this).attr('data-axis');
979+
var newAxis = $(this).data('axis');
929980
that.state.axis = newAxis;
930981
} else {
931982
$(this).removeClass('selected');
@@ -955,7 +1006,7 @@ define([
9551006
// click menu item
9561007
$(document).on('click', this.wrapSelector('.' + VP_FE_MENU_ITEM), function(event) {
9571008
event.stopPropagation();
958-
var editType = $(this).attr('data-type');
1009+
var editType = $(this).data('type');
9591010
switch (parseInt(editType)) {
9601011
case FRAME_EDIT_TYPE.ADD_COL:
9611012
case FRAME_EDIT_TYPE.ADD_ROW:
@@ -970,10 +1021,23 @@ define([
9701021
that.hideMenu();
9711022
});
9721023

1024+
// popup : replace - add button
1025+
$(document).on('click', this.wrapSelector('.vp-popup-replace-add'), function() {
1026+
var newInput = $(that.renderReplaceInput(++that.state.popup.replace.index));
1027+
newInput.insertBefore(
1028+
$(that.wrapSelector('.vp-popup-replace-table tr:last'))
1029+
);
1030+
});
1031+
1032+
// popup : replace - delete row
1033+
$(document).on('click', this.wrapSelector('.vp-popup-delete'), function() {
1034+
$(this).closest('tr').remove();
1035+
});
1036+
9731037
// ok input popup
9741038
$(document).on('click', this.wrapSelector('.' + VP_FE_POPUP_OK), function() {
9751039
// ok input popup
976-
that.loadCode(that.getTypeCode(that.state.popup, that.getPopupContent()));
1040+
that.loadCode(that.getTypeCode(that.state.popup.type, that.getPopupContent()));
9771041
that.closeInputPopup();
9781042
});
9791043

0 commit comments

Comments
 (0)