| Conditions | 2 |
| Paths | 2 |
| Total Lines | 61 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 1 | Features | 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 path from 'path' |
||
| 10 | var route = function(router, req, res, next) { |
||
| 11 | abeExtend.hooks.instance.trigger('beforeRoute', req, res, next) |
||
| 12 | var routes = router.stack |
||
| 13 | var urls = [] |
||
| 14 | var html = '' |
||
| 15 | |||
| 16 | Array.prototype.forEach.call(routes, function(route) { |
||
| 17 | urls.push({ |
||
| 18 | url: route.route.path, |
||
| 19 | method: Object.keys(route.route.methods)[0].toUpperCase(), |
||
| 20 | regex: route.route.path.replace(/\*$/, '') + '.*' |
||
| 21 | }) |
||
| 22 | }) |
||
| 23 | |||
| 24 | var page = path.join(__dirname + '/../views/list-workflow.html') |
||
|
|
|||
| 25 | if (coreUtils.file.exist(page)) { |
||
| 26 | html = fse.readFileSync(page, 'utf8') |
||
| 27 | } |
||
| 28 | |||
| 29 | var workflowUrl = {} |
||
| 30 | var previous = "" |
||
| 31 | var next = "" |
||
| 32 | Array.prototype.forEach.call(config.users.workflow, (flow) => { |
||
| 33 | var current = false |
||
| 34 | if (flow != 'publish') { |
||
| 35 | Array.prototype.forEach.call(config.users.workflow, (flowCheck) => { |
||
| 36 | if (current) { |
||
| 37 | next = flowCheck |
||
| 38 | current = false |
||
| 39 | } |
||
| 40 | if (flow === flowCheck) { |
||
| 41 | current = true |
||
| 42 | } |
||
| 43 | }) |
||
| 44 | }else { |
||
| 45 | next = "draft" |
||
| 46 | } |
||
| 47 | workflowUrl[flow] = [ |
||
| 48 | {url: `/abe/operations/edit/${flow}`, action: 'edit', workflow: flow, previous: previous, next: next}, |
||
| 49 | {url: `/abe/operations/delete/${flow}`, action: 'delete', workflow: flow, previous: previous, next: next}, |
||
| 50 | {url: `/abe/operations/submit/${flow}`, action: 'submit', workflow: flow, previous: previous, next: next} |
||
| 51 | ] |
||
| 52 | |||
| 53 | if (flow !== 'draft') { |
||
| 54 | workflowUrl[flow].push({url: `/abe/operations/reject/${flow}`, action: 'reject', workflow: flow, previous: previous, next: next}) |
||
| 55 | } |
||
| 56 | previous = flow |
||
| 57 | }) |
||
| 58 | var template = Handlebars.compile(html, {noEscape: true}) |
||
| 59 | var tmp = template({ |
||
| 60 | urls: urls, |
||
| 61 | user: res.user, |
||
| 62 | config: JSON.stringify(config), |
||
| 63 | roles: config.users.roles, |
||
| 64 | workflow: config.users.workflow, |
||
| 65 | workflowUrl: workflowUrl |
||
| 66 | }) |
||
| 67 | |||
| 68 | res.cookie('csrf-token', res.locals.csrfToken) |
||
| 69 | return res.send(tmp) |
||
| 70 | } |
||
| 71 | |||
| 72 | export default route |