<commit_before>"use strict";

var express  = require('express');
var async    = require('async');
var moment   = require('moment-timezone');
var router   = express.Router();
var debug    = require('debug')('OSMBC:routes:layout');

var util          = require('../util.js');
var config        = require('../config.js');
var version = require('../version.js');

var articleModule = require('../model/article.js');
var blogModule    = require('../model/blog.js');

var htmlRoot = config.getValue("htmlroot");
var bootstrap = config.getValue("bootstrap");


function calculateUnreadMessages(list,user) {
  var result = 0;
  for (let k=0;k<list.length;k++) {
    let a = list[k];
    if (a.commentRead && a.commentRead[user]>= a.commentList.length-1) continue;
    result +=1;
  }
  return result;
}


function prepareRenderLayout(req,res,next) {
  debug('prepareRenderLayout');




  // Variables for rendering purposes

  // ListOfOrphanBlog is used to show all orphanedBlog to assign an article to
  var style = "style.css";
  if (req.query.tempstyleOff == 'true') req.session.tempstyle=true;
  if (req.query.tempstyleOff == 'false') delete req.session.tempstyle;
  if (!req.session.tempstyle && config.getValue("style")) style = config.getValue("style");



  var languages = [];
  if (config.getLanguages()) languages = config.getLanguages();

 
  var userMentions = 0;
  var mainLangMentions = 0;
  var secondLangMentions = 0;
  var usedLanguages = {};
  usedLanguages[req.user.language]=true;

  // Used for display changes

  // Params is used for indicating Edit

  async.auto({
    
    listOfOrphanBlog:
    function (callback) {
      articleModule.getListOfOrphanBlog(function(err,result) {
        callback(err,result);
      });
    },
    listOfOpenBlog:
    function (callback) {
      blogModule.find({status:"open"},function(err,result) {
        if (err) return callback(err);
        var list = [];
        for (var i=0;i<result.length;i++) {
          list.push(result[i]);
        }
        async.each(list,function(item,cb){
          item.calculateDerived(req.user,function(err){
            if (err) cb(err);
            userMentions += calculateUnreadMessages(item._userMention,req.user.OSMUser);
            mainLangMentions += calculateUnreadMessages(item._mainLangMention,req.user.OSMUser);
            secondLangMentions += calculateUnreadMessages(item._secondLangMention,req.user.OSMUser);
            for (let k in item._usedLanguages) usedLanguages[k]=true;
            cb();
          });
        },function(err){
          callback(err,list);
        });
      });
    },
    listOfEditBlog:
    function (callback) {
      blogModule.find({status:"edit"},function(err,result) {
        if (err) return callback(err);
        var list = [];
        for (var i=0;i<result.length;i++) {
          if (!(result[i]["reviewComment"+req.user.getMainLang()])) {
            list.push(result[i]);
          }
        }
        async.each(list,function(item,cb){
          item.calculateDerived(req.user,function(err){
            if (err) cb(err);
            userMentions += calculateUnreadMessages(item._userMention,req.user.OSMUser);
            mainLangMentions += calculateUnreadMessages(item._mainLangMention,req.user.OSMUser);
            secondLangMentions += calculateUnreadMessages(item._secondLangMention,req.user.OSMUser);
            for (let k in item._usedLanguages) usedLanguages[k]=true;
            cb();

          });
        },function(err){callback(err,list);});
      });
    },
    listOfReviewBlog:
    function (callback) {
      blogModule.find({status:"edit"},function(err,result) {
        if (err) return callback(err);
        var list = [];
        for (var i=0;i<result.length;i++) {
          if ((result[i]["reviewComment"+req.user.getMainLang()]) &&
              !(result[i]["close"+req.user.getMainLang()])) {
            list.push(result[i]);
          }
        }
        async.each(list,function(item,cb){
          item.calculateDerived(req.user,function (err){
            if (err) cb(err);
            userMentions += calculateUnreadMessages(item._userMention,req.user.OSMUser);
            mainLangMentions += calculateUnreadMessages(item._mainLangMention,req.user.OSMUser);
            secondLangMentions += calculateUnreadMessages(item._secondLangMention,req.user.OSMUser);
            for (let k in item._usedLanguages) usedLanguages[k]=true;
            cb();
          });
        },function(err){callback(err,list);});<commit_msg>Quick Fix, missing languages in tool.<commit_after>"use strict";

var express  = require('express');
var async    = require('async');
var moment   = require('moment-timezone');
var router   = express.Router();
var debug    = require('debug')('OSMBC:routes:layout');

var util          = require('../util.js');
var config        = require('../config.js');
var version = require('../version.js');

var articleModule = require('../model/article.js');
var blogModule    = require('../model/blog.js');

var htmlRoot = config.getValue("htmlroot");
var bootstrap = config.getValue("bootstrap");


function calculateUnreadMessages(list,user) {
  var result = 0;
  for (let k=0;k<list.length;k++) {
    let a = list[k];
    if (a.commentRead && a.commentRead[user]>= a.commentList.length-1) continue;
    result +=1;
  }
  return result;
}


function prepareRenderLayout(req,res,next) {
  debug('prepareRenderLayout');




  // Variables for rendering purposes

  // ListOfOrphanBlog is used to show all orphanedBlog to assign an article to
  var style = "style.css";
  if (req.query.tempstyleOff == 'true') req.session.tempstyle=true;
  if (req.query.tempstyleOff == 'false') delete req.session.tempstyle;
  if (!req.session.tempstyle && config.getValue("style")) style = config.getValue("style");



  var languages = [];
  if (config.getLanguages()) languages = config.getLanguages();

 
  var userMentions = 0;
  var mainLangMentions = 0;
  var secondLangMentions = 0;
  var usedLanguages = {};
  usedLanguages[req.user.language]=true;

  // Used for display changes

  // Params is used for indicating Edit

  async.auto({
    
    listOfOrphanBlog:
    function (callback) {
      articleModule.getListOfOrphanBlog(function(err,result) {
        callback(err,result);
      });
    },
    listOfOpenBlog:
    function (callback) {
      blogModule.find({status:"open"},function(err,result) {
        if (err) return callback(err);
        var list = [];
        for (var i=0;i<result.length;i++) {
          list.push(result[i]);
        }
        async.each(list,function(item,cb){
          item.calculateDerived(req.user,function(err){
            if (err) cb(err);
            userMentions += calculateUnreadMessages(item._userMention,req.user.OSMUser);
            mainLangMentions += calculateUnreadMessages(item._mainLangMention,req.user.OSMUser);
            secondLangMentions += calculateUnreadMessages(item._secondLangMention,req.user.OSMUser);
            for (let k in item._usedLanguages) usedLanguages[k]=true;
            cb();
          });
        },function(err){
          callback(err,list);
        });
      });
    },
    listOfEditBlog:
    function (callback) {
      blogModule.find({status:"edit"},function(err,result) {
        if (err) return callback(err);
        var list = [];
        for (var i=0;i<result.length;i++) {
          if (!(result[i]["reviewComment"+req.user.getMainLang()])) {
            list.push(result[i]);
          }
        }
        async.each(result,function(item,cb){
          item.calculateDerived(req.user,function(err){
            if (err) cb(err);
            userMentions += calculateUnreadMessages(item._userMention,req.user.OSMUser);
            mainLangMentions += calculateUnreadMessages(item._mainLangMention,req.user.OSMUser);
            secondLangMentions += calculateUnreadMessages(item._secondLangMention,req.user.OSMUser);
            for (let k in item._usedLanguages) usedLanguages[k]=true;
            cb();

          });
        },function(err){callback(err,list);});
      });
    },
    listOfReviewBlog:
    function (callback) {
      blogModule.find({status:"edit"},function(err,result) {
        if (err) return callback(err);
        var list = [];
        for (var i=0;i<result.length;i++) {
          if ((result[i]["reviewComment"+req.user.getMainLang()]) &&
              !(result[i]["close"+req.user.getMainLang()])) {
            list.push(result[i]);
          }
        }
       callback(err,list);
{'fraction_non_alphanumeric': 0.1489111241907004, 'fraction_numerical': 0.002354326074161271, 'mean_word_length': 2.882998171846435, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 5, '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': '758462', 'n_tokens_mistral': 2618, 'n_tokens_neox': 2552, 'n_words': 453}