| Conditions | 1 |
| Paths | 1 |
| Total Lines | 72 |
| 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 | /** |
||
| 23 | (function () { |
||
| 24 | 'use strict'; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @ngdoc function |
||
| 28 | * @name passmanApp.controller:ImportCtrl |
||
| 29 | * @description |
||
| 30 | * # ImportCtrl |
||
| 31 | * Controller of the passmanApp |
||
| 32 | */ |
||
| 33 | angular.module('passmanApp') |
||
| 34 | .controller('ExportCtrl', ['$scope', '$window', 'CredentialService', 'VaultService', '$translate', function ($scope, $window, CredentialService, VaultService, $translate) { |
||
| 35 | $scope.available_exporters = []; |
||
| 36 | $scope.active_vault = VaultService.getActiveVault(); |
||
| 37 | $scope.confirm_key = ''; |
||
| 38 | |||
| 39 | $scope.$watch(function () { |
||
| 40 | return $window.PassmanExporter; |
||
| 41 | }, function (exporters) { |
||
| 42 | exporters = Object.keys(angular.copy(exporters)); |
||
| 43 | for (var i = 0; i < exporters.length; i++) { |
||
| 44 | var exporter = exporters[i]; |
||
| 45 | if ($window.PassmanExporter[exporter].hasOwnProperty('info')) { |
||
| 46 | $scope.available_exporters.push($window.PassmanExporter[exporter].info); |
||
| 47 | } |
||
| 48 | } |
||
| 49 | }, true); |
||
| 50 | $scope.log = []; |
||
| 51 | $scope.setExporter = function (exporter) { |
||
| 52 | exporter = JSON.parse(exporter); |
||
| 53 | $scope.selectedExporter = exporter; |
||
| 54 | }; |
||
| 55 | var _log = function (str) { |
||
| 56 | $scope.log.push(str); |
||
| 57 | }; |
||
| 58 | |||
| 59 | |||
| 60 | $scope.startExport = function () { |
||
| 61 | $scope.error = false; |
||
| 62 | if(VaultService.getActiveVault().vaultKey !== $scope.confirm_key){ |
||
| 63 | var msg = $translate.instant('invalid.vault.key'); |
||
| 64 | $scope.error = msg; |
||
| 65 | _log(msg); |
||
| 66 | return; |
||
| 67 | } |
||
| 68 | _log($translate.instant('export.starting')); |
||
| 69 | var _credentials = []; |
||
| 70 | VaultService.getVault(VaultService.getActiveVault()).then(function (vault) { |
||
| 71 | _log($translate.instant('export.decrypt')); |
||
| 72 | if (vault.hasOwnProperty('credentials')) { |
||
| 73 | if (vault.credentials.length > 0) { |
||
| 74 | for (var i = 0; i < vault.credentials.length; i++) { |
||
| 75 | var _credential = angular.copy(vault.credentials[i]); |
||
| 76 | if (_credential.hidden === 0) { |
||
| 77 | var key = CredentialService.getSharedKeyFromCredential(_credential); |
||
| 78 | _credential = CredentialService.decryptCredential(_credential, key); |
||
| 79 | _credentials.push(_credential); |
||
| 80 | } |
||
| 81 | } |
||
| 82 | $window.PassmanExporter[$scope.selectedExporter.id].export(_credentials).then(function () { |
||
| 83 | _log($translate.instant('done')); |
||
| 84 | }); |
||
| 85 | } |
||
| 86 | |||
| 87 | } |
||
| 88 | }); |
||
| 89 | }; |
||
| 90 | |||
| 91 | |||
| 92 | }]); |
||
| 93 | |||
| 94 | }()); |