github.com/siglens/siglens@v0.0.0-20240328180423-f7ce9ae441ed/static/js/edit-panel-screen.js (about) 1 /* 2 Copyright 2023. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 'use strict'; 18 19 let currentPanel; 20 let selectedChartTypeIndex = -1, selectedDataSourceTypeIndex = -1; 21 let selectedUnitTypeIndex = -1; 22 let selectedDataTypeIndex = -1; 23 let prevSelectedDataTypeIndex = -2; 24 let selectedLogLinesViewTypeIndex = -1; 25 let selectedQueryLanguageIndex = -1; 26 27 let mapChartTypeToIndex = new Map([ 28 ["Line Chart", 0], 29 ["Bar Chart", 1], 30 ["Pie Chart", 2], 31 ["Data Table", 3], 32 ["number", 4], 33 ["loglines",5], 34 ]) 35 let mapDataSourceTypeToIndex = new Map([ 36 ["metrics", 0], 37 ["logs", 1], 38 ["traces", 2] 39 ]); 40 let mapIndexToChartType = new Map([ 41 [0, "Line Chart"], 42 [1, "Bar Chart"], 43 [2, "Pie Chart"], 44 [3, "Data Table"], 45 [4, "number"], 46 [5, "loglines"], 47 ]) 48 let mapIndexToDataSourceType = new Map([ 49 [0, "metrics"], 50 [1, "logs"], 51 [2, "traces"] 52 ]); 53 54 let mapUnitTypeToIndex = new Map([ 55 ["", -1], 56 ["misc", 0], 57 ["data", 1], 58 ["throughput", 2], 59 ["time", 3], 60 ["data Rate", 4], 61 ]) 62 63 let mapMiscOptionsToIndex = new Map([ 64 ["", -1], 65 ["none", 0], 66 ["percent(0-100)", 1], 67 ]) 68 69 let mapDataTypeToIndex = new Map([ 70 ["", -1], 71 ["bytes", 0], 72 ["kB", 1], 73 ["MB", 2], 74 ["GB", 3], 75 ["TB", 4], 76 ["PB", 5], 77 ["EB", 6], 78 ["ZB", 7], 79 ["YB", 8], 80 ]) 81 82 let mapIndexToUnitType = new Map([ 83 [-1, ""], 84 [0, "misc"], 85 [1, "data"], 86 [2, "throughput"], 87 [3, "time"], 88 [4, "data Rate"], 89 ]) 90 91 let mapThroughputOptionsToIndex = new Map([ 92 ["", -1], 93 ["counts/sec", 0], 94 ["writes/sec", 1], 95 ["reads/sec", 2], 96 ["requests/sec", 3], 97 ["ops/sec", 4], 98 ]) 99 100 101 let mapTimeOptionsToIndex = new Map([ 102 ["", -1], 103 ["hertz(1/s)", 0], 104 ["nanoseconds(ns)", 1], 105 ["microsecond(µs)", 2], 106 ["milliseconds(ms)", 3], 107 ["seconds(s)", 4], 108 ["minutes(m)", 5], 109 ["hours(h)", 6], 110 ["days(d)", 7], 111 ]) 112 113 let mapDataRateTypeToIndex = new Map([ 114 ["", -1], 115 ["packets/sec", 0], 116 ["bytes/sec", 1], 117 ["bits/sec", 2], 118 ["kilobytes/sec", 3], 119 ["kilobits/sec", 4], 120 ["megabytes/sec", 5], 121 ["megabits/sec", 6], 122 ["gigabytes/sec", 7], 123 ["gigabits/sec", 8], 124 ["terabytes/sec", 9], 125 ["terabits/sec", 10], 126 ["petabytes/sec", 11], 127 ["petabits/sec", 12], 128 ]) 129 130 let mapIndexToMiscOptions = new Map([ 131 [-1, ""], 132 [0, "none"], 133 [1, "percent(0-100)"] 134 ]) 135 136 let mapIndexToDataType = new Map([ 137 [-1, ""], 138 [0, "bytes"], 139 [1, "kB"], 140 [2, "MB"], 141 [3, "GB"], 142 [4, "TB"], 143 [5, "PB"], 144 [6, "EB"], 145 [7, "ZB"], 146 [8, "YB"], 147 ]) 148 149 let mapIndexToThroughputOptions = new Map([ 150 [-1, ""], 151 [0, "counts/sec"], 152 [1, "writes/sec"], 153 [2, "reads/sec"], 154 [3, "requests/sec"], 155 [4, "ops/sec"] 156 ]) 157 158 159 let mapIndexToTimeOptions = new Map([ 160 [-1, ""], 161 [0, "hertz(1/s)"], 162 [1, "nanoseconds(ns)"], 163 [2, "microsecond(µs)"], 164 [3, "milliseconds(ms)"], 165 [4, "seconds(s)"], 166 [5, "minutes(m)"], 167 [6, "hours(h)"], 168 [7, "days(d)"], 169 ]) 170 171 let mapIndexToDataRateType = new Map([ 172 [-1, ""], 173 [0, "packets/sec"], 174 [1, "bytes/sec"], 175 [2, "bits/sec"], 176 [3, "kilobytes/sec"], 177 [4, "kilobits/sec"], 178 [5, "megabytes/sec"], 179 [6, "megabits/sec"], 180 [7, "gigabytes/sec"], 181 [8, "gigabits/sec"], 182 [9, "terabytes/sec"], 183 [10, "terabits/sec"], 184 [11, "petabytes/sec"], 185 [12, "petabits/sec"], 186 ]) 187 188 let mapIndexToLogLinesViewType = new Map([ 189 [0, "Single line display view"], 190 [1, "Multi line display view"], 191 ]) 192 193 $(document).ready(function () { 194 195 $("#info-icon-metrics").tooltip({ 196 delay: { show: 0, hide: 300 }, 197 trigger: 'click' 198 }); 199 200 $('#info-icon-metrics').on('click', function (e) { 201 $('#info-icon-metrics').tooltip('show'); 202 203 }); 204 205 $(document).mouseup(function (e) { 206 if ($(e.target).closest(".tooltip-inner").length === 0) { 207 $('#info-icon-metrics').tooltip('hide'); 208 } 209 }); 210 211 $("#info-icon-logs").tooltip({ 212 delay: { show: 0, hide: 300 }, 213 trigger: 'click' 214 }); 215 216 $('#info-icon-logs').on('click', function (e) { 217 $('#info-icon-logs').tooltip('show'); 218 }); 219 220 $(document).mouseup(function (e) { 221 if ($(e.target).closest(".tooltip-inner").length === 0) { 222 $('#info-icon-logs').tooltip('hide'); 223 } 224 }); 225 226 $("#info-icon-sql").tooltip({ 227 delay: { show: 0, hide: 300 }, 228 trigger: 'click' 229 }); 230 231 $('#info-icon-sql').on('click', function (e) { 232 $('#info-icon-sql').tooltip('show'); 233 }); 234 235 $(document).mouseup(function (e) { 236 if ($(e.target).closest(".tooltip-inner").length === 0) { 237 $('#info-icon-sql').tooltip('hide'); 238 } 239 }); 240 241 $("#info-icon-logQL").tooltip({ 242 delay: { show: 0, hide: 300 }, 243 trigger: 'click' 244 }); 245 246 $('#info-icon-logQL').on('click', function (e) { 247 $('#info-icon-logQL').tooltip('show'); 248 }); 249 250 $(document).mouseup(function (e) { 251 if ($(e.target).closest(".tooltip-inner").length === 0) { 252 $('#info-icon-logQL').tooltip('hide'); 253 } 254 }); 255 256 $("#info-icon-spl").tooltip({ 257 delay: { show: 0, hide: 300 }, 258 trigger: 'click' 259 }); 260 261 $('#info-icon-spl').on('click', function (e) { 262 $('#info-icon-spl').tooltip('show'); 263 }); 264 265 $(document).mouseup(function (e) { 266 if ($(e.target).closest(".tooltip-inner").length === 0) { 267 $('#info-icon-spl').tooltip('hide'); 268 } 269 }); 270 }) 271 272 function editPanelInit(redirectedFromViewScreen) { 273 $('.panelDisplay #empty-response').empty(); 274 $('.panelDisplay #corner-popup').empty(); 275 $('.panelDisplay #corner-popup').hide(); 276 $('.panelDisplay #panelLogResultsGrid').empty(); 277 $('.panelDisplay #panelLogResultsGrid').hide(); 278 $('.panelDisplay .panel-info-corner').hide(); 279 currentPanel = JSON.parse(JSON.stringify(localPanels[panelIndex])); 280 $('.panEdit-navBar .panEdit-dbName').html(`${dbName}`); 281 // reset inputs to show placeholders 282 $('.panEdit-navBar .panelTitle').html(currentPanel.name) 283 $('#panEdit-nameChangeInput').val(currentPanel.name); 284 $('#panEdit-descrChangeInput').val(currentPanel.description); 285 $('#panEdit-nameChangeInput').attr("placeholder", "Name") 286 $('#panEdit-descrChangeInput').attr("placeholder", "Description (Optional)") 287 toggleSwitch.checked = false; 288 if(currentPanel.description){ 289 const panelInfoCorner = $(".panelEditor-container .panelDisplay .panel-info-corner"); 290 const panelDescIcon = $(".panelEditor-container .panelDisplay .panel-info-corner #panel-desc-info"); 291 panelInfoCorner.show(); 292 panelDescIcon.tooltip('dispose'); 293 panelDescIcon.attr('title',currentPanel.description); 294 panelDescIcon.tooltip({ 295 delay: { show: 0, hide: 300 }, 296 trigger: 'hover'}); 297 panelInfoCorner.hover(function () {panelDescIcon.tooltip('show');}, 298 function () {panelDescIcon.tooltip('hide');}); 299 } 300 301 if (currentPanel.queryData && (currentPanel.queryData.searchText != undefined || currentPanel.queryData.query != undefined)) { 302 if(currentPanel.queryType==='metrics') 303 queryStr = currentPanel.queryData.query; 304 else 305 queryStr = currentPanel.queryData.searchText; 306 } 307 else { 308 queryStr = ""; 309 } 310 $('.queryInput').val(queryStr); 311 312 if (currentPanel.chartType != "") 313 selectedChartTypeIndex = mapChartTypeToIndex.get(currentPanel.chartType); 314 if (currentPanel.queryType != "") 315 selectedDataSourceTypeIndex = mapDataSourceTypeToIndex.get(currentPanel.queryType); 316 317 if (selectedChartTypeIndex === 4){ 318 $('.dropDown-unit').css('display','flex') 319 $('#nestedDropDownContainer').css('display','flex') 320 }else{ 321 $('#nestedDropDownContainer').css('display','none') 322 $('.dropDown-unit').css('display','none') 323 } 324 325 if (selectedChartTypeIndex === 5){ 326 $('.dropDown-logLinesView').css('display','flex'); 327 }else{ 328 $('.dropDown-logLinesView').css('display','none'); 329 } 330 331 if (selectedChartTypeIndex === 3){ 332 currentPanel.logLinesViewType="Table view"; 333 } 334 335 let currentPanelLogViewType = currentPanel.logLinesViewType; 336 337 if (currentPanelLogViewType === undefined && selectedChartTypeIndex === 5) { 338 selectedLogLinesViewTypeIndex = 0; 339 currentPanel.logLinesViewType="Single line display view"; 340 } 341 else if(currentPanelLogViewType==="Single line display view"){ 342 selectedLogLinesViewTypeIndex = 0; 343 } 344 else if(currentPanelLogViewType==="Multi line display view"){ 345 selectedLogLinesViewTypeIndex = 1; 346 } 347 348 selectedUnitTypeIndex = mapUnitTypeToIndex.get(currentPanel.unit); 349 350 let currentPanelUnit = currentPanel.unit; 351 if (currentPanelUnit === "") { 352 selectedDataTypeIndex = -1; 353 } 354 else if (currentPanelUnit === "misc") 355 selectedDataTypeIndex = mapMiscOptionsToIndex.get(currentPanel.dataType); 356 else if (currentPanelUnit === "data") 357 selectedDataTypeIndex = mapDataTypeToIndex.get(currentPanel.dataType); 358 else if (currentPanelUnit === "throughput") 359 selectedDataTypeIndex = mapThroughputOptionsToIndex.get(currentPanel.dataType); 360 else if (currentPanelUnit === "time") 361 selectedDataTypeIndex = mapTimeOptionsToIndex.get(currentPanel.dataType); 362 else if (currentPanelUnit === "data Rate") 363 selectedDataTypeIndex = mapDataRateTypeToIndex.get(currentPanel.dataType); 364 365 if (selectedDataTypeIndex == -1) { 366 $('.dropDown-misc-options span').html('Misc'); 367 $('.dropDown-data-options span').html('Data'); 368 $('.dropDown-throughput-options span').html('Throughput'); 369 $('.dropDown-percent-options span').html('Percent'); 370 $('.dropDown-time-options span').html('Time'); 371 $('.dropDown-data-rate-options span').html('Data Rate'); 372 prevSelectedDataTypeIndex = -2; 373 } 374 if (selectedDataSourceTypeIndex === -1 || selectedDataSourceTypeIndex === undefined) { 375 selectedDataSourceTypeIndex = mapDataSourceTypeToIndex.get("logs"); 376 } 377 refreshDataSourceMenuOptions(); 378 379 if (selectedDataSourceTypeIndex != -1 && selectedDataSourceTypeIndex !== undefined) { 380 381 if(selectedDataSourceTypeIndex == 1) { 382 $("#index-btn").css('display', 'inline-flex'); 383 $("#query-language-btn").css('display', 'inline-flex'); 384 $("#metrics-query-language-btn").css('display', 'none'); 385 if(selectedChartTypeIndex=== -1){ 386 selectedChartTypeIndex = mapChartTypeToIndex.get("Data Table"); 387 currentPanel.chartType = "Data Table"; 388 currentPanel.logLinesViewType = "Table view"; 389 } 390 } else if (selectedDataSourceTypeIndex==0){ 391 $("#metrics-query-language-btn").css('display', 'inline-block'); 392 $("#index-btn").css('display', 'none'); 393 $("#query-language-btn").css('display', 'none'); 394 } 395 else{ 396 $("#index-btn").css('display', 'none'); 397 $("#query-language-btn").css('display', 'none'); 398 $("#metrics-query-language-btn").css('display', 'none'); 399 } 400 displayQueryToolTip(selectedDataSourceTypeIndex); 401 $(".editPanelMenu-dataSource .editPanelMenu-options[data-index='" + selectedDataSourceTypeIndex + "']").click(); 402 } 403 if (selectedChartTypeIndex != -1 && selectedChartTypeIndex !== undefined) 404 refreshChartMenuOptions(); 405 if (selectedUnitTypeIndex != -1 && selectedUnitTypeIndex !== undefined) 406 refreshUnitMenuOptions(); 407 408 if (currentPanelLogViewType && currentPanelLogViewType!="Table view") 409 refreshLogLinesViewMenuOptions(); 410 411 if (selectedDataTypeIndex != -1 && selectedDataTypeIndex !== undefined) { 412 if (currentPanelUnit === "misc") 413 refreshNestedMiscMenuOptions(); 414 else if (currentPanelUnit === "data") 415 refreshNestedDataMenuOptions(); 416 else if (currentPanelUnit === "throughput") 417 refreshNestedTptMenuOptions(); 418 else if (currentPanelUnit === "percent") 419 refreshNestedPercentMenuOptions() 420 else if (currentPanelUnit === "time") 421 refreshNestedTimeMenuOptions() 422 else if (currentPanelUnit === "data Rate") 423 refreshNestedDataRateMenuOptions() 424 } 425 426 if(currentPanel.queryData) { 427 $('.panEdit-query-language-option').removeClass('active'); 428 if(currentPanel.queryData.queryLanguage === "SQL") { 429 $('#query-language-options #option-1').addClass('active'); 430 $('#query-language-btn span').html('SQL'); 431 } else if (currentPanel.queryData.queryLanguage === "Log QL"){ 432 $('#query-language-options #option-2').addClass('active'); 433 $('#query-language-btn span').html('Log QL'); 434 } else if (currentPanel.queryData.queryLanguage === "Splunk QL"){ 435 $('#query-language-options #option-3').addClass('active'); 436 $('#query-language-btn span').html('Splunk QL'); 437 } 438 } 439 displayQueryToolTip(selectedDataSourceTypeIndex); 440 441 if ($('.dropDown-dataSource.active').length) handleSourceDropDownClick(); 442 if ($('.dropDown-chart.active').length) handleChartDropDownClick(); 443 if ($('.dropDown-color.active').length) handleColorDropDownClick(); 444 if ($('.dropDown-unit.active').length) handleUnitDropDownClick(); 445 if ($('.dropDown-logLinesView.active').length) handleLogLinesViewDropDownClick(); 446 $( ".editPanelMenu-inner-options" ).slideUp(); 447 $(".inner-options").on('click',runQueryBtnHandler) 448 $('.panelDisplay #empty-response').empty(); 449 $('.panelDisplay #empty-response').hide(); 450 $('.panelDisplay .panEdit-panel').show(); 451 $(".panEdit-apply").unbind("click"); 452 $('.panEdit-apply').on('click', () => applyChangesToPanel(redirectedFromViewScreen)) 453 $(".panEdit-goToDB").unbind("click"); 454 $('.panEdit-goToDB').on("click", () => handleGoToDBArrowClick(redirectedFromViewScreen)) 455 setTimePicker(); 456 pauseRefreshInterval(); 457 if(currentPanel.queryRes){ 458 runQueryBtnHandler(); 459 } 460 } 461 462 $('#panelLogResultsGrid').empty(); 463 $('#panelLogResultsGrid').hide(); 464 465 $('.panEdit-discard').on("click", goToDashboard) 466 $('.panEdit-save').on("click", function(){ 467 if (!currentPanel.queryData && currentPanel.chartType ==='Data Table' && currentPanel.queryType ==='logs') { 468 currentPanel.chartType = ""; 469 currentPanel.queryType = ""; 470 } 471 localPanels[panelIndex] = JSON.parse(JSON.stringify(currentPanel)); 472 updateDashboard(); 473 }); 474 475 $('#panEdit-nameChangeInput').on('change keyup paste', updatePanelName) 476 $('#panEdit-descrChangeInput').on('change keyup paste', updatePanelDescr) 477 478 $('#panEdit-nameChangeInput').on("focus", function () { 479 $('#panEdit-nameChangeInput').val(currentPanel.name) 480 }) 481 $('#panEdit-descrChangeInput').on("focus", function () { 482 $('#panEdit-descrChangeInput').val(currentPanel.description) 483 }) 484 485 $('.dropDown-dataSource').on('click', handleSourceDropDownClick) 486 $('.dropDown-chart').on('click', handleChartDropDownClick) 487 $('.dropDown-color').on('click', handleColorDropDownClick) 488 $('.dropDown-unit').on('click', handleUnitDropDownClick) 489 490 $('.dropDown-logLinesView').on('click', handleLogLinesViewDropDownClick); 491 492 $('#nestedMiscDropDown').on('click', handleNestedMiscDropDownClick) 493 494 $('#nestedDataDropDown').on('click', handleNestedDataDropDownClick) 495 $('#nestedThroughputDropDown').on('click', handleNestedTptDropDownClick) 496 $('#nestedPercentDropDown').on('click', handleNestedPercentDropDownClick); 497 $('#nestedTimeDropDown').on('click', handleNestedTimeDropDownClick); 498 $('#nestedDataRateDropDown').on('click', handleNestedDataRateDropDownClick); 499 $('#query-language-options .panEdit-query-language-option').on('click', setQueryLangHandlerEditPanel); 500 501 $('.btn-runQuery').on('click', runQueryBtnHandler); 502 503 function handleSourceDropDownClick() { 504 $('.dropDown-dataSource').toggleClass("active") 505 $('.editPanelMenu-dataSource').slideToggle(); 506 $('.dropDown-dataSource .caret').css("rotate", "180deg"); 507 $('.dropDown-dataSource.active .caret').css("rotate", "360deg"); 508 } 509 510 function handleChartDropDownClick() { 511 $('.dropDown-chart').toggleClass("active") 512 $('.editPanelMenu-chart').slideToggle(); 513 $('.dropDown-chart .caret').css("rotate", "180deg"); 514 $('.dropDown-chart.active .caret').css("rotate", "360deg"); 515 } 516 517 function handleColorDropDownClick() { 518 $('.dropDown-color').toggleClass("active") 519 $('.editPanelMenu-color').slideToggle(); 520 $('.dropDown-color .caret').css("rotate", "180deg"); 521 $('.dropDown-color.active .caret').css("rotate", "360deg"); 522 } 523 524 function handleUnitDropDownClick(e) { 525 $('.dropDown-unit').toggleClass("active"); 526 //to close the inner dropdown when unit menu is clicked 527 $('.editPanelMenu-inner-options').hide() 528 $('.editPanelMenu-unit').slideToggle(); 529 $('.dropDown-unit .caret').css("rotate", "180deg"); 530 $('.dropDown-unit.active .caret').css("rotate", "360deg"); 531 } 532 533 534 function handleLogLinesViewDropDownClick(e) { 535 $('.dropDown-logLinesView').toggleClass('active'); 536 $('.editPanelMenu-logLinesView').slideToggle(); 537 $('.dropDown-logLinesView .caret').css("rotate", "180deg"); 538 $('.dropDown-logLinesView.active .caret').css("rotate", "360deg"); 539 } 540 541 function handleNestedMiscDropDownClick(e) { 542 543 let selectedUnitMenuItem = $('.editPanelMenu-unit .editPanelMenu-unit-options.selected'); 544 selectedUnitMenuItem.removeClass("selected"); 545 546 if(parseInt(selectedUnitMenuItem.attr('data-index')) !== $(this).data('index')) 547 resetNestedUnitMenuOptions(selectedUnitTypeIndex); 548 549 $(".editPanelMenu-inner-options").each(function(el) { 550 if($(this).attr('id') !== 'miscOptionsDropDown') { 551 $(this).hide(); 552 } 553 }); 554 555 $('#nestedMiscDropDown').toggleClass("active"); 556 $('#miscOptionsDropDown').slideToggle(); 557 $('#nestedMiscDropDown .horizontalCaret').css("rotate", "90deg"); 558 $('#nestedMiscDropDown.active .horizontalCaret').css("rotate", "270deg"); 559 if (e) e.stopPropagation(); 560 selectedUnitTypeIndex = $(this).data('index'); 561 currentPanel.unit = mapIndexToUnitType.get(selectedUnitTypeIndex); 562 let unitTypeMenuItems = $('.editPanelMenu-unit .editPanelMenu-unit-options'); 563 unitTypeMenuItems[selectedUnitTypeIndex].classList.add("selected"); 564 let unit = mapIndexToUnitType.get(selectedUnitTypeIndex); 565 unit = unit.charAt(0).toUpperCase() + unit.slice(1); 566 $('.dropDown-unit span').html(unit) 567 if(selectedDataTypeIndex != -1 && selectedDataTypeIndex !== undefined) { 568 let dataTypeMenuItems = $('.misc-options'); 569 dataTypeMenuItems.each(function (index, item) { 570 item.classList.remove("selected"); 571 }) 572 dataTypeMenuItems[selectedDataTypeIndex].classList.add("selected"); 573 } 574 575 } 576 577 function handleNestedDataDropDownClick(e) { 578 let selectedUnitMenuItem = $('.editPanelMenu-unit .editPanelMenu-unit-options.selected'); 579 selectedUnitMenuItem.removeClass("selected"); 580 if(parseInt(selectedUnitMenuItem.attr('data-index')) !== $(this).data('index')) 581 resetNestedUnitMenuOptions(selectedUnitTypeIndex); 582 583 $(".editPanelMenu-inner-options").each(function(el) { 584 if($(this).attr('id') !== 'dataOptionsDropDown') { 585 $(this).hide(); 586 } 587 }); 588 589 $('#nestedDataDropDown').toggleClass("active"); 590 $('#dataOptionsDropDown').slideToggle(); 591 $('#nestedDataDropDown .horizontalCaret').css("rotate", "90deg"); 592 $('#nestedDataDropDown.active .horizontalCaret').css("rotate", "270deg"); 593 if (e) e.stopPropagation(); 594 selectedUnitTypeIndex = $(this).data('index'); 595 currentPanel.unit = mapIndexToUnitType.get(selectedUnitTypeIndex); 596 let unitTypeMenuItems = $('.editPanelMenu-unit .editPanelMenu-unit-options'); 597 unitTypeMenuItems[selectedUnitTypeIndex].classList.add("selected"); 598 let unit = mapIndexToUnitType.get(selectedUnitTypeIndex); 599 unit = unit.charAt(0).toUpperCase() + unit.slice(1); 600 $('.dropDown-unit span').html(unit) 601 if(selectedDataTypeIndex != -1 && selectedDataTypeIndex !== undefined) { 602 let dataTypeMenuItems = $('.data-options'); 603 dataTypeMenuItems.each(function (index, item) { 604 item.classList.remove("selected"); 605 }) 606 dataTypeMenuItems[selectedDataTypeIndex].classList.add("selected"); 607 } 608 } 609 610 function handleNestedTptDropDownClick(e) { 611 let selectedUnitMenuItem = $('.editPanelMenu-unit .editPanelMenu-unit-options.selected'); 612 selectedUnitMenuItem.removeClass("selected"); 613 614 if(parseInt(selectedUnitMenuItem.attr('data-index')) !== $(this).data('index')) 615 resetNestedUnitMenuOptions(selectedUnitTypeIndex); 616 617 $(".editPanelMenu-inner-options").each(function( el ) { 618 if($(this).attr('id') !== 'throughputOptionsDropDown') { 619 $(this).hide(); 620 } 621 }); 622 $('#nestedThroughputDropDown').toggleClass("active"); 623 $('#throughputOptionsDropDown').slideToggle(); 624 $('#nestedThroughputDropDown .horizontalCaret').css("rotate", "90deg"); 625 $('#nestedThroughputDropDown.active .horizontalCaret').css("rotate", "270deg"); 626 if (e) e.stopPropagation(); 627 selectedUnitTypeIndex = $(this).data('index'); 628 currentPanel.unit = mapIndexToUnitType.get(selectedUnitTypeIndex); 629 630 let unitTypeMenuItems = $('.editPanelMenu-unit .editPanelMenu-unit-options'); 631 unitTypeMenuItems[selectedUnitTypeIndex].classList.add("selected"); 632 let unit = mapIndexToUnitType.get(selectedUnitTypeIndex); 633 unit = unit.charAt(0).toUpperCase() + unit.slice(1); 634 $('.dropDown-unit span').html(unit) 635 if(selectedDataTypeIndex != -1 && selectedDataTypeIndex !== undefined) { 636 let dataTypeMenuItems = $('.throughput-options'); 637 dataTypeMenuItems.each(function (index, item) { 638 item.classList.remove("selected"); 639 }) 640 dataTypeMenuItems[selectedDataTypeIndex].classList.add("selected"); 641 } 642 } 643 644 function handleNestedPercentDropDownClick(e) { 645 let selectedUnitMenuItem = $('.editPanelMenu-unit .editPanelMenu-unit-options.selected'); 646 selectedUnitMenuItem.removeClass("selected"); 647 if(parseInt(selectedUnitMenuItem.attr('data-index')) !== $(this).data('index')) 648 resetNestedUnitMenuOptions(selectedUnitTypeIndex); 649 650 $(".editPanelMenu-inner-options").each(function( el ) { 651 if($(this).attr('id') !== 'percentOptionsDropDown') { 652 $(this).hide(); 653 } 654 }); 655 $('#nestedPercentDropDown').toggleClass("active"); 656 $('#percentOptionsDropDown').slideToggle(); 657 $('#nestedPercentDropDown .horizontalCaret').css("rotate", "90deg"); 658 $('#nestedPercentDropDown.active .horizontalCaret').css("rotate", "270deg"); 659 if (e) e.stopPropagation(); 660 selectedUnitTypeIndex = $(this).data('index'); 661 currentPanel.unit = mapIndexToUnitType.get(selectedUnitTypeIndex); 662 let unitTypeMenuItems = $('.editPanelMenu-unit .editPanelMenu-unit-options'); 663 unitTypeMenuItems[selectedUnitTypeIndex].classList.add("selected"); 664 665 let unit = mapIndexToUnitType.get(selectedUnitTypeIndex); 666 unit = unit.charAt(0).toUpperCase() + unit.slice(1); 667 $('.dropDown-unit span').html(unit) 668 if(selectedDataTypeIndex != -1 && selectedDataTypeIndex !== undefined) { 669 let dataTypeMenuItems = $('.percent-options'); 670 dataTypeMenuItems.each(function (index, item) { 671 item.classList.remove("selected"); 672 }) 673 dataTypeMenuItems[selectedDataTypeIndex].classList.add("selected"); 674 } 675 } 676 677 function handleNestedTimeDropDownClick(e) { 678 let selectedUnitMenuItem = $('.editPanelMenu-unit .editPanelMenu-unit-options.selected'); 679 selectedUnitMenuItem.removeClass("selected"); 680 if(parseInt(selectedUnitMenuItem.attr('data-index')) !== $(this).data('index')) 681 resetNestedUnitMenuOptions(selectedUnitTypeIndex); 682 683 $(".editPanelMenu-inner-options").each(function( el ) { 684 if($(this).attr('id') !== 'timeOptionsDropDown') { 685 $(this).hide(); 686 } 687 }); 688 $('#nestedTimeDropDown').toggleClass("active"); 689 $('#timeOptionsDropDown').slideToggle(); 690 $('#nestedTimeDropDown .horizontalCaret').css("rotate", "90deg"); 691 $('#nestedTimeDropDown.active .horizontalCaret').css("rotate", "270deg"); 692 if (e) e.stopPropagation(); 693 selectedUnitTypeIndex = $(this).data('index'); 694 currentPanel.unit = mapIndexToUnitType.get(selectedUnitTypeIndex); 695 let unitTypeMenuItems = $('.editPanelMenu-unit .editPanelMenu-unit-options'); 696 unitTypeMenuItems[selectedUnitTypeIndex].classList.add("selected"); 697 698 let unit = mapIndexToUnitType.get(selectedUnitTypeIndex); 699 unit = unit.charAt(0).toUpperCase() + unit.slice(1); 700 $('.dropDown-unit span').html(unit) 701 if(selectedDataTypeIndex != -1 && selectedDataTypeIndex !== undefined) { 702 let dataTypeMenuItems = $('.time-options'); 703 dataTypeMenuItems.each(function (index, item) { 704 item.classList.remove("selected"); 705 }) 706 dataTypeMenuItems[selectedDataTypeIndex].classList.add("selected"); 707 } 708 } 709 710 function handleNestedDataRateDropDownClick(e) { 711 let selectedUnitMenuItem = $('.editPanelMenu-unit .editPanelMenu-unit-options.selected'); 712 selectedUnitMenuItem.removeClass("selected"); 713 if(parseInt(selectedUnitMenuItem.attr('data-index')) !== $(this).data('index')) 714 resetNestedUnitMenuOptions(selectedUnitTypeIndex); 715 716 $(".editPanelMenu-inner-options").each(function( el ) { 717 if($(this).attr('id') !== 'dataRateOptionsDropDown') { 718 $(this).hide(); 719 } 720 }); 721 $('#nestedDataRateDropDown').toggleClass("active"); 722 $('#dataRateOptionsDropDown').slideToggle(); 723 $('#nestedDataRateDropDown .horizontalCaret').css("rotate", "90deg"); 724 $('#nestedDataRateDropDown.active .horizontalCaret').css("rotate", "270deg"); 725 if (e) e.stopPropagation(); 726 selectedUnitTypeIndex = $(this).data('index'); 727 currentPanel.unit = mapIndexToUnitType.get(selectedUnitTypeIndex); 728 let unitTypeMenuItems = $('.editPanelMenu-unit .editPanelMenu-unit-options'); 729 unitTypeMenuItems[selectedUnitTypeIndex].classList.add("selected"); 730 731 let unit = mapIndexToUnitType.get(selectedUnitTypeIndex); 732 unit = unit.charAt(0).toUpperCase() + unit.slice(1); 733 $('.dropDown-unit span').html(unit) 734 if(selectedDataTypeIndex != -1 && selectedDataTypeIndex !== undefined) { 735 let dataTypeMenuItems = $('.data-rate-options'); 736 dataTypeMenuItems.each(function (index, item) { 737 item.classList.remove("selected"); 738 }) 739 dataTypeMenuItems[selectedDataTypeIndex].classList.add("selected"); 740 } 741 } 742 743 $(".editPanelMenu-dataSource .editPanelMenu-options").on('click', function () { 744 selectedDataSourceTypeIndex = $(this).data('index'); 745 displayQueryToolTip(selectedDataSourceTypeIndex); 746 if(selectedDataSourceTypeIndex == 1) { 747 $("#index-btn").css('display', 'inline-flex'); 748 $("#query-language-btn").css('display', 'inline-flex'); 749 $("#metrics-query-language-btn").css('display', 'none'); 750 } else if (selectedDataSourceTypeIndex==0){ 751 $("#metrics-query-language-btn").css('display', 'inline-block'); 752 $("#index-btn").css('display', 'none'); 753 $("#query-language-btn").css('display', 'none'); 754 } 755 else{ 756 $("#index-btn").css('display', 'none'); 757 $("#query-language-btn").css('display', 'none'); 758 $("#metrics-query-language-btn").css('display', 'none'); 759 } 760 currentPanel.queryType = mapIndexToDataSourceType.get(selectedDataSourceTypeIndex); 761 refreshDataSourceMenuOptions(); 762 }); 763 764 $(".editPanelMenu-chart .editPanelMenu-options").on('click', function () { 765 selectedChartTypeIndex = $(this).data('index'); 766 currentPanel.chartType = mapIndexToChartType.get(selectedChartTypeIndex); 767 if (selectedChartTypeIndex === 4) { 768 $('.dropDown-unit').css('display','flex') 769 $('#nestedDropDownContainer').css('display','flex') 770 $('.dropDown-logLinesView').css('display','none'); 771 772 }else if (selectedChartTypeIndex === 5){ 773 currentPanel.logLinesViewType="Single line display view"; 774 $('.dropDown-logLinesView').css('display','flex') 775 $('#nestedDropDownContainer').css('display','none') 776 $('.dropDown-unit').css('display','none') 777 }else if (selectedChartTypeIndex === 3){ 778 currentPanel.logLinesViewType="Table view"; 779 $('#nestedDropDownContainer').css('display','none') 780 $('.dropDown-unit').css('display','none') 781 $('.dropDown-logLinesView').css('display','none'); 782 } 783 else{ 784 $('#nestedDropDownContainer').css('display','none') 785 $('.dropDown-unit').css('display','none') 786 if (selectedUnitTypeIndex !== 0) 787 $('.dropDown-unit span').html('Unit'); 788 $('.dropDown-logLinesView').css('display','none'); 789 } 790 $('.editPanelMenu-inner-options').css('display',"none"); 791 $('.horizontalCaret').css('rotate','90deg'); 792 refreshChartMenuOptions(); 793 }); 794 795 $(".colorCircle").on("click", function () { 796 let colorCircles = $('.colorCircle') 797 colorCircles.map((index, el) => { 798 el.classList.remove("selected"); 799 }) 800 $(this).addClass("selected") 801 }) 802 803 $(".editPanelMenu-unit .editPanelMenu-unit-options").on('click', function () { 804 selectedUnitTypeIndex = $(this).data('index'); 805 currentPanel.unit = mapIndexToUnitType.get(selectedUnitTypeIndex); 806 refreshUnitMenuOptions(); 807 }); 808 809 810 $(".editPanelMenu-logLinesView .editPanelMenu-options").on('click', function () { 811 selectedLogLinesViewTypeIndex = $(this).data('index'); 812 if(selectedLogLinesViewTypeIndex === 0){ 813 currentPanel.logLinesViewType="Single line display view"; 814 }else if (selectedLogLinesViewTypeIndex === 1){ 815 currentPanel.logLinesViewType="Multi line display view"; 816 } 817 refreshLogLinesViewMenuOptions(); 818 runQueryBtnHandler(); 819 }); 820 821 $(".misc-options").on('click', function () { 822 selectedDataTypeIndex = $(this).data('index'); 823 currentPanel.dataType = mapIndexToMiscOptions.get(selectedDataTypeIndex); 824 $('#miscOptionsDropDown').slideToggle(); 825 $('#nestedMiscDropDown').toggleClass("active"); 826 $('#nestedMiscDropDown .horizontalCaret').css("rotate", "90deg"); 827 let dataTypeMenuItems = $('.misc-options'); 828 dataTypeMenuItems.each(function (index, item) { 829 item.classList.remove("selected"); 830 }) 831 $(this).addClass('selected'); 832 if (prevSelectedDataTypeIndex != selectedDataTypeIndex) { 833 refreshNestedMiscMenuOptions(); 834 } else { 835 $(this).removeClass('selected'); 836 $('.dropDown-misc-options span').html('Misc'); 837 prevSelectedDataTypeIndex = -2; 838 currentPanel.dataType = ""; 839 selectedDataTypeIndex = -1; 840 } 841 842 }); 843 844 function refreshNestedMiscMenuOptions() { 845 let dataType = mapIndexToMiscOptions.get(selectedDataTypeIndex); 846 dataType = dataType.charAt(0).toUpperCase() + dataType.slice(1); 847 $('.dropDown-misc-options span').html(dataType) 848 prevSelectedDataTypeIndex = selectedDataTypeIndex; 849 } 850 851 $(".data-options").on('click', function () { 852 selectedDataTypeIndex = $(this).data('index'); 853 currentPanel.dataType = mapIndexToDataType.get(selectedDataTypeIndex); 854 855 $('#dataOptionsDropDown').slideToggle(); 856 $('#nestedDataDropDown').toggleClass("active"); 857 $('#nestedDataDropDown .horizontalCaret').css("rotate", "90deg"); 858 let dataTypeMenuItems = $('.data-options'); 859 dataTypeMenuItems.each(function (index, item) { 860 item.classList.remove("selected"); 861 }) 862 $(this).addClass('selected'); 863 if (prevSelectedDataTypeIndex != selectedDataTypeIndex) { 864 refreshNestedDataMenuOptions(); 865 } else { 866 $(this).removeClass('selected'); 867 $('.dropDown-data-options span').html('Data'); 868 prevSelectedDataTypeIndex = -2; 869 currentPanel.dataType = ""; 870 selectedDataTypeIndex = -1; 871 } 872 }); 873 874 function refreshNestedDataMenuOptions() { 875 let dataType = mapIndexToDataType.get(selectedDataTypeIndex); 876 dataType = dataType.charAt(0).toUpperCase() + dataType.slice(1); 877 $('.dropDown-data-options span').html(dataType) 878 prevSelectedDataTypeIndex = selectedDataTypeIndex; 879 } 880 881 $(".throughput-options").on('click', function () { 882 selectedDataTypeIndex = $(this).data('index'); 883 currentPanel.dataType = mapIndexToThroughputOptions.get(selectedDataTypeIndex); 884 $('#throughputOptionsDropDown').slideToggle(); 885 $('#nestedThroughputDropDown').toggleClass("active"); 886 $('#nestedThroughputDropDown .horizontalCaret').css("rotate", "90deg"); 887 let dataTypeMenuItems = $('.throughput-options'); 888 dataTypeMenuItems.each(function (index, item) { 889 item.classList.remove("selected"); 890 }) 891 $(this).addClass('selected'); 892 if (prevSelectedDataTypeIndex != selectedDataTypeIndex) { 893 refreshNestedTptMenuOptions(); 894 } else { 895 $(this).removeClass('selected'); 896 $('.dropDown-throughput-options span').html('Throughput'); 897 prevSelectedDataTypeIndex = -2; 898 currentPanel.dataType = ""; 899 selectedDataTypeIndex = -1; 900 } 901 }); 902 903 function refreshNestedTptMenuOptions() { 904 let dataType = mapIndexToThroughputOptions.get(selectedDataTypeIndex); 905 dataType = dataType.charAt(0).toUpperCase() + dataType.slice(1); 906 $('.dropDown-throughput-options span').html(dataType) 907 prevSelectedDataTypeIndex = selectedDataTypeIndex; 908 } 909 910 $(".percent-options").on('click', function () { 911 selectedDataTypeIndex = $(this).data('index'); 912 currentPanel.dataType = mapIndexToPercentOption.get(selectedDataTypeIndex); 913 $('#percentOptionsDropDown').slideToggle(); 914 $('#nestedPercentDropDown').toggleClass("active"); 915 $('#nestedPercentDropDown .horizontalCaret').css("rotate", "90deg"); 916 let dataTypeMenuItems = $('.percent-options'); 917 dataTypeMenuItems.each(function (index, item) { 918 item.classList.remove("selected"); 919 }) 920 $(this).addClass('selected'); 921 if (prevSelectedDataTypeIndex != selectedDataTypeIndex) { 922 refreshNestedPercentMenuOptions(); 923 } else { 924 $(this).removeClass('selected'); 925 $('.dropDown-percent-options span').html('Percent'); 926 prevSelectedDataTypeIndex = -2; 927 currentPanel.dataType = ""; 928 selectedDataTypeIndex = -1; 929 } 930 }); 931 932 function refreshNestedPercentMenuOptions() { 933 let dataType = mapIndexToPercentOption.get(selectedDataTypeIndex); 934 dataType = dataType.charAt(0).toUpperCase() + dataType.slice(1); 935 $('.dropDown-percent-options span').html(dataType) 936 prevSelectedDataTypeIndex = selectedDataTypeIndex; 937 } 938 939 $(".time-options").on('click', function () { 940 selectedDataTypeIndex = $(this).data('index'); 941 currentPanel.dataType = mapIndexToTimeOptions.get(selectedDataTypeIndex); 942 $('#timeOptionsDropDown').slideToggle(); 943 $('#nestedTimeDropDown').toggleClass("active"); 944 $('#nestedTimeDropDown .horizontalCaret').css("rotate", "90deg"); 945 let dataTypeMenuItems = $('.time-options'); 946 dataTypeMenuItems.each(function (index, item) { 947 item.classList.remove("selected"); 948 }) 949 $(this).addClass('selected'); 950 if (prevSelectedDataTypeIndex != selectedDataTypeIndex) { 951 refreshNestedTimeMenuOptions(); 952 } else { 953 $(this).removeClass('selected'); 954 $('.dropDown-time-options span').html('Time'); 955 prevSelectedDataTypeIndex = -2; 956 currentPanel.dataType = ""; 957 selectedDataTypeIndex = -1; 958 } 959 }); 960 961 function refreshNestedTimeMenuOptions() { 962 let dataType = mapIndexToTimeOptions.get(selectedDataTypeIndex); 963 dataType = dataType.charAt(0).toUpperCase() + dataType.slice(1); 964 $('.dropDown-time-options span').html(dataType) 965 prevSelectedDataTypeIndex = selectedDataTypeIndex; 966 } 967 968 $(".data-rate-options").on('click', function () { 969 selectedDataTypeIndex = $(this).data('index'); 970 currentPanel.dataType = mapIndexToDataRateType.get(selectedDataTypeIndex); 971 $('#dataRateOptionsDropDown').slideToggle(); 972 $('#nestedDataRateDropDown').toggleClass("active"); 973 $('#nestedDataRateDropDown .horizontalCaret').css("rotate", "90deg"); 974 let dataTypeMenuItems = $('.data-rate-options'); 975 dataTypeMenuItems.each(function (index, item) { 976 item.classList.remove("selected"); 977 }) 978 $(this).addClass('selected'); 979 if (prevSelectedDataTypeIndex != selectedDataTypeIndex) { 980 refreshNestedDataRateMenuOptions(); 981 } else { 982 $(this).removeClass('selected'); 983 $('.dropDown-data-rate-options span').html('Data Rate'); 984 prevSelectedDataTypeIndex = -2; 985 currentPanel.dataType = ""; 986 selectedDataTypeIndex = -1; 987 } 988 }); 989 990 function refreshNestedDataRateMenuOptions() { 991 let dataType = mapIndexToDataRateType.get(selectedDataTypeIndex); 992 dataType = dataType.charAt(0).toUpperCase() + dataType.slice(1); 993 $('.dropDown-data-rate-options span').html(dataType); 994 prevSelectedDataTypeIndex = selectedDataTypeIndex; 995 } 996 997 // common function to reset all unit dropdowns 998 function resetNestedUnitMenuOptions(selectedUnitTypeIndex) { 999 if (selectedUnitTypeIndex !== -1 && selectedUnitTypeIndex !== undefined) { 1000 $('.editPanelMenu-unit .editPanelMenu-unit-options').each(function (index, item) { 1001 item.classList.remove("active"); 1002 }) 1003 $('.horizontalCaret').css("rotate", "90deg"); 1004 let prevDataTypeSelectedMenuID; 1005 if (selectedUnitTypeIndex === 0) { 1006 prevDataTypeSelectedMenuID = 'miscOptionsDropDown'; 1007 $('.dropDown-misc-options span').html('Misc'); 1008 } else if (selectedUnitTypeIndex === 1) { 1009 prevDataTypeSelectedMenuID = 'dataOptionsDropDown'; 1010 $('.dropDown-data-options span').html('Data'); 1011 } else if (selectedUnitTypeIndex === 2){ 1012 prevDataTypeSelectedMenuID = 'throughputOptionsDropDown'; 1013 $('.dropDown-throughput-options span').html('Throughput'); 1014 } else if (selectedUnitTypeIndex === 3){ 1015 prevDataTypeSelectedMenuID = 'timeOptionsDropDown'; 1016 $('.dropDown-time-options span').html('Time'); 1017 } else if (selectedUnitTypeIndex === 4){ 1018 prevDataTypeSelectedMenuID = 'dataRateOptionsDropDown'; 1019 $('.dropDown-data-rate-options span').html('Data Rate'); 1020 } 1021 1022 let allInnerOptions = $(`#${prevDataTypeSelectedMenuID}`).find('.inner-options'); 1023 allInnerOptions.each(function(index, item ) { 1024 item.classList.remove("selected"); 1025 }); 1026 1027 prevSelectedDataTypeIndex = -2; 1028 currentPanel.dataType = ""; 1029 currentPanel.unit = ""; 1030 selectedDataTypeIndex = -1; 1031 } 1032 } 1033 1034 $('.queryInput').on('input', function (e) { 1035 queryStr = e.target.value; 1036 $(this).val(queryStr); 1037 }) 1038 1039 function updatePanelName() { 1040 let nameEl = $('#panEdit-nameChangeInput') 1041 currentPanel.name = nameEl.val(); 1042 $('.panEdit-navBar .panelTitle').html(nameEl.val()) 1043 } 1044 1045 function updatePanelDescr() { 1046 let descrEl = $('#panEdit-descrChangeInput') 1047 currentPanel.description = descrEl.val(); 1048 } 1049 1050 function refreshDataSourceMenuOptions() { 1051 let dataSourceTypeMenuItems = $('.editPanelMenu-dataSource .editPanelMenu-options'); 1052 dataSourceTypeMenuItems.each(function (index, item) { 1053 item.classList.remove("selected"); 1054 }) 1055 dataSourceTypeMenuItems[selectedDataSourceTypeIndex].classList.add("selected"); 1056 let dataSource = mapIndexToDataSourceType.get(selectedDataSourceTypeIndex); 1057 dataSource = dataSource.charAt(0).toUpperCase() + dataSource.slice(1); 1058 $('.dropDown-dataSource span').html(dataSource); 1059 } 1060 1061 function refreshChartMenuOptions() { 1062 let chartTypeMenuItems = $('.editPanelMenu-chart .editPanelMenu-options'); 1063 chartTypeMenuItems.each(function (index, item) { 1064 item.classList.remove("selected"); 1065 }) 1066 chartTypeMenuItems[selectedChartTypeIndex].classList.add("selected"); 1067 let chartType = mapIndexToChartType.get(selectedChartTypeIndex); 1068 chartType = chartType.charAt(0).toUpperCase() + chartType.slice(1); 1069 $('.dropDown-chart span').html(chartType); 1070 } 1071 1072 function refreshUnitMenuOptions() { 1073 let unitTypeMenuItems = $('.editPanelMenu-unit .editPanelMenu-unit-options'); 1074 unitTypeMenuItems.each(function (index, item) { 1075 item.classList.remove("selected"); 1076 }) 1077 1078 1079 unitTypeMenuItems[selectedUnitTypeIndex].classList.add("selected"); 1080 let unit = mapIndexToUnitType.get(selectedUnitTypeIndex); 1081 unit = unit.charAt(0).toUpperCase() + unit.slice(1); 1082 $('.dropDown-unit span').html(unit) 1083 } 1084 1085 function refreshLogLinesViewMenuOptions(){ 1086 let viewTypeMenuItems = $('.editPanelMenu-logLinesView .editPanelMenu-options'); 1087 viewTypeMenuItems.each(function (index, item) { 1088 item.classList.remove("selected"); 1089 }) 1090 viewTypeMenuItems[selectedLogLinesViewTypeIndex].classList.add("selected"); 1091 let logLineView = mapIndexToLogLinesViewType.get(selectedLogLinesViewTypeIndex); 1092 logLineView = logLineView.charAt(0).toUpperCase() + logLineView.slice(1); 1093 $('.dropDown-logLinesView span').html(logLineView); 1094 } 1095 1096 function applyChangesToPanel(redirectedFromViewScreen) { 1097 flagDBSaved = false; 1098 // update current panel with new time values 1099 if(currentPanel && currentPanel.queryData) { 1100 if(currentPanel.chartType === 'Line Chart') { 1101 currentPanel.queryData.start = filterStartDate 1102 currentPanel.queryData.end = filterEndDate 1103 } else { 1104 currentPanel.queryData.startEpoch = filterStartDate 1105 currentPanel.queryData.endEpoch = filterEndDate 1106 } 1107 } 1108 if (!currentPanel.queryData && currentPanel.chartType === 'Data Table' && currentPanel.queryType === 'logs') { 1109 currentPanel.chartType = ""; 1110 currentPanel.queryType = ""; 1111 } 1112 localPanels[panelIndex] = JSON.parse(JSON.stringify(currentPanel)); 1113 // update filterStartDate, filterEndDate before leaving edit panel screen 1114 setTimePicker(); 1115 resetNestedUnitMenuOptions(selectedUnitTypeIndex); 1116 if(redirectedFromViewScreen === -1) { 1117 updateTimeRangeForPanel(panelIndex); 1118 goToViewScreen(panelIndex); 1119 } 1120 else { 1121 updateTimeRangeForPanels(); 1122 goToDashboard(); 1123 } 1124 } 1125 1126 function handleGoToDBArrowClick(redirectedFromViewScreen) { 1127 if (!checkUnsavedChages()) { 1128 showPrompt(redirectedFromViewScreen) 1129 } else { 1130 goToDashboard(redirectedFromViewScreen); 1131 } 1132 1133 function checkUnsavedChages() { 1134 let serverPanel = JSON.parse(JSON.stringify(localPanels[panelIndex])); 1135 return (currentPanel.chartType === serverPanel.chartType 1136 && currentPanel.dataType === serverPanel.dataType 1137 && currentPanel.description === serverPanel.description 1138 && currentPanel.name === serverPanel.name 1139 && currentPanel.queryType === serverPanel.queryType 1140 && currentPanel.unit === serverPanel.unit 1141 && currentPanel.panelIndex === serverPanel.panelIndex 1142 1143 && currentPanel.queryData?.endEpoch === serverPanel.queryData?.endEpoch 1144 && currentPanel.queryData?.indexName === serverPanel.queryData?.indexName 1145 && currentPanel.queryData?.queryLanguage === serverPanel.queryData?.queryLanguage 1146 && currentPanel.queryData?.searchText === serverPanel.queryData?.searchText 1147 && currentPanel.queryData?.startEpoch === serverPanel.queryData?.startEpoch 1148 && currentPanel.queryData?.state === serverPanel.queryData?.state); 1149 } 1150 1151 function showPrompt(redirectedFromViewScreen) { 1152 $('.popupOverlay, .popupContent').addClass('active'); 1153 $('#exit-btn-panel').on("click", function () { 1154 $('.popupOverlay, .popupContent').removeClass('active'); 1155 goToDashboard(redirectedFromViewScreen); 1156 }); 1157 $('#cancel-btn-panel, .popupOverlay').on("click", function () { 1158 $('.popupOverlay, .popupContent').removeClass('active'); 1159 }); 1160 } 1161 } 1162 1163 function goToViewScreen(panelIndex) { 1164 currentPanel = undefined; 1165 resetEditPanelScreen(); 1166 viewPanelInit(); 1167 displayPanelView(panelIndex); 1168 } 1169 1170 function goToDashboard(redirectedFromViewScreen) { 1171 setTimePicker(); 1172 resetNestedUnitMenuOptions(selectedUnitTypeIndex); 1173 currentPanel = undefined; 1174 resetEditPanelScreen(); 1175 if(redirectedFromViewScreen === -1) { 1176 if(localPanels !== undefined) { 1177 let stDate; 1178 let endDate 1179 if(localPanels[panelIndex].queryData) { 1180 if(localPanels[panelIndex].chartType === "line") { 1181 stDate = localPanels[panelIndex].queryData.start; 1182 endDate = localPanels[panelIndex].queryData.end; 1183 } else { 1184 stDate = localPanels[panelIndex].queryData.startEpoch; 1185 endDate = localPanels[panelIndex].queryData.endEpoch; 1186 } 1187 } 1188 $('.inner-range #' + stDate).addClass('active'); 1189 datePickerHandler(stDate, endDate, stDate); 1190 } 1191 goToViewScreen(panelIndex); 1192 } 1193 else { 1194 $('.panelEditor-container').hide(); 1195 $('#app-container').show(); 1196 $('#viewPanel-container').hide(); 1197 if(localPanels !== undefined) { 1198 let stDate; 1199 let endDate 1200 let i = 0; 1201 while(i < localPanels.length) { 1202 if(localPanels[i].queryData) { 1203 if(localPanels[i].chartType === "line") { 1204 stDate = localPanels[i].queryData.start; 1205 endDate = localPanels[i].queryData.end; 1206 } else { 1207 stDate = localPanels[i].queryData.startEpoch; 1208 endDate = localPanels[i].queryData.endEpoch; 1209 } 1210 break; 1211 } 1212 i++; 1213 } 1214 } 1215 displayPanels(); 1216 if(dbRefresh){ 1217 startRefreshInterval(dbRefresh) 1218 } 1219 } 1220 } 1221 1222 function resetPanelTimeRanges() { 1223 for (let i = 0; i < localPanels.length; i++) { 1224 if (localPanels[i].queryData) { 1225 ((localPanels[i].chartType === "Line Chart" || localPanels[i].chartType === "number" ) && localPanels[i].queryType === "metrics") 1226 ?(localPanels[i].queryData.start = filterStartDate) 1227 :(localPanels[i].queryData.startEpoch = filterStartDate) 1228 } 1229 } 1230 } 1231 1232 function resetEditPanelScreen() { 1233 resetEditPanel(); 1234 $('.dropDown-dataSource span').html("Data Source") 1235 $('.dropDown-chart span').html("Chart Type") 1236 $('.dropDown-unit span').html("Unit") 1237 $('.dropDown-logLinesView span').html("Single line display view") 1238 $("#index-btn").css('display', 'none'); 1239 $("#query-language-btn").css('display', 'none'); 1240 $("#metrics-query-language-btn").css('display', 'none'); 1241 $('.query-language-option').removeClass('active'); 1242 $('#query-language-btn span').html('Splunk QL'); 1243 $('#query-language-options #option-3').addClass('active'); 1244 } 1245 1246 function resetEditPanel() { 1247 $('.panelDisplay .panEdit-panel').remove(); 1248 const panEditEl = `<div id="panEdit-panel" class="panEdit-panel"></div>` 1249 $('.panelDisplay').append(panEditEl); 1250 1251 selectedChartTypeIndex = -1; 1252 selectedDataSourceTypeIndex = -1; 1253 selectedLogLinesViewTypeIndex = -1; 1254 1255 let dataSourceTypeMenuItems = $('.editPanelMenu-dataSource .editPanelMenu-options'); 1256 dataSourceTypeMenuItems.each(function (index, item) { 1257 item.classList.remove("selected"); 1258 }) 1259 1260 let chartTypeMenuItems = $('.editPanelMenu-chart .editPanelMenu-options'); 1261 chartTypeMenuItems.each(function (index, item) { 1262 item.classList.remove("selected"); 1263 }) 1264 1265 let unitTypeMenuItems = $('.editPanelMenu-unit .editPanelMenu-unit-options'); 1266 unitTypeMenuItems.each(function (index, item) { 1267 item.classList.remove("selected"); 1268 }) 1269 1270 let viewTypeMenuItems = $('.editPanelMenu-logLinesView .editPanelMenu-options'); 1271 viewTypeMenuItems.each(function (index, item) { 1272 item.classList.remove("selected"); 1273 }) 1274 1275 $('.range-item').each(function() { 1276 if($(this).hasClass('active')) { 1277 $(this).removeClass('active'); 1278 return; 1279 } 1280 }) 1281 } 1282 1283 function getMetricsQData() { 1284 let filterValue = queryStr; 1285 let endDate = filterEndDate || "now"; 1286 let stDate = filterStartDate || "now-15m"; 1287 1288 return { 1289 'query': filterValue, 1290 'start': stDate.toString(), 1291 'end': endDate.toString(), 1292 }; 1293 } 1294 1295 function setQueryLangHandlerEditPanel(e) { 1296 $('.panelEditor-container .panEdit-query-language-option').removeClass('active'); 1297 $('.panelEditor-container #query-language-btn span').html($(this).html()); 1298 displayQueryToolTip(selectedDataSourceTypeIndex); 1299 $(this).addClass('active'); 1300 } 1301 1302 function displayQueryToolTip(selectedDataSourceTypeIndex) { 1303 $('#info-icon-metrics, #info-icon-sql, #info-icon-logQL, #info-icon-spl').hide(); 1304 let queryLanguage = $('.panelEditor-container .queryInput-container #query-language-btn span').html(); 1305 if (selectedDataSourceTypeIndex === 0) { 1306 $('#info-icon-metrics').show(); 1307 } else if (queryLanguage === "SQL" && selectedDataSourceTypeIndex === 1) { 1308 $('#info-icon-sql').show(); 1309 } else if (queryLanguage === "Log QL" && selectedDataSourceTypeIndex === 1) { 1310 $('#info-icon-logQL').show(); 1311 } else if (queryLanguage === "Splunk QL" && selectedDataSourceTypeIndex === 1) { 1312 $('#info-icon-spl').show(); 1313 } 1314 } 1315 1316 async function runQueryBtnHandler() { 1317 // reset the current panel's queryRes attribute 1318 delete currentPanel.queryRes; 1319 resetEditPanel(); 1320 $('.panelDisplay .ag-root-wrapper').remove(); 1321 $(".panelDisplay #empty-response").empty(); 1322 $(".panelDisplay #empty-response").hide(); 1323 $('.panelDisplay #corner-popup').hide(); 1324 $('.panelDisplay #panelLogResultsGrid').hide(); 1325 $('.panelDisplay .big-number-display-container').hide(); 1326 1327 // runs the query according to the query type selected and irrespective of chart type 1328 if (currentPanel.queryType == 'metrics'){ 1329 data = getMetricsQData(); 1330 currentPanel.queryData = data; 1331 runMetricsQuery(data, -1, currentPanel); 1332 }else if (currentPanel.queryType == 'logs'){ 1333 data = getQueryParamsData(); 1334 currentPanel.queryData = data; 1335 $('.panelDisplay .panEdit-panel').hide(); 1336 await runPanelLogsQuery(data, -1,currentPanel); 1337 } 1338 toggleTableView(); 1339 } 1340 $(document).on('click', function(event) { 1341 if (!$(event.target).closest('.dropDown-dataSource').length) { 1342 $('.editPanelMenu-dataSource').slideUp(); 1343 $('.dropDown-dataSource').removeClass("active"); 1344 } 1345 1346 if (!$(event.target).closest('.dropDown-chart').length) { 1347 $('.editPanelMenu-chart').slideUp(); 1348 $('.dropDown-chart').removeClass("active"); 1349 } 1350 1351 if (!$(event.target).closest('.dropDown-color').length) { 1352 $('.editPanelMenu-color').slideUp(); 1353 $('.dropDown-color').removeClass("active"); 1354 } 1355 1356 if (!$(event.target).closest('.dropDown-logLinesView').length) { 1357 $('.editPanelMenu-logLinesView').slideUp(); 1358 $('.dropDown-logLinesView').removeClass("active"); 1359 } 1360 1361 if (!$(event.target).closest('.dropDown-unit').length) { 1362 $('.editPanelMenu-unit').slideUp(); 1363 $('.dropDown-unit').removeClass("active"); 1364 } 1365 1366 if (!$(event.target).closest('.editPanelMenu-inner-options').length) { 1367 $( ".editPanelMenu-inner-options" ).slideUp(); 1368 $('.dropDown-unit').removeClass("active"); 1369 } 1370 }); 1371 1372 const toggleSwitch = document.getElementById('toggle-switch'); 1373 1374 toggleSwitch.addEventListener('change', toggleTableView); 1375 1376 function toggleTableView() { 1377 const chartType = currentPanel.chartType; 1378 const cornerPopup = $(".panelDisplay #corner-popup"); 1379 const emptyResponse = $(".panelDisplay #empty-response"); 1380 1381 const isCornerPopup = $(".panelDisplay #corner-popup").css("display") === "flex"; 1382 const isErrorResponse = $(".panelDisplay #empty-response").css("display") === "flex"; 1383 if (isCornerPopup || isErrorResponse) return; 1384 if (chartType === 'Line Chart'||chartType === 'Data Table'|| chartType==='loglines') return; 1385 const panelLogResultsGrid = $(".panelDisplay #panelLogResultsGrid"); 1386 const panEditPanel = $('.panelDisplay .panEdit-panel'); 1387 const bigNumberDisplayContainer = $('.panelDisplay .big-number-display-container'); 1388 1389 if (toggleSwitch.checked) { 1390 panelLogResultsGrid.show(); 1391 emptyResponse.empty().hide(); 1392 cornerPopup.hide(); 1393 panEditPanel.hide(); 1394 bigNumberDisplayContainer.hide(); 1395 if(!chartType){ 1396 panelLogResultsGrid.hide(); 1397 panEditPanel.show(); 1398 } 1399 } else { 1400 panelLogResultsGrid.hide(); 1401 emptyResponse.empty().hide(); 1402 cornerPopup.hide(); 1403 panEditPanel.hide(); 1404 if(!chartType){ 1405 panEditPanel.show(); 1406 } 1407 switch (chartType) { 1408 case "Bar Chart": 1409 case "Pie Chart": 1410 panEditPanel.show(); 1411 break; 1412 case "number": 1413 bigNumberDisplayContainer.show(); 1414 break; 1415 } 1416 } 1417 };