Conditions | 1 |
Paths | 2 |
Total Lines | 107 |
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('MainCtrl', ['$scope', 'Settings', '$location', '$rootScope', '$timeout', function ($scope, Settings, $window, $rootScope, $timeout) { |
||
37 | |||
38 | var port = API.runtime.connect(null, { |
||
39 | name: "PassmanCommunication" |
||
40 | }); |
||
41 | |||
42 | |||
43 | var messageParser = function (message) { |
||
44 | var e = message.split(':'); |
||
45 | |||
46 | switch (e[0]) { |
||
|
|||
47 | case "credential_amount": |
||
48 | $scope.credential_amount = e[1]; |
||
49 | $scope.refreshing_credentials = false; |
||
50 | } |
||
51 | |||
52 | $scope.$apply(); |
||
53 | }; |
||
54 | |||
55 | /** |
||
56 | * Connect to the background service |
||
57 | */ |
||
58 | var initApp = function () { |
||
59 | port.onMessage.addListener(messageParser); |
||
60 | API.runtime.sendMessage(API.runtime.id, {method: "getMasterPasswordSet"}).then(function (isPasswordSet) { |
||
61 | //First check attributes |
||
62 | if (!isPasswordSet) { |
||
63 | return; |
||
64 | } |
||
65 | $scope.refreshing_credentials = true; |
||
66 | setTimeout(function () { |
||
67 | port.postMessage("credential_amount"); |
||
68 | }, 500); |
||
69 | }); |
||
70 | }; |
||
71 | |||
72 | |||
73 | $scope.refreshing_credentials = false; |
||
74 | $scope.refresh = function () { |
||
75 | $scope.refreshing_credentials = true; |
||
76 | API.runtime.sendMessage(API.runtime.id, {method: "getCredentials"}).then(function () { |
||
77 | setTimeout(function () { |
||
78 | port.postMessage("credential_amount"); |
||
79 | }, 1900); |
||
80 | }); |
||
81 | }; |
||
82 | |||
83 | $scope.menuIsOpen = false; |
||
84 | $scope.bodyOverflow = false; |
||
85 | $scope.showHeader = true; |
||
86 | |||
87 | $scope.toggleMenu = function () { |
||
88 | $scope.menuIsOpen = !$scope.menuIsOpen; |
||
89 | $scope.bodyOverflow = true; |
||
90 | $timeout(function () { |
||
91 | $scope.bodyOverflow = false; |
||
92 | }, 1500); |
||
93 | }; |
||
94 | |||
95 | $rootScope.$on('hideHeader', function () { |
||
96 | $scope.showHeader = false; |
||
97 | }); |
||
98 | |||
99 | $rootScope.$on('showHeader', function () { |
||
100 | $scope.showHeader = true; |
||
101 | }); |
||
102 | |||
103 | API.runtime.sendMessage(API.runtime.id, {'method': 'getRuntimeSettings'}).then(function (settings) { |
||
104 | |||
105 | $rootScope.app_settings = settings; |
||
106 | if (!settings || Object.keys(settings).length === 0) { |
||
107 | window.location = '#!/setup'; |
||
108 | } else if (settings.hasOwnProperty('isInstalled')) { |
||
109 | window.location = '#!/locked'; |
||
110 | } else { |
||
111 | initApp(); |
||
112 | } |
||
113 | }); |
||
114 | |||
115 | |||
116 | $scope.goto = function (page) { |
||
117 | window.location = '#!/' + page; |
||
118 | $scope.menuIsOpen = false; |
||
119 | }; |
||
120 | |||
121 | |||
122 | $scope.lockExtension = function () { |
||
123 | API.runtime.sendMessage(API.runtime.id, { |
||
124 | method: "setMasterPassword", |
||
125 | args: {password: null} |
||
126 | }).then(function () { |
||
127 | window.location = '#!/locked'; |
||
128 | }); |
||
129 | }; |
||
130 | }]); |
||
131 | }()); |
||
132 | |||
133 |