[SSE] Import data from text/csv file
This commit is contained in:
parent
ea0e580b0b
commit
b5438c6648
|
@ -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,
|
||||
|
|
|
@ -60,7 +60,20 @@ define([
|
|||
height = 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 = 220;
|
||||
break;
|
||||
default:
|
||||
height = options.warning ? 187 : 147;
|
||||
break;
|
||||
}
|
||||
// height = (options.type == Common.Utils.importTextType.CSV || options.type == Common.Utils.importTextType.Paste || options.type == Common.Utils.importTextType.Columns) ? 190 : (options.warning ? 187 : 147);
|
||||
}
|
||||
|
||||
_.extend(_options, {
|
||||
|
@ -98,7 +111,7 @@ define([
|
|||
'<% } %>',
|
||||
'<% } else { %>',
|
||||
'<% if (codepages && codepages.length>0) { %>',
|
||||
'<div style="<% if (!!preview && (type == Common.Utils.importTextType.CSV || type == Common.Utils.importTextType.Paste || type == Common.Utils.importTextType.Columns)) { %>width: 230px;margin-right: 10px;display: inline-block;<% } else { %>width: 100%;<% } %>margin-bottom:15px;">',
|
||||
'<div style="<% if (!!preview && (type == Common.Utils.importTextType.CSV || type == Common.Utils.importTextType.Paste || type == Common.Utils.importTextType.Columns || type == Common.Utils.importTextType.Data)) { %>width: 230px;margin-right: 10px;display: inline-block;<% } else { %>width: 100%;<% } %>margin-bottom:15px;">',
|
||||
'<label class="header">' + t.txtEncoding + '</label>',
|
||||
'<div>',
|
||||
'<div id="id-codepages-combo" class="input-group-nr" style="width: 100%; display: inline-block; vertical-align: middle;"></div>',
|
||||
|
@ -114,7 +127,7 @@ 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>',
|
||||
|
@ -321,7 +334,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 +364,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 +396,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_TextFromFileOrUrl(options, _.bind(this.previewCallback, this), undefined, true);
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -424,7 +445,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)
|
||||
|
|
|
@ -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
|
||||
|
@ -221,6 +222,63 @@ define([
|
|||
})).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(data) {
|
||||
if (!data || !data.length) return;
|
||||
|
||||
var me = this;
|
||||
(new Common.Views.OpenDialog({
|
||||
title: me.textWizard,
|
||||
closable: true,
|
||||
type: Common.Utils.importTextType.Data,
|
||||
preview: true,
|
||||
previewData: data,
|
||||
settings: me._state.CSVOptions,
|
||||
api: me.api,
|
||||
handler: function (result, encoding, delimiter, delimiterChar, decimal, thousands, range) {
|
||||
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, me.api.asc_getTextFromFileOrUrl(), range);
|
||||
}
|
||||
}
|
||||
me.api.asc_cleanTextFromFileOrUrl();
|
||||
}
|
||||
})).show();
|
||||
},
|
||||
|
||||
onShowClick: function() {
|
||||
this.api.asc_changeGroupDetails(true);
|
||||
},
|
||||
|
@ -379,7 +437,8 @@ 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.'
|
||||
|
||||
}, SSE.Controllers.DataTab || {}));
|
||||
});
|
|
@ -198,6 +198,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>
|
||||
|
|
|
@ -102,6 +102,9 @@ define([
|
|||
me.btnCustomSort.on('click', function (b, e) {
|
||||
me.fireEvent('data:sortcustom');
|
||||
});
|
||||
me.btnDataFromText.menu.on('item:click', function (menu, item, e) {
|
||||
me.fireEvent('data:fromtext', [item.value]);
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
|
@ -117,6 +120,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-cell-group',
|
||||
caption: this.capDataFromText,
|
||||
menu: true,
|
||||
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 +265,15 @@ define([
|
|||
});
|
||||
me.btnGroup.setMenu(_menu);
|
||||
|
||||
me.btnDataFromText.updateHint(me.tipDataFromText);
|
||||
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 +349,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 || {}));
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue