| Conditions | 4 |
| Paths | 8 |
| Total Lines | 85 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
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:
If many parameters/temporary variables are present:
| 1 | import Handlebars from 'handlebars' |
||
| 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}">✔</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 { |
||
|
|
|||
| 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 |