<commit_before>"use strict"

import $ from 'jquery'
import _ from 'lodash'
import './style.css'

const hostname = "http://ec2-54-186-163-30.us-west-2.compute.amazonaws.com/"

$(document).ready(main);

async function main() {
  const fetchOptions = { method: "GET"
                      //  , headers: { 'Accept': 'application/json'
                      //             , "Authorization": "Basic " +
                      //                btoa(username + ":" + password)
                      //  }
                       , mode: "cors"
                       }
  const errorHandler = error => {
    console.log(error)
  }
  const teachers = await fetch( "http://${hostname}:8083/admin/list-teachers"
                              , fetchOptions)
                         .then(response => response.json())
                         .catch(errorHandler)
  drawTable(teachers);
  $("#add-teacher-button").click(function() {
      var uname = $("#new-teacher-username").val();
      var pwd = $("#new-teacher-password").val();
      if (isInvalid(uname) || isInvalid(pwd)) {
        alert("Username or Password is invalid!");
        return;
      }
      var newTeacher = { username:uname
                       , password:<PASSWORD>
                       };
      $.ajax({
        type: "POST",
        headers: {
            'Accept': 'application/json',
            'Content-Type': 'application/json'
        },
        success: function(justAddedTeacher) {
          drawRow(justAddedTeacher)
        },
        url: "http://127.0.0.1:8083/admin/register-teacher",
        data: JSON.stringify(newTeacher),
      })
  })
  $('#teachers-list-table').on('click', '.delete-button', function() {
     const rowToDelete = $(this).parent().parent()
     const teacherToDeleteID = rowToDelete.find("td").first().html()
     $.ajax({
       type: "POST",
       headers: {
           'Accept': 'application/json',
           'Content-Type': 'application/json'
       },
       success: function() {
         rowToDelete.remove();
       },
       url: "http://127.0.0.1:8083/admin/delete-teacher",
       data: teacherToDeleteID,
     })
  })
}

function drawTable(data) {
    for (var i = 0; i < data.length; ++i) {
        drawRow(data[i]);
    }
}

function drawRow(rowData) {
    var row = $("<tr />")
    // console.log($("#teachers-list-table:last"));
    // $("#teachers-list-table").append(row); //this will append tr element to table... keep its reference for a while since we will add cels into it<commit_msg>admin.js ajax hostname fix<commit_after>"use strict"

import $ from 'jquery'
import _ from 'lodash'
import './style.css'

const hostname = "http://ec2-54-186-163-30.us-west-2.compute.amazonaws.com/"

$(document).ready(main);

async function main() {
  const fetchOptions = { method: "GET"
                      //  , headers: { 'Accept': 'application/json'
                      //             , "Authorization": "Basic " +
                      //                btoa(username + ":" + password)
                      //  }
                       , mode: "cors"
                       }
  const errorHandler = error => {
    console.log(error)
  }
  const teachers = await fetch( "http://${hostname}:8083/admin/list-teachers"
                              , fetchOptions)
                              .then(response => response.json())
                              .catch(errorHandler)
  drawTable(teachers);
  $("#add-teacher-button").click(function() {
      var uname = $("#new-teacher-username").val();
      var pwd = $("#new-teacher-password").val();
      if (isInvalid(uname) || isInvalid(pwd)) {
        alert("Username or Password is invalid!");
        return;
      }
      var newTeacher = { username:uname
                       , password:<PASSWORD>
                       };
      $.ajax({
        type: "POST",
        headers: {
            'Accept': 'application/json',
            'Content-Type': 'application/json'
        },
        success: function(justAddedTeacher) {
          drawRow(justAddedTeacher)
        },
        url: "http://${hostname}:8083/admin/register-teacher",
        data: JSON.stringify(newTeacher),
      })
  })
  $('#teachers-list-table').on('click', '.delete-button', function() {
     const rowToDelete = $(this).parent().parent()
     const teacherToDeleteID = rowToDelete.find("td").first().html()
     $.ajax({
       type: "POST",
       headers: {
           'Accept': 'application/json',
           'Content-Type': 'application/json'
       },
       success: function() {
         rowToDelete.remove();
       },
       url: "http://${hostname}:8083/admin/delete-teacher",
       data: teacherToDeleteID,
     })
  })
}

function drawTable(data) {
    for (var i = 0; i < data.length; ++i) {
        drawRow(data[i]);
    }
}

function drawRow(rowData) {
    var row = $("<tr />")
    // console.log($("#teachers-list-table:last"));
    // $("#teachers-list-table").append(row); //this will append tr element to table... keep its reference for a while since we will add cels into it
{'fraction_non_alphanumeric': 0.16241345202769536, 'fraction_numerical': 0.012265084075173096, 'mean_word_length': 1.813578185865331, 'pattern_counts': {'":': 4, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '314471', 'n_tokens_mistral': 1508, 'n_tokens_neox': 1456, 'n_words': 282}