src/scripts/component/dashboard-list.js   A
last analyzed

Complexity

Total Complexity 10
Complexity/F 3.33

Size

Lines of Code 42
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 0
wmc 10
nc 1
mnd 2
bc 8
fnc 3
dl 0
loc 42
rs 10
bpm 2.6666
cpm 3.3333
noi 0
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
B dashboard-list.js ➔ dashboardList 0 34 1
1
/**
2
 getHtml
3
 Simple component to retrieve the HTML value of a resource.
4
5
 @namespace Components
6
 */
7
'use strict';
8
9
angular.module('game').component('dashboardList', {
10
  templateUrl: 'views/dashboard-list.html',
11
  controller: ['data','state','util','visibility', dashboardList],
12
  controllerAs: 'ct'
13
});
14
15
function dashboardList(data, state, util, visibility) {
16
  let ct = this;
17
  ct.data = data;
18
  ct.state = state;
19
  ct.util = util;
20
  ct.searchText = '';
21
22
  ct.resourcesForElement = function(element, player) {
23
    return visibility.visible(data.resources, filter, element, null, player);
24
  };
25
26
  function filter(name, currentElement, player) {
27
    if(player.resources[name] === null){
28
      return false;
29
    }
30
    if(ct.searchText && name.toLowerCase().indexOf(ct.searchText.toLowerCase()) === -1){
31
      return false;
32
    }
33
    // This is for global resources e.g. protons, which do not
34
    // belong to any element
35
    let elements = data.resources[name].elements;
36
    if (Object.keys(elements).length === 0 && currentElement === '') {
37
      return true;
38
    }
39
40
    for (let element in elements) {
41
      if (currentElement === element) {
42
        return true;
43
      }
44
    }
45
46
    return false;
47
  }
48
}
49