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

Beautify Portal TraceLog UI interface #5149

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,7 @@ <h2>{{ 'ApolloAuditLog.TraceDetailTips' | translate }}</h2>
{{'ApolloAuditLog.TraceAuditLogTips' | translate }}</span>
</div>
<div class="panel-body">
<div class="media hover" ng-repeat="detail in traceDetails">
<h4 class="media-heading word-break" data-toggle="collapse" data-target="#detail{{ detail.logDTO.id }}"
ng-click="setShowingDetail(detail);removeInClassFromLogDropDownExceptId(detail.logDTO.id)">
{{detail.logDTO.opName}}
<span class="glyphicon glyphicon-menu-down"></span>
</h4>
<div id="detail{{ detail.logDTO.id }}" class="panel-collapse collapse">
<div class="word-break">{{'ApolloAuditLog.SpanIdTips' | translate }}:{{detail.logDTO.spanId.substr(0,5)+'...'}}</div>
<div class="word-break">{{'ApolloAuditLog.ParentSpan' | translate }}:{{findOpNameBySpanId(detail.logDTO.parentSpanId)}}</div>
<div class="word-break">{{'ApolloAuditLog.FollowsFromSpan' | translate }}:{{findOpNameBySpanId(detail.logDTO.followsFromSpanId)}}</div>
</div>
</div>
<div id="treeview" class="treeview"></div>
</div>
</div>
<!--properties mode info-->
Expand All @@ -89,7 +78,7 @@ <h4 style="margin: 8px 0px">{{'ApolloAuditLog.OpType' | translate}}:{{showingDet
<div style="font-size: 12pt; word-break: break-all">
{{'ApolloAuditLog.Description' | translate}}:{{showingDetail.logDTO.description}}
</div>
<hr style="margin: 5px"/>
<hr style="margin: 5px 0px"/>
<h4 style="word-break: break-all;">
{{'ApolloAuditLog.InfluenceEntity' | translate}}:
</h4>
Expand Down Expand Up @@ -153,7 +142,7 @@ <h4 ng-show="relatedDataInfluences && relatedDataInfluences.length > 0"
</h4>
<div class="table-responsive">
<table ng-show="relatedDataInfluences && relatedDataInfluences.length > 0"
class="no-margin table table-striped table-hover table-bordered">
class="no-margin table table-striped table-hover table-bordered">
<thead>
<tr>
<th style="width: 50%">{{'ApolloAuditLog.DataInfluence.FieldNewValue' | translate }}</th>
Expand Down Expand Up @@ -181,7 +170,7 @@ <h5>{{'ApolloAuditLog.NoDataInfluence' | translate }}</h5>
</div>
</div>

<div class="panel-body" ng-show="!traceDetails || traceDetails == 0">
<div class="panel-body" ng-show="!traceDetailsTree || traceDetailsTree.length == 0">
<h4 class="text-center empty-container">
{{'ApolloAuditLog.NoTraceDetail' | translate }}</h4>
</div>
Expand All @@ -206,12 +195,13 @@ <h4 class="text-center empty-container">

<script src="vendor/angular/angular-translate.2.18.1/angular-translate.min.js"></script>
<script
src="vendor/angular/angular-translate.2.18.1/angular-translate-loader-static-files.min.js"></script>
src="vendor/angular/angular-translate.2.18.1/angular-translate-loader-static-files.min.js"></script>
<script
src="vendor/angular/angular-translate.2.18.1/angular-translate-storage-cookie.min.js"></script>
src="vendor/angular/angular-translate.2.18.1/angular-translate-storage-cookie.min.js"></script>

<!-- bootstrap.js -->
<script src="vendor/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
<script src="vendor/bootstrap/js/bootstrap-treeview.min.js" type="text/javascript"></script>

<script src="vendor/diff.min.js" type="text/javascript"></script>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,160 +16,160 @@
*/
audit_log_menu_module.controller('AuditLogMenuController',
['$scope', '$window', '$translate', '$document', 'toastr', 'AppService', 'AppUtil', 'EventManager', 'AuditLogService',
auditLogMenuController]
auditLogMenuController]
);

function auditLogMenuController($scope, $window, $translate, $document, toastr, AppService, AppUtil, EventManager, AuditLogService) {

$scope.auditEnabled = false;
$scope.auditEnabled = false;

$scope.auditLogList = [];
$scope.goToTraceDetailsPage = goToTraceDetailsPage;
$scope.searchByOpNameAndDate = searchByOpNameAndDate;
$scope.getMoreAuditLogs = getMoreAuditLogs;
$scope.auditLogList = [];
$scope.goToTraceDetailsPage = goToTraceDetailsPage;
$scope.searchByOpNameAndDate = searchByOpNameAndDate;
$scope.getMoreAuditLogs = getMoreAuditLogs;

$scope.page = 0;
var PAGE_SIZE = 10;
$scope.page = 0;
var PAGE_SIZE = 10;

$scope.opName = '';
$scope.startDate = null;
$scope.endDate = null;
$scope.startDateFmt = null;
$scope.endDateFmt = null;
$scope.opName = '';
$scope.startDate = null;
$scope.endDate = null;
$scope.startDateFmt = null;
$scope.endDateFmt = null;

$scope.hasLoadAll = false;
$scope.hasLoadAll = false;

$scope.options = [];
$scope.showSearchDropdown = false;
$scope.options = [];
$scope.showSearchDropdown = false;

$scope.showOptions = function(query) {
$scope.options = [];
searchAuditLogs(query);
};
$scope.showOptions = function (query) {
$scope.options = [];
searchAuditLogs(query);
};
Comment on lines +45 to +48
Copy link
Contributor

@coderabbitai coderabbitai bot May 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using arrow functions for cleaner and more concise syntax.

- $scope.showOptions = function (query) {
-     $scope.options = [];
-     searchAuditLogs(query);
- };
+ $scope.showOptions = (query) => {
+     $scope.options = [];
+     searchAuditLogs(query);
+ };

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
$scope.showOptions = function (query) {
$scope.options = [];
searchAuditLogs(query);
};
$scope.showOptions = (query) => {
$scope.options = [];
searchAuditLogs(query);
};

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😅

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BlackBear2003, glad to see the suggestion got a smile! 😄 If you have any questions or need further assistance, feel free to ask. Happy coding!


$scope.selectOption = function(option) {
$scope.opName = option.opName;
$scope.showSearchDropdown = false;
};
$scope.selectOption = function (option) {
$scope.opName = option.opName;
$scope.showSearchDropdown = false;
};
Comment on lines +50 to +53
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Convert this function expression to an arrow function for consistency and improved readability.

- $scope.selectOption = function (option) {
-     $scope.opName = option.opName;
-     $scope.showSearchDropdown = false;
- };
+ $scope.selectOption = (option) => {
+     $scope.opName = option.opName;
+     $scope.showSearchDropdown = false;
+ };

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
$scope.selectOption = function (option) {
$scope.opName = option.opName;
$scope.showSearchDropdown = false;
};
$scope.selectOption = (option) => {
$scope.opName = option.opName;
$scope.showSearchDropdown = false;
};


init();
init();

function init() {
getAuditProperties();
initSearchingMenu();
}
function init() {
getAuditProperties();
initSearchingMenu();
}

function getAuditProperties() {
AuditLogService.get_properties().then(function (result) {
$scope.auditEnabled = result.enabled;
});
}

function initSearchingMenu() {
AuditLogService.find_all_logs($scope.page, PAGE_SIZE).then(function (result) {
if (!result || result.length < PAGE_SIZE) {
$scope.hasLoadAll = true;
}
if (result.length === 0) {
return;
}
$scope.auditLogList = $scope.auditLogList.concat(result);
});
}
function getAuditProperties() {
AuditLogService.get_properties().then(function (result) {
$scope.auditEnabled = result.enabled;
});
Comment on lines +63 to +65
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use arrow function for a more concise and modern approach.

- function getAuditProperties() {
-     AuditLogService.get_properties().then(function (result) {
-         $scope.auditEnabled = result.enabled;
-     });
- }
+ const getAuditProperties = () => {
+     AuditLogService.get_properties().then((result) => {
+         $scope.auditEnabled = result.enabled;
+     });
+ };

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
AuditLogService.get_properties().then(function (result) {
$scope.auditEnabled = result.enabled;
});
const getAuditProperties = () => {
AuditLogService.get_properties().then((result) => {
$scope.auditEnabled = result.enabled;
});
};

}

function searchByOpNameAndDate(opName, startDate, endDate) {
if (startDate !== null) {
$scope.startDateFmt = new Date(startDate).Format("yyyy-MM-dd hh:mm:ss.S");
function initSearchingMenu() {
AuditLogService.find_all_logs($scope.page, PAGE_SIZE).then(function (result) {
if (!result || result.length < PAGE_SIZE) {
$scope.hasLoadAll = true;
}
if (endDate !== null) {
$scope.endDateFmt = new Date(endDate).Format("yyyy-MM-dd hh:mm:ss.S");
if (result.length === 0) {
return;
}
$scope.auditLogList = [];
$scope.page = 0;
$scope.opName = opName;
$scope.startDate = startDate;
$scope.endDate = endDate;
$scope.auditLogList = $scope.auditLogList.concat(result);
});
Comment on lines +69 to +77
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactor to use arrow functions for asynchronous operations.

- function initSearchingMenu() {
-     AuditLogService.find_all_logs($scope.page, PAGE_SIZE).then(function (result) {
-         if (!result || result.length < PAGE_SIZE) {
-             $scope.hasLoadAll = true;
-         }
-         if (result.length === 0) {
-             return;
-         }
-         $scope.auditLogList = $scope.auditLogList.concat(result);
-     });
- }
+ const initSearchingMenu = () => {
+     AuditLogService.find_all_logs($scope.page, PAGE_SIZE).then((result) => {
+         if (!result || result.length < PAGE_SIZE) {
+             $scope.hasLoadAll = true;
+         }
+         if (result.length === 0) {
+             return;
+         }
+         $scope.auditLogList = $scope.auditLogList.concat(result);
+     });
+ };

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
AuditLogService.find_all_logs($scope.page, PAGE_SIZE).then(function (result) {
if (!result || result.length < PAGE_SIZE) {
$scope.hasLoadAll = true;
}
if (endDate !== null) {
$scope.endDateFmt = new Date(endDate).Format("yyyy-MM-dd hh:mm:ss.S");
if (result.length === 0) {
return;
}
$scope.auditLogList = [];
$scope.page = 0;
$scope.opName = opName;
$scope.startDate = startDate;
$scope.endDate = endDate;
$scope.auditLogList = $scope.auditLogList.concat(result);
});
const initSearchingMenu = () => {
AuditLogService.find_all_logs($scope.page, PAGE_SIZE).then((result) => {
if (!result || result.length < PAGE_SIZE) {
$scope.hasLoadAll = true;
}
if (result.length === 0) {
return;
}
$scope.auditLogList = $scope.auditLogList.concat(result);
});
};

}

function searchByOpNameAndDate(opName, startDate, endDate) {
if (startDate !== null) {
$scope.startDateFmt = new Date(startDate).Format("yyyy-MM-dd hh:mm:ss.S");
}
if (endDate !== null) {
$scope.endDateFmt = new Date(endDate).Format("yyyy-MM-dd hh:mm:ss.S");
}
$scope.auditLogList = [];
$scope.page = 0;
$scope.opName = opName;
$scope.startDate = startDate;
$scope.endDate = endDate;
AuditLogService.find_logs_by_opName(
$scope.opName,
$scope.startDateFmt,
$scope.endDateFmt,
$scope.page,
PAGE_SIZE
).then(function (result) {
if (!result || result.length < PAGE_SIZE) {
$scope.hasLoadAll = true;
}
if (result.length === 0) {
return;
}
$scope.auditLogList = $scope.auditLogList.concat(result);
});
Comment on lines +98 to +106
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Convert this function to use arrow syntax for consistency and modern JavaScript practices.

- function searchByOpNameAndDate(opName, startDate, endDate) {
-     if (startDate !== null) {
-         $scope.startDateFmt = new Date(startDate).Format("yyyy-MM-dd hh:mm:ss.S");
-     }
-     if (endDate !== null) {
-         $scope.endDateFmt = new Date(endDate).Format("yyyy-MM-dd hh:mm:ss.S");
-     }
-     $scope.auditLogList = [];
-     $scope.page = 0;
-     $scope.opName = opName;
-     $scope.startDate = startDate;
-     $scope.endDate = endDate;
-     AuditLogService.find_logs_by_opName(
-         $scope.opName,
-         $scope.startDateFmt,
-         $scope.endDateFmt,
-         $scope.page,
-         PAGE_SIZE
-     ).then(function (result) {
-         if (!result || result.length < PAGE_SIZE) {
-             $scope.hasLoadAll = true;
-         }
-         if (result.length === 0) {
-             return;
-         }
-         $scope.auditLogList = $scope.auditLogList.concat(result);
-     });
- }
+ const searchByOpNameAndDate = (opName, startDate, endDate) => {
+     if (startDate !== null) {
+         $scope.startDateFmt = new Date(startDate).Format("yyyy-MM-dd hh:mm:ss.S");
+     }
+     if (endDate !== null) {
+         $scope.endDateFmt = new Date(endDate).Format("yyyy-MM-dd hh:mm:ss.S");
+     }
+     $scope.auditLogList = [];
+     $scope.page = 0;
+     $scope.opName = opName;
+     $scope.startDate = startDate;
+     $scope.endDate = endDate;
+     AuditLogService.find_logs_by_opName(
+         $scope.opName,
+         $scope.startDateFmt,
+         $scope.endDateFmt,
+         $scope.page,
+         PAGE_SIZE
+     ).then((result) => {
+         if (!result || result.length < PAGE_SIZE) {
+             $scope.hasLoadAll = true;
+         }
+         if (result.length === 0) {
+             return;
+         }
+         $scope.auditLogList = $scope.auditLogList.concat(result);
+     });
+ };

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
).then(function (result) {
if (!result || result.length < PAGE_SIZE) {
$scope.hasLoadAll = true;
}
if (result.length === 0) {
return;
}
$scope.auditLogList = $scope.auditLogList.concat(result);
});
).then((result) => {
if (!result || result.length < PAGE_SIZE) {
$scope.hasLoadAll = true;
}
if (result.length === 0) {
return;
}
$scope.auditLogList = $scope.auditLogList.concat(result);
});

}

function getMoreAuditLogs() {
$scope.page = $scope.page + 1;
if ($scope.opName === '') {
AuditLogService.find_all_logs($scope.page, PAGE_SIZE).then(function (result) {
if (!result || result.length < PAGE_SIZE) {
$scope.hasLoadAll = true;
}
if (result.length === 0) {
return;
}
$scope.auditLogList = $scope.auditLogList.concat(result);
});
} else {
AuditLogService.find_logs_by_opName(
$scope.opName,
$scope.startDateFmt,
$scope.endDateFmt,
$scope.page,
PAGE_SIZE
).then(function (result) {
if (!result || result.length < PAGE_SIZE) {
$scope.hasLoadAll = true;
}
if (result.length === 0) {
return;
}
$scope.auditLogList = $scope.auditLogList.concat(result);
if (!result || result.length < PAGE_SIZE) {
$scope.hasLoadAll = true;
}
if (result.length === 0) {
return;
}
$scope.auditLogList = $scope.auditLogList.concat(result);
});
}

function getMoreAuditLogs() {
$scope.page = $scope.page + 1;
if($scope.opName === '') {
AuditLogService.find_all_logs($scope.page, PAGE_SIZE).then(function (result) {
if (!result || result.length < PAGE_SIZE) {
$scope.hasLoadAll = true;
}
if (result.length === 0) {
return;
}
$scope.auditLogList = $scope.auditLogList.concat(result);
});
}else {
AuditLogService.find_logs_by_opName(
$scope.opName,
$scope.startDateFmt,
$scope.endDateFmt,
$scope.page,
PAGE_SIZE
).then(function (result) {
if (!result || result.length < PAGE_SIZE) {
$scope.hasLoadAll = true;
}
if (result.length === 0) {
return;
}
$scope.auditLogList = $scope.auditLogList.concat(result);
});
}
}

function searchAuditLogs(query) {
AuditLogService.search_by_name_or_type_or_operator(query, 0, 20).then(function (result) {
result.forEach(function (log) {
var optionDisplay = log.opName + '-(' + log.opType + ').by:' + log.operator;
var option = {
id: log.id,
display: optionDisplay,
opName: log.opName
};
$scope.options.push(option);
});
$scope.showSearchDropdown = $scope.options.length > 0;
}
}

function searchAuditLogs(query) {
AuditLogService.search_by_name_or_type_or_operator(query, 0, 20).then(function (result) {
result.forEach(function (log) {
var optionDisplay = log.opName + '-(' + log.opType + ').by:' + log.operator;
var option = {
id: log.id,
display: optionDisplay,
opName: log.opName
};
$scope.options.push(option);
});
}
$scope.showSearchDropdown = $scope.options.length > 0;
});
Comment on lines +141 to +152
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer using for...of instead of forEach for better performance and readability.

- result.forEach(function (log) {
-     var optionDisplay = log.opName + '-(' + log.opType + ').by:' + log.operator;
-     var option = {
-         id: log.id,
-         display: optionDisplay,
-         opName: log.opName
-     };
-     $scope.options.push(option);
- });
+ for (const log of result) {
+     const optionDisplay = `${log.opName}-(${log.opType}).by:${log.operator}`;
+     const option = {
+         id: log.id,
+         display: optionDisplay,
+         opName: log.opName
+     };
+     $scope.options.push(option);
+ }

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
AuditLogService.search_by_name_or_type_or_operator(query, 0, 20).then(function (result) {
result.forEach(function (log) {
var optionDisplay = log.opName + '-(' + log.opType + ').by:' + log.operator;
var option = {
id: log.id,
display: optionDisplay,
opName: log.opName
};
$scope.options.push(option);
});
}
$scope.showSearchDropdown = $scope.options.length > 0;
});
AuditLogService.search_by_name_or_type_or_operator(query, 0, 20).then(function (result) {
for (const log of result) {
const optionDisplay = `${log.opName}-(${log.opType}).by:${log.operator}`;
const option = {
id: log.id,
display: optionDisplay,
opName: log.opName
};
$scope.options.push(option);
}
$scope.showSearchDropdown = $scope.options.length > 0;
});

}

function goToTraceDetailsPage(traceId) {
$window.location.href = AppUtil.prefixPath() + "/audit_log_trace_detail.html?#traceId=" + traceId;
}
function goToTraceDetailsPage(traceId) {
$window.location.href = AppUtil.prefixPath() + "/audit_log_trace_detail.html?#traceId=" + traceId;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use template literals for string concatenation to improve readability and maintainability.

- $window.location.href = AppUtil.prefixPath() + "/audit_log_trace_detail.html?#traceId=" + traceId;
+ $window.location.href = `${AppUtil.prefixPath()}/audit_log_trace_detail.html?#traceId=${traceId}`;

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
$window.location.href = AppUtil.prefixPath() + "/audit_log_trace_detail.html?#traceId=" + traceId;
$window.location.href = `${AppUtil.prefixPath()}/audit_log_trace_detail.html?#traceId=${traceId}`;

}

$document.on('click', function(event) {
if (!$scope.showSearchDropdown) {
return;
}
$document.on('click', function (event) {
if (!$scope.showSearchDropdown) {
return;
}

var target = angular.element(event.target);
var target = angular.element(event.target);

// 检查点击的目标是否是输入框或下拉栏,如果不是,则隐藏下拉栏
if (!target.hasClass('form-control') && !target.hasClass('options-container')) {
$scope.$apply(function() {
$scope.showSearchDropdown = false;
});
}
});
// 检查点击的目标是否是输入框或下拉栏,如果不是,则隐藏下拉栏
if (!target.hasClass('form-control') && !target.hasClass('options-container')) {
$scope.$apply(function () {
$scope.showSearchDropdown = false;
});
}
});
}


Expand Down
Loading
Loading