Conditions | 1 |
Paths | 27 |
Total Lines | 122 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
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:
If many parameters/temporary variables are present:
1 | /* global API */ |
||
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', '$rootScope', 'Settings', '$location', function ($scope, $rootScope, Settings, $location) { |
||
37 | $scope.settings = { |
||
38 | nextcloud_host: '', |
||
39 | nextcloud_username: '', |
||
40 | nextcloud_password: '', |
||
41 | ignoreProtocol: true, |
||
42 | ignoreSubdomain: true, |
||
43 | ignorePort: true, |
||
44 | ignorePath: true, |
||
45 | generatedPasswordLength: 12, |
||
46 | remember_password: true, |
||
47 | remember_vault_password: true, |
||
48 | refreshTime: 60, |
||
49 | debug: false |
||
50 | }; |
||
51 | $scope.errors = []; |
||
52 | |||
53 | API.runtime.sendMessage(API.runtime.id, {'method': 'getRuntimeSettings'}).then(function (settings) { |
||
54 | $scope.errors = []; |
||
55 | if (settings) { |
||
56 | $scope.settings = angular.copy(settings); |
||
57 | } |
||
58 | |||
59 | $scope.get_vaults = function () { |
||
60 | if (!$scope.settings.hasOwnProperty('nextcloud_host') || !$scope.settings.hasOwnProperty('nextcloud_password') || !$scope.settings.hasOwnProperty('nextcloud_username')) { |
||
61 | return; |
||
62 | } |
||
63 | PAPI.username = $scope.settings.nextcloud_username; |
||
64 | PAPI.password = $scope.settings.nextcloud_password; |
||
65 | PAPI.host = $scope.settings.nextcloud_host; |
||
66 | $scope.extension = API.runtime.getManifest().name + ' extension ' + API.runtime.getManifest().version; |
||
67 | PAPI.getVaults(function (vaults) { |
||
68 | $scope.errors = []; |
||
69 | var save_btn = jQuery('#save'), |
||
70 | login_required = jQuery('.login-req'); |
||
71 | if (vaults.hasOwnProperty('error')) { |
||
72 | |||
73 | var errors = API.i18n.getMessage('invalid_response_from_server', [vaults.result.status, vaults.result.statusText]); |
||
74 | $scope.errors.push(errors); |
||
75 | login_required.hide(); |
||
76 | save_btn.hide(); |
||
77 | $scope.$apply(); |
||
78 | return; |
||
79 | |||
80 | } |
||
81 | login_required.show(); |
||
82 | save_btn.show(); |
||
83 | $scope.vaults = vaults; |
||
84 | $scope.$apply(); |
||
85 | |||
86 | }); |
||
87 | }; |
||
88 | |||
89 | $scope.$watch('[settings.nextcloud_host, settings.nextcloud_username, settings.nextcloud_password]', function () { |
||
90 | if ($scope.settings.nextcloud_host && $scope.settings.nextcloud_username && $scope.settings.nextcloud_password) { |
||
91 | $scope.get_vaults(); |
||
92 | } |
||
93 | }, true); |
||
94 | |||
95 | if ($scope.settings.nextcloud_host && $scope.settings.nextcloud_username && $scope.settings.nextcloud_password) { |
||
96 | $scope.get_vaults(); |
||
97 | } |
||
98 | $scope.$apply(); |
||
99 | }); |
||
100 | |||
101 | $scope.saving = false; |
||
102 | $scope.saveSettings = function () { |
||
103 | $scope.errors = []; |
||
104 | var settings = angular.copy($scope.settings); |
||
105 | for (var i =0; i < $scope.vaults.length; i++){ |
||
106 | var vault = $scope.vaults[i]; |
||
107 | if(vault.guid === settings.default_vault.guid){ |
||
108 | settings.default_vault = angular.copy(vault); |
||
109 | break; |
||
110 | } |
||
111 | } |
||
112 | |||
113 | try { |
||
114 | /** global: PAPI */ |
||
115 | PAPI.decryptString(settings.default_vault.challenge_password, settings.vault_password); |
||
116 | } catch (e) { |
||
117 | $scope.errors.push(API.i18n.getMessage('invalid_vault_password')); |
||
118 | return; |
||
119 | } |
||
120 | |||
121 | $scope.saving = true; |
||
122 | API.runtime.sendMessage(API.runtime.id, {method: "saveSettings", args: settings}).then(function () { |
||
123 | setTimeout(function () { |
||
124 | window.location = '#!/'; |
||
125 | $scope.saving = false; |
||
126 | }, 750); |
||
127 | }); |
||
128 | }; |
||
129 | |||
130 | $scope.removeSite = function (site) { |
||
131 | var idx = $scope.settings.ignored_sites.indexOf(site); |
||
132 | $scope.settings.ignored_sites.splice(idx, 1); |
||
133 | }; |
||
134 | |||
135 | $scope.ignoreSite = ''; |
||
136 | $scope.addSite = function (site) { |
||
137 | $scope.settings.ignored_sites.push(site); |
||
138 | $scope.ignoreSite = ''; |
||
139 | }; |
||
140 | |||
141 | |||
142 | $scope.cancel = function () { |
||
143 | window.location = '#!/'; |
||
144 | }; |
||
145 | }]); |
||
146 | }()); |
||
147 | |||
148 |
This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.