<commit_before>'use strict';
(function (angular) {
    angular
        .module('peoplePluginContent')
        .controller('ContentPeopleCtrl', ['$scope', 'Location', '$modal', 'Buildfire', 'TAG_NAMES', 'STATUS_CODE', '$routeParams',
            function ($scope, Location, $modal, Buildfire, TAG_NAMES, STATUS_CODE, $routeParams) {
                var ContentPeople = this;
                ContentPeople.isUpdating = false;
                ContentPeople.linksSortableOptions = {
                    handle: '> .cursor-grab'
                };
                ContentPeople.item = {
                    data: {
                        topImage: '',
                        iconImage: '',
                        fName: '',
                        lName: '',
                        position: '',
                        deepLinkUrl: '',
                        dateCreated: +new Date(),
                        socailLinks: [],
                        bodyContent: ''
                    }
                };
                updateMasterItem(ContentPeople.item);
                function updateMasterItem(item) {
                    ContentPeople.masterItem = angular.copy(item);
                }

                function resetItem() {
                    ContentPeople.item = angular.copy(ContentPeople.masterItem);
                }

                function isUnchanged(item) {
                    return angular.equals(item, ContentPeople.masterItem);
                }

                /*On click button done it redirects to home*/
                ContentPeople.done = function () {
                    Location.goToHome();
                };

                /*On click button delete it removes current item from datastore*/
                ContentPeople.deleteItem = function () {
                    var item = ContentPeople.item;
                    if (item.id) {
                        Buildfire.datastore.delete(item.id, TAG_NAMES.PEOPLE, function (err, result) {
                            if (err)
                                return;
                            Location.goToHome();
                        });
                    }
                };
                ContentPeople.getItem = function (itemId) {
                    Buildfire.datastore.getById(itemId, TAG_NAMES.PEOPLE, function (err, data) {
                        if (err)
                            console.error('There was a problem saving your data');
                        ContentPeople.item = data;
                        updateMasterItem(ContentPeople.item);
                        $scope.$digest();
                    });
                };
                if ($routeParams.itemId) {
                    ContentPeople.getItem($routeParams.itemId);
                }
                ContentPeople.addNewItem = function () {
                    ContentPeople.item.data.dateCreated = new Date();
                    Buildfire.datastore.insert(ContentPeople.item.data, TAG_NAMES.PEOPLE, false, function (err, data) {
                        ContentPeople.isUpdating = false;
                        if (err)
                            return console.error('There was a problem saving your data');
                        ContentPeople.getItem(data.id);
                    });
                };
                ContentPeople.updateItemData = function () {
                    if (ContentPeople.item.id) {
                        Buildfire.datastore.update(ContentPeople.item.id, ContentPeople.item.data, TAG_NAMES.PEOPLE, function (err) {
                            ContentPeople.isUpdating = false;
                            if (err)
                                console.error('There was a problem saving your data');
                        })
                    }
                    ContentPeople.isUpdating = false;
                };
                Buildfire.datastore.onUpdate(function (event) {
                    if (event && event.status) {
                        switch (event.status) {
                            case STATUS_CODE.INSERTED:
                                console.log('Data inserted Successfully');
                                break;
                            case STATUS_CODE.UPDATED:
                                console.log('Data updated Successfully');
                                break;
                        }
                    }
                });

                ContentPeople.openAddLinkPopup = function () {
                    var modalInstance = $modal
                        .open({
                            templateUrl: 'people/modals/add-item-link.html',
                            controller: 'AddItemLinkPopupCtrl',
                            controllerAs: 'AddItemLinkPopup',
                            size: 'sm'
                        });
                    modalInstance.result.then(function (_link) {
                        if (_link) {
                            ContentPeople.item.data.socailLinks.push(JSON.parse(angular.toJson(_link)));
                        }
                    }, function (err) {
                        if (err) {
                            console.error('Error:', err)
                        }
                    });
                };

                ContentPeople.removeLink = function (_index) {
                    ContentPeople.item.data.socailLinks.splice(_index, 1);
                };

                var options = {showIcons: false, multiSelection: false};
                var callback = function (error, result) {
                    if (error) {
                        console.error('Error:', error);
                    } else {
                        ContentPeople.item.data.topImage = result.selectedFiles && result.selectedFiles[0] || null;
                        $scope.$digest();
                    }
                };

                ContentPeople.selectTopImage = function () {
                    Buildfire.imageLib.showDialog(options, callback);
                };

                ContentPeople.removeTopImage = function () {
                    ContentPeople.item.data.topImage = null;
                };


                var tmrDelayForPeoples = null;
                var updateItemsWithDelay = function (newObj) {
                    if (tmrDelayForPeoples) clearTimeout(tmrDelayForPeoples);
                    if (ContentPeople.item && ContentPeople.isUpdating && !isUnchanged(ContentPeople.item)) {
                        ContentPeople.isUpdating = true;
                        if (ContentPeople.item.id) {
                            tmrDelayForPeoples = setTimeout(function () {
                                ContentPeople.updateItemData();
                            }, 500);
                        }
                        else {
                            tmrDelayForPeoples = setTimeout(function () {
                                ContentPeople.addNewItem();
                            }, 500);
                        }
                    }

                };

                $scope.$watch(function () {
                    return ContentPeople.item;
                }, updateItemsWithDelay, true);
            }]);<commit_msg>#15: remove issue of isUpdating<commit_after>'use strict';
(function (angular) {
    angular
        .module('peoplePluginContent')
        .controller('ContentPeopleCtrl', ['$scope', 'Location', '$modal', 'Buildfire', 'TAG_NAMES', 'STATUS_CODE', '$routeParams',
            function ($scope, Location, $modal, Buildfire, TAG_NAMES, STATUS_CODE, $routeParams) {
                var ContentPeople = this;
                ContentPeople.isUpdating = false;
                ContentPeople.linksSortableOptions = {
                    handle: '> .cursor-grab'
                };
                ContentPeople.item = {
                    data: {
                        topImage: '',
                        iconImage: '',
                        fName: '',
                        lName: '',
                        position: '',
                        deepLinkUrl: '',
                        dateCreated: +new Date(),
                        socailLinks: [],
                        bodyContent: ''
                    }
                };
                updateMasterItem(ContentPeople.item);
                function updateMasterItem(item) {
                    ContentPeople.masterItem = angular.copy(item);
                }

                function resetItem() {
                    ContentPeople.item = angular.copy(ContentPeople.masterItem);
                }

                function isUnchanged(item) {
                    return angular.equals(item, ContentPeople.masterItem);
                }

                /*On click button done it redirects to home*/
                ContentPeople.done = function () {
                    Location.goToHome();
                };

                /*On click button delete it removes current item from datastore*/
                ContentPeople.deleteItem = function () {
                    var item = ContentPeople.item;
                    if (item.id) {
                        Buildfire.datastore.delete(item.id, TAG_NAMES.PEOPLE, function (err, result) {
                            if (err)
                                return;
                            Location.goToHome();
                        });
                    }
                };
                ContentPeople.getItem = function (itemId) {
                    Buildfire.datastore.getById(itemId, TAG_NAMES.PEOPLE, function (err, data) {
                        if (err)
                            console.error('There was a problem saving your data');
                        ContentPeople.item = data;
                        updateMasterItem(ContentPeople.item);
                        $scope.$digest();
                    });
                };
                if ($routeParams.itemId) {
                    ContentPeople.getItem($routeParams.itemId);
                }
                ContentPeople.addNewItem = function () {
                    ContentPeople.item.data.dateCreated = new Date();
                    Buildfire.datastore.insert(ContentPeople.item.data, TAG_NAMES.PEOPLE, false, function (err, data) {
                        ContentPeople.isUpdating = false;
                        if (err)
                            return console.error('There was a problem saving your data');
                        ContentPeople.getItem(data.id);
                    });
                };
                ContentPeople.updateItemData = function () {
                    Buildfire.datastore.update(ContentPeople.item.id, ContentPeople.item.data, TAG_NAMES.PEOPLE, function (err) {
                        ContentPeople.isUpdating = false;
                        if (err)
                            console.error('There was a problem saving your data');
                    })
                };
                Buildfire.datastore.onUpdate(function (event) {
                    if (event && event.status) {
                        switch (event.status) {
                            case STATUS_CODE.INSERTED:
                                console.log('Data inserted Successfully');
                                break;
                            case STATUS_CODE.UPDATED:
                                console.log('Data updated Successfully');
                                break;
                        }
                    }
                });

                ContentPeople.openAddLinkPopup = function () {
                    var modalInstance = $modal
                        .open({
                            templateUrl: 'people/modals/add-item-link.html',
                            controller: 'AddItemLinkPopupCtrl',
                            controllerAs: 'AddItemLinkPopup',
                            size: 'sm'
                        });
                    modalInstance.result.then(function (_link) {
                        if (_link) {
                            ContentPeople.item.data.socailLinks.push(JSON.parse(angular.toJson(_link)));
                        }
                    }, function (err) {
                        if (err) {
                            console.error('Error:', err)
                        }
                    });
                };

                ContentPeople.removeLink = function (_index) {
                    ContentPeople.item.data.socailLinks.splice(_index, 1);
                };

                var options = {showIcons: false, multiSelection: false};
                var callback = function (error, result) {
                    if (error) {
                        console.error('Error:', error);
                    } else {
                        ContentPeople.item.data.topImage = result.selectedFiles && result.selectedFiles[0] || null;
                        $scope.$digest();
                    }
                };

                ContentPeople.selectTopImage = function () {
                    Buildfire.imageLib.showDialog(options, callback);
                };

                ContentPeople.removeTopImage = function () {
                    ContentPeople.item.data.topImage = null;
                };


                var tmrDelayForPeoples = null;
                var updateItemsWithDelay = function (newObj) {
                    if (tmrDelayForPeoples) {
                        clearTimeout(tmrDelayForPeoples);
                        ContentPeople.isUpdating = false;
                    }
                    if (ContentPeople.item && !ContentPeople.isUpdating && !isUnchanged(ContentPeople.item)) {
                        ContentPeople.isUpdating = true;
                        if (ContentPeople.item.id) {
                            tmrDelayForPeoples = setTimeout(function () {
                                ContentPeople.updateItemData();
                            }, 500);
                        }
                        else {
                            tmrDelayForPeoples = setTimeout(function () {
                                ContentPeople.addNewItem();
                            }, 500);
                        }
                    }

                };

                $scope.$watch(function () {
                    return ContentPeople.item;
                }, updateItemsWithDelay, true);
            }]);
{'fraction_non_alphanumeric': 0.0879983331018197, 'fraction_numerical': 0.0012501736352271149, 'mean_word_length': 0.9863429438543247, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2142105', 'n_tokens_mistral': 3255, 'n_tokens_neox': 2956, 'n_words': 550}