* Fix cancel btn status when install fail.

This commit is contained in:
zhaoke
2023-09-25 13:54:39 +08:00
parent dd90e50f48
commit d6c6bdb924
4 changed files with 46 additions and 30 deletions
+23 -7
View File
@@ -358,17 +358,12 @@ class install extends control
$this->send(array('result' => 'success', 'message' => $this->lang->solution->notices->success, 'data' => $solution, 'locate' => $this->inLink('progress', "id={$solution->id}&install=true")));
}
$clusterResource = $this->loadModel('cne')->cneMetrics();
$freeMemory = intval($clusterResource->metrics->memory->allocatable * 0.9);
$appMap = $this->loadModel('store')->getAppMapByNames(array_keys($cloudSolution->apps));
$category = helper::arrayColumn($components->category, 'name');
$category = array_filter($category, function($cate){return $cate !== 'pms';});
$category = helper::arrayColumn($components->category, 'name');
$category = array_filter($category, function($cate){return $cate !== 'pms';});
$this->view->title = $this->lang->solution->install;
$this->view->cloudSolution = $cloudSolution;
$this->view->components = $components;
$this->view->appMap = $appMap;
$this->view->freeMemory = $freeMemory;
$this->view->category = $category;
$this->display();
@@ -480,4 +475,25 @@ class install extends control
$this->send(array('result' => 'success', 'message' => '', 'locate' => $this->inLink('index')));
}
/**
* Check memory and cpu.
* 检查内存与CPU是否满足安装所需。
*
* @param int $solutionID
* @access public
* @return void
*/
public function ajaxCheck()
{
$this->loadModel('common');
$data = fixer::input('post')->get();
$appMap = $this->loadModel('store')->getAppMapByNames($data->apps);
$resources = array();
foreach($data->apps as $app) $resources[] = array('cpu' => $appMap->$app->cpu, 'memory' => $appMap->$app->memory);
$result = $this->loadModel('cne')->tryAllocate($resources);
$this->send(array('result' => 'success', 'message' => '', 'code' => $result->code));
}
}
+15 -11
View File
@@ -46,22 +46,26 @@ $(function()
*/
function checkMemory()
{
var memory = 0;
var apps = [];
$.each(category, (index, cate) =>
{
var item = $('#' + cate).val();
memory += appMap[item].memory;
apps.push(item);
});
if(freeMemory < memory)
$.post(createLink('install', 'ajaxCheck'), {apps: apps}).done(function(response)
{
$('#skipBtn').show();
$('#overMemoryNotice').show();
$('#submitBtn').attr('disabled', true);
return;
}
var res = JSON.parse(response);
if(res.code == undefined || res.code == 41010)
{
$('#skipBtn').show();
$('#overMemoryNotice').show();
$('#submitBtn').attr('disabled', true);
return;
}
$('#skipBtn').hide();
$('#overMemoryNotice').hide();
$('#submitBtn').attr('disabled', false);
$('#skipBtn').hide();
$('#overMemoryNotice').hide();
$('#submitBtn').attr('disabled', false);
});
}
+7 -11
View File
@@ -68,6 +68,7 @@ $(function()
{
$('#retryInstallBtn').show();
$('#skipInstallBtn').show();
$('#cancelInstallBtn').hide();
$('.progress.loading').hide();
var errMessage = res.message;
@@ -116,6 +117,8 @@ $(function()
if(!result) return;
$('#retryInstallBtn').hide();
$('#skipInstallBtn').hide();
$('#cancelInstallBtn').show();
$('.error-message').text('');
$('.progress.loading').show();
@@ -138,18 +141,11 @@ $(function()
});
});
if(hasError && !startInstall)
{
$('#retryInstallBtn').show();
$('#skipInstallBtn').show();
}
else
{
$('#retryInstallBtn').hide();
$('#skipInstallBtn').hide();
}
$('#retryInstallBtn').hide();
$('#skipInstallBtn').hide();
$('#cancelInstallBtn').show();
if(startInstall)
if('true' === startInstall)
{
$.get(createLink('install', 'ajaxInstall', 'id=' + solutionID)).done(function(response){});
}
+1 -1
View File
@@ -48,7 +48,7 @@
</div>
<div class='error-message text-red text-center'></div>
<div class='form-actions text-center'>
<?php echo html::a(inlink('step6'), $lang->install->solution->skip, 'id="skipInstallBtn"', "class='btn btn-install btn-wide' style='display: none;'");?>
<?php echo html::a(inlink('step6'), $lang->install->solution->skip, '', "class='btn btn-install btn-wide' style='display: none;' id='skipInstallBtn'");?>
<?php echo html::commonButton($lang->solution->retryInstall, "id='retryInstallBtn' class='hide'", 'btn btn-primary btn-wide');?>
<?php echo html::commonButton($lang->solution->cancelInstall, "id='cancelInstallBtn'", 'btn btn-primary btn-wide');?>
</div>