Completed
Push — phpunit ( 7f2080...75f541 )
by Marcos
14:28 queued 10:45
created

js/importers/importer-keepasscsv.js   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 49

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 49
rs 9.2258

1 Function

Rating   Name   Duplication   Size   Complexity  
B PassmanImporter.keepassCsv.readFile 0 37 1
1
// Importers should always start with this
2
var PassmanImporter = PassmanImporter || {};
1 ignored issue
show
Bug introduced by
The variable PassmanImporter seems to be never initialized.
Loading history...
3
(function(window, $, PassmanImporter) {
4
	'use strict';
5
	// Define the importer
6
	PassmanImporter.keepassCsv = {
7
		info: {
8
			name: 'KeePass csv',
9
			id: 'keepassCsv',
10
			description: 'Create an csv export with the following options enabled: http://i.imgur.com/CaeTA4d.png'
11
		}
12
	};
13
14
	PassmanImporter.keepassCsv.readFile = function (file_data) {
15
		var p = new C_Promise(function(){
0 ignored issues
show
Bug introduced by
The variable C_Promise seems to be never declared. If this is a global, consider adding a /** global: C_Promise */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
16
			var parsed_csv = PassmanImporter.readCsv(file_data);
17
			var credential_list = [];
18
			for (var i = 0; i < parsed_csv.length; i++) {
19
				var row = parsed_csv[i];
20
				var _credential = PassmanImporter.newCredential();
21
				_credential.label = row.account;
22
				_credential.username = row.login_name;
23
				_credential.password = row.password;
24
				_credential.url = row.web_site;
25
				if (row.hasOwnProperty('expires')) {
26
					row.expires = row.expires.replace('"','');
27
					_credential.expire_time = new Date(row.expires).getTime() / 1000;
28
				}
29
				var tags = [{text: row.group}];
30
				if (row.hasOwnProperty('group_tree')) {
31
					var exploded_tree = row.group_tree.split('\\\\');
32
					for (var t = 0; t < exploded_tree.length; t++) {
33
						tags.push({text: exploded_tree[t]});
34
					}
35
				}
36
				_credential.tags = tags;
37
				credential_list.push(_credential);
38
39
				var progress = {
40
					percent: i/parsed_csv.length*100,
41
					loaded: i,
42
					total: parsed_csv.length
43
				};
44
45
				this.call_progress(progress);
46
			}
47
			this.call_then(credential_list);
48
		});
49
		return p;
50
	};
51
})(window, $, PassmanImporter);
52