* Refactor view and browse of store.

This commit is contained in:
zhaoke
2023-08-03 14:04:05 +08:00
parent 669d4f3b02
commit ba8cd0be5c
21 changed files with 188 additions and 52 deletions
+2 -1
View File
@@ -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';
+2
View File
@@ -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();
+2
View File
@@ -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
+2
View File
@@ -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
+2
View File
@@ -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
+1 -1
View File
@@ -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);
-1
View File
@@ -200,7 +200,6 @@ div
setClass('basis-auto'),
history
(
set::commentBtn(true),
set::commentUrl(createLink('action', 'comment', array('objectType' => 'instance', 'objectID' => $instance->id))),
)
)
+2
View File
@@ -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
+2
View File
@@ -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
+6 -2
View File
@@ -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();
+1 -1
View File
@@ -12,7 +12,7 @@ function onChangeType(event)
{
$('.storePanel').removeClass('hidden');
$('.externalPanel').addClass('hidden');
$('#storetype_store').prop('checked', true);
$('#type_store').prop('checked', true);
}
}
+11 -2
View File
@@ -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',
+50 -26
View File
@@ -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(),
),
),
+4 -2
View File
@@ -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;
+15
View File
@@ -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'
+27
View File
@@ -0,0 +1,27 @@
<?php
$lang->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';
+1
View File
@@ -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'] = '最新上架';
+18 -1
View File
@@ -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);
}
+5 -14
View File
@@ -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')),
)
)
)
+2 -1
View File
@@ -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)),
)
+33
View File
@@ -0,0 +1,33 @@
<?php
declare(strict_types=1);
/**
* The zen file of store module of ZenTaoPMS.
*
* @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.zentao.net)
* @license ZPL(https://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
* @author Ke Zhao<zhaoke@easycorp.ltd>
* @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;
}
}