每个基本组件预置一或多个实施。实施用于在用户界面中显示特定信息。如需显示不同的信息,您可以通过创建自定义实施来自定义自己的组件。例如,“项标识”基本组件预置两个实施:“部件标识”和“任务标识”。也可以创建“项标识”(如“文档标识”) 基本组件的自定义实施。
可按照以下步骤从现有基本组件创建自定义实施:
1. 选取一个现有基本组件,用作自定义实施的起始点。请根据您的 ThingWorx Navigate 版本在下表中查找基本组件,并记录其事物模板和项目。您稍后将需要此信息。
基本组件 | 事物模板 | 项目 (ThingWorx Navigate 9.0) | 项目 (ThingWorx Navigate 9.1 及更高版本) |
---|
属性 | PTC.Nav.AttributesBusinessLogicThingTemplate | PTC.Nav.AttributesProject | PTC.Nav.AttributesBusinessLogicProject |
项标识 | PTC.Nav.ItemIdentityBusinessLogicThingTemplate | PTC.Nav.ItemIdentityProject | PTC.Nav.ItemIdentityBusinessLogicProject |
项列表 | PTC.Nav.ItemListBusinessLogicThingTemplate | PTC.Nav.ItemListProject | PTC.Nav.ItemListBusinessLogicProject |
进度 | PTC.Nav.ProgressBusinessLogicThingTemplate | PTC.Nav.ProgressProject | PTC.Nav.ProgressBusinessLogicProject |
磁贴 | PTC.Nav.TilesBusinessLogicThingTemplate | PTC.Nav.TilesProject | PTC.Nav.TilesBusinessLogicProject |
2. 为自定义实施创建项目。在“项目依存项”下,输入在步骤 1 中记录的项目。保存该项目。
3. 为自定义实施创建模板。在“项目”下,输入在步骤 2 中创建的项目。在“基本事物模板”下,输入在步骤 1 中记录的事物模板。
4. 为自定义实施创建事物。在“项目”下,输入在步骤 2 中创建的项目。在“基本事物模板”下,输入在步骤 3 中记录的事物模板。
5. 在您所创建的事物中,单击
“服务”选项卡。然后,单击
以改写
GetImplementationConfigurationVersion 服务并为您的实施设置一个版本。此版本可以使用任何值。保存该事物。
6. 标识自定义实施中需要改写的服务。有关预置组件中的服务的详细信息,请在
可用组件下查找有关正在扩展的组件的主题,然后查看“自定义服务”表格。
7. 在您所创建的事物模板中,单击
“服务”选项卡。然后单击
以改写必要的服务。建议在改写其他服务之前改写
GetConfigurations 服务。
在 GetConfigurations 服务的代码中设置 implementationConfigurationVersion 的版本,使其与在步骤 5 中为 GetImplementationConfigurationVersion 设置的版本相匹配。跳过此步骤可能会导致在以后的 ThingWorx Navigate 版本中出现兼容性问题。
8. 改写剩余的必要服务。当改写以参数形式接收此配置的服务时,首先调用代码中的 Migrate 服务并传递基本和实施版本。
◦ 要确定在 Migrate 服务中使用的 targetBaseVersion 值,请对在步骤 4 中创建的事物执行 GetBaseConfigurationVersion 服务。不要调用 GetBaseConfigurationVersion 服务代码并返回其值。
◦ 在 Migrate 服务中设置 targetImplementationVersion 时,请使用之前已在步骤 5 中设置的版本。
| 改写服务时,不要改写类别为 PTC.Nav.Private 的服务。 |
9. 保存事物模板。现在,您的自定义实施已准备就绪,可供使用。要使用实施,请创建混搭。将实施的基本组件添加到混搭,然后单击
。在
“配置类型”下拉菜单中,选择属于您的自定义实施的配置。
可按照以下步骤从现有实施创建自定义实施:
1. 选取一个现有实施,用作自定义实施的起始点。
◦ 如果使用预置实施,请根据您的 ThingWorx Navigate 版本在下表中查找该实施,并记录其事物模板和项目。您稍后将需要此信息。
◦ 如果使用自定义实施,请记录其事物模板和项目。您稍后将需要此信息。
实施 | 事物模板 | 项目 (ThingWorx Navigate 9.0) | 项目 (ThingWorx Navigate 9.1 及更高版本) |
---|
活动 | PTC.Nav.ActivityBusinessLogicThingTemplate | PTC.Nav.ItemListProject | PTC.Nav.ActivityBusinessLogicProject |
受影响的项 | PTC.Nav.AffectedItemsBusinessLogicThingTemplate | PTC.Nav.ItemListProject | PTC.Nav.AttachmentsBusinessLogicProject |
附件 | PTC.Nav.AttachmentsBusinessLogicThingTemplate | PTC.Nav.ItemListProject | PTC.Nav.AffectedItemsBusinessLogicProject |
属性通用 | PTC.Nav.AttributesGenericBusinessLogicThingTemplate | PTC.Nav.AttributesProject | PTC.Nav.AttributesGenericBusinessLogicProject |
部件标识 | PTC.Nav.PartIdentityBusinessLogicThingTemplate | PTC.Nav.ItemIdentityProject | PTC.Nav.PartIdentityBusinessLogicProject |
任务标识 | PTC.Nav.TaskIdentityBusinessLogicThingTemplate | PTC.Nav.ItemIdentityProject | PTC.Nav.TaskIdentityBusinessLogicProject |
任务进度 | PTC.Nav.TaskProgressBusinessLogicThingTemplate | PTC.Nav.ProgressProject | PTC.Nav.TaskProgressBusinessLogicProject |
任务 | PTC.Nav.TaskListBusinessLogicThingTemplate | PTC.Nav.ItemListProject | PTC.Nav.TaskListBusinessLogicProject |
磁贴通用 | PTC.Nav.TilesGenericBusinessLogicThingTemplate | PTC.Nav.TilesProject | PTC.Nav.TilesGenericBusinessLogicProject |
2. 为自定义实施创建项目。在“项目依存项”下,输入在步骤 1 中记录的项目。保存该项目。
3. 为自定义实施创建模板。在“项目”下,输入在步骤 2 中创建的项目。在“基本事物模板”下,输入在步骤 1 中记录的事物模板。
4. 为自定义实施创建事物。在“项目”下,输入在步骤 2 中创建的项目。在“基本事物模板”下,输入在步骤 3 中记录的事物模板。
5. 在您所创建的事物中,单击“服务”选项卡。
◦ 单击
可将
GetBaseMigrationVersion 改写为您的
ThingWorx Navigate 版本,例如 9.0.0 或 9.1.0。
◦ 单击
可将
GetImplementationConfigurationVersion 改写为您的
ThingWorx Navigate 版本,例如 9.0.0 或 9.1.0。
6. 保存该事物。
7. 标识自定义实施中需要改写的服务。有关预置组件中的服务的详细信息,请在
可用组件下查找有关正在扩展的组件的主题,然后查看“自定义服务”表格。
8. 在您所创建的事物模板中,单击
“服务”选项卡。然后单击
以改写必要的服务。建议在改写其他服务之前改写
GetConfigurations 服务。
| • 改写 GetConfigurations 服务时,不支持从其系统预置结构更改配置结构。仅可更改单个 JSON 属性的值。有关详细信息,请参阅 配置属性更改示例主题。 • 在配置中,请确保将 implementationConfigurationVersion 属性的值设置为与 GetImplementationConfigurationVersion 服务所返回的值相同。 |
9. 改写剩余的必要服务。当改写以参数形式接收此配置的服务时,首先调用代码中的 Migrate 服务并传递基本和实施版本。
◦ 要确定将传递到 Migrate 服务的基本版本,请对在步骤 4 中创建的事物执行 GetBaseConfigurationVersion 服务。不要调用 GetBaseConfigurationVersion 服务并返回其值。
◦ 要确定将传递到 Migrate 服务的实施版本,请对在步骤 4 中创建的事物执行 GetImplementationConfigurationVersion 服务。不要调用 GetImplementationConfigurationVersion 服务并返回其值。
| 改写服务时,不要改写类别为 PTC.Nav.Private 的服务。 |
10. 保存事物模板。现在,您的自定义实施已准备就绪,可供使用。要使用实施,请创建混搭。将实施的基本组件添加到混搭,然后单击
。在
“配置类型”下拉菜单中,选择属于您的自定义实施的配置。
以下示例将展示如何创建名为“部件列表”的自定义实施,它是项列表基本组件的实施。部件列表将部件作为输入接收,并返回其包含的第一级部件。
| 以下示例旨在用于 ThingWorx Navigate 9.0,且代码段中使用的版本值适用于 ThingWorx Navigate 的此版本。在 ThingWorx Navigate 的更高版本中按照此示例进行操作时,请确保在代码中使用正确的版本值。 |
1. 在 ThingWorx Composer 中,创建名为 Demo.PartsListProject 的新项目。
◦ 在 ThingWorx Navigate 9.0 中,在“项目依存项”下输入 PTC.Nav.ItemListProject。
◦ 在 ThingWorx Navigate 9.1 及更高版本中,在“项目依存项”下输入 PTC.Nav.ItemListBusinessLogicProject。
2. 创建名为 Demo.PartsListBusinessLogicThingTemplate 的新事物模板。将“项目”设置为 Demo.PartsListProject,并将“基本事物模板”设置为 PTC.Nav.ItemListBusinessLogicThingTemplate。
3. 创建名为 Demo.PartsListBusinessLogicThing 的事物。将“项目”设置为 Demo.PartsListProject,并将“基本事物模板”设置为 Demo.PartsListBusinessLogicThingTemplate。
4. 单击
“服务”选项卡,然后查找
GetImplementationConfigurationVersion 服务。单击
以改写服务,并使用以下代码将版本设置为 1.0.0:
result = "1.0.0";
单击“完成”。单击“保存”以保存事物。
5. 检查
项列表的自定义服务表格,并标识需要在事物模板中改写的服务。对于此自定义实施,我们需要改写三个服务:
◦ GetConfigurations - 此服务返回可用于实施的配置。我们将对其进行编辑以定义部件列表的配置。
◦ GetImplementationLabel - 此服务用于返回在 Mashup Builder 中显示的实施名称。我们将其设置为显示名称 Parts List Demo。
◦ GetItems - 此服务将输入和配置作为参数接收,并返回
CCO 格式的 JSON,其中包含在“项列表”用户界面中显示的数据。我们将对其进行设置,以返回指定部件的第一级部件以及第一级部件的属性。
6. 打开 Demo.ItemListBusinessLogicThingTemplate 事物模板。单击“服务”选项卡。
7. 单击
以改写
GetConfigurations 服务。将以下代码粘贴到服务中。此代码包括一个在 Mashup Builder 和
ThingWorx Navigate 用户界面中标签为
Parts List 的“部件列表”配置。
result = {
"partsList": {
"label": "Parts List",
"configuration": {
"selectionType": {
"selectedKey": "single"
},
"waitForInput": {
"value": true
},
"actionBarConfiguration": {
"value": {
"actionBarConfigurationJSON": {
"value": ""
}
}
},
"baseConfigurationVersion": {
"value": "9.0.0"
},
"implementationConfigurationVersion": {
"value": "1.0.0"
},
"defaultSortFields": {
"selectedValues": {
"data": [{
"itemListsData": [{
"items": [{
"additionalData": {
"itemListDefaultSortFieldDefinition": {
"defaultSortDirection": {
"selectedKey": "asc"
}
}
},
"id": "Name"
}
],
"objectType": "PTC.ProdMgmt.Part"
}
],
"adapter": {
"instanceName": "windchill",
"thingName": "PTC.WCAdapter"
}
}
]
}
},
"attributes": {
"selectedValues": {
"data": [{
"itemListsData": [{
"items": [{
"id": "Name",
"ordinal": 1
}, {
"id": "State#Display",
"ordinal": 2
}, {
"id": "Version",
"ordinal": 3
}, {
"id": "Number",
"ordinal": 0
}, {
"id": "ID",
"ordinal": 4
}
],
"objectType": "PTC.ProdMgmt.Part"
}
],
"adapter": {
"instanceName": "windchill",
"thingName": "PTC.WCAdapter"
}
}
]
},
"inTailoring": false
},
"label": {
"value": "Parts List"
},
"showExportAction": {
"value": true
},
"enableSearch": {
"additionalData": {
"itemListSearchDefinition": {
"searchHintText": {
"value": "Find"
}
}
},
"value": true
},
"maxNumberOfRowsInGrid": {
"inTailoring": false,
"value": 50
}
}
}
};
此处是 GetConfigurations 的另一个示例代码,其中包含两个而非一个配置。第一个配置与上述代码中的配置相同。第二个配置用于部件列表的小型版本。它仅显示三个属性和最多五行。它在 Mashup Builder 中标签为 Parts List mini,在 ThingWorx Navigate 用户界面中标签为 Parts List。
result = {
"partsList": {
"label": "Parts List",
"configuration": {
"selectionType": {
"selectedKey": "single"
},
"waitForInput": {
"value": true
},
"actionBarConfiguration": {
"value": {
"actionBarConfigurationJSON": {
"value": ""
}
}
},
"baseConfigurationVersion": {
"value": "9.0.0"
},
"implementationConfigurationVersion": {
"value": "1.0.0"
},
"defaultSortFields": {
"selectedValues": {
"data": [{
"itemListsData": [{
"items": [{
"additionalData": {
"itemListDefaultSortFieldDefinition": {
"defaultSortDirection": {
"selectedKey": "asc"
}
}
},
"id": "Name"
}
],
"objectType": "PTC.ProdMgmt.Part"
}
],
"adapter": {
"instanceName": "windchill",
"thingName": "PTC.WCAdapter"
}
}
]
}
},
"attributes": {
"selectedValues": {
"data": [{
"itemListsData": [{
"items": [{
"id": "Name",
"ordinal": 1
}, {
"id": "State#Display",
"ordinal": 2
}, {
"id": "Version",
"ordinal": 3
}, {
"id": "Number",
"ordinal": 0
}, {
"id": "ID",
"ordinal": 4
}
],
"objectType": "PTC.ProdMgmt.Part"
}
],
"adapter": {
"instanceName": "windchill",
"thingName": "PTC.WCAdapter"
}
}
]
},
"inTailoring": false
},
"label": {
"value": "Parts List"
},
"showExportAction": {
"value": true
},
"enableSearch": {
"additionalData": {
"itemListSearchDefinition": {
"searchHintText": {
"value": "Find"
}
}
},
"value": true
},
"maxNumberOfRowsInGrid": {
"inTailoring": false,
"value": 50
}
}
},
"partsListMini": {
"label": "Parts List mini",
"configuration": {
"selectionType": {
"selectedKey": "single"
},
"waitForInput": {
"value": true
},
"actionBarConfiguration": {
"value": {
"actionBarConfigurationJSON": {
"value": ""
}
}
},
"baseConfigurationVersion": {
"value": "9.0.0"
},
"implementationConfigurationVersion": {
"value": "1.0.0"
},
"defaultSortFields": {
"selectedValues": {
"data": [{
"itemListsData": [{
"items": [{
"additionalData": {
"itemListDefaultSortFieldDefinition": {
"defaultSortDirection": {
"selectedKey": "asc"
}
}
},
"id": "Name"
}
],
"objectType": "PTC.ProdMgmt.Part"
}
],
"adapter": {
"instanceName": "windchill",
"thingName": "PTC.WCAdapter"
}
}
]
}
},
"attributes": {
"selectedValues": {
"data": [{
"itemListsData": [{
"items": [{
"id": "Name",
"ordinal": 1
}, {
"id": "Version",
"ordinal": 2
}, {
"id": "Number",
"ordinal": 0
}
],
"objectType": "PTC.ProdMgmt.Part"
}
],
"adapter": {
"instanceName": "windchill",
"thingName": "PTC.WCAdapter"
}
}
]
},
"inTailoring": false
},
"label": {
"value": "Parts List"
},
"showExportAction": {
"value": true
},
"enableSearch": {
"additionalData": {
"itemListSearchDefinition": {
"searchHintText": {
"value": "Find"
}
}
},
"value": true
},
"maxNumberOfRowsInGrid": {
"inTailoring": false,
"value": 5
}
}
}
};
添加代码后,单击“完成”。
8. 改写 GetImplementationLabel 服务。使用以下代码设置实施标签:
result = "Parts List Demo";
单击“完成”。
9. GetItems 服务将从 Windchill 检索第一级部件,过程如下:
a. 通过服务
ConvertAttributesToCCO (我们将创建) 将配置的属性部分转换为
CCO 结构。
b. 将生成的
CCO 格式的 JSON 传递到
PTC.WCAdapter 的
GetRelatedItems 服务。此服务将数据作为
UsageLink 对象检索。
c. 使用 ConvertUsageLinkToPart 服务(我们将创建)将 UsageLink 对象转换为 Part 对象。
在改写 GetItems 服务之前,需要创建服务 ConvertAttributesToCCO 和 ConvertUsageLinkToPart。
10. 创建新服务并将其命名为 ConvertAttributesToCCO。在“输入”下,添加以下输入:
◦ configuration,其“基本类型”为 JSON
◦ attributesPrefix,其“基本类型”为 STRING
◦ replaceObjectType,其“基本类型”为 STRING
在“输出”下,从下拉菜单中选择 JSON。
11. 将以下代码粘贴到 ConvertAttributesToCCO 服务中:
let attributesData = configuration.attributes.selectedValues;
attributesPrefix = attributesPrefix || "";
let objectType = replaceObjectType || attributesData.data[0].itemListsData[0].objectType;
attributesData.data[0].itemListsData[0].objectType = objectType;
let items = attributesData.data[0].itemListsData[0].items;
let newItems = [];
let newObj = {};
let hasID = false;
//convert to CCO
for(var i = 0; i < items.length; i++) {
let item = items[i];
if (item.id === 'ID') {
hasID = true;
}
newObj[attributesPrefix + item.id] = {"value":""};
}
//add ID if needed
if (!hasID) {
newObj[attributesPrefix + 'ID'] = {"value":""};
}
newItems.push (newObj);
attributesData.data[0].itemListsData[0].items = newItems;
//create date
var dateValue = new Date();
var y = dateValue.getFullYear();
var mo = dateValue.getMonth()+1;
if(mo<10) {mo='0'+mo;}
var d = dateValue.getDate();
if(d<10) {d='0'+d;}
//create time
var h = dateValue.getHours();
if(h<10) {h='0'+h;}
var mi = dateValue.getMinutes();
if(mi<10) {mi='0'+mi;}
var s = dateValue.getSeconds();
if(s<10) {s='0'+s;}
var ms = dateValue.getMilliseconds();
if(ms<10) {ms='00'+ms;} else {if(ms>=10 && ms<100) {ms='0'+ms;}}
attributesData.timeStamp = y + "-" + mo + "-" + d + " " + h + ":" + mi + ":" + s + "." + ms;
attributesData.version = "";
attributesData.statusMessage = "OK";
attributesData.status = "200";
result = attributesData;
单击“完成”。
12. 创建新服务并将其命名为 ConvertUsageLinkToPart。在“输入”下,添加以下输入:
◦ usageLinkCCO,其“基本类型”为 JSON
在“输出”下,从下拉菜单中选择 JSON。
13. 将以下代码粘贴到 ConvertUsageLinkToPart 服务中:
let itemListsData = usageLinkCCO.data[0].itemListsData[0];
let tempMetadata = itemListsData.metadata;
let items = itemListsData.items;
//convert metadata
delete tempMetadata.ID;
let newMetadata = {};
for (var key in tempMetadata) {
let newKey = key.replace(/^(Uses\|)/,"");
newMetadata[newKey] = tempMetadata[key];
}
newMetadata['id'] = newMetadata.ID;
itemListsData['metadata'] = newMetadata;
//convert Items
let newItems = [];
for (var i=0 ; i<items.length ; i++) {
let item = items[i];
let newItem = {};
for (key in item) {
let newKey = key.replace(/^(Uses\|)/,"");
newItem[newKey] = item[key];
}
newItem['id'] = newItem.ID;
newItems.push(newItem);
}
itemListsData['items'] = newItems;
itemListsData['objectType'] = 'PTC.ProdMgmt.Part';
//update CCO
let partsListCCO = usageLinkCCO;
partsListCCO.data[0].itemListsData = [itemListsData];
result = partsListCCO;
单击“完成”。
14. 单击
以改写
GetItems 服务。将以下代码粘贴到
GetItems 服务中:
var migratedConfig = me.Migrate({
targetImplementationVersion: "1.0.0" /* STRING */,
data: configuration /* JSON */,
migrationType: "Configuration" /* STRING */,
targetBaseVersion: "9.0.0" /* STRING */
});
var attributesConfigurationCCO = me.ConvertAttributesToCCO({
configuration:migratedConfig /* JSON */,
attributesPrefix: "Uses|" /* STRING */,
replaceObjectType: "PTC.ProdMgmt.PartUse" /* STRING */
});
// result: JSON
var tempResult = Things["PTC.WCAdapter"].GetRelatedItems({
item: input /* JSON */,
relation: {path:"Uses"} /* JSON */,
attributes: attributesConfigurationCCO /* JSON */
});
var convertedResults = me.ConvertUsageLinkToPart({
usageLinkCCO:tempResult /* JSON */
});
var result = convertedResults;
单击“完成”。然后单击“保存”以保存事物模板。
现在,“部件列表”自定义实施及其配置即创建完毕,可以在 Mashup Builder 中使用。要使用实施,请将项列表基本组件添加到混搭,然后单击
。在
“配置类型”下拉菜单中,选择标签为
Parts Lists Demo - Parts List 的部件列表配置。
如果您要使用“部件列表”创建下面视频中所示的混搭,那么一些附加代码如下所示:
• 用于配置 Attributes 组件的代码:
{
"layout": {
"selectedKey": "horizontal",
"additionalData": {
"dimensionDefinition": {
"maxHeight": {
"value": 200,
"version": "1.0.0"
},
"maxWidth": {
"value": 200,
"version": "1.0.0"
}
}
},
"version": "1.0.0"
},
"attributes": {
"sets": [{
"data": {
"selectedValues": {
"data": [{
"itemListsData": [{
"items": [{
"id": "ModifiedBy",
"ordinal": 0
}, {
"id": "GatheringPart",
"ordinal": 1
}, {
"id": "Latest",
"ordinal": 2
}, {
"id": "FolderName",
"ordinal": 3
}
],
"objectType": "PTC.ProdMgmt.Part"
}
],
"adapter": {
"instanceName": "windchill",
"thingName": "PTC.WCAdapter"
}
}
]
}
},
"name": ""
}
],
"inTailoring": true,
"filteredValues": {
"data": [{
"itemListsData": [{
"objectType": ""
}
],
"adapter": {
"instanceName": "",
"thingName": ""
}
}
]
},
"version": "1.0.0"
}
}
• 用于混搭 input 参数的代码。请确保添加一个有效的部件 ID:
{
"version": "1.0.0",
"data": [{
"adapter": {
"thingName": "PTC.WCAdapter",
"instanceName": "windchill"
},
"itemListsData": [{
"objectType": "PTC.ProdMgmt.Part",
"items": [{
"id": {
"value": ""
}
}
]
}
]
}
]
}
下面两个视频教程演示了如何创建和使用自定义实施“部件列表”。第一个视频演示了如何创建“部件列表”,请遵循上面示例中所示的步骤。第二个视频演示了如何在混搭中使用“部件列表”。您可以在上述示例中找到这些视频中使用的所有代码。