| Conditions | 4 |
| Paths | 8 |
| Total Lines | 57 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 | /** |
||
| 34 | .controller('MainCtrl', ['$scope', '$rootScope', '$location', 'SettingsService', '$window', '$interval', '$filter', function ($scope, $rootScope, $location, SettingsService, $window, $interval, $filter) { |
||
| 35 | $scope.selectedVault = false; |
||
| 36 | |||
| 37 | $scope.http_warning_hidden = true; |
||
| 38 | if ($location.$$protocol === 'http' && $location.$$host !== 'localhost' && $location.$host !== '127.0.0.1') { |
||
| 39 | $scope.using_http = true; |
||
| 40 | $scope.http_warning_hidden = false; |
||
| 41 | |||
| 42 | } |
||
| 43 | |||
| 44 | $rootScope.$on('settings_loaded', function(){ |
||
| 45 | if (SettingsService.getSetting('disable_contextmenu') === '1' || SettingsService.getSetting('disable_contextmenu') === 1) { |
||
| 46 | document.addEventListener('contextmenu', function (event) { |
||
| 47 | event.preventDefault(); |
||
| 48 | }); |
||
| 49 | } |
||
| 50 | if (SettingsService.getSetting('https_check') === '0' || SettingsService.getSetting('https_check') === 0) { |
||
| 51 | $scope.http_warning_hidden = true; |
||
| 52 | } |
||
| 53 | }); |
||
| 54 | |||
| 55 | $rootScope.setHttpWarning = function (state) { |
||
| 56 | $scope.http_warning_hidden = state; |
||
| 57 | }; |
||
| 58 | |||
| 59 | $rootScope.$on('app_menu', function (evt, shown) { |
||
| 60 | $scope.app_sidebar = shown; |
||
| 61 | }); |
||
| 62 | |||
| 63 | $rootScope.$on('logout', function () { |
||
| 64 | $scope.selectedVault = false; |
||
| 65 | }); |
||
| 66 | |||
| 67 | var tickSessionTimer = function(){ |
||
| 68 | if($scope.session_time_left){ |
||
| 69 | $scope.session_time_left--; |
||
| 70 | var session_time_left_formatted = $filter('toHHMMSS')($scope.session_time_left); |
||
| 71 | $scope.translationData = { |
||
| 72 | session_time: session_time_left_formatted |
||
| 73 | }; |
||
| 74 | $rootScope.$broadcast('logout_timer_tick_tack', $scope.session_time_left); |
||
| 75 | if($scope.session_time_left === 0){ |
||
| 76 | $window.location.reload(); |
||
| 77 | } |
||
| 78 | } |
||
| 79 | }; |
||
| 80 | |||
| 81 | $scope.session_time_left = false; |
||
| 82 | $scope.$on('logout_timer_set', function(evt, timer){ |
||
| 83 | $scope.session_time_left = timer; |
||
| 84 | $scope.translationData = { |
||
| 85 | session_time: timer |
||
| 86 | }; |
||
| 87 | $interval(tickSessionTimer, 1000); |
||
| 88 | }); |
||
| 89 | |||
| 90 | }]); |
||
| 91 | |||
| 92 | }()); |