Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance UI of Disk Selection in VM Creation Phase #1431

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 63 additions & 59 deletions api-runtime/rest-runtime/admin-web/html/vm.html
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,31 @@
transform: translateX(-100%);
animation: progress-animation 3s linear infinite;
}
.checkbox-wrapper {
display: block;
margin-right: 0px;
}

.checkbox-wrapper input[type="checkbox"] {
margin-right: 5px;
}

#dataDiskSelect {
border: 1px solid black;
padding: 10px;
width: 60%;
overflow-y: auto;
overflow-x: auto;
margin: 0 auto;
white-space: normal;
max-height:300px;
}

#diskSelect p {
margin: 5px 0;
color: red;
font-size: 14px;
}

@keyframes progress-animation {
0% {
Expand Down Expand Up @@ -866,9 +891,7 @@ <h2>Add New VM</h2>

<div class="form-group">
<label for="dataDiskSelect">Data Disk Names:</label>
<select id="dataDiskSelect" name="dataDiskSelect" multiple>
<option value="">Select a Subnet first...</option>
</select>
<div id="dataDiskSelect" name="dataDiskSelect"></div>
</div>

<div class="form-group">
Expand Down Expand Up @@ -1249,8 +1272,8 @@ <h2>System ID (Managed by CSP)</h2>
SubnetName: document.getElementById('subnetSelect').value,
SecurityGroupNames: [document.getElementById('securityGroupSelect').value],
RootDiskType: document.getElementById('rootDiskType').value,
RootDiskSize: document.getElementById('rootDiskSize').value || undefined,
DataDiskNames: Array.from(document.getElementById('dataDiskSelect').selectedOptions).map(option => option.value),
RootDiskSize: document.getElementById('rootDiskSize').value || undefined,
DataDiskNames: Array.from(document.querySelectorAll('#dataDiskSelect input[type="checkbox"]:checked')).map(checkbox => checkbox.value),
KeyPairName: document.getElementById('keypairSelect').value,
VMUserId: document.getElementById('vmUserId').value,
VMUserPasswd: document.getElementById('vmUserPasswd').value,
Expand Down Expand Up @@ -1341,9 +1364,6 @@ <h2>System ID (Managed by CSP)</h2>
document.getElementById('overlay').style.display = 'flex';
document.addEventListener('keydown', handleEsc);
clearFormFields();

const dataDiskSelect = document.getElementById('dataDiskSelect');
dataDiskSelect.selectedIndex = -1;
}

function clearFormFields() {
Expand Down Expand Up @@ -1699,7 +1719,7 @@ <h2>System ID (Managed by CSP)</h2>
const vpcSelect = document.getElementById('vpcSelect');
const selectedSubnets = JSON.parse(vpcSelect.value);
const subnetSelect = document.getElementById('subnetSelect');
const dataDiskSelect = document.getElementById('dataDiskSelect');
const dataDiskSelect = document.getElementById('dataDiskSelect'); // here

subnetSelect.innerHTML = '';

Expand All @@ -1716,7 +1736,6 @@ <h2>System ID (Managed by CSP)</h2>
loadDataDisks(firstSubnetZone);
} else {
subnetSelect.innerHTML = '<option>No subnets available for this VPC.</option>';
dataDiskSelect.innerHTML = '<option>Select a Subnet first...</option>';
}
}

Expand Down Expand Up @@ -2053,37 +2072,54 @@ <h2>SSH Access</h2>
}
});

function loadDataDisks() {
const vmZone = document.getElementById('vmZone').value;
function loadDataDisks(zone) {
const connConfig = document.getElementById('connConfig').value;

fetch('/spider/disk', {
fetch(`/spider/disk?ConnectionName=${connConfig}`, {
method: 'GET',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ ConnectionName: connConfig })
}
})
.then(response => response.json())
.then(data => {
const diskSelect = document.getElementById('dataDiskSelect');
diskSelect.innerHTML = '';

if (data.disk && data.disk.length > 0) {
data.disk.forEach(disk => {
if (disk.Zone === vmZone && disk.Status === "Available") {
const option = document.createElement('option');
option.value = disk.IId.NameId;
option.textContent = `${disk.IId.NameId} (${disk.DiskSize} GB)`;
diskSelect.appendChild(option);
console.log(data);

const filteredDisks = data.disk.filter(disk => disk.Zone === zone && disk.Status === "Available");

if (filteredDisks.length > 0){
console.log(filteredDisks);
filteredDisks.forEach(disk => {
if (disk.Zone === zone && disk.Status === "Available"){
const checkboxWrapper = document.createElement('div');
checkboxWrapper.className = 'checkbox-wrapper';

const checkbox = document.createElement('input');
checkbox.type = 'checkbox';
checkbox.name = 'disks';
checkbox.value = disk.IId.NameId;
checkbox.id = `disk-${disk.IId.NameId}`;

const label = document.createElement('label');
label.htmlFor = `disk-${disk.IId.NameId}`;
label.textContent = `${disk.IId.NameId} (${disk.DiskSize} GB)`;

checkboxWrapper.appendChild(checkbox);
checkboxWrapper.appendChild(label);

diskSelect.appendChild(checkboxWrapper);
}
});
} else {
diskSelect.innerHTML = '<option>No disks available in the same zone.</option>';
const noDiskMessage = document.createElement('p');
noDiskMessage.textContent = 'No disks available in the same zone.';
noDiskMessage.style.color = 'red';
diskSelect.appendChild(noDiskMessage);
}
})
.catch(error => {
alert('Error loading data disks: ' + error.message);
}).catch(error =>{
alert("Error loading data disks: " + error.message);
});
}

Expand All @@ -2092,38 +2128,6 @@ <h2>SSH Access</h2>
loadDataDisks(selectedZone);
});

function loadDataDisks(zone) {
const connConfig = document.getElementById('connConfig').value;

fetch(`/spider/disk?ConnectionName=${connConfig}`, {
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
})
.then(response => response.json())
.then(data => {
const diskSelect = document.getElementById('dataDiskSelect');
diskSelect.innerHTML = '';

if (data.disk && data.disk.length > 0) {
data.disk.forEach(disk => {
if (disk.Zone === zone && disk.Status === "Available") {
const option = document.createElement('option');
option.value = disk.IId.NameId;
option.textContent = `${disk.IId.NameId} (${disk.DiskSize} GB)`;
diskSelect.appendChild(option);
}
});
} else {
diskSelect.innerHTML = '<option>No disks available in the same zone.</option>';
}
})
.catch(error => {
alert('Error loading data disks: ' + error.message);
});
}

function showMiscOverlay(button) {
const miscContent = button.previousElementSibling.innerHTML;
document.getElementById('miscContent').innerHTML = `<div>${miscContent}</div>`;
Expand Down