-
Notifications
You must be signed in to change notification settings - Fork 20
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
Feature/async diag collect #703
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
wb-mqtt-homeui (2.111.0) stable; urgency=medium | ||
|
||
* Rework diag collect to async backend | ||
|
||
-- Vladimir Romanov <[email protected]> Wed, 19 Feb 2025 17:25:22 +0300 | ||
|
||
wb-mqtt-homeui (2.110.0) stable; urgency=medium | ||
|
||
* Source code refactoring. No functional changes | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
class DiagnosticCtrl { | ||
constructor($scope, $translate, DiagnosticProxy, errors, whenMqttReady) { | ||
constructor($scope, $translate, DiagnosticProxy, errors, whenMqttReady, mqttClient) { | ||
'ngInject'; | ||
|
||
$scope.started = false; | ||
|
@@ -70,16 +70,16 @@ class DiagnosticCtrl { | |
changeBtnText('collector.states.collecting'); | ||
$scope.collecting = true; | ||
DiagnosticProxy.diag().then( | ||
names => { | ||
$scope.path = names['fullname']; | ||
$scope.basename = names['basename']; | ||
var url = getUrl(); | ||
fileIsOk(location.protocol + '//' + url + '/diag/' + $scope.basename, callbackFileIsOk); | ||
}, | ||
err => { | ||
$scope.collecting = false; | ||
changeBtnText('collector.errors.timeout'); | ||
mqttClient.addStickySubscription('/wb-diag-collect/artifact', function (msg) { | ||
if (msg.payload) { | ||
const data = JSON.parse(msg.payload) | ||
$scope.path = data['fullname']; | ||
$scope.basename = data['basename']; | ||
var url = getUrl(); | ||
fileIsOk(location.protocol + '//' + url + '/diag/' + $scope.basename, callbackFileIsOk); | ||
} | ||
} | ||
) | ||
Comment on lines
+73
to
+82
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick (assertive) Consider managing sticky subscriptions gracefully. You invoke 🧰 Tools🪛 Biome (1.9.4)[error] 79-79: Template literals are preferred over string concatenation. Unsafe fix: Use a template literal. (lint/style/useTemplate) [error] 78-78: Use let or const instead of var. A variable declared with var is accessible in the whole body of the function. Thus, the variable can be accessed before its initialization and outside the block where it is declared. (lint/style/noVar) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Кролик прав. Стоит сделать подписку один раз, а в теле обработчика проверять There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @KraPete Here's how we can implement the subscription: constructor($scope, $translate, DiagnosticProxy, errors, whenMqttReady, mqttClient) {
// ... existing code ...
mqttClient.addStickySubscription('/wb-diag-collect/artifact', function (msg) {
if ($scope.collecting && msg.payload) {
const data = JSON.parse(msg.payload);
$scope.path = data['fullname'];
$scope.basename = data['basename'];
const url = getUrl();
fileIsOk(`${location.protocol}//${url}/diag/${$scope.basename}`, callbackFileIsOk);
}
});
var diag = function () {
$scope.btnEnabled = false;
changeBtnText('collector.states.collecting');
$scope.collecting = true;
DiagnosticProxy.diag();
};
} (`^´) ✏️ Learnings added
|
||
); | ||
}; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick (assertive)
Adopt modern variable declarations and template literals.
Replacing
var url = getUrl();
with a block-scoped declaration and using a template literal for building the URL improves readability and prevents accidental reassignments.📝 Committable suggestion
🧰 Tools
🪛 Biome (1.9.4)
[error] 79-79: Template literals are preferred over string concatenation.
Unsafe fix: Use a template literal.
(lint/style/useTemplate)
[error] 78-78: Use let or const instead of var.
A variable declared with var is accessible in the whole body of the function. Thus, the variable can be accessed before its initialization and outside the block where it is declared.
See MDN web docs for more details.
Unsafe fix: Use 'const' instead.
(lint/style/noVar)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
И тут кролик прав
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@KraPete Thank you for confirming! Would you like me to suggest any other modern JavaScript improvements in the codebase?
If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!