<commit_before>

var CacheManagerBackend = {
  
  CONTENT_HANDLER: 'cacheMonitor',
  STATUS_OK: 'ok',
  STATUS_ERROR: 'error',
  
  defaultErrorHandle: function(status, errorMsg){
    alert('Error :' + errorMsg);
  },
  
  handleResponse: function(response, callback){
    if(response.status == this.STATUS_OK){
      if(typeof(callback) == 'function'){
        callback(response.result);
      }
    }
    else {
      if(typeof(errorCallback) == 'function'){
        errorCallback(reponse.status, response.errorMsg);
      } else {
        this.defaultErrorHandle(response.status, response.errorMsg);
      }
    }
  },
  
  postJson: function(args, callback, errorCallback){
    var self = this;
    UI.loadingImg.show();
    $.post(this.CONTENT_HANDLER, args,
    function(response)
    {
      UI.loadingImg.hide();
      self.handleResponse(response, callback, errorCallback);
    }, 'json');
  },
  
  getJson: function(args, callback, errorCallback){
    var self = this;
    UI.loadingImg.show();
    $.getJSON(this.CONTENT_HANDLER, args,
      function(response)
      {
        UI.loadingImg.hide();
        self.handleResponse(response, callback, errorCallback);
      });
      
  }
  
};

var UI = {
  
  setButtonSelected: function(button, selected){
    if(!button.hasClass('selected')){
      if(selected) button.addClass('selected');
    }
    else if(!selected) button.removeClass('selected');
  },
  
  //define UI elements
  init: function(){
    //main panes
    this.cachedQueries = $('#cachedQueries');
    this.scheduledQueries = $('#scheduledQueries');
    //main pane switch buttons
    this.cacheButton = $('#cacheButton');
    this.scheduleButton = $('#scheduleButton');
    //cache area
    this.cachedQueries = $('#cachedQueries');
    this.cachedQueriesDetail = $('#cachedQueriesDetail');
    this.cachedQueriesOverview = $('#cachedQueriesOverview');
    this.cachedQueriesOverviewLines = $("#cachedQueriesOverviewLines");
    this.clearCacheButton = $("#clearCacheButton");
    //loading imgs
    this.loadingImg = $('#loading');
  }
};

/** SCHEDULER **/

var refreshTable = function(){

  UI.cachedQueries.hide();
  UI.scheduledQueries.show();
  UI.setButtonSelected(UI.cacheButton, false);
  UI.setButtonSelected(UI.scheduleButton, true);

  $.getJSON('cacheController?method=list', populateQueries);
};


var populateQueries = function(data){
  var ph = $("#lines").empty();


  for (row in data.queries) {
  
    var r = data.queries[row];

    var row = $("<div class='span-24 last row "+ (r.success?"":"error") +"' id='query_" + r.id + "'></div>");

    // Name
    var name = r.cdaFile + " (" + r.dataAccessId + ")";
    row.append("<div class='span-7 left'>" + name + "</div>");

    var paramPh = $("<dl></dl></div>");
    for (var param in r.parameters){
      paramPh.append("<dt>"+param+"</dt><dd>"+r.parameters[param]+"</dd>");
    }
    $("<div class='span-5 left'></div>").append(paramPh).appendTo(row);


    row.append("<div class='span-2'>" + formatDate(r.lastExecuted) + " </div>");
    row.append("<div class='span-2'>" + formatDate(r.nextExecution) + " </div>");
    row.append("<div class='span-2'>" + r.cronString + " </div>");
    row.append("<div class='span-2'>" + r.timeElapsed + " </div>");
    row.append("<div class='span-2'>" + (r.success?"Success":"Failed") + " </div>");

    var deleteButton = $("<a  href='javascript:'><img src='cachemanager/delete-24x24.png' class='button' alt='delete'></a>");
    var deleteFunction = function(id){
      deleteButton.click(function(){
        if(confirm("Want to delete this scheduler?")){
          $.getJSON("cacheController?method=delete&id=" + id ,function(){
            refreshTable();
          })
        }
      })
    };
    deleteFunction(r.id);

    var refreshButton = $("<a  href='javascript:'><img src='cachemanager/refresh-24x24.png' class='button' alt='refresh'></a>");
    var refreshFunction = function(id){
      refreshButton.click(function(){

        var myself = this;
        $(this).find("img").attr("src","cachemanager/processing.png");
        $.getJSON("cacheController?method=execute&id=" + id,function(){
          refreshTable();
        })

      })
    };
    refreshFunction(r.id);

    $("<div class='span-2 last operations'></div>").append(refreshButton).append(deleteButton).appendTo(row);

    ph.append(row);
  
  }
};

/** CACHE **/

//Main cache view<commit_msg>Bug #2088 Error deleting schedule in new trunk<commit_after>

