Passed
Push — develop ( 9a1b4b...96b452 )
by Xaver
03:40
created

lib/filters/filtergui.js   A

Complexity

Total Complexity 9
Complexity/F 1.5

Size

Lines of Code 44
Function Count 6

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 9
eloc 28
mnd 3
bc 3
fnc 6
dl 0
loc 44
rs 10
bpm 0.5
cpm 1.5
noi 0
c 0
b 0
f 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
B filtergui.js ➔ filtersChanged 0 25 6
A filtergui.js ➔ render 0 3 3
1
define(function () {
2
  'use strict';
3
4
  return function (distributor) {
5
    var container = document.createElement('ul');
6
    container.classList.add('filters');
7
    var div = document.createElement('div');
8
9
    function render(el) {
10
      el.appendChild(div);
11
    }
12
13
    function filtersChanged(filters) {
14
      while (container.firstChild) {
15
        container.removeChild(container.firstChild);
16
      }
17
18
      filters.forEach(function (d) {
19
        var li = document.createElement('li');
20
        container.appendChild(li);
21
        d.render(li);
22
23
        var button = document.createElement('button');
24
        button.classList.add('ion-close');
25
        button.setAttribute('aria-label', _.t('remove'));
26
        button.onclick = function onclick() {
27
          distributor.removeFilter(d);
28
        };
29
        li.appendChild(button);
30
      });
31
32
      if (container.parentNode === div && filters.length === 0) {
33
        div.removeChild(container);
34
      } else if (filters.length > 0) {
35
        div.appendChild(container);
36
      }
37
    }
38
39
    return {
40
      render: render,
41
      filtersChanged: filtersChanged
42
    };
43
  };
44
});
45