Commit 05281db8 by Jason Song

Merge pull request #230 from lepdou/bugfix

文本模式下value包含\n处理
parents ea3563c5 71c4ec27
...@@ -213,11 +213,18 @@ ...@@ -213,11 +213,18 @@
</header> </header>
<!--text view--> <!--text view-->
<!--只读模式下的文本内容,不替换换行符-->
<textarea class="form-control" rows="{{namespace.itemCnt}}" style="border-radius: 0px" <textarea class="form-control" rows="{{namespace.itemCnt}}" style="border-radius: 0px"
ng-show="namespace.viewType == 'text'" ng-show="namespace.viewType == 'text' && !namespace.isTextEditing"
ng-disabled="!namespace.isTextEditing" ng-model="namespace.text" ng-disabled="!namespace.isTextEditing" ng-model="namespace.text"
ng-bind="namespace.text"> ng-bind="namespace.text">
</textarea> </textarea>
<!--编辑状态下的文本内容,会过滤掉换行符-->
<textarea class="form-control" rows="{{namespace.itemCnt}}" style="border-radius: 0px"
ng-show="namespace.viewType == 'text' && namespace.isTextEditing"
ng-disabled="!namespace.isTextEditing" ng-model="namespace.editText"
ng-bind="namespace.editText">
</textarea>
<!--table view--> <!--table view-->
<div class="namespace-view-table"> <div class="namespace-view-table">
......
...@@ -63,7 +63,7 @@ application_module.controller("ConfigNamespaceController", ...@@ -63,7 +63,7 @@ application_module.controller("ConfigNamespaceController",
var MAX_ROW_SIZE = 30; var MAX_ROW_SIZE = 30;
var APPEND_ROW_SIZE = 8; var APPEND_ROW_SIZE = 8;
//把表格内容解析成文本 //把表格内容解析成文本
function parseModel2Text(namespace) { function parseModel2Text(namespace, modeType) {
if (!namespace.items) { if (!namespace.items) {
return "无配置信息"; return "无配置信息";
...@@ -72,8 +72,18 @@ application_module.controller("ConfigNamespaceController", ...@@ -72,8 +72,18 @@ application_module.controller("ConfigNamespaceController",
var itemCnt = 0; var itemCnt = 0;
namespace.items.forEach(function (item) { namespace.items.forEach(function (item) {
if (item.item.key) { if (item.item.key) {
var itemValue = item.item.value;
if (modeType == 'edit') {//编辑状态下替换value的换行符
if (item.item.value && (item.item.value.indexOf("\n") > -1)) {
alert("警告:[" + item.item.key + "]的值包含换行符\\n,文本编辑会过滤掉换行符.");
while (itemValue.indexOf("\n") > -1) {
itemValue = itemValue.replace("\n", "");
}
}
}
result += result +=
item.item.key + " = " + item.item.value + "\n"; item.item.key + " = " + itemValue + "\n";
} else { } else {
result += item.item.comment + "\n"; result += item.item.comment + "\n";
} }
...@@ -97,7 +107,7 @@ application_module.controller("ConfigNamespaceController", ...@@ -97,7 +107,7 @@ application_module.controller("ConfigNamespaceController",
ConfigService.modify_items($scope.pageContext.appId, $scope.pageContext.env, ConfigService.modify_items($scope.pageContext.appId, $scope.pageContext.env,
$scope.pageContext.clusterName, $scope.pageContext.clusterName,
$scope.toCommitNamespace.namespace.namespaceName, $scope.toCommitNamespace.namespace.namespaceName,
$scope.toCommitNamespace.text, $scope.toCommitNamespace.editText,
$scope.toCommitNamespace.namespace.id, $scope.toCommitNamespace.namespace.id,
$scope.commitComment).then( $scope.commitComment).then(
function (result) { function (result) {
...@@ -120,6 +130,8 @@ application_module.controller("ConfigNamespaceController", ...@@ -120,6 +130,8 @@ application_module.controller("ConfigNamespaceController",
if (namespace.isTextEditing) {//切换为编辑状态 if (namespace.isTextEditing) {//切换为编辑状态
$scope.toCommitNamespace.commited = false; $scope.toCommitNamespace.commited = false;
namespace.backupText = namespace.text; namespace.backupText = namespace.text;
namespace.editText = parseModel2Text(namespace, 'edit');
} else { } else {
if (!$scope.toCommitNamespace.commited) {//取消编辑,则复原 if (!$scope.toCommitNamespace.commited) {//取消编辑,则复原
namespace.text = namespace.backupText; namespace.text = namespace.backupText;
...@@ -234,7 +246,7 @@ application_module.controller("ConfigNamespaceController", ...@@ -234,7 +246,7 @@ application_module.controller("ConfigNamespaceController",
itemModal.modal('hide'); itemModal.modal('hide');
$rootScope.refreshNamespaces(namespace_view_type.TABLE); $rootScope.refreshNamespaces(namespace_view_type.TABLE);
}, function (result) { }, function (result) {
AppUtil.errorMsg(result); toastr.error(AppUtil.errorMsg(result), "添加失败");
}); });
} else if ($scope.tableViewOperType == TABLE_VIEW_OPER_TYPE.UPDATE) { } else if ($scope.tableViewOperType == TABLE_VIEW_OPER_TYPE.UPDATE) {
...@@ -250,7 +262,7 @@ application_module.controller("ConfigNamespaceController", ...@@ -250,7 +262,7 @@ application_module.controller("ConfigNamespaceController",
itemModal.modal('hide'); itemModal.modal('hide');
$rootScope.refreshNamespaces(namespace_view_type.TABLE); $rootScope.refreshNamespaces(namespace_view_type.TABLE);
}, function (result) { }, function (result) {
AppUtil.errorMsg(result); toastr.error(AppUtil.errorMsg(result), "更新失败");
}); });
} }
}); });
......
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