From 7416a215513d79a56f385e6b72d00d26ae0504fe Mon Sep 17 00:00:00 2001 From: zhaoke Date: Fri, 28 Jul 2023 15:13:21 +0800 Subject: [PATCH] * Support install app by appid. --- module/instance/control.php | 2 +- module/instance/model.php | 12 ++++++------ module/space/control.php | 12 ++++++++---- module/space/js/browse.ui.js | 2 +- module/space/ui/createapplication.html.php | 13 +++++++++---- module/store/ui/browse.html.php | 2 +- 6 files changed, 26 insertions(+), 17 deletions(-) diff --git a/module/instance/control.php b/module/instance/control.php index b07de285ef..4ed9e41f52 100644 --- a/module/instance/control.php +++ b/module/instance/control.php @@ -438,7 +438,7 @@ class instance extends control if(!$instance) return $this->send(array('result' => 'fail', 'message' => $this->lang->instance->notices['installFail'])); unset($_GET['onlybody']); - $this->send(array('result' => 'success', 'message' => $this->lang->instance->notices['installSuccess'], 'locate' => $this->createLink('instance', 'view', "id=$instance->id", '', false))); + $this->send(array('result' => 'success', 'message' => $this->lang->instance->notices['installSuccess'], 'load' => $this->createLink('instance', 'view', "id=$instance->id"), 'closeModal' => true)); } $this->lang->switcherMenu = $this->instance->getInstallSwitcher($cloudApp); diff --git a/module/instance/model.php b/module/instance/model.php index 04dceb99a2..4d05b6a972 100644 --- a/module/instance/model.php +++ b/module/instance/model.php @@ -464,7 +464,7 @@ class InstanceModel extends model */ public function canDo($action, $instance) { - $busy = in_array($instance->status, array('creating', 'initializing', 'starting', 'stopping', 'suspending', 'pulling', 'destroying')); + // $busy = in_array($instance->status, array('creating', 'initializing', 'starting', 'stopping', 'suspending', 'pulling', 'destroying')); switch($action) { case 'start': @@ -2045,13 +2045,13 @@ class InstanceModel extends model */ public function isClickable(object $instance, string $action): bool { - if($action == 'start') return $instance->type == 'app' ? $this->canDo('start', $instance) : false; - if($action == 'stop') return $instance->type == 'app' ? $this->canDo('stop', $instance) : false; - if($action == 'uninstall') return $instance->type == 'app' && $this->canDo('uninstall', $instance); - if($action == 'visit') return $instance->type == 'app' ? ($instance->domain && $this->canDo('visit', $instance)) : true; + if($action == 'start') return $instance->type != 'external' ? $this->canDo('start', $instance) : false; + if($action == 'stop') return $instance->type != 'external' ? $this->canDo('stop', $instance) : false; + if($action == 'uninstall') return $instance->type != 'external' && $this->canDo('uninstall', $instance); + if($action == 'visit') return $instance->type != 'external' ? ($instance->domain && $this->canDo('visit', $instance)) : true; if($action == 'upgrade') return !empty($instance->latestVersion); if($action == 'bindUser') return ($instance->type == 'external' && in_array($instance->appName, array('Gitlab', 'Gitea', 'Gogs'))) ? true : false; - if($action == 'edit') return $instance->type == 'app' ? false : true; + if($action == 'edit') return $instance->type != 'external' ? false : true; return true; } diff --git a/module/space/control.php b/module/space/control.php index 6134e4d290..cec0ab0b96 100644 --- a/module/space/control.php +++ b/module/space/control.php @@ -94,10 +94,11 @@ class space extends control * 创建一个应用。 * Create a application. * + * @param int $appID * @access public * @return viod */ - public function createApplication() + public function createApplication($appID = 0) { $this->app->loadLang('sonarqube'); $this->app->loadLang('jenkins'); @@ -113,9 +114,12 @@ class space extends control $mysqlList = $this->cne->sharedDBList('mysql'); $pgList = $this->cne->sharedDBList('postgresql'); - $this->view->mysqlList = $mysqlList; - $this->view->pgList = $pgList; - $this->view->apps = $apps; + $this->view->apps = $apps; + $this->view->appID = $appID; + $this->view->pgList = $pgList; + $this->view->mysqlList = $mysqlList; + $this->view->addType = empty($appID) ? 'external' : 'store'; + $this->view->thirdDomain = $this->loadModel('instance')->randThirdDomain(); $this->display(); } diff --git a/module/space/js/browse.ui.js b/module/space/js/browse.ui.js index 4b55dfa35c..d23c2a16b7 100644 --- a/module/space/js/browse.ui.js +++ b/module/space/js/browse.ui.js @@ -61,7 +61,7 @@ window.afterPageUpdate = function() }); } }); - }, 5000); + }, 10000); } window.onPageUnmount = function() diff --git a/module/space/ui/createapplication.html.php b/module/space/ui/createapplication.html.php index c843e9cdd6..448bbf9b85 100644 --- a/module/space/ui/createapplication.html.php +++ b/module/space/ui/createapplication.html.php @@ -20,12 +20,13 @@ jsVar('apps', $apps); jsVar('mysqlList', $mysqlList); jsVar('pgList', $pgList); +$showVersion = getenv('ALLOW_SELECT_VERSION') && (strtolower(getenv('ALLOW_SELECT_VERSION')) == 'true' || strtolower(getenv('ALLOW_SELECT_VERSION')) == '1'); $dbTypeItems = array(); foreach($lang->instance->dbTypes as $type => $db) $dbTypeItems[] = array('text' => $db, 'value' => $type); formPanel ( - setClass('externalPanel'), + setClass('externalPanel' . (!$appID ? '' : ' hidden')), set::id('createAppForm'), set::title($lang->space->install), set::url($this->createLink('gitlab', 'create')), @@ -100,7 +101,7 @@ formPanel formPanel ( - setClass('hidden storePanel'), + setClass('storePanel' . ($appID ? '' : ' hidden')), set::id('createStoreAppForm'), set::title($lang->space->install), formGroup @@ -109,6 +110,8 @@ formPanel set::label($lang->app->common), set::name('storeAppType'), set::items($apps), + set::value($appID), + set::disabled(!!$appID), set::required(true), on::change('onChangeStoreAppType'), ), @@ -116,7 +119,8 @@ formPanel ( set::label($lang->space->addType), set::name('storetype'), - set::value('store'), + set::value($addType), + set::disabled(!!$appID), set::control('radioListInline'), set::items(array(array('text' => $lang->store->common, 'value' => 'store'), array('text' => $lang->space->handConfig, 'value' => 'external'))), set::required(true), @@ -127,7 +131,7 @@ formPanel set::width('1/2'), set::label($lang->instance->version), set::name('app_version'), - set::readonly(true), + set::readonly(!$showVersion), set::required(true), input ( @@ -148,6 +152,7 @@ formPanel ( setClass('form-control'), set::name('customDomain'), + set::value($thirdDomain), ), input ( diff --git a/module/store/ui/browse.html.php b/module/store/ui/browse.html.php index 2c539df1c7..192e8a6fd4 100644 --- a/module/store/ui/browse.html.php +++ b/module/store/ui/browse.html.php @@ -72,7 +72,7 @@ foreach ($cloudApps as $group) setClass('primary btn size-sm install-btn'), setData('prevent', true), setData('toggle', 'modal'), - setData('url', $this->createLink('instance', 'install', "id={$cloudApp->id}")), + setData('url', $this->createLink('space', 'createApplication', "id={$cloudApp->id}")), on::click('installApp', array('stop' => true)), ) )