<commit_before>'use strict';
(function (angular) {
    angular
        .module('peoplePluginContent')
        .controller('ContentPeopleCtrl', ['$scope', 'Location', '$modal', 'Buildfire', 'TAG_NAMES', 'STATUS_CODE', '$routeParams', 'RankOfLastItem',
            function ($scope, Location, $modal, Buildfire, TAG_NAMES, STATUS_CODE, $routeParams, RankOfLastItem) {

                var _rankOfLastItem = RankOfLastItem.getRank();
                console.log('-----------------------_rankOfLastItem-----------------------------', _rankOfLastItem);
                var ContentPeople = this;
                ContentPeople.isUpdating = false;
                ContentPeople.linksSortableOptions = {
                    handle: '> .cursor-grab'
                };
                ContentPeople.item = {
                    data: {
                        topImage: '',
                        iconImage: '',
                        fName: '',
                        lName: '',
                        position: '',
                        deepLinkUrl: '',
                        dateCreated: +new Date(),
                        socialLinks: [],
                        bodyContent: '',
                        rank: _rankOfLastItem
                    }
                };
                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 () {
                    _rankOfLastItem = _rankOfLastItem + 10;
                    ContentPeople.item.data.dateCreated = new Date();
                    ContentPeople.item.data.rank = _rankOfLastItem;

                    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');
                        RankOfLastItem.setRank(_rankOfLastItem);
                        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');
                                Buildfire.datastore.get(TAG_NAMES.PEOPLE_INFO, function (err, result) {
                                    if (err) {
                                        console.error('There was a problem saving your data');
                                    } else {
                                        result.data.content.rankOfLastItem = _rankOfLastItem;
                                        Buildfire.datastore.save(result.data, TAG_NAMES.PEOPLE_INFO, function (err) {
                                            if (err)
                                                console.error('There was a problem saving last item rank');
                                        });
                                    }
                                });
                                break;
                            case STATUS_CODE.UPDATED:
                                console.log('Data updated Successfully');
                                break;
                        }
                    }
                });

                ContentPeople.openAddLinkPopup = function () {
                  var options = {showIcons: false};
                  var callback = function (error, result) {
                    if (error) {
                      console.error('Error:', error);
                    } else {
                      ContentPeople.item.data.socialLinks.push(result);
                      console.log(ContentPeople.item.data.socialLinks);
                      $scope.$digest();
                    }
                  };
                  if($routeParams.itemId){
                      Buildfire.actionItems.showDialog (null, options , callback);
                  }
                    else{
                      Buildfire.actionItems.showDialog (null , options , callback);
                  }
                };

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

                var options = {showIcons: false, multiSelection: false};
                var callback = function (error, result) {<commit_msg>Implemented adding more links while editing an item<commit_after>'use strict';
(function (angular) {
    angular
        .module('peoplePluginContent')
        .controller('ContentPeopleCtrl', ['$scope', 'Location', '$modal', 'Buildfire', 'TAG_NAMES', 'STATUS_CODE', '$routeParams', 'RankOfLastItem',
            function ($scope, Location, $modal, Buildfire, TAG_NAMES, STATUS_CODE, $routeParams, RankOfLastItem) {

                var _rankOfLastItem = RankOfLastItem.getRank();
                console.log('-----------------------_rankOfLastItem-----------------------------', _rankOfLastItem);
                var ContentPeople = this;
                ContentPeople.isUpdating = false;
                ContentPeople.linksSortableOptions = {
                    handle: '> .cursor-grab'
                };
                ContentPeople.item = {
                    data: {
                        topImage: '',
                        iconImage: '',
                        fName: '',
                        lName: '',
                        position: '',
                        deepLinkUrl: '',
                        dateCreated: +new Date(),
                        socialLinks: [],
                        bodyContent: '',
                        rank: _rankOfLastItem
                    }
                };
                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 () {
                    _rankOfLastItem = _rankOfLastItem + 10;
                    ContentPeople.item.data.dateCreated = new Date();
                    ContentPeople.item.data.rank = _rankOfLastItem;

                    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');
                        RankOfLastItem.setRank(_rankOfLastItem);
                        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');
                                Buildfire.datastore.get(TAG_NAMES.PEOPLE_INFO, function (err, result) {
                                    if (err) {
                                        console.error('There was a problem saving your data');
                                    } else {
                                        result.data.content.rankOfLastItem = _rankOfLastItem;
                                        Buildfire.datastore.save(result.data, TAG_NAMES.PEOPLE_INFO, function (err) {
                                            if (err)
                                                console.error('There was a problem saving last item rank');
                                        });
                                    }
                                });
                                break;
                            case STATUS_CODE.UPDATED:
                                console.log('Data updated Successfully');
                                break;
                        }
                    }
                });

                ContentPeople.openAddLinkPopup = function () {
                  var options = {showIcons: false};
                  var callback = function (error, result) {
                    if (error) {
                      console.error('Error:', error);
                    } else {
                      if (!ContentPeople.item.data.socialLinks)
                        ContentPeople.item.data.socialLinks = [];
                      ContentPeople.item.data.socialLinks.push(result);
                      $scope.$digest();
                    }
                  };
                  Buildfire.actionItems.showDialog (null , options , callback);
                };

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

                var options = {showIcons: false, multiSelection: false};
                var callback = function (error, result) {
{'fraction_non_alphanumeric': 0.09258977480219112, 'fraction_numerical': 0.0004564820450395618, 'mean_word_length': 1.0099388379204892, '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': 22, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4263333', 'n_tokens_mistral': 2939, 'n_tokens_neox': 2676, 'n_words': 541}