-
-
Notifications
You must be signed in to change notification settings - Fork 242
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
Add error page for initial REST request failure & Abort further load #1987
Merged
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d8dc59c
Fix alert for initial REST request failure & Abort further load
florian-h05 994046d
Add initial REST connection failure page
florian-h05 df8f5ec
Clean-Ups
florian-h05 eed615b
Merge branch 'main' into load-failure
florian-h05 61154cb
Refactor connection health stuff to mixin
florian-h05 7d11d39
Merge branch 'main' into load-failure
florian-h05 23c1c78
Refactor reload methods to mixin
florian-h05 674a900
Fix lint
florian-h05 1dc4640
Fixes, improvements & address review
florian-h05 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
bundles/org.openhab.ui/web/src/components/connection-health-mixin.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import mixin from 'reload-mixin.js' | ||
|
||
export default { | ||
mixins: [mixin], | ||
data () { | ||
return { | ||
// For the communication failure toast | ||
communicationFailureToast: null, | ||
communicationFailureTimeoutId: null, | ||
// For the communication failure page | ||
communicationFailureMsg: null | ||
} | ||
}, | ||
methods: { | ||
/** | ||
* Creates and opens a toast message that indicates a failure, e.g. of SSE connection | ||
* @param {string} message message to show | ||
* @param {boolean} [reloadButton=false] displays a reload button | ||
* @param {boolean} [autoClose=true] closes toast automatically | ||
* @returns {Toast.Toast} | ||
*/ | ||
displayFailureToast (message, reloadButton = false, autoClose = true) { | ||
const toast = this.$f7.toast.create({ | ||
text: message, | ||
closeButton: reloadButton, | ||
closeButtonText: this.$t('dialogs.reload'), | ||
destroyOnClose: autoClose, | ||
closeTimeout: (autoClose) ? 5000 : undefined, | ||
cssClass: 'failure-toast button-outline', | ||
position: 'bottom', | ||
horizontalPosition: 'center' | ||
}) | ||
toast.on('closeButtonClick', () => { | ||
window.location.reload() | ||
}) | ||
toast.open() | ||
return toast | ||
} | ||
}, | ||
created () { | ||
this.checkPurgeServiceWorkerAndCachesAvailable() | ||
}, | ||
mounted () { | ||
this.$f7ready((f7) => { | ||
this.$store.subscribe((mutation, state) => { | ||
if (this.ready) { | ||
if (mutation.type === 'sseConnected') { | ||
if (!window.OHApp && this.$f7) { | ||
if (mutation.payload === false) { | ||
if (this.communicationFailureToast === null) { | ||
this.communicationFailureTimeoutId = setTimeout(() => { | ||
if (this.communicationFailureToast !== null) return | ||
this.communicationFailureToast = this.displayFailureToast(this.$t('error.communicationFailure'), true, false) | ||
this.communicationFailureToast.open() | ||
this.communicationFailureTimeoutId = null | ||
}, 1000) | ||
} | ||
} else if (mutation.payload === true) { | ||
if (this.communicationFailureTimeoutId !== null) clearTimeout(this.communicationFailureTimeoutId) | ||
if (this.communicationFailureToast !== null) { | ||
this.communicationFailureToast.close() | ||
this.communicationFailureToast.destroy() | ||
this.communicationFailureToast = null | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}) | ||
|
||
this.$store.subscribeAction({ | ||
error: (action, state, error) => { | ||
if (action.type === 'sendCommand') { | ||
let reloadButton = true | ||
let msg = this.$t('error.communicationFailure') | ||
switch (error) { | ||
case 404: | ||
case 'Not Found': | ||
msg = this.$t('error.itemNotFound').replace('%s', action.payload.itemName) | ||
reloadButton = false | ||
return this.displayFailureToast(msg, reloadButton) | ||
} | ||
if (this.communicationFailureToast === null) { | ||
this.communicationFailureToast = this.displayFailureToast(this.$t('error.communicationFailure'), true, true) | ||
this.communicationFailureToast.on('closed', () => { | ||
this.communicationFailureToast = null | ||
}) | ||
} | ||
} | ||
} | ||
}) | ||
}) | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Thanks - this could have waited, enjoy your concert! (who is it?)
I'll tentatively do the testing tomorrow. The builds still fail, though:
As an habit I dropped the .js extensions in imports, except in
assets
where is it required to build the component docs (as it is run by Node which requires them).