Commit 6aaa2773 by lepdou

table view cru

parent 0b3ace80
......@@ -36,7 +36,14 @@ public class ItemController {
BeanUtils.copyEntityProperties(entity, managedEntity);
entity = itemService.update(managedEntity);
} 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.setDataChangeLastModifiedBy(user.getUsername());
entity = itemService.save(entity);
}
......
......@@ -12,4 +12,5 @@ public interface ItemRepository extends PagingAndSortingRepository<Item, Long> {
List<Item> findByNamespaceIdOrderByLineNumAsc(Long namespaceId);
Item findFirst1ByNamespaceIdOrderByLineNumDesc(Long namespaceId);
}
......@@ -45,6 +45,17 @@ public class ItemService {
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) {
Item item = itemRepository.findOne(itemId);
return item;
......
......@@ -115,6 +115,12 @@ public class AdminServiceAPI {
.format("apps/%s/clusters/%s/namespaces/%s/itemset", appId, clusterName, namespace),
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
......
......@@ -37,7 +37,7 @@ public class PortalConfigController {
@RequestBody NamespaceTextModel model) {
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.setClusterName(clusterName);
......@@ -51,13 +51,39 @@ public class PortalConfigController {
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 = {
"application/json"})
public ReleaseDTO createRelease(@PathVariable String appId,
@PathVariable String env, @PathVariable String clusterName,
@PathVariable String namespaceName, @RequestBody NamespaceReleaseModel model) {
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.setClusterName(clusterName);
......@@ -77,7 +103,7 @@ public class PortalConfigController {
@PathVariable String clusterName, @PathVariable String 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);
......@@ -87,7 +113,7 @@ public class PortalConfigController {
"application/json"})
public List<ItemDiffs> diff(@RequestBody NamespaceSyncModel model){
if (model == null){
throw new BadRequestException("request payload shoud not be null");
throw new BadRequestException("request payload should not be null");
}
if (model.isInvalid()) {
throw new BadRequestException("request model is invalid");
......@@ -100,7 +126,7 @@ public class PortalConfigController {
"application/json"})
public ResponseEntity<Void> update(@RequestBody NamespaceSyncModel model){
if (model == null){
throw new BadRequestException("request payload shoud not be null");
throw new BadRequestException("request payload should not be null");
}
if (model.isInvalid()) {
throw new BadRequestException("request model is invalid");
......@@ -109,4 +135,8 @@ public class PortalConfigController {
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 {
}
}
public ItemDTO createOrUpdateItem(String appId, Env env, String clusterName, String namespaceName, ItemDTO item){
return itemAPI.createOrUpdateItem(appId, env, clusterName, namespaceName, item);
}
/**
* createRelease config items
*/
......
......@@ -25,26 +25,26 @@
<div class="panel-body">
<form class="form-horizontal" ng-controller="CreateAppController" ng-submit="create()">
<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">
<input type="text" class="form-control" name="appAppId" ng-model="app.appId"
required>
</div>
</div>
<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">
<input type="text" class="form-control" name="appName" ng-model="app.name" required>
</div>
</div>
<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">
<input type="text" class="form-control" name="appOwner" ng-model="app.ownerName" required>
</div>
</div>
<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">
<input type="email" class="form-control" ng-model="app.ownerEmail" required>
</div>
......
......@@ -60,7 +60,7 @@
<label class="control-label">需要同步的配置</label>
</div>
<div class="col-sm-10">
<table class="table table-bordered table-striped table-hover">
<table class="table table-bordered table-striped table-hover" >
<thead>
<tr>
<td><input type="checkbox" ng-click="toggleItemsCheckedStatus()"></td>
......
/** navbar */
directive_module.directive('apollonav', function ($compile, $window, AppService, EnvService) {
return {
......@@ -44,14 +43,14 @@ directive_module.directive('apollonav', function ($compile, $window, AppService,
};
scope.jumpToConfigPage = function () {
if (selectedApp.appId){
if (selectedApp.appId) {
var needReloadPage = false;
if ($window.location.href.indexOf("config.html") > -1){
if ($window.location.href.indexOf("config.html") > -1) {
needReloadPage = true;
}
$window.location.href = '/config.html?#appid=' + selectedApp.appId;
if (needReloadPage){
if (needReloadPage) {
$window.location.reload();
}
}
......@@ -72,10 +71,10 @@ directive_module.directive('apollonav', function ($compile, $window, AppService,
scope.copyedApps[--selectedAppIdx].selected = true;
}
} else if (event.keyCode == 13) {
if (scope.shouldShowAppList && selectedAppIdx > -1){
if (scope.shouldShowAppList && selectedAppIdx > -1) {
select(scope.copyedApps[selectedAppIdx]);
event.preventDefault();
}else {
} else {
scope.jumpToConfigPage();
}
......@@ -157,15 +156,21 @@ directive_module.directive('apolloclusterselector', function ($compile, $window,
scope.select(collectSelectedClusters());
};
scope.switchSelect = function (o) {
scope.switchSelect = function (o, $event) {
o.checked = !o.checked;
$event.stopPropagation();
scope.select(collectSelectedClusters());
};
scope.toggleClusterCheckedStatus = function (cluster) {
cluster.checked = !cluster.checked;
scope.select(collectSelectedClusters());
};
function collectSelectedClusters() {
var selectedClusters = [];
scope.clusters.forEach(function (cluster) {
if (cluster.checked){
if (cluster.checked) {
cluster.clusterName = cluster.name;
selectedClusters.push(cluster);
}
......@@ -177,3 +182,13 @@ directive_module.directive('apolloclusterselector', function ($compile, $window,
}
});
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)
isArray: true,
url: '/apps/:appId/env/:env/clusters/:clusterName/namespaces'
},
find_items:{
method:'GET',
find_items: {
method: 'GET',
isArray: true,
url:'/apps/:appId/env/:env/clusters/:clusterName/namespaces/:namespaceName/items'
url: '/apps/:appId/env/:env/clusters/:clusterName/namespaces/:namespaceName/items'
},
modify_items: {
method: 'PUT',
......@@ -16,7 +16,7 @@ appService.service("ConfigService", ['$resource', '$q', function ($resource, $q)
},
release: {
method: 'POST',
url:'/apps/:appId/env/:env/clusters/:clusterName/namespaces/:namespaceName/release'
url: '/apps/:appId/env/:env/clusters/:clusterName/namespaces/:namespaceName/release'
},
diff: {
method: 'POST',
......@@ -27,6 +27,14 @@ appService.service("ConfigService", ['$resource', '$q', function ($resource, $q)
method: 'PUT',
url: '/namespaces/:namespaceName/items',
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'
}
});
......@@ -70,7 +78,7 @@ appService.service("ConfigService", ['$resource', '$q', function ($resource, $q)
{
configText: configText,
namespaceId: namespaceId,
comment:comment
comment: comment
}, function (result) {
d.resolve(result);
......@@ -120,6 +128,36 @@ appService.service("ConfigService", ['$resource', '$q', function ($resource, $q)
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);
}, function (result) {
d.reject(result);
});
return d.promise;
}
}
......
......@@ -212,22 +212,21 @@ table th {
}
.namespace-view-table {
max-height: 700px;
}
.namespace-view-table table {
table-layout: fixed;
}
.namespace-view-table tr {
cursor: pointer;
.namespace-view-table table {
table-layout: inherit;
}
.namespace-view-table td {
word-wrap: break-word;
}
.namespace-view-table .glyphicon{
cursor: pointer;
}
.history-view {
padding: 50px 20px;
......
<table class="table table-hover">
<table class="table table-hover" style="width: 250px">
<thead>
<tr>
<td><input type="checkbox" ng-checked="envAllSelected" ng-click="toggleEnvsCheckedStatus()"></td>
......@@ -8,9 +8,9 @@
</tr>
</thead>
<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"
ng-click="switchSelect(cluster)"></td>
ng-click="switchSelect(cluster, $event)"></td>
<td width="30%" ng-bind="cluster.env"></td>
<td width="60%" ng-bind="cluster.name"></td>
</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