Completed
Push — master ( 78d2f9...949122 )
by greg
42s
created

listPage.js ➔ listPage   B

Complexity

Conditions 4
Paths 8

Size

Total Lines 85

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
nc 8
dl 0
loc 85
rs 8.452
c 0
b 0
f 0
nop 3

1 Function

Rating   Name   Duplication   Size   Complexity  
A listPage.js ➔ ... ➔ ??? 0 18 4

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
import Handlebars from 'handlebars'
2
import moment from 'moment'
3
import {
4
  math
5
  ,abeExtend
6
  ,config
7
} from '../../../'
8
9
export default function listPage(file, index, text) {
10
  var res = ''
11
12
  file = abeExtend.hooks.instance.trigger('beforeListPage', file, index, text)
13
14
  res += '<tr>'
15
  res += `<td>${math(index, '+', 1)}</td>
16
        <td>
17
          <a href="/abe/editor${file.abe_meta.link}" class="file-path">
18
            ${file.abe_meta.link}
19
          </a>
20
        </td>`
21
  
22
  if(file.abe_meta.template){
23
    res += `<td align="center">
24
              ${file.abe_meta.template}
25
            </td>`
26
  }else {
27
    res += '<td align="center"></td>'
28
  }
29
  
30
  if(file.date){
31
    var dateSearch = moment(file.date).format('YYYY-MM-DD')
32
    var dateOrder = new Date(file.date).getTime()
33
    res += `<td align="center" data-search="${dateSearch}" data-order="${dateOrder}">
34
              ${dateSearch}
35
            </td>`
36
  }else {
37
    res += '<td align="center" data-search="0000-00-00" data-order="0"></td>'
38
  }
39
40
  var workflow = ''
41
42
  var status = file.abe_meta.status
43
  var workflowUser = config.users.workflow
44
  Array.prototype.forEach.call(workflowUser, (flow) => {
45
    var hidden = ''
46
    if(status !== flow) {
47
      hidden = 'hidden'
48
    }
49
50
    workflow += `<td align="center" class="${flow}">`
51
    if(file[flow]) {
52
      if (flow === 'publish') {
53
        workflow += `<a href="/abe/editor${file[flow].html}" class="checkmark label-published" title="${file[flow].cleanDate}">&#10004;</a>`
54
      }else {
55
        workflow += `<a href="/abe/editor${file[flow].html}" class="${hidden} label label-default label-draft" title="${file[flow].cleanDate}">${flow}</a>`
56
      }
57
    }else {
0 ignored issues
show
Comprehensibility Documentation Best Practice introduced by
This code block is empty. Consider removing it or adding a comment to explain.
Loading history...
58
59
    }
60
    workflow += '</td>'
61
  })
62
63
  res += workflow
64
65
  res += `<td align="center">
66
            <div class="row icons-action">`
67
68
  if(file.publish != null) {
69
    res += `<a href="/abe/unpublish${file.abe_meta.link}"
70
               title="${text.unpublish}"
71
               class="icon" data-unpublish="true" data-text="${text.confirmUnpublish} ${file.abe_meta.link}"
72
               title="unpublish">
73
              <span class="glyphicon glyphicon-eye-close"></span>
74
            </a>`
75
  }
76
      
77
  res += `<a href="/abe/delete${file.abe_meta.link}"
78
             title="${text.delete}"
79
             class="icon"
80
             data-delete="true"
81
             data-text="${text.confirmDelete} ${file.abe_meta.link}"
82
             title="remove">
83
            <span class="glyphicon glyphicon-trash"></span>
84
          </a>`
85
86
  res += `
87
        </div>
88
      </td>
89
    </tr>`
90
91
  res = abeExtend.hooks.instance.trigger('afterListPage', res, file, index, text)
92
  return new Handlebars.SafeString(res)
93
}
94