Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix show-text-modal.html number display(#3821) #3851

Merged
merged 4 commits into from
Jul 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ Apollo 1.9.0
* [fix size of create project button](https://github.com/ctripcorp/apollo/pull/3849)
* [translation of "portal-how-to-enable-webhook-notification.md"](https://github.com/ctripcorp/apollo/pull/3847)
* [feature: add history detail for not key-value type of namespace](https://github.com/ctripcorp/apollo/pull/3856)
* [fix show-text-modal number display](https://github.com/ctripcorp/apollo/pull/3851)

------------------
All issues and pull requests are [here](https://github.com/ctripcorp/apollo/milestone/6?closed=1)

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,37 @@
* limitations under the License.
*
*/
directive_module.directive('showtextmodal', showTextModalDirective);
directive_module.directive('showtextmodal', showTextModalDirective)
.filter('jsonBigIntFilter', function () {
return function (text) {
if (typeof(text) === "undefined" || typeof JSON.parse(text) !== "object"
|| !text) {
return;
}

const numberRegex = /\d{16,}/g;
const splitRegex = /"\d\d+"/;
const splitArray = text.split(splitRegex);
const matchResult = text.match(numberRegex);

if (!matchResult) {
return text;
}

let resultStr = '';
let index = 0;

Object.keys(splitArray).forEach(function (key) {
resultStr = resultStr.concat(splitArray[key]);
if (typeof(matchResult[index]) !== "undefined") {
resultStr = resultStr.concat(matchResult[index++])
}
})

return resultStr;
}
});


function showTextModalDirective(AppUtil) {
return {
Expand All @@ -31,7 +61,7 @@ function showTextModalDirective(AppUtil) {
function init() {
scope.jsonObject = undefined;
if (isJsonText(scope.text)) {
scope.jsonObject = JSON.parse(scope.text);
scope.jsonObject = parseBigInt(scope.text);
}
}

Expand All @@ -42,6 +72,28 @@ function showTextModalDirective(AppUtil) {
return false;
}
}

function parseBigInt(str) {
if (/\d{16,}/.test(str)) {
let replaceMap = [];
let n = 0;
str = str.replace(/"(\\?[\s\S])*?"/g, function (match) {
if (/\d{16,}/.test(match)) {
replaceMap.push(match);
return '"""';
}
return match;
}).replace(/[+\-\d.eE]{16,}/g, function (match) {
if (/^\d{16,}$/.test(match)) {
return '"' + match + '"';
}
return match;
}).replace(/"""/g, function () {
return replaceMap[n++];
})
}
return JSON.parse(str);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ <h4 class="modal-title">{{'Component.ShowText.Title' | translate }}</h4>
<pre class="modal-body no-radius" style="margin-bottom: 0" ng-show="!jsonObject" ng-bind="text">
</pre>
<pre class="modal-body no-radius" style="margin-bottom: 0" ng-show="jsonObject"
ng-bind="jsonObject | json:4">
ng-bind="jsonObject | json:4 | jsonBigIntFilter">
</pre>
</div>
</div>
Expand Down