<commit_before>/**
 * Create self executing function to avoid global scope creation
 */
(function (angular, tinymce) {
    'use strict';
    angular.module('placesContent')
        .controller('ContentSectionCtrl', ['$scope', '$routeParams', 'DB', '$timeout', 'COLLECTIONS', 'Orders', 'OrdersItems', 'AppConfig', 'Messaging', 'EVENTS', 'PATHS', '$csv', 'Buildfire', 'Location', 'placesInfo', 'sectionInfo',
            function ($scope, $routeParams, DB, $timeout, COLLECTIONS, Orders, OrdersItems, AppConfig, Messaging, EVENTS, PATHS, $csv, Buildfire, Location, placesInfo, sectionInfo) {
                /**
                 * ContentSection._Sections is an instance of Sections db collection
                 * @type {DB}
                 *
                 * PlaceSettings will get the Place initialized settings
                 *
                 */
                var ContentSection = this
                    , tmrDelayForMedia = null
                    , _sectionData = {
                        data: {
                            mainImage: '',
                            secTitle: '',
                            secSummary: '',
                            itemListBGImage: '',
                            sortBy: '',
                            rankOfLastItem: ''
                        }
                    }
                    , selectImageOptions = {showIcons: false, multiSelection: false}
                    , PlaceInfo = new DB(COLLECTIONS.PlaceInfo)
                    , updating = false
                    , _placeInfoData = {
                        data: {
                            content: {
                                images: [],
                                descriptionHTML: '<p>&nbsp;<br></p>',
                                description: '<p>&nbsp;<br></p>',
                                sortBy: Orders.ordersMap.Manually,
                                rankOfLastItem: '',
                                sortByItems: OrdersItems.ordersMap.Newest,
                                showAllItems: 'true'
                            },
                            design: {
                                secListLayout: "sec-list-1-1",
                                mapLayout: "map-1",
                                itemListLayout: "item-list-1",
                                itemDetailsLayout: "item-details-1",
                                secListBGImage: ""
                            },
                            settings: {
                                defaultView: "list",
                                showDistanceIn: "miles"
                            }
                        }
                    };
                ContentSection._Sections = new DB(COLLECTIONS.Sections);
                var placeInfoData;
                if (placesInfo) {
                    placeInfoData = placesInfo;
                }
                else {
                    placeInfoData = _placeInfoData;
                }


                if (sectionInfo) {
                    ContentSection.section = sectionInfo;
                    updateMasterSection(ContentSection.section);
                }
                else {
                    ContentSection.section = _sectionData;
                    updateMasterSection(ContentSection.section);
                }
                function updateMasterSection(item) {
                    ContentSection.masterSection = angular.copy(item);
                }

                /**
                 * This resetItem will reset the ContentSection.section with ContentSection.masterSection
                 */
                function resetItem() {
                    ContentSection.section = angular.copy(ContentSection.masterSection);
                }


                /**
                 * isUnChanged to check whether there is change in controller section or not
                 * @param item
                 * @returns {*|boolean}
                 */
                function isUnChanged(item) {
                    return angular.equals(item, ContentSection.masterSection);
                }

                /**
                 * This updateItemData method will call the Builfire update method to update the ContentMedia.item
                 */
                function updateItemData(_section) {
                    ContentSection._Sections.update(_section.id, _section.data).then(function (data) {
                        updating = false;
                        updateMasterSection(_section);
                    }, function (err) {
                        updating = false;
                        resetItem();
                        console.error('Error-------', err);
                    });
                }

                /**
                 * This addNewItem method will call the Builfire insert method to insert ContentMedia.item
                 */

                function addNewItem(_section) {
                    ContentSection._Sections.insert(_section.data).then(function (item) {
                        ContentSection.section.id = item.id;
                        ContentSection.section.data.deepLinkUrl = Buildfire.deeplink.createLink({id: item.id});
                        updateMasterSection(item);
                        placeInfoData.data.content.rankOfLastItem = item.data.rank;
                        updating = false;
                        PlaceInfo.save(placeInfoData.data).then(function (data) {
                        }, function (err) {
                            resetItem();
                            console.error('Error while getting----------', err);
                        });
                    }, function (err) {
                        updating = false;
                        console.error('---------------Error while inserting data------------', err);
                    });
                }


                function insertAndUpdate(_item) {
                    updating = true;
                    if (_item.id) {
                        console.info('****************Section exist***********************');
                        ContentSection._Sections.update(_item.id, _item.data).then(function (data) {
                            updating = false;
                            updateMasterSection(_item);
                        }, function (err) {
                            resetItem();
                            updating = false;
                            console.log('Error while updating data---', err);
                        });
                    }
                    else {
                        console.info('****************Section inserted***********************');
                        _item.data.dateCreated = new Date();
                        ContentSection._Sections.insert(_item.data).then(function (item) {
                            ContentSection.section.id = item.id;
                            ContentSection.section.data.deepLinkUrl = Buildfire.deeplink.createLink({id: item.id});
                            updateMasterSection(item);
                            placeInfoData.data.content.rankOfLastItem = item.data.rank;
                            updating = false;
                            PlaceInfo.save(placeInfoData.data).then(function (data) {
                            }, function (err) {<commit_msg>Sorting Issue Fixed<commit_after>/**
 * Create self executing function to avoid global scope creation
 */
(function (angular, tinymce) {
    'use strict';
    angular.module('placesContent')
        .controller('ContentSectionCtrl', ['$scope', '$routeParams', 'DB', '$timeout', 'COLLECTIONS', 'Orders', 'OrdersItems', 'AppConfig', 'Messaging', 'EVENTS', 'PATHS', '$csv', 'Buildfire', 'Location', 'placesInfo', 'sectionInfo',
            function ($scope, $routeParams, DB, $timeout, COLLECTIONS, Orders, OrdersItems, AppConfig, Messaging, EVENTS, PATHS, $csv, Buildfire, Location, placesInfo, sectionInfo) {
                /**
                 * ContentSection._Sections is an instance of Sections db collection
                 * @type {DB}
                 *
                 * PlaceSettings will get the Place initialized settings
                 *
                 */
                var ContentSection = this
                    , tmrDelayForMedia = null
                    , _sectionData = {
                        data: {
                            mainImage: '',
                            secTitle: '',
                            secSummary: '',
                            itemListBGImage: '',
                            sortBy: '',
                            rankOfLastItem: ''
                        }
                    }
                    , selectImageOptions = {showIcons: false, multiSelection: false}
                    , PlaceInfo = new DB(COLLECTIONS.PlaceInfo)
                    , updating = false
                    , _placeInfoData = {
                        data: {
                            content: {
                                images: [],
                                descriptionHTML: '<p>&nbsp;<br></p>',
                                description: '<p>&nbsp;<br></p>',
                                sortBy: Orders.ordersMap.Manually,
                                rankOfLastItem: '',
                                sortByItems: OrdersItems.ordersMap.Newest,
                                showAllItems: 'true'
                            },
                            design: {
                                secListLayout: "sec-list-1-1",
                                mapLayout: "map-1",
                                itemListLayout: "item-list-1",
                                itemDetailsLayout: "item-details-1",
                                secListBGImage: ""
                            },
                            settings: {
                                defaultView: "list",
                                showDistanceIn: "miles"
                            }
                        }
                    };
                ContentSection._Sections = new DB(COLLECTIONS.Sections);
                var placeInfoData;
                if (placesInfo) {
                    placeInfoData = placesInfo;
                }
                else {
                    placeInfoData = _placeInfoData;
                }


                if (sectionInfo) {
                    ContentSection.section = sectionInfo;
                    updateMasterSection(ContentSection.section);
                }
                else {
                    ContentSection.section = _sectionData;
                    updateMasterSection(ContentSection.section);
                }
                function updateMasterSection(item) {
                    ContentSection.masterSection = angular.copy(item);
                }

                /**
                 * This resetItem will reset the ContentSection.section with ContentSection.masterSection
                 */
                function resetItem() {
                    ContentSection.section = angular.copy(ContentSection.masterSection);
                }


                /**
                 * isUnChanged to check whether there is change in controller section or not
                 * @param item
                 * @returns {*|boolean}
                 */
                function isUnChanged(item) {
                    return angular.equals(item, ContentSection.masterSection);
                }

                /**
                 * This updateItemData method will call the Builfire update method to update the ContentMedia.item
                 */
                function updateItemData(_section) {
                    ContentSection._Sections.update(_section.id, _section.data).then(function (data) {
                        updating = false;
                        updateMasterSection(_section);
                    }, function (err) {
                        updating = false;
                        resetItem();
                        console.error('Error-------', err);
                    });
                }

                /**
                 * This addNewItem method will call the Builfire insert method to insert ContentMedia.item
                 */

                function addNewItem(_section) {
                    ContentSection._Sections.insert(_section.data).then(function (item) {
                        ContentSection.section.id = item.id;
                        ContentSection.section.data.deepLinkUrl = Buildfire.deeplink.createLink({id: item.id});
                        updateMasterSection(item);
                        placeInfoData.data.content.rankOfLastItem = item.data.rank;
                        updating = false;
                        PlaceInfo.save(placeInfoData.data).then(function (data) {
                        }, function (err) {
                            resetItem();
                            console.error('Error while getting----------', err);
                        });
                    }, function (err) {
                        updating = false;
                        console.error('---------------Error while inserting data------------', err);
                    });
                }


                function insertAndUpdate(_item) {
                    updating = true;
                    if (_item.id) {
                        console.info('****************Section exist***********************');
                        ContentSection._Sections.update(_item.id, _item.data).then(function (data) {
                            updating = false;
                            updateMasterSection(_item);
                        }, function (err) {
                            resetItem();
                            updating = false;
                            console.log('Error while updating data---', err);
                        });
                    }
                    else {
                        console.info('****************Section inserted***********************');
                        _item.data.rank = (placeInfoData.data.content.rankOfLastItem || 0) + 10;
                        _item.data.dateCreated = new Date();
                        ContentSection._Sections.insert(_item.data).then(function (item) {
                            ContentSection.section.id = item.id;
                            ContentSection.section.data.deepLinkUrl = Buildfire.deeplink.createLink({id: item.id});
                            updateMasterSection(item);
                            placeInfoData.data.content.rankOfLastItem = item.data.rank;
                            updating = false;
                            PlaceInfo.save(placeInfoData.data).then(function (data) {
                            }, function (err) {
{'fraction_non_alphanumeric': 0.10069608704467121, 'fraction_numerical': 0.0008785564641481382, 'mean_word_length': 1.011417697431018, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '1084362', 'n_tokens_mistral': 3183, 'n_tokens_neox': 2949, 'n_words': 598}