Skip to content

Commit

Permalink
Update PriceInfo Request page in AdminWeb
Browse files Browse the repository at this point in the history
  • Loading branch information
powerkimhub committed Jan 15, 2024
1 parent 61c0364 commit f1a8b63
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 17 deletions.
2 changes: 1 addition & 1 deletion api-runtime/rest-runtime/CBSpiderRuntime.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ func RunServer() {
{"GET", "/adminweb/vmimage/:ConnectConfig", aw.VMImage},
{"GET", "/adminweb/vmspec/:ConnectConfig", aw.VMSpec},
{"GET", "/adminweb/regionzone/:ConnectConfig", aw.RegionZone},
{"GET", "/adminweb/priceinforequest/:ConnectConfig", aw.RiceInfoRequest},
{"GET", "/adminweb/priceinforequest/:ConnectConfig", aw.PRiceInfoRequest},

{"GET", "/adminweb/cluster/:ConnectConfig", aw.Cluster},
{"GET", "/adminweb/clustermgmt/:ConnectConfig", aw.ClusterMgmt},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ import (
)

func productFamilyList() []string {
return []string{"Compute", "Storage", "Database"}
return []string{"Select a Region first"}
}

func regionList() []string {
return []string{"us-east-1", "us-west-1", "eu-central-1"}
return []string{"No regions available"}
}

//====================================== PriceInfo Request

func RiceInfoRequest(c echo.Context) error {
func PRiceInfoRequest(c echo.Context) error {
cblog.Info("call RequestRiceInfo()")

connConfig := c.Param("ConnectConfig")
Expand Down Expand Up @@ -82,12 +82,14 @@ func RiceInfoRequest(c echo.Context) error {

type PageData struct {
LoggingUrl template.JS
ConnectionName string
RegionList []string
ProductFamilyList []string
LoggingResult template.JS
}

data := PageData{
ConnectionName: connConfig,
RegionList: regionNameList,
ProductFamilyList: productFamilyList(),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@
position: absolute;
top: 50%;
left: 50%;
width: 70%;
height: 70%;
width: 90%;
height: 90%;
transform: translate(-50%, -50%);
background-color: white;
border: none;
Expand All @@ -100,6 +100,7 @@
</style>
</head>
<body>
<input type="hidden" id="connectionName" value="{{.ConnectionName}}">
<div class="container">
<h2>Multi-Cloud Price Info</h2>
<form id="filterForm">
Expand Down Expand Up @@ -138,12 +139,13 @@ <h2>Multi-Cloud Price Info</h2>
</div>

<script>
// Example data - Replace with actual function calls
const productFamilies = productFamilyList();
const regions = regionList();

function populateSelect(selectId, options) {
const select = document.getElementById(selectId);
// Remove all existing options
while (select.options.length > 0) {
select.remove(0);
}
options.forEach(option => {
let opt = document.createElement('option');
opt.value = option;
Expand All @@ -152,13 +154,33 @@ <h2>Multi-Cloud Price Info</h2>
});
}

// Populate the select boxes
populateSelect('productFamily', productFamilies);
populateSelect('region', regions);
document.getElementById('region').addEventListener('change', function() {
const selectedRegion = this.value;
const connectionName = document.getElementById('connectionName').value;
updateProductFamilyList(selectedRegion, connectionName);
});

// Replace the above example data with actual function calls
// populateSelect('productFamily', productFamilyList());
// populateSelect('region', regionList());
function updateProductFamilyList(region, connectionName) {
// Clear the product family select box and show a fetching message
const productFamilySelect = document.getElementById('productFamily');
productFamilySelect.innerHTML = '<option>fetching</option>';
let fetchText = 'fetching';
let intervalId = setInterval(() => {
fetchText += '.';
productFamilySelect.innerHTML = `<option>${fetchText}</option>`;
}, 100);

fetch(`/spider/productfamily/${region}?ConnectionName=${connectionName}`)
.then(response => response.json())
.then(productFamilies => {
clearInterval(intervalId); // stop the interval
populateSelect('productFamily', productFamilies);
})
.catch(error => {
console.error('Error:', error);
clearInterval(intervalId); // stop the interval
});
}

function openOverlay() {
document.getElementById('overlay').style.display = 'block';
Expand All @@ -172,8 +194,7 @@ <h2>Multi-Cloud Price Info</h2>

function setFilter(filterContent) {
document.getElementById('filter').value = filterContent;
document.getElementById('overlay').style.display = 'none';
document.getElementById('overlayContent').src = '';
closeOverlay();
}
</script>
</body>
Expand Down

0 comments on commit f1a8b63

Please sign in to comment.