github.com/rohankumardubey/aresdb@v0.0.2-0.20190517170215-e54e3ca06b9c/api/ui/debug/js/redologs.js (about)

     1  //  Copyright (c) 2017-2018 Uber Technologies, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  var upsertbatchTable
    16  
    17  function initRedoLogsPage() {
    18      // Init table selector.
    19      $('#table-selector').select2({
    20          ajax: {
    21              url: "/schema/tables",
    22              dataType: 'json',
    23              quietMillis: 50,
    24              processResults: function (data) {
    25                  return {
    26                      results: $.map(data, function (item, idx) {
    27                          return {
    28                              text: item,
    29                              id: idx + 1,
    30                          }
    31                      })
    32                  };
    33              }
    34          },
    35          width: 'resolve'
    36      }).on('change', function () {
    37          refreshRedoLogFilesList()
    38      });
    39  
    40      // Init shard selector.
    41      $('#shard-selector').select2({
    42          data: [
    43              {
    44                  "id": 0,
    45                  "text": 0,
    46              }
    47          ]
    48      }).on('change', function (e) {
    49          refreshRedoLogFilesList()
    50      });
    51  }
    52  
    53  function refreshRedoLogFilesList() {
    54      var table = $("#table-selector").select2('data')[0].text
    55      var shard = $("#shard-selector").select2('data')[0].text
    56  
    57      // Need to explicitly destroy redo log selector.
    58      if ($('#redologs-selector').select2()) {
    59          $('#redologs-selector').empty()
    60          $('#redologs-selector').select2("destroy");
    61      }
    62  
    63      $('#redologs-selector').select2({
    64          ajax: {
    65              url: "/dbg/{0}/{1}/redologs".format(table, shard),
    66              cache: true,
    67              dataType: 'json',
    68              quietMillis: 50,
    69              processResults: function (data) {
    70                  return {
    71                      results: $.map(data, function (item, idx) {
    72                          return {
    73                              text: item,
    74                              id: idx + 1,
    75                          }
    76                      })
    77                  };
    78              },
    79          },
    80          width: '100px',
    81          minimumResultsForSearch: -1,
    82      }).on('change', function (e) {
    83          refreshUpsertBatchList()
    84      });
    85  }
    86  
    87  
    88  function refreshUpsertBatchList() {
    89      var table = $("#table-selector").select2('data')[0].text
    90      var shard = $("#shard-selector").select2('data')[0].text
    91      var redoLog = $("#redologs-selector").select2('data')[0].text
    92  
    93      // Need to explicitly destroy upsert batch selector.
    94      if ($('#upsertbatch-selector').select2()) {
    95          $('#upsertbatch-selector').empty()
    96          $('#upsertbatch-selector').select2("destroy");
    97      }
    98  
    99      $('#upsertbatch-selector').select2({
   100          ajax: {
   101              url: "/dbg/{0}/{1}/redologs/{2}/upsertbatches".format(table, shard, redoLog),
   102              dataType: 'json',
   103              quietMillis: 50,
   104              processResults: function (data) {
   105                  return {
   106                      results: $.map(data, function (item, idx) {
   107                          return {
   108                              text: item,
   109                              id: idx + 1,
   110                          }
   111                      })
   112                  };
   113              }
   114          },
   115          minimumResultsForSearch: -1
   116      }).on('change', function () {
   117          initUpsertBatchTable()
   118      });
   119  }
   120  
   121  function initUpsertBatchTable() {
   122      var table = $("#table-selector").select2('data')[0].text
   123      var shard = $("#shard-selector").select2('data')[0].text
   124      var redoLog = $("#redologs-selector").select2('data')[0].text
   125      var upsertBatch = $("#upsertbatch-selector").select2('data')[0].text
   126  
   127      $.ajax(
   128          {
   129              url: "/dbg/{0}/{1}/redologs/{2}/upsertbatches/{3}".format(table, shard, redoLog, upsertBatch),
   130              success: function (body) {
   131                  var columns = body.columnNames.map(function (name) {
   132                          return {"title": name}
   133                      }
   134                  )
   135  
   136                  // Need to explicitly destroy old data table.
   137                  if (upsertbatchTable) {
   138                      upsertbatchTable.destroy()
   139                      $('#upsertbatch-table').empty()
   140                  }
   141  
   142                  upsertbatchTable = $('#upsertbatch-table').DataTable({
   143                      "serverSide": true,
   144                      "processing": true,
   145                      "paging": true,
   146                      "searching": false,
   147                      "pageLength": 20,
   148                      "lengthMenu": [[1, 10, 25, 50, 100], [1, 10, 25, 50, 100]],
   149                      "columns": columns,
   150                      "ajax": {
   151                          "type": "GET",
   152                          "url": "/dbg/{0}/{1}/redologs/{2}/upsertbatches/{3}".format(table, shard, redoLog, upsertBatch),
   153                          "dataType": "json",
   154                          "contentType": 'application/json'
   155                      }
   156                  });
   157              },
   158              error: function (error) {
   159                  alert('error: ' + eval(error));
   160              }
   161          }
   162      )
   163  
   164  }