github.com/siglens/siglens@v0.0.0-20240328180423-f7ce9ae441ed/static/js/log-search.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 $(document).ready(() => { 20 setSaveQueriesDialog(); 21 getListIndices(); 22 const currentUrl = window.location.href; 23 if (currentUrl.includes("live-tail.html")) { 24 $(".nav-live").addClass("active"); 25 $(".nav-search").removeClass("active"); 26 }else{ 27 $(".nav-search").addClass("active"); 28 } 29 if (Cookies.get('theme')){ 30 theme = Cookies.get('theme'); 31 $('body').attr('data-theme', theme); 32 } 33 $('.theme-btn').on('click', themePickerHandler); 34 let ele = $('#available-fields .select-unselect-header'); 35 36 if (theme === "light"){ 37 ele.append(`<img class="select-unselect-checkmark" src="assets/available-fields-check-light.svg">`); 38 }else{ 39 ele.append(`<img class="select-unselect-checkmark" src="assets/index-selection-check.svg">`); 40 } 41 42 setupEventHandlers(); 43 44 resetDashboard(); 45 46 if (Cookies.get('startEpoch') && Cookies.get('endEpoch')){ 47 let cookieVar = Cookies.get('endEpoch'); 48 if(cookieVar === "now"){ 49 filterStartDate = Cookies.get('startEpoch'); 50 filterEndDate = Cookies.get('endEpoch'); 51 $('.inner-range #' + filterStartDate).addClass('active'); 52 } else { 53 filterStartDate = Number(Cookies.get('startEpoch')); 54 filterEndDate = Number(Cookies.get('endEpoch')); 55 } 56 } 57 58 if (Cookies.get('customStartDate')){ 59 let cookieVar = new Date(Cookies.get('customStartDate')); 60 $('#date-start').val(cookieVar.toISOString().substring(0,10)); 61 $('#date-start').addClass('active'); 62 } 63 if (Cookies.get('customEndDate')){ 64 let cookieVar = new Date(Cookies.get('customEndDate')); 65 $('#date-end').val(cookieVar.toISOString().substring(0,10)); 66 $('#date-end').addClass('active'); 67 } 68 if (Cookies.get('customStartTime')){ 69 $('#time-start').val(Cookies.get('customStartTime')); 70 $('#time-start').addClass('active'); 71 } 72 if (Cookies.get('customEndTime')){ 73 $('#time-end').val(Cookies.get('customEndTime')); 74 $('#time-end').addClass('active'); 75 } 76 77 if (!Cookies.get('IndexList')) { 78 Cookies.set('IndexList', "*"); 79 } 80 81 if (window.location.search) { 82 data = getInitialSearchFilter(false, false); 83 } else { 84 console.log(`No query string found, using default search filter.`) 85 data = getSearchFilter(false, false); 86 } 87 88 $("#info-icon-sql").tooltip({ 89 delay: { show: 0, hide: 300 }, 90 trigger: 'click' 91 }); 92 93 $('#info-icon-sql').on('click', function (e) { 94 $('#info-icon-sql').tooltip('show'); 95 }); 96 97 $(document).mouseup(function (e) { 98 if ($(e.target).closest(".tooltip-inner").length === 0) { 99 $('#info-icon-sql').tooltip('hide'); 100 } 101 }); 102 103 $("#info-icon-logQL").tooltip({ 104 delay: { show: 0, hide: 300 }, 105 trigger: 'click' 106 }); 107 108 $('#info-icon-logQL').on('click', function (e) { 109 $('#info-icon-logQL').tooltip('show'); 110 }); 111 112 $(document).mouseup(function (e) { 113 if ($(e.target).closest(".tooltip-inner").length === 0) { 114 $('#info-icon-logQL').tooltip('hide'); 115 } 116 }); 117 118 $("#info-icon-spl").tooltip({ 119 delay: { show: 0, hide: 300 }, 120 trigger: 'click' 121 }); 122 123 $('#info-icon-spl').on('click', function (e) { 124 $('#info-icon-spl').tooltip('show'); 125 }); 126 127 $(document).mouseup(function (e) { 128 if ($(e.target).closest(".tooltip-inner").length === 0) { 129 $('#info-icon-spl').tooltip('hide'); 130 } 131 }); 132 133 doSearch(data); 134 135 $("#filter-input").focus(function() { 136 if ($(this).val() === "*") { 137 $(this).val(""); 138 } 139 }); 140 }); 141 function displayQueryLangToolTip(selectedQueryLangID) { 142 $('#info-icon-sql, #info-icon-logQL, #info-icon-spl').hide(); 143 $("#clearInput").hide(); 144 switch (selectedQueryLangID) { 145 case "1": 146 $('#info-icon-sql').show(); 147 $("#filter-input").attr("placeholder", "Enter your SQL query here, or click the 'i' icon for examples"); 148 break; 149 case "2": 150 $('#info-icon-logQL').show(); 151 $("#filter-input").attr("placeholder", "Enter your LogQL query here, or click the 'i' icon for examples"); 152 break; 153 case "3": 154 $('#info-icon-spl').show(); 155 $("#filter-input").attr("placeholder", "Enter your SPL query here, or click the 'i' icon for examples"); 156 break; 157 } 158 } 159 160 $("#filter-input").on("input", function() { 161 if ($(this).val().trim() !== "") { 162 $("#clearInput").show(); 163 } else { 164 $("#clearInput").hide(); 165 } 166 }); 167 168 $("#clearInput").click(function() { 169 $("#filter-input").val("").focus(); 170 $(this).hide(); 171 }); 172 173 /* 174 Function to clear the query input field, search filter tags, and related elements 175 */ 176 function clearQueryInput() { 177 // Clear the query input field 178 $("#query-input").val("*").focus(); 179 180 // Hide the clear button for the query input field if it's empty 181 if ($("#query-input").val().trim() !== "") { 182 $("#clear-query-btn").show(); 183 } else { 184 $("#clear-query-btn").hide(); 185 } 186 187 // Clear all search filter tags and related elements 188 $("#tags, #tags-second, #tags-third").empty(); 189 firstBoxSet.clear(); 190 secondBoxSet.clear(); 191 thirdBoxSet.clear(); 192 193 // Show the default text for search filters, aggregation attribute, and aggregations 194 $("#search-filter-text, #aggregate-attribute-text, #aggregations").show(); 195 } 196 197 // Event handler for the clear button associated with the query input field 198 $("#clear-query-btn").click(function() { 199 clearQueryInput(); 200 });