<commit_before>/* 
 * amtc-web.js - part of amtc-web, part of amtc
 * https://github.com/schnoddelbotz/amtc
 *
 * this jQuery spaghetti renders the web GUI of amtc-web.
 */
/*
 * FIXMEs
 * - configTabs do not update hash onClick
 */

var visitorScript = 'amtc-web.php';
var adminScript = 'admin/admin.php';

var infoURL = visitorScript+"?action=getState&mode=live&roomname=";
var logURL  = visitorScript+"?action=getState&mode=log&roomname=";
var roomURL = visitorScript+"?action=getRooms";
/* these admin only pages will trigger http basic auth popups 
   ... as long as an adequate .htaccess file exists in /admin */
var ctrlURL = adminScript+"?action=submitJob";
var cfgURL = adminScript+"?action=config&mode=";


var msg_PleaseSelectRoom = 'Please select a room.';
var msg_LoadingLive  = 'Loading live state of room, please wait...';

var currentRoom;
var hostList;
var hostLog;
var showingHosts=0;
var today=new Date();
var selectedDate=new Date();
var showLive=1; /* alternative: showLog, FIXME showConfig */
var zoom=1;
var configTabs;
var amtc_rooms;
var currentViewMode;
var powerstates = {"pc":"any", "S0":"on", "S3":"sleep", "S4":"hibernate", "S5":"soft-off",
                   "S16":"no-reply", "ssh":"SSH","rdp":"RDP","none":"No-OS"};


$(document).ready(function() { 
  $("#wheel").hide();
  $("#ctrlSubmit").removeAttr('disabled');
  loadRooms();
  initViewModeButtons();
  initConfigScreens();
  initPowerController();
});


/* called when a room is selected in admin mode.
 * loads roomdata and prepares forms */
function cfgRoom(room/*name*/) {
  $(".selected-room").removeClass("selected-room");
  $.getJSON(cfgURL+'rooms&roomname='+room, function(data) {
      currentRoom = room;
      window.location.hash = '#config;rooms;'+room;
      $("#cfghosts").html("");
      $("#cfgr_"+room).addClass("selected-room");
      if (data.success) {
        if (data.data.room) {
          hostList=data.data.room.hosts;
          drawConfigHosts();
        } 
        $("#existingRoom").show(); 
        $("#roomName").val(room);
        $("#amtVersion").val(data.data.roomMeta.has_amt);
        $("#idlePower").val(data.data.roomMeta.avg_pwr_on);
        $("#roomid").val(data.data.roomMeta.id);
        $("#createPc_submit").val('Create new PC in room '+room);
        $("#modRoom_msg").html("");
      } else {
        $("#cfghosts").html('<h2 class="warning">'+data.usermsg+'</h2>');
      }
  }).error(function(e) {
        $("#cfghosts").html('<h2 class="warning">ERROR: '+e.statusText+'</h2>');
  });
}

/* called upon page load and after admin modifications.
 * renders list of amt-enabled (non-version-0) rooms as chooser */
function loadRooms() {
  $("#hosts").html("Loading room data...");
  $("#rooms").html(""); 
  $.getJSON(roomURL, function(data) {
      if (data.success) {
        $("#hosts").html(msg_PleaseSelectRoom);
        amtc_rooms = data.data;
        $.each( amtc_rooms, function( key, value ) {
          var room = '<div id="'+key+'" class="room ui-corner-top">' +  key + '</div>';
          var cfgroom = '<div id="cfgr_'+key+'" roomname="'+key+'" class="room ui-corner-top">' +  key + '</div>';
          $("#rooms").append(room);
          $("#"+key).click(function() { setRoom($(this).attr("id"),0); });
        });
        $(".roomSelector").css( 'cursor', 'pointer' );
     } else {
      if (!window.location.hash)
          $("#admin").trigger('click');
     }
     goHashUrl();
  });
}

/* called upon page admin tab switch and after modifications to rooms.
 * renders list of any user-created rooms as chooser */
function loadCfgRooms() {
  $("#existingRoom").hide(); 
  $("#roomcfg_rooms").html(""); 
  $.getJSON(cfgURL+'rooms', function(data) {
      if (data.success) {
        amtc_rooms = data.data.rooms;
        $.each( amtc_rooms, function( key, value ) {
          var cfgroom = '<div id="cfgr_'+key+'" roomname="'+key+'" class="room ui-corner-top">' +  key + '</div>';
          $("#roomcfg_rooms").append(cfgroom);
          $("#cfgr_"+key).click(function() { cfgRoom($(this).attr("roomname"),0); });
        });
        $(".roomSelector").css( 'cursor', 'pointer' );
     } else {
          $("#admin").trigger('click');
     }
  });
}

/* called upon page load.
 * tries to get back to the right(tm) state */
