-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathexchanges.js
More file actions
107 lines (102 loc) · 3.53 KB
/
exchanges.js
File metadata and controls
107 lines (102 loc) · 3.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import * as HTTP from './http.js'
import * as Helpers from './helpers.js'
import * as DOM from './dom.js'
import * as Table from './table.js'
Helpers.addVhostOptions('addExchange')
HTTP.request('GET', 'api/overview').then(function (response) {
const exchangeTypes = response.exchange_types
const select = document.forms.addExchange.elements.type
exchangeTypes.forEach(item => {
const name = (item && typeof item === 'object') ? item.name : item
const human = (item && typeof item === 'object' && 'human' in item) ? item.human : undefined
const opt = document.createElement('option')
opt.text = human || name
opt.value = name
select.add(opt)
})
})
const vhost = window.sessionStorage.getItem('vhost')
let url = 'api/exchanges'
if (vhost && vhost !== '_all') {
url += HTTP.url`/${vhost}`
}
const tableOptions = {
url,
keyColumns: ['vhost', 'name'],
pagination: true,
columnSelector: true,
search: true
}
const exchangeTable = Table.renderTable('table', tableOptions, function (tr, item, all) {
if (all) {
if (item.name === '') {
item.name = 'amq.default'
}
const features = document.createElement('span')
features.className = 'features'
if (item.durable) {
const durable = document.createElement('span')
durable.textContent = 'D'
durable.title = 'Durable'
features.appendChild(durable)
}
if (item.auto_delete) {
const autoDelete = document.createElement('span')
autoDelete.textContent = ' AD'
autoDelete.title = 'Auto Delete'
features.appendChild(autoDelete)
}
if (item.internal) {
const internal = document.createElement('span')
internal.textContent = ' I'
internal.title = 'Internal'
features.appendChild(internal)
}
if (item.arguments['x-delayed-exchange']) {
const delayed = document.createElement('span')
delayed.textContent = ' d'
delayed.title = 'Delayed'
features.appendChild(delayed)
}
const exchangeLink = document.createElement('a')
exchangeLink.href = HTTP.url`exchange#vhost=${item.vhost}&name=${item.name}`
exchangeLink.textContent = item.name
Table.renderCell(tr, 0, item.vhost)
Table.renderCell(tr, 1, exchangeLink)
Table.renderCell(tr, 2, item.type)
Table.renderCell(tr, 3, features, 'center')
}
let policyLink = ''
if (item.policy) {
policyLink = document.createElement('a')
policyLink.href = HTTP.url`policies#name=${item.policy}&vhost=${item.vhost}`
policyLink.textContent = item.policy
}
Table.renderCell(tr, 4, policyLink, 'center')
Table.renderCell(tr, 5, item.message_stats.publish_in_details.rate, 'center')
Table.renderCell(tr, 6, item.message_stats.publish_out_details.rate, 'center')
})
document.querySelector('#addExchange').addEventListener('submit', function (evt) {
evt.preventDefault()
const data = new window.FormData(this)
const vhost = data.get('vhost')
const exchange = data.get('name').trim()
const url = HTTP.url`api/exchanges/${vhost}/${exchange}`
const body = {
durable: data.get('durable') === '1',
auto_delete: data.get('auto_delete') === '1',
internal: data.get('internal') === '1',
delayed: data.get('delayed') === '1',
type: data.get('type'),
arguments: DOM.parseJSON(data.get('arguments'))
}
HTTP.submitForm(evt.target, 'PUT', url, {
body,
table: exchangeTable
}).then(() => {
DOM.toast(`Exhange ${exchange} created`)
})
})
document.querySelector('#dataTags').addEventListener('click', e => {
Helpers.argumentHelperJSON('addExchange', 'arguments', e)
})