<commit_before>(function(exports) {
  // Placeholder as we move to data-binding as a basis for re-rendering.
  function renderMenu() {
    var sections = [];
    // Retrieve latest section data.
    for (var id in allData) {
      var doc = allData[id];
      if (doc.type !== "section") continue;
      sections.push(doc);
    }
    sections = _.sortBy(sections, function(d) { return d.order; });
    var $list = $("ol.sectionlist").empty();
    _.each(sections, function(o, index) {
      if (o.type != 'section' || o.pending) return '';
      $list.append('<li><a href="' + (++index) + '/">' + escapeLaTeX(o.title || "No title") + '</a>');
    });
  }

  function renderMath(target) {
    if (typeof MathJax === 'undefined') return;
    MathJax.Hub.Queue(["Typeset", MathJax.Hub, target]);
    citations();
    refreshNames(target);
  }

  function trim(s) {
    return s.replace(/^\s\s*/, "").replace(/\s\s*$/, "");
  }

  function refreshNames(target) {
    var names = [];
    $('span.by-id', target).each(function() {
      var $el = $(this);
      names.push(function(cb) {
        fetchName($el.text(), $el, cb);
      });
    });
    async.parallel(names, function(err, result) {
      // Sort alphabetically by last name...
      result.sort(function(a, b) { return a.split(" ").pop() < b.split(" ").pop() ? -1 : 1; });
      d3.select("h3.editors").selectAll(".by-id").text(function(d, i) { return result[i]; });
    });
  }

  function log() {
    if (typeof console !== 'undefined' && console.log)
      console.log(arguments);
  }

  function render(doc, template, $target) {
    doc = processLaTeX(doc);
    doc = _.defaults({perms: perms}, doc);
    if (doc.type === "problem") {
      doc.by = doc.by || null;
      doc.by_id = (!doc.by_id || doc.by_id == "custom") ? null : doc.by_id;
      doc.sec_num = sec_num;
      if (doc.tag) {
        doc.tag = {
          'problem': 'Problem',
          'prob': 'Problem',
          'rhequivalence': 'RH Equivalence',
          'rhequiv': 'RH Equivalence',
          'conjecture': 'Conjecture'
        }[doc.tag] || 'Problem';
      } else {
        doc.tag = 'Problem';
      }
    }
    $target.append(compileTemplate(template)(doc));
    renderMath($target[0]);
  }

  function approveReject(model, type, el, isAdd) {
    var id = _.last(model.attributes.path);  // parent id or id of original document
    // id of document(new or edit) to approve/reject
    var url = '/api/queue/' + model.id + '/' + type;
    if (isAdd) {
      model.attributes.order = $('.editable[data-id="' + id + '"] .children').eq(0).find("li").size() + 1;
      model.attributes.list_pos = model.attributes.order;
      model.attributes.number = "";
    }
    $.ajax({
      url: url,
      type: 'POST',
      data: JSON.stringify(model.attributes),
      dataType: 'json',
      contentType: 'application/json',
      success: function(data) {
        model.attributes._rev = data._rev;
        model.collection.remove(model);
        if (type === 'approve') {
          if (!isAdd)
            model.attributes._id = id;    // replace the id of edit document with the original document id
          var $target = !isAdd
            ? $('.editable[data-id="' + id + '"] .render').eq(0).empty()
            : $('<li/>').attr("data-id", model.id).attr("class", model.attributes.type).appendTo($('.editable[data-id="' + id + '"] .children').eq(0));
          delete model.attributes.pending;
          allData[isAdd ? model.id : id] = model.attributes;
          // Reset numbers
          if (model.attributes.type === "section") {
            renderMenu();
          }
          if (model.attributes.type === "problem") {
            var data = [];
            $target.parents(".sortable").eq(0).children('li').each(function() {
              data.push($(this).data('id'));
            });<commit_msg>Fixes #13. Removes the extra id in the path section of the document<commit_after>(function(exports) {
  // Placeholder as we move to data-binding as a basis for re-rendering.
  function renderMenu() {
    var sections = [];
    // Retrieve latest section data.
    for (var id in allData) {
      var doc = allData[id];
      if (doc.type !== "section") continue;
      sections.push(doc);
    }
    sections = _.sortBy(sections, function(d) { return d.order; });
    var $list = $("ol.sectionlist").empty();
    _.each(sections, function(o, index) {
      if (o.type != 'section' || o.pending) return '';
      $list.append('<li><a href="' + (++index) + '/">' + escapeLaTeX(o.title || "No title") + '</a>');
    });
  }

  function renderMath(target) {
    if (typeof MathJax === 'undefined') return;
    MathJax.Hub.Queue(["Typeset", MathJax.Hub, target]);
    citations();
    refreshNames(target);
  }

  function trim(s) {
    return s.replace(/^\s\s*/, "").replace(/\s\s*$/, "");
  }

  function refreshNames(target) {
    var names = [];
    $('span.by-id', target).each(function() {
      var $el = $(this);
      names.push(function(cb) {
        fetchName($el.text(), $el, cb);
      });
    });
    async.parallel(names, function(err, result) {
      // Sort alphabetically by last name...
      result.sort(function(a, b) { return a.split(" ").pop() < b.split(" ").pop() ? -1 : 1; });
      d3.select("h3.editors").selectAll(".by-id").text(function(d, i) { return result[i]; });
    });
  }

  function log() {
    if (typeof console !== 'undefined' && console.log)
      console.log(arguments);
  }

  function render(doc, template, $target) {
    doc = processLaTeX(doc);
    doc = _.defaults({perms: perms}, doc);
    if (doc.type === "problem") {
      doc.by = doc.by || null;
      doc.by_id = (!doc.by_id || doc.by_id == "custom") ? null : doc.by_id;
      doc.sec_num = sec_num;
      if (doc.tag) {
        doc.tag = {
          'problem': 'Problem',
          'prob': 'Problem',
          'rhequivalence': 'RH Equivalence',
          'rhequiv': 'RH Equivalence',
          'conjecture': 'Conjecture'
        }[doc.tag] || 'Problem';
      } else {
        doc.tag = 'Problem';
      }
    }
    $target.append(compileTemplate(template)(doc));
    renderMath($target[0]);
  }

  function approveReject(model, type, el, isAdd) {
    var id = _.last(model.attributes.path);  // parent id or id of original document
    // id of document(new or edit) to approve/reject
    var url = '/api/queue/' + model.id + '/' + type;
    if (isAdd) {
      model.attributes.order = $('.editable[data-id="' + id + '"] .children').eq(0).find("li").size() + 1;
      model.attributes.list_pos = model.attributes.order;
      model.attributes.number = "";
    }
    $.ajax({
      url: url,
      type: 'POST',
      data: JSON.stringify(model.attributes),
      dataType: 'json',
      contentType: 'application/json',
      success: function(data) {
        model.attributes._rev = data._rev;
        model.collection.remove(model);
        if (type === 'approve') {
          if (!isAdd)
            model.attributes._id = id;    // replace the id of edit document with the original document id
          var $target = !isAdd
            ? $('.editable[data-id="' + id + '"] .render').eq(0).empty()
            : $('<li/>').attr("data-id", model.id).attr("class", model.attributes.type).appendTo($('.editable[data-id="' + id + '"] .children').eq(0));
          delete model.attributes.pending;
          allData[isAdd ? model.id : id] = model.attributes;
          if (!isAdd)
            allData[id].path.pop();  // remove the extra id from the path
          // Reset numbers
          if (model.attributes.type === "section") {
            renderMenu();
          }
          if (model.attributes.type === "problem") {
            var data = [];
            $target.parents(".sortable").eq(0).children('li').each(function() {
              data.push($(this).data('id'));
            });
{'fraction_non_alphanumeric': 0.1900995151824445, 'fraction_numerical': 0.0028068384792038787, 'mean_word_length': 2.358611825192802, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, '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': '81092', 'n_tokens_mistral': 2547, 'n_tokens_neox': 2483, 'n_words': 546}