<commit_before>
(function () {

    var directive = function () {
        return {
            restrict: "EA",
            bindToController: {
                stepIndex: '@'
            },
            require:['thinkbigDefineFeedGeneralInfo','^thinkbigStepper'],
            scope: {},
            controllerAs: 'vm',
            templateUrl: 'js/define-feed/feed-details/define-feed-general-info.html',
            controller: "DefineFeedGeneralInfoController",
            link: function ($scope, element, attrs, controllers) {
                var thisController = controllers[0];
                var stepperController = controllers[1];
                thisController.stepperController = stepperController;
                thisController.totalSteps = stepperController.totalSteps;
            }

        };
    }

    var controller =  function($scope,$log, $http,$mdToast,RestUrlService, FeedService, CategoriesService) {

        var self = this;

        /**
         * The angular form
         * @type {{}}
         */
        this.defineFeedGeneralForm = {};
        this.templates = [];
        this.model = FeedService.createFeedModel;
        this.isValid = false;
        this.stepNumber = parseInt(this.stepIndex)+1
        this.stepperController = null;

        // Contains existing system feed names for the current category
        this.existingFeedNames = {};

        this.categorySearchText = '';
        this.category;
        self.categorySelectedItemChange = selectedItemChange;
        self.categorySearchTextChanged = searchTextChange;
        self.categoriesService = CategoriesService;

        function searchTextChange(text) {
         //   $log.info('Text changed to ' + text);
        }
        function selectedItemChange(item) {
            if(item != null && item != undefined) {
                self.model.category.name = item.name;
                self.model.category.id = item.id;
                self.model.category.systemName = item.systemName;
                setSecurityGroups(item.name);
                validateUniqueFeedName();
            }
            else {
                self.model.category.name = null;
                self.model.category.id = null;
                self.model.category.systemName = null;
                self.existingFeedNames = {};
                self.defineFeedGeneralForm['feedName'].$setValidity('notUnique', true);
            }
        }

        function existingFeedNameKey(categoryId, feedName) {
            return categoryId + "-" + feedName;
        }

        populateExistingFeedNames();

        /**
         * updates the {@code existingFeedNames} object with the latest feed names from the server
         * @returns {promise}
         */
        function populateExistingFeedNames() {
            return $http.get(RestUrlService.GET_FEEDS_URL).then(function (response) {
                self.existingFeedNames = {};
                angular.forEach(response.data, function (feed) {
                    self.existingFeedNames[existingFeedNameKey(feed.categoryId, feed.systemFeedName)] = feed.systemFeedName;
                });
            });
        }

        function validateUniqueFeedName() {

            function _validate() {
                //validate to ensure the name is unique in this category
                if (self.model && self.model.category && self.existingFeedNames[existingFeedNameKey(self.model.category.id, self.model.systemFeedName)]) {
                    self.defineFeedGeneralForm['feedName'].$setValidity('notUnique', false);
                }
                else {
                    self.defineFeedGeneralForm['feedName'].$setValidity('notUnique', true);
                }
            }

            if (_.isEmpty(self.existingFeedNames)) {
                populateExistingFeedNames().then(function () {
                    _validate();
                });
            }<commit_msg>ensure form is there for validation<commit_after>
(function () {

    var directive = function () {
        return {
            restrict: "EA",
            bindToController: {
                stepIndex: '@'
            },
            require:['thinkbigDefineFeedGeneralInfo','^thinkbigStepper'],
            scope: {},
            controllerAs: 'vm',
            templateUrl: 'js/define-feed/feed-details/define-feed-general-info.html',
            controller: "DefineFeedGeneralInfoController",
            link: function ($scope, element, attrs, controllers) {
                var thisController = controllers[0];
                var stepperController = controllers[1];
                thisController.stepperController = stepperController;
                thisController.totalSteps = stepperController.totalSteps;
            }

        };
    }

    var controller =  function($scope,$log, $http,$mdToast,RestUrlService, FeedService, CategoriesService) {

        var self = this;

        /**
         * The angular form
         * @type {{}}
         */
        this.defineFeedGeneralForm = {};
        this.templates = [];
        this.model = FeedService.createFeedModel;
        this.isValid = false;
        this.stepNumber = parseInt(this.stepIndex)+1
        this.stepperController = null;

        // Contains existing system feed names for the current category
        this.existingFeedNames = {};

        this.categorySearchText = '';
        this.category;
        self.categorySelectedItemChange = selectedItemChange;
        self.categorySearchTextChanged = searchTextChange;
        self.categoriesService = CategoriesService;

        function searchTextChange(text) {
         //   $log.info('Text changed to ' + text);
        }
        function selectedItemChange(item) {
            if(item != null && item != undefined) {
                self.model.category.name = item.name;
                self.model.category.id = item.id;
                self.model.category.systemName = item.systemName;
                setSecurityGroups(item.name);
                validateUniqueFeedName();
            }
            else {
                self.model.category.name = null;
                self.model.category.id = null;
                self.model.category.systemName = null;
                self.existingFeedNames = {};
                if (self.defineFeedGeneralForm && self.defineFeedGeneralForm['feedName']) {
                    self.defineFeedGeneralForm['feedName'].$setValidity('notUnique', true);
                }
            }
        }

        function existingFeedNameKey(categoryId, feedName) {
            return categoryId + "-" + feedName;
        }

        populateExistingFeedNames();

        /**
         * updates the {@code existingFeedNames} object with the latest feed names from the server
         * @returns {promise}
         */
        function populateExistingFeedNames() {
            return $http.get(RestUrlService.GET_FEEDS_URL).then(function (response) {
                self.existingFeedNames = {};
                angular.forEach(response.data, function (feed) {
                    self.existingFeedNames[existingFeedNameKey(feed.categoryId, feed.systemFeedName)] = feed.systemFeedName;
                });
            });
        }

        function validateUniqueFeedName() {

            function _validate() {
                //validate to ensure the name is unique in this category
                if (self.model && self.model.category && self.existingFeedNames[existingFeedNameKey(self.model.category.id, self.model.systemFeedName)]) {
                    if (self.defineFeedGeneralForm && self.defineFeedGeneralForm['feedName']) {
                        self.defineFeedGeneralForm['feedName'].$setValidity('notUnique', false);
                    }
                }
                else {
                    if (self.defineFeedGeneralForm && self.defineFeedGeneralForm['feedName']) {
                        self.defineFeedGeneralForm['feedName'].$setValidity('notUnique', true);
                    }
                }
            }

            if (_.isEmpty(self.existingFeedNames)) {
                populateExistingFeedNames().then(function () {
                    _validate();
                });
            }
{'fraction_non_alphanumeric': 0.10241994622341725, 'fraction_numerical': 0.0007333170373991689, 'mean_word_length': 1.772018970189702, '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': '2660073', 'n_tokens_mistral': 2037, 'n_tokens_neox': 1933, 'n_words': 348}