var CacheManagerBackend = {
  
  CONTENT_HANDLER: 'cacheMonitor',
  STATUS_OK: 'ok',
  STATUS_ERROR: 'error',
  
  defaultErrorHandle: function(status, errorMsg){
    alert('Error :' + errorMsg);
  },
  
  handleResponse: function(response, callback){
    if(response.status == this.STATUS_OK){
      if(typeof(callback) == 'function'){
        callback(response.result);
      }
    }
    else {
      if(typeof(errorCallback) == 'function'){
        errorCallback(reponse.status, response.errorMsg);
      } else {
        this.defaultErrorHandle(response.status, response.errorMsg);
      }
    }
  },
  
  postJson: function(args, callback, errorCallback){
    var self = this;
    UI.loadingImg.show();
    $.post(this.CONTENT_HANDLER, args,
    function(response)
    {
      UI.loadingImg.hide();
      self.handleResponse(response, callback, errorCallback);
    }, 'json');
  },
  
  getJson: function(args, callback, errorCallback){
    var self = this;
    UI.loadingImg.show();
    $.getJSON(this.CONTENT_HANDLER, args,
      function(response)
      {
        UI.loadingImg.hide();
        self.handleResponse(response, callback, errorCallback);
      });
      
  }
  
};

var UI = {
  
  setButtonSelected: function(button, selected){
    if(!button.hasClass('selected')){
      if(selected) button.addClass('selected');
    }
    else if(!selected) button.removeClass('selected');
  },
  
  //define UI elements
  init: function(){
    //main panes
    this.cachedQueries = $('#cachedQueries');
    this.scheduledQueries = $('#scheduledQueries');
    //main pane switch buttons
    this.cacheButton = $('#cacheButton');
    this.scheduleButton = $('#scheduleButton');
    //cache area
    this.cachedQueries = $('#cachedQueries');
    this.cachedQueriesDetail = $('#cachedQueriesDetail');
    this.cachedQueriesOverview = $('#cachedQueriesOverview');
    this.cachedQueriesOverviewLines = $("#cachedQueriesOverviewLines");
    this.clearCacheButton = $("#clearCacheButton");
    //loading imgs
    this.loadingImg = $('#loading');
  }
};

/** SCHEDULER **/

var refreshTable = function(){

  UI.cachedQueries.hide();
  UI.scheduledQueries.show();
  UI.setButtonSelected(UI.cacheButton, false);
  UI.setButtonSelected(UI.scheduleButton, true);

  $.getJSON('cacheController?method=list', populateQueries);
};


var populateQueries = function(data){
  var ph = $("#lines").empty();


  for (row in data.queries) {
  
    var r = data.queries[row];

    var row = $("<div class='span-24 last row "+ (r.success?"":"error") +"' id='query_" + r.id + "'></div>");

    // Name
    var name = r.cdaFile + " (" + r.dataAccessId + ")";
    row.append("<div class='span-7 left'>" + name + "</div>");

    var paramPh = $("<dl></dl></div>");
    for (var param in r.parameters){
      paramPh.append("<dt>"+param+"</dt><dd>"+r.parameters[param]+"</dd>");
    }
    $("<div class='span-5 left'></div>").append(paramPh).appendTo(row);


    row.append("<div class='span-2'>" + formatDate(r.lastExecuted) + " </div>");
    row.append("<div class='span-2'>" + formatDate(r.nextExecution) + " </div>");
    row.append("<div class='span-2'>" + r.cronString + " </div>");
    row.append("<div class='span-2'>" + r.timeElapsed + " </div>");
    row.append("<div class='span-2'>" + (r.success?"Success":"Failed") + " </div>");

    var deleteButton = $("<a  href='javascript:'><img src='cachemanager/delete-24x24.png' class='button' alt='delete'></a>");
    var deleteFunction = function(id){
      deleteButton.click(function(){
        if(confirm("Want to delete this scheduler?")){
          $.getJSON("cacheController?method=delete&object=" + id ,function(){
            refreshTable();
          })
        }
      })
    };
    deleteFunction(r.id);

    var refreshButton = $("<a  href='javascript:'><img src='cachemanager/refresh-24x24.png' class='button' alt='refresh'></a>");
    var refreshFunction = function(id){
      refreshButton.click(function(){

        var myself = this;
        $(this).find("img").attr("src","cachemanager/processing.png");
        $.getJSON("cacheController?method=execute&object=" + id,function(){
          refreshTable();
        })

      })
    };
    refreshFunction(r.id);

    $("<div class='span-2 last operations'></div>").append(refreshButton).append(deleteButton).appendTo(row);

    ph.append(row);
  
  }
};

/** CACHE **/

//Main cache view
{'fraction_non_alphanumeric': 0.1874506263401422, 'fraction_numerical': 0.00451416318699921, 'mean_word_length': 3.3441176470588236, 'pattern_counts': {'":': 4, '<': 65, '<?xml version=': 0, '>': 65, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1448796', 'n_tokens_mistral': 2830, 'n_tokens_neox': 2759, 'n_words': 472}