<commit_before>(function () {
    'use strict';

    function ContentEditController($rootScope, $scope, $routeParams, $q, $window,
        appState, contentResource, entityResource, navigationService, notificationsService,
        serverValidationManager, contentEditingHelper, localizationService, formHelper, umbRequestHelper,
        editorState, $http, eventsService, overlayService, $location) {

        var evts = [];
        var infiniteMode = $scope.infiniteModel && $scope.infiniteModel.infiniteMode;
        var watchingCulture = false;

        //setup scope vars
        $scope.defaultButton = null;
        $scope.subButtons = [];

        $scope.page = {};
        $scope.page.loading = false;
        $scope.page.menu = {};
        $scope.page.menu.currentNode = null;
        $scope.page.menu.currentSection = appState.getSectionState("currentSection");
        $scope.page.listViewPath = null;
        $scope.page.isNew = $scope.isNew ? true : false;

        if (infiniteMode) {
            $scope.page.allowInfinitePublishAndClose = $scope.infiniteModel.allowPublishAndClose;
            $scope.page.allowInfiniteSaveAndClose = $scope.infiniteModel.allowSaveAndClose;
        }

        $scope.page.buttonGroupState = "init";
        $scope.page.hideActionsMenu = infiniteMode ? true : false;
        $scope.page.hideChangeVariant = false;
        $scope.allowOpen = true;
        $scope.app = null;

        //initializes any watches
        function startWatches(content) {

            //watch for changes to isNew & the content.id, set the page.isNew accordingly and load the breadcrumb if we can
            $scope.$watchGroup(['isNew', 'content.id'], function (newVal, oldVal) {
                
                var contentId = newVal[1];
                $scope.page.isNew = Object.toBoolean(newVal[0]);

                //We fetch all ancestors of the node to generate the footer breadcrumb navigation
                if (!$scope.page.isNew && contentId && content.parentId && content.parentId !== -1) {
                    loadBreadcrumb();
                    if (!watchingCulture) {
                        $scope.$watch('culture',
                            function (value, oldValue) {
                                if (value !== oldValue) {
                                    loadBreadcrumb();
                                }
                            });
                    }
                }
            });

        }

        //this initializes the editor with the data which will be called more than once if the data is re-loaded
        function init() {

            var content = $scope.content;
            if (content.id && content.isChildOfListView && content.trashed === false) {
                $scope.page.listViewPath = "/content/content/edit/" + content.parentId
                    + "?list=" + $routeParams.list
                    + "&page=" + $routeParams.page 
                    + "&filter=" + $routeParams.filter
                    + "&orderBy=" + $routeParams.orderBy
                    + "&orderDirection=" + $routeParams.orderDirection;
            }

            // we need to check wether an app is present in the current data, if not we will present the default app.
            var isAppPresent = false;

            // on first init, we dont have any apps. but if we are re-initializing, we do, but ...
            if ($scope.app) {

                // lets check if it still exists as part of our apps array. (if not we have made a change to our docType, even just a re-save of the docType it will turn into new Apps.)
                _.forEach(content.apps, function (app) {
                    if (app === $scope.app) {
                        isAppPresent = true;
                    }
                });

                // if we did reload our DocType, but still have the same app we will try to find it by the alias.
                if (isAppPresent === false) {
                    _.forEach(content.apps, function (app) {
                        if (app.alias === $scope.app.alias) {
                            isAppPresent = true;
                            app.active = true;
                            $scope.appChanged(app);
                        }
                    });
                }

            }

            // if we still dont have a app, lets show the first one:
            if (isAppPresent === false && content.apps.length) {
                content.apps[0].active = true;
                $scope.appChanged(content.apps[0]);
            }
            // otherwise make sure the save options are up to date with the current content state
            else {
                createButtons($scope.content);
            }

            editorState.set(content);

            bindEvents();

            resetVariantFlags();
        }

        function loadBreadcrumb() {
            entityResource.getAncestors($scope.content.id, "document", $scope.culture)
                .then(function (anc) {
                    $scope.ancestors = anc;
                });
        }

        /**
         * This will reset isDirty flags if save is true.
         * When working with multiple variants, this will set the save/publish flags of each one to false.
         * When working with a single variant, this will set the publish flag to false and the save flag to true.
         */
        function resetVariantFlags() {
            if ($scope.content.variants.length > 1) {
                for (var i = 0; i < $scope.content.variants.length; i++) {
                    var v = $scope.content.variants[i];
                    if (v.save) {
                        v.isDirty = false;
                    }
                    v.save = false;
                    v.publish = false;
                }
            }
            else {
                if ($scope.content.variants[0].save) {
                    $scope.content.variants[0].isDirty = false;
                }
                $scope.content.variants[0].save = true;
                $scope.content.variants[0].publish = false;
            }
        }

        /** Returns true if the content item varies by culture */
        function isContentCultureVariant() {
            return $scope.content.variants.length > 1;
        }

        function reload() {
            $scope.page.loading = true;
            loadContent().then(function () {
                $scope.page.loading = false;
            });
        }

        function bindEvents() {
            //bindEvents can be called more than once and we don't want to have multiple bound events
            for (var e in evts) {
                eventsService.unsubscribe(evts[e]);
            }

            evts.push(eventsService.on("editors.documentType.saved", function (name, args) {
                // if this content item uses the updated doc type we need to reload the content item
                if (args && args.documentType && $scope.content.documentType.id === args.documentType.id) {
                    reload();
                }
            }));

        }

        /**
         *  This does the content loading and initializes everything, called on first load
         */
        function loadContent() {

            //we are editing so get the content item from the server
            return $scope.getMethod()($scope.contentId)
                .then(function (data) {

                    $scope.content = data;

                    init();

                    syncTreeNode($scope.content, $scope.content.path, true);
<commit_msg>Reload after rollback<commit_after>(function () {
    'use strict';

    function ContentEditController($rootScope, $scope, $routeParams, $q, $window,
        appState, contentResource, entityResource, navigationService, notificationsService,
        serverValidationManager, contentEditingHelper, localizationService, formHelper, umbRequestHelper,
        editorState, $http, eventsService, overlayService, $location) {

        var evts = [];
        var infiniteMode = $scope.infiniteModel && $scope.infiniteModel.infiniteMode;
        var watchingCulture = false;

        //setup scope vars
        $scope.defaultButton = null;
        $scope.subButtons = [];

        $scope.page = {};
        $scope.page.loading = false;
        $scope.page.menu = {};
        $scope.page.menu.currentNode = null;
        $scope.page.menu.currentSection = appState.getSectionState("currentSection");
        $scope.page.listViewPath = null;
        $scope.page.isNew = $scope.isNew ? true : false;

        if (infiniteMode) {
            $scope.page.allowInfinitePublishAndClose = $scope.infiniteModel.allowPublishAndClose;
            $scope.page.allowInfiniteSaveAndClose = $scope.infiniteModel.allowSaveAndClose;
        }

        $scope.page.buttonGroupState = "init";
        $scope.page.hideActionsMenu = infiniteMode ? true : false;
        $scope.page.hideChangeVariant = false;
        $scope.allowOpen = true;
        $scope.app = null;

        //initializes any watches
        function startWatches(content) {

            //watch for changes to isNew & the content.id, set the page.isNew accordingly and load the breadcrumb if we can
            $scope.$watchGroup(['isNew', 'content.id'], function (newVal, oldVal) {
                
                var contentId = newVal[1];
                $scope.page.isNew = Object.toBoolean(newVal[0]);

                //We fetch all ancestors of the node to generate the footer breadcrumb navigation
                if (!$scope.page.isNew && contentId && content.parentId && content.parentId !== -1) {
                    loadBreadcrumb();
                    if (!watchingCulture) {
                        $scope.$watch('culture',
                            function (value, oldValue) {
                                if (value !== oldValue) {
                                    loadBreadcrumb();
                                }
                            });
                    }
                }
            });

        }

        //this initializes the editor with the data which will be called more than once if the data is re-loaded
        function init() {

            var content = $scope.content;
            if (content.id && content.isChildOfListView && content.trashed === false) {
                $scope.page.listViewPath = "/content/content/edit/" + content.parentId
                    + "?list=" + $routeParams.list
                    + "&page=" + $routeParams.page 
                    + "&filter=" + $routeParams.filter
                    + "&orderBy=" + $routeParams.orderBy
                    + "&orderDirection=" + $routeParams.orderDirection;
            }

            // we need to check wether an app is present in the current data, if not we will present the default app.
            var isAppPresent = false;

            // on first init, we dont have any apps. but if we are re-initializing, we do, but ...
            if ($scope.app) {

                // lets check if it still exists as part of our apps array. (if not we have made a change to our docType, even just a re-save of the docType it will turn into new Apps.)
                _.forEach(content.apps, function (app) {
                    if (app === $scope.app) {
                        isAppPresent = true;
                    }
                });

                // if we did reload our DocType, but still have the same app we will try to find it by the alias.
                if (isAppPresent === false) {
                    _.forEach(content.apps, function (app) {
                        if (app.alias === $scope.app.alias) {
                            isAppPresent = true;
                            app.active = true;
                            $scope.appChanged(app);
                        }
                    });
                }

            }

            // if we still dont have a app, lets show the first one:
            if (isAppPresent === false && content.apps.length) {
                content.apps[0].active = true;
                $scope.appChanged(content.apps[0]);
            }
            // otherwise make sure the save options are up to date with the current content state
            else {
                createButtons($scope.content);
            }

            editorState.set(content);

            bindEvents();

            resetVariantFlags();
        }

        function loadBreadcrumb() {
            entityResource.getAncestors($scope.content.id, "document", $scope.culture)
                .then(function (anc) {
                    $scope.ancestors = anc;
                });
        }

        /**
         * This will reset isDirty flags if save is true.
         * When working with multiple variants, this will set the save/publish flags of each one to false.
         * When working with a single variant, this will set the publish flag to false and the save flag to true.
         */
        function resetVariantFlags() {
            if ($scope.content.variants.length > 1) {
                for (var i = 0; i < $scope.content.variants.length; i++) {
                    var v = $scope.content.variants[i];
                    if (v.save) {
                        v.isDirty = false;
                    }
                    v.save = false;
                    v.publish = false;
                }
            }
            else {
                if ($scope.content.variants[0].save) {
                    $scope.content.variants[0].isDirty = false;
                }
                $scope.content.variants[0].save = true;
                $scope.content.variants[0].publish = false;
            }
        }

        /** Returns true if the content item varies by culture */
        function isContentCultureVariant() {
            return $scope.content.variants.length > 1;
        }

        function reload() {
            $scope.page.loading = true;
            loadContent().then(function () {
                $scope.page.loading = false;
            });
        }

        function bindEvents() {
            //bindEvents can be called more than once and we don't want to have multiple bound events
            for (var e in evts) {
                eventsService.unsubscribe(evts[e]);
            }

            evts.push(eventsService.on("editors.documentType.saved", function (name, args) {
                // if this content item uses the updated doc type we need to reload the content item
                if (args && args.documentType && $scope.content.documentType.id === args.documentType.id) {
                    reload();
                }
            }));

            evts.push(eventsService.on("editors.content.reload", function (name, args) {                
                if (args && args.node && $scope.content.id === args.node.id) {
                    reload();
                    loadBreadcrumb();
                    syncTreeNode($scope.content, $scope.content.path);
                }
            }));

        }

        /**
         *  This does the content loading and initializes everything, called on first load
         */
        function loadContent() {

            //we are editing so get the content item from the server
            return $scope.getMethod()($scope.contentId)
                .then(function (data) {

                    $scope.content = data;

                    init();

                    syncTreeNode($scope.content, $scope.content.path, true);

{'fraction_non_alphanumeric': 0.09938650306748466, 'fraction_numerical': 0.0015498869874071683, 'mean_word_length': 1.4441287878787878, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2409001', 'n_tokens_mistral': 3946, 'n_tokens_neox': 3721, 'n_words': 1069}