<commit_before>/*
 * Copyright 2014 <NAME>. (http://www.onehippo.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

(function () {
    "use strict";
    angular.module('hippo.essentials')

        .controller('introductionCtrl', function ($scope, $location, $sce, $log, $rootScope, $http) {
            // just sets a hide screen boolean flag to true
            $scope.addUrl = function () {
                $scope.projectSettings.pluginRepositories.push('');
            };

            $scope.removeUrl = function (url) {
                var idx = $scope.projectSettings.pluginRepositories.indexOf(url);
                if (idx > -1) {
                    $scope.projectSettings.pluginRepositories.splice(idx, 1);
                }
            };
            $scope.getStarted = function () {
                // mark setup as done...
                $scope.projectSettings.setupDone = true;
                $http.post($rootScope.REST.save_settings, $scope.projectSettings).success(function (data) {
                    $location.path('/library'); // Start in the Library
                });

            };
            $scope.setup = function () {
                $http.get($rootScope.REST.project_settings).success(function (data) {
                    $scope.projectSettings = data;
                });
            };
            // initialize
            $scope.setup();
        })

        .controller('pluginCtrl', function ($scope, $location, $sce, $log, $rootScope, $http) {

            $scope.allPluginsInstalled = "No additional plugins could be found";
            $scope.plugins = [];
            $scope.selectedPlugin = null;
            $scope.tabs = [
                {name: "Installed Plugins", link: "/plugins"},
                {name: "Find", link: "/find-plugins"}
            ];
            $scope.isPageSelected = function (path) {
                return $location.path() == path;
            };
            $scope.isTabSelected = function (path) {
                var myPath = $location.path();
                return  myPath.indexOf(path) != -1;
            };
            $scope.isMenuSelected = function (path) {
                var myPath = $location.path();
                return  myPath.indexOf(path) != -1;
            };
            $scope.isInstalledFeature = function (plugin) {
                return plugin.type === 'feature'
                        && plugin.installState === 'installed';
            };
            $scope.isInstalledFeatureAndRequiresAttention = function (plugin) {
                return plugin.type === 'feature'
                        && plugin.installState !== 'discovered'
                        && plugin.installState !== 'installed';
            };
            $scope.isInstalledTool = function (plugin) {
                return plugin.type === 'tool'; // TODO: handle install state.
            };

            $scope.showPluginDetail = function (pluginId) {
                $scope.selectedPlugin = extracted(pluginId);
                $rootScope.selectedPlugin = extracted(pluginId);
            };
            $scope.installPlugin = function (pluginId) {
                $rootScope.pluginsCache = null;
                $scope.selectedPlugin = extracted(pluginId);
                if ($scope.selectedPlugin) {
                    $http.post($rootScope.REST.pluginInstall + pluginId).success(function (data) {
                        // we'll get error message or
                        $scope.init();
                    });
                }
            };
            // Receive state updates from individual plugins
            $rootScope.$on('update-plugin-install-state', function(event, data) {
                angular.forEach($scope.plugins, function (plugin) {
                    if (plugin.id === data.pluginId) {
                        plugin.installState = data.state;
                    }
                });
            });

            //fetch plugin list
            $scope.init = function () {

                // Retrieve project settings
                $http.get($rootScope.REST.project_settings).success(function (data) {
                    $rootScope.projectSettings = data;
                });

                if ($rootScope.pluginsCache) {
                    processItems($rootScope.pluginsCache);
                } else {
                    $http.get($rootScope.REST.plugins).success(function (data) {
                        var items = data.items;
                        $rootScope.pluginsCache = items;
                        processItems(items);
                    });
                }

                function processItems(items) {
                    $scope.plugins = items;
                }
            };
            $scope.init();
            function extracted(pluginId) {
                var sel = null;
                angular.forEach($scope.plugins, function (selected) {
                    if (selected.id == pluginId) {
                        sel = selected;
                    }
                });
                return sel;
            }
        })

        /*
         //############################################
         // MENU CONTROLLER
         //############################################
         */
        .controller('mainMenuCtrl', ['$scope', '$location', '$rootScope', function ($scope, $location, $rootScope) {
            $rootScope.addLogClass = true;
            $scope.isPageSelected = function (path) {
                var myPath = $location.path();

                // Map plugin-specific pages to the corresponding plugin-type page
                if (myPath.slice(0, "/plugins".length) == "/plugins") {
                    myPath = '/installed-features';
                }
                else if (myPath.slice(0, "/tools".length) == "/tools") {
                    myPath = '/tools';
                }

                return  '#' + myPath == path;
            };
        }])
        .controller('navbarCtrl', ['$scope', '$rootScope', '$location', '$log',
                          function ($scope,   $rootScope,   $location,   $log) {
            $scope.getPageTitle = function() {
                var myPath = $location.path();

                // Map plugin-specific pages to the corresponding plugin-type page
                if (myPath.slice(0, "/plugins".length) == "/plugins") {
                    myPath = '/installed-features';
                }
                else if (myPath.slice(0, "/tools".length) == "/tools") {
                    myPath = '/tools';
                }

                var pageMap = {
                    '/introduction': 'Setup',
                    '/library': 'Library',
                    '/installed-features': 'Installed features',
                    '/tools': 'Tools',
                    '/build': 'Rebuild'
                };

                return  pageMap[myPath];
            };<commit_msg>Improve behavior of dashboard header.<commit_after>/*
 * Copyright 2014 <NAME>. (http://www.oneh<EMAIL>)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

(function () {
    "use strict";
    angular.module('hippo.essentials')

        .controller('introductionCtrl', function ($scope, $location, $sce, $log, $rootScope, $http) {
            // just sets a hide screen boolean flag to true
            $scope.addUrl = function () {
                $scope.projectSettings.pluginRepositories.push('');
            };

            $scope.removeUrl = function (url) {
                var idx = $scope.projectSettings.pluginRepositories.indexOf(url);
                if (idx > -1) {
                    $scope.projectSettings.pluginRepositories.splice(idx, 1);
                }
            };
            $scope.getStarted = function () {
                // mark setup as done...
                $scope.projectSettings.setupDone = true;
                $http.post($rootScope.REST.save_settings, $scope.projectSettings).success(function () {
                    $location.path('/library'); // Start in the Library
                });

            };
            $scope.setup = function () {
                $http.get($rootScope.REST.project_settings).success(function (data) {
                    $scope.projectSettings = data;
                });
            };
            // initialize
            $scope.setup();
        })

        .controller('pluginCtrl', function ($scope, $location, $sce, $log, $rootScope, $http) {

            $scope.allPluginsInstalled = "No additional plugins could be found";
            $scope.plugins = [];
            $scope.selectedPlugin = null;
            $scope.tabs = [
                {name: "Installed Plugins", link: "/plugins"},
                {name: "Find", link: "/find-plugins"}
            ];
            $scope.isPageSelected = function (path) {
                return $location.path() == path;
            };
            $scope.isTabSelected = function (path) {
                var myPath = $location.path();
                return  myPath.indexOf(path) != -1;
            };
            $scope.isMenuSelected = function (path) {
                var myPath = $location.path();
                return  myPath.indexOf(path) != -1;
            };
            $scope.isInstalledFeature = function (plugin) {
                return plugin.type === 'feature'
                        && plugin.installState === 'installed';
            };
            $scope.isInstalledFeatureAndRequiresAttention = function (plugin) {
                return plugin.type === 'feature'
                        && plugin.installState !== 'discovered'
                        && plugin.installState !== 'installed';
            };
            $scope.isInstalledTool = function (plugin) {
                return plugin.type === 'tool'; // TODO: handle install state.
            };

            $scope.showPluginDetail = function (pluginId) {
                $scope.selectedPlugin = extracted(pluginId);
                $rootScope.selectedPlugin = extracted(pluginId);
            };
            $scope.installPlugin = function (pluginId) {
                $rootScope.pluginsCache = null;
                $scope.selectedPlugin = extracted(pluginId);
                if ($scope.selectedPlugin) {
                    $http.post($rootScope.REST.pluginInstall + pluginId).success(function () {
                        // we'll get error message or
                        $scope.init();
                    });
                }
            };
            // Receive state updates from individual plugins
            $rootScope.$on('update-plugin-install-state', function(event, data) {
                angular.forEach($scope.plugins, function (plugin) {
                    if (plugin.id === data.pluginId) {
                        plugin.installState = data.state;
                    }
                });
            });

            //fetch plugin list
            $scope.init = function () {

                // Retrieve project settings
                $http.get($rootScope.REST.project_settings).success(function (data) {
                    $rootScope.projectSettings = data;
                });

                if ($rootScope.pluginsCache) {
                    processItems($rootScope.pluginsCache);
                } else {
                    $http.get($rootScope.REST.plugins).success(function (data) {
                        var items = data.items;
                        $rootScope.pluginsCache = items;
                        processItems(items);
                    });
                }

                function processItems(items) {
                    $scope.plugins = items;
                }
            };
            $scope.init();
            function extracted(pluginId) {
                var sel = null;
                angular.forEach($scope.plugins, function (selected) {
                    if (selected.id == pluginId) {
                        sel = selected;
                    }
                });
                return sel;
            }
        })

        /*
         //############################################
         // MENU CONTROLLER
         //############################################
         */
        .controller('mainMenuCtrl', ['$scope', '$location', '$rootScope', function ($scope, $location, $rootScope) {
            $rootScope.addLogClass = true;
            $scope.isPageSelected = function (path) {
                var myPath = $location.path();

                // Map plugin-specific pages to the corresponding plugin-type page
                if (myPath.slice(0, "/plugins".length) == "/plugins") {
                    myPath = '/installed-features';
                }
                else if (myPath.slice(0, "/tools".length) == "/tools") {
                    myPath = '/tools';
                }

                return  '#' + myPath == path;
            };
        }])
        .controller('navbarCtrl', ['$scope', '$rootScope', '$location', '$log',
                          function ($scope,   $rootScope,   $location,   $log) {
            $scope.getPageTitle = function() {
                var myPath = $location.path();

                // Map plugin-specific pages to the corresponding plugin-type page
                if (myPath.slice(0, "/features".length) == "/features") {
                    myPath = '/installed-features';
                }
                else if (myPath.slice(0, "/tools".length) == "/tools") {
                    myPath = '/tools';
                }

                var pageMap = {
                    '/introduction': 'Setup',
                    '/library': 'Library',
                    '/installed-features': 'Installed features',
                    '/tools': 'Tools',
                    '/build': 'Rebuild'
                };

                return  pageMap[myPath];
            };
{'fraction_non_alphanumeric': 0.1308889937318865, 'fraction_numerical': 0.0021567702365707354, 'mean_word_length': 1.3920683540222474, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '1210458', 'n_tokens_mistral': 3660, 'n_tokens_neox': 3404, 'n_words': 804}