github.com/siglens/siglens@v0.0.0-20240328180423-f7ce9ae441ed/static/js/available-fields.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  function renderAvailableFields(columnOrder) {
    20      let el = $('#available-fields .fields');
    21      let columnsToIgnore = ['timestamp', 'logs'];
    22      el.empty();
    23      columnOrder.forEach((colName, index) => {
    24          if (columnsToIgnore.indexOf(colName) == -1) {
    25              if (!availColNames.includes(colName)){
    26                  availColNames.push(colName);
    27                  selectedFieldsList.push(colName)
    28              }
    29          }
    30      });
    31      
    32      // Render all the available fields
    33      availColNames.forEach((colName, index) => {
    34          el.append(`<div class="available-fields-dropdown-item toggle-field toggle-${string2Hex(colName)}" data-index="${colName}">
    35                          <span class="fieldname-text">${colName}</span>
    36                          <img src="/assets/index-selection-check.svg">
    37                          </div>`);
    38      });
    39  
    40  let afieldDropDownItem = $(".fields .available-fields-dropdown-item");
    41  afieldDropDownItem.each(function (idx, li) {
    42      li.style.width = "auto"; 
    43  });
    44  
    45  let afieldDropDown = document.getElementById("available-fields");
    46  afieldDropDown.style.width = "auto"; 
    47  
    48      if (updatedSelFieldList){
    49          selectedFieldsList = _.intersection(selectedFieldsList, availColNames);
    50      }else{
    51          selectedFieldsList = _.union(selectedFieldsList, availColNames);
    52      }
    53  
    54      if (selectedFieldsList.length != 0) {
    55          availColNames.forEach((colName, index) => {
    56              if(selectedFieldsList.includes(colName)){
    57                  $(`.toggle-${string2Hex(colName)}`).addClass('active');
    58              } else {
    59                  $(`.toggle-${string2Hex(colName)}`).removeClass('active');
    60              }
    61          });
    62      } else {
    63          selectedFieldsList = [];
    64          availColNames.forEach((colName, index) => {
    65              $(`.toggle-${string2Hex(colName)}`).addClass('active');
    66              selectedFieldsList.push(colName);
    67          });
    68      }
    69  }
    70  
    71  function resetAvailableFields() {
    72      $('#available-fields .fields').html('');
    73  }