updates
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
const { assetCategoryManager } = require('../../datasets/assetData');
|
||||
const assetApiConfig = require('../configs/assetApiConfig.js');
|
||||
|
||||
class AssetMenu {
|
||||
constructor({ manager = assetCategoryManager, softwareType = null } = {}) {
|
||||
@@ -67,7 +68,11 @@ class AssetMenu {
|
||||
|
||||
return {
|
||||
categories: selectedCategories,
|
||||
defaultCategory: categoryKey
|
||||
defaultCategory: categoryKey,
|
||||
apiConfig: {
|
||||
url: `${assetApiConfig.baseUrl}/apis/products/PLC/integration/`,
|
||||
headers: { ...assetApiConfig.headers }
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -107,13 +112,7 @@ class AssetMenu {
|
||||
const menuAsset = window.EVOLV.nodes.${nodeName}.menuData.asset || {};
|
||||
const categories = menuAsset.categories || {};
|
||||
const defaultCategory = menuAsset.defaultCategory || Object.keys(categories)[0] || null;
|
||||
const apiConfig = menuAsset.apiConfig || {
|
||||
url: 'http://localhost:8000/apis/products/PLC/integration/',
|
||||
headers: {
|
||||
accept: 'application/json',
|
||||
Authorization: '4a49332a-fc3e-11f0-bf0a-9457f8d645d9'
|
||||
}
|
||||
};
|
||||
const apiConfig = menuAsset.apiConfig || {};
|
||||
const elems = {
|
||||
supplier: document.getElementById('node-input-supplier'),
|
||||
type: document.getElementById('node-input-assetType'),
|
||||
@@ -133,7 +132,7 @@ class AssetMenu {
|
||||
|
||||
function normalizeModel(model = {}) {
|
||||
return {
|
||||
id: model.id || model.name,
|
||||
id: model.id ?? model.name,
|
||||
name: model.name,
|
||||
units: model.units || []
|
||||
};
|
||||
@@ -261,7 +260,7 @@ class AssetMenu {
|
||||
);
|
||||
|
||||
const activeSupplier = suppliers.find(
|
||||
(supplier) => (supplier.id || supplier.name) === node.supplier
|
||||
(supplier) => String(supplier.id || supplier.name) === String(node.supplier)
|
||||
);
|
||||
const types = activeSupplier ? activeSupplier.types : [];
|
||||
populate(
|
||||
@@ -273,7 +272,7 @@ class AssetMenu {
|
||||
);
|
||||
|
||||
const activeType = types.find(
|
||||
(type) => (type.id || type.name) === node.assetType
|
||||
(type) => String(type.id || type.name) === String(node.assetType)
|
||||
);
|
||||
const models = activeType ? activeType.models : [];
|
||||
populate(
|
||||
@@ -285,10 +284,11 @@ class AssetMenu {
|
||||
);
|
||||
|
||||
const activeModel = models.find(
|
||||
(model) => (model.id || model.name) === node.model
|
||||
(model) => String(model.id || model.name) === String(node.model)
|
||||
);
|
||||
if (activeModel) {
|
||||
node.modelMetadata = activeModel;
|
||||
node.modelName = activeModel.name;
|
||||
}
|
||||
populate(
|
||||
elems.unit,
|
||||
@@ -376,7 +376,7 @@ class AssetMenu {
|
||||
const category = getActiveCategory();
|
||||
const supplier = category
|
||||
? category.suppliers.find(
|
||||
(item) => (item.id || item.name) === elems.supplier.value
|
||||
(item) => String(item.id || item.name) === String(elems.supplier.value)
|
||||
)
|
||||
: null;
|
||||
const types = supplier ? supplier.types : [];
|
||||
@@ -396,12 +396,12 @@ class AssetMenu {
|
||||
const category = getActiveCategory();
|
||||
const supplier = category
|
||||
? category.suppliers.find(
|
||||
(item) => (item.id || item.name) === elems.supplier.value
|
||||
(item) => String(item.id || item.name) === String(elems.supplier.value)
|
||||
)
|
||||
: null;
|
||||
const type = supplier
|
||||
? supplier.types.find(
|
||||
(item) => (item.id || item.name) === elems.type.value
|
||||
(item) => String(item.id || item.name) === String(elems.type.value)
|
||||
)
|
||||
: null;
|
||||
const models = type ? type.models : [];
|
||||
@@ -426,20 +426,21 @@ class AssetMenu {
|
||||
const category = getActiveCategory();
|
||||
const supplier = category
|
||||
? category.suppliers.find(
|
||||
(item) => (item.id || item.name) === elems.supplier.value
|
||||
(item) => String(item.id || item.name) === String(elems.supplier.value)
|
||||
)
|
||||
: null;
|
||||
const type = supplier
|
||||
? supplier.types.find(
|
||||
(item) => (item.id || item.name) === elems.type.value
|
||||
(item) => String(item.id || item.name) === String(elems.type.value)
|
||||
)
|
||||
: null;
|
||||
const model = type
|
||||
? type.models.find(
|
||||
(item) => (item.id || item.name) === elems.model.value
|
||||
(item) => String(item.id || item.name) === String(elems.model.value)
|
||||
)
|
||||
: null;
|
||||
node.modelMetadata = model;
|
||||
node.modelName = model ? model.name : '';
|
||||
populate(
|
||||
elems.unit,
|
||||
model ? model.units || [] : [],
|
||||
@@ -634,6 +635,9 @@ class AssetMenu {
|
||||
acc[field] = node[field];
|
||||
return acc;
|
||||
}, {});
|
||||
if (node.modelMetadata && typeof node.modelMetadata.id !== 'undefined') {
|
||||
saved.modelId = node.modelMetadata.id;
|
||||
}
|
||||
console.log('[AssetMenu] save result:', saved);
|
||||
|
||||
if (errors.length === 0 && this.syncAsset) {
|
||||
|
||||
Reference in New Issue
Block a user