<commit_before>var exphbs = require('express-handlebars');
var moment = require('moment');

var activeRoute = '';
var blocks = [];

function HandlebarBoot(expressApp, viewsPath) {
    var Handlebars = exphbs.create({
        defaultLayout: 'main',
        layoutsDir: viewsPath + '/layouts/',
        partialsDir: viewsPath + '/partials/',
        helpers: {
            url: function(routeName, params) {
                return expressApp.locals.url(routeName, params);
            },
            activeRoute: function(routeName) {
                return routeName === activeRoute ? 'active' : '';
            },
            activeRoutes: function(routeNames) {
                // TODO
                return routeNames.split(',').indexOf(activeRoute) >= 0 ? 'active' : '';
            },
            isYes: function(value) {
                if(value=='Y'){
                    return 'checked'
                }else{
                    return '';
                }
            },
            isNo: function(value) {
                if(value=='N'){
                    return 'checked'
                }else{
                    return '';
                }
            },
            isAdmin: function(value) {
                if(value=='Admin'){
                    return 'checked'
                }else{
                    return '';
                }
            },
            isOperator: function(value) {
                if(value=='Operator'){
                    return 'checked'
                }else{
                    return '';
                }
            },
            isReader: function(value) {
                if(value=='Reader'){
                    return 'checked'
                }else{
                    return '';
                }
            },
            block: function(name) {
                var val = (blocks[name] || []).join('\n');

                // clear the block
                blocks[name] = [];
                return val;
            },
            formatTimeDate: function(date, displaySecond) {

                if(displaySecond === true)
                    return moment(date).format('YYYY-MM-DD HH:mm:ss');
                else
                    return moment(date).format('YYYY-MM-DD HH:mm');
            },
            pagination: function(currentPage, totalCount) {

                console.log('currentPage : '+currentPage);
                console.log('totalCount : '+totalCount);


                var str = '';
                var perPage = 15;
                var lastPage = Math.ceil((totalCount / perPage - 1) + 1);
                var maxDisplayPage = 10;

                console.log('lastPage : '+lastPage);

                if(currentPage > 1){
                    str += '<li><a href="?page='+(currentPage - 1) + '">&laquo;</a></li>';
                }
                str += '<li><a href="#">' + currentPage  + '</a></li>';
                var i = currentPage + 1;
                for(; i < lastPage ; i++)
                {
                    str += '<li><a href="?page='+i + '">'+i+'</a></li>';
                }
                console.log(' after loop i '+i);
                if(i <= lastPage){
                    str += '<li><a href="?page=';
                    str += i;
                    str += '">&raquo;</a></li>';
                }
                return str;
            },
            extend: function(name, context) {
                var block = blocks[name];
                if (!block) {
                    block = blocks[name] = [];
                }

                block.push(context.fn(this)); // for older versions of handlebars, use block.push(context(this));
            }
        }
    });

    // View engine setup
    expressApp.engine('handlebars', Handlebars.engine);
    expressApp.set('view engine', 'handlebars');
    expressApp.set('views', viewsPath);
}

module.exports = HandlebarBoot;
<commit_msg>fix pagination display.<commit_after>var exphbs = require('express-handlebars');
var moment = require('moment');

var activeRoute = '';
var blocks = [];

function HandlebarBoot(expressApp, viewsPath) {
    var Handlebars = exphbs.create({
        defaultLayout: 'main',
        layoutsDir: viewsPath + '/layouts/',
        partialsDir: viewsPath + '/partials/',
        helpers: {
            url: function(routeName, params) {
                return expressApp.locals.url(routeName, params);
            },
            activeRoute: function(routeName) {
                return routeName === activeRoute ? 'active' : '';
            },
            activeRoutes: function(routeNames) {
                // TODO
                return routeNames.split(',').indexOf(activeRoute) >= 0 ? 'active' : '';
            },
            isYes: function(value) {
                if(value=='Y'){
                    return 'checked'
                }else{
                    return '';
                }
            },
            isNo: function(value) {
                if(value=='N'){
                    return 'checked'
                }else{
                    return '';
                }
            },
            isAdmin: function(value) {
                if(value=='Admin'){
                    return 'checked'
                }else{
                    return '';
                }
            },
            isOperator: function(value) {
                if(value=='Operator'){
                    return 'checked'
                }else{
                    return '';
                }
            },
            isReader: function(value) {
                if(value=='Reader'){
                    return 'checked'
                }else{
                    return '';
                }
            },
            block: function(name) {
                var val = (blocks[name] || []).join('\n');

                // clear the block
                blocks[name] = [];
                return val;
            },
            formatTimeDate: function(date, displaySecond) {

                if(displaySecond === true)
                    return moment(date).format('YYYY-MM-DD HH:mm:ss');
                else
                    return moment(date).format('YYYY-MM-DD HH:mm');
            },
            pagination: function(currentPage, totalCount) {

                var str = '';
                var perPage = 15;
                var block = 5;

                var lastPage = Math.ceil((totalCount / perPage - 1) + 1);

                var totalPage = Math.ceil(totalCount / perPage);
                var totalBlock = Math.ceil(totalPage / block);
                var currentBlock = Math.ceil(currentPage / block);

                var startPage = (currentBlock * block) - (block - 1);

                if(startPage < 1) { startPage = 1;}

                var endPage = currentBlock * block;
                if(totalPage <= endPage){
                    endPage = totalPage;
                }

                for(var p = startPage; p<=endPage; p++){
                    if(currentPage == p) {
                        str += '<li class="paginate_button active"><a href="?page=' + p + '">' + p + '</a></li>';
                    }else {
                        str += '<li class="paginate_button"><a href="?page=' + p + '">' + p + '</a></li>';
                    }
                }

                return str;
            },
            extend: function(name, context) {
                var block = blocks[name];
                if (!block) {
                    block = blocks[name] = [];
                }

                block.push(context.fn(this)); // for older versions of handlebars, use block.push(context(this));
            }
        }
    });

    // View engine setup
    expressApp.engine('handlebars', Handlebars.engine);
    expressApp.set('view engine', 'handlebars');
    expressApp.set('views', viewsPath);
}

module.exports = HandlebarBoot;

{'fraction_non_alphanumeric': 0.1323940086316324, 'fraction_numerical': 0.0024117796395024117, 'mean_word_length': 1.1527322404371585, 'pattern_counts': {'":': 0, '<': 32, '<?xml version=': 0, '>': 30, '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': '6420684', 'n_tokens_mistral': 2079, 'n_tokens_neox': 1892, 'n_words': 403}