Commit 6aaa2773 by lepdou

table view cru

parent 0b3ace80
...@@ -36,7 +36,14 @@ public class ItemController { ...@@ -36,7 +36,14 @@ public class ItemController {
BeanUtils.copyEntityProperties(entity, managedEntity); BeanUtils.copyEntityProperties(entity, managedEntity);
entity = itemService.update(managedEntity); entity = itemService.update(managedEntity);
} else { } else {
Item lastItem = itemService.findLastOne(appId, clusterName, namespaceName);
int lineNum = 1;
if (lastItem != null){
lineNum = lastItem.getLineNum() + 1;
}
entity.setLineNum(lineNum);
entity.setDataChangeCreatedBy(user.getUsername()); entity.setDataChangeCreatedBy(user.getUsername());
entity.setDataChangeLastModifiedBy(user.getUsername());
entity = itemService.save(entity); entity = itemService.save(entity);
} }
......
...@@ -12,4 +12,5 @@ public interface ItemRepository extends PagingAndSortingRepository<Item, Long> { ...@@ -12,4 +12,5 @@ public interface ItemRepository extends PagingAndSortingRepository<Item, Long> {
List<Item> findByNamespaceIdOrderByLineNumAsc(Long namespaceId); List<Item> findByNamespaceIdOrderByLineNumAsc(Long namespaceId);
Item findFirst1ByNamespaceIdOrderByLineNumDesc(Long namespaceId);
} }
...@@ -45,6 +45,17 @@ public class ItemService { ...@@ -45,6 +45,17 @@ public class ItemService {
return item; return item;
} }
public Item findLastOne(String appId, String clusterName, String namespaceName) {
Namespace namespace = namespaceRepository.findByAppIdAndClusterNameAndNamespaceName(appId,
clusterName, namespaceName);
if (namespace == null) {
throw new NotFoundException(
String.format("namespace not found for %s %s %s", appId, clusterName, namespaceName));
}
Item item = itemRepository.findFirst1ByNamespaceIdOrderByLineNumDesc(namespace.getId());
return item;
}
public Item findOne(long itemId) { public Item findOne(long itemId) {
Item item = itemRepository.findOne(itemId); Item item = itemRepository.findOne(itemId);
return item; return item;
......
...@@ -115,6 +115,12 @@ public class AdminServiceAPI { ...@@ -115,6 +115,12 @@ public class AdminServiceAPI {
.format("apps/%s/clusters/%s/namespaces/%s/itemset", appId, clusterName, namespace), .format("apps/%s/clusters/%s/namespaces/%s/itemset", appId, clusterName, namespace),
changeSets, Void.class); changeSets, Void.class);
} }
public ItemDTO createOrUpdateItem(String appId, Env env, String clusterName, String namespace, ItemDTO item){
return restTemplate.postForEntity(getAdminServiceHost(env) + String
.format("apps/%s/clusters/%s/namespaces/%s/items", appId, clusterName, namespace),
item, ItemDTO.class).getBody();
}
} }
@Service @Service
......
...@@ -37,7 +37,7 @@ public class PortalConfigController { ...@@ -37,7 +37,7 @@ public class PortalConfigController {
@RequestBody NamespaceTextModel model) { @RequestBody NamespaceTextModel model) {
if (model == null) { if (model == null) {
throw new BadRequestException("request payload shoud not be null"); throw new BadRequestException("request payload should not be null");
} }
model.setAppId(appId); model.setAppId(appId);
model.setClusterName(clusterName); model.setClusterName(clusterName);
...@@ -51,13 +51,39 @@ public class PortalConfigController { ...@@ -51,13 +51,39 @@ public class PortalConfigController {
configService.updateConfigItemByText(model); configService.updateConfigItemByText(model);
} }
@RequestMapping(value = "/apps/{appId}/env/{env}/clusters/{clusterName}/namespaces/{namespaceName}/item", method = RequestMethod.POST)
public ItemDTO createItem(@PathVariable String appId, @PathVariable String env,
@PathVariable String clusterName, @PathVariable String namespaceName,
@RequestBody ItemDTO item){
if (StringUtils.isContainEmpty(appId, env, clusterName, namespaceName)){
throw new BadRequestException("request payload should not be contain empty.");
}
if (!isValidItem(item) && item.getNamespaceId() <= 0){
throw new BadRequestException("request model is invalid");
}
return configService.createOrUpdateItem(appId, Env.valueOf(env), clusterName, namespaceName, item);
}
@RequestMapping(value = "/apps/{appId}/env/{env}/clusters/{clusterName}/namespaces/{namespaceName}/item", method = RequestMethod.PUT)
public ItemDTO updateItem(@PathVariable String appId, @PathVariable String env,
@PathVariable String clusterName, @PathVariable String namespaceName,
@RequestBody ItemDTO item){
if (StringUtils.isContainEmpty(appId, env, clusterName, namespaceName)){
throw new BadRequestException("request payload should not be contain empty.");
}
if (!isValidItem(item)){
throw new BadRequestException("request model is invalid");
}
return configService.createOrUpdateItem(appId, Env.valueOf(env), clusterName, namespaceName, item);
}
@RequestMapping(value = "/apps/{appId}/env/{env}/clusters/{clusterName}/namespaces/{namespaceName}/release", method = RequestMethod.POST, consumes = { @RequestMapping(value = "/apps/{appId}/env/{env}/clusters/{clusterName}/namespaces/{namespaceName}/release", method = RequestMethod.POST, consumes = {
"application/json"}) "application/json"})
public ReleaseDTO createRelease(@PathVariable String appId, public ReleaseDTO createRelease(@PathVariable String appId,
@PathVariable String env, @PathVariable String clusterName, @PathVariable String env, @PathVariable String clusterName,
@PathVariable String namespaceName, @RequestBody NamespaceReleaseModel model) { @PathVariable String namespaceName, @RequestBody NamespaceReleaseModel model) {
if (model == null) { if (model == null) {
throw new BadRequestException("request payload shoud not be null"); throw new BadRequestException("request payload should not be null");
} }
model.setAppId(appId); model.setAppId(appId);
model.setClusterName(clusterName); model.setClusterName(clusterName);
...@@ -77,7 +103,7 @@ public class PortalConfigController { ...@@ -77,7 +103,7 @@ public class PortalConfigController {
@PathVariable String clusterName, @PathVariable String namespaceName){ @PathVariable String clusterName, @PathVariable String namespaceName){
if (StringUtils.isContainEmpty(appId, env, clusterName, namespaceName)){ if (StringUtils.isContainEmpty(appId, env, clusterName, namespaceName)){
throw new BadRequestException("appid,env,cluster name,namespace name can not be null"); throw new BadRequestException("appid,env,cluster name,namespace name can not be empty");
} }
return configService.findItems(appId, Env.valueOf(env), clusterName, namespaceName); return configService.findItems(appId, Env.valueOf(env), clusterName, namespaceName);
...@@ -87,7 +113,7 @@ public class PortalConfigController { ...@@ -87,7 +113,7 @@ public class PortalConfigController {
"application/json"}) "application/json"})
public List<ItemDiffs> diff(@RequestBody NamespaceSyncModel model){ public List<ItemDiffs> diff(@RequestBody NamespaceSyncModel model){
if (model == null){ if (model == null){
throw new BadRequestException("request payload shoud not be null"); throw new BadRequestException("request payload should not be null");
} }
if (model.isInvalid()) { if (model.isInvalid()) {
throw new BadRequestException("request model is invalid"); throw new BadRequestException("request model is invalid");
...@@ -100,7 +126,7 @@ public class PortalConfigController { ...@@ -100,7 +126,7 @@ public class PortalConfigController {
"application/json"}) "application/json"})
public ResponseEntity<Void> update(@RequestBody NamespaceSyncModel model){ public ResponseEntity<Void> update(@RequestBody NamespaceSyncModel model){
if (model == null){ if (model == null){
throw new BadRequestException("request payload shoud not be null"); throw new BadRequestException("request payload should not be null");
} }
if (model.isInvalid()) { if (model.isInvalid()) {
throw new BadRequestException("request model is invalid"); throw new BadRequestException("request model is invalid");
...@@ -109,4 +135,8 @@ public class PortalConfigController { ...@@ -109,4 +135,8 @@ public class PortalConfigController {
return ResponseEntity.status(HttpStatus.OK).build(); return ResponseEntity.status(HttpStatus.OK).build();
} }
private boolean isValidItem(ItemDTO item){
return item != null && !StringUtils.isContainEmpty(item.getKey(), item.getValue());
}
} }
...@@ -71,6 +71,11 @@ public class PortalConfigService { ...@@ -71,6 +71,11 @@ public class PortalConfigService {
} }
} }
public ItemDTO createOrUpdateItem(String appId, Env env, String clusterName, String namespaceName, ItemDTO item){
return itemAPI.createOrUpdateItem(appId, env, clusterName, namespaceName, item);
}
/** /**
* createRelease config items * createRelease config items
*/ */
......
...@@ -25,26 +25,26 @@ ...@@ -25,26 +25,26 @@
<div class="panel-body"> <div class="panel-body">
<form class="form-horizontal" ng-controller="CreateAppController" ng-submit="create()"> <form class="form-horizontal" ng-controller="CreateAppController" ng-submit="create()">
<div class="form-group"> <div class="form-group">
<label class="col-sm-2 control-label"><font style="color: red">*</font> 应用ID</label> <label class="col-sm-2 control-label"><apollorequiredfiled></apollorequiredfiled> 应用ID</label>
<div class="col-sm-3"> <div class="col-sm-3">
<input type="text" class="form-control" name="appAppId" ng-model="app.appId" <input type="text" class="form-control" name="appAppId" ng-model="app.appId"
required> required>
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label class="col-sm-2 control-label"><font style="color: red">*</font> 应用名称</label> <label class="col-sm-2 control-label"><apollorequiredfiled></apollorequiredfiled> 应用名称</label>
<div class="col-sm-5"> <div class="col-sm-5">
<input type="text" class="form-control" name="appName" ng-model="app.name" required> <input type="text" class="form-control" name="appName" ng-model="app.name" required>
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label class="col-sm-2 control-label"><font style="color: red">*</font>应用Owner</label> <label class="col-sm-2 control-label"><apollorequiredfiled></apollorequiredfiled>应用Owner</label>
<div class="col-sm-3"> <div class="col-sm-3">
<input type="text" class="form-control" name="appOwner" ng-model="app.ownerName" required> <input type="text" class="form-control" name="appOwner" ng-model="app.ownerName" required>
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label class="col-sm-2 control-label"><font style="color: red">*</font>邮箱地址</label> <label class="col-sm-2 control-label"><apollorequiredfiled></apollorequiredfiled>邮箱地址</label>
<div class="col-sm-4"> <div class="col-sm-4">
<input type="email" class="form-control" ng-model="app.ownerEmail" required> <input type="email" class="form-control" ng-model="app.ownerEmail" required>
</div> </div>
......
...@@ -60,7 +60,7 @@ ...@@ -60,7 +60,7 @@
<label class="control-label">需要同步的配置</label> <label class="control-label">需要同步的配置</label>
</div> </div>
<div class="col-sm-10"> <div class="col-sm-10">
<table class="table table-bordered table-striped table-hover"> <table class="table table-bordered table-striped table-hover" >
<thead> <thead>
<tr> <tr>
<td><input type="checkbox" ng-click="toggleItemsCheckedStatus()"></td> <td><input type="checkbox" ng-click="toggleItemsCheckedStatus()"></td>
......
/** navbar */ /** navbar */
directive_module.directive('apollonav', function ($compile, $window, AppService, EnvService) { directive_module.directive('apollonav', function ($compile, $window, AppService, EnvService) {
return { return {
...@@ -10,7 +9,7 @@ directive_module.directive('apollonav', function ($compile, $window, AppService, ...@@ -10,7 +9,7 @@ directive_module.directive('apollonav', function ($compile, $window, AppService,
scope.sourceApps = []; scope.sourceApps = [];
scope.copyedApps = []; scope.copyedApps = [];
EnvService.find_all_envs().then(function (result) { EnvService.find_all_envs().then(function (result) {
//default select first env //default select first env
AppService.find_all_app(result[0]).then(function (result) { AppService.find_all_app(result[0]).then(function (result) {
...@@ -35,23 +34,23 @@ directive_module.directive('apollonav', function ($compile, $window, AppService, ...@@ -35,23 +34,23 @@ directive_module.directive('apollonav', function ($compile, $window, AppService,
scope.changeSearchKey = function () { scope.changeSearchKey = function () {
scope.copyedApps = []; scope.copyedApps = [];
scope.sourceApps.forEach(function (app) { scope.sourceApps.forEach(function (app) {
if (app.name.indexOf(scope.searchKey) > -1 || app.appId.indexOf(scope.searchKey) > -1) { if (app.name.indexOf(scope.searchKey) > -1 || app.appId.indexOf(scope.searchKey) > -1) {
scope.copyedApps.push(app); scope.copyedApps.push(app);
} }
}); });
scope.shouldShowAppList = true; scope.shouldShowAppList = true;
}; };
scope.jumpToConfigPage = function () { scope.jumpToConfigPage = function () {
if (selectedApp.appId){ if (selectedApp.appId) {
var needReloadPage = false; var needReloadPage = false;
if ($window.location.href.indexOf("config.html") > -1){ if ($window.location.href.indexOf("config.html") > -1) {
needReloadPage = true; needReloadPage = true;
} }
$window.location.href = '/config.html?#appid=' + selectedApp.appId; $window.location.href = '/config.html?#appid=' + selectedApp.appId;
if (needReloadPage){ if (needReloadPage) {
$window.location.reload(); $window.location.reload();
} }
} }
...@@ -72,10 +71,10 @@ directive_module.directive('apollonav', function ($compile, $window, AppService, ...@@ -72,10 +71,10 @@ directive_module.directive('apollonav', function ($compile, $window, AppService,
scope.copyedApps[--selectedAppIdx].selected = true; scope.copyedApps[--selectedAppIdx].selected = true;
} }
} else if (event.keyCode == 13) { } else if (event.keyCode == 13) {
if (scope.shouldShowAppList && selectedAppIdx > -1){ if (scope.shouldShowAppList && selectedAppIdx > -1) {
select(scope.copyedApps[selectedAppIdx]); select(scope.copyedApps[selectedAppIdx]);
event.preventDefault(); event.preventDefault();
}else { } else {
scope.jumpToConfigPage(); scope.jumpToConfigPage();
} }
...@@ -157,23 +156,39 @@ directive_module.directive('apolloclusterselector', function ($compile, $window, ...@@ -157,23 +156,39 @@ directive_module.directive('apolloclusterselector', function ($compile, $window,
scope.select(collectSelectedClusters()); scope.select(collectSelectedClusters());
}; };
scope.switchSelect = function (o) { scope.switchSelect = function (o, $event) {
o.checked = !o.checked; o.checked = !o.checked;
$event.stopPropagation();
scope.select(collectSelectedClusters());
};
scope.toggleClusterCheckedStatus = function (cluster) {
cluster.checked = !cluster.checked;
scope.select(collectSelectedClusters()); scope.select(collectSelectedClusters());
}; };
function collectSelectedClusters() { function collectSelectedClusters() {
var selectedClusters = []; var selectedClusters = [];
scope.clusters.forEach(function (cluster) { scope.clusters.forEach(function (cluster) {
if (cluster.checked){ if (cluster.checked) {
cluster.clusterName = cluster.name; cluster.clusterName = cluster.name;
selectedClusters.push(cluster); selectedClusters.push(cluster);
} }
}); });
return selectedClusters; return selectedClusters;
} }
} }
} }
}); });
directive_module.directive('apollorequiredfiled', function ($compile, $window) {
return {
restrict: 'E',
template: '<span style="color: red">*</span>',
transclude: true,
replace: true
}
});
...@@ -5,10 +5,10 @@ appService.service("ConfigService", ['$resource', '$q', function ($resource, $q) ...@@ -5,10 +5,10 @@ appService.service("ConfigService", ['$resource', '$q', function ($resource, $q)
isArray: true, isArray: true,
url: '/apps/:appId/env/:env/clusters/:clusterName/namespaces' url: '/apps/:appId/env/:env/clusters/:clusterName/namespaces'
}, },
find_items:{ find_items: {
method:'GET', method: 'GET',
isArray: true, isArray: true,
url:'/apps/:appId/env/:env/clusters/:clusterName/namespaces/:namespaceName/items' url: '/apps/:appId/env/:env/clusters/:clusterName/namespaces/:namespaceName/items'
}, },
modify_items: { modify_items: {
method: 'PUT', method: 'PUT',
...@@ -16,7 +16,7 @@ appService.service("ConfigService", ['$resource', '$q', function ($resource, $q) ...@@ -16,7 +16,7 @@ appService.service("ConfigService", ['$resource', '$q', function ($resource, $q)
}, },
release: { release: {
method: 'POST', method: 'POST',
url:'/apps/:appId/env/:env/clusters/:clusterName/namespaces/:namespaceName/release' url: '/apps/:appId/env/:env/clusters/:clusterName/namespaces/:namespaceName/release'
}, },
diff: { diff: {
method: 'POST', method: 'POST',
...@@ -27,6 +27,14 @@ appService.service("ConfigService", ['$resource', '$q', function ($resource, $q) ...@@ -27,6 +27,14 @@ appService.service("ConfigService", ['$resource', '$q', function ($resource, $q)
method: 'PUT', method: 'PUT',
url: '/namespaces/:namespaceName/items', url: '/namespaces/:namespaceName/items',
isArray: false isArray: false
},
create_item: {
method: 'POST',
url: '/apps/:appId/env/:env/clusters/:clusterName/namespaces/:namespaceName/item'
},
update_item: {
method: 'PUT',
url: '/apps/:appId/env/:env/clusters/:clusterName/namespaces/:namespaceName/item'
} }
}); });
...@@ -34,10 +42,10 @@ appService.service("ConfigService", ['$resource', '$q', function ($resource, $q) ...@@ -34,10 +42,10 @@ appService.service("ConfigService", ['$resource', '$q', function ($resource, $q)
load_all_namespaces: function (appId, env, clusterName) { load_all_namespaces: function (appId, env, clusterName) {
var d = $q.defer(); var d = $q.defer();
config_source.load_all_namespaces({ config_source.load_all_namespaces({
appId: appId, appId: appId,
env: env, env: env,
clusterName: clusterName clusterName: clusterName
}, function (result) { }, function (result) {
d.resolve(result); d.resolve(result);
}, function (result) { }, function (result) {
d.reject(result); d.reject(result);
...@@ -52,9 +60,9 @@ appService.service("ConfigService", ['$resource', '$q', function ($resource, $q) ...@@ -52,9 +60,9 @@ appService.service("ConfigService", ['$resource', '$q', function ($resource, $q)
clusterName: clusterName, clusterName: clusterName,
namespaceName: namespaceName namespaceName: namespaceName
}, function (result) { }, function (result) {
d.resolve(result); d.resolve(result);
}, function (result) { }, function (result) {
d.reject(result); d.reject(result);
}); });
return d.promise; return d.promise;
}, },
...@@ -70,16 +78,16 @@ appService.service("ConfigService", ['$resource', '$q', function ($resource, $q) ...@@ -70,16 +78,16 @@ appService.service("ConfigService", ['$resource', '$q', function ($resource, $q)
{ {
configText: configText, configText: configText,
namespaceId: namespaceId, namespaceId: namespaceId,
comment:comment comment: comment
}, function (result) { }, function (result) {
d.resolve(result); d.resolve(result);
}, function (result) { }, function (result) {
d.reject(result); d.reject(result);
}); });
return d.promise; return d.promise;
}, },
release: function (appId, env, clusterName, namespaceName, releaseBy, comment) { release: function (appId, env, clusterName, namespaceName, releaseBy, comment) {
var d = $q.defer(); var d = $q.defer();
config_source.release({ config_source.release({
...@@ -113,8 +121,38 @@ appService.service("ConfigService", ['$resource', '$q', function ($resource, $q) ...@@ -113,8 +121,38 @@ appService.service("ConfigService", ['$resource', '$q', function ($resource, $q)
sync_items: function (namespaceName, sourceData) { sync_items: function (namespaceName, sourceData) {
var d = $q.defer(); var d = $q.defer();
config_source.sync_item({ config_source.sync_item({
namespaceName: namespaceName namespaceName: namespaceName
}, sourceData, function (result) { }, sourceData, function (result) {
d.resolve(result);
}, function (result) {
d.reject(result);
});
return d.promise;
},
create_item: function (appId, env, clusterName, namespaceName, item) {
var d = $q.defer();
config_source.create_item({
appId: appId,
env: env,
clusterName: clusterName,
namespaceName: namespaceName
}, item, function (result) {
d.resolve(result);
}, function (result) {
d.reject(result);
});
return d.promise;
},
update_item: function (appId, env, clusterName, namespaceName, item) {
var d = $q.defer();
config_source.update_item({
appId: appId,
env: env,
clusterName: clusterName,
namespaceName: namespaceName
}, item, function (result) {
d.resolve(result); d.resolve(result);
}, function (result) { }, function (result) {
d.reject(result); d.reject(result);
......
...@@ -212,22 +212,21 @@ table th { ...@@ -212,22 +212,21 @@ table th {
} }
.namespace-view-table { .namespace-view-table {
max-height: 700px;
}
.namespace-view-table table {
table-layout: fixed;
} }
.namespace-view-table tr { .namespace-view-table table {
cursor: pointer; table-layout: inherit;
} }
.namespace-view-table td { .namespace-view-table td {
word-wrap: break-word; word-wrap: break-word;
} }
.namespace-view-table .glyphicon{
cursor: pointer;
}
.history-view { .history-view {
padding: 50px 20px; padding: 50px 20px;
......
<table class="table table-hover"> <table class="table table-hover" style="width: 250px">
<thead> <thead>
<tr> <tr>
<td><input type="checkbox" ng-checked="envAllSelected" ng-click="toggleEnvsCheckedStatus()"></td> <td><input type="checkbox" ng-checked="envAllSelected" ng-click="toggleEnvsCheckedStatus()"></td>
...@@ -8,9 +8,9 @@ ...@@ -8,9 +8,9 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr ng-repeat="cluster in clusters"> <tr style="cursor: pointer" ng-repeat="cluster in clusters" ng-click="toggleClusterCheckedStatus(cluster)">
<td width="10%"><input type="checkbox" ng-checked="cluster.checked" <td width="10%"><input type="checkbox" ng-checked="cluster.checked"
ng-click="switchSelect(cluster)"></td> ng-click="switchSelect(cluster, $event)"></td>
<td width="30%" ng-bind="cluster.env"></td> <td width="30%" ng-bind="cluster.env"></td>
<td width="60%" ng-bind="cluster.name"></td> <td width="60%" ng-bind="cluster.name"></td>
</tr> </tr>
......
19575
\ No newline at end of file
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