1 | import { a as __extends, b as __awaiter, c as __generator, d as __spreadArray, _ as __assign } from './tslib.es6-863e3717.js';
|
2 | import { I as InstancesSort, H as HierarchiesExpand, e as HierarchiesSort, U as Utils, K as KeyCodes } from './Utils-5f9f1f09.js';
|
3 | import { event, create, select, selectAll, mouse } from 'd3';
|
4 | import { S as ServerClient } from './ServerClient-f4bd7870.js';
|
5 | import { C as Component } from './Component-5b66527b.js';
|
6 | import { M as ModelAutocomplete } from './ModelAutocomplete-6a9a44cd.js';
|
7 |
|
8 | var HierarchyNavigation = (function (_super) {
|
9 | __extends(HierarchyNavigation, _super);
|
10 | function HierarchyNavigation(renderTarget) {
|
11 | var _this = _super.call(this, renderTarget) || this;
|
12 | _this.usedInstanceSearchContinuationTokens = {};
|
13 | _this.envHierarchies = {};
|
14 | _this.envTypes = {};
|
15 | _this.selectedHierarchyName = HierarchySelectionValues.All;
|
16 | _this.viewType = ViewType.Hierarchy;
|
17 | _this.mode = State.Navigate;
|
18 | _this.searchString = "";
|
19 | _this.path = [];
|
20 | _this.originalPathBeforeReverseLookup = [];
|
21 | _this.renderHierarchySelection = function () {
|
22 | var hierarchyList = __spreadArray(__spreadArray([HierarchySelectionValues.All], Object.keys(_this.envHierarchies)), [HierarchySelectionValues.Unparented]);
|
23 | _this.hierarchyListElem.text('');
|
24 | var self = _this;
|
25 | hierarchyList.forEach(function (h) {
|
26 | var title = h === HierarchySelectionValues.All ? _this.getString("All hierarchies") :
|
27 | h === HierarchySelectionValues.Unparented ? _this.getString("Unassigned Time Series Instances") : h;
|
28 | _this.hierarchyListElem.append('li').classed('selected', h === _this.selectedHierarchyName)
|
29 | .attr("hName", h)
|
30 | .attr('tabindex', 0)
|
31 | .attr('role', 'option')
|
32 | .attr('aria-selected', h === _this.selectedHierarchyName)
|
33 | .attr('title', title)
|
34 | .text(title).on('click keydown', function () {
|
35 | if (event && event.type && event.type === 'keydown') {
|
36 | event.preventDefault();
|
37 | var key = event.which || event.keyCode;
|
38 | if (key === KeyCodes.Down) {
|
39 | if (this.nextElementSibling)
|
40 | this.nextElementSibling.focus();
|
41 | else {
|
42 | self.hierarchyListElem.selectAll("li").nodes()[0].focus();
|
43 | }
|
44 | }
|
45 | else if (key === KeyCodes.Up) {
|
46 | if (this.previousElementSibling)
|
47 | this.previousElementSibling.focus();
|
48 | else {
|
49 | self.hierarchyListElem.selectAll("li").nodes()[self.hierarchyListElem.selectAll("li").nodes().length - 1].focus();
|
50 | }
|
51 | }
|
52 | else if (key === KeyCodes.Enter) {
|
53 | self.selectHierarchy(h);
|
54 | self.searchGloballyElem.node().style.display = 'none';
|
55 | self.hierarchySelectorElem.node().focus();
|
56 | }
|
57 | else if (key === KeyCodes.Esc) {
|
58 | self.isHierarchySelectionActive = false;
|
59 | self.hierarchyListWrapperElem.style('display', 'none');
|
60 | self.hierarchySelectorElem.node().focus();
|
61 | }
|
62 | return;
|
63 | }
|
64 | self.selectHierarchy(h);
|
65 | self.hierarchySelectorElem.node().focus();
|
66 | if (h === HierarchySelectionValues.All) {
|
67 | self.searchGloballyElem.node().style.display = 'none';
|
68 | }
|
69 | });
|
70 | });
|
71 | _this.hierarchyListWrapperElem.style('display', 'inline-flex');
|
72 | _this.hierarchyListElem.select("li.selected").node().focus();
|
73 | };
|
74 |
|
75 | _this.switchToSearchView = function (view, applySearch) {
|
76 | if (applySearch === void 0) { applySearch = true; }
|
77 | return __awaiter(_this, void 0, void 0, function () {
|
78 | return __generator(this, function (_a) {
|
79 | switch (_a.label) {
|
80 | case 0:
|
81 | this.closeContextMenu();
|
82 | this.viewType = view;
|
83 | this.viewTypesElem.selectAll('.tsi-view-type').classed('selected', false).attr('aria-selected', false);
|
84 | if (!(this.viewType === ViewType.Hierarchy)) return [3 , 3];
|
85 | select(this.viewTypesElem.selectAll('.tsi-view-type').nodes()[0]).classed('selected', true).attr('aria-selected', true);
|
86 | if (this.searchString) {
|
87 | this.setModeAndRequestParamsForFilter();
|
88 | }
|
89 | else {
|
90 | this.setModeAndRequestParamsForNavigate();
|
91 | }
|
92 | if (!(selectAll('.tsi-hierarchy ul').size() === 0 && applySearch)) return [3 , 2];
|
93 | this.hierarchyElem.text('');
|
94 | return [4 , this.pathSearchAndRenderResult({ search: { payload: this.requestPayload() }, render: { target: this.hierarchyElem } })];
|
95 | case 1:
|
96 | _a.sent();
|
97 | _a.label = 2;
|
98 | case 2:
|
99 | this.hierarchyElem.node().style.display = 'block';
|
100 | this.instanceListWrapperElem.node().style.display = 'none';
|
101 | return [3 , 6];
|
102 | case 3:
|
103 | select(this.viewTypesElem.selectAll('.tsi-view-type').nodes()[1]).classed('selected', true).attr('aria-selected', true);
|
104 | this.setModeAndRequestParamsForSearch();
|
105 | if (this.selectedHierarchyName === HierarchySelectionValues.Unparented) {
|
106 | this.chartOptions.hierarchyOptions.isInstancesRecursive = false;
|
107 | }
|
108 | if (!(selectAll('.tsi-modelResultWrapper').size() === 0 && applySearch)) return [3 , 5];
|
109 | this.instanceListElem.text('');
|
110 | this.lastInstanceContinuationToken = null;
|
111 | this.usedInstanceSearchContinuationTokens = {};
|
112 | return [4 , this.pathSearchAndRenderResult({ search: { payload: this.requestPayload() }, render: { target: this.instanceListElem } })];
|
113 | case 4:
|
114 | _a.sent();
|
115 | _a.label = 5;
|
116 | case 5:
|
117 | this.hierarchyElem.node().style.display = 'none';
|
118 | this.instanceListWrapperElem.node().style.display = 'block';
|
119 | _a.label = 6;
|
120 | case 6: return [2 ];
|
121 | }
|
122 | });
|
123 | });
|
124 | };
|
125 | _this.showNoResultsForSearch = function () {
|
126 | _this.viewTypesElem.node().style.display = 'none';
|
127 | if (_this.mode === State.Search && ((_this.selectedHierarchyName !== HierarchySelectionValues.All) || _this.filterPathElem.classed('visible'))) {
|
128 | _this.searchGloballyElem.style('display', 'inline');
|
129 | _this.noResultsElem.select(".tsi-clear").style('display', 'inline-block');
|
130 | }
|
131 | else {
|
132 | _this.searchGloballyElem.style('display', 'none');
|
133 | _this.noResultsElem.select(".tsi-clear").style('display', 'none');
|
134 | }
|
135 | _this.noResultsElem.classed('border-top', _this.filterPathElem.classed('visible'));
|
136 | _this.noResultsElem.select(".tsi-not-found-message").node().childNodes[0].textContent = _this.mode === State.Search ? _this.getString("No search result") : _this.getString("No instances");
|
137 | _this.noResultsElem.style('display', 'flex');
|
138 | };
|
139 |
|
140 | _this.doExactSearchWithPossiblePaths = function (tsid, hNames) {
|
141 | _this.setModeAndRequestParamsForFilter();
|
142 | var escapedTsidString = Utils.escapedTsidForExactSearch(tsid === null || tsid === void 0 ? void 0 : tsid.join(" "));
|
143 | _this.searchString = "\"" + escapedTsidString + "\"";
|
144 | return Promise.all(hNames.map(function (hName) {
|
145 | var payload = hName ? _this.requestPayload([hName]) : _this.requestPayload(null);
|
146 | return _this.getToken().then(function (token) {
|
147 | return _this.server.getTimeseriesInstancesPathSearch(token, _this.environmentFqdn, payload, null, null)
|
148 | .catch(function (err) { throw err; });
|
149 | })
|
150 | .catch(function (err) { throw err; });
|
151 | })).catch(function (err) { return _this.chartOptions.onError("Error in hierarchy navigation", "Failed to complete search", err instanceof XMLHttpRequest ? err : null); });
|
152 | };
|
153 |
|
154 | _this.prepareComponentForLookup = function (timeSeriesID) {
|
155 | _this.hierarchyElem.style('display', 'none');
|
156 | _this.noResultsElem.style('display', 'none');
|
157 | _this.notFoundElem.style('display', 'none');
|
158 | _this.instanceLookupLoadingElem.select('.tsi-lookup-instance').text(_this.getString("Looking for") + " " + timeSeriesID.join(" "));
|
159 | _this.instanceLookupLoadingElem.style('display', 'flex');
|
160 | _this.viewTypesElem.style("display", "none");
|
161 | _this.searchWrapperElem.select("input").node().value = "";
|
162 | _this.searchGloballyElem.style("display", "none");
|
163 | _this.originalPathBeforeReverseLookup = _this.path;
|
164 | _this.path = _this.selectedHierarchyName !== HierarchySelectionValues.All && _this.selectedHierarchyName !== HierarchySelectionValues.Unparented ? [_this.selectedHierarchyName] : [];
|
165 | };
|
166 |
|
167 | _this.getInstance = function (timeSeriesID) {
|
168 | return _this.getToken()
|
169 | .then(function (token) {
|
170 | return _this.server.getTimeseriesInstances(token, _this.environmentFqdn, 1, [timeSeriesID]).catch(function (err) { return _this.chartOptions.onError("Error in hierarchy navigation", "Failed to get instance details", err instanceof XMLHttpRequest ? err : null); });
|
171 | })
|
172 | .catch(function (err) { return _this.chartOptions.onError("Error in hierarchy navigation", "Failed to get token", err instanceof XMLHttpRequest ? err : null); });
|
173 | };
|
174 |
|
175 | _this.simulateExpand = function (path, hierarchyNamesFromParam, instance) { return __awaiter(_this, void 0, void 0, function () {
|
176 | var instanceIdentifier, isHierarchySelected, lastHierarchyNodeParent, ulToLook, nameSpan, _loop_1, this_1, idx, instanceNode, li, newListContentElem, instanceCount, hitElem;
|
177 | var _this = this;
|
178 | return __generator(this, function (_a) {
|
179 | switch (_a.label) {
|
180 | case 0:
|
181 | instanceIdentifier = this.instanceNodeIdentifier(instance);
|
182 | isHierarchySelected = this.selectedHierarchyName !== HierarchySelectionValues.All && this.selectedHierarchyName !== HierarchySelectionValues.Unparented;
|
183 | lastHierarchyNodeParent = document.getElementsByClassName("tsi-hierarchy")[0];
|
184 | _loop_1 = function (idx) {
|
185 | var p, hierarchyNodeToExpand, pathNodeName, hierarchyNode_1, li, newListContentElem, hitCount, onClickFunc;
|
186 | return __generator(this, function (_b) {
|
187 | switch (_b.label) {
|
188 | case 0:
|
189 | p = path[idx];
|
190 | if (isHierarchySelected && idx === 0) {
|
191 | return [2 , "continue"];
|
192 | }
|
193 | hierarchyNodeToExpand = void 0;
|
194 | pathNodeName = this_1.hierarchyNodeIdentifier(p);
|
195 | ulToLook = lastHierarchyNodeParent.getElementsByTagName("ul")[0];
|
196 | nameSpan = Array.from(ulToLook.getElementsByClassName("tsi-name")).find(function (e) { return e.innerText === pathNodeName; });
|
197 | if (!nameSpan) {
|
198 | hierarchyNode_1 = new HierarchyNode(pathNodeName, path.slice(0, idx), isHierarchySelected || hierarchyNamesFromParam ? idx - 1 : idx, '');
|
199 | hierarchyNode_1.expand = function () {
|
200 | return _this.pathSearchAndRenderResult({ search: { payload: _this.requestPayload(hierarchyNode_1.path), bubbleUpReject: true }, render: { target: hierarchyNode_1.node } })
|
201 | .then(function (r) { return __awaiter(_this, void 0, void 0, function () {
|
202 | var payload;
|
203 | return __generator(this, function (_a) {
|
204 | switch (_a.label) {
|
205 | case 0:
|
206 | payload = this.requestPayload(hierarchyNode_1.path);
|
207 | payload["instances"].recursive = true;
|
208 | return [4 , this.pathSearch(payload, null, null)
|
209 | .then(function (r) {
|
210 | hierarchyNode_1.node.select(".tsi-instanceCount").text(r.instances.hitCount);
|
211 | })
|
212 | .catch(function (err) { })];
|
213 | case 1:
|
214 | _a.sent();
|
215 | hierarchyNode_1.isExpanded = true;
|
216 | hierarchyNode_1.node.classed('tsi-expanded', true);
|
217 | return [2 ];
|
218 | }
|
219 | });
|
220 | }); })
|
221 | .catch(function (err) { });
|
222 | };
|
223 | li = create("li").attr("role", "none");
|
224 | ulToLook.insertBefore(li.node(), ulToLook.firstChild);
|
225 | newListContentElem = this_1.createHierarchyItemElem(hierarchyNode_1, this_1.hierarchyNodeIdentifier(hierarchyNode_1.name));
|
226 | li.node().appendChild(newListContentElem.node());
|
227 | hierarchyNode_1.node = li;
|
228 | nameSpan = newListContentElem.select('.tsi-name').node();
|
229 | hitCount = parseInt(lastHierarchyNodeParent.getElementsByClassName("tsi-hitCount")[0].innerText);
|
230 | if (ulToLook.getElementsByClassName("tsi-hierarchyItem").length === hitCount + 1) {
|
231 | ulToLook.removeChild(ulToLook.lastChild);
|
232 | }
|
233 | }
|
234 | hierarchyNodeToExpand = nameSpan.parentNode;
|
235 | lastHierarchyNodeParent = hierarchyNodeToExpand.parentNode;
|
236 | onClickFunc = select(hierarchyNodeToExpand).on("click");
|
237 | return [4 , onClickFunc.apply(hierarchyNodeToExpand)];
|
238 | case 1:
|
239 | _b.sent();
|
240 | return [2 ];
|
241 | }
|
242 | });
|
243 | };
|
244 | this_1 = this;
|
245 | idx = 0;
|
246 | _a.label = 1;
|
247 | case 1:
|
248 | if (!(idx < path.length)) return [3 , 4];
|
249 | return [5 , _loop_1(idx)];
|
250 | case 2:
|
251 | _a.sent();
|
252 | _a.label = 3;
|
253 | case 3:
|
254 | idx++;
|
255 | return [3 , 1];
|
256 | case 4:
|
257 |
|
258 | ulToLook = lastHierarchyNodeParent.getElementsByTagName("ul")[0];
|
259 | nameSpan = Array.from(ulToLook.getElementsByClassName("tsi-name")).find(function (e) { return e.innerText === _this.instanceNodeString(instance); });
|
260 | if (!nameSpan) {
|
261 | instanceNode = new InstanceNode(instance.timeSeriesId, instance.name, this.envTypes[instance.typeId], instance.hierarchyIds, instance.highlights, isHierarchySelected || hierarchyNamesFromParam ? path.length - 1 : path.length);
|
262 | li = create("li").classed('tsi-leaf', true).attr("role", "none");
|
263 | newListContentElem = this.createHierarchyItemElem(instanceNode, instanceIdentifier);
|
264 | li.node().appendChild(newListContentElem.node());
|
265 | ulToLook.insertBefore(li.node(), ulToLook.getElementsByClassName('tsi-leaf')[0]);
|
266 | instanceNode.node = li;
|
267 | instanceCount = parseInt(lastHierarchyNodeParent.getElementsByClassName("tsi-instanceCount")[0].innerText);
|
268 | if (ulToLook.getElementsByClassName("tsi-hierarchyItem").length === instanceCount + 1) {
|
269 | ulToLook.removeChild(ulToLook.lastChild);
|
270 | }
|
271 | nameSpan = newListContentElem.select('.tsi-name').node();
|
272 | }
|
273 | else {
|
274 | ulToLook.insertBefore(nameSpan.parentNode.parentNode, ulToLook.getElementsByClassName('tsi-leaf')[0]);
|
275 | }
|
276 | hitElem = document.createElement('hit');
|
277 | Utils.appendFormattedElementsFromString(select(hitElem), nameSpan.innerText);
|
278 | nameSpan.innerText = '';
|
279 | nameSpan.appendChild(hitElem);
|
280 | return [2 ];
|
281 | }
|
282 | });
|
283 | }); };
|
284 | _this.prepareComponentForAfterLookup = function () {
|
285 | _this.searchString = "";
|
286 | _this.setModeAndRequestParamsForNavigate();
|
287 | _this.viewType = ViewType.Hierarchy;
|
288 | };
|
289 | _this.removeCurrentHitsOfLastLookup = function () {
|
290 | var hitNodes = _this.hierarchyElem.selectAll('hit').nodes();
|
291 | if (hitNodes) {
|
292 | hitNodes.forEach(function (hitNode) {
|
293 | var spanElem = hitNode.parentNode;
|
294 | spanElem.innerText = '';
|
295 | Utils.appendFormattedElementsFromString(select(spanElem), _this.instanceNodeStringToDisplay(_this.lastLookedupInstance));
|
296 | });
|
297 | }
|
298 | };
|
299 | _this.showNotFoundForReverseLookup = function () {
|
300 | _this.prepareComponentForAfterLookup();
|
301 | _this.instanceLookupLoadingElem.style('display', 'none');
|
302 | if (_this.selectedHierarchyName !== HierarchySelectionValues.All || _this.filterPathElem.classed('visible')) {
|
303 | _this.lookupGloballyElem.style('display', 'inline');
|
304 | }
|
305 | else {
|
306 | _this.lookupGloballyElem.style('display', 'none');
|
307 | if (_this.hierarchyElem.text() === '') {
|
308 | _this.clearAndGetResults();
|
309 | }
|
310 | }
|
311 | _this.notFoundElem.classed('border-top', _this.filterPathElem.classed('visible'));
|
312 | _this.notFoundElem.style('display', 'flex');
|
313 | _this.hierarchyElem.style('display', 'block');
|
314 | _this.path = _this.originalPathBeforeReverseLookup;
|
315 | };
|
316 |
|
317 | _this.renderInstances = function (data, target) {
|
318 | var self = _this;
|
319 | if (Object.keys(data).length === 0) {
|
320 | _this.showNoResultsForSearch();
|
321 | return;
|
322 | }
|
323 | else {
|
324 | _this.noResultsElem.style('display', 'none');
|
325 | _this.viewTypesElem.node().style.display = 'inline-flex';
|
326 | }
|
327 | target.select('.tsi-show-more.tsi-show-more-instance').remove();
|
328 | Object.keys(data).forEach(function (i) {
|
329 | var div;
|
330 | if (data[i].name === _this.getString("Show More Instances")) {
|
331 | div = target.append('div').classed('tsi-show-more tsi-show-more-instance', true);
|
332 | div.append('span').classed('tsi-markedName', true).attr('tabindex', 0).text(i).on('click keydown', function () {
|
333 | if (Utils.isKeyDownAndNotEnter(event)) {
|
334 | return;
|
335 | }
|
336 | data[i].onClick();
|
337 | });
|
338 | }
|
339 | else {
|
340 | div = target.append('div').classed('tsi-modelResultWrapper', true).attr('tabindex', 0);
|
341 | var instanceElem = _this.createInstanceElem(data[i]);
|
342 | div.node().appendChild(instanceElem.node());
|
343 | div.on('click keydown', function () {
|
344 | var _this = this;
|
345 | var clickInstance = function () {
|
346 | event.stopPropagation();
|
347 | self.closeContextMenu();
|
348 | var target = self.instanceListElem.select(function () { return this.parentNode.parentNode; });
|
349 | var mouseWrapper = mouse(target.node());
|
350 | var mouseElt = mouse(_this);
|
351 | self.prepareForContextMenu(data[i], target, mouseWrapper[1], mouseElt[1]);
|
352 | self.chartOptions.onInstanceClick(data[i]);
|
353 | };
|
354 | if (event && event.type && event.type === 'keydown') {
|
355 | var key = event.which || event.keyCode;
|
356 | if (key === 40) {
|
357 | if (this.nextElementSibling)
|
358 | this.nextElementSibling.focus();
|
359 | }
|
360 | else if (key === 38) {
|
361 | if (this.previousElementSibling)
|
362 | this.previousElementSibling.focus();
|
363 | }
|
364 | else if (key === 13) {
|
365 | clickInstance();
|
366 | }
|
367 | return;
|
368 | }
|
369 | clickInstance();
|
370 | });
|
371 | }
|
372 | data[i].node = div;
|
373 | });
|
374 | };
|
375 | _this.pathSearchAndRenderResult = function (_a) {
|
376 | var _b = _a.search, payload = _b.payload, _c = _b.instancesContinuationToken, instancesContinuationToken = _c === void 0 ? null : _c, _d = _b.hierarchiesContinuationToken, hierarchiesContinuationToken = _d === void 0 ? null : _d, _e = _b.bubbleUpReject, bubbleUpReject = _e === void 0 ? false : _e, _f = _a.render, target = _f.target, _g = _f.locInTarget, locInTarget = _g === void 0 ? null : _g, _h = _f.skipLevels, skipLevels = _h === void 0 ? null : _h;
|
377 | return _this.pathSearch(payload, instancesContinuationToken, hierarchiesContinuationToken).then(function (r) {
|
378 | try {
|
379 | if (r.error) {
|
380 | throw r.error;
|
381 | }
|
382 | else {
|
383 | _this.renderSearchResult(r, payload, target, locInTarget, skipLevels);
|
384 | }
|
385 | }
|
386 | catch (err) {
|
387 | throw err;
|
388 | }
|
389 | }).catch(function (err) {
|
390 | _this.chartOptions.onError("Error in hierarchy navigation", "Failed to complete search", err instanceof XMLHttpRequest ? err : null);
|
391 | if (bubbleUpReject) {
|
392 | throw err;
|
393 | }
|
394 | });
|
395 | };
|
396 | _this.pathSearch = function (payload, instancesContinuationToken, hierarchiesContinuationToken) {
|
397 | if (instancesContinuationToken === void 0) { instancesContinuationToken = null; }
|
398 | if (hierarchiesContinuationToken === void 0) { hierarchiesContinuationToken = null; }
|
399 | return _this.getToken().then(function (token) {
|
400 | return _this.server.getTimeseriesInstancesPathSearch(token, _this.environmentFqdn, payload, instancesContinuationToken, hierarchiesContinuationToken);
|
401 | }).catch(function (err) { throw err; });
|
402 | };
|
403 | _this.renderSearchResult = function (r, payload, target, locInTarget, skipLevels) {
|
404 | var _a, _b, _c, _d, _e;
|
405 | if (locInTarget === void 0) { locInTarget = null; }
|
406 | if (skipLevels === void 0) { skipLevels = null; }
|
407 | var self = _this;
|
408 | var hierarchyData = {};
|
409 | var instancesData = {};
|
410 | if ((_b = (_a = r.hierarchyNodes) === null || _a === void 0 ? void 0 : _a.hits) === null || _b === void 0 ? void 0 : _b.length) {
|
411 | var hitCountElem = target.select(".tsi-hitCount");
|
412 | if (hitCountElem.size() == 0) {
|
413 | hitCountElem = target.append('span').classed('tsi-hitCount', true).text('');
|
414 | }
|
415 | hitCountElem.text(r.hierarchyNodes.hitCount);
|
416 | hierarchyData = self.fillDataRecursively(r.hierarchyNodes, _this.getToken, _this.environmentFqdn, payload, payload);
|
417 | }
|
418 | if ((_d = (_c = r.instances) === null || _c === void 0 ? void 0 : _c.hits) === null || _d === void 0 ? void 0 : _d.length) {
|
419 | r.instances.hits.forEach(function (i) {
|
420 | instancesData[_this.instanceNodeIdentifier(i)] = new InstanceNode(i.timeSeriesId, i.name, self.envTypes[i.typeId], i.hierarchyIds, i.highlights, payload.path.length - self.path.length);
|
421 | });
|
422 | }
|
423 | if (((_e = r.instances) === null || _e === void 0 ? void 0 : _e.continuationToken) && r.instances.continuationToken !== 'END') {
|
424 | var showMoreInstances_1 = new InstanceNode(null, _this.getString("Show More Instances"), null, null, null, payload.path.length - self.path.length);
|
425 | showMoreInstances_1.onClick = function () { return __awaiter(_this, void 0, void 0, function () {
|
426 | return __generator(this, function (_a) {
|
427 | this.pathSearchAndRenderResult({
|
428 | search: { payload: payload, hierarchiesContinuationToken: null, instancesContinuationToken: r.instances['continuationToken'] },
|
429 | render: { target: showMoreInstances_1.node.select(function () { return this.parentNode; }), locInTarget: '.tsi-show-more.tsi-show-more-instance' }
|
430 | });
|
431 | return [2 ];
|
432 | });
|
433 | }); };
|
434 | instancesData[showMoreInstances_1.name] = showMoreInstances_1;
|
435 | if (!self.usedInstanceSearchContinuationTokens[r.instances.continuationToken]) {
|
436 | self.lastInstanceContinuationToken = r.instances.continuationToken;
|
437 | }
|
438 | }
|
439 | else {
|
440 | self.lastInstanceContinuationToken = "END";
|
441 | }
|
442 | if (self.mode === State.Navigate) {
|
443 | if (self.selectedHierarchyName !== HierarchySelectionValues.Unparented) {
|
444 | self.renderTree(__assign(__assign({}, hierarchyData), instancesData), target, locInTarget);
|
445 | }
|
446 | else {
|
447 | self.renderTree(instancesData, target, locInTarget);
|
448 | }
|
449 | }
|
450 | else if (self.mode === State.Filter) {
|
451 | self.renderTree(__assign(__assign({}, hierarchyData), instancesData), target, locInTarget, skipLevels);
|
452 | }
|
453 | else {
|
454 | self.renderInstances(instancesData, target);
|
455 | }
|
456 | };
|
457 | _this.closeContextMenu = function () {
|
458 | if (_this.clickedInstance && _this.contextMenu) {
|
459 | _this.contextMenu.remove();
|
460 | selectAll('li.tsi-selected').classed('tsi-selected', false);
|
461 | }
|
462 | selectAll('.tsi-modelResultWrapper').classed('tsi-selected', false);
|
463 | _this.clickedInstance = null;
|
464 | };
|
465 | _this.prepareForContextMenu = function (instanceObj, target, wrapperMousePos, eltMousePos) {
|
466 | var contextMenuProps = {};
|
467 | contextMenuProps['target'] = target;
|
468 | contextMenuProps['wrapperMousePos'] = wrapperMousePos;
|
469 | contextMenuProps['eltMousePos'] = eltMousePos;
|
470 | _this.contextMenuProps = contextMenuProps;
|
471 | _this.clickedInstance = instanceObj;
|
472 | instanceObj.node.classed('tsi-selected', true);
|
473 | };
|
474 | _this.drawContextMenu = function (contextMenuItems, contextMenuOptions) {
|
475 | var itemList = [];
|
476 | var contextMenuList;
|
477 | var searchString = "";
|
478 | _this.contextMenu = _this.contextMenuProps['target'].append('div').classed('tsi-hierarchyNavigationContextMenu', true).attr('style', function () { return "top: " + (_this.contextMenuProps['wrapperMousePos'] - _this.contextMenuProps['eltMousePos']) + "px"; });
|
479 | var renderList = function (contextMenuItems) {
|
480 | if (_this.contextMenu.select("ul").empty()) {
|
481 | contextMenuList = _this.contextMenu.append('ul');
|
482 | }
|
483 | else {
|
484 | _this.contextMenu.select("ul").text('');
|
485 | }
|
486 | contextMenuItems.forEach(function (item) {
|
487 | var option = item.name;
|
488 | var li = contextMenuList.append('li');
|
489 | if (!contextMenuOptions.isSelectionEnabled) {
|
490 | li.attr('tabindex', 0)
|
491 | .attr('arialabel', option)
|
492 | .attr('title', option)
|
493 | .on('click keydown', function () {
|
494 | if (Utils.isKeyDownAndNotEnter(event)) {
|
495 | return;
|
496 | }
|
497 | item.action();
|
498 | _this.closeContextMenu();
|
499 | });
|
500 | var itemWrapperElem = li.append('div').classed('tsi-selectionItemWrapper', true);
|
501 | Utils.appendFormattedElementsFromString(itemWrapperElem, Utils.mark(searchString, option), { splitByTag: 'mark' });
|
502 | }
|
503 | else {
|
504 | li.attr('tabindex', 0)
|
505 | .on('click keydown', function () {
|
506 | if (Utils.isKeyDownAndNotEnter(event)) {
|
507 | return;
|
508 | }
|
509 | var elem = select(event.currentTarget).select(".tsi-hierarchyCheckbox");
|
510 | if (elem.classed("tsi-notSelected")) {
|
511 | itemList.push(item);
|
512 | elem.classed("tsi-notSelected", false);
|
513 | elem.attr("aria-checked", true);
|
514 | }
|
515 | else {
|
516 | var index = itemList.map(function (elem) { return elem.name; }).indexOf(item.name);
|
517 | itemList.splice(index, 1);
|
518 | elem.classed("tsi-notSelected", true);
|
519 | elem.attr("aria-checked", false);
|
520 | }
|
521 | itemList.length === 0 ?
|
522 | _this.contextMenu.select("button").classed("disabled", true)
|
523 | : _this.contextMenu.select("button").classed("disabled", false);
|
524 | });
|
525 | var itemWrapperElem = li.append('div').classed('tsi-selectionItemWrapper', true);
|
526 | itemWrapperElem.append('span').classed('tsi-hierarchyCheckbox tsi-notSelected', true)
|
527 | .attr("role", "checkbox").attr("aria-checked", false);
|
528 | var itemElem = itemWrapperElem.append('span').classed('tsi-selectionItem', true).attr('title', option);
|
529 | Utils.appendFormattedElementsFromString(itemElem, Utils.mark(searchString, option), { splitByTag: 'mark' });
|
530 | itemWrapperElem.append('span').classed('tsi-selectionItemKind', true).classed(item.kind, true).attr('title', item.kind.charAt(0).toUpperCase() + item.kind.slice(1));
|
531 | }
|
532 | });
|
533 | };
|
534 |
|
535 | if (contextMenuOptions.isFilterEnabled) {
|
536 | var searchBox = _this.contextMenu.append('div').classed('tsi-search', true);
|
537 | searchBox.append('i').classed('tsi-search-icon', true);
|
538 | searchBox.append('input').classed('tsi-searchInput', true).attr('placeholder', _this.getString('Search'))
|
539 | .on('input', function () {
|
540 | var regex = new RegExp(event.currentTarget.value, 'gi');
|
541 | searchString = event.currentTarget.value;
|
542 | renderList(contextMenuItems.filter(function (varObj) { return varObj.name.match(regex); }));
|
543 | itemList = [];
|
544 | _this.contextMenu.select("button").classed("disabled", true);
|
545 | });
|
546 | }
|
547 |
|
548 | renderList(contextMenuItems);
|
549 |
|
550 | if (contextMenuOptions.isSelectionEnabled) {
|
551 | _this.contextMenu.append('button').classed("tsi-primaryButton", true).classed("disabled", true).text(_this.getString("Add")).on('click', function () {
|
552 | itemList.forEach(function (item) { return item.action(); });
|
553 | _this.closeContextMenu();
|
554 | });
|
555 | }
|
556 |
|
557 | var leftSpaceAtBottom = _this.contextMenuProps['target'].node().getBoundingClientRect().height - parseFloat(_this.contextMenu.node().style.top);
|
558 | var overflowAtBottom = _this.contextMenu.node().getBoundingClientRect().height - leftSpaceAtBottom;
|
559 | if (overflowAtBottom > 0)
|
560 | _this.contextMenu.style('top', (parseFloat(_this.contextMenu.node().style.top) - overflowAtBottom) + 'px');
|
561 | var contextMenuFirstElt = select('.tsi-hierarchyNavigationContextMenu li').node();
|
562 | if (contextMenuFirstElt) {
|
563 | contextMenuFirstElt.focus();
|
564 | }
|
565 | };
|
566 | _this.hasHits = function (str) {
|
567 | return str && (str.indexOf("<hit>") !== -1);
|
568 | };
|
569 | _this.hierarchyNodeIdentifier = function (hName) {
|
570 | return hName ? hName : '(' + _this.getString("Empty") + ')';
|
571 | };
|
572 | _this.instanceNodeIdentifier = function (instance) {
|
573 | return "instance-" + Utils.getInstanceKey(instance);
|
574 | };
|
575 | _this.instanceNodeStringToDisplay = function (instance) {
|
576 | var _a;
|
577 | return ((_a = instance.highlights) === null || _a === void 0 ? void 0 : _a.name) || Utils.getHighlightedTimeSeriesIdToDisplay(instance)
|
578 | || instance.name || Utils.getTimeSeriesIdToDisplay(instance, _this.getString('Empty'));
|
579 | };
|
580 | _this.instanceNodeString = function (instance) {
|
581 | return instance.name || Utils.getTimeSeriesIdString(instance);
|
582 | };
|
583 | _this.clearAndHideFilterPath = function () {
|
584 | select('.tsi-path-list').text('');
|
585 | select('.tsi-filter-clear').style('display', 'none');
|
586 | _this.filterPathElem.classed('visible', false);
|
587 | };
|
588 |
|
589 | _this.selectHierarchy = function (pathName, applySearch) {
|
590 | if (applySearch === void 0) { applySearch = true; }
|
591 | _this.path = pathName === HierarchySelectionValues.All || pathName === HierarchySelectionValues.Unparented ? [] : [pathName];
|
592 | _this.selectedHierarchyName = pathName;
|
593 | var selectedhierarchyId = pathName === HierarchySelectionValues.All || pathName === HierarchySelectionValues.Unparented ? pathName : _this.envHierarchies[_this.selectedHierarchyName].id;
|
594 | _this.chartOptions.onSelect(selectedhierarchyId);
|
595 | var pathText = pathName === HierarchySelectionValues.All ? _this.getString("All hierarchies") : pathName === HierarchySelectionValues.Unparented ? _this.getString("Unassigned Time Series Instances") : pathName;
|
596 | select('.tsi-hierarchy-name').text(pathText).attr('title', pathText);
|
597 | _this.clearAndGetResults(applySearch);
|
598 | _this.clearAndHideFilterPath();
|
599 | _this.isHierarchySelectionActive = false;
|
600 | _this.hierarchyListWrapperElem.style('display', 'none');
|
601 | _this.notFoundElem.style('display', 'none');
|
602 | };
|
603 | _this.resettingVariablesForEnvChange = function () {
|
604 | _this.path = [];
|
605 | _this.selectedHierarchyName = HierarchySelectionValues.All;
|
606 | _this.searchString = '';
|
607 | _this.lastInstanceContinuationToken = null;
|
608 | _this.usedInstanceSearchContinuationTokens = {};
|
609 | _this.envHierarchies = {};
|
610 | _this.envTypes = {};
|
611 | _this.setModeAndRequestParamsForNavigate();
|
612 | _this.viewType = ViewType.Hierarchy;
|
613 | _this.clickedInstance = null;
|
614 | _this.isHierarchySelectionActive = false;
|
615 | };
|
616 | _this.server = new ServerClient();
|
617 | function isTarget() {
|
618 | return event.target === this || this.contains(event.target);
|
619 | }
|
620 | select("html").on("click. keydown." + Utils.guid(), function () {
|
621 | if (_this.clickedInstance && _this.contextMenu) {
|
622 | if (event.type && event.type === 'keydown') {
|
623 | if (!_this.contextMenu.filter(isTarget).empty()) {
|
624 | var key = event.which || event.keyCode;
|
625 | if (key === KeyCodes.Esc) {
|
626 | _this.closeContextMenu();
|
627 | }
|
628 | return;
|
629 | }
|
630 | }
|
631 | else {
|
632 | if (_this.contextMenu.filter(isTarget).empty()) {
|
633 | _this.closeContextMenu();
|
634 | }
|
635 | }
|
636 | }
|
637 | if (_this.isHierarchySelectionActive) {
|
638 | if (event && event.type && event.type === 'keydown') {
|
639 | if (!select(_this.hierarchyListWrapperElem.node().parentNode).filter(isTarget).empty()) {
|
640 | var key = event.which || event.keyCode;
|
641 | if (key === KeyCodes.Esc) {
|
642 | _this.isHierarchySelectionActive = false;
|
643 | _this.hierarchyListWrapperElem.style('display', 'none');
|
644 | }
|
645 | return;
|
646 | }
|
647 | }
|
648 | else {
|
649 | if (select(_this.hierarchyListWrapperElem.node().parentNode).filter(isTarget).empty()) {
|
650 | _this.isHierarchySelectionActive = false;
|
651 | _this.hierarchyListWrapperElem.style('display', 'none');
|
652 | }
|
653 | }
|
654 | }
|
655 | });
|
656 | return _this;
|
657 | }
|
658 | HierarchyNavigation.prototype.HierarchyNavigation = function () {
|
659 | };
|
660 | HierarchyNavigation.prototype.render = function (environmentFqdn, getToken, hierarchyNavOptions) {
|
661 | if (hierarchyNavOptions === void 0) { hierarchyNavOptions = {}; }
|
662 | return __awaiter(this, void 0, void 0, function () {
|
663 | var self, targetElement, hierarchyNavWrapper, selectedHierarchyId, hierarchy, autocompleteOnInput, handleKeydown;
|
664 | var _this = this;
|
665 | return __generator(this, function (_a) {
|
666 | switch (_a.label) {
|
667 | case 0:
|
668 | self = this;
|
669 | this.chartOptions.setOptions(hierarchyNavOptions);
|
670 | this.getToken = getToken;
|
671 | this.environmentFqdn = environmentFqdn;
|
672 | this.resettingVariablesForEnvChange();
|
673 | targetElement = select(this.renderTarget);
|
674 | targetElement.text('');
|
675 | hierarchyNavWrapper = targetElement.append('div').attr('class', 'tsi-hierarchy-nav-wrapper');
|
676 | _super.prototype.themify.call(this, hierarchyNavWrapper, this.chartOptions.theme);
|
677 |
|
678 | return [4 , getToken().then(function (token) {
|
679 | return _this.server.getTimeseriesTypes(token, environmentFqdn).then(function (r) {
|
680 | try {
|
681 | if (r.error) {
|
682 | throw r.error;
|
683 | }
|
684 | else {
|
685 | r.types.forEach(function (t) {
|
686 | _this.envTypes[t.id] = t;
|
687 | });
|
688 | }
|
689 | }
|
690 | catch (err) {
|
691 | throw err;
|
692 | }
|
693 | }).catch(function (err) { return _this.chartOptions.onError("Error in hierarchy navigation", "Failed to load types for navigation", err instanceof XMLHttpRequest ? err : null); });
|
694 | }).catch(function (err) { return _this.chartOptions.onError("Error in hierarchy navigation", "Failed to get token", err instanceof XMLHttpRequest ? err : null); })];
|
695 | case 1:
|
696 |
|
697 | _a.sent();
|
698 |
|
699 | return [4 , getToken().then(function (token) {
|
700 | return _this.server.getTimeseriesHierarchies(token, environmentFqdn).then(function (r) {
|
701 | try {
|
702 | if (r.error) {
|
703 | throw r.error;
|
704 | }
|
705 | else {
|
706 | r.hierarchies.forEach(function (h) {
|
707 | _this.envHierarchies[h.name] = h;
|
708 | });
|
709 | }
|
710 | }
|
711 | catch (err) {
|
712 | throw err;
|
713 | }
|
714 | }).catch(function (err) { return _this.chartOptions.onError("Error in hierarchy navigation", "Failed to load hierarchies for navigation", err instanceof XMLHttpRequest ? err : null); });
|
715 | }).catch(function (err) { return _this.chartOptions.onError("Error in hierarchy navigation", "Failed to get token", err instanceof XMLHttpRequest ? err : null); })];
|
716 | case 2:
|
717 |
|
718 | _a.sent();
|
719 | selectedHierarchyId = hierarchyNavOptions.selectedHierarchyId;
|
720 | if (selectedHierarchyId) {
|
721 | if (selectedHierarchyId === HierarchySelectionValues.All || selectedHierarchyId === HierarchySelectionValues.Unparented) {
|
722 | this.selectedHierarchyName = selectedHierarchyId;
|
723 | this.path = [];
|
724 | }
|
725 | else {
|
726 | hierarchy = Object.values(this.envHierarchies).find(function (h) { return h["id"] === selectedHierarchyId; });
|
727 | if (hierarchy) {
|
728 | this.selectedHierarchyName = hierarchy["name"];
|
729 | this.path = [this.selectedHierarchyName];
|
730 | }
|
731 | }
|
732 | }
|
733 | getToken().then(function (token) {
|
734 | self.server.getTimeseriesInstancesPathSearch(token, environmentFqdn, { searchString: '', path: _this.path, hierarchies: { sort: { by: HierarchiesSort.CumulativeInstanceCount }, expand: { kind: HierarchiesExpand.OneLevel }, pageSize: 100 } }).then(function (r) {
|
735 | try {
|
736 | if (r.error) {
|
737 | throw r.error;
|
738 | }
|
739 | else {
|
740 |
|
741 | var hierarchySelectionWrapper = hierarchyNavWrapper.append('div').classed('tsi-hierarchy-selection-wrapper', true);
|
742 | _this.hierarchySelectorElem = hierarchySelectionWrapper.append('button').classed('tsi-hierarchy-select', true)
|
743 | .attr("aria-haspopup", "listbox")
|
744 | .on('click keydown', function () {
|
745 | if (Utils.isKeyDownAndNotEnter(event)) {
|
746 | return;
|
747 | }
|
748 | if (_this.isHierarchySelectionActive) {
|
749 | _this.hierarchyListWrapperElem.style('display', 'none');
|
750 | _this.isHierarchySelectionActive = false;
|
751 | }
|
752 | else {
|
753 | _this.renderHierarchySelection();
|
754 | _this.isHierarchySelectionActive = true;
|
755 | }
|
756 | });
|
757 | _this.hierarchySelectorElem.append('span').classed('tsi-hierarchy-name', true).text(_this.selectedHierarchyName === HierarchySelectionValues.All ? _this.getString("All hierarchies")
|
758 | : _this.selectedHierarchyName === HierarchySelectionValues.Unparented ? _this.getString("Unassigned Time Series Instances")
|
759 | : _this.selectedHierarchyName);
|
760 | _this.hierarchySelectorElem.append('i').classed('tsi-down-caret-icon', true);
|
761 |
|
762 | _this.hierarchyListWrapperElem = hierarchySelectionWrapper.append('div').classed('tsi-hierarchy-list-wrapper', true);
|
763 | _this.hierarchyListElem = _this.hierarchyListWrapperElem.append('ul').classed('tsi-hierarchy-list', true).attr('role', 'listbox').attr("id", "tsi-hierarchy-listbox");
|
764 |
|
765 | _this.searchWrapperElem = hierarchyNavWrapper.append('div').classed('tsi-hierarchy-search', true);
|
766 | var modelAutocomplete = new ModelAutocomplete(_this.searchWrapperElem.node());
|
767 | modelAutocomplete.render(environmentFqdn, getToken, {
|
768 | onInput: autocompleteOnInput,
|
769 | onKeydown: function (event, ap) { handleKeydown(event, ap); },
|
770 | theme: hierarchyNavOptions.theme,
|
771 | strings: _this.chartOptions.strings
|
772 | });
|
773 | _this.viewTypesElem = _this.searchWrapperElem.append('div').classed('tsi-view-types', true).attr("role", "tablist");
|
774 | _this.viewTypesElem.append('div').classed('tsi-view-type', true)
|
775 | .attr('title', 'Hierarchy View')
|
776 | .attr('tabindex', 0)
|
777 | .attr('arialabel', 'Hierarchy View')
|
778 | .attr('role', 'tab')
|
779 | .on('click keydown', function () {
|
780 | if (Utils.isKeyDownAndNotEnter(event)) {
|
781 | return;
|
782 | }
|
783 | self.switchToSearchView(ViewType.Hierarchy);
|
784 | })
|
785 | .append('i').classed('tsi-tree-icon', true);
|
786 | _this.viewTypesElem.append('div').classed('tsi-view-type selected', true)
|
787 | .attr('title', 'List View')
|
788 | .attr('tabindex', 0)
|
789 | .attr('arialabel', 'List View')
|
790 | .attr('role', 'tab')
|
791 | .attr('aria-selected', true)
|
792 | .on('click keydown', function () {
|
793 | if (Utils.isKeyDownAndNotEnter(event)) {
|
794 | return;
|
795 | }
|
796 | self.switchToSearchView(ViewType.List);
|
797 | })
|
798 | .append('i').classed('tsi-list-icon', true);
|
799 |
|
800 | _this.filterPathElem = hierarchyNavWrapper.append('div').classed('tsi-filter-path-wrapper', true);
|
801 | var filterPath = _this.filterPathElem.append('div').classed('tsi-filter-path', true);
|
802 | filterPath.append('span').classed('tsi-path-list', true);
|
803 | filterPath.append('i').classed('tsi-close-icon tsi-filter-clear', true)
|
804 | .attr('tabindex', 0)
|
805 | .attr('arialabel', 'Clear Path Filter')
|
806 | .attr('title', 'Clear Path Filter')
|
807 | .on('click keydown', function () {
|
808 | if (Utils.isKeyDownAndNotEnter(event)) {
|
809 | return;
|
810 | }
|
811 | self.path = (self.selectedHierarchyName === HierarchySelectionValues.All || self.selectedHierarchyName === HierarchySelectionValues.Unparented) ? [] : [self.selectedHierarchyName];
|
812 | self.noResultsElem.style('display', 'none');
|
813 | self.clearAndGetResults();
|
814 | self.clearAndHideFilterPath();
|
815 | });
|
816 | _this.instanceLookupLoadingElem = hierarchyNavWrapper.append('div').classed('tsi-instance-lookup-loading', true);
|
817 | _this.instanceLookupLoadingElem.append('i').classed('tsi-spinner-icon', true);
|
818 | _this.instanceLookupLoadingElem.append('span').classed('tsi-lookup-instance', true);
|
819 |
|
820 | _this.noResultsElem = hierarchyNavWrapper.append('div').classed('tsi-noResults', true).style('display', 'none');
|
821 | var noInstancesMessage = _this.noResultsElem.append('div').classed('tsi-not-found-message', true).text(_this.getString("No search result")).attr("role", "alert");
|
822 | _this.searchGloballyElem = noInstancesMessage.append('a').classed('tsi-search-globally-link', true).text(_this.getString("Search globally")).style('display', 'none')
|
823 | .attr('title', _this.getString("Search globally"))
|
824 | .attr('tabindex', 0)
|
825 | .attr('arialabel', _this.getString("Search globally"))
|
826 | .on('click keydown', function () {
|
827 | if (Utils.isKeyDownAndNotEnter(event)) {
|
828 | return;
|
829 | }
|
830 | self.selectHierarchy(HierarchySelectionValues.All, false);
|
831 | self.switchToSearchView(ViewType.List);
|
832 | self.noResultsElem.style('display', 'none');
|
833 | });
|
834 | _this.noResultsElem.append('i').attr('class', 'tsi-clear')
|
835 | .attr('title', _this.getString("Dismiss"))
|
836 | .attr("tabindex", "0").attr("role", "button")
|
837 | .attr("aria-label", _this.getString("Dismiss"))
|
838 | .on('click keydown', function () {
|
839 | if (Utils.isKeyDownAndNotEnter(event)) {
|
840 | return;
|
841 | }
|
842 | self.searchWrapperElem.select("input").node().value = "";
|
843 | self.searchWrapperElem.select(".tsi-clear").dispatch('click');
|
844 | self.noResultsElem.style('display', 'none');
|
845 | });
|
846 |
|
847 | _this.notFoundElem = hierarchyNavWrapper.append('div').classed('tsi-notFound', true).style('display', 'none');
|
848 | var notFoundMessage = _this.notFoundElem.append('div').classed('tsi-not-found-message', true).text(_this.getString("Instance not found")).attr("role", "alert");
|
849 | _this.lookupGloballyElem = notFoundMessage.append('a').classed('tsi-search-globally-link', true).text(_this.getString("Lookup globally")).style('display', 'none')
|
850 | .attr('title', _this.getString("Lookup globally"))
|
851 | .attr('tabindex', 0)
|
852 | .attr('arialabel', _this.getString("Lookup globally"))
|
853 | .on('click keydown', function () {
|
854 | if (Utils.isKeyDownAndNotEnter(event)) {
|
855 | return;
|
856 | }
|
857 | self.selectHierarchy(HierarchySelectionValues.All, false);
|
858 | self.showInstance(self.timeSeriesIdForLookup);
|
859 | });
|
860 | _this.notFoundElem.append('i').attr('class', 'tsi-clear')
|
861 | .attr('title', _this.getString("Dismiss"))
|
862 | .attr("tabindex", "0").attr("role", "button")
|
863 | .attr("aria-label", _this.getString("Dismiss"))
|
864 | .on('click keydown', function () {
|
865 | if (Utils.isKeyDownAndNotEnter(event)) {
|
866 | return;
|
867 | }
|
868 | self.notFoundElem.style('display', 'none');
|
869 | });
|
870 |
|
871 | var results = hierarchyNavWrapper.append('div').classed('tsi-hierarchy-or-list-wrapper', true);
|
872 |
|
873 | _this.hierarchyElem = results.append('div').classed('tsi-hierarchy', true).attr("role", "navigation").on('scroll', function () {
|
874 | self.closeContextMenu();
|
875 | });
|
876 |
|
877 | _this.instanceListWrapperElem = results.append('div').classed('tsi-list', true).on('scroll', function () {
|
878 | if (self.viewType === ViewType.List) {
|
879 | self.closeContextMenu();
|
880 | if (self.lastInstanceContinuationToken && (self.lastInstanceContinuationToken !== "END")) {
|
881 | var that = this;
|
882 | if (that.scrollTop + that.clientHeight + 50 > self.instanceListElem.node().clientHeight) {
|
883 | if (self.lastInstanceContinuationToken === null || !self.usedInstanceSearchContinuationTokens[self.lastInstanceContinuationToken]) {
|
884 | self.usedInstanceSearchContinuationTokens[self.lastInstanceContinuationToken] = true;
|
885 | self.pathSearchAndRenderResult({ search: { payload: self.requestPayload(), instancesContinuationToken: self.lastInstanceContinuationToken }, render: { target: self.instanceListElem } });
|
886 | }
|
887 | }
|
888 | }
|
889 | }
|
890 | });
|
891 | _this.instanceListElem = _this.instanceListWrapperElem.append('div').classed('tsi-search-results', true);
|
892 | _this.pathSearchAndRenderResult({ search: { payload: self.requestPayload() }, render: { target: _this.hierarchyElem } });
|
893 | }
|
894 | }
|
895 | catch (err) {
|
896 | throw err;
|
897 | }
|
898 | }).catch(function (err) { return _this.chartOptions.onError("Error in hierarchy navigation", "Failed to complete search", err instanceof XMLHttpRequest ? err : null); });
|
899 | }).catch(function (err) { return _this.chartOptions.onError("Error in hierarchy navigation", "Failed to get token", err instanceof XMLHttpRequest ? err : null); });
|
900 | autocompleteOnInput = function (st, event) {
|
901 | if (st.length === 0) {
|
902 | _this.searchString = st;
|
903 | _this.viewTypesElem.node().style.display = 'none';
|
904 | _this.searchGloballyElem.node().style.display = 'none';
|
905 | _this.switchToSearchView(ViewType.Hierarchy, false);
|
906 | _this.clearAndGetResults();
|
907 | }
|
908 | else {
|
909 | if (event.which === 13 || event.keyCode === 13) {
|
910 | _this.searchString = st;
|
911 | _this.switchToSearchView(ViewType.List, false);
|
912 | _this.clearAndGetResults();
|
913 | }
|
914 | }
|
915 | };
|
916 | handleKeydown = function (event, ap) {
|
917 | if (!ap.isOpened) ;
|
918 | };
|
919 | return [2 ];
|
920 | }
|
921 | });
|
922 | });
|
923 | };
|
924 | HierarchyNavigation.prototype.setModeAndRequestParamsForSearch = function () {
|
925 | this.mode = State.Search;
|
926 | var options = this.chartOptions.hierarchyOptions;
|
927 | options.isInstancesRecursive = true;
|
928 | options.isInstancesHighlighted = true;
|
929 | options.instancesSort = InstancesSort.Rank;
|
930 | options.hierarchiesExpand = HierarchiesExpand.UntilChildren;
|
931 | options.hierarchiesSort = HierarchiesSort.CumulativeInstanceCount;
|
932 | };
|
933 | HierarchyNavigation.prototype.setModeAndRequestParamsForNavigate = function () {
|
934 | this.mode = State.Navigate;
|
935 | var options = this.chartOptions.hierarchyOptions;
|
936 | options.isInstancesRecursive = false;
|
937 | options.isInstancesHighlighted = true;
|
938 | options.instancesSort = InstancesSort.DisplayName;
|
939 | options.hierarchiesExpand = HierarchiesExpand.OneLevel;
|
940 | options.hierarchiesSort = HierarchiesSort.Name;
|
941 | };
|
942 | HierarchyNavigation.prototype.setModeAndRequestParamsForFilter = function () {
|
943 | this.mode = State.Filter;
|
944 | var options = this.chartOptions.hierarchyOptions;
|
945 | options.isInstancesRecursive = false;
|
946 | options.isInstancesHighlighted = true;
|
947 | options.instancesSort = InstancesSort.DisplayName;
|
948 | options.hierarchiesExpand = HierarchiesExpand.UntilChildren;
|
949 | options.hierarchiesSort = HierarchiesSort.CumulativeInstanceCount;
|
950 | };
|
951 |
|
952 | HierarchyNavigation.prototype.requestPayload = function (path) {
|
953 | if (path === void 0) { path = null; }
|
954 | var payload = {};
|
955 | payload["searchString"] = this.searchString;
|
956 | payload["path"] = path ? path : this.path;
|
957 | payload["instances"] = { recursive: this.chartOptions.hierarchyOptions.isInstancesRecursive, sort: { by: this.chartOptions.hierarchyOptions.instancesSort }, highlights: this.chartOptions.hierarchyOptions.isInstancesHighlighted, pageSize: this.chartOptions.hierarchyOptions.instancesPageSize };
|
958 | if (this.selectedHierarchyName !== HierarchySelectionValues.Unparented && (this.mode !== State.Search)) {
|
959 | payload["hierarchies"] = { expand: { kind: this.chartOptions.hierarchyOptions.hierarchiesExpand }, sort: { by: this.chartOptions.hierarchyOptions.hierarchiesSort }, pageSize: this.chartOptions.hierarchyOptions.hierarchiesPageSize };
|
960 | }
|
961 | return payload;
|
962 | };
|
963 |
|
964 | HierarchyNavigation.prototype.clearAndGetResults = function (applySearch) {
|
965 | if (applySearch === void 0) { applySearch = true; }
|
966 | this.instanceListElem.text('');
|
967 | this.hierarchyElem.text('');
|
968 | this.lastInstanceContinuationToken = null;
|
969 | this.usedInstanceSearchContinuationTokens = {};
|
970 | if (this.mode === State.Search) {
|
971 | this.chartOptions.hierarchyOptions.isInstancesRecursive = this.selectedHierarchyName === HierarchySelectionValues.Unparented ? false : true;
|
972 | }
|
973 | if (applySearch) {
|
974 | if (this.viewType === ViewType.Hierarchy) {
|
975 | return this.pathSearchAndRenderResult({ search: { payload: this.requestPayload() }, render: { target: this.hierarchyElem } });
|
976 | }
|
977 | else {
|
978 | return this.pathSearchAndRenderResult({ search: { payload: this.requestPayload() }, render: { target: this.instanceListElem } });
|
979 | }
|
980 | }
|
981 | };
|
982 | HierarchyNavigation.prototype.showInstance = function (timeSeriesID, hierarchyIds) {
|
983 | if (hierarchyIds === void 0) { hierarchyIds = null; }
|
984 | return __awaiter(this, void 0, void 0, function () {
|
985 | var isHierarchySelected, hierarchyNamesFromParam, hNames, instance, paths, response, instanceFieldValues_1, err_1, err_2;
|
986 | var _this = this;
|
987 | return __generator(this, function (_a) {
|
988 | switch (_a.label) {
|
989 | case 0:
|
990 | this.removeCurrentHitsOfLastLookup();
|
991 | this.timeSeriesIdForLookup = timeSeriesID;
|
992 | isHierarchySelected = this.selectedHierarchyName !== HierarchySelectionValues.All && this.selectedHierarchyName !== HierarchySelectionValues.Unparented;
|
993 | hierarchyNamesFromParam = hierarchyIds ? hierarchyIds.map(function (hId) { return Object.keys(_this.envHierarchies).find(function (n) { return _this.envHierarchies[n].id === hId; }); }) : null;
|
994 | hNames = hierarchyNamesFromParam ? hierarchyNamesFromParam : isHierarchySelected ? [null, this.selectedHierarchyName] : __spreadArray([null], Object.keys(this.envHierarchies));
|
995 | paths = [];
|
996 | _a.label = 1;
|
997 | case 1:
|
998 | _a.trys.push([1, 13, , 14]);
|
999 | this.prepareComponentForLookup(timeSeriesID);
|
1000 | response = void 0;
|
1001 | return [4 , this.getInstance(timeSeriesID)];
|
1002 | case 2:
|
1003 | response = _a.sent();
|
1004 | instance = response['get'][0]['instance'];
|
1005 | instanceFieldValues_1 = instance.instanceFields ? Object.values(instance.instanceFields) : [];
|
1006 | if (!instance) return [3 , 11];
|
1007 | _a.label = 3;
|
1008 | case 3:
|
1009 | _a.trys.push([3, 9, , 10]);
|
1010 | this.lastLookedupInstance = instance;
|
1011 | return [4 , this.doExactSearchWithPossiblePaths(timeSeriesID, hNames)];
|
1012 | case 4:
|
1013 | response = _a.sent();
|
1014 | response.forEach(function (r, idx) {
|
1015 | var _a, _b, _c, _d;
|
1016 | if (r.error) {
|
1017 | throw r.error;
|
1018 | }
|
1019 | if (idx === 0) {
|
1020 | if ((_a = r.instances) === null || _a === void 0 ? void 0 : _a.hitCount) {
|
1021 | paths.push([]);
|
1022 | }
|
1023 | }
|
1024 | else {
|
1025 | if ((_c = (_b = r.hierarchyNodes) === null || _b === void 0 ? void 0 : _b.hits) === null || _c === void 0 ? void 0 : _c.length) {
|
1026 | r.hierarchyNodes.hits.forEach(function (h) {
|
1027 | var currentHit = h;
|
1028 | if (instanceFieldValues_1.indexOf(currentHit.name) !== -1) {
|
1029 | var path = [hNames[idx]];
|
1030 | path.push(currentHit.name);
|
1031 | while (currentHit.hierarchyNodes) {
|
1032 | currentHit = currentHit.hierarchyNodes.hits[0];
|
1033 | if ((instanceFieldValues_1 === null || instanceFieldValues_1 === void 0 ? void 0 : instanceFieldValues_1.indexOf(currentHit.name)) !== -1) {
|
1034 | path.push(currentHit.name);
|
1035 | }
|
1036 | }
|
1037 | paths.push(path);
|
1038 | }
|
1039 | });
|
1040 | }
|
1041 | else if ((_d = r.instances) === null || _d === void 0 ? void 0 : _d.hitCount) {
|
1042 | var path = [hNames[idx]];
|
1043 | paths.push(path);
|
1044 | }
|
1045 | }
|
1046 | });
|
1047 | if (!paths.length) return [3 , 7];
|
1048 |
|
1049 | this.prepareComponentForAfterLookup();
|
1050 | return [4 , this.clearAndGetResults()];
|
1051 | case 5:
|
1052 | _a.sent();
|
1053 | return [4 , Promise.all(paths.map(function (p) { return _this.simulateExpand(p, hierarchyNamesFromParam, instance); }))];
|
1054 | case 6:
|
1055 | _a.sent();
|
1056 | this.clearAndHideFilterPath();
|
1057 | return [3 , 8];
|
1058 | case 7:
|
1059 | this.showNotFoundForReverseLookup();
|
1060 | _a.label = 8;
|
1061 | case 8:
|
1062 | this.hierarchyElem.style('display', 'block');
|
1063 | this.instanceLookupLoadingElem.style('display', 'none');
|
1064 | return [3 , 10];
|
1065 | case 9:
|
1066 | err_1 = _a.sent();
|
1067 | throw err_1;
|
1068 | case 10: return [3 , 12];
|
1069 | case 11:
|
1070 | this.showNotFoundForReverseLookup();
|
1071 | _a.label = 12;
|
1072 | case 12: return [3 , 14];
|
1073 | case 13:
|
1074 | err_2 = _a.sent();
|
1075 | this.showNotFoundForReverseLookup();
|
1076 | return [3 , 14];
|
1077 | case 14: return [2 ];
|
1078 | }
|
1079 | });
|
1080 | });
|
1081 | };
|
1082 |
|
1083 | HierarchyNavigation.prototype.renderTree = function (data, target, locInTarget, skipLevels) {
|
1084 | var _this = this;
|
1085 | if (locInTarget === void 0) { locInTarget = null; }
|
1086 | if (skipLevels === void 0) { skipLevels = null; }
|
1087 | if (Object.keys(data).length === 0) {
|
1088 | this.showNoResultsForSearch();
|
1089 | return;
|
1090 | }
|
1091 | else {
|
1092 | this.noResultsElem.style('display', 'none');
|
1093 | if (this.mode === State.Filter) {
|
1094 | this.viewTypesElem.node().style.display = 'inline-flex';
|
1095 | }
|
1096 | }
|
1097 | var list, currentShowMore;
|
1098 | if (!locInTarget) {
|
1099 | list = target.append('ul').attr("role", target === this.hierarchyElem ? "tree" : "group");
|
1100 | }
|
1101 | else {
|
1102 | if (locInTarget === '.tsi-show-more.tsi-show-more-hierarchy')
|
1103 | currentShowMore = target.selectAll('.tsi-show-more.tsi-show-more-hierarchy').filter(function (d, i, list) {
|
1104 | return i === list.length - 1;
|
1105 | });
|
1106 | else
|
1107 | currentShowMore = target.selectAll('.tsi-show-more.tsi-show-more-instance').filter(function (d, i, list) {
|
1108 | return i === list.length - 1;
|
1109 | });
|
1110 | currentShowMore.node().style.display = 'none';
|
1111 | currentShowMore.classed('tsi-target-loc', true);
|
1112 | }
|
1113 | if (locInTarget && skipLevels) {
|
1114 | while (skipLevels) {
|
1115 | data = data[Object.keys(data)[0]].children;
|
1116 | skipLevels--;
|
1117 | }
|
1118 | }
|
1119 | Object.keys(data).forEach(function (el) {
|
1120 | var li, newListElem;
|
1121 | var nodeNameToCheckIfExists = data[el] instanceof InstanceNode && data[el].name !== _this.getString("Show More Instances") ? _this.instanceNodeString(data[el]) : el;
|
1122 | if (locInTarget) {
|
1123 | if (target.selectAll(".tsi-name").nodes().find(function (e) { return e.innerText === nodeNameToCheckIfExists; })) {
|
1124 | return;
|
1125 | }
|
1126 | li = target.insert('li', '.tsi-target-loc').classed('tsi-leaf', data[el].isLeaf);
|
1127 | }
|
1128 | else {
|
1129 | if (list.selectAll(".tsi-name").nodes().find(function (e) { return e.innerText === nodeNameToCheckIfExists; })) {
|
1130 | return;
|
1131 | }
|
1132 | li = list.append('li').classed('tsi-leaf', data[el].isLeaf);
|
1133 | }
|
1134 | li.attr("role", "none");
|
1135 | if (el === _this.getString("Show More Hierarchies")) {
|
1136 | li.classed('tsi-show-more tsi-show-more-hierarchy', true)
|
1137 | .append('span')
|
1138 | .classed('tsi-hierarchyItem', true)
|
1139 | .attr('tabindex', 0)
|
1140 | .attr("role", "treeitem").attr('aria-expanded', false)
|
1141 | .attr('style', "padding-left: " + ((data[el].level) * 18 + 20) + "px").text(_this.getString("Show more")).on('click keydown', function () {
|
1142 | if (Utils.isKeyDownAndNotEnter(event)) {
|
1143 | return;
|
1144 | }
|
1145 | return data[el].onClick();
|
1146 | });
|
1147 | }
|
1148 | else if (el === _this.getString("Show More Instances")) {
|
1149 | li.classed('tsi-show-more tsi-show-more-instance', true)
|
1150 | .append('span')
|
1151 | .classed('tsi-hierarchyItem', true)
|
1152 | .attr('tabindex', 0)
|
1153 | .attr("role", "treeitem").attr('aria-expanded', false)
|
1154 | .attr('style', "padding-left: " + ((data[el].level) * 18 + 20) + "px").text(_this.getString("Show more")).on('click keydown', function () {
|
1155 | if (Utils.isKeyDownAndNotEnter(event)) {
|
1156 | return;
|
1157 | }
|
1158 | data[el].onClick();
|
1159 | });
|
1160 | }
|
1161 | else {
|
1162 | newListElem = _this.createHierarchyItemElem(data[el], el);
|
1163 | li.node().appendChild(newListElem.node());
|
1164 | }
|
1165 | data[el].node = li;
|
1166 | if (data[el].children) {
|
1167 | data[el].isExpanded = true;
|
1168 | data[el].node.classed('tsi-expanded', true);
|
1169 | _this.renderTree(data[el].children, data[el].node);
|
1170 | }
|
1171 | if (data[el] instanceof HierarchyNode && el !== _this.getString("Show More Hierarchies") && _this.mode === State.Filter && data[el].cumulativeInstanceCount == 1 && !data[el].isExpanded) {
|
1172 | newListElem.node().click();
|
1173 | }
|
1174 | });
|
1175 | if (locInTarget) {
|
1176 | currentShowMore.remove();
|
1177 | }
|
1178 | };
|
1179 |
|
1180 | HierarchyNavigation.prototype.fillDataRecursively = function (hierarchyNodes, getToken, envFqdn, payload, payloadForContinuation) {
|
1181 | var _this = this;
|
1182 | if (payloadForContinuation === void 0) { payloadForContinuation = null; }
|
1183 | var data = {};
|
1184 | hierarchyNodes.hits.forEach(function (h) {
|
1185 | var hierarchy = new HierarchyNode(h.name, payload.path, payload.path.length - _this.path.length, h.cumulativeInstanceCount);
|
1186 | hierarchy.expand = function () {
|
1187 | var expandNode = function () {
|
1188 | hierarchy.isExpanded = true;
|
1189 | hierarchy.node.classed('tsi-expanded', true);
|
1190 | };
|
1191 | if (_this.mode === State.Search) {
|
1192 | return _this.pathSearchAndRenderResult({ search: { payload: _this.requestPayload(hierarchy.path), bubbleUpReject: true }, render: { target: _this.instanceListElem } }).then(function (r) { return expandNode(); }).catch(function (err) { });
|
1193 | }
|
1194 | else {
|
1195 | return _this.pathSearchAndRenderResult({ search: { payload: _this.requestPayload(hierarchy.path), bubbleUpReject: true }, render: { target: hierarchy.node } }).then(function (r) { return expandNode(); }).catch(function (err) { });
|
1196 | }
|
1197 | };
|
1198 | data[_this.hierarchyNodeIdentifier(h.name)] = hierarchy;
|
1199 | if (h.hierarchyNodes && h.hierarchyNodes.hits.length) {
|
1200 | hierarchy.children = _this.fillDataRecursively(h.hierarchyNodes, getToken, envFqdn, _this.requestPayload(hierarchy.path), payloadForContinuation);
|
1201 | }
|
1202 | });
|
1203 | if (hierarchyNodes.continuationToken && hierarchyNodes.continuationToken !== 'END') {
|
1204 | var showMorehierarchy_1 = new HierarchyNode(this.getString("Show More Hierarchies"), payload.path, payload.path.length - this.path.length);
|
1205 | showMorehierarchy_1.onClick = function () {
|
1206 | return _this.pathSearchAndRenderResult({
|
1207 | search: { payload: (payloadForContinuation ? payloadForContinuation : payload), hierarchiesContinuationToken: hierarchyNodes.continuationToken },
|
1208 | render: { target: showMorehierarchy_1.node.select(function () { return this.parentNode; }), locInTarget: '.tsi-show-more.tsi-show-more-hierarchy', skipLevels: payloadForContinuation ? payload.path.length - payloadForContinuation.path.length : null }
|
1209 | });
|
1210 | };
|
1211 | data[showMorehierarchy_1.name] = showMorehierarchy_1;
|
1212 | }
|
1213 | return data;
|
1214 | };
|
1215 |
|
1216 | HierarchyNavigation.prototype.createHierarchyItemElem = function (hORi, key) {
|
1217 | var _this = this;
|
1218 | var self = this;
|
1219 | var isHierarchyNode = hORi instanceof HierarchyNode;
|
1220 | var hierarchyItemElem = create('div').classed('tsi-hierarchyItem', true)
|
1221 | .attr('style', "padding-left: " + (hORi.isLeaf ? hORi.level * 18 + 20 : (hORi.level + 1) * 18 + 20) + "px")
|
1222 | .attr('tabindex', 0)
|
1223 | .attr('arialabel', isHierarchyNode ? key : Utils.getTimeSeriesIdString(hORi))
|
1224 | .attr('title', isHierarchyNode ? key : Utils.getTimeSeriesIdString(hORi))
|
1225 | .attr("role", "treeitem").attr('aria-expanded', hORi.isExpanded)
|
1226 | .on('click keydown', function () {
|
1227 | return __awaiter(this, void 0, void 0, function () {
|
1228 | var mouseElt, target, mouseWrapper;
|
1229 | return __generator(this, function (_a) {
|
1230 | switch (_a.label) {
|
1231 | case 0:
|
1232 | if (Utils.isKeyDownAndNotEnter(event)) {
|
1233 | return [2 ];
|
1234 | }
|
1235 | if (!!isHierarchyNode) return [3 , 1];
|
1236 | event.stopPropagation();
|
1237 | self.closeContextMenu();
|
1238 | mouseElt = mouse(this);
|
1239 | target = self.hierarchyElem.select(function () { return this.parentNode; });
|
1240 | mouseWrapper = mouse(target.node());
|
1241 | self.prepareForContextMenu(hORi, target, mouseWrapper[1], mouseElt[1]);
|
1242 | self.chartOptions.onInstanceClick(hORi);
|
1243 | return [3 , 4];
|
1244 | case 1:
|
1245 | if (!hORi.isExpanded) return [3 , 2];
|
1246 | hORi.collapse();
|
1247 | return [3 , 4];
|
1248 | case 2: return [4 , hORi.expand()];
|
1249 | case 3:
|
1250 | _a.sent();
|
1251 | _a.label = 4;
|
1252 | case 4: return [2 ];
|
1253 | }
|
1254 | });
|
1255 | });
|
1256 | })
|
1257 | .on('mouseover focus', function () {
|
1258 | if (isHierarchyNode) {
|
1259 | if (event.relatedTarget != select(this.parentNode).select('.tsi-filter-icon').node()) {
|
1260 | select(this.parentNode).select('.tsi-filter-icon').node().style.visibility = 'visible';
|
1261 | }
|
1262 | }
|
1263 | })
|
1264 | .on('mouseleave blur', function () {
|
1265 | if (isHierarchyNode) {
|
1266 | if (event.relatedTarget != select(this.parentNode).select('.tsi-filter-icon').node()) {
|
1267 | select(this.parentNode).select('.tsi-filter-icon').node().style.visibility = 'hidden';
|
1268 | }
|
1269 | }
|
1270 | });
|
1271 | if (isHierarchyNode) {
|
1272 | hierarchyItemElem.append('span').classed('tsi-caret-icon', true).attr('style', "left: " + ((hORi.level) * 18 + 20) + "px");
|
1273 | hierarchyItemElem.append('span').classed('tsi-name', true).text(key);
|
1274 | hierarchyItemElem.append('span').classed('tsi-instanceCount', true).text(hORi.cumulativeInstanceCount);
|
1275 | hierarchyItemElem.append('span').classed('tsi-hitCount', true).text('');
|
1276 | hierarchyItemElem.append('div').classed('tsi-filter-icon', true).attr('title', this.getString('Add to Filter Path'))
|
1277 | .attr('tabindex', 0)
|
1278 | .attr('arialabel', this.getString('Add to Filter Path'))
|
1279 | .attr('role', 'button')
|
1280 | .on('click keydown', function () {
|
1281 | if (Utils.isKeyDownAndNotEnter(event)) {
|
1282 | return;
|
1283 | }
|
1284 | self.path = hORi.path;
|
1285 | var pathListElem = select('.tsi-path-list');
|
1286 | pathListElem.text('');
|
1287 | var pathToLoop = self.selectedHierarchyName !== HierarchySelectionValues.All ? hORi.path.slice(1) : hORi.path;
|
1288 | pathToLoop.forEach(function (a, i) {
|
1289 | if (i > 0) {
|
1290 | pathListElem.append('span').text(' / ');
|
1291 | }
|
1292 | var pathName = self.hierarchyNodeIdentifier(a);
|
1293 | pathListElem.append('span').classed('tsi-path', true)
|
1294 | .text(pathName)
|
1295 | .attr('title', pathName)
|
1296 | .attr('tabindex', 0)
|
1297 | .attr('arialabel', pathName)
|
1298 | .on('click keydown', function () {
|
1299 | if (Utils.isKeyDownAndNotEnter(event)) {
|
1300 | return;
|
1301 | }
|
1302 | self.path = self.path.slice(0, i + (self.selectedHierarchyName === HierarchySelectionValues.All ? 1 : 2));
|
1303 | selectAll(pathListElem.selectAll('span').nodes().splice((i * 2) + 1, pathListElem.selectAll('span').nodes().length)).remove();
|
1304 | self.clearAndGetResults();
|
1305 | });
|
1306 | });
|
1307 | select('.tsi-filter-clear').style('display', 'inline-block');
|
1308 | self.filterPathElem.classed('visible', true);
|
1309 | self.clearAndGetResults();
|
1310 | }).on('mouseleave blur', function () {
|
1311 | if (event.relatedTarget != select(this.parentNode)) {
|
1312 | this.style.visibility = 'hidden';
|
1313 | }
|
1314 | });
|
1315 | }
|
1316 | else {
|
1317 | var spanElem = hierarchyItemElem.append('span').classed('tsi-name', true);
|
1318 | Utils.appendFormattedElementsFromString(spanElem, this.instanceNodeStringToDisplay(hORi));
|
1319 | if (hORi.highlights) {
|
1320 | var hitsExist_1 = false;
|
1321 | var highlightDetails = hierarchyItemElem.append('div').classed('tsi-highlights-detail', true);
|
1322 | if (hORi.highlights.description && this.hasHits(hORi.highlights.description)) {
|
1323 | hitsExist_1 = true;
|
1324 | Utils.appendFormattedElementsFromString(highlightDetails, hORi.highlights.description);
|
1325 | }
|
1326 | var hitTuples_1 = [];
|
1327 | if (hORi.highlights.name && this.hasHits(Utils.getHighlightedTimeSeriesIdToDisplay(hORi))) {
|
1328 | hitsExist_1 = true;
|
1329 | hitTuples_1.push([this.getString("Time Series ID"), Utils.getHighlightedTimeSeriesIdToDisplay(hORi)]);
|
1330 | }
|
1331 | hORi.highlights.instanceFieldNames.forEach(function (ifn, idx) {
|
1332 | var val = hORi.highlights.instanceFieldValues[idx];
|
1333 | if (_this.hasHits(ifn) || _this.hasHits(val)) {
|
1334 | hitsExist_1 = true;
|
1335 | hitTuples_1.push([ifn, hORi.highlights.instanceFieldValues[idx]]);
|
1336 | }
|
1337 | });
|
1338 | var rows = highlightDetails.append('table').selectAll("tr")
|
1339 | .data(hitTuples_1)
|
1340 | .enter()
|
1341 | .append("tr");
|
1342 | var cells = rows.selectAll("td")
|
1343 | .data(function (d) {
|
1344 | return d;
|
1345 | });
|
1346 | cells.enter()
|
1347 | .append("td")
|
1348 | .each(function (d) {
|
1349 | Utils.appendFormattedElementsFromString(select(this), d);
|
1350 | })
|
1351 | .merge(cells);
|
1352 | cells.exit().remove();
|
1353 | rows.exit().remove();
|
1354 | if (hitsExist_1) {
|
1355 | highlightDetails.style("display", "block");
|
1356 | }
|
1357 | }
|
1358 | }
|
1359 | return hierarchyItemElem;
|
1360 | };
|
1361 |
|
1362 | HierarchyNavigation.prototype.createInstanceElem = function (i) {
|
1363 | var _this = this;
|
1364 | var instanceElem = create('div').classed('tsi-modelResult', true);
|
1365 | var firstLine = instanceElem.append('div').classed('tsi-modelPK', true);
|
1366 | i.highlights.name ? Utils.appendFormattedElementsFromString(firstLine, i.highlights.name) : Utils.appendFormattedElementsFromString(firstLine, Utils.getHighlightedTimeSeriesIdToDisplay(i));
|
1367 | var secondLine = instanceElem.append('div').classed('tsi-modelHighlights', true);
|
1368 | Utils.appendFormattedElementsFromString(secondLine, i.highlights.description && i.highlights.description.length ? i.highlights.description : 'No description');
|
1369 | secondLine.append('br');
|
1370 | var hitTuples = [];
|
1371 | if (i.highlights.name) {
|
1372 | hitTuples.push([this.getString("Time Series ID"), Utils.getHighlightedTimeSeriesIdToDisplay(i)]);
|
1373 | }
|
1374 | i.highlights.instanceFieldNames.forEach(function (ifn, idx) {
|
1375 | var val = i.highlights.instanceFieldValues[idx];
|
1376 | if (_this.searchString) {
|
1377 | if (_this.hasHits(ifn) || _this.hasHits(val)) {
|
1378 | hitTuples.push([ifn, i.highlights.instanceFieldValues[idx]]);
|
1379 | }
|
1380 | }
|
1381 | else if (val.length !== 0) {
|
1382 | hitTuples.push([ifn, i.highlights.instanceFieldValues[idx]]);
|
1383 | }
|
1384 | });
|
1385 | var rows = secondLine.append('table').selectAll("tr")
|
1386 | .data(hitTuples)
|
1387 | .enter()
|
1388 | .append("tr");
|
1389 | var cells = rows.selectAll("td")
|
1390 | .data(function (d) {
|
1391 | return d;
|
1392 | });
|
1393 | cells.enter()
|
1394 | .append("td")
|
1395 | .each(function (d) {
|
1396 | Utils.appendFormattedElementsFromString(select(this), d);
|
1397 | })
|
1398 | .merge(cells);
|
1399 | cells.exit().remove();
|
1400 | rows.exit().remove();
|
1401 | return instanceElem;
|
1402 | };
|
1403 | return HierarchyNavigation;
|
1404 | }(Component));
|
1405 | function HierarchyNode(name, parentPath, level, cumulativeInstanceCount) {
|
1406 | var _this = this;
|
1407 | if (cumulativeInstanceCount === void 0) { cumulativeInstanceCount = null; }
|
1408 | this.name = name;
|
1409 | this.path = parentPath.concat([name]);
|
1410 | this.expand = function () { };
|
1411 | this.level = level;
|
1412 | this.cumulativeInstanceCount = cumulativeInstanceCount;
|
1413 | this.node = null;
|
1414 | this.children = null;
|
1415 | this.isExpanded = false;
|
1416 | this.collapse = function () { _this.isExpanded = false; _this.node.classed('tsi-expanded', false); _this.node.selectAll('ul').remove(); };
|
1417 | }
|
1418 | function InstanceNode(tsId, name, type, hierarchyIds, highlights, level) {
|
1419 | if (name === void 0) { name = null; }
|
1420 | this.timeSeriesId = tsId;
|
1421 | this.name = name;
|
1422 | this.type = type;
|
1423 | this.hierarchyIds = hierarchyIds;
|
1424 | this.highlights = highlights;
|
1425 | this.suppressDrawContextMenu = false;
|
1426 | this.isLeaf = true;
|
1427 | this.level = level;
|
1428 | this.node = null;
|
1429 | }
|
1430 | var HierarchySelectionValues;
|
1431 | (function (HierarchySelectionValues) {
|
1432 | HierarchySelectionValues["All"] = "0";
|
1433 | HierarchySelectionValues["Unparented"] = "-1";
|
1434 | })(HierarchySelectionValues || (HierarchySelectionValues = {}));
|
1435 | var ViewType;
|
1436 | (function (ViewType) {
|
1437 | ViewType[ViewType["Hierarchy"] = 0] = "Hierarchy";
|
1438 | ViewType[ViewType["List"] = 1] = "List";
|
1439 | })(ViewType || (ViewType = {}));
|
1440 | var State;
|
1441 | (function (State) {
|
1442 | State[State["Navigate"] = 0] = "Navigate";
|
1443 | State[State["Search"] = 1] = "Search";
|
1444 | State[State["Filter"] = 2] = "Filter";
|
1445 | })(State || (State = {}));
|
1446 |
|
1447 | export { HierarchyNavigation as H };
|