Completed
Push — master ( 7adf3a...ab1d76 )
by Sander
45s
created

js/ui/popup/controllers/settings.js   A

Complexity

Conditions 1
Paths 2

Size

Total Lines 75

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 75
rs 9

1 Function

Rating   Name   Duplication   Size   Complexity  
A angular.controller(ꞌSettingsCtrlꞌ) 0 63 2

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
/* global API */
2
3
/**
4
 * Nextcloud - passman
5
 *
6
 * @copyright Copyright (c) 2016, Sander Brand ([email protected])
7
 * @copyright Copyright (c) 2016, Marcos Zuriaga Miguel ([email protected])
8
 * @license GNU AGPL version 3 or any later version
9
 *
10
 * This program is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU Affero General Public License as
12
 * published by the Free Software Foundation, either version 3 of the
13
 * License, or (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU Affero General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU Affero General Public License
21
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
 *
23
 */
24
25
(function () {
26
    'use strict';
27
28
    /**
29
     * @ngdoc function
30
     * @name passmanApp.controller:MainCtrl
31
     * @description
32
     * # MainCtrl
33
     * Controller of the passmanApp
34
     */
35
    angular.module('passmanExtension')
36
        .controller('SettingsCtrl', ['$scope', 'notify', '$routeParams', function ($scope, notify, $routeParams) {
37
            $scope.settings = {
38
                accounts: [],
39
                ignoreProtocol: true,
40
                ignoreSubdomain: true,
41
                ignorePort: true,
42
                ignorePath: true,
43
                generatedPasswordLength: 12,
44
                remember_password: true,
45
                refreshTime: 60,
46
                debug: false
47
            };
48
            $scope.errors = [];
49
50
            $scope.tabActive =  ($routeParams.tab) ? parseInt($routeParams.tab) : 1;
51
52
            API.runtime.sendMessage(API.runtime.id, {'method': 'getRuntimeSettings'}).then(function (settings) {
53
                $scope.errors = [];
54
                if (settings) {
55
                    $scope.settings = angular.copy(settings);
56
                }
57
                $scope.$apply();
58
            });
59
60
            $scope.saving = false;
61
            $scope.saveSettings = function (redirect) {
62
                $scope.errors = [];
63
                var settings = angular.copy($scope.settings);
64
                $scope.saving = true;
65
                API.runtime.sendMessage(API.runtime.id, {method: "saveSettings", args: settings}).then(function () {
66
                    setTimeout(function () {
67
                        if(redirect) {
68
                            window.location = '#!/';
69
                        }
70
                        $scope.saving = false;
71
                    }, 750);
72
                });
73
            };
74
75
            $scope.removeSite = function (site) {
76
                var idx = $scope.settings.ignored_sites.indexOf(site);
77
                $scope.settings.ignored_sites.splice(idx, 1);
78
            };
79
80
            $scope.ignoreSite = '';
81
            $scope.addSite = function (site) {
82
                $scope.settings.ignored_sites.push(site);
83
                $scope.ignoreSite = '';
84
            };
85
86
            $scope.removeAccount = function (account) {
87
                var idx = $scope.settings.accounts.indexOf(account);
88
                $scope.settings.accounts.splice(idx, 1);
89
                $scope.saveSettings(false);
90
            };
91
92
            $scope.cancel = function () {
93
                window.location = '#!/';
94
            };
95
            $scope.addAccount = function () {
96
                window.location = '#!/accounts/add';
97
            };
98
        }]);
99
}());
100
101