<commit_before>"use strict";
var view = require("./blogList.html");
var Menu = require("./menu");
var datastore = require("../scripts/datastore");
var modelBlogList = require("../model/blogList");
var modelBlog = require("../model/blog");
var Component = require("./component");
var LoadError = require("./loadError");
import route from "./route";

class ctlBlogList extends Component {
  constructor(containerID) {
    super(containerID, "Grackle");
    this.global();
  }
  getBlogList(callback) {
    if (this.blogList) {
      return callback();
    }

    datastore("GET","BlogList",null,function (err,res) {
      if (err) {
        return callback(err);
      }

      this.blogList = new modelBlogList.BlogList();
      this.blogList.loadObject(res);
      this.blogList.sort();
      callback();
    }.bind(this));
  }
  render(callback) {
    this.getBlogList(function (err) {
      if (err) {
        let c = new LoadError(this.container, "", err);
        return callback(err, c);
      }

      let menu = new Menu("", false, false);
      menu.render(function (err, menuView) {
        let template = Handlebars.compile(view);
        var blogListHTML = template(this.blogList);
        callback(null, menuView + blogListHTML);
      }.bind(this));
    }.bind(this));
  }
  addBlog() {
    var blogInfo = new modelBlog.BlogInfo(0, this.blogList.getNewTitle(), this.blogList.getDOMID());
    this.blogList.add(blogInfo);
    this.show();
    datastore("PUT", "Blog", blogInfo.exportObject(), function (err,res) {
      if (err) {
        $("#placeForAlert").addClass("alert alert-warning");
        $("#placeForAlert").html(err);
        return;
      }

      blogInfo._id = res._id;
    });
  }
  editBlog(domID) {
    var blogInfo = this.blogList.getBlogInfo(domID);
    route("/blog/" + blogInfo.title);
  }<commit_msg>sort blog list after adding a blog<commit_after>"use strict";
var view = require("./blogList.html");
var Menu = require("./menu");
var datastore = require("../scripts/datastore");
var modelBlogList = require("../model/blogList");
var modelBlog = require("../model/blog");
var Component = require("./component");
var LoadError = require("./loadError");
import route from "./route";

class ctlBlogList extends Component {
  constructor(containerID) {
    super(containerID, "Grackle");
    this.global();
  }
  getBlogList(callback) {
    if (this.blogList) {
      return callback();
    }

    datastore("GET","BlogList",null,function (err,res) {
      if (err) {
        return callback(err);
      }

      this.blogList = new modelBlogList.BlogList();
      this.blogList.loadObject(res);
      this.blogList.sort();
      callback();
    }.bind(this));
  }
  render(callback) {
    this.getBlogList(function (err) {
      if (err) {
        let c = new LoadError(this.container, "", err);
        return callback(err, c);
      }

      let menu = new Menu("", false, false);
      menu.render(function (err, menuView) {
        let template = Handlebars.compile(view);
        var blogListHTML = template(this.blogList);
        callback(null, menuView + blogListHTML);
      }.bind(this));
    }.bind(this));
  }
  addBlog() {
    var blogInfo = new modelBlog.BlogInfo(0, this.blogList.getNewTitle(), this.blogList.getDOMID());
    this.blogList.add(blogInfo);
    this.blogList.sort();
    this.show();
    datastore("PUT", "Blog", blogInfo.exportObject(), function (err,res) {
      if (err) {
        $("#placeForAlert").addClass("alert alert-warning");
        $("#placeForAlert").html(err);
        return;
      }

      blogInfo._id = res._id;
    });
  }
  editBlog(domID) {
    var blogInfo = this.blogList.getBlogInfo(domID);
    route("/blog/" + blogInfo.title);
  }
{'fraction_non_alphanumeric': 0.16751815004033344, 'fraction_numerical': 0.0005377789728421619, 'mean_word_length': 2.982869379014989, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1322704', 'n_tokens_mistral': 1198, 'n_tokens_neox': 1158, 'n_words': 235}