Completed
Push — master ( 34f5de...9cf608 )
by greg
45s
created

get-list-url.js ➔ ... ➔ ???   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 6
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 6
loc 6
rs 9.4285
c 0
b 0
f 0
1 View Code Duplication
import path from 'path'
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
2
import fse from 'fs-extra'
3
import Handlebars from 'handlebars'
4
import {
5
  abeExtend
6
  ,coreUtils
7
  ,config
8
} from '../../cli'
9
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-url.html')
0 ignored issues
show
Compatibility introduced by
Consider using the path module for constructing paths since they are otherwise not cross-OS compatible.
Loading history...
25
  if (coreUtils.file.exist(page)) {
26
    html = fse.readFileSync(page, 'utf8')
27
  }
28
29
  var workflowUrl = {}
30
  Array.prototype.forEach.call(config.users.workflow, (flow) => {
31
    workflowUrl[flow] = [
32
      {url: `/abe/operations/${flow}/edit`, action: 'edit', workflow: flow},
33
      {url: `/abe/operations/${flow}/delete`, action: 'delete', workflow: flow}
34
    ]
35
  })
36
  var template = Handlebars.compile(html, {noEscape: true})
37
  var tmp = template({
38
    urls: urls,
39
    user: res.user,
40
    config: JSON.stringify(config),
41
    roles: config.users.roles,
42
    workflow: config.users.workflow,
43
    workflowUrl: workflowUrl
44
  })
45
  
46
  res.cookie('csrf-token', res.locals.csrfToken)
47
  return res.send(tmp)
48
}
49
50
export default route