|
|
|
|
@ -241,24 +241,6 @@ function routeChanged() {
|
|
|
|
|
byId('cloud-vpcs-workspace')?.scrollIntoView({ block: 'start' });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function tableCell(className, label, content) {
|
|
|
|
|
const cell = element('td', className, content);
|
|
|
|
|
cell.dataset.label = label;
|
|
|
|
|
return cell;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function tableHeader(labels) {
|
|
|
|
|
const head = element('thead');
|
|
|
|
|
const row = element('tr');
|
|
|
|
|
for (const label of labels) {
|
|
|
|
|
const cell = element('th', '', label);
|
|
|
|
|
cell.scope = 'col';
|
|
|
|
|
row.append(cell);
|
|
|
|
|
}
|
|
|
|
|
head.append(row);
|
|
|
|
|
return head;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function selectionForVpc(vpc, action) {
|
|
|
|
|
const key = `${vpcKey(vpc)}:${action}`;
|
|
|
|
|
if (!state.selections.has(key)) state.selections.set(key, new Set());
|
|
|
|
|
@ -402,20 +384,25 @@ function canSelectInstance(instance, action, batchBlocked) {
|
|
|
|
|
function renderInstanceRow(instance, vpc, joining, checkbox) {
|
|
|
|
|
const id = instanceId(instance);
|
|
|
|
|
const port = instance.port || {};
|
|
|
|
|
const row = element('tr', 'cloud-vpc-instance-row');
|
|
|
|
|
const row = element('article', 'cloud-vpc-instance-card cloud-vpc-instance-row');
|
|
|
|
|
row.setAttribute('role', 'listitem');
|
|
|
|
|
row.classList.toggle('selected', checkbox.checked);
|
|
|
|
|
const select = tableCell('cloud-vpc-table-select', '选择');
|
|
|
|
|
select.append(checkbox);
|
|
|
|
|
const identity = tableCell('cloud-vpc-instance-identity', '实例');
|
|
|
|
|
const select = element('label', 'cloud-vpc-instance-select');
|
|
|
|
|
select.append(checkbox, element('span', 'sr-only', `选择 ${instance.name || id}`));
|
|
|
|
|
const identity = element('div', 'cloud-vpc-instance-identity');
|
|
|
|
|
const link = element('a', 'cloud-vpc-name-link', instance.name || `实例 #${id}`);
|
|
|
|
|
link.href = `/user/cloud/instances/${encodeURIComponent(id)}`;
|
|
|
|
|
identity.append(link);
|
|
|
|
|
const publicAddress = tableCell('cloud-vpc-table-address', '公网 IPv4');
|
|
|
|
|
publicAddress.append(element('code', '', publicIpv4(instance)));
|
|
|
|
|
const privateAddress = tableCell('cloud-vpc-table-address cloud-vpc-private-address',
|
|
|
|
|
joining ? '私网分配' : '私网 IPv4');
|
|
|
|
|
privateAddress.append(element(joining ? 'span' : 'code', '', joining
|
|
|
|
|
const facts = element('dl', 'cloud-vpc-instance-facts');
|
|
|
|
|
const publicAddress = element('div');
|
|
|
|
|
const publicValue = element('dd');
|
|
|
|
|
publicValue.append(element('code', '', publicIpv4(instance)));
|
|
|
|
|
publicAddress.append(element('dt', '', '公网 IPv4'), publicValue);
|
|
|
|
|
const privateAddress = element('div', 'cloud-vpc-private-address');
|
|
|
|
|
const privateValue = element('dd');
|
|
|
|
|
privateValue.append(element(joining ? 'span' : 'code', '', joining
|
|
|
|
|
? '自动分配' : port.private_ip || '待分配'));
|
|
|
|
|
privateAddress.append(element('dt', '', joining ? '私网分配' : '私网 IPv4'), privateValue);
|
|
|
|
|
if (!joining && port.mac_address) {
|
|
|
|
|
const details = element('details', 'cloud-vpc-mac');
|
|
|
|
|
details.open = state.expandedMacs.has(id);
|
|
|
|
|
@ -424,8 +411,9 @@ function renderInstanceRow(instance, vpc, joining, checkbox) {
|
|
|
|
|
if (details.open) state.expandedMacs.add(id);
|
|
|
|
|
else state.expandedMacs.delete(id);
|
|
|
|
|
});
|
|
|
|
|
privateAddress.append(details);
|
|
|
|
|
privateValue.append(details);
|
|
|
|
|
}
|
|
|
|
|
facts.append(publicAddress, privateAddress);
|
|
|
|
|
|
|
|
|
|
const batchItem = activeBatchItemForInstance(vpc, instance);
|
|
|
|
|
const [label, type] = batchItem
|
|
|
|
|
@ -433,7 +421,7 @@ function renderInstanceRow(instance, vpc, joining, checkbox) {
|
|
|
|
|
: joining
|
|
|
|
|
? (instance.can_attach === true ? ['可加入', 'running'] : ['暂不可加入', 'other'])
|
|
|
|
|
: PORT_STATE_LABELS[String(port.state || '')] || ['状态待确认', 'other'];
|
|
|
|
|
const status = tableCell('cloud-vpc-instance-status', '状态');
|
|
|
|
|
const status = element('div', 'cloud-vpc-instance-status');
|
|
|
|
|
status.append(element('span', `state-pill ${type}`, label));
|
|
|
|
|
if (!batchItem && instance.action_unavailable_reason) {
|
|
|
|
|
status.append(element('small', '', instance.action_unavailable_reason));
|
|
|
|
|
@ -452,7 +440,7 @@ function renderInstanceRow(instance, vpc, joining, checkbox) {
|
|
|
|
|
void mutatePort(instance, vpc, action === 'retry_attach' ? 'attach' : 'detach'));
|
|
|
|
|
status.append(retry);
|
|
|
|
|
}
|
|
|
|
|
row.append(select, identity, publicAddress, privateAddress, status);
|
|
|
|
|
row.append(select, identity, facts, status);
|
|
|
|
|
return row;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -494,9 +482,6 @@ function renderInstanceManager(vpc, joining) {
|
|
|
|
|
searchField.append(search);
|
|
|
|
|
section.append(searchField);
|
|
|
|
|
}
|
|
|
|
|
const table = element('table', 'cloud-vpc-table cloud-vpc-member-table');
|
|
|
|
|
table.setAttribute('aria-label', joining ? '可加入实例' : '已加入实例');
|
|
|
|
|
const header = tableHeader(['', '实例', '公网 IPv4', joining ? '私网分配' : '私网 IPv4', '状态']);
|
|
|
|
|
const selectAll = element('input');
|
|
|
|
|
selectAll.type = 'checkbox';
|
|
|
|
|
selectAll.dataset.vpcFocus = 'select-all';
|
|
|
|
|
@ -504,9 +489,11 @@ function renderInstanceManager(vpc, joining) {
|
|
|
|
|
selectAll.disabled = eligibleIds.size === 0;
|
|
|
|
|
const selectAllLabel = element('label', 'cloud-vpc-select-all');
|
|
|
|
|
selectAllLabel.append(selectAll, element('span', '', joining ? '全选可加入实例' : '全选可移出实例'));
|
|
|
|
|
header.querySelector('th').append(selectAllLabel);
|
|
|
|
|
table.append(header);
|
|
|
|
|
const body = element('tbody');
|
|
|
|
|
const controls = element('div', 'cloud-vpc-list-controls');
|
|
|
|
|
controls.append(selectAllLabel);
|
|
|
|
|
const list = element('div', 'cloud-vpc-instance-list');
|
|
|
|
|
list.setAttribute('role', 'list');
|
|
|
|
|
list.setAttribute('aria-label', joining ? '可加入实例' : '已加入实例');
|
|
|
|
|
const checks = [];
|
|
|
|
|
const countLabel = element('span');
|
|
|
|
|
countLabel.setAttribute('role', 'status');
|
|
|
|
|
@ -553,7 +540,7 @@ function renderInstanceManager(vpc, joining) {
|
|
|
|
|
updateControls();
|
|
|
|
|
});
|
|
|
|
|
checks.push({ id, checkbox, row, instance });
|
|
|
|
|
body.append(row);
|
|
|
|
|
list.append(row);
|
|
|
|
|
}
|
|
|
|
|
selectAll.addEventListener('change', () => {
|
|
|
|
|
for (const { id, row } of checks) {
|
|
|
|
|
@ -566,7 +553,6 @@ function renderInstanceManager(vpc, joining) {
|
|
|
|
|
clear.addEventListener('click', () => { selection.clear(); updateControls(); });
|
|
|
|
|
submit.addEventListener('click', () => void submitMembershipBatch(vpc, action,
|
|
|
|
|
instances.filter(item => selection.has(instanceId(item)) && eligibleIds.has(instanceId(item)))));
|
|
|
|
|
table.append(body);
|
|
|
|
|
const noMatches = emptyState('没有匹配的实例', '请尝试其他实例名称或公网 IP。');
|
|
|
|
|
noMatches.classList.add('cloud-vpc-search-empty');
|
|
|
|
|
noMatches.hidden = true;
|
|
|
|
|
@ -588,7 +574,7 @@ function renderInstanceManager(vpc, joining) {
|
|
|
|
|
search?.addEventListener('input', applySearch);
|
|
|
|
|
const toolbar = element('div', 'cloud-vpc-batch-toolbar');
|
|
|
|
|
toolbar.append(countLabel, clear, submit);
|
|
|
|
|
section.append(table, noMatches, toolbar);
|
|
|
|
|
section.append(controls, list, noMatches, toolbar);
|
|
|
|
|
applySearch();
|
|
|
|
|
return section;
|
|
|
|
|
}
|
|
|
|
|
|