提交 2ef6cf95 编写于 作者: L lepdou

集群选择做成一个标签

上级 ff8856fc
......@@ -46,24 +46,8 @@
<div class="form-group">
<label class="col-sm-2 control-label">同步到那个集群</label>
<div class="col-sm-6">
<table class="table table-hover">
<thead>
<tr>
<td><input type="checkbox" ng-click="toggleEnvsCheckedStatus()"></td>
</td>
<td>环境</td>
<td>集群</td>
</tr>
</thead>
<tbody>
<tr ng-repeat="namespaceIdentifer in namespaceIdentifers">
<td width="10%"><input type="checkbox" ng-checked="namespaceIdentifer.checked"
ng-click="switchSelect(namespaceIdentifer)"></td>
<td width="30%" ng-bind="namespaceIdentifer.env"></td>
<td width="60%" ng-bind="namespaceIdentifer.name"></td>
</tr>
</tbody>
</table>
<apolloclusterselector apollo-app-id="pageContext.appId" apollo-default-checked="true"
apollo-select="collectSelectedClusters"></apolloclusterselector>
</div>
</div>
</div>
......
......@@ -15,7 +15,7 @@
<div class="site-notice">当前站点支持
&nbsp;<a ng-repeat="env in envs" ng-class="{selected:selectedEnv == env}" ng-click="switchEnv(env)"><em ng-bind="env">
</em></a>&nbsp;
</em>&nbsp;</a>
环境点击切换
</div>
......
......@@ -41,24 +41,8 @@
<div class="form-group">
<label class="col-sm-3 control-label"><font style="color: red">*</font>选择集群</label>
<div class="col-sm-6">
<table class="table table-hover">
<thead>
<tr>
<td><input type="checkbox" ng-click="toggleEnvsCheckedStatus()"></td>
</td>
<td>环境</td>
<td>集群</td>
</tr>
</thead>
<tbody>
<tr ng-repeat="namespaceIdentifer in namespaceIdentifers">
<td width="10%"><input type="checkbox" ng-checked="namespaceIdentifer.checked"
ng-click="switchSelect(namespaceIdentifer)"></td>
<td width="30%" ng-bind="namespaceIdentifer.env"></td>
<td width="60%" ng-bind="namespaceIdentifer.name"></td>
</tr>
</tbody>
</table>
<apolloclusterselector apollo-app-id="appId" apollo-default-checked="true"
apollo-select="collectSelectedClusters"></apolloclusterselector>
</div>
</div>
</div>
......
......@@ -5,7 +5,7 @@ var appService = angular.module('app.service', ['ngResource']);
var appUtil = angular.module('app.util', ['toastr']);
/** directive */
var directive_module = angular.module('apollo.directive', ['app.service']);
var directive_module = angular.module('apollo.directive', ['app.service', 'app.util', 'toastr']);
/** page module 定义*/
// 首页
......
......@@ -8,22 +8,6 @@ namespace_module.controller("LinkNamespaceController",
$scope.step = 1;
////// load env //////
AppService.load_nav_tree($scope.appId).then(function (result) {
$scope.namespaceIdentifers = [];
var envClusterInfo = AppUtil.collectData(result);
envClusterInfo.forEach(function (node) {
var env = node.env;
node.clusters.forEach(function (cluster) {
cluster.env = env;
cluster.checked = false;
$scope.namespaceIdentifers.push(cluster);
})
});
}, function (result) {
toastr.error(AppUtil.errorMsg(result), "加载环境出错");
});
NamespaceService.find_public_namespaces().then(function (result) {
var publicNamespaces = [];
result.forEach(function (item) {
......@@ -45,9 +29,13 @@ namespace_module.controller("LinkNamespaceController",
name:'',
comment:''
};
var selectedClusters = [];
$scope.collectSelectedClusters = function (data) {
selectedClusters = data;
};
$scope.createNamespace = function () {
if ($scope.type == 'link'){
var selectedClusters = collectSelectedClusters();
if (selectedClusters.length == 0){
toastr.warning("请选择集群");
return;
......@@ -85,35 +73,11 @@ namespace_module.controller("LinkNamespaceController",
};
var envAllSelected = false;
$scope.toggleEnvsCheckedStatus = function () {
envAllSelected = !envAllSelected;
$scope.namespaceIdentifers.forEach(function (namespaceIdentifer) {
namespaceIdentifer.checked = envAllSelected;
})
};
function collectSelectedClusters() {
var selectedClusters = [];
$scope.namespaceIdentifers.forEach(function (namespaceIdentifer) {
if (namespaceIdentifer.checked){
namespaceIdentifer.clusterName = namespaceIdentifer.name;
selectedClusters.push(namespaceIdentifer);
}
});
return selectedClusters;
}
$scope.namespaceType = 1;
$scope.selectNamespaceType = function (type) {
$scope.namespaceType = type;
};
$scope.switchSelect = function (o) {
o.checked = !o.checked;
};
$scope.back = function () {
$window.location.href = '/config.html?#appid=' + $scope.appId;
};
......
......@@ -10,31 +10,7 @@ sync_item_module.controller("SyncItemController",
namespaceName: params.namespaceName
};
////// load env //////
AppService.load_nav_tree($scope.pageContext.appId).then(function (result) {
$scope.namespaceIdentifers = [];
var envClusterInfo = AppUtil.collectData(result);
envClusterInfo.forEach(function (node) {
var env = node.env;
node.clusters.forEach(function (cluster) {
cluster.env = env;
cluster.checked = false;
if (env != $scope.pageContext.env || cluster.name != $scope.pageContext.clusterName){
$scope.namespaceIdentifers.push(cluster);
}
})
});
}, function (result) {
toastr.error(AppUtil.errorMsg(result), "加载环境出错");
});
var envAllSelected = false;
$scope.toggleEnvsCheckedStatus = function () {
envAllSelected = !envAllSelected;
$scope.namespaceIdentifers.forEach(function (namespaceIdentifer) {
namespaceIdentifer.checked = envAllSelected;
})
};
////// load items //////
ConfigService.find_items($scope.pageContext.appId, $scope.pageContext.env,
......@@ -85,6 +61,11 @@ sync_item_module.controller("SyncItemController",
toastr.error(AppUtil.errorMsg(result));
});
};
var selectedClusters = [];
$scope.collectSelectedClusters = function (data) {
selectedClusters = data;
};
function parseSyncSourceData() {
var sourceData = {
......@@ -92,11 +73,11 @@ sync_item_module.controller("SyncItemController",
syncItems: []
};
var namespaceName = $scope.pageContext.namespaceName;
$scope.namespaceIdentifers.forEach(function (namespaceIdentifer) {
if (namespaceIdentifer.checked){
namespaceIdentifer.clusterName = namespaceIdentifer.name;
namespaceIdentifer.namespaceName = namespaceName;
sourceData.syncToNamespaces.push(namespaceIdentifer);
selectedClusters.forEach(function (cluster) {
if (cluster.checked){
cluster.clusterName = cluster.name;
cluster.namespaceName = namespaceName;
sourceData.syncToNamespaces.push(cluster);
}
});
$scope.sourceItems.forEach(function (item) {
......
/** navbar */
directive_module.directive('apollonav', function ($compile, $window, AppService, EnvService) {
return {
restrict: 'E',
......@@ -113,3 +115,65 @@ directive_module.directive('apollonav', function ($compile, $window, AppService,
}
});
/** env cluster selector*/
directive_module.directive('apolloclusterselector', function ($compile, $window, AppService, AppUtil, toastr) {
return {
restrict: 'E',
templateUrl: '../views/component/env-selector.html',
transclude: true,
replace: true,
scope: {
appId: '=apolloAppId',
defaultChecked: '=apolloDefaultChecked',
select: '=apolloSelect'
},
link: function (scope, element, attrs) {
////// load env //////
AppService.load_nav_tree(scope.appId).then(function (result) {
scope.clusters = [];
var envClusterInfo = AppUtil.collectData(result);
envClusterInfo.forEach(function (node) {
var env = node.env;
node.clusters.forEach(function (cluster) {
cluster.env = env;
cluster.checked = scope.defaultChecked;
scope.clusters.push(cluster);
})
});
scope.select(collectSelectedClusters());
}, function (result) {
toastr.error(AppUtil.errorMsg(result), "加载环境信息出错");
});
scope.envAllSelected = scope.defaultChecked;
scope.toggleEnvsCheckedStatus = function () {
scope.envAllSelected = !scope.envAllSelected;
scope.clusters.forEach(function (cluster) {
cluster.checked = scope.envAllSelected;
});
scope.select(collectSelectedClusters());
};
scope.switchSelect = function (o) {
o.checked = !o.checked;
scope.select(collectSelectedClusters());
};
function collectSelectedClusters() {
var selectedClusters = [];
scope.clusters.forEach(function (cluster) {
if (cluster.checked){
cluster.clusterName = cluster.name;
selectedClusters.push(cluster);
}
});
return selectedClusters;
}
}
}
});
<table class="table table-hover">
<thead>
<tr>
<td><input type="checkbox" ng-checked="envAllSelected" ng-click="toggleEnvsCheckedStatus()"></td>
</td>
<td>环境</td>
<td>集群</td>
</tr>
</thead>
<tbody>
<tr ng-repeat="cluster in clusters">
<td width="10%"><input type="checkbox" ng-checked="cluster.checked"
ng-click="switchSelect(cluster)"></td>
<td width="30%" ng-bind="cluster.env"></td>
<td width="60%" ng-bind="cluster.name"></td>
</tr>
</tbody>
</table>
7804
\ No newline at end of file
13303
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册