Completed
Push — master ( f48291...a65f2c )
by greg
74:59
created

recursiveFolder.js ➔ recursiveFolder   B

Complexity

Conditions 5
Paths 16

Size

Total Lines 43

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 5
c 2
b 0
f 0
nc 16
dl 0
loc 43
rs 8.439
nop 5

1 Function

Rating   Name   Duplication   Size   Complexity  
B recursiveFolder.js ➔ ... ➔ ??? 0 15 6
1
export default function recursiveFolder(obj, index = 1, dataShow = '', links = null, visible = false) {
2
  var classHidden = ''
3
  if(index > 1 && !visible) {
4
    classHidden = 'hidden'
5
  }
6
7
  var id = `level-${index}`
8
  if(dataShow) {
9
    id += `-${dataShow}`
10
  }
11
  var parent = obj[0] ? obj[0].cleanPath.split('/')[0] : ''
12
  var res = `<div class="form-group level-${index} ${classHidden}" data-parent="${parent}" data-shown="${dataShow}">
13
    <label for="${id}" class="col-sm-5 control-label">Level ${index}</label>
14
    <div class="col-sm-7">
15
      <select data-show-hide-sub-folder="true" id="${id}" class="form-control">
16
        <option data-level-hide="${index+1}"></option>`
17
18
  var sub = ''
19
20
  Array.prototype.forEach.call(obj, (o) => {
21
    var selected = ''
22
    var isVisible = false
23
    if(links != null && links[index - 1] != null) {
24
      if (links[index - 1] === o.name) {
25
        selected = 'selected="selected"'
26
        isVisible = true
27
      }
28
    }
29
    res += `<option ${selected} data-level-hide="${index+2}" data-level-show="${index+1}" data-show="${o.name.replace(/\.| |\#/g, '_')}">${o.name}</option>`
30
31
    if(o.folders != null && o.folders.length > 0) {
32
      sub += recursiveFolder(o.folders, index+1, o.name.replace(/\.| |\#/g, '_'), links, isVisible)
33
    }
34
  })
35
36
  res += `</select>
37
    </div>
38
  </div>`
39
40
  res += sub
41
42
  return res
43
}
44