IndexController.js 1.9 KB
Newer Older
L
lepdou 已提交
1 2
index_module.controller('IndexController', ['$scope', '$window', 'toastr', 'AppService', 'AppUtil', 'EnvService',
        function ($scope, $window, toastr, AppService, AppUtil, EnvService) {
L
lepdou 已提交
3

4 5 6 7 8 9 10
            $scope.envs = [];
            $scope.selectedEnv = '';
            EnvService.find_all_envs().then(function (result) {
                $scope.envs = result;
                //default select first env
                $scope.switchEnv($scope.envs[0]);
            }, function (result) {
L
lepdou 已提交
11
                    toastr.error(AppUtil.errorMsg(result), "load env error");
12
            });
L
lepdou 已提交
13

14 15 16 17 18 19 20 21 22 23 24 25 26 27
            var apps = [];
       
            $scope.switchEnv = function (env) {
                $scope.selectedEnv = env;
                loadApps(env);
            };
            
            function loadApps(env){
                AppService.find_all_app(env).then(function (result) {
                    apps = result;
                    $scope.apps = apps;
                    $scope.appsCount = apps.length;
                    $scope.selectedEnv = env;
                }, function (result) {
L
lepdou 已提交
28
                    toastr.error(AppUtil.errorMsg(result), "load apps error"); 
29
                });    
L
lepdou 已提交
30
            }
31 32
            
            $scope.search = function () {
L
lepdou 已提交
33
                    var key = $scope.searchKey.toLocaleLowerCase();
34 35 36 37 38 39
                    if (key == '') {
                            $scope.apps = apps;
                            return;
                    }
                    var result = [];
                    apps.forEach(function (item) {
L
lepdou 已提交
40 41
                            if (item.appId.toLocaleLowerCase().indexOf(key) >= 0 ||
                                item.name.toLocaleLowerCase().indexOf(key) >= 0) {
42 43 44 45 46 47
                                    result.push(item);
                            }
                    });

                    $scope.apps = result;
            };
L
lepdou 已提交
48 49

        }]);