Commit 8630a340 authored by nobodyiam's avatar nobodyiam

do lazy load if page contains too many namespaces(>10)

parent b3e5798b
...@@ -214,7 +214,8 @@ ...@@ -214,7 +214,8 @@
pre-delete-item="preDeleteItem" pre-delete-item="preDeleteItem"
show-text="showText" show-text="showText"
show-no-modify-permission-dialog="showNoModifyPermissionDialog" show-no-modify-permission-dialog="showNoModifyPermissionDialog"
show-body="namespaces.length == 1" show-body="namespaces.length < 3"
lazy-load="namespaces.length > 10"
pre-create-branch="preCreateBranch" pre-create-branch="preCreateBranch"
pre-delete-branch="preDeleteBranch"> pre-delete-branch="preDeleteBranch">
</apollonspanel> </apollonspanel>
......
...@@ -116,7 +116,7 @@ function ConfigBaseInfoController($rootScope, $scope, $window, $location, toastr ...@@ -116,7 +116,7 @@ function ConfigBaseInfoController($rootScope, $scope, $window, $location, toastr
$scope.findMissingNamespaces = function () { $scope.findMissingNamespaces = function () {
$scope.missingNamespaces = []; $scope.missingNamespaces = [];
// only check missing private namespaces when app exists in current env // only check missing private namespaces when app exists in current env
if ($scope.missEnvs.indexOf($rootScope.pageContext.env) === -1) { if ($rootScope.pageContext.env && $scope.missEnvs.indexOf($rootScope.pageContext.env) === -1) {
AppService.find_missing_namespaces($rootScope.pageContext.appId, $rootScope.pageContext.env, AppService.find_missing_namespaces($rootScope.pageContext.appId, $rootScope.pageContext.env,
$rootScope.pageContext.clusterName).then(function (result) { $rootScope.pageContext.clusterName).then(function (result) {
$scope.missingNamespaces = AppUtil.collectData(result); $scope.missingNamespaces = AppUtil.collectData(result);
......
...@@ -130,6 +130,7 @@ function controller($rootScope, $scope, toastr, AppUtil, EventManager, ConfigSer ...@@ -130,6 +130,7 @@ function controller($rootScope, $scope, toastr, AppUtil, EventManager, ConfigSer
if (namespace.baseInfo.namespaceName == result.baseInfo.namespaceName) { if (namespace.baseInfo.namespaceName == result.baseInfo.namespaceName) {
$scope.namespaces[index] = result; $scope.namespaces[index] = result;
$scope.namespaces[index].showNamespaceBody = true; $scope.namespaces[index].showNamespaceBody = true;
$scope.namespaces[index].initialized = true;
} }
}); });
......
...@@ -22,7 +22,8 @@ function directive($window, toastr, AppUtil, EventManager, PermissionService, Na ...@@ -22,7 +22,8 @@ function directive($window, toastr, AppUtil, EventManager, PermissionService, Na
preCreateBranch: '=', preCreateBranch: '=',
preDeleteBranch: '=', preDeleteBranch: '=',
showMergeAndPublishGrayTips: '=', showMergeAndPublishGrayTips: '=',
showBody: "=?" showBody: "=?",
lazyLoad: "=?"
}, },
link: function (scope) { link: function (scope) {
...@@ -43,6 +44,7 @@ function directive($window, toastr, AppUtil, EventManager, PermissionService, Na ...@@ -43,6 +44,7 @@ function directive($window, toastr, AppUtil, EventManager, PermissionService, Na
var operate_branch_storage_key = 'OperateBranch'; var operate_branch_storage_key = 'OperateBranch';
scope.init = init;
scope.switchView = switchView; scope.switchView = switchView;
scope.toggleItemSearchInput = toggleItemSearchInput; scope.toggleItemSearchInput = toggleItemSearchInput;
scope.searchItems = searchItems; scope.searchItems = searchItems;
...@@ -75,18 +77,34 @@ function directive($window, toastr, AppUtil, EventManager, PermissionService, Na ...@@ -75,18 +77,34 @@ function directive($window, toastr, AppUtil, EventManager, PermissionService, Na
subscriberId, scope.namespace.baseInfo.namespaceName); subscriberId, scope.namespace.baseInfo.namespaceName);
}); });
init(); preInit(scope.namespace);
function init() { if (!scope.lazyLoad || scope.namespace.initialized) {
init(false);
}
function preInit(namespace) {
scope.showNamespaceBody = false;
namespace.isLinkedNamespace =
namespace.isPublic ? namespace.parentAppId != namespace.baseInfo.appId : false;
//namespace view name hide suffix
namespace.viewName = namespace.baseInfo.namespaceName.replace(".xml", "").replace(
".properties", "").replace(".json", "").replace(".yml", "")
.replace(".yaml", "");
}
function init(forceShowBody) {
initNamespace(scope.namespace); initNamespace(scope.namespace);
initOther(); initOther();
scope.namespace.initialized = true;
if (forceShowBody) {
scope.showNamespaceBody = true;
}
} }
function initNamespace(namespace, viewType) { function initNamespace(namespace, viewType) {
namespace.hasBranch = false; namespace.hasBranch = false;
namespace.isBranch = false; namespace.isBranch = false;
namespace.isLinkedNamespace =
namespace.isPublic ? namespace.parentAppId != namespace.baseInfo.appId : false;
namespace.displayControl = { namespace.displayControl = {
currentOperateBranch: 'master', currentOperateBranch: 'master',
showSearchInput: false, showSearchInput: false,
...@@ -309,12 +327,6 @@ function directive($window, toastr, AppUtil, EventManager, PermissionService, Na ...@@ -309,12 +327,6 @@ function directive($window, toastr, AppUtil, EventManager, PermissionService, Na
} }
function initNamespaceViewName(namespace) { function initNamespaceViewName(namespace) {
//namespace view name hide suffix
namespace.viewName =
namespace.baseInfo.namespaceName.replace(".xml", "").replace(
".properties", "").replace(".json", "").replace(".yml", "")
.replace(".yaml", "");
if (!viewType) { if (!viewType) {
if (namespace.isPropertiesFormat) { if (namespace.isPropertiesFormat) {
switchView(namespace, namespace_view_type.TABLE); switchView(namespace, namespace_view_type.TABLE);
...@@ -350,7 +362,7 @@ function directive($window, toastr, AppUtil, EventManager, PermissionService, Na ...@@ -350,7 +362,7 @@ function directive($window, toastr, AppUtil, EventManager, PermissionService, Na
localStorage.setItem(operate_branch_storage_key, JSON.stringify(operateBranchStorage)); localStorage.setItem(operate_branch_storage_key, JSON.stringify(operateBranchStorage));
switchBranch(operateBranchStorage[namespaceId]); switchBranch(operateBranchStorage[namespaceId], false);
} }
...@@ -380,11 +392,14 @@ function directive($window, toastr, AppUtil, EventManager, PermissionService, Na ...@@ -380,11 +392,14 @@ function directive($window, toastr, AppUtil, EventManager, PermissionService, Na
}); });
} }
function switchBranch(branchName) { function switchBranch(branchName, forceShowBody) {
if (branchName != 'master') { if (branchName != 'master') {
initRules(scope.namespace.branch); initRules(scope.namespace.branch);
}
if (forceShowBody) {
scope.showNamespaceBody = true; scope.showNamespaceBody = true;
} }
scope.namespace.displayControl.currentOperateBranch = branchName; scope.namespace.displayControl.currentOperateBranch = branchName;
//save to local storage //save to local storage
......
<section class="branch-panel-body" <section class="branch-panel-body"
ng-if="namespace.hasBranch && namespace.displayControl.currentOperateBranch != 'master'"> ng-if="namespace.initialized &&
(namespace.hasBranch && namespace.displayControl.currentOperateBranch != 'master')">
<!--main header--> <!--main header-->
<header class="panel-heading"> <header class="panel-heading">
<div class="row"> <div class="row">
<div class="col-md-6 col-sm-6 header-namespace"> <div class="col-md-6 col-sm-6 header-namespace">
<span class="cursor-pointer"
data-toggle="collapse" data-target="#BODY{{namespace.branch.id}}" aria-expanded="false"
ng-click="namespace.branch.displayControl.show = !namespace.branch.displayControl.show">
</span>
<b class="namespace-name" ng-bind="namespace.viewName"></b> <b class="namespace-name" ng-bind="namespace.viewName"></b>
<span class="label label-warning no-radius namespace-label" <span class="label label-warning no-radius namespace-label"
ng-show="namespace.branch.itemModifiedCnt > 0">有修改 ng-show="namespace.branch.itemModifiedCnt > 0">有修改
......
...@@ -21,11 +21,11 @@ ...@@ -21,11 +21,11 @@
</div> </div>
<div class="col-md-6 text-right" style="padding-right:23px;"> <div class="col-md-6 text-right" style="padding-right:23px;">
<span data-toggle="collapse" data-target="#BODY{{namespace.branch.id}}" aria-expanded="false"> <span data-toggle="collapse" data-target="#BODY{{namespace.branch.id}}" aria-expanded="false">
<span <span class="label no-radius cursor-pointer"
class="label no-radius cursor-pointer" data-toggle="collapse" data-target="#BODY{{namespace.id}}" aria-expanded="false"
data-toggle="collapse" data-target="#BODY{{namespace.id}}" aria-expanded="false" ng-click="showNamespaceBody = !showNamespaceBody"
ng-click="showNamespaceBody = !showNamespaceBody"> ng-show="namespace.initialized">
<a ><small>[展开/收缩]</small></a> <a>[展开/收缩]</a>
</span> </span>
</span> </span>
</div> </div>
...@@ -33,20 +33,20 @@ ...@@ -33,20 +33,20 @@
</header> </header>
<!--branch nav--> <!--branch nav-->
<header class="panel-heading second-panel-heading" ng-show="namespace.hasBranch"> <header class="panel-heading second-panel-heading" ng-show="namespace.initialized && namespace.hasBranch">
<div class="row"> <div class="row">
<div class="col-md-8 pull-left"> <div class="col-md-8 pull-left">
<ul class="nav nav-tabs"> <ul class="nav nav-tabs">
<li role="presentation"> <li role="presentation">
<a ng-class="{'node_active': namespace.displayControl.currentOperateBranch == 'master'}" <a ng-class="{'node_active': namespace.displayControl.currentOperateBranch == 'master'}"
ng-click="switchBranch('master')"> ng-click="switchBranch('master', true)">
<img src="img/branch.png"> <img src="img/branch.png">
主版本 主版本
</a> </a>
</li> </li>
<li role="presentation"> <li role="presentation">
<a ng-class="{'node_active': namespace.displayControl.currentOperateBranch != 'master'}" <a ng-class="{'node_active': namespace.displayControl.currentOperateBranch != 'master'}"
ng-click="switchBranch(namespace.branchName)"> ng-click="switchBranch(namespace.branchName, true)">
<img src="img/branch.png"> <img src="img/branch.png">
灰度版本 灰度版本
</a> </a>
......
<!--master panel body when not initialized-->
<section class="master-panel-body" ng-if="!namespace.initialized">
<!--main header-->
<header class="panel-heading">
<div class="row">
<div class="col-md-6 col-sm-6 header-namespace">
<b class="namespace-name" ng-bind="namespace.viewName"></b>
</div>
<div class="col-md-6 col-sm-6 text-right header-buttons">
<button type="button" class="btn btn-default btn-sm"
data-tooltip="tooltip" data-placement="bottom" title="加载Namespace"
ng-click="init(true)">
<img src="img/more.png">
加载Namespace
</button>
</div>
</div>
</header>
</section>
<!--master panel body--> <!--master panel body-->
<section class="master-panel-body" <section class="master-panel-body"
ng-if="namespace.hasBranch ng-if="namespace.initialized &&
&& namespace.displayControl.currentOperateBranch == 'master' || (namespace.hasBranch && namespace.displayControl.currentOperateBranch == 'master' || !namespace.hasBranch)">
!namespace.hasBranch">
<!--main header--> <!--main header-->
<header class="panel-heading"> <header class="panel-heading">
<div class="row"> <div class="row">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment