Skip to content

Commit

Permalink
fixFeature non properties diff (#4547)
Browse files Browse the repository at this point in the history
  • Loading branch information
SunnyBoy-WYH authored Sep 2, 2022
1 parent 9b14c3e commit 2662f03
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 52 deletions.
6 changes: 3 additions & 3 deletions apollo-portal/src/main/resources/static/config/diff.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ <h4 class="modal-title">{{'Config.Diff.Title' | translate }}
<div class="col-sm-6">
<div class="radio-inline">
<label >
<input type="radio" name="tableDiff" ng-click="isTableDiff" checked="true" ng-checked="isTableDiff">
<input type="radio" name="tableDiff" ng-click="isTableDiff = true" checked="true" ng-checked="isTableDiff">
{{'Config.Diff.TableDiff' | translate }}
</label>
</div>
<div class="radio-inline">
<label >
<input type="radio" name="tableDiff" ng-click="!isTableDiff" ng-checked="!isTableDiff">
<input type="radio" name="tableDiff" ng-click="isTableDiff = false" ng-checked="!isTableDiff">
{{'Config.Diff.TextDiff' | translate }}
</label>
</div>
Expand All @@ -115,7 +115,7 @@ <h4 class="modal-title">{{'Config.Diff.Title' | translate }}
ng-model="searchKey"
placeholder="{{'Config.Diff.SearchKey' | translate }}">
</label>
<label class="control-label">
<label class="control-label" ng-show="isPropertiesFormat">
<input type="checkbox" class="comment-toggle" ng-checked="showCommentDiff"
ng-click="showCommentDiff=!showCommentDiff">
{{'Config.Diff.HasDiffComment' | translate }}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ diff_item_module.controller("DiffItemController",
$scope.itemsKeyedByKey = {};
$scope.allNamespaceValueEqualed = {};
$scope.isTableDiff = true;
$scope.isPropertiesFormat = true;

$scope.syncData = {
syncToNamespaces: [],
Expand All @@ -66,60 +67,90 @@ diff_item_module.controller("DiffItemController",
namespace.env,
namespace.clusterName,
namespace.namespaceName).then(function (result) {
loadedNamespaceCnt ++;
const suffixArray = namespace.namespaceName.match(/[^.]+$/);
result.forEach(function (originItem) {
if (originItem.key === "") {
return
}
let res = [];
// prop
if (suffixArray.length === 0) {
loadedNamespaceCnt++;
let suffix = ''
if (namespace.namespaceName.includes('.')) {
suffix = namespace.namespaceName.match(/[^.]+$/)[0];
$scope.isPropertiesFormat = false
}
let res = [];
let propTextInfo = "";
let propTextArr = [];

result.forEach(function (originItem) {
if (originItem.key === "") {
return
}
// prop
if (suffix === '') {
res.push(originItem)
propTextArr.push(originItem)

} else {
namespace.originTextInfo = originItem.value
if (suffix === 'yml') {
res = Obj2Prop(
YAML.parse(originItem.value))
} else if (suffix === 'json') {
res = Obj2Prop(
JSON.parse(originItem.value))
} else if (suffix === 'xml') {
const x2js = new X2JS();
res = Obj2Prop(
x2js.xml_str2json(originItem.value))
} else {
//txt
res.push(originItem)
}
}
});
// For prop textDiff,need parse prop to text
if (suffix === '') {
// to align key
propTextArr.sort((item1, item2) => item1.key.localeCompare(item2.key));
propTextArr.forEach(function (item) {
if (item.key) {
//use string \n to display as new line
var itemValue = item.value.replace(/\n/g, "\\n");

propTextInfo += item.key + " = " + itemValue + "\n";
} else {
namespace.originTextInfo = originItem.value
const suffix = suffixArray[0];
if (suffix === 'yml') {
res = Obj2Prop(
YAML.parse(originItem.value))
} else if (suffix === 'json') {
res = Obj2Prop(
JSON.parse(originItem.value))
} else if (suffix === 'xml') {
const x2js = new X2JS();
res = Obj2Prop(
x2js.xml_str2json(originItem.value))
} else {
//txt
res.push(originItem)
}
propTextInfo += item.comment + "\n";
}

res.forEach(function (item){
const itemsKeyedByClusterName = $scope.itemsKeyedByKey[item.key] || {};
itemsKeyedByClusterName[namespace.env + ':' + namespace.clusterName + ':' + namespace.namespaceName] = item;
$scope.itemsKeyedByKey[item.key] = itemsKeyedByClusterName;
})
});

//After loading all the compared namespaces, check whether the values are consistent
//itemsKeyedByKey struct : itemKey => namespace => item
if (loadedNamespaceCnt === namespaceCnt) {
Object.keys($scope.itemsKeyedByKey).forEach(function (key) {
namespace.originTextInfo = propTextInfo
}
res.forEach(function (item) {
const itemsKeyedByClusterName = $scope.itemsKeyedByKey[item.key] || {};
itemsKeyedByClusterName[namespace.env + ':' + namespace.clusterName + ':' + namespace.namespaceName] = item;
$scope.itemsKeyedByKey[item.key] = itemsKeyedByClusterName;
})
//After loading all the compared namespaces, check whether the values are consistent
//itemsKeyedByKey struct : itemKey => namespace => item
if (loadedNamespaceCnt === namespaceCnt) {
Object.keys($scope.itemsKeyedByKey).forEach(
function (key) {
let lastValue = null;
let allEqualed = true;
Object.values($scope.itemsKeyedByKey[key]).forEach(function (item) {
if (lastValue == null) {
lastValue = item.value;
}
if (lastValue !== item.value) {
allEqualed = false;
}
})
$scope.allNamespaceValueEqualed[key]=allEqualed;
// some namespace lack key,determined as not allEqual
if (Object.keys($scope.itemsKeyedByKey[key]).length !== namespaceCnt) {
allEqualed = false;
} else {
// check key items allEqual
Object.values($scope.itemsKeyedByKey[key]).forEach(
function (item) {
if (lastValue == null) {
lastValue = item.value;
}
if (lastValue !== item.value) {
allEqualed = false;
}
})
}
$scope.allNamespaceValueEqualed[key] = allEqualed;
})
}
});
}
});
});
$scope.syncItemNextStep(1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@
</ul>
</div>
<div class="col-md-6 col-sm-6 text-right">
<img src="img/compare.png" class="ns_btn clipboard cursor-pointer"
data-tooltip="tooltip" data-placement="bottom"
title="{{'Component.Namespace.Master.Items.DiffItemTips' | translate }}"
ng-click="goToDiffPage(namespace)"
ng-show="namespace.displayControl.currentOperateBranch == 'master' && !namespace.isPropertiesFormat && !namespace.isTextEditing">
&nbsp;
<img src="img/copy.png" class="ns_btn clipboard cursor-pointer"
data-clipboard-text="{{namespace.text}}" data-tooltip="tooltip" data-placement="bottom"
title="{{'Component.Namespace.Master.Items.CopyText' | translate }}"
Expand Down Expand Up @@ -233,8 +239,8 @@

<button type="button" class="btn btn-default btn-sm J_tableview_btn" data-tooltip="tooltip"
data-placement="bottom" title="{{'Component.Namespace.Master.Items.DiffItemTips' | translate }}"
ng-click="goToDiffPage(namespace)" ng-show=" namespace.displayControl.currentOperateBranch == 'master'
">
ng-click="goToDiffPage(namespace)" ng-show="namespace.viewType == 'table' && namespace.displayControl.currentOperateBranch == 'master'
&& namespace.isPropertiesFormat">
<img src="img/diff.png">
{{'Component.Namespace.Master.Items.DiffItem' | translate }}
</button>
Expand Down

0 comments on commit 2662f03

Please sign in to comment.