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

angular.filter(ꞌcredentialSearchꞌ)   D

Complexity

Conditions 9
Paths 9

Size

Total Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 9
c 1
b 0
f 0
nc 9
nop 2
dl 0
loc 33
rs 4.909
1
(function () {
2
	'use strict';
3
	/**
4
	 * @ngdoc filter
5
	 * @name passmanApp.filter:selectedTags
6
	 * @function
7
	 * @description
8
	 * # selectedTags
9
	 * Filter in the passmanApp.
10
	 */
11
	angular.module('passmanApp')
12
		.filter('credentialSearch', function () {
13
			return function (credentials, filter) {
14
				var _credentials = [];
15
				if (credentials) {
16
					if(!filter){
17
						return credentials;
18
					}
19
					if (filter.filterText.trim() === "") {
20
						return credentials;
21
					}
22
23
					for (var ci = 0; ci < credentials.length; ci++) {
24
						var c = credentials[ci];
25
						for (var f = 0; f < filter.fields.length; f++) {
26
							var field = filter.fields[f];
27
							if (typeof c[field] === 'string') {
28
								if (c[field].toLowerCase().indexOf(filter.filterText.toLowerCase()) >= 0) {
29
									_credentials.push(c);
30
									break;
31
								}
32
							} else {
33
								var t = JSON.stringify(c[field]);
34
								if (t.indexOf(filter.filterText) >= 0) {
35
									_credentials.push(c);
36
									break;
37
								}
38
							}
39
						}
40
					}
41
					return _credentials;
42
				} else {
43
					return [];
44
				}
45
			};
46
		});
47
}());