| 71 | } |
| 72 | |
| 73 | class Notifier { |
| 74 | constructor(modal, snackbar) { |
| 75 | this.modal = modal; |
| 76 | this.snackbar = snackbar; |
| 77 | } |
| 78 | |
| 79 | success(msg, autoHideDuration = AUTO_HIDE_DURATION) { |
| 80 | this.snackbar.callNotify(msg, MESSAGE_TYPE.SUCCESS, autoHideDuration); |
| 81 | } |
| 82 | |
| 83 | warning(msg, autoHideDuration = AUTO_HIDE_DURATION) { |
| 84 | this.snackbar.callNotify(msg, MESSAGE_TYPE.WARNING, autoHideDuration); |
| 85 | } |
| 86 | |
| 87 | info(msg, autoHideDuration = AUTO_HIDE_DURATION) { |
| 88 | this.snackbar.callNotify(msg, MESSAGE_TYPE.INFO, autoHideDuration); |
| 89 | } |
| 90 | |
| 91 | error(msg, autoHideDuration = AUTO_HIDE_DURATION) { |
| 92 | this.snackbar.callNotify(msg, MESSAGE_TYPE.ERROR, autoHideDuration); |
| 93 | } |
| 94 | |
| 95 | // Plain-text snackbar variants. Use these when `msg` is, or may contain, |
| 96 | // text from an untrusted source (PostgreSQL server, driver, remote API, |
| 97 | // user input). Newlines are preserved; no HTML is interpreted. |
| 98 | successText(msg, autoHideDuration = AUTO_HIDE_DURATION) { |
| 99 | this.snackbar.callNotify(msg, MESSAGE_TYPE.SUCCESS, autoHideDuration, {plainText: true}); |
| 100 | } |
| 101 | warningText(msg, autoHideDuration = AUTO_HIDE_DURATION) { |
| 102 | this.snackbar.callNotify(msg, MESSAGE_TYPE.WARNING, autoHideDuration, {plainText: true}); |
| 103 | } |
| 104 | infoText(msg, autoHideDuration = AUTO_HIDE_DURATION) { |
| 105 | this.snackbar.callNotify(msg, MESSAGE_TYPE.INFO, autoHideDuration, {plainText: true}); |
| 106 | } |
| 107 | errorText(msg, autoHideDuration = AUTO_HIDE_DURATION) { |
| 108 | this.snackbar.callNotify(msg, MESSAGE_TYPE.ERROR, autoHideDuration, {plainText: true}); |
| 109 | } |
| 110 | |
| 111 | // proxy |
| 112 | notify(...args) { |
| 113 | this.snackbar.notify(...args); |
| 114 | } |
| 115 | |
| 116 | pgRespErrorNotify(error, prefixMsg='') { |
| 117 | if (error.response?.status === 410) { |
| 118 | this.alertText( |
| 119 | gettext('Error: Object not found - %s.', error.response.statusText), |
| 120 | parseApiError(error) |
| 121 | ); |
| 122 | } else { |
| 123 | this.errorText(prefixMsg + ' ' + parseApiError(error)); |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | pgNotifier(type, error, promptmsg, onJSONResult) { |
| 128 | let msg; |
| 129 | |
| 130 | if(!error.response) { |
nothing calls this directly
no outgoing calls
no test coverage detected