@riil-frontend/component-topology 11.0.11 → 11.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -22,12 +22,12 @@ var _keyBy = _interopRequireDefault(require("lodash/keyBy"));
22
22
  /**
23
23
  * Ci类型属性、指标缓存
24
24
  */
25
- var CiTyeCache = /*#__PURE__*/function () {
26
- function CiTyeCache() {
25
+ var CiTypeCache = /*#__PURE__*/function () {
26
+ function CiTypeCache() {
27
27
  this.cache = {};
28
28
  }
29
29
 
30
- var _proto = CiTyeCache.prototype;
30
+ var _proto = CiTypeCache.prototype;
31
31
 
32
32
  _proto.getCiTypeMap = /*#__PURE__*/function () {
33
33
  var _getCiTypeMap = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(ciTypeIds) {
@@ -71,7 +71,7 @@ var CiTyeCache = /*#__PURE__*/function () {
71
71
  var _load = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(ciTypeIds) {
72
72
  var _this = this;
73
73
 
74
- var unLoadCiTypeIds, ciTypeMetas, cache;
74
+ var unLoadCiTypeIds, ciTypeMetas;
75
75
  return _regenerator["default"].wrap(function _callee2$(_context2) {
76
76
  while (1) {
77
77
  switch (_context2.prev = _context2.next) {
@@ -84,36 +84,10 @@ var CiTyeCache = /*#__PURE__*/function () {
84
84
 
85
85
  case 3:
86
86
  ciTypeMetas = _context2.sent;
87
- cache = (0, _extends2["default"])({}, this.cache);
88
- ciTypeMetas.forEach(function (ciTypeMeta) {
89
- var attributes = (ciTypeMeta.attributes || []).map(function (attr) {
90
- if (ciTypeMeta.code !== 'network_link') {
91
- return attr;
92
- } // 链路属性名称转化,临时方案
93
-
94
-
95
- var name = {
96
- source_id: '源端口',
97
- destination_id: '目的端口'
98
- }[attr.code] || attr.name;
99
- var userVisible = ['source_id', 'destination_id'].indexOf(attr.code) !== -1 ? true : attr.userVisible;
100
- return (0, _extends2["default"])({}, attr, {
101
- name: name,
102
- userVisible: userVisible
103
- });
104
- });
105
- var metrics = ciTypeMeta.metrics || [];
106
- cache[ciTypeMeta.code] = (0, _extends2["default"])({}, ciTypeMeta, {
107
- attributes: attributes,
108
- attributeMap: (0, _keyBy["default"])(attributes, 'code'),
109
- metrics: metrics,
110
- metricMap: (0, _keyBy["default"])(metrics, 'code')
111
- });
112
- });
113
- this.cache = cache;
87
+ this.addCiTypes(ciTypeMetas);
114
88
  return _context2.abrupt("return", this.cache);
115
89
 
116
- case 8:
90
+ case 6:
117
91
  case "end":
118
92
  return _context2.stop();
119
93
  }
@@ -128,15 +102,32 @@ var CiTyeCache = /*#__PURE__*/function () {
128
102
  return load;
129
103
  }();
130
104
 
105
+ _proto.addCiTypes = function addCiTypes(ciTypeMetas) {
106
+ var _this2 = this;
107
+
108
+ ciTypeMetas.forEach(function (ciTypeMeta) {
109
+ _this2.addCiType(ciTypeMeta);
110
+ });
111
+ };
112
+
113
+ _proto.addCiType = function addCiType(ciTypeMeta) {
114
+ var cache = (0, _extends2["default"])({}, this.cache);
115
+ var attributes = adapterNetworkLinkAttributes(ciTypeMeta, ciTypeMeta.attributes || []);
116
+ var metrics = ciTypeMeta.metrics || [];
117
+ cache[ciTypeMeta.code] = (0, _extends2["default"])({}, ciTypeMeta, {
118
+ attributes: attributes,
119
+ attributeMap: (0, _keyBy["default"])(attributes, 'code'),
120
+ metrics: metrics,
121
+ metricMap: (0, _keyBy["default"])(metrics, 'code')
122
+ });
123
+ this.cache = cache;
124
+ };
125
+
131
126
  _proto.getCiType = function getCiType(typeCode) {
132
127
  return this.cache[typeCode];
133
128
  };
134
129
 
135
130
  _proto.getCiTypeByCi = function getCiTypeByCi(ci) {
136
- // if (ci.ciType === 'network_link') {
137
- // const supportTemplates = link.attributes.support_templates;
138
- // } else {
139
- // }
140
131
  return this.getCiType(ci.ciType);
141
132
  };
142
133
 
@@ -150,15 +141,34 @@ var CiTyeCache = /*#__PURE__*/function () {
150
141
  return ciType === null || ciType === void 0 ? void 0 : ciType.metricMap[metricCode];
151
142
  };
152
143
 
153
- (0, _createClass2["default"])(CiTyeCache, [{
144
+ (0, _createClass2["default"])(CiTypeCache, [{
154
145
  key: "ciTypes",
155
146
  get: function get() {
156
147
  return this.cache;
157
148
  }
158
149
  }]);
159
- return CiTyeCache;
150
+ return CiTypeCache;
160
151
  }();
161
152
 
162
- var _default = new CiTyeCache();
153
+ function adapterNetworkLinkAttributes(ciTypeMeta, attributes) {
154
+ return attributes.map(function (attr) {
155
+ if (ciTypeMeta.code !== 'network_link') {
156
+ return attr;
157
+ } // 链路属性名称转化,临时方案
158
+
159
+
160
+ var name = {
161
+ source_id: '源端口',
162
+ destination_id: '目的端口'
163
+ }[attr.code] || attr.name;
164
+ var userVisible = ['source_id', 'destination_id'].indexOf(attr.code) !== -1 ? true : attr.userVisible;
165
+ return (0, _extends2["default"])({}, attr, {
166
+ name: name,
167
+ userVisible: userVisible
168
+ });
169
+ });
170
+ }
171
+
172
+ var _default = new CiTypeCache();
163
173
 
164
174
  exports["default"] = _default;
@@ -11,15 +11,21 @@ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")
11
11
 
12
12
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
13
13
 
14
+ var _keyBy = _interopRequireDefault(require("lodash/keyBy"));
15
+
16
+ var _rlog = _interopRequireDefault(require("@riil-frontend/component-topology-utils/lib/rlog"));
17
+
14
18
  var _utils = require("./utils");
15
19
 
16
20
  var _tagtip = require("../../services/topo/tagtip");
17
21
 
18
- var _rlog = _interopRequireDefault(require("@riil-frontend/component-topology-utils/lib/rlog"));
19
-
22
+ /**
23
+ * 标注、悬浮框字段模型
24
+ */
20
25
  var ElementTagTipConfig = /*#__PURE__*/function () {
21
26
  function ElementTagTipConfig(topo) {
22
27
  this.topoData = void 0;
28
+ this.modelMap = {};
23
29
  this.mtCodes = void 0;
24
30
  this.mtMetricsMap = {};
25
31
  this.mtCiTypeMap = void 0;
@@ -35,52 +41,213 @@ var ElementTagTipConfig = /*#__PURE__*/function () {
35
41
  switch (_context.prev = _context.next) {
36
42
  case 0:
37
43
  this.topoData = topoData;
38
- this.mtCodes = (0, _utils.getMonitorTemplateCodesFromTopoData)(topoData);
39
- _context.prev = 2;
44
+ _context.next = 3;
45
+ return this.initNetworkLinkModel();
46
+
47
+ case 3:
48
+ this.mtCiTypeMap = (0, _utils.getMtCodeCiTypeMap)(topoData);
49
+
50
+ case 4:
51
+ case "end":
52
+ return _context.stop();
53
+ }
54
+ }
55
+ }, _callee, this);
56
+ }));
57
+
58
+ function init(_x) {
59
+ return _init.apply(this, arguments);
60
+ }
61
+
62
+ return init;
63
+ }();
64
+
65
+ _proto.initNetworkLinkModel = /*#__PURE__*/function () {
66
+ var _initNetworkLinkModel = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2() {
67
+ var mtCodes;
68
+ return _regenerator["default"].wrap(function _callee2$(_context2) {
69
+ while (1) {
70
+ switch (_context2.prev = _context2.next) {
71
+ case 0:
72
+ _context2.prev = 0;
73
+ mtCodes = ['m.critical_link', 'm.ethernet_link'];
40
74
 
41
- if (!this.mtCodes.length) {
42
- _context.next = 7;
75
+ if (!mtCodes.length) {
76
+ _context2.next = 6;
43
77
  break;
44
78
  }
45
79
 
46
- _context.next = 6;
47
- return (0, _tagtip.getMetricsByMonitorTemplateCodes)(this.mtCodes);
80
+ _context2.next = 5;
81
+ return (0, _tagtip.getMetricsByMonitorTemplateCodes)(mtCodes);
48
82
 
49
- case 6:
50
- this.mtMetricsMap = _context.sent;
83
+ case 5:
84
+ this.mtMetricsMap = _context2.sent;
51
85
 
52
- case 7:
53
- _context.next = 12;
86
+ case 6:
87
+ _context2.next = 11;
54
88
  break;
55
89
 
56
- case 9:
57
- _context.prev = 9;
58
- _context.t0 = _context["catch"](2);
90
+ case 8:
91
+ _context2.prev = 8;
92
+ _context2.t0 = _context2["catch"](0);
59
93
 
60
- _rlog["default"].error('查询监控模板指标失败', _context.t0);
94
+ _rlog["default"].error('查询监控模板指标失败', _context2.t0);
61
95
 
62
- case 12:
63
- this.mtCiTypeMap = (0, _utils.getMtCodeCiTypeMap)(topoData);
64
-
65
- case 13:
96
+ case 11:
66
97
  case "end":
67
- return _context.stop();
98
+ return _context2.stop();
68
99
  }
69
100
  }
70
- }, _callee, this, [[2, 9]]);
101
+ }, _callee2, this, [[0, 8]]);
71
102
  }));
72
103
 
73
- function init(_x) {
74
- return _init.apply(this, arguments);
104
+ function initNetworkLinkModel() {
105
+ return _initNetworkLinkModel.apply(this, arguments);
75
106
  }
76
107
 
77
- return init;
78
- }()
108
+ return initNetworkLinkModel;
109
+ }();
110
+
111
+ _proto.getModelTypes = function getModelTypes(cis) {
112
+ var _this = this;
113
+
114
+ var modelTypes = [];
115
+ cis.forEach(function (ci) {
116
+ var modelType = _this.getModelType(ci);
117
+
118
+ if (modelType && modelTypes.indexOf(modelType) < 0) {
119
+ modelTypes.push(modelType);
120
+ }
121
+ });
122
+ return modelTypes;
123
+ }
79
124
  /**
80
- * 获得节点字段配置项map
125
+ * 查询模型
126
+ * @param {*} ci
127
+ * @returns
81
128
  */
129
+ // eslint-disable-next-line class-methods-use-this
82
130
  ;
83
131
 
132
+ _proto.getModelType = function getModelType(ci) {
133
+ if (ci.ciType === 'network_link') {
134
+ return ci.attributes.support_templates;
135
+ }
136
+
137
+ return ci.ciType;
138
+ };
139
+
140
+ _proto.getModelByType = function getModelByType(type) {
141
+ return this.getNetworkLinkModel(type) || this.topo.ciTyeCache.getCiType(type);
142
+ };
143
+
144
+ _proto.getNetworkLinkModel = function getNetworkLinkModel(type) {
145
+ var _this2 = this;
146
+
147
+ var baseInfo = [{
148
+ code: 'm.critical_link',
149
+ displayName: '关键链路',
150
+ typeCode: 'network_link'
151
+ }, {
152
+ code: 'm.ethernet_link',
153
+ displayName: '网络链路',
154
+ typeCode: 'network_link'
155
+ }].find(function (item) {
156
+ return item.code === type;
157
+ });
158
+
159
+ if (!baseInfo) {
160
+ return null;
161
+ }
162
+
163
+ var ciTypeModel = this.topo.ciTyeCache.getCiType('network_link');
164
+ var metrics = ciTypeModel.metrics.filter(function (m) {
165
+ return _this2.mtMetricsMap[type] && !!_this2.mtMetricsMap[type][m.code];
166
+ });
167
+ return (0, _extends2["default"])({}, this.topo.ciTyeCache.getCiType('network_link'), baseInfo, {
168
+ metrics: metrics,
169
+ metricMap: (0, _keyBy["default"])(metrics, 'code')
170
+ });
171
+ }
172
+ /**
173
+ * 获取链路标注悬浮框属性配置数据
174
+ * @returns
175
+ */
176
+ ;
177
+
178
+ _proto.getLinkConfigItems = function getLinkConfigItems() {
179
+ var _this3 = this;
180
+
181
+ var _this$topo$dataModel$ = this.topo.dataModel.getData(),
182
+ links = _this$topo$dataModel$.links;
183
+
184
+ var modelTypes = this.getModelTypes(links);
185
+ var list = modelTypes.map(this.getModelByType.bind(this)).map(function (item) {
186
+ return _this3.buildModels(item, 'link');
187
+ });
188
+ return list;
189
+ } // eslint-disable-next-line
190
+ ;
191
+
192
+ _proto.buildModels = function buildModels(ciTypeObj, type) {
193
+ return {
194
+ id: ciTypeObj.code,
195
+ label: ciTypeObj.displayName,
196
+ icon: "/img/model/" + ciTypeObj.icon + ".svg",
197
+ list: this.buildModelFields(ciTypeObj, type)
198
+ };
199
+ }
200
+ /**
201
+ * 过滤ci元数据中的属性和指标,用于属性和指标显示设置
202
+ * @param {} ciTypeObj
203
+ * @returns
204
+ */
205
+ // eslint-disable-next-line
206
+ ;
207
+
208
+ _proto.buildModelFields = function buildModelFields(ciTypeObj, type) {
209
+ var custom = [];
210
+
211
+ if (type === 'node') {
212
+ custom.push.apply(custom, [{
213
+ id: 'graph:name',
214
+ code: 'name',
215
+ name: '图片名称',
216
+ type: 'custom'
217
+ }, {
218
+ id: 'ciType:display_name',
219
+ code: 'ciType',
220
+ name: '资源类型',
221
+ type: 'custom'
222
+ }]);
223
+ }
224
+
225
+ var attributes = ciTypeObj.attributes.filter(function (attr) {
226
+ return !!attr.userVisible;
227
+ }).map(function (item) {
228
+ return {
229
+ type: 'attribute',
230
+ id: "attribute:" + item.code,
231
+ code: "attribute:" + item.code,
232
+ name: item.name,
233
+ typeName: '属性'
234
+ };
235
+ });
236
+ var metrics = ciTypeObj.metrics.map(function (item) {
237
+ return {
238
+ type: 'metric',
239
+ id: "metric:" + item.code,
240
+ code: "metric:" + item.code,
241
+ name: item.name,
242
+ typeName: '指标'
243
+ };
244
+ });
245
+ return [].concat(custom, attributes, metrics);
246
+ };
247
+
248
+ /**
249
+ * 获得节点字段配置项map
250
+ */
84
251
  _proto.getNodeFiedldMap = function getNodeFiedldMap() {
85
252
  var mtCodes = (0, _utils.getNodeMtCodes)(this.topoData);
86
253
  return this.getFiedldMapByMtCodes(mtCodes, 'node');
@@ -93,48 +260,15 @@ var ElementTagTipConfig = /*#__PURE__*/function () {
93
260
  _proto.getLinkFidldMap = function getLinkFidldMap() {
94
261
  var mtCodes = (0, _utils.getLinkMtCodes)(this.topoData);
95
262
  return this.getFiedldMapByMtCodes(mtCodes, 'link');
96
- }
97
- /**
98
- * 获取链路标注悬浮框属性配置数据
99
- * @returns
100
- */
101
- ;
102
-
103
- _proto.getLinkConfigItems = function getLinkConfigItems() {
104
- var mtCodes = (0, _utils.getLinkMtCodes)(this.topoData);
105
- var linkFidldMap = this.getLinkFidldMap();
106
- var list = [{
107
- id: 'm.critical_link',
108
- label: '关键链路'
109
- }, {
110
- id: 'm.ethernet_link',
111
- label: '网络链路'
112
- }] // 只拓扑图上已有资源的监控模板
113
- .filter(function (item) {
114
- return mtCodes.includes(item.id);
115
- }).map(function (t) {
116
- return (0, _extends2["default"])({}, t, {
117
- icon: '/img/model/networkLink.svg',
118
- list: linkFidldMap[t.id] || []
119
- });
120
- });
121
- return list; // return [
122
- // { id: 'ax1', label: '本级平台', children: list, type: 'folder', disabled: true },
123
- // {
124
- // id: 'bb22', label: '下级平台', type: 'folder', children: [
125
- // { id: 'xvdafa', label: '关键链路', icon: '/img/model/networkLink.svg' },
126
- // ]
127
- // },
128
- // ]
129
263
  };
130
264
 
131
265
  _proto.getFiedldMapByMtCodes = function getFiedldMapByMtCodes(mtCodes, type) {
132
- var _this = this;
266
+ var _this4 = this;
133
267
 
134
268
  var map = {};
135
269
  mtCodes.forEach(function (mtCode) {
136
- var ciType = _this.mtCiTypeMap[mtCode];
137
- map[mtCode] = _this.getFiedldMapByType(ciType, type, mtCode);
270
+ var ciType = _this4.mtCiTypeMap[mtCode];
271
+ map[mtCode] = _this4.getFiedldMapByType(ciType, type, mtCode);
138
272
  });
139
273
  return map;
140
274
  };
@@ -173,12 +307,12 @@ var ElementTagTipConfig = /*#__PURE__*/function () {
173
307
  };
174
308
 
175
309
  _proto.getMtMetricModels = function getMtMetricModels(mtCode) {
176
- var _this2 = this;
310
+ var _this5 = this;
177
311
 
178
312
  var ciType = this.mtCiTypeMap[mtCode];
179
313
  var ciTypeModel = this.topo.ciTyeCache.getCiType(ciType);
180
314
  var metrics = ciTypeModel.metrics.filter(function (m) {
181
- return _this2.mtMetricsMap[mtCode] && !!_this2.mtMetricsMap[mtCode][m.code];
315
+ return _this5.mtMetricsMap[mtCode] && !!_this5.mtMetricsMap[mtCode][m.code];
182
316
  });
183
317
  return metrics;
184
318
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riil-frontend/component-topology",
3
- "version": "11.0.11",
3
+ "version": "11.0.12",
4
4
  "description": "拓扑",
5
5
  "scripts": {
6
6
  "start": "build-scripts start",
@@ -118,6 +118,6 @@
118
118
  "access": "public"
119
119
  },
120
120
  "license": "MIT",
121
- "homepage": "https://unpkg.com/@riil-frontend/component-topology@11.0.11/build/index.html",
121
+ "homepage": "https://unpkg.com/@riil-frontend/component-topology@11.0.12/build/index.html",
122
122
  "gitHead": "2da19ffccbb7ca60a8acf396e39f542c68bb33f5"
123
123
  }