Merge branch 'feature/sse-from-text' into develop

This commit is contained in:
Julia Radzhabova 2021-04-05 11:34:54 +03:00
commit 77cd81322c
11 changed files with 231 additions and 37 deletions

View file

@ -114,7 +114,8 @@ Common.Utils = _.extend(new(function() {
CSV: 1,
TXT: 2,
Paste: 3,
Columns: 4
Columns: 4,
Data: 5
},
isMobile = /android|avantgo|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od|ad)|iris|kindle|lge |maemo|midp|mmp|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(navigator.userAgent || navigator.vendor || window.opera),
me = this,

View file

@ -57,10 +57,22 @@ define([
if (options.preview) {
width = 414;
height = 277;
height = (options.type==Common.Utils.importTextType.Data) ? 385 : 277;
} else {
width = (options.type !== Common.Utils.importTextType.DRM) ? 340 : (options.warning ? 420 : 280);
height = (options.type == Common.Utils.importTextType.CSV || options.type == Common.Utils.importTextType.Paste || options.type == Common.Utils.importTextType.Columns) ? 190 : (options.warning ? 187 : 147);
switch (options.type) {
case Common.Utils.importTextType.CSV:
case Common.Utils.importTextType.Paste:
case Common.Utils.importTextType.Columns:
height = 190;
break;
case Common.Utils.importTextType.Data:
height = 245;
break;
default:
height = options.warning ? 187 : 147;
break;
}
}
_.extend(_options, {
@ -114,13 +126,13 @@ define([
'</div>',
'</div>',
'<% } %>',
'<% if (type == Common.Utils.importTextType.Paste || type == Common.Utils.importTextType.Columns) { %>',
'<% if (type == Common.Utils.importTextType.Paste || type == Common.Utils.importTextType.Columns || type == Common.Utils.importTextType.Data) { %>',
'<div style="display: inline-block; margin-bottom:15px;width: 100%;">',
'<label class="header">' + t.txtDelimiter + '</label>',
'<div>',
'<div id="id-delimiters-combo" class="input-group-nr" style="max-width: 100px;display: inline-block; vertical-align: middle;"></div>',
'<div id="id-delimiter-other" class="input-row" style="display: inline-block; vertical-align: middle;margin-left: 10px;"></div>',
'<button type="button" class="btn btn-text-default" id="id-delimiters-advanced" style="min-width:100px; display: inline-block;float:right;">' + t.txtAdvanced + '</button>',
'<button type="button" class="btn auto btn-text-default" id="id-delimiters-advanced" style="min-width:100px; display: inline-block;float:right;">' + t.txtAdvanced + '</button>',
'</div>',
'</div>',
'<% } %>',
@ -138,6 +150,10 @@ define([
'</div>',
'</div>',
'<% } %>',
'<% if (type == Common.Utils.importTextType.Data) { %>',
'<label class="header" style="margin-top:15px;">' + t.txtDestData + '</label>',
'<div id="id-open-data-range" class="input-row" style="width: 100%;"></div>',
'<% } %>',
'<% } %>',
'</div>',
'</div>',
@ -204,6 +220,19 @@ define([
(this.previewData) ? this.previewCallback(this.previewData) : this.updatePreview();
}
}
if (this.type == Common.Utils.importTextType.Data) {
this.txtDestRange = new Common.UI.InputFieldBtn({
el : $('#id-open-data-range'),
name : 'range',
style : 'width: 100%;',
btnHint : this.textSelectData,
allowBlank : true,
validateOnChange: true,
validateOnBlur: false
});
this.txtDestRange.on('button:click', _.bind(this.onSelectData, this));
}
this.onPrimary = function() {
me._handleInput('ok');
return false;
@ -235,8 +264,12 @@ define([
_handleInput: function(state) {
if (this.handler) {
if (this.type == Common.Utils.importTextType.DRM) {
this.handler.call(this, state, this.inputPwd.getValue());
this.handler.call(this, state, {drmOptions: new Asc.asc_CDRMAdvancedOptions(this.inputPwd.getValue())});
} else {
if ( this.type == Common.Utils.importTextType.Data && state == 'ok' && !this.isRangeValid() ) {
return;
}
var encoding = (this.cmbEncoding && !this.cmbEncoding.isDisabled()) ? this.cmbEncoding.getValue() :
((this.settings && this.settings.asc_getCodePage()) ? this.settings.asc_getCodePage() : 0),
delimiter = this.cmbDelimiter ? this.cmbDelimiter.getValue() : null,
@ -248,7 +281,14 @@ define([
var decimal = this.separatorOptions ? this.separatorOptions.decimal : undefined,
thousands = this.separatorOptions ? this.separatorOptions.thousands : undefined;
this.handler.call(this, state, encoding, delimiter, delimiterChar, decimal, thousands);
var options = new Asc.asc_CTextOptions(encoding, delimiter, delimiterChar);
decimal && options.asc_setNumberDecimalSeparator(decimal);
thousands && options.asc_setNumberGroupSeparator(thousands);
this.handler.call(this, state, {
textOptions: options,
range: this.txtDestRange ? this.txtDestRange.getValue() : '',
data: this.data
});
}
}
@ -321,7 +361,7 @@ define([
ul.find('li div').width(width);
}
if (this.type == Common.Utils.importTextType.CSV || this.type == Common.Utils.importTextType.Paste || this.type == Common.Utils.importTextType.Columns) {
if (this.type == Common.Utils.importTextType.CSV || this.type == Common.Utils.importTextType.Paste || this.type == Common.Utils.importTextType.Columns || this.type == Common.Utils.importTextType.Data) {
this.cmbDelimiter = new Common.UI.ComboBox({
el: $('#id-delimiters-combo', this.$window),
style: 'width: 100px;',
@ -351,7 +391,7 @@ define([
if (this.preview)
this.inputDelimiter.on ('changing', _.bind(this.updatePreview, this));
if (this.type == Common.Utils.importTextType.Paste || this.type == Common.Utils.importTextType.Columns) {
if (this.type == Common.Utils.importTextType.Paste || this.type == Common.Utils.importTextType.Columns || this.type == Common.Utils.importTextType.Data) {
this.btnAdvanced = new Common.UI.Button({
el: $('#id-delimiters-advanced')
});
@ -383,6 +423,14 @@ define([
}
this.api.asc_TextImport(options, _.bind(this.previewCallback, this), this.type == Common.Utils.importTextType.Paste);
break;
case Common.Utils.importTextType.Data:
var options = new Asc.asc_CTextOptions(encoding, delimiter, delimiterChar);
if (this.separatorOptions) {
options.asc_setNumberDecimalSeparator(this.separatorOptions.decimal);
options.asc_setNumberGroupSeparator(this.separatorOptions.thousands);
}
this.api.asc_decodeBuffer(this.preview, options, _.bind(this.previewCallback, this));
break;
}
},
@ -424,7 +472,7 @@ define([
delete this.scrollerX;
}
if (this.type == Common.Utils.importTextType.CSV || this.type == Common.Utils.importTextType.Paste || this.type == Common.Utils.importTextType.Columns) {
if (this.type == Common.Utils.importTextType.CSV || this.type == Common.Utils.importTextType.Paste || this.type == Common.Utils.importTextType.Columns || this.type == Common.Utils.importTextType.Data) {
var maxlength = 0;
for (var i=0; i<data.length; i++) {
if (data[i].length>maxlength)
@ -492,6 +540,60 @@ define([
})).show();
},
onSelectData: function(type) {
var me = this,
txtRange = me.txtDestRange;
if (me.api) {
var handlerDlg = function(dlg, result) {
if (result == 'ok') {
var txt = dlg.getSettings();
me.dataDestValid = txt;
txtRange.setValue(txt);
txtRange.checkValidate();
}
};
var win = new SSE.Views.CellRangeDialog({
handler: handlerDlg
}).on('close', function() {
me.show();
_.delay(function(){
txtRange.focus();
},1);
});
var xy = me.$window.offset();
me.hide();
win.show(xy.left + 160, xy.top + 125);
win.setSettings({
api : me.api,
range : (!_.isEmpty(txtRange.getValue()) && (txtRange.checkValidate()==true)) ? txtRange.getValue() : (me.dataDestValid),
type : Asc.c_oAscSelectionDialogType.Chart
});
}
},
isRangeValid: function() {
var isvalid = true,
txtError = '';
if (_.isEmpty(this.txtDestRange.getValue())) {
isvalid = false;
txtError = this.txtEmpty;
} else {
isvalid = this.api.asc_checkDataRange(Asc.c_oAscSelectionDialogType.Chart, this.txtDestRange.getValue());
isvalid = (isvalid == Asc.c_oAscError.ID.No);
!isvalid && (txtError = this.textInvalidRange);
}
if (!isvalid) {
this.txtDestRange.showError([txtError]);
this.txtDestRange.focus();
return isvalid;
}
return isvalid;
},
txtDelimiter : "Delimiter",
txtEncoding : "Encoding ",
txtSpace : "Space",
@ -508,7 +610,11 @@ define([
txtSemicolon: 'Semicolon',
txtProtected: 'Once you enter the password and open the file, the current password to the file will be reset.',
txtAdvanced: 'Advanced',
txtOpenFile: "Enter a password to open the file"
txtOpenFile: "Enter a password to open the file",
textSelectData: 'Select data',
txtDestData: 'Choose where to put the data',
txtEmpty: 'This field is required',
textInvalidRange: 'Invalid cells range'
}, Common.Views.OpenDialog || {}));
});

View file

@ -77,7 +77,7 @@
}
}
.icon {
.icon.img-commonctrl {
float: left;
width: 35px;
height: 35px;

View file

@ -2179,15 +2179,15 @@ define([
codepages: advOptions.asc_getCodePages(),
settings: advOptions.asc_getRecommendedSettings(),
api: me.api,
handler: function (result, encoding) {
handler: function (result, settings) {
me.isShowOpenDialog = false;
if (result == 'ok') {
if (me && me.api) {
if (mode==2) {
formatOptions && formatOptions.asc_setAdvancedOptions(new Asc.asc_CTextOptions(encoding));
formatOptions && formatOptions.asc_setAdvancedOptions(settings.textOptions);
me.api.asc_DownloadAs(formatOptions);
} else
me.api.asc_setAdvancedOptions(type, new Asc.asc_CTextOptions(encoding));
me.api.asc_setAdvancedOptions(type, settings.textOptions);
me.loadMask && me.loadMask.show();
}
}
@ -2206,7 +2206,7 @@ define([
me.isShowOpenDialog = false;
if (result == 'ok') {
if (me.api) {
me.api.asc_setAdvancedOptions(type, new Asc.asc_CDRMAdvancedOptions(value));
me.api.asc_setAdvancedOptions(type, value.drmOptions);
me.loadMask && me.loadMask.show();
}
} else {

View file

@ -2020,7 +2020,7 @@ define([
me.isShowOpenDialog = false;
if (result == 'ok') {
if (me.api) {
me.api.asc_setAdvancedOptions(type, new Asc.asc_CDRMAdvancedOptions(value));
me.api.asc_setAdvancedOptions(type, value.drmOptions);
me.loadMask && me.loadMask.show();
}
} else {

View file

@ -92,7 +92,8 @@ define([
'data:groupsettings': this.onGroupSettings,
'data:sortcustom': this.onCustomSort,
'data:remduplicates': this.onRemoveDuplicates,
'data:datavalidation': this.onDataValidation
'data:datavalidation': this.onDataValidation,
'data:fromtext': this.onDataFromText
},
'Statusbar': {
'sheet:changed': this.onApiSheetChanged
@ -208,15 +209,59 @@ define([
previewData: data,
settings: me._state.CSVOptions,
api: me.api,
handler: function (result, encoding, delimiter, delimiterChar, decimal, thousands) {
if (result == 'ok') {
if (me && me.api) {
var options = new Asc.asc_CTextOptions(encoding, delimiter, delimiterChar);
decimal && options.asc_setNumberDecimalSeparator(decimal);
thousands && options.asc_setNumberGroupSeparator(thousands);
me.api.asc_TextToColumns(options);
handler: function (result, settings) {
if (result == 'ok' && me.api) {
me.api.asc_TextToColumns(settings.textOptions);
}
}
})).show();
},
onDataFromText: function(type) {
var me = this;
if (type === 'file') {
if (this.api)
this.api.asc_TextFromFileOrUrl(this._state.CSVOptions, _.bind(this.onDataFromTextCallback, this));
Common.NotificationCenter.trigger('edit:complete', this.toolbar);
} else if (type === 'url') {
(new Common.Views.ImageFromUrlDialog({
handler: function(result, value) {
if (result == 'ok') {
if (me.api) {
var checkUrl = value.replace(/\s/g, '');
if (!_.isEmpty(checkUrl)) {
me.api.asc_TextFromFileOrUrl(me._state.CSVOptions, _.bind(me.onDataFromTextCallback, me), checkUrl);
} else {
Common.UI.warning({
msg: me.textEmptyUrl
});
}
}
Common.NotificationCenter.trigger('edit:complete', me.toolbar);
}
}
})).show();
} else if (type === 'storage') {
// Common.NotificationCenter.trigger('storage:data-load', 'add');
}
},
onDataFromTextCallback: function(advOptions) {
var me = this;
(new Common.Views.OpenDialog({
title: me.txtImportWizard,
closable: true,
type: Common.Utils.importTextType.Data,
preview: advOptions.asc_getData(),
settings: advOptions ? advOptions.asc_getRecommendedSettings() : me._state.CSVOptions,
codepages: advOptions ? advOptions.asc_getCodePages() : null,
api: me.api,
handler: function (result, settings) {
if (result == 'ok' && me.api) {
me.api.asc_TextToColumns(settings.textOptions, settings.data, settings.range);
}
}
})).show();
},
@ -379,7 +424,9 @@ define([
textColumns: 'Columns',
txtDataValidation: 'Data Validation',
txtExtendDataValidation: 'The selection contains some cells without Data Validation settings.<br>Do you want to extend Data Validation to these cells?',
txtRemoveDataValidation: 'The selection contains more than one type of validation.<br>Erase current settings and continue?'
txtRemoveDataValidation: 'The selection contains more than one type of validation.<br>Erase current settings and continue?',
textEmptyUrl: 'You need to specify URL.',
txtImportWizard: 'Text Import Wizard'
}, SSE.Controllers.DataTab || {}));
});

View file

@ -2592,16 +2592,12 @@ define([
type: Common.Utils.importTextType.Paste,
preview: true,
api: me.api,
handler: function (result, encoding, delimiter, delimiterChar, decimal, thousands) {
handler: function (result, settings) {
if (result == 'ok') {
if (me && me.api) {
var props = new Asc.SpecialPasteProps();
props.asc_setProps(Asc.c_oSpecialPasteProps.useTextImport);
var options = new Asc.asc_CTextOptions(encoding, delimiter, delimiterChar);
decimal && options.asc_setNumberDecimalSeparator(decimal);
thousands && options.asc_setNumberGroupSeparator(thousands);
props.asc_setAdvancedOptions(options);
props.asc_setAdvancedOptions(settings.textOptions);
me.api.asc_SpecialPaste(props);
}
me._state.lastSpecPasteChecked = item;

View file

@ -1917,15 +1917,15 @@ define([
codepages: advOptions.asc_getCodePages(),
settings: advOptions.asc_getRecommendedSettings(),
api: me.api,
handler: function (result, encoding, delimiter, delimiterChar) {
handler: function (result, settings) {
me.isShowOpenDialog = false;
if (result == 'ok') {
if (me && me.api) {
if (mode==2) {
formatOptions && formatOptions.asc_setAdvancedOptions(new Asc.asc_CTextOptions(encoding, delimiter, delimiterChar));
formatOptions && formatOptions.asc_setAdvancedOptions(settings.textOptions);
me.api.asc_DownloadAs(formatOptions);
} else
me.api.asc_setAdvancedOptions(type, new Asc.asc_CTextOptions(encoding, delimiter, delimiterChar));
me.api.asc_setAdvancedOptions(type, settings.textOptions);
me.loadMask && me.loadMask.show();
}
}
@ -1944,7 +1944,7 @@ define([
me.isShowOpenDialog = false;
if (result == 'ok') {
if (me && me.api) {
me.api.asc_setAdvancedOptions(type, new Asc.asc_CDRMAdvancedOptions(value));
me.api.asc_setAdvancedOptions(type, value.drmOptions);
me.loadMask && me.loadMask.show();
}
} else {

View file

@ -199,6 +199,10 @@
</div>
</section>
<section class="panel" data-tab="data">
<div class="group">
<span class="btn-slot text x-huge" id="slot-btn-data-from-text"></span>
</div>
<div class="separator long"></div>
<div class="group">
<div class="elset">
<span class="btn-slot split slot-btn-setfilter"></span>

View file

@ -102,6 +102,12 @@ define([
me.btnCustomSort.on('click', function (b, e) {
me.fireEvent('data:sortcustom');
});
me.btnDataFromText.menu ?
me.btnDataFromText.menu.on('item:click', function (menu, item, e) {
me.fireEvent('data:fromtext', [item.value]);
}) : me.btnDataFromText.on('click', function (b, e) {
me.fireEvent('data:fromtext', ['file']);
});
}
return {
@ -117,6 +123,17 @@ define([
$host = me.toolbar.$el,
_set = SSE.enumLock;
this.btnDataFromText = new Common.UI.Button({
parentEl: $host.find('#slot-btn-data-from-text'),
cls: 'btn-toolbar x-huge icon-top',
iconCls: 'toolbar__icon btn-import-data',
caption: this.capDataFromText,
menu: !this.toolbar.mode.isDesktopApp,
disabled: true,
lock: [_set.editCell, _set.selChart, _set.selChartText, _set.selShape, _set.selShapeText, _set.selImage, _set.selSlicer, _set.sheetLock, _set.lostConnect, _set.coAuth]
});
this.lockedControls.push(this.btnDataFromText);
this.btnGroup = new Common.UI.Button({
parentEl: $host.find('#slot-btn-group'),
cls: 'btn-toolbar x-huge icon-top',
@ -251,6 +268,15 @@ define([
});
me.btnGroup.setMenu(_menu);
me.btnDataFromText.updateHint(me.tipDataFromText);
me.btnDataFromText.menu && me.btnDataFromText.setMenu(new Common.UI.Menu({
items: [
{ caption: me.mniFromFile, value: 'file' },
{ caption: me.mniFromUrl, value: 'url' }
// { caption: me.mniImageFromStorage, value: 'storage'}
]
}));
me.btnTextToColumns.updateHint(me.tipToColumns);
me.btnRemoveDuplicates.updateHint(me.tipRemDuplicates);
me.btnDataValidation.updateHint(me.tipDataValidation);
@ -326,7 +352,11 @@ define([
capBtnTextRemDuplicates: 'Remove Duplicates',
tipRemDuplicates: 'Remove duplicate rows from a sheet',
capBtnTextDataValidation: 'Data Validation',
tipDataValidation: 'Data validation'
tipDataValidation: 'Data validation',
capDataFromText: 'From Text/CSV',
tipDataFromText: 'Get data from Text/CSV file',
mniFromFile: 'Get Data from File',
mniFromUrl: 'Get Data from URL'
}
}()), SSE.Views.DataTab || {}));
});

View file

@ -249,6 +249,10 @@
"Common.Views.OpenDialog.txtTab": "Tab",
"Common.Views.OpenDialog.txtTitle": "Choose %1 options",
"Common.Views.OpenDialog.txtTitleProtected": "Protected File",
"Common.Views.OpenDialog.textSelectData": "Select data",
"Common.Views.OpenDialog.txtDestData": "Choose where to put the data",
"Common.Views.OpenDialog.txtEmpty": "This field is required",
"Common.Views.OpenDialog.textInvalidRange": "Invalid cells range",
"Common.Views.PasswordDialog.txtDescription": "Set a password to protect this document",
"Common.Views.PasswordDialog.txtIncorrectPwd": "Confirmation password is not identical",
"Common.Views.PasswordDialog.txtPassword": "Password",
@ -398,6 +402,8 @@
"SSE.Controllers.DataTab.txtRemDuplicates": "Remove Duplicates",
"SSE.Controllers.DataTab.txtRemoveDataValidation": "The selection contains more than one type of validation.<br>Erase current settings and continue?",
"SSE.Controllers.DataTab.txtRemSelected": "Remove in selected",
"SSE.Controllers.DataTab.textEmptyUrl": "You need to specify URL.",
"SSE.Controllers.DataTab.txtImportWizard": "Text Import Wizard",
"SSE.Controllers.DocumentHolder.alignmentText": "Alignment",
"SSE.Controllers.DocumentHolder.centerText": "Center",
"SSE.Controllers.DocumentHolder.deleteColumnText": "Delete Column",
@ -1673,6 +1679,10 @@
"SSE.Views.DataTab.tipRemDuplicates": "Remove duplicate rows from a sheet",
"SSE.Views.DataTab.tipToColumns": "Separate cell text into columns",
"SSE.Views.DataTab.tipUngroup": "Ungroup range of cells",
"SSE.Views.DataTab.capDataFromText": "From Text/CSV",
"SSE.Views.DataTab.tipDataFromText": "Get data from Text/CSV file",
"SSE.Views.DataTab.mniFromFile": "Get Data from File",
"SSE.Views.DataTab.mniFromUrl": "Get Data from URL",
"SSE.Views.DataValidationDialog.errorFormula": "The value currently evaluates to an error. Do you want to continue?",
"SSE.Views.DataValidationDialog.errorInvalid": "The value you entered for the field \"{0}\" is invalid.",
"SSE.Views.DataValidationDialog.errorInvalidDate": "The date you entered for the field \"{0}\" is invalid.",