<commit_before>﻿/*
//------------------------------------------------------------------------------
// <copyright company="LeanKit Inc.">
//     Copyright (c) LeanKit Inc.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------
*/
App.module("Main", function (Main, App, Backbone, Marionette, $, _) {


    Main.controllers.LaneStateMappingController = Marionette.Controller.extend({
        initialize: function (options) {
            this.owner = options.owner;

            //this.customStateCollection = new Backbone.Collection();
            //this.listenTo(this.customStateCollection, "remove", this.customStateRemoved, this);
            //App.commands.setHandler('customStateAdded', this.customStateAdded, this);
            this.model = options.model;
            if (_.isObject(options.board)) {
                this.model.set("LaneHtml", options.board.LaneHtml(), { silent: true });
            }
            this.lanesAndStates = options.lanesAndStates;
            this.currentStates = new Backbone.Collection();
            this.listenTo(this.currentStates, "remove", this.stateRemoved, this);

            this.workflowStates = new Backbone.Collection();
            
            this.configureViews();
            App.reqres.setHandler('getStatesForPicker', this.getStatesForPicker, this);
            
            // subscribe to tab:activated events
            this.listenTo(Main, 'tab:activated', this.tabActivated, this);
        },

        getStatesForPicker:function () {
            return this.statesForPicker;
        },
        
        configureViews: function () {
            this.view = new Main.views.LaneStateMappingView({ controller: this, model:this.model });
            
            this.viewFactory = new App.ViewFactory(this, "laneStateMap");

            this.viewFactory.register("StateButtons", function (c) {
                var states = App.request("getStates");
                c.statesForPicker = _.pluck(states, "Name");
                c.statesForPicker.unshift("");
                c.stateCollection = new Backbone.Collection(states);
                var view = new Main.views.ButtonCollectionView({ id: "StateButtons", collection: c.stateCollection });
                
                return view;
            });

            this.viewFactory.register("States", function(c) {
                var view = new Main.views.StateCollectionView({ id: "States", collection: c.currentStates });
                return view;
            });
            
            this.viewFactory.register("CustomStates", function(c) {
                var view = new Main.views.CustomStateCollectionView({ id: "CustomStates", collection: c.customStateCollection });
                return view;
            });

            this.viewFactory.register("WorkflowStates", function(c) {
                var view = new Main.views.StateCollectionView({ id: "WorkflowStates", collection: c.workflowStates });
                return view;
            });
            
        },
        
        onPrepViews:function () {
            this.viewFactory.each(function(view) {
                if (_.isString(view.id)) {
                    var id = "#" + view.id;
                    var $el = this.view.$(id);
                    if (_.isObject($el)) {
                        view.$el = $el;
                        view.bindUIElements();
                        view.delegateEvents();
                        //view.triggerMethod("prep:Views");
                    }
                }
            }, this);
        },

        laneSelected: function (laneId) {
            this.currentLane = laneId;
            var stateArr = this.model.LaneToStatesMap()[laneId];
            if (_.isUndefined(stateArr)) {
                stateArr = [];
            }
            var states = [];
            _.each(stateArr, function(state) {
                states.push({ State: state });
            }, this);
            
            this.currentStates.reset(states);

        },
        
        stateAdded: function (state, addToWorkFlow) {
            if (addToWorkFlow) {
                this.workflowStates.add(new Backbone.Model({ State: state }));
            } else {
                this.currentStates.add(new Backbone.Model({ State: state }));
                this.owner.model.addStateToLane(this.currentLane, state);
                this.view.markUnassignedStatesAsWarning(this.model.unassignedStates);
            }
        },
        
        stateRemoved: function (model) {
            var state = model.get("State");
            this.owner.model.removeStateFromLane(this.currentLane, state);
            this.view.markUnassignedStatesAsWarning(this.model.unassignedStates);
        },

        useWorkflow: function () {
            if (this.workflowStates.length === 0) return;
            var workflowState = "";
            this.workflowStates.each(function(model) {
                workflowState += model.get("State") + ">";
            }, this);
            workflowState = workflowState.substring(0, workflowState.length-1);
            this.stateAdded(workflowState);
            this.workflowStates.reset();
        },
        
        resetWorkflowStates: function () {
            this.workflowStates.reset();
        },
        
        addCustomState: function (state) {
            this.customStateCollection.add(new Backbone.Model({ State: state }));
        },
        
        
        tabActivated:function (tabName) {
            if (tabName !== "Lanes and States") return;
            // if the required states differ from queryStates, update required states and re-validate
            if(this.requiredStates !== this.model.QueryStates()) {
                this.requiredStates = this.model.QueryStates();
                // validate
                this.model.isValid();
                this.view.markUnassignedStatesAsWarning(this.model.unassignedStates);
            }
        },
        
        onClose: function () {
            this.stopListening();
        }



    });
<commit_msg>Whitespace cleanup<commit_after>﻿/*
//------------------------------------------------------------------------------
// <copyright company="LeanKit Inc.">
//     Copyright (c) LeanKit Inc.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------
*/
App.module("Main", function (Main, App, Backbone, Marionette, $, _) {


    Main.controllers.LaneStateMappingController = Marionette.Controller.extend({
        initialize: function (options) {
            this.owner = options.owner;

            //this.customStateCollection = new Backbone.Collection();
            //this.listenTo(this.customStateCollection, "remove", this.customStateRemoved, this);
            //App.commands.setHandler('customStateAdded', this.customStateAdded, this);
            this.model = options.model;
            if (_.isObject(options.board)) {
                this.model.set("LaneHtml", options.board.LaneHtml(), { silent: true });
            }
            this.lanesAndStates = options.lanesAndStates;
            this.currentStates = new Backbone.Collection();
            this.listenTo(this.currentStates, "remove", this.stateRemoved, this);

            this.workflowStates = new Backbone.Collection();
            
            this.configureViews();
            App.reqres.setHandler('getStatesForPicker', this.getStatesForPicker, this);
            
            // subscribe to tab:activated events
            this.listenTo(Main, 'tab:activated', this.tabActivated, this);
        },

        getStatesForPicker:function () {
            return this.statesForPicker;
        },
        
        configureViews: function () {
            this.view = new Main.views.LaneStateMappingView({ controller: this, model:this.model });
            
            this.viewFactory = new App.ViewFactory(this, "laneStateMap");

            this.viewFactory.register("StateButtons", function (c) {
                var states = App.request("getStates");
                c.statesForPicker = _.pluck(states, "Name");
                c.statesForPicker.unshift("");
                c.stateCollection = new Backbone.Collection(states);
                var view = new Main.views.ButtonCollectionView({ id: "StateButtons", collection: c.stateCollection });
                
                return view;
            });

            this.viewFactory.register("States", function(c) {
                var view = new Main.views.StateCollectionView({ id: "States", collection: c.currentStates });
                return view;
            });
            
            this.viewFactory.register("CustomStates", function(c) {
                var view = new Main.views.CustomStateCollectionView({ id: "CustomStates", collection: c.customStateCollection });
                return view;
            });

            this.viewFactory.register("WorkflowStates", function(c) {
                var view = new Main.views.StateCollectionView({ id: "WorkflowStates", collection: c.workflowStates });
                return view;
            });
            
        },
        
        onPrepViews:function () {
            this.viewFactory.each(function(view) {
                if (_.isString(view.id)) {
                    var id = "#" + view.id;
                    var $el = this.view.$(id);
                    if (_.isObject($el)) {
                        view.$el = $el;
                        view.bindUIElements();
                        view.delegateEvents();
                        //view.triggerMethod("prep:Views");
                    }
                }
            }, this);
        },

        laneSelected: function (laneId) {
            this.currentLane = laneId;
            var stateArr = this.model.LaneToStatesMap()[laneId];
            if (_.isUndefined(stateArr)) {
                stateArr = [];
            }
            var states = [];
            _.each(stateArr, function(state) {
                states.push({ State: state });
            }, this);
            
            this.currentStates.reset(states);

        },
        
        stateAdded: function (state, addToWorkFlow) {
            if (addToWorkFlow) {
                this.workflowStates.add(new Backbone.Model({ State: state }));
            } else {
                this.currentStates.add(new Backbone.Model({ State: state }));
                this.owner.model.addStateToLane(this.currentLane, state);
                this.view.markUnassignedStatesAsWarning(this.model.unassignedStates);
            }
        },
        
        stateRemoved: function (model) {
            var state = model.get("State");
            this.owner.model.removeStateFromLane(this.currentLane, state);
            this.view.markUnassignedStatesAsWarning(this.model.unassignedStates);
        },

        useWorkflow: function () {
            if (this.workflowStates.length === 0) return;
            var workflowState = "";
            this.workflowStates.each(function(model) {
                workflowState += model.get("State") + ">";
            }, this);
            workflowState = workflowState.substring(0, workflowState.length-1);
            this.stateAdded(workflowState);
            this.workflowStates.reset();
        },
        
        resetWorkflowStates: function () {
            this.workflowStates.reset();
        },
        
        addCustomState: function (state) {
            this.customStateCollection.add(new Backbone.Model({ State: state }));
        },
                
        tabActivated:function (tabName) {
            if (tabName !== "Lanes and States") return;
            // if the required states differ from queryStates, update required states and re-validate
            if(this.requiredStates !== this.model.QueryStates()) {
                this.requiredStates = this.model.QueryStates();
                // validate
                this.model.isValid();
                this.view.markUnassignedStatesAsWarning(this.model.unassignedStates);
            }
        },
        
        onClose: function () {
            this.stopListening();
        }

    });

{'fraction_non_alphanumeric': 0.14035087719298245, 'fraction_numerical': 0.0004918839153959665, 'mean_word_length': 1.569833579102591, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '3018075', 'n_tokens_mistral': 3056, 'n_tokens_neox': 2955, 'n_words': 527}