function goHashUrl() {<commit_msg>catch php support missing server-side client-side<commit_after>/* 
 * amtc-web.js - part of amtc-web, part of amtc
 * https://github.com/schnoddelbotz/amtc
 *
 * this jQuery spaghetti renders the web GUI of amtc-web.
 */
/*
 * FIXMEs
 * - configTabs do not update hash onClick
 */

var visitorScript = 'amtc-web.php';
var adminScript = 'admin/admin.php';

var infoURL = visitorScript+"?action=getState&mode=live&roomname=";
var logURL  = visitorScript+"?action=getState&mode=log&roomname=";
var roomURL = visitorScript+"?action=getRooms";
/* these admin only pages will trigger http basic auth popups 
   ... as long as an adequate .htaccess file exists in /admin */
var ctrlURL = adminScript+"?action=submitJob";
var cfgURL = adminScript+"?action=config&mode=";


var msg_PleaseSelectRoom = 'Please select a room.';
var msg_LoadingLive  = 'Loading live state of room, please wait...';

var currentRoom;
var hostList;
var hostLog;
var showingHosts=0;
var today=new Date();
var selectedDate=new Date();
var showLive=1; /* alternative: showLog, FIXME showConfig */
var zoom=1;
var configTabs;
var amtc_rooms;
var currentViewMode;
var powerstates = {"pc":"any", "S0":"on", "S3":"sleep", "S4":"hibernate", "S5":"soft-off",
                   "S16":"no-reply", "ssh":"SSH","rdp":"RDP","none":"No-OS"};


$(document).ready(function() { 
  $("#wheel").hide();
  $("#ctrlSubmit").removeAttr('disabled');
  loadRooms();
  initViewModeButtons();
  initConfigScreens();
  initPowerController();
});


/* called when a room is selected in admin mode.
 * loads roomdata and prepares forms */
function cfgRoom(room/*name*/) {
  $(".selected-room").removeClass("selected-room");
  $.getJSON(cfgURL+'rooms&roomname='+room, function(data) {
      currentRoom = room;
      window.location.hash = '#config;rooms;'+room;
      $("#cfghosts").html("");
      $("#cfgr_"+room).addClass("selected-room");
      if (data.success) {
        if (data.data.room) {
          hostList=data.data.room.hosts;
          drawConfigHosts();
        } 
        $("#existingRoom").show(); 
        $("#roomName").val(room);
        $("#amtVersion").val(data.data.roomMeta.has_amt);
        $("#idlePower").val(data.data.roomMeta.avg_pwr_on);
        $("#roomid").val(data.data.roomMeta.id);
        $("#createPc_submit").val('Create new PC in room '+room);
        $("#modRoom_msg").html("");
      } else {
        $("#cfghosts").html('<h2 class="warning">'+data.usermsg+'</h2>');
      }
  }).error(function(e) {
        $("#cfghosts").html('<h2 class="warning">ERROR: '+e.statusText+'</h2>');
  });
}

/* called upon page load and after admin modifications.
 * renders list of amt-enabled (non-version-0) rooms as chooser */
function loadRooms() {
  $("#hosts").html("Loading room data...");
  $("#rooms").html(""); 
  $.getJSON(roomURL, function(data) {
      if (data.success) {
        $("#hosts").html(msg_PleaseSelectRoom);
        amtc_rooms = data.data;
        $.each( amtc_rooms, function( key, value ) {
          var room = '<div id="'+key+'" class="room ui-corner-top">' +  key + '</div>';
          var cfgroom = '<div id="cfgr_'+key+'" roomname="'+key+'" class="room ui-corner-top">' +  key + '</div>';
          $("#rooms").append(room);
          $("#"+key).click(function() { setRoom($(this).attr("id"),0); });
        });
        $(".roomSelector").css( 'cursor', 'pointer' );
     } else {
      if (!window.location.hash)
          $("#admin").trigger('click');
     }
     goHashUrl();
  }).error(function(e) {
      if (e.responseText.substring(0,5)==='<?php') {
        $("#hosts").html('<h2 class="warning">ERROR: Seems your webserver has no PHP support enabled?</h2>');
      } else 
        $("#hosts").html('<h2 class="warning">ERROR: '+e.statusText+'</h2>');
  });;
}

/* called upon page admin tab switch and after modifications to rooms.
 * renders list of any user-created rooms as chooser */
function loadCfgRooms() {
  $("#existingRoom").hide(); 
  $("#roomcfg_rooms").html(""); 
  $.getJSON(cfgURL+'rooms', function(data) {
      if (data.success) {
        amtc_rooms = data.data.rooms;
        $.each( amtc_rooms, function( key, value ) {
          var cfgroom = '<div id="cfgr_'+key+'" roomname="'+key+'" class="room ui-corner-top">' +  key + '</div>';
          $("#roomcfg_rooms").append(cfgroom);
          $("#cfgr_"+key).click(function() { cfgRoom($(this).attr("roomname"),0); });
        });
        $(".roomSelector").css( 'cursor', 'pointer' );
     } else {
          $("#admin").trigger('click');
     }
  });
}

/* called upon page load.
 * tries to get back to the right(tm) state */
function goHashUrl() {
{'fraction_non_alphanumeric': 0.20378457059679767, 'fraction_numerical': 0.004254842682790281, 'mean_word_length': 3.4065120868278242, 'pattern_counts': {'":': 18, '<': 28, '<?xml version=': 0, '>': 27, 'https://': 2, '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': '3700571', 'n_tokens_mistral': 2894, 'n_tokens_neox': 2890, 'n_words': 626}