Passed
Push — master ( 61dd3f...482d1b )
by greg
01:51
created

src/cli/cms/editor/handlebars/recursiveFolder.js   A

Complexity

Total Complexity 16
Complexity/F 8

Size

Lines of Code 44
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
wmc 16
c 1
b 0
f 0
nc 1
mnd 2
bc 7
fnc 2
dl 0
loc 44
rs 10
bpm 3.5
cpm 8
noi 0
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(typeof dataShow !== 'undefined' && dataShow !== null && 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(typeof links !== 'undefined' && links !== null &&
24
      typeof links[index - 1] !== 'undefined' && links[index - 1] !== null) {
25
      if (links[index - 1] === o.name) {
26
        selected = 'selected="selected"'
27
        isVisible = true
28
      }
29
    }
30
    res += `<option ${selected} data-level-hide="${index+2}" data-level-show="${index+1}" data-show="${o.name.replace(/\.| |\#/g, '_')}">${o.name}</option>`
31
32
    if(typeof o.folders !== 'undefined' && o.folders !== null && o.folders.length > 0) {
33
      sub += recursiveFolder(o.folders, index+1, o.name.replace(/\.| |\#/g, '_'), links, isVisible)
34
    }
35
  })
36
37
  res += `</select>
38
    </div>
39
  </div>`
40
41
  res += sub
42
43
  return res
44
}
45