2019-06-23 03:35:23 -07:00
|
|
|
<template>
|
|
|
|
<div class="workflow-activator">
|
2022-11-11 00:07:14 -08:00
|
|
|
<div :class="$style.activeStatusText" data-test-id="workflow-activator-status">
|
2022-12-14 01:04:10 -08:00
|
|
|
<n8n-text
|
|
|
|
v-if="workflowActive"
|
|
|
|
:color="couldNotBeStarted ? 'danger' : 'success'"
|
|
|
|
size="small"
|
|
|
|
bold
|
|
|
|
>
|
2022-10-18 06:28:21 -07:00
|
|
|
{{ $locale.baseText('workflowActivator.active') }}
|
|
|
|
</n8n-text>
|
|
|
|
<n8n-text v-else color="text-base" size="small" bold>
|
|
|
|
{{ $locale.baseText('workflowActivator.inactive') }}
|
|
|
|
</n8n-text>
|
|
|
|
</div>
|
2022-01-21 09:00:00 -08:00
|
|
|
<n8n-tooltip :disabled="!disabled" placement="bottom">
|
2022-11-18 05:59:31 -08:00
|
|
|
<template #content>
|
|
|
|
<div>{{ $locale.baseText('workflowActivator.thisWorkflowHasNoTriggerNodes') }}</div>
|
|
|
|
</template>
|
2022-01-21 09:00:00 -08:00
|
|
|
<el-switch
|
2022-06-20 12:39:24 -07:00
|
|
|
v-loading="updatingWorkflowActivation"
|
2023-07-28 00:51:07 -07:00
|
|
|
:modelValue="workflowActive"
|
|
|
|
@update:modelValue="activeChanged"
|
2022-12-14 01:04:10 -08:00
|
|
|
:title="
|
|
|
|
workflowActive
|
|
|
|
? $locale.baseText('workflowActivator.deactivateWorkflow')
|
|
|
|
: $locale.baseText('workflowActivator.activateWorkflow')
|
|
|
|
"
|
2022-06-20 12:39:24 -07:00
|
|
|
:disabled="disabled || updatingWorkflowActivation"
|
2022-01-21 09:00:00 -08:00
|
|
|
:active-color="getActiveColor"
|
|
|
|
inactive-color="#8899AA"
|
2022-11-25 06:32:09 -08:00
|
|
|
element-loading-spinner="el-icon-loading"
|
|
|
|
data-test-id="workflow-activate-switch"
|
|
|
|
>
|
2022-01-21 09:00:00 -08:00
|
|
|
</el-switch>
|
|
|
|
</n8n-tooltip>
|
2019-06-23 03:35:23 -07:00
|
|
|
|
|
|
|
<div class="could-not-be-started" v-if="couldNotBeStarted">
|
2021-08-29 04:36:17 -07:00
|
|
|
<n8n-tooltip placement="top">
|
2022-11-18 05:59:31 -08:00
|
|
|
<template #content>
|
2022-12-14 01:04:10 -08:00
|
|
|
<div
|
|
|
|
@click="displayActivationError"
|
|
|
|
v-html="$locale.baseText('workflowActivator.theWorkflowIsSetToBeActiveBut')"
|
|
|
|
></div>
|
2022-11-18 05:59:31 -08:00
|
|
|
</template>
|
2019-06-23 03:35:23 -07:00
|
|
|
<font-awesome-icon @click="displayActivationError" icon="exclamation-triangle" />
|
2021-08-29 04:36:17 -07:00
|
|
|
</n8n-tooltip>
|
2019-06-23 03:35:23 -07:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2023-05-15 09:41:13 -07:00
|
|
|
import { useToast } from '@/composables';
|
2022-11-23 04:41:53 -08:00
|
|
|
import { workflowActivate } from '@/mixins/workflowActivate';
|
2023-05-05 01:41:54 -07:00
|
|
|
import { useUIStore } from '@/stores/ui.store';
|
|
|
|
import { useWorkflowsStore } from '@/stores/workflows.store';
|
2022-11-04 06:04:31 -07:00
|
|
|
import { mapStores } from 'pinia';
|
2023-05-15 09:41:13 -07:00
|
|
|
import { defineComponent } from 'vue';
|
2022-11-23 04:41:53 -08:00
|
|
|
import { getActivatableTriggerNodes } from '@/utils';
|
2022-01-21 09:00:00 -08:00
|
|
|
|
2023-05-15 09:41:13 -07:00
|
|
|
export default defineComponent({
|
2022-12-14 01:04:10 -08:00
|
|
|
name: 'WorkflowActivator',
|
|
|
|
props: ['workflowActive', 'workflowId'],
|
2023-05-15 09:41:13 -07:00
|
|
|
mixins: [workflowActivate],
|
|
|
|
setup(props) {
|
|
|
|
return {
|
|
|
|
...useToast(),
|
2023-07-28 00:51:07 -07:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
2023-05-15 09:41:13 -07:00
|
|
|
...workflowActivate.setup?.(props),
|
|
|
|
};
|
|
|
|
},
|
2022-12-14 01:04:10 -08:00
|
|
|
computed: {
|
|
|
|
...mapStores(useUIStore, useWorkflowsStore),
|
|
|
|
nodesIssuesExist(): boolean {
|
|
|
|
return this.workflowsStore.nodesIssuesExist;
|
|
|
|
},
|
|
|
|
isWorkflowActive(): boolean {
|
|
|
|
const activeWorkflows = this.workflowsStore.activeWorkflows;
|
|
|
|
return activeWorkflows.includes(this.workflowId);
|
|
|
|
},
|
|
|
|
couldNotBeStarted(): boolean {
|
|
|
|
return this.workflowActive === true && this.isWorkflowActive !== this.workflowActive;
|
|
|
|
},
|
|
|
|
getActiveColor(): string {
|
|
|
|
if (this.couldNotBeStarted === true) {
|
|
|
|
return '#ff4949';
|
|
|
|
}
|
|
|
|
return '#13ce66';
|
|
|
|
},
|
|
|
|
isCurrentWorkflow(): boolean {
|
|
|
|
return this.workflowsStore.workflowId === this.workflowId;
|
|
|
|
},
|
|
|
|
disabled(): boolean {
|
|
|
|
const isNewWorkflow = !this.workflowId;
|
|
|
|
if (isNewWorkflow || this.isCurrentWorkflow) {
|
|
|
|
return !this.workflowActive && !this.containsTrigger;
|
|
|
|
}
|
2022-01-21 09:00:00 -08:00
|
|
|
|
2022-12-14 01:04:10 -08:00
|
|
|
return false;
|
|
|
|
},
|
|
|
|
containsTrigger(): boolean {
|
|
|
|
const foundTriggers = getActivatableTriggerNodes(this.workflowsStore.workflowTriggerNodes);
|
|
|
|
return foundTriggers.length > 0;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
async activeChanged(newActiveState: boolean) {
|
2023-05-10 08:10:03 -07:00
|
|
|
return this.updateWorkflowActivation(this.workflowId, newActiveState);
|
2022-12-14 01:04:10 -08:00
|
|
|
},
|
|
|
|
async displayActivationError() {
|
|
|
|
let errorMessage: string;
|
|
|
|
try {
|
2023-04-24 01:50:49 -07:00
|
|
|
const errorData = await this.workflowsStore.getActivationError(this.workflowId);
|
2019-06-23 03:35:23 -07:00
|
|
|
|
2022-12-14 01:04:10 -08:00
|
|
|
if (errorData === undefined) {
|
|
|
|
errorMessage = this.$locale.baseText(
|
|
|
|
'workflowActivator.showMessage.displayActivationError.message.errorDataUndefined',
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
errorMessage = this.$locale.baseText(
|
|
|
|
'workflowActivator.showMessage.displayActivationError.message.errorDataNotUndefined',
|
|
|
|
{ interpolate: { message: errorData.error.message } },
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
errorMessage = this.$locale.baseText(
|
|
|
|
'workflowActivator.showMessage.displayActivationError.message.catchBlock',
|
|
|
|
);
|
|
|
|
}
|
2019-06-23 03:35:23 -07:00
|
|
|
|
2023-05-15 09:41:13 -07:00
|
|
|
this.showMessage({
|
2022-12-14 01:04:10 -08:00
|
|
|
title: this.$locale.baseText('workflowActivator.showMessage.displayActivationError.title'),
|
|
|
|
message: errorMessage,
|
|
|
|
type: 'warning',
|
|
|
|
duration: 0,
|
2023-05-22 06:09:29 -07:00
|
|
|
dangerouslyUseHTMLString: true,
|
2022-12-14 01:04:10 -08:00
|
|
|
});
|
2019-12-29 13:02:21 -08:00
|
|
|
},
|
2022-12-14 01:04:10 -08:00
|
|
|
},
|
|
|
|
});
|
2019-06-23 03:35:23 -07:00
|
|
|
</script>
|
|
|
|
|
2022-10-18 06:28:21 -07:00
|
|
|
<style lang="scss" module>
|
|
|
|
.activeStatusText {
|
|
|
|
width: 64px; // Required to avoid jumping when changing active state
|
|
|
|
padding-right: var(--spacing-2xs);
|
|
|
|
box-sizing: border-box;
|
|
|
|
display: inline-block;
|
|
|
|
text-align: right;
|
|
|
|
}
|
|
|
|
</style>
|
2022-01-21 09:00:00 -08:00
|
|
|
|
2022-10-18 06:28:21 -07:00
|
|
|
<style lang="scss" scoped>
|
2019-06-23 03:35:23 -07:00
|
|
|
.workflow-activator {
|
2022-10-18 06:28:21 -07:00
|
|
|
display: inline-flex;
|
|
|
|
flex-wrap: nowrap;
|
|
|
|
align-items: center;
|
2023-07-28 00:51:07 -07:00
|
|
|
|
|
|
|
:deep(.el-loading-spinner) {
|
|
|
|
margin-top: -10px;
|
|
|
|
}
|
2019-06-23 03:35:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
.could-not-be-started {
|
|
|
|
display: inline-block;
|
|
|
|
color: #ff4949;
|
|
|
|
margin-left: 0.5em;
|
|
|
|
}
|
|
|
|
</style>
|