From ba8cd0be5c00c8f87e24cd06a3a0451194e73a99 Mon Sep 17 00:00:00 2001 From: zhaoke Date: Thu, 3 Aug 2023 14:04:01 +0800 Subject: [PATCH] * Refactor view and browse of store. --- config/zentaopms.php | 3 +- lib/zin/wg/backbtn/v1.php | 2 + module/gitea/ui/edit.html.php | 2 + module/gitlab/ui/edit.html.php | 2 + module/gogs/ui/edit.html.php | 2 + module/instance/control.php | 2 +- module/instance/ui/view.html.php | 1 - module/jenkins/ui/edit.html.php | 2 + module/sonarqube/ui/edit.html.php | 2 + module/space/control.php | 8 ++- module/space/js/createapplication.ui.js | 2 +- module/space/ui/browse.html.php | 13 +++- module/space/ui/createapplication.html.php | 76 ++++++++++++++-------- module/store/control.php | 6 +- module/store/js/browse.ui.js | 15 +++++ module/store/lang/en.php | 27 ++++++++ module/store/lang/zh-cn.php | 1 + module/store/model.php | 19 +++++- module/store/ui/appview.html.php | 19 ++---- module/store/ui/browse.html.php | 3 +- module/store/zen.php | 33 ++++++++++ 21 files changed, 188 insertions(+), 52 deletions(-) create mode 100644 module/store/lang/en.php create mode 100644 module/store/zen.php diff --git a/config/zentaopms.php b/config/zentaopms.php index b844d4b7dc..f234725ce8 100644 --- a/config/zentaopms.php +++ b/config/zentaopms.php @@ -240,7 +240,8 @@ $config->openMethods[] = 'custom.index'; $config->openMethods[] = 'testcase.getxmindimport'; $config->openMethods[] = 'testcase.showxmindimport'; $config->openMethods[] = 'testcase.savexmindimport'; -$config->openMethods[] = 'search.buildZinForm'; +$config->openMethods[] = 'search.buildzinform'; +$config->openMethods[] = 'space.createapplication'; $config->openModules = array(); $config->openModules[] = 'install'; diff --git a/lib/zin/wg/backbtn/v1.php b/lib/zin/wg/backbtn/v1.php index 8e53e04d60..9838f0c444 100644 --- a/lib/zin/wg/backbtn/v1.php +++ b/lib/zin/wg/backbtn/v1.php @@ -60,6 +60,8 @@ class backBtn extends btn 'mr' => 'mr-browse', 'repo' => 'repo-log,repo-browse', 'compile' => 'compile-browse', + 'store' => 'store-browse', + 'space' => 'store-browse', ); $props = parent::getProps(); diff --git a/module/gitea/ui/edit.html.php b/module/gitea/ui/edit.html.php index b2c3ba2d48..5e7745de69 100644 --- a/module/gitea/ui/edit.html.php +++ b/module/gitea/ui/edit.html.php @@ -16,6 +16,8 @@ formPanel ( set::id('giteaCreateForm'), set::title($lang->gitea->edit), + set::submitBtnText($lang->save), + set::actions(array('submit', array('text' => $lang->cancel, 'data-type' => 'submit', 'data-dismiss' => 'modal'))), formRow ( formGroup diff --git a/module/gitlab/ui/edit.html.php b/module/gitlab/ui/edit.html.php index 394dc90ba4..01222a2fe9 100644 --- a/module/gitlab/ui/edit.html.php +++ b/module/gitlab/ui/edit.html.php @@ -16,6 +16,8 @@ formPanel ( set::id('gitlabCreateForm'), set::title($lang->gitlab->edit), + set::submitBtnText($lang->save), + set::actions(array('submit', array('text' => $lang->cancel, 'data-type' => 'submit', 'data-dismiss' => 'modal'))), formRow ( formGroup diff --git a/module/gogs/ui/edit.html.php b/module/gogs/ui/edit.html.php index 6758c48491..7543d6ffaa 100644 --- a/module/gogs/ui/edit.html.php +++ b/module/gogs/ui/edit.html.php @@ -16,6 +16,8 @@ formPanel ( set::id('gogsCreateForm'), set::title($lang->gogs->edit), + set::submitBtnText($lang->save), + set::actions(array('submit', array('text' => $lang->cancel, 'data-type' => 'submit', 'data-dismiss' => 'modal'))), formRow ( formGroup diff --git a/module/instance/control.php b/module/instance/control.php index 4ed9e41f52..8d379d9e52 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'], 'load' => $this->createLink('instance', 'view', "id=$instance->id"), 'closeModal' => true)); + return $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/ui/view.html.php b/module/instance/ui/view.html.php index e2db61f6fc..940b3b180d 100644 --- a/module/instance/ui/view.html.php +++ b/module/instance/ui/view.html.php @@ -200,7 +200,6 @@ div setClass('basis-auto'), history ( - set::commentBtn(true), set::commentUrl(createLink('action', 'comment', array('objectType' => 'instance', 'objectID' => $instance->id))), ) ) diff --git a/module/jenkins/ui/edit.html.php b/module/jenkins/ui/edit.html.php index c8c49f98d0..99f4e5843c 100644 --- a/module/jenkins/ui/edit.html.php +++ b/module/jenkins/ui/edit.html.php @@ -16,6 +16,8 @@ formPanel ( set::id('jenkinsCreateForm'), set::title($lang->jenkins->edit), + set::submitBtnText($lang->save), + set::actions(array('submit', array('text' => $lang->cancel, 'data-type' => 'submit', 'data-dismiss' => 'modal'))), formRow ( formGroup diff --git a/module/sonarqube/ui/edit.html.php b/module/sonarqube/ui/edit.html.php index 7ba04ad7db..456c69f7a4 100644 --- a/module/sonarqube/ui/edit.html.php +++ b/module/sonarqube/ui/edit.html.php @@ -16,6 +16,8 @@ formPanel ( set::id('sonarqubeCreateForm'), set::title($lang->sonarqube->editServer), + set::submitBtnText($lang->save), + set::actions(array('submit', array('text' => $lang->cancel, 'data-type' => 'submit', 'data-dismiss' => 'modal'))), formRow ( formGroup diff --git a/module/space/control.php b/module/space/control.php index cec0ab0b96..78a5639949 100644 --- a/module/space/control.php +++ b/module/space/control.php @@ -100,6 +100,8 @@ class space extends control */ public function createApplication($appID = 0) { + if(!commonModel::hasPriv('instance', 'create')) $this->loadModel('common')->deny('instance', 'create', false); + $this->app->loadLang('sonarqube'); $this->app->loadLang('jenkins'); $this->loadModel('cne'); @@ -111,13 +113,15 @@ class space extends control $apps[$app->id] = $app->alias; } - $mysqlList = $this->cne->sharedDBList('mysql'); - $pgList = $this->cne->sharedDBList('postgresql'); + $mysqlList = $this->cne->sharedDBList('mysql'); + $pgList = $this->cne->sharedDBList('postgresql'); + $versionList = $this->store->getVersionPairs($appID); $this->view->apps = $apps; $this->view->appID = $appID; $this->view->pgList = $pgList; $this->view->mysqlList = $mysqlList; + $this->view->versionList = $versionList; $this->view->addType = empty($appID) ? 'external' : 'store'; $this->view->thirdDomain = $this->loadModel('instance')->randThirdDomain(); $this->display(); diff --git a/module/space/js/createapplication.ui.js b/module/space/js/createapplication.ui.js index f7590d188b..2a50b7f23f 100644 --- a/module/space/js/createapplication.ui.js +++ b/module/space/js/createapplication.ui.js @@ -12,7 +12,7 @@ function onChangeType(event) { $('.storePanel').removeClass('hidden'); $('.externalPanel').addClass('hidden'); - $('#storetype_store').prop('checked', true); + $('#type_store').prop('checked', true); } } diff --git a/module/space/ui/browse.html.php b/module/space/ui/browse.html.php index f3f5073f53..f4aea19c57 100644 --- a/module/space/ui/browse.html.php +++ b/module/space/ui/browse.html.php @@ -10,7 +10,9 @@ declare(strict_types=1); */ namespace zin; -$statusMap = array(); +$statusMap = array(); +$canInstall = hasPriv('instance', 'create'); + foreach($instances as $instance) if(!$instance->externalID) $statusMap[$instance->id] = $instance->status; jsVar('statusMap', $statusMap); jsVar('idList', array_keys($statusMap)); @@ -25,7 +27,14 @@ featureBar toolBar ( - hasPriv('instance', 'create') ? item(set(array + $canInstall ? item(set(array + ( + 'text' => $lang->store->cloudStore, + 'icon' => 'program', + 'class' => 'btn ghost', + 'url' => createLink('store', 'browse'), + ))) : null, + $canInstall ? item(set(array ( 'text' => $lang->space->install, 'icon' => 'plus', diff --git a/module/space/ui/createapplication.html.php b/module/space/ui/createapplication.html.php index 448bbf9b85..de0f678ccc 100644 --- a/module/space/ui/createapplication.html.php +++ b/module/space/ui/createapplication.html.php @@ -104,35 +104,64 @@ formPanel setClass('storePanel' . ($appID ? '' : ' hidden')), set::id('createStoreAppForm'), set::title($lang->space->install), - formGroup + formRow + ( + setStyle('display', $appID ? 'block' : 'none'), + formGroup + ( + set::width('1/2'), + set::label($lang->instance->name), + set::name('customName'), + set::control('input'), + set::value($appID ? $apps[$appID] : ''), + set::required(true), + ) + ), + formRow + ( + setStyle('display', $appID ? 'none' : 'block'), + formGroup + ( + set::width('1/2'), + set::label($lang->app->common), + set::name('storeAppType'), + set::items($apps), + set::value($appID), + set::disabled(!!$appID), + set::required(true), + on::change('onChangeStoreAppType'), + ) + ), + formRow + ( + setStyle('display', $appID ? 'none' : 'block'), + formGroup + ( + set::label($lang->space->addType), + set::name('type'), + set::value('store'), + 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), + on::change('onChangeType'), + ) + ), + $showVersion ? formGroup ( set::width('1/2'), - set::label($lang->app->common), - set::name('storeAppType'), - set::items($apps), - set::value($appID), - set::disabled(!!$appID), + set::label($lang->instance->version), + set::name('version'), set::required(true), - on::change('onChangeStoreAppType'), - ), - formGroup - ( - set::label($lang->space->addType), - set::name('storetype'), - 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), - on::change('onChangeType'), - ), - formGroup + set::control('picker'), + set::items($versionList) + ) : formGroup ( set::width('1/2'), set::label($lang->instance->version), set::name('app_version'), - set::readonly(!$showVersion), set::required(true), + set::readonly(true), input ( set::type('hidden'), @@ -154,11 +183,6 @@ formPanel set::name('customDomain'), set::value($thirdDomain), ), - input - ( - set::type('hidden'), - set::name('customName'), - ), $this->cne->sysDomain(), ), ), diff --git a/module/store/control.php b/module/store/control.php index 58373c491a..a2d5d460a0 100644 --- a/module/store/control.php +++ b/module/store/control.php @@ -70,6 +70,7 @@ class store extends control } $pagedApps = $this->store->searchApps($sortType, $keyword, $postCategories, $pageID, $recPerPage); + $this->app->loadClass('pager', true); $pager = pager::init($pagedApps->total, $recPerPage, $pageID); @@ -81,6 +82,7 @@ class store extends control $this->view->title = $this->lang->store->common; $this->view->position[] = $this->lang->store->common; $this->view->cloudApps = $pagedApps->apps; + $this->view->installedApps = $this->storeZen->getInstalledApps(); $this->view->categories = $categories; $this->view->postCategories = $postCategories; $this->view->keyword = $keyword; @@ -95,7 +97,7 @@ class store extends control * * @param int $id * @access public - * @return viod + * @return void */ public function appView($id, $pageID = 1, $recPerPage = 20) { @@ -116,7 +118,7 @@ class store extends control $this->app->loadClass('pager', true); $pager = pager::init($totalArticle, $recPerPage, $pageID); - $this->view->dynamicPager = $pager; + $this->view->pager = $pager; $this->view->title = $appInfo->alias; $this->view->position[] = $appInfo->alias; diff --git a/module/store/js/browse.ui.js b/module/store/js/browse.ui.js index ac3430af29..9deed781b6 100644 --- a/module/store/js/browse.ui.js +++ b/module/store/js/browse.ui.js @@ -31,6 +31,21 @@ window.treeClick = function(info) */ window.installApp = function() { + var confirm = $(this).data('confirm'); + console.log(confirm); + if(confirm) + { + zui.Modal.confirm(confirm).then(result => + { + if(!result) return; + zui.Modal.open({ + url: $(this).data('url'), + id: 'installModal' + }); + }); + return; + } + zui.Modal.open({ url: $(this).data('url'), id: 'installModal' diff --git a/module/store/lang/en.php b/module/store/lang/en.php new file mode 100644 index 0000000000..ee76f1c7fc --- /dev/null +++ b/module/store/lang/en.php @@ -0,0 +1,27 @@ +store->appType = 'Type'; +$lang->store->appVersion = 'Version'; +$lang->store->releaseDate = 'Publish Time'; +$lang->store->author = 'Author'; +$lang->store->empty = 'Empty'; +$lang->store->install = 'Install'; +$lang->store->customInstall = 'Custom Install'; +$lang->store->searchApp = 'Search'; +$lang->store->testChannel = 'Test Version'; +$lang->store->stableChannel = 'Stable Version'; +$lang->store->appBasicInfo = 'Basic Info'; +$lang->store->screenshots = 'Screenshots'; +$lang->store->appDynamic = 'Dynamic'; +$lang->store->noDynamicArticle = 'Empty'; +$lang->store->noScreenshot = 'Empty'; +$lang->store->cloudStore = 'APP Store'; + +$lang->store->support = 'Support'; +$lang->store->gitUrl = 'Git'; +$lang->store->dockerfileUrl = 'Dockerfile'; +$lang->store->forumUrl = 'Forum'; +$lang->store->alreadyInstalled = 'The application has been installed on the platform, Are you sure you want to continue with the installation?'; + +$lang->store->featureBar['browse']['id'] = 'Default'; +$lang->store->featureBar['browse']['create_time'] = 'Newest'; +$lang->store->featureBar['browse']['update_time'] = 'Recently updated'; diff --git a/module/store/lang/zh-cn.php b/module/store/lang/zh-cn.php index 0b6543cf42..84218dd1d9 100644 --- a/module/store/lang/zh-cn.php +++ b/module/store/lang/zh-cn.php @@ -20,6 +20,7 @@ $lang->store->support = '支持'; $lang->store->gitUrl = '应用源码'; $lang->store->dockerfileUrl = 'Dockerfile'; $lang->store->forumUrl = '论坛'; +$lang->store->alreadyInstalled = '平台已安装过该应用,确定要继续安装么?'; $lang->store->featureBar['browse']['id'] = '默认'; $lang->store->featureBar['browse']['create_time'] = '最新上架'; diff --git a/module/store/model.php b/module/store/model.php index 87d716d35a..b5f990a84e 100644 --- a/module/store/model.php +++ b/module/store/model.php @@ -101,6 +101,23 @@ class storeModel extends model return $result->data; } + /** + * Get app version pairs by id. + * + * @param int $id + * @access public + * @return array + */ + public function getVersionPairs(int $id): array + { + $pairs = array(); + $versions = $this->appVersionList($id); + + foreach($versions as $version) $pairs[$version->version] = $version->app_version . '-' . $version->version; + + return $pairs; + } + /** * Get app version list to install. * @@ -125,7 +142,7 @@ class storeModel extends model $apiUrl = $this->config->cloud->api->host; $apiUrl .= '/api/market/app/version'; $result = commonModel::apiGet($apiUrl, $apiParams, $this->config->cloud->api->headers); - if(!isset($result->code) || $result->code != 200) return null; + if(!isset($result->code) || $result->code != 200) return array(); return array_combine(array_column($result->data, 'version'), $result->data); } diff --git a/module/store/ui/appview.html.php b/module/store/ui/appview.html.php index ff06a118cd..d095f35f74 100644 --- a/module/store/ui/appview.html.php +++ b/module/store/ui/appview.html.php @@ -13,8 +13,7 @@ declare(strict_types=1); namespace zin; -$setting = usePager('dynamicPager'); -$screenshots = array_filter($cloudApp->screenshot_urls); +$screenshots = array_filter($cloudApp->screenshot_urls); if(!empty($screenshots) && count($screenshots)%3) $screenshots = array_merge($screenshots, array_fill(0, count($screenshots)%3, '')); $screenshotsWg = array(); foreach($screenshots as $screenshot) @@ -22,12 +21,12 @@ foreach($screenshots as $screenshot) $screenshotsWg[] = div ( setClass('flex-1 img-thumbnail'), - !$screenshot ? '' : img + $screenshot ? img ( set::src($screenshot), setClass('state'), on::click('window.open("' . $screenshot . '")') - ) + ) : null, ); } @@ -72,7 +71,7 @@ detailHeader( backBtn ( $lang->store->install, - setClass('primary btn size-sm install-btn'), + setClass('primary btn install-btn w-20'), set::type('primary'), set::url($this->createLink('instance', 'install', "id={$cloudApp->id}")), setData('toggle', 'modal'), @@ -141,15 +140,7 @@ detailBody setClass('table borderless table-hover mb-3'), ...$dynamicArticlesWd, ), - pager( - setID('dynamicPager'), - set::page($setting['page']), - set::recTotal($setting['recTotal']), - set::recPerPage($setting['recPerPage']), - set::linkCreator($setting['linkCreator']), - set::items($setting['items']), - set::gap($setting['gap']), - ), + pager(setID('dynamicPager')), ) ) ) diff --git a/module/store/ui/browse.html.php b/module/store/ui/browse.html.php index 9f803619b1..e154dc0042 100644 --- a/module/store/ui/browse.html.php +++ b/module/store/ui/browse.html.php @@ -49,7 +49,7 @@ foreach ($cloudApps as $group) div ( setStyle('height', '100px'), - setClass('flex border-b border-light'), + setClass('flex border-b border-lighter'), img(set::src($cloudApp->logo), setStyle(array('width' => '80px', 'height' => '80px'))), div ( @@ -72,6 +72,7 @@ foreach ($cloudApps as $group) setClass('primary btn size-sm install-btn'), setData('prevent', true), setData('toggle', 'modal'), + in_array($cloudApp->id, $installedApps) ? setData('confirm', $lang->store->alreadyInstalled) : null, setData('url', $this->createLink('space', 'createApplication', "id={$cloudApp->id}")), on::click('installApp', array('stop' => true)), ) diff --git a/module/store/zen.php b/module/store/zen.php new file mode 100644 index 0000000000..073c568b20 --- /dev/null +++ b/module/store/zen.php @@ -0,0 +1,33 @@ + + * @package store + * @link https://www.zentao.net + */ +class storeZen extends store +{ + /** + * 获取已安装的所有应用。 + * Get all installed apps. + * + * @param form $formData + * @param bool $isPipelineServer + * @access protected + * @return object|false + */ + protected function getInstalledApps(): array + { + $installedApps = array(); + $space = $this->loadModel('space')->defaultSpace($this->app->user->account); + $instances = $this->space->getSpaceInstances($space->id, 'all'); + foreach($instances as $instance) $installedApps[] = $instance->appID; + + return $installedApps; + } +} +