fix: Show 10 rows in preview
This commit is contained in:
parent
d5c6a69e23
commit
13df26eaab
4 changed files with 22 additions and 37 deletions
|
|
@ -20,14 +20,14 @@ from frappe.exceptions import ValidationError, MandatoryError
|
|||
from frappe.model import display_fieldtypes, no_value_fields, table_fields
|
||||
|
||||
INVALID_VALUES = ["", None]
|
||||
MAX_ROWS_IN_PREVIEW = 500
|
||||
MAX_ROWS_IN_PREVIEW = 10
|
||||
|
||||
|
||||
class Importer:
|
||||
def __init__(self, doctype, data_import=None, file_path=None, content=None):
|
||||
self.doctype = doctype
|
||||
self.template_options = frappe._dict(
|
||||
{"remap_column": {}, "edited_rows": []}
|
||||
{"remap_column": {}}
|
||||
)
|
||||
|
||||
if data_import:
|
||||
|
|
@ -144,8 +144,9 @@ class Importer:
|
|||
out.fields = fields
|
||||
|
||||
if len(out.data) > MAX_ROWS_IN_PREVIEW:
|
||||
out.data = []
|
||||
out.data = out.data[:MAX_ROWS_IN_PREVIEW]
|
||||
out.max_rows_exceeded = True
|
||||
out.max_rows_in_preview = MAX_ROWS_IN_PREVIEW
|
||||
return out
|
||||
|
||||
def get_parsed_data_from_template(self):
|
||||
|
|
@ -153,9 +154,6 @@ class Importer:
|
|||
formats, formats_warnings = self.parse_formats_from_first_10_rows()
|
||||
fields, data = self.add_serial_no_column(fields, self.data)
|
||||
|
||||
if self.template_options.edited_rows:
|
||||
data = self.template_options.edited_rows
|
||||
|
||||
warnings = fields_warnings + formats_warnings
|
||||
|
||||
return frappe._dict(
|
||||
|
|
|
|||
|
|
@ -103,10 +103,6 @@ frappe.ui.form.on('Data Import Beta', {
|
|||
},
|
||||
|
||||
start_import(frm) {
|
||||
let csv_array = frm.import_preview.get_rows_as_csv_array();
|
||||
let template_options = JSON.parse(frm.doc.template_options || '{}');
|
||||
template_options.edited_rows = csv_array;
|
||||
frm.set_value('template_options', JSON.stringify(template_options));
|
||||
frm.save().then(() => frm.call('start_import'));
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -12,14 +12,13 @@
|
|||
"import_file",
|
||||
"column_break_5",
|
||||
"status",
|
||||
"submit_after_import",
|
||||
"section_break_7",
|
||||
"date_format",
|
||||
"submit_after_import",
|
||||
"template_options",
|
||||
"template_warnings",
|
||||
"section_import_preview",
|
||||
"import_preview",
|
||||
"import_warnings_section",
|
||||
"template_warnings",
|
||||
"import_warnings",
|
||||
"import_log_section",
|
||||
"import_log",
|
||||
|
|
@ -59,7 +58,7 @@
|
|||
{
|
||||
"fieldname": "section_import_preview",
|
||||
"fieldtype": "Section Break",
|
||||
"label": "Import Preview"
|
||||
"label": "Preview"
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break_5",
|
||||
|
|
@ -70,15 +69,8 @@
|
|||
"depends_on": "eval:!doc.__islocal",
|
||||
"fieldname": "section_break_7",
|
||||
"fieldtype": "Section Break",
|
||||
"hidden": 1,
|
||||
"label": "Import Options"
|
||||
},
|
||||
{
|
||||
"fieldname": "date_format",
|
||||
"fieldtype": "Select",
|
||||
"label": "Date Format",
|
||||
"options": "\nYYYY-MM-DD\nDD-MM-YYYY\nMM-DD-YYYY\nYYYY/MM/DD\nDD/MM/YYYY\nMM/DD/YYYY\nMM/DD/YY\nDD/MM/YY\nYYYY.MM.DD\nDD.MM.YYYY\nMM.DD.YYYY"
|
||||
},
|
||||
{
|
||||
"fieldname": "template_options",
|
||||
"fieldtype": "Code",
|
||||
|
|
@ -115,6 +107,7 @@
|
|||
{
|
||||
"fieldname": "template_warnings",
|
||||
"fieldtype": "Code",
|
||||
"hidden": 1,
|
||||
"label": "Template Warnings",
|
||||
"options": "JSON"
|
||||
},
|
||||
|
|
@ -127,7 +120,7 @@
|
|||
{
|
||||
"fieldname": "import_warnings_section",
|
||||
"fieldtype": "Section Break",
|
||||
"label": "Import Warnings"
|
||||
"label": "Warnings"
|
||||
},
|
||||
{
|
||||
"fieldname": "import_warnings",
|
||||
|
|
|
|||
|
|
@ -30,7 +30,6 @@ frappe.data_import.ImportPreview = class ImportPreview {
|
|||
this.header_row = this.preview_data.header_row;
|
||||
this.fields = this.preview_data.fields;
|
||||
this.data = this.preview_data.data;
|
||||
this.max_rows_exceeded = this.preview_data.max_rows_exceeded;
|
||||
this.make_wrapper();
|
||||
this.prepare_columns();
|
||||
this.prepare_data();
|
||||
|
|
@ -47,6 +46,7 @@ frappe.data_import.ImportPreview = class ImportPreview {
|
|||
<div class="table-actions margin-bottom">
|
||||
</div>
|
||||
<div class="table-preview border"></div>
|
||||
<div class="table-message"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -110,7 +110,7 @@ frappe.data_import.ImportPreview = class ImportPreview {
|
|||
name: column_title,
|
||||
content: `<span class="indicator green">${df.header_title || df.label}</span>`,
|
||||
df: df,
|
||||
editable: true,
|
||||
editable: false,
|
||||
align: 'left',
|
||||
header_row_index,
|
||||
width: column_width
|
||||
|
|
@ -134,11 +134,6 @@ frappe.data_import.ImportPreview = class ImportPreview {
|
|||
this.datatable.destroy();
|
||||
}
|
||||
|
||||
let no_data_message = this.max_rows_exceeded
|
||||
? __('Cannot load preview for more than 500 rows. You can still remap or skip columns.')
|
||||
: __('No Data');
|
||||
no_data_message = `<span class="text-muted">${no_data_message}</span>`;
|
||||
|
||||
this.datatable = new DataTable(this.$table_preview.get(0), {
|
||||
data: this.data,
|
||||
columns: this.columns,
|
||||
|
|
@ -146,10 +141,19 @@ frappe.data_import.ImportPreview = class ImportPreview {
|
|||
cellHeight: 35,
|
||||
serialNoColumn: false,
|
||||
checkboxColumn: false,
|
||||
pasteFromClipboard: true,
|
||||
noDataMessage: no_data_message
|
||||
noDataMessage: __('No Data'),
|
||||
disableReorderColumn: true
|
||||
});
|
||||
|
||||
let { max_rows_exceeded, max_rows_in_preview } = this.preview_data;
|
||||
if (max_rows_exceeded) {
|
||||
this.wrapper.find('.table-message').html(`
|
||||
<div class="text-muted margin-top text-medium">
|
||||
${__('Showing only first {0} rows in preview', [max_rows_in_preview])}
|
||||
</div>
|
||||
`);
|
||||
}
|
||||
|
||||
if (this.data.length === 0) {
|
||||
this.datatable.style.setStyle('.dt-scrollable', {
|
||||
height: 'auto'
|
||||
|
|
@ -161,12 +165,6 @@ frappe.data_import.ImportPreview = class ImportPreview {
|
|||
});
|
||||
}
|
||||
|
||||
get_rows_as_csv_array() {
|
||||
return this.datatable.getRows().map(row => {
|
||||
return row.map(cell => cell.content);
|
||||
});
|
||||
}
|
||||
|
||||
setup_styles() {
|
||||
// import success checkbox
|
||||
this.datatable.style.setStyle(`svg.import-success`, {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue