Commit 83ae4032 by lepdou

rollback 优化

parent 4d79b4f7
......@@ -5,18 +5,49 @@ import java.util.List;
public class ReleaseCompareResult {
private List<EntityPair<KVEntity>> changes = new LinkedList<>();
private List<Change> changes = new LinkedList<>();
public void addEntityPair(KVEntity firstEntity, KVEntity secondEntity){
changes.add(new EntityPair<>(firstEntity, secondEntity));
public void addEntityPair(ChangeType type, KVEntity firstEntity, KVEntity secondEntity) {
changes.add(new Change(type, new EntityPair<>(firstEntity, secondEntity)));
}
public List<EntityPair<KVEntity>> getChanges() {
public List<Change> getChanges() {
return changes;
}
public void setChanges(
List<EntityPair<KVEntity>> changes) {
public void setChanges(List<Change> changes) {
this.changes = changes;
}
public class Change {
private ChangeType type;
private EntityPair<KVEntity> entity;
public Change(ChangeType type, EntityPair<KVEntity> entity) {
this.type = type;
this.entity = entity;
}
public ChangeType getType() {
return type;
}
public void setType(ChangeType type) {
this.type = type;
}
public EntityPair<KVEntity> getEntity() {
return entity;
}
public void setEntity(
EntityPair<KVEntity> entity) {
this.entity = entity;
}
}
public enum ChangeType {
ADD, MODIFY, DELETE
}
}
......@@ -98,9 +98,15 @@ public class ReleaseService {
String key = entry.getKey();
String firstValue = entry.getValue();
String secondValue = secondItems.get(key);
if (!Objects.equal(firstValue, secondValue)) {
compareResult.addEntityPair(new KVEntity(key, firstValue), new KVEntity(key, secondValue));
//added
if (secondValue == null) {
compareResult.addEntityPair(ReleaseCompareResult.ChangeType.DELETE, new KVEntity(key, firstValue),
new KVEntity(key, secondValue));
} else if (!Objects.equal(firstValue, secondValue)) {
compareResult.addEntityPair(ReleaseCompareResult.ChangeType.MODIFY, new KVEntity(key, firstValue),
new KVEntity(key, secondValue));
}
}
//deleted in firstRelease
......@@ -108,7 +114,8 @@ public class ReleaseService {
String key = entry.getKey();
String value = entry.getValue();
if (firstItems.get(key) == null) {
compareResult.addEntityPair(new KVEntity(key, ""), new KVEntity(key, value));
compareResult
.addEntityPair(ReleaseCompareResult.ChangeType.ADD, new KVEntity(key, ""), new KVEntity(key, value));
}
}
......
......@@ -97,7 +97,7 @@
pre-release-ns="prepareReleaseNamespace"
create-item="createItem" edit-item="editItem"
pre-delete-item="preDeleteItem" commit-change="commitChange"
show-rollback-tips="showRollbackTips"></apollonspanel>
pre-rollback="preRollback"></apollonspanel>
</div>
<!-- delete modal-->
......@@ -116,9 +116,9 @@
apollo-detail="'您不能发布哟~ 编辑和发布不能为同一个人'"
apollo-show-cancel-btn="false"></apolloconfirmdialog>
<apolloconfirmdialog apollo-dialog-id="'rollbackTips'" apollo-title="'回滚'"
apollo-detail="'此操作将会回滚到上一个发布版本,且作废当前版本。确定要回滚吗?'"
apollo-show-cancel-btn="true" apollo-confirm="preRollback"></apolloconfirmdialog>
<apolloconfirmdialog apollo-dialog-id="'rollbackAlertDialog'" apollo-title="'回滚'"
apollo-detail="'确定要回滚吗?'"
apollo-show-cancel-btn="true" apollo-confirm="rollback"></apolloconfirmdialog>
<!--create createRelease modal-->
......@@ -325,29 +325,37 @@
<!--rollback-->
<form class="modal fade form-horizontal" id="rollbackModal" tabindex="-1" role="dialog"
ng-submit="rollback()">
ng-submit="showRollbackAlertDialog()">
<div class="modal-dialog" role="document" style="width: 960px">
<div class="modal-content">
<div class="modal-header panel-primary">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
aria-hidden="true">&times;</span></button>
<h4 class="modal-title">回滚</h4>
</div>
<div class="modal-body">
<div class="row text-center">
<div class="modal-title text-center">
<span style="font-size: 18px;" ng-bind="firstRelease.name"></span>
<span style="font-size: 18px;"> &nbsp;回滚到&nbsp;</span>
<span style="font-size: 18px;" ng-bind="secondRelease.name"></span>
</div>
</div>
<div class="modal-body">
<div class="alert alert-warning" role="alert">
此操作将会回滚到上一个发布版本,且当前版本作废,但不影响正在修改的配置。可在发布历史页面查看当前生效的版本
<a target="_blank"
href="/config/history.html?#/appid={{toRollbackNamespace.baseInfo.appId}}&env={{pageContext.env}}&clusterName={{toRollbackNamespace.baseInfo.clusterName}}&namespaceName={{toRollbackNamespace.baseInfo.namespaceName}}">点击查看</a>
</div>
<div class="form-group" style="margin-top: 15px;">
<label class="col-sm-2 control-label">
Changes:</label>
<div class="col-sm-10" ng-if="releaseCompareResult.length > 0">
<table class="table table-bordered table-striped text-center table-hover">
<!--properties format-->
<div class="col-sm-12"
ng-if="releaseCompareResult.length > 0 && toRollbackNamespace.isPropertiesFormat">
<table class="table table-bordered table-striped text-center table-hover"
ng-if="toRollbackNamespace.isPropertiesFormat">
<thead>
<tr>
<th>
Type
</th>
<th>
Key
</th>
<th>
......@@ -360,22 +368,45 @@
</thead>
<tbody>
<tr ng-repeat="pair in releaseCompareResult">
<td width="20%" ng-bind="pair.firstEntity.key">
<tr ng-repeat="change in releaseCompareResult">
<td width="10%">
<span ng-show="change.type == 'ADD'">新增</span>
<span ng-show="change.type == 'MODIFY'">更新</span>
<span ng-show="change.type == 'DELETE'">删除</span>
</td>
<td width="20%" ng-bind="change.entity.firstEntity.key">
</td>
<td width="40%" ng-bind="pair.firstEntity.value">
<td width="35%" ng-bind="change.entity.firstEntity.value">
</td>
<td width="40%" ng-bind="pair.secondEntity.value">
<td width="35%" ng-bind="change.entity.secondEntity.value">
</td>
</tr>
</tbody>
</table>
</div>
<div class="col-sm-5">
<span ng-if="releaseCompareResult.length == 0">
<!--file format -->
<div class="col-sm-12"
ng-if="releaseCompareResult.length > 0 && !toRollbackNamespace.isPropertiesFormat">
<div ng-repeat="change in releaseCompareResult"
ng-if="!toRollbackNamespace.isPropertiesFormat">
<h5>回滚前</h5>
<textarea class="form-control no-radius" rows="20"
ng-disabled="true" ng-bind="change.entity.firstEntity.value">
</textarea>
<hr>
<h5>回滚后</h5>
<textarea class="form-control no-radius" rows="20"
ng-disabled="true" ng-bind="change.entity.secondEntity.value">
</textarea>
</div>
</div>
<div class="col-sm-12 text-center" ng-if="releaseCompareResult.length == 0">
<h4>
配置没有变化
</span>
</h4>
</div>
</div>
......@@ -384,7 +415,7 @@
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
<button type="submit" class="btn btn-danger" ng-if="releaseCompareResult.length > 0"
ng-disabled="rollbackBtnDisabled">确定回滚
ng-disabled="rollbackBtnDisabled">回滚
</button>
</div>
</div>
......
......@@ -12,26 +12,18 @@ $(document).ready(function () {
zindex: '1000'
});
// bootstrap tooltip
// bootstrap tooltip & textarea scroll
setInterval(function () {
$('[data-tooltip="tooltip"]').tooltip();
$('html').bind('mousewheel DOMMouseScroll',
function (e) {
var e0 = e.originalEvent,
delta = e0.wheelDelta
|| -e0.detail;
this.scrollTop +=
( delta < 0 ? 1 : -1 ) * 30;
e.preventDefault();
});
$("textarea").niceScroll({styler: "fb", cursorcolor: "#fff"});
}, 2500);
});
// (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423
// (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423
// (new Date()).Format("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18
Date.prototype.Format = function (fmt) {
Date.prototype.Format = function (fmt) {
var o = {
"M+": this.getMonth() + 1, //月份
"d+": this.getDate(), //日
......
......@@ -26,7 +26,7 @@ application_module.controller("ConfigNamespaceController",
$scope.release = release;
$scope.showRollbackTips = showRollbackTips;
$scope.showRollbackAlertDialog = showRollbackAlertDialog;
$scope.preRollback = preRollback;
......@@ -75,7 +75,7 @@ application_module.controller("ConfigNamespaceController",
function (result) {
$scope.namespaces = result;
}, function (result) {
toastr.error(AppUtil.errorMsg(result), "加载配置信息出错");
});
......@@ -152,21 +152,20 @@ application_module.controller("ConfigNamespaceController",
);
}
var toRollbackNamespace = {};
function showRollbackTips(namespace) {
toRollbackNamespace = namespace;
$("#rollbackTips").modal('show');
function showRollbackAlertDialog() {
$("#rollbackModal").modal('hide');
$("#rollbackAlertDialog").modal('show');
}
function preRollback() {
$scope.toRollbackNamespace = {};
function preRollback(namespace) {
$scope.toRollbackNamespace = namespace;
//load latest two active releases
ReleaseService.findActiveRelease($rootScope.pageContext.appId,
$rootScope.pageContext.env,
$rootScope.pageContext.clusterName,
toRollbackNamespace.baseInfo.namespaceName, 0, 2)
$scope.toRollbackNamespace.baseInfo.namespaceName, 0, 2)
.then(function (result) {
if (result.length <= 1) {
toastr.error("没有可以回滚的发布历史");
......@@ -180,6 +179,7 @@ application_module.controller("ConfigNamespaceController",
$scope.secondRelease.id)
.then(function (result) {
$scope.releaseCompareResult = result.changes;
$("#rollbackModal").modal('show');
}, function (result) {
toastr.error(AppUtil.errorMsg(result), "对比失败");
......
......@@ -12,7 +12,7 @@ directive_module.directive('apollonspanel',
env: '=',
cluster: '=',
preReleaseNs: '=',
showRollbackTips: '=',
preRollback: '=',
createItem: '=',
editItem: '=',
preDeleteItem: '=',
......
......@@ -33,7 +33,7 @@
<button type="button"
class="btn btn-default btn-sm J_tableview_btn"
ng-show="namespace.hasReleasePermission"
ng-click="showRollbackTips(namespace)">
ng-click="preRollback(namespace)">
<img src="img/rollback.png">
回滚
</button>
......
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