提交 f2c7de85 编写于 作者: L lepdou

add namespace

上级 605847dd
package com.ctrip.apollo.adminservice.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ctrip.apollo.biz.entity.AppNamespace;
import com.ctrip.apollo.biz.service.AppNamespaceService;
import com.ctrip.apollo.common.utils.BeanUtils;
import com.ctrip.apollo.core.dto.AppNamespaceDTO;
import java.util.List;
@RestController
public class AppNamespaceController {
......@@ -18,4 +24,11 @@ public class AppNamespaceController {
@PathVariable("appnamespace") String appnamespace) {
return appNamespaceService.isAppNamespaceNameUnique(appId, appnamespace);
}
@RequestMapping("/appnamespaces/public")
public List<AppNamespaceDTO> findPublicAppNamespaces(){
List<AppNamespace> appNamespaces = appNamespaceService.findPublicAppNamespaces();
return BeanUtils.batchTransform(AppNamespaceDTO.class, appNamespaces);
}
}
......@@ -4,10 +4,14 @@ import org.springframework.data.repository.PagingAndSortingRepository;
import com.ctrip.apollo.biz.entity.AppNamespace;
import java.util.List;
public interface AppNamespaceRepository extends PagingAndSortingRepository<AppNamespace, Long>{
AppNamespace findByAppIdAndName(String appId, String namespaceName);
AppNamespace findByName(String namespaceName);
List<AppNamespace> findByNameNot(String namespaceName);
}
......@@ -2,9 +2,12 @@ package com.ctrip.apollo.biz.service;
import com.google.common.base.Preconditions;
import java.util.List;
import java.util.Objects;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
......@@ -50,4 +53,8 @@ public class AppNamespaceService {
auditService.audit(AppNamespace.class.getSimpleName(), appNs.getId(), Audit.OP.INSERT,
createBy);
}
public List<AppNamespace> findPublicAppNamespaces(){
return appNamespaceRepository.findByNameNot(ConfigConsts.NAMESPACE_DEFAULT);
}
}
package com.ctrip.apollo.biz;
import com.ctrip.apollo.biz.message.DatabaseMessageSenderTest;
import com.ctrip.apollo.biz.repository.AppNamespaceRepositoryTest;
import com.ctrip.apollo.biz.repository.AppRepositoryTest;
import com.ctrip.apollo.biz.service.AdminServiceTest;
import com.ctrip.apollo.biz.service.AdminServiceTransactionTest;
......@@ -14,6 +15,7 @@ import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
@SuiteClasses({
AppRepositoryTest.class,
AppNamespaceRepositoryTest.class,
AdminServiceTest.class,
ConfigServiceTest.class,
PrivilegeServiceTest.class,
......
package com.ctrip.apollo.biz.repository;
import com.ctrip.apollo.biz.BizTestConfiguration;
import com.ctrip.apollo.biz.entity.AppNamespace;
import com.ctrip.apollo.core.ConfigConsts;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = BizTestConfiguration.class)
@Transactional
@Rollback
public class AppNamespaceRepositoryTest {
@Autowired
private AppNamespaceRepository repository;
@Test
public void testFindAllPublicAppNamespaces(){
List<AppNamespace> appNamespaceList = repository.findByNameNot(ConfigConsts.NAMESPACE_DEFAULT);
Assert.assertEquals(4, appNamespaceList.size());
}
}
INSERT INTO AppNamespace (AppId, Name) VALUES ('100003171', 'application');
INSERT INTO AppNamespace (AppId, Name) VALUES ('100003171', 'fx.apollo.config');
INSERT INTO AppNamespace (AppId, Name) VALUES ('100003172', 'application');
INSERT INTO AppNamespace (AppId, Name) VALUES ('100003172', 'fx.apollo.admin');
INSERT INTO AppNamespace (AppId, Name) VALUES ('100003173', 'application');
INSERT INTO AppNamespace (AppId, Name) VALUES ('100003173', 'fx.apollo.portal');
INSERT INTO AppNamespace (AppID, Name) VALUES ('fxhermesproducer', 'fx.hermes.producer');
package com.ctrip.apollo.core.dto;
public class AppNamespaceDTO {
private String name;
private String appId;
private String comment;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAppId() {
return appId;
}
public void setAppId(String appId) {
this.appId = appId;
}
public String getComment() {
return comment;
}
public void setComment(String comment) {
this.comment = comment;
}
}
......@@ -28,4 +28,8 @@ public class PortalSettings {
public List<Env> getEnvs() {
return envs;
}
public Env getFirstEnv(){
return envs.get(0);
}
}
package com.ctrip.apollo.portal.api;
import com.ctrip.apollo.core.dto.AppNamespaceDTO;
import com.ctrip.apollo.core.enums.Env;
import com.ctrip.apollo.core.dto.AppDTO;
import com.ctrip.apollo.core.dto.ClusterDTO;
......@@ -61,6 +62,21 @@ public class AdminServiceAPI {
+ String.format("apps/%s/clusters/%s/namespaces/%s", appId, clusterName, namespaceName),
NamespaceDTO.class);
}
public List<AppNamespaceDTO> findPublicAppNamespaces(Env env){
AppNamespaceDTO[] appNamespaceDTOs = restTemplate.getForObject(
getAdminServiceHost(env)+ "appnamespaces/public",
AppNamespaceDTO[].class);
return Arrays.asList(appNamespaceDTOs);
}
public NamespaceDTO save(Env env, NamespaceDTO namespace) {
return restTemplate.postForEntity(getAdminServiceHost(env) +
String.format("/apps/%s/clusters/%s/namespaces", namespace.getAppId(),
namespace.getClusterName()), namespace, NamespaceDTO.class)
.getBody();
}
}
@Service
......
package com.ctrip.apollo.portal.controller;
import com.ctrip.apollo.core.dto.AppNamespaceDTO;
import com.ctrip.apollo.core.dto.NamespaceDTO;
import com.ctrip.apollo.core.enums.Env;
import com.ctrip.apollo.core.exception.BadRequestException;
import com.ctrip.apollo.core.utils.StringUtils;
import com.ctrip.apollo.portal.service.NamespaceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
public class NamespaceController {
@Autowired
private NamespaceService namespaceService;
@RequestMapping("/appnamespaces/public")
public List<AppNamespaceDTO> findPublicAppNamespaces(){
return namespaceService.findPublicAppNamespaces();
}
@RequestMapping(value = "/apps/{appId}/envs/{env}/clusters/{clusterName}/namespaces", method = RequestMethod.POST)
public NamespaceDTO save(@PathVariable String env, @RequestBody NamespaceDTO namespace){
if (StringUtils.isContainEmpty(env, namespace.getAppId(), namespace.getClusterName(), namespace.getNamespaceName())){
throw new BadRequestException("request payload contains empty");
}
return namespaceService.save(Env.valueOf(env), namespace);
}
}
package com.ctrip.apollo.portal.service;
import com.ctrip.apollo.core.dto.AppNamespaceDTO;
import com.ctrip.apollo.core.dto.NamespaceDTO;
import com.ctrip.apollo.core.enums.Env;
import com.ctrip.apollo.portal.PortalSettings;
import com.ctrip.apollo.portal.api.AdminServiceAPI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class NamespaceService {
@Autowired
private AdminServiceAPI.NamespaceAPI namespaceAPI;
@Autowired
private PortalSettings portalSettings;
public List<AppNamespaceDTO> findPublicAppNamespaces(){
return namespaceAPI.findPublicAppNamespaces(portalSettings.getFirstEnv());
}
public NamespaceDTO save(Env env, NamespaceDTO namespace){
return namespaceAPI.save(env, namespace);
}
}
......@@ -3,16 +3,16 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- styles -->
<link rel="stylesheet" type="text/css" href="../vendor/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="../vendor/angular/angular-toastr-1.4.1.min.css">
<link rel="stylesheet" type="text/css" media='all' href="../vendor/angular/loading-bar.min.css">
<link rel="stylesheet" type="text/css" href="../styles/common-style.css">
<link rel="stylesheet" type="text/css" href="vendor/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="vendor/angular/angular-toastr-1.4.1.min.css">
<link rel="stylesheet" type="text/css" media='all' href="vendor/angular/loading-bar.min.css">
<link rel="stylesheet" type="text/css" href="styles/common-style.css">
<title>新建项目</title>
</head>
<body>
<div ng-include="'common/nav.html'"></div>
<div ng-include="'views/common/nav.html'"></div>
<div class="container-fluid apollo-container">
......@@ -64,25 +64,25 @@
</div>
</div>
<div ng-include="'common/footer.html'"></div>
<div ng-include="'views/common/footer.html'"></div>
<!--angular-->
<script src="../vendor/angular/angular.min.js"></script>
<script src="../vendor/angular/angular-route.min.js"></script>
<script src="../vendor/angular/angular-resource.min.js"></script>
<script src="../vendor/angular/angular-toastr-1.4.1.tpls.min.js"></script>
<script src="../vendor/angular/loading-bar.min.js"></script>
<script src="vendor/angular/angular.min.js"></script>
<script src="vendor/angular/angular-route.min.js"></script>
<script src="vendor/angular/angular-resource.min.js"></script>
<script src="vendor/angular/angular-toastr-1.4.1.tpls.min.js"></script>
<script src="vendor/angular/loading-bar.min.js"></script>
<!-- jquery.js -->
<script src="../vendor/jquery.js" type="text/javascript"></script>
<script src="vendor/jquery.js" type="text/javascript"></script>
<!-- bootstrap.js -->
<script src="../vendor/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
<script src="vendor/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
<script type="application/javascript" src="../scripts/app.js"></script>
<script type="application/javascript" src="../scripts/services/AppService.js"></script>
<script type="application/javascript" src="../scripts/AppUtils.js"></script>
<script type="application/javascript" src="scripts/app.js"></script>
<script type="application/javascript" src="scripts/services/AppService.js"></script>
<script type="application/javascript" src="scripts/AppUtils.js"></script>
<script type="application/javascript" src="../scripts/controller/CreateAppController.js"></script>
<script type="application/javascript" src="scripts/controller/CreateAppController.js"></script>
</body>
</html>
......@@ -4,15 +4,15 @@
<head>
<meta charset="UTF-8">
<title>apollo</title>
<link rel="stylesheet" type="text/css" href="../vendor/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="../vendor/angular/angular-toastr-1.4.1.min.css">
<link rel="stylesheet" type="text/css" media='all' href="../vendor/angular/loading-bar.min.css">
<link rel="stylesheet" type="text/css" href="../styles/common-style.css">
<link rel="stylesheet" type="text/css" href="vendor/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="vendor/angular/angular-toastr-1.4.1.min.css">
<link rel="stylesheet" type="text/css" media='all' href="vendor/angular/loading-bar.min.css">
<link rel="stylesheet" type="text/css" href="styles/common-style.css">
</head>
<body>
<div ng-include="'common/nav.html'"></div>
<div ng-include="'views/common/nav.html'"></div>
<div class="container-fluid apollo-container">
<div class="app" ng-controller="AppConfigController as appConfig">
......@@ -28,7 +28,7 @@
<!--app info-->
<section class="panel">
<header class="panel-heading">
<img src="../img/info.png" class="i-25-20"/> 应用信息
<img src="img/info.png" class="i-25-20"/> 应用信息
<span class="tools pull-right">
<a href="javascript:;" class="icon-chevron-down"></a>
</span>
......@@ -68,14 +68,13 @@
<a class="list-group-item" data-toggle="modal" data-target="#createEnvModal"
ng-show="missEnvs.length > 0">
<div class="row">
<div class="col-md-2"><img src="../img/plus.png" class="i-20"></div>
<div class="col-md-2"><img src="img/plus.png" class="i-20"></div>
<div class="col-md-7 hidden-xs">
<p class="apps-description">添加环境</p>
<p class="btn-title">添加环境</p>
</div>
</div>
</a>
<!--<a class="list-group-item" target="_blank" href="/views/app.html?#/appid={{app.appId}}">-->
<!--<a class="list-group-item" target="_blank" href="/views/config.html?#/appid={{app.appId}}">-->
<!--<div class="row">-->
<!--<div class="col-md-2"><img src="../img/plus.png" class="i-20"></div>-->
<!--<div class="col-md-7 hidden-xs">-->
......@@ -84,15 +83,14 @@
<!--</div>-->
<!--</a>-->
<!--<a class="list-group-item" target="_blank" href="/views/app.html?#/appid={{app.appId}}">-->
<!--<div class="row">-->
<!--<div class="col-md-2"><img src="../img/plus.png" class="i-20"></div>-->
<!--<div class="col-md-7 hidden-xs">-->
<!--<p class="apps-description">添加Namespace</p>-->
<!--</div>-->
<!--</div>-->
<!--</a>-->
<a class="list-group-item" target="_blank" href="namespace.html?#/appid={{pageContext.appId}}">
<div class="row">
<div class="col-md-2"><img src="img/plus.png" class="i-20"></div>
<div class="col-md-7 hidden-xs">
<p class="btn-title">添加Namespace</p>
</div>
</div>
</a>
</section>
</div>
......@@ -128,7 +126,7 @@
<!--class="btn btn-default btn-sm J_tableview_btn">授权-->
<!--</button>-->
<a type="button" target="_blank"
href="sync.html?#/appid={{pageContext.appId}}&env={{pageContext.env}}&clusterName={{pageContext.clusterName}}&namespaceName={{namespace.namespace.namespaceName}}"
href="config/sync.html?#/appid={{pageContext.appId}}&env={{pageContext.env}}&clusterName={{pageContext.clusterName}}&namespaceName={{namespace.namespace.namespaceName}}"
class="btn btn-default btn-sm J_tableview_btn">同步
</a>
</div>
......@@ -236,7 +234,7 @@
<div class="row">
<div class="col-md-11 col-md-offset-1 list" style="">
<div class="media">
<img src="../img/history.png"/>
<img src="img/history.png"/>
<div class="row">
<div class="col-md-10"><h5 class="media-heading">2016-02-23
......@@ -254,7 +252,7 @@
<hr>
</div>
<div class="media">
<img src="../img/history.png"/>
<img src="img/history.png"/>
<div class="row">
<div class="col-md-10"><h5 class="media-heading">2016-02-23
......@@ -316,7 +314,7 @@
<h4 class="modal-title">Commit changes</h4>
</div>
<div class="modal-body">
<textarea rows="4" class="form-control" style="width:570px;" placeholder="input change log...."
<textarea rows="4" class="form-control" style="width:570px;" placeholder="Add an optional extended description..."
ng-model="commitComment"></textarea>
</div>
<div class="modal-footer">
......@@ -342,7 +340,7 @@
<input type="text" class="form-control" placeholder="input release title"
ng-model="releaseTitle" required="required">
<textarea rows="4" class="form-control" style="margin-top: 15px;" ng-model="releaseComment"
placeholder="input release log...."></textarea>
placeholder="Add an optional extended description..."></textarea>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
......@@ -387,41 +385,41 @@
</div>
<div ng-include="'common/footer.html'"></div>
<div ng-include="'views/common/footer.html'"></div>
<!-- jquery.js -->
<script src="../vendor/jquery.js" type="text/javascript"></script>
<script src="vendor/jquery.js" type="text/javascript"></script>
<!--lodash.js-->
<script src="../vendor/lodash.min.js" type="text/javascript"></script>
<script src="vendor/lodash.min.js" type="text/javascript"></script>
<!--nicescroll-->
<script src="../vendor/jquery.nicescroll.min.js"></script>
<script src="vendor/jquery.nicescroll.min.js"></script>
<!--angular-->
<script src="../vendor/angular/angular.min.js"></script>
<script src="../vendor/angular/angular-ui-router.min.js"></script>
<script src="../vendor/angular/angular-resource.min.js"></script>
<script src="../vendor/angular/angular-toastr-1.4.1.tpls.min.js"></script>
<script src="../vendor/angular/loading-bar.min.js"></script>
<script src="vendor/angular/angular.min.js"></script>
<script src="vendor/angular/angular-ui-router.min.js"></script>
<script src="vendor/angular/angular-resource.min.js"></script>
<script src="vendor/angular/angular-toastr-1.4.1.tpls.min.js"></script>
<script src="vendor/angular/loading-bar.min.js"></script>
<!-- bootstrap.js -->
<script src="../vendor/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
<script src="../vendor/bootstrap/js/bootstrap-treeview.min.js" type="text/javascript"></script>
<script src="vendor/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
<script src="vendor/bootstrap/js/bootstrap-treeview.min.js" type="text/javascript"></script>
<!--biz script-->
<script type="application/javascript" src="../scripts/app.js"></script>
<script type="application/javascript" src="scripts/app.js"></script>
<!--service-->
<script type="application/javascript" src="../scripts/services/AppService.js"></script>
<script type="application/javascript" src="../scripts/services/ConfigService.js"></script>
<script type="application/javascript" src="../scripts/AppUtils.js"></script>
<script type="application/javascript" src="scripts/services/AppService.js"></script>
<script type="application/javascript" src="scripts/services/ConfigService.js"></script>
<script type="application/javascript" src="scripts/AppUtils.js"></script>
<!--controller-->
<script type="application/javascript" src="../scripts/controller/app/AppConfigController.js"></script>
<script type="application/javascript" src="scripts/controller/app/AppConfigController.js"></script>
<script type="application/javascript" src="../scripts/PageCommon.js"></script>
<script type="application/javascript" src="scripts/PageCommon.js"></script>
</body>
</html>
......@@ -12,7 +12,7 @@
<body>
<div ng-include="'common/nav.html'"></div>
<div ng-include="'../views/common/nav.html'"></div>
<div class="container-fluid apollo-container" ng-controller="SyncItemController">
<section class="panel col-md-offset-1 col-md-10">
......@@ -175,7 +175,7 @@
</section>
</div>
<div ng-include="'common/footer.html'"></div>
<div ng-include="'../views/common/footer.html'"></div>
<!--angular-->
<script src="../vendor/angular/angular.min.js"></script>
......
......@@ -25,7 +25,7 @@
<div class="col-xs-12"><h1>Apollo</h1>
<p>携程统一配置中心<br>
<span class="package-amount">共收录了 <strong>{{appsCount}}</strong> 个项目</span>
<a class="btn btn-success" href="views/create-app.html">创建项目</a>
<a class="btn btn-success" href="app.html">创建项目</a>
</p>
<form class="" role="search">
......@@ -42,7 +42,7 @@
<div class="container-fluid apollo-container">
<div class="list-group apps">
<a class="package list-group-item" target="_blank" href="/views/app.html?#/appid={{app.appId}}"
<a class="package list-group-item" target="_blank" href="config.html?#/appid={{app.appId}}"
ng-repeat="app in apps ">
<div class="row">
<div class="col-md-3"><h4 class="apps-name">{{app.appId}}</h4></div>
......
<!doctype html>
<html ng-app="application">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- styles -->
<link rel="stylesheet" type="text/css" href="vendor/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="vendor/angular/angular-toastr-1.4.1.min.css">
<link rel="stylesheet" type="text/css" media='all' href="vendor/angular/loading-bar.min.css">
<link href="http://cdn.bootcss.com/select2/4.0.2-rc.1/css/select2.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="styles/common-style.css">
<title>新建Namespace</title>
</head>
<body>
<div ng-include="'views/common/nav.html'"></div>
<div class="container-fluid apollo-container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel">
<header class="panel-heading">
新建Namespace
</header>
<div class="panel-body">
<form class="form-horizontal" ng-controller="LinkNamespaceController" ng-submit="saveNamespace()">
<div class="form-group">
<label class="col-sm-3 control-label">应用ID</label>
<div class="col-sm-6">
{{appId}}
</div>
</div>
<div class="form-horizontal">
<div class="form-group">
<label class="col-sm-3 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%">{{namespaceIdentifer.env}}</td>
<td width="60%">{{namespaceIdentifer.name}}</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="form-group" ng-show="isRootUser">
<label class="col-sm-3 control-label"><font style="color: red">*</font>namespace类型</label>
<div class="col-sm-4">
<label class="radio-inline">
<input type="radio" name="x" ng-checked="namespaceType == 1" ng-click="selectNamespaceType(1)"> 关联
</label>
<label class="radio-inline">
<input type="radio" name="x" ng-checked="namespaceType == 2" ng-click="selectNamespaceType(2)"> 新建
</label>
</div>
</div>
<div class="form-group" ng-show="namespaceType == 2">
<label class="col-sm-3 control-label"><font style="color: red">*</font>namespace</label>
<div class="col-sm-4">
<input type="text" class="form-control" placeholder="输入namespace名称">
</div>
</div>
<div class="form-group" ng-show="namespaceType == 1">
<label class="col-sm-3 control-label"><font style="color: red">*</font>namespace</label>
<div class="col-sm-4">
<select id="namespaces">
</select>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">提交</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<div ng-include="'views/common/footer.html'"></div>
<!--angular-->
<script src="vendor/angular/angular.min.js"></script>
<script src="vendor/angular/angular-resource.min.js"></script>
<script src="vendor/angular/angular-toastr-1.4.1.tpls.min.js"></script>
<script src="vendor/angular/loading-bar.min.js"></script>
<!-- jquery.js -->
<script src="vendor/jquery.js" type="text/javascript"></script>
<script src="http://cdn.bootcss.com/select2/4.0.2-rc.1/js/select2.min.js"></script>
<!-- bootstrap.js -->
<script src="vendor/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
<script type="application/javascript" src="scripts/app.js"></script>
<script type="application/javascript" src="scripts/services/AppService.js"></script>
<script type="application/javascript" src="scripts/services/NamespaceService.js"></script>
<script type="application/javascript" src="scripts/AppUtils.js"></script>
<script type="application/javascript" src="scripts/controller/LinkNamespaceController.js"></script>
</body>
</html>
......@@ -5,7 +5,7 @@ create_app_module.controller('CreateAppController', ['$scope', '$window', 'toast
AppService.create('ALL', $scope.app).then(function (result) {
toastr.success('添加成功!');
setInterval(function () {
$window.location.href = '/views/app.html?#appid=' + result.appId;
$window.location.href = '/views/config.html?#appid=' + result.appId;
}, 1000);
}, function (result) {
toastr.error(AppUtil.errorMsg(result), '添加失败!');
......
application_module.controller("LinkNamespaceController",
['$scope', '$location', '$window', 'toastr', 'AppService', 'AppUtil', 'NamespaceService',
function ($scope, $location, $window, toastr, AppService, AppUtil, NamespaceService) {
var params = AppUtil.parseParams($location.$$url);
$scope.appId = params.appid;
$scope.isRootUser = params.root ? true : false;
////// load env //////
AppService.load_nav_tree($scope.appId).then(function (result) {
$scope.namespaceIdentifers = [];
result.nodes.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) {
var namespace = {};
namespace.id = item.name;
namespace.text = item.name;
publicNamespaces.push(namespace);
});
$('#namespaces').select2({
width: '250px',
data: publicNamespaces
});
}, function (result) {
toastr.error(AppUtil.errorMsg(result), "load public namespace error");
});
$scope.saveNamespace = function () {
var selectedClusters = collectSelectedClusters();
if (selectedClusters.length == 0){
toastr.warning("请选择集群");
return;
}
var namespaceName = $('#namespaces').select2('data')[0].id;
selectedClusters.forEach(function (cluster) {
NamespaceService.save($scope.appId, cluster.env, cluster.clusterName,
namespaceName).then(function (result) {
toastr.success(
cluster.env + "_" + result.clusterName + "_" + result.namespaceName
+ "创建成功");
}, function (result) {
toastr.error(AppUtil.errorMsg(result),
cluster.env + "_" + cluster.clusterName + "_"
+ namespaceName + "创建失败");
});
})
};
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;
}
}]);
......@@ -3,7 +3,6 @@ sync_item_module.controller("SyncItemController",
function ($scope, $location, $window, toastr, AppService, AppUtil, ConfigService) {
var params = AppUtil.parseParams($location.$$url);
var currentUser = 'test_user';
$scope.pageContext = {
appId: params.appid,
env: params.env,
......@@ -115,7 +114,7 @@ sync_item_module.controller("SyncItemController",
};
$scope.backToAppHomePage = function () {
$window.location.href = '/views/app.html?#appid=' + $scope.pageContext.appId;
$window.location.href = '/views/config.html?#appid=' + $scope.pageContext.appId;
};
$scope.switchSelect = function (o) {
......
appService.service("NamespaceService", ['$resource', '$q', function ($resource, $q) {
var namespace_source = $resource("", {}, {
find_public_namespaces: {
method: 'GET',
isArray: true,
url: '/appnamespaces/public'
},
save: {
method: 'POST',
url: '/apps/:appId/envs/:env/clusters/:clusterName/namespaces',
isArray: false
}
});
return {
find_public_namespaces: function () {
var d = $q.defer();
namespace_source.find_public_namespaces({}, function (result) {
d.resolve(result);
}, function (result) {
d.reject(result);
});
return d.promise;
},
save: function (appId, env, clusterName, namespaceName) {
var d = $q.defer();
namespace_source.save({
appId: appId,
env: env,
clusterName: clusterName
}, {
appId: appId,
clusterName: clusterName,
namespaceName: namespaceName
}, function (result) {
d.resolve(result);
}, function (result) {
d.reject(result);
});
return d.promise;
}
}
}]);
......@@ -259,3 +259,9 @@ table th {
padding-bottom: 4px;
}
.list-group-item .btn-title{
color: gray;
font-family: "Apple Color Emoji";
font-size: 16px;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册