2021-08-29 04:36:17 -07:00
|
|
|
// @ts-ignore
|
2021-07-22 01:22:17 -07:00
|
|
|
import { ElNotificationComponent, ElNotificationOptions } from 'element-ui/types/notification';
|
2021-05-05 17:46:33 -07:00
|
|
|
import mixins from 'vue-typed-mixins';
|
|
|
|
|
|
|
|
import { externalHooks } from '@/components/mixins/externalHooks';
|
2021-07-10 02:34:41 -07:00
|
|
|
import { ExecutionError } from 'n8n-workflow';
|
2021-09-11 01:15:36 -07:00
|
|
|
import { ElMessageBoxOptions } from 'element-ui/types/message-box';
|
|
|
|
import { MessageType } from 'element-ui/types/message';
|
2021-05-05 17:46:33 -07:00
|
|
|
|
|
|
|
export const showMessage = mixins(externalHooks).extend({
|
2019-06-23 03:35:23 -07:00
|
|
|
methods: {
|
2021-06-12 08:06:56 -07:00
|
|
|
$showMessage(messageData: ElNotificationOptions) {
|
2019-06-23 03:35:23 -07:00
|
|
|
messageData.dangerouslyUseHTMLString = true;
|
|
|
|
if (messageData.position === undefined) {
|
|
|
|
messageData.position = 'bottom-right';
|
|
|
|
}
|
|
|
|
|
2021-08-29 04:36:17 -07:00
|
|
|
return this.$notify(messageData);
|
2019-06-23 03:35:23 -07:00
|
|
|
},
|
2021-06-12 08:06:56 -07:00
|
|
|
|
2021-07-22 01:22:17 -07:00
|
|
|
$showWarning(title: string, message: string, config?: {onClick?: () => void, duration?: number, customClass?: string, closeOnClick?: boolean}) {
|
2021-08-29 04:36:17 -07:00
|
|
|
// eslint-disable-next-line prefer-const
|
2021-07-22 01:22:17 -07:00
|
|
|
let notification: ElNotificationComponent;
|
|
|
|
if (config && config.closeOnClick) {
|
|
|
|
const cb = config.onClick;
|
|
|
|
config.onClick = () => {
|
|
|
|
if (notification) {
|
|
|
|
notification.close();
|
|
|
|
}
|
|
|
|
if (cb) {
|
|
|
|
cb();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
notification = this.$showMessage({
|
|
|
|
title,
|
|
|
|
message,
|
|
|
|
type: 'warning',
|
|
|
|
...(config || {}),
|
|
|
|
});
|
|
|
|
|
|
|
|
return notification;
|
|
|
|
},
|
|
|
|
|
2021-07-10 02:34:41 -07:00
|
|
|
$getExecutionError(error?: ExecutionError) {
|
|
|
|
// There was a problem with executing the workflow
|
|
|
|
let errorMessage = 'There was a problem executing the workflow!';
|
|
|
|
|
|
|
|
if (error && error.message) {
|
|
|
|
let nodeName: string | undefined;
|
|
|
|
if (error.node) {
|
|
|
|
nodeName = typeof error.node === 'string'
|
|
|
|
? error.node
|
|
|
|
: error.node.name;
|
|
|
|
}
|
|
|
|
|
|
|
|
const receivedError = nodeName
|
|
|
|
? `${nodeName}: ${error.message}`
|
|
|
|
: error.message;
|
|
|
|
errorMessage = `There was a problem executing the workflow:<br /><strong>"${receivedError}"</strong>`;
|
|
|
|
}
|
|
|
|
|
|
|
|
return errorMessage;
|
|
|
|
},
|
|
|
|
|
2021-06-22 10:33:07 -07:00
|
|
|
$showError(error: Error, title: string, message?: string) {
|
|
|
|
const messageLine = message ? `${message}<br/>` : '';
|
2019-06-23 03:35:23 -07:00
|
|
|
this.$showMessage({
|
|
|
|
title,
|
2021-06-12 08:06:56 -07:00
|
|
|
message: `
|
2021-06-22 10:33:07 -07:00
|
|
|
${messageLine}
|
2021-06-12 08:06:56 -07:00
|
|
|
<i>${error.message}</i>
|
|
|
|
${this.collapsableDetails(error)}`,
|
2019-06-23 03:35:23 -07:00
|
|
|
type: 'error',
|
|
|
|
duration: 0,
|
|
|
|
});
|
2021-06-12 08:06:56 -07:00
|
|
|
|
|
|
|
this.$externalHooks().run('showMessage.showError', {
|
|
|
|
title,
|
|
|
|
message,
|
|
|
|
errorMessage: error.message,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2021-09-11 01:15:36 -07:00
|
|
|
async confirmMessage (message: string, headline: string, type: MessageType | null = 'warning', confirmButtonText = 'OK', cancelButtonText = 'Cancel'): Promise<boolean> {
|
|
|
|
try {
|
|
|
|
const options: ElMessageBoxOptions = {
|
|
|
|
confirmButtonText,
|
|
|
|
cancelButtonText,
|
|
|
|
dangerouslyUseHTMLString: true,
|
|
|
|
...(type && { type }),
|
|
|
|
};
|
|
|
|
|
|
|
|
await this.$confirm(message, headline, options);
|
|
|
|
return true;
|
|
|
|
} catch (e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2021-06-12 08:06:56 -07:00
|
|
|
// @ts-ignore
|
|
|
|
collapsableDetails({ description, node }: Error) {
|
|
|
|
if (!description) return '';
|
|
|
|
|
|
|
|
const errorDescription =
|
|
|
|
description.length > 500
|
|
|
|
? `${description.slice(0, 500)}...`
|
|
|
|
: description;
|
|
|
|
|
|
|
|
return `
|
|
|
|
<br>
|
|
|
|
<br>
|
|
|
|
<details>
|
|
|
|
<summary
|
|
|
|
style="color: #ff6d5a; font-weight: bold; cursor: pointer;"
|
|
|
|
>
|
|
|
|
Show Details
|
|
|
|
</summary>
|
|
|
|
<p>${node.name}: ${errorDescription}</p>
|
|
|
|
</details>
|
|
|
|
`;
|
2019-06-23 03:35:23 -07:00
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|