Commit 1437f2b9 by lepdou

server config has page to config

parent 9f28a766
package com.ctrip.framework.apollo.portal;
import com.google.common.collect.Lists;
import java.util.ArrayList;
import java.util.Arrays;
......@@ -58,8 +57,7 @@ public class PortalSettings {
//初始化portal支持操作的环境集合,线上的portal可能支持所有的环境操作,而线下环境则支持一部分.
// 每个环境的portal支持哪些环境配置在数据库里
ServerConfig serverConfig = serverConfigRepository.findByKey("apollo.portal.envs");
// TODO: 16/5/24 线上环境暂时从本地配置里拿,之后也放在数据库上并提供界面可操作
if (serverConfig != null){//如果db有配置则从db里取
if (serverConfig != null){
String[] configedEnvs = serverConfig.getValue().split(",");
allStrEnvs = Arrays.asList(configedEnvs);
}
......
package com.ctrip.framework.apollo.portal.controller;
import com.ctrip.framework.apollo.common.utils.BeanUtils;
import com.ctrip.framework.apollo.core.exception.BadRequestException;
import com.ctrip.framework.apollo.core.utils.StringUtils;
import com.ctrip.framework.apollo.portal.entity.po.ServerConfig;
import com.ctrip.framework.apollo.portal.repository.ServerConfigRepository;
import org.springframework.beans.factory.annotation.Autowired;
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;
/**
* 配置中心本身需要一些配置,这些配置放在数据库里面
*/
@RestController
public class PortalServerConfigController {
@Autowired
private ServerConfigRepository serverConfigRepository;
@RequestMapping(value = "/server/config", method = RequestMethod.POST)
public ServerConfig createOrUpdate(@RequestBody ServerConfig serverConfig) {
if (serverConfig == null || StringUtils.isContainEmpty(serverConfig.getKey(), serverConfig.getValue())) {
throw new BadRequestException("request payload contains empty");
}
// TODO: 16/6/2 接入sso之后改成当前登录用户
String modifiedBy = "admin";
ServerConfig storedConfig = serverConfigRepository.findByKey(serverConfig.getKey());
if (storedConfig == null) {//create
serverConfig.setDataChangeCreatedBy(modifiedBy);
serverConfig.setDataChangeLastModifiedBy(modifiedBy);
return serverConfigRepository.save(serverConfig);
} else {//update
BeanUtils.copyEntityProperties(serverConfig, storedConfig);
storedConfig.setDataChangeLastModifiedBy(modifiedBy);
return serverConfigRepository.save(storedConfig);
}
}
}
......@@ -5,9 +5,6 @@ import com.ctrip.framework.apollo.portal.entity.po.ServerConfig;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
* @author Jason Song(song_s@ctrip.com)
*/
public interface ServerConfigRepository extends PagingAndSortingRepository<ServerConfig, Long> {
ServerConfig findByKey(String key);
}
......@@ -13,12 +13,13 @@ var index_module = angular.module('index', ['toastr', 'app.service', 'app.util',
//项目主页
var application_module = angular.module('application', ['app.service', 'apollo.directive', 'app.util', 'toastr', 'angular-loading-bar']);
//创建项目页面
var create_app_module = angular.module('create_app', ['ngResource', 'apollo.directive', 'toastr', 'app.service', 'app.util', 'angular-loading-bar']);
var create_app_module = angular.module('create_app', ['apollo.directive', 'toastr', 'app.service', 'app.util', 'angular-loading-bar']);
//配置同步页面
var sync_item_module = angular.module('sync_item', ['app.service', 'apollo.directive', 'app.util', 'toastr', 'angular-loading-bar']);
//namespace
var namespace_module = angular.module('namespace', ['app.service', 'apollo.directive', 'app.util', 'toastr', 'angular-loading-bar']);
//server config
var server_config_module = angular.module('server_config', ['app.service', 'apollo.directive', 'app.util', 'toastr', 'angular-loading-bar']);
......
server_config_module.controller('ServerConfigController',
['$scope', '$window', 'toastr', 'ServerConfigService', 'AppUtil',
function ($scope, $window, toastr, ServerConfigService, AppUtil) {
$scope.serverConfig = {};
$scope.create = function () {
ServerConfigService.create($scope.serverConfig).then(function (result) {
toastr.success("添加成功");
}, function (result) {
toastr.error(AppUtil.errorMsg(result), "添加失败");
});
};
}]);
appService.service('ServerConfigService', ['$resource', '$q', function ($resource, $q) {
var server_config_resource = $resource('', {}, {
create_server_config: {
method: 'POST',
url:'/server/config'
}
});
return {
create: function (serverConfig) {
var d = $q.defer();
server_config_resource.create_server_config({}, serverConfig, function (result) {
d.resolve(result);
}, function (result) {
d.reject(result);
});
return d.promise;
}
}
}]);
<!doctype html>
<html ng-app="server_config">
<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">
<title>应用配置</title>
</head>
<body>
<apollonav></apollonav>
<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">
应用配置
</header>
<div class="panel-body">
<form class="form-horizontal" ng-controller="ServerConfigController" ng-submit="create()">
<div class="form-group">
<label class="col-sm-2 control-label">
<apollorequiredfiled></apollorequiredfiled>
key</label>
<div class="col-sm-9">
<input type="text" class="form-control" name="key" ng-model="serverConfig.key"
required>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">
<apollorequiredfiled></apollorequiredfiled>
value</label>
<div class="col-sm-9">
<textarea class="form-control" rows="4" name="comment" ng-model="serverConfig.value"></textarea>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">
comment</label>
<div class="col-sm-9">
<textarea class="form-control" rows="4" name="comment" ng-model="serverConfig.comment"></textarea>
</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-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.min.js" type="text/javascript"></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/directive.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/EnvService.js"></script>
<script type="application/javascript" src="scripts/services/ServerConfigService.js"></script>
<script type="application/javascript" src="scripts/controller/ServerConfigController.js"></script>
</body>
</html>
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