<commit_before>/**
 * ProjectController
 *
 * @module      ::  Controller
 * @description ::  Contains logic for handling requests.
 */
var jQuery = require('jquery');

module.exports = {
    /**
     * Project add action.
     *
     * @param   {Request}   req Request object
     * @param   {Response}  res Response object
     */
    add: function(req, res) {
        if (!req.isAjax) {
            res.send('Only AJAX request allowed', 403);
        }

        // Fetch all users
        User
            .find()
            .sort('lastName ASC')
            .done(function(error, users) {
                if (error) {
                    res.send(error, 500);
                } else {
                    res.view({
                        layout: "layout_ajax",
                        users: users
                    });
                }
            });
    },

    /**
     * Project edit action.
     *
     * @param   {Request}   req Request object
     * @param   {Response}  res Response object
     */
    edit: function(req, res) {
        if (!req.isAjax) {
            res.send('Only AJAX request allowed', 403);
        }

        var projectId = parseInt(req.param('id'), 10);

        // Specify template data to use
        var data = {
            layout: "layout_ajax",
            project: false,
            users: false
        };

        // Fetch project data.
        Project
            .findOne(projectId)
            .done(function(error, project) {
                if (error) {
                    res.send(error, 500);
                } else if (!project) {
                    res.send("Project not found.", 404);
                } else {
                    data.project = project;

                    makeView();
                }
            });

        // Fetch all users
        User
            .find()
            .sort('lastName ASC')
            .done(function(error, users) {
                if (error) {
                    res.send(error, 500);
                } else {
                    data.users = users;

                    makeView();
                }
            });

        /**
         * Function makes actual view if all necessary data is fetched
         * from database for template.
         */
        function makeView() {
            var ok = true;

            jQuery.each(data, function(key, data) {
                if (data === false) {
                    ok = false;
                }
            });

            if (ok) {
                res.view(data);
            }
        }
    },

    /**
     * Project milestones action
     *
     * @param   {Request}   req Request object
     * @param   {Response}  res Response object
     */
    milestones: function(req, res) {
        if (!req.isAjax) {
            res.send('Only AJAX request allowed', 403);
        }

        var projectId = parseInt(req.param('id'), 10);

        var data = {
            layout: "layout_ajax",
            milestones: false,
            project: false,
            progressMilestones: 0,
            progressStories: 0,
            cntMilestonesDone: 0,
            cntMilestonesTotal: 0,
            cntStoriesDone: 0,
            cntStoriesTotal: 0
        };

        // Fetch project data.
        Project
            .findOne(projectId)
            .done(function(error, project) {
                if (error) {
                    res.send(error, 500);
                } else if (!project) {
                    res.send("Project not found.", 404);
                } else {
                    data.project = project;

                    makeView();
                }
            });

        // Fetch milestone data
        Milestone
            .find()
            .where({
                projectId: projectId
            })
            .sort('deadline ASC')
            .sort('title ASC')
            .done(function(error, milestones) {
                if (error) {
                    res.send(error, 500);
                } else {
                    data.milestones = milestones;
                    data.cntMilestonesTotal = milestones.length;

                    fetchStories();
                }
            });

        /**
         * Function to fetch attached milestone stories.
         */
        function fetchStories() {
            // We have no milestones, so make view
            if (data.milestones.length === 0) {
                makeView();
            } else {
                // Iterate milestones
                jQuery.each(data.milestones, function(key, /** sails.model.milestone */milestone) {
                    // Initialize milestone stories property
                    milestone.stories = false;

                    // Find all user stories which are attached to current milestone
                    Story
                        .find()
                        .where({
                            milestoneId: milestone.id
                        })
                        .sort('title ASC')
                        .done(function(error, stories) {
                            // Add stories to milestone data
                            milestone.stories = stories;
                            milestone.doneStories = _.reduce(stories, function(memo, story) { return (story.isDone) ? memo + 1 : memo; }, 0);

                            data.cntStoriesTotal = data.cntStoriesTotal + milestone.stories.length;<commit_msg>Code reformat<commit_after>/**
 * ProjectController
 *
 * @module      ::  Controller
 * @description ::  Contains logic for handling requests.
 */
var jQuery = require('jquery');

module.exports = {
    /**
     * Project add action.
     *
     * @param   {Request}   req Request object
     * @param   {Response}  res Response object
     */
    add: function(req, res) {
        if (!req.isAjax) {
            res.send('Only AJAX request allowed', 403);
        }

        // Fetch all users
        User
            .find()
            .sort('lastName ASC')
            .done(function(error, users) {
                if (error) {
                    res.send(error, 500);
                } else {
                    res.view({
                        layout: "layout_ajax",
                        users: users
                    });
                }
            });
    },

    /**
     * Project edit action.
     *
     * @param   {Request}   req Request object
     * @param   {Response}  res Response object
     */
    edit: function(req, res) {
        if (!req.isAjax) {
            res.send('Only AJAX request allowed', 403);
        }

        var projectId = parseInt(req.param('id'), 10);

        // Specify template data to use
        var data = {
            layout: "layout_ajax",
            project: false,
            users: false
        };

        // Fetch project data.
        Project
            .findOne(projectId)
            .done(function(error, project) {
                if (error) {
                    res.send(error, 500);
                } else if (!project) {
                    res.send("Project not found.", 404);
                } else {
                    data.project = project;

                    makeView();
                }
            });

        // Fetch all users
        User
            .find()
            .sort('lastName ASC')
            .done(function(error, users) {
                if (error) {
                    res.send(error, 500);
                } else {
                    data.users = users;

                    makeView();
                }
            });

        /**
         * Function makes actual view if all necessary data is fetched
         * from database for template.
         */
        function makeView() {
            var ok = true;

            jQuery.each(data, function(key, data) {
                if (data === false) {
                    ok = false;
                }
            });

            if (ok) {
                res.view(data);
            }
        }
    },

    /**
     * Project milestones action
     *
     * @param   {Request}   req Request object
     * @param   {Response}  res Response object
     */
    milestones: function(req, res) {
        if (!req.isAjax) {
            res.send('Only AJAX request allowed', 403);
        }

        var projectId = parseInt(req.param('id'), 10);

        var data = {
            layout: "layout_ajax",
            milestones: false,
            project: false,
            progressMilestones: 0,
            progressStories: 0,
            cntMilestonesDone: 0,
            cntMilestonesTotal: 0,
            cntStoriesDone: 0,
            cntStoriesTotal: 0
        };

        // Fetch project data.
        Project
            .findOne(projectId)
            .done(function(error, project) {
                if (error) {
                    res.send(error, 500);
                } else if (!project) {
                    res.send("Project not found.", 404);
                } else {
                    data.project = project;

                    makeView();
                }
            });

        // Fetch milestone data
        Milestone
            .find()
            .where({
                projectId: projectId
            })
            .sort('deadline ASC')
            .sort('title ASC')
            .done(function(error, milestones) {
                if (error) {
                    res.send(error, 500);
                } else {
                    data.milestones = milestones;
                    data.cntMilestonesTotal = milestones.length;

                    fetchStories();
                }
            });

        /**
         * Function to fetch attached milestone stories.
         */
        function fetchStories() {
            // We have no milestones, so make view
            if (data.milestones.length === 0) {
                makeView();
            } else {
                // Iterate milestones
                jQuery.each(data.milestones, function(key, /** sails.model.milestone */milestone) {
                    // Initialize milestone stories property
                    milestone.stories = false;

                    // Find all user stories which are attached to current milestone
                    Story
                        .find()
                        .where({
                            milestoneId: milestone.id
                        })
                        .sort('title ASC')
                        .done(function(error, stories) {
                            // Add stories to milestone data
                            milestone.stories = stories;
                            milestone.doneStories = _.reduce(stories, function (memo, story) {
                                return (story.isDone) ? memo + 1 : memo;
                            }, 0);

                            data.cntStoriesTotal = data.cntStoriesTotal + milestone.stories.length;
{'fraction_non_alphanumeric': 0.10086956521739131, 'fraction_numerical': 0.007871853546910754, 'mean_word_length': 1.0147519822976212, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '653341', 'n_tokens_mistral': 2868, 'n_tokens_neox': 2569, 'n_words': 659}