fix: Select "Don't Import" to skip a column
- Remove separate skip_column structure - Simpler Map Columns dialog
This commit is contained in:
parent
addc20cde4
commit
d5c6a69e23
5 changed files with 41 additions and 75 deletions
|
|
@ -27,7 +27,7 @@ class Importer:
|
|||
def __init__(self, doctype, data_import=None, file_path=None, content=None):
|
||||
self.doctype = doctype
|
||||
self.template_options = frappe._dict(
|
||||
{"remap_column": {}, "skip_import": [], "edited_rows": []}
|
||||
{"remap_column": {}, "edited_rows": []}
|
||||
)
|
||||
|
||||
if data_import:
|
||||
|
|
@ -164,7 +164,6 @@ class Importer:
|
|||
|
||||
def parse_fields_from_header_row(self):
|
||||
remap_column = self.template_options.remap_column
|
||||
skip_import = self.template_options.skip_import
|
||||
fields = []
|
||||
warnings = []
|
||||
|
||||
|
|
@ -173,8 +172,8 @@ class Importer:
|
|||
for i, header_title in enumerate(self.header_row):
|
||||
header_row_index = str(i)
|
||||
column_number = str(i + 1)
|
||||
if remap_column.get(header_row_index):
|
||||
fieldname = remap_column.get(header_row_index)
|
||||
fieldname = remap_column.get(header_row_index)
|
||||
if fieldname and fieldname != "Don't Import":
|
||||
df = df_by_labels_and_fieldnames.get(fieldname)
|
||||
warnings.append(
|
||||
{
|
||||
|
|
@ -194,7 +193,7 @@ class Importer:
|
|||
field.header_title = header_title
|
||||
field.skip_import = False
|
||||
|
||||
if i in skip_import:
|
||||
if fieldname == "Don't Import":
|
||||
field.skip_import = True
|
||||
warnings.append(
|
||||
{
|
||||
|
|
|
|||
|
|
@ -197,36 +197,10 @@ frappe.ui.form.on('Data Import Beta', {
|
|||
let template_options = JSON.parse(frm.doc.template_options || '{}');
|
||||
template_options.remap_column = template_options.remap_column || {};
|
||||
Object.assign(template_options.remap_column, changed_map);
|
||||
|
||||
// if the column is remapped, remove it from skip_import
|
||||
if (template_options.skip_import) {
|
||||
template_options.skip_import = template_options.skip_import.filter(
|
||||
d => !Object.keys(template_options.remap_column).includes(cstr(d))
|
||||
);
|
||||
}
|
||||
frm.set_value('template_options', JSON.stringify(template_options));
|
||||
frm.save().then(() => frm.trigger('import_file'));
|
||||
},
|
||||
|
||||
skip_import(header_row_index) {
|
||||
let template_options = JSON.parse(frm.doc.template_options || '{}');
|
||||
template_options.skip_import = template_options.skip_import || [];
|
||||
if (!template_options.skip_import.includes(header_row_index)) {
|
||||
template_options.skip_import.push(header_row_index);
|
||||
}
|
||||
// if column is being skipped, remove it from remap_column
|
||||
if (
|
||||
template_options.remap_column &&
|
||||
template_options.remap_column[header_row_index]
|
||||
) {
|
||||
delete template_options.remap_column[header_row_index];
|
||||
}
|
||||
frm.set_value('template_options', JSON.stringify(template_options));
|
||||
frm.save().then(() => {
|
||||
frm.trigger('import_file');
|
||||
});
|
||||
},
|
||||
|
||||
export_errored_rows() {
|
||||
open_url_post('/api/method/frappe.core.doctype.data_import_beta.data_import_beta.download_errored_template', {
|
||||
data_import_name: frm.doc.name
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ class DataImportBeta(Document):
|
|||
|
||||
def start_import(self):
|
||||
if frappe.utils.scheduler.is_scheduler_inactive():
|
||||
frappe.throw(_("Scheduler is inactive. Cannot import data."), title=_("Error"))
|
||||
frappe.throw(_("Scheduler is inactive. Cannot import data."), title=_("Scheduler Inactive"))
|
||||
|
||||
enqueued_jobs = [d.get("job_name") for d in get_info()]
|
||||
|
||||
|
|
@ -46,7 +46,7 @@ class DataImportBeta(Document):
|
|||
event="data_import",
|
||||
job_name=self.name,
|
||||
data_import=self.name,
|
||||
# now=True
|
||||
now=True
|
||||
)
|
||||
|
||||
def get_importer(self):
|
||||
|
|
|
|||
|
|
@ -249,31 +249,27 @@ frappe.data_import.ImportPreview = class ImportPreview {
|
|||
}
|
||||
return [
|
||||
{
|
||||
label: __('Column {0}', [i]),
|
||||
label: '',
|
||||
fieldtype: 'Data',
|
||||
default: df.header_title,
|
||||
fieldname: `Column ${i}`,
|
||||
read_only: 1
|
||||
},
|
||||
{
|
||||
fieldtype: 'Button',
|
||||
label: 'Skip Column',
|
||||
fieldname: 'skip_' + i,
|
||||
click: () => {
|
||||
let header_row_index = i - 1;
|
||||
this.events.skip_import(header_row_index);
|
||||
}
|
||||
},
|
||||
{
|
||||
fieldtype: 'Column Break'
|
||||
},
|
||||
{
|
||||
fieldtype: 'Autocomplete',
|
||||
fieldname: i,
|
||||
label: __('Select field'),
|
||||
label: '',
|
||||
max_items: Infinity,
|
||||
options: column_picker_fields.get_fields_as_options(),
|
||||
default: fieldname,
|
||||
options: [
|
||||
{
|
||||
label: __("Don't Import"),
|
||||
value: "Don't Import"
|
||||
}
|
||||
].concat(column_picker_fields.get_fields_as_options()),
|
||||
default: fieldname || "Don't Import",
|
||||
change() {
|
||||
changed.push(i);
|
||||
}
|
||||
|
|
@ -285,8 +281,24 @@ frappe.data_import.ImportPreview = class ImportPreview {
|
|||
});
|
||||
// flatten the array
|
||||
fields = fields.reduce((acc, curr) => [...acc, ...curr]);
|
||||
let file_name = (this.frm.doc.import_file || '').split('/').pop();
|
||||
fields = [
|
||||
{
|
||||
fieldtype: 'HTML',
|
||||
fieldname: 'heading',
|
||||
options: `
|
||||
<div class="margin-top text-muted">
|
||||
${__('Map columns from {0} to fields in {1}', [file_name.bold(), this.doctype.bold()])}
|
||||
</div>
|
||||
`
|
||||
},
|
||||
{
|
||||
fieldtype: 'Section Break'
|
||||
}
|
||||
].concat(fields);
|
||||
|
||||
let dialog = new frappe.ui.Dialog({
|
||||
title: __('Column Mapper'),
|
||||
title: __('Map Columns'),
|
||||
fields,
|
||||
primary_action: (values) => {
|
||||
let changed_map = {};
|
||||
|
|
@ -300,37 +312,10 @@ frappe.data_import.ImportPreview = class ImportPreview {
|
|||
dialog.hide();
|
||||
}
|
||||
});
|
||||
dialog.$body.addClass('map-columns');
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
remap_column(col) {
|
||||
let column_picker_fields = new ColumnPickerFields({
|
||||
doctype: this.doctype
|
||||
});
|
||||
let dialog = new frappe.ui.Dialog({
|
||||
title: __('Remap Column: {0}', [col.name]),
|
||||
fields: [
|
||||
{
|
||||
fieldtype: 'Autocomplete',
|
||||
fieldname: 'fieldname',
|
||||
label: __('Select field'),
|
||||
max_items: Infinity,
|
||||
options: column_picker_fields.get_fields_as_options()
|
||||
}
|
||||
],
|
||||
primary_action: ({ fieldname }) => {
|
||||
if (!fieldname) return;
|
||||
this.events.remap_column(col.header_row_index, fieldname);
|
||||
dialog.hide();
|
||||
}
|
||||
});
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
skip_import(col) {
|
||||
this.events.skip_import(col.header_row_index);
|
||||
}
|
||||
|
||||
is_row_imported(row) {
|
||||
let serial_no = row[0].content;
|
||||
return this.import_log.find(log => {
|
||||
|
|
|
|||
|
|
@ -984,3 +984,11 @@ body[data-route^="Form/Communication"] textarea[data-fieldname="subject"] {
|
|||
.followed-by-label{
|
||||
margin-top: 30px;
|
||||
}
|
||||
|
||||
.map-columns .form-section {
|
||||
padding: 0 7px 7px;
|
||||
}
|
||||
|
||||
.map-columns .form-section:first-child {
|
||||
padding-top: 7px;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue