UI parser choise
This commit is contained in:
parent
c4719913b3
commit
98334009c5
@ -123,6 +123,18 @@ class ImportApp(QMainWindow):
|
|||||||
import_layout.addWidget(self.import_label)
|
import_layout.addWidget(self.import_label)
|
||||||
import_layout.addWidget(self.import_type)
|
import_layout.addWidget(self.import_type)
|
||||||
|
|
||||||
|
# === parserName (если предусмотрен шаблоном) ===
|
||||||
|
self.parser_label = QLabel("Parser name:")
|
||||||
|
self.parser_box = QComboBox()
|
||||||
|
self.parser_box.setEditable(True) # можно вписать вручную
|
||||||
|
self.parser_label.hide()
|
||||||
|
self.parser_box.hide()
|
||||||
|
|
||||||
|
parser_layout = QHBoxLayout()
|
||||||
|
parser_layout.addWidget(self.parser_label)
|
||||||
|
parser_layout.addWidget(self.parser_box)
|
||||||
|
main_layout.addLayout(parser_layout)
|
||||||
|
|
||||||
# Кнопки Excel
|
# Кнопки Excel
|
||||||
self.btn_load_excel = QPushButton("📂 Загрузить Excel-файл")
|
self.btn_load_excel = QPushButton("📂 Загрузить Excel-файл")
|
||||||
self.btn_load_excel.clicked.connect(self.load_excel)
|
self.btn_load_excel.clicked.connect(self.load_excel)
|
||||||
@ -206,6 +218,22 @@ class ImportApp(QMainWindow):
|
|||||||
with open(path, "r", encoding="utf-8") as f:
|
with open(path, "r", encoding="utf-8") as f:
|
||||||
self.current_mapping = json.load(f)
|
self.current_mapping = json.load(f)
|
||||||
self.log(f"📘 Загружен шаблон: {import_type}")
|
self.log(f"📘 Загружен шаблон: {import_type}")
|
||||||
|
# Если шаблон содержит parserName с choices — показать выбор
|
||||||
|
fields = self.current_mapping.get("fields", {})
|
||||||
|
parser_meta = fields.get("parserName", {})
|
||||||
|
|
||||||
|
if isinstance(parser_meta, dict) and "choices" in parser_meta:
|
||||||
|
self.parser_label.show()
|
||||||
|
self.parser_box.show()
|
||||||
|
self.parser_box.clear()
|
||||||
|
for opt in parser_meta["choices"]:
|
||||||
|
self.parser_box.addItem(opt)
|
||||||
|
# выбираем первый как дефолт
|
||||||
|
self.parser_box.setCurrentIndex(0)
|
||||||
|
else:
|
||||||
|
self.parser_label.hide()
|
||||||
|
self.parser_box.hide()
|
||||||
|
|
||||||
self.populate_map_table()
|
self.populate_map_table()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.current_mapping = {}
|
self.current_mapping = {}
|
||||||
@ -421,7 +449,19 @@ class ImportApp(QMainWindow):
|
|||||||
# "parserName": fixed или из поля,
|
# "parserName": fixed или из поля,
|
||||||
# "items": [ { category:{name}, brand:{name}, variant:{...} } ]
|
# "items": [ { category:{name}, brand:{name}, variant:{...} } ]
|
||||||
# }
|
# }
|
||||||
parser_name = fields_meta.get("parserName", {}).get("fixed", "ikea")
|
parser_meta = fields_meta.get("parserName", {})
|
||||||
|
parser_name = "unknown"
|
||||||
|
|
||||||
|
# если есть choices — берём выбранное из UI
|
||||||
|
if isinstance(parser_meta, dict) and "choices" in parser_meta:
|
||||||
|
parser_name = self.parser_box.currentText().strip() or parser_meta["choices"][0]
|
||||||
|
# иначе если fixed
|
||||||
|
elif isinstance(parser_meta, dict) and "fixed" in parser_meta:
|
||||||
|
parser_name = parser_meta["fixed"]
|
||||||
|
# fallback
|
||||||
|
else:
|
||||||
|
parser_name = "xlsx-parser"
|
||||||
|
|
||||||
result = {"parserName": parser_name, "items": []}
|
result = {"parserName": parser_name, "items": []}
|
||||||
|
|
||||||
# подготовим индекс колонок
|
# подготовим индекс колонок
|
||||||
|
|||||||
@ -27,8 +27,8 @@
|
|||||||
"fields": {
|
"fields": {
|
||||||
"parserName": {
|
"parserName": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"fixed": "ikea",
|
"choices": ["ikea", "B2Parf", "Decathlon"],
|
||||||
"description": "Идентификатор парсера (постоянный)"
|
"description": "Идентификатор парсера (выбор из списка)"
|
||||||
},
|
},
|
||||||
"category.name": { "type": "string", "source": "путь категории" },
|
"category.name": { "type": "string", "source": "путь категории" },
|
||||||
"brand.name": { "type": "string", "source": "название бренда" },
|
"brand.name": { "type": "string", "source": "название бренда" },
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user