2019-06-23 03:35:23 -07:00
|
|
|
<template>
|
|
|
|
<div class="workflow-activator">
|
2022-01-21 09:00:00 -08:00
|
|
|
<n8n-tooltip :disabled="!disabled" placement="bottom">
|
|
|
|
<div slot="content">{{ $locale.baseText('workflowActivator.thisWorkflowHasNoTriggerNodes') }}</div>
|
|
|
|
<el-switch
|
2022-06-20 12:39:24 -07:00
|
|
|
v-loading="updatingWorkflowActivation"
|
2022-01-21 09:00:00 -08:00
|
|
|
:value="workflowActive"
|
|
|
|
@change="activeChanged"
|
|
|
|
: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"
|
|
|
|
element-loading-spinner="el-icon-loading">
|
|
|
|
</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-01-21 09:00:00 -08:00
|
|
|
<div @click="displayActivationError" slot="content" v-html="$locale.baseText('workflowActivator.theWorkflowIsSetToBeActiveBut')"></div>
|
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">
|
|
|
|
|
|
|
|
import { showMessage } from '@/components/mixins/showMessage';
|
2022-06-20 12:39:24 -07:00
|
|
|
import { workflowActivate } from '@/components/mixins/workflowActivate';
|
2019-06-23 03:35:23 -07:00
|
|
|
|
|
|
|
import mixins from 'vue-typed-mixins';
|
2021-07-23 00:32:56 -07:00
|
|
|
import { mapGetters } from "vuex";
|
2019-06-23 03:35:23 -07:00
|
|
|
|
2022-01-21 09:00:00 -08:00
|
|
|
import { getActivatableTriggerNodes } from './helpers';
|
|
|
|
|
2019-06-23 03:35:23 -07:00
|
|
|
export default mixins(
|
|
|
|
showMessage,
|
2022-06-20 12:39:24 -07:00
|
|
|
workflowActivate,
|
2019-06-23 03:35:23 -07:00
|
|
|
)
|
|
|
|
.extend(
|
|
|
|
{
|
|
|
|
name: 'WorkflowActivator',
|
|
|
|
props: [
|
|
|
|
'workflowActive',
|
|
|
|
'workflowId',
|
|
|
|
],
|
|
|
|
computed: {
|
2021-07-23 00:32:56 -07:00
|
|
|
...mapGetters({
|
|
|
|
dirtyState: "getStateIsDirty",
|
|
|
|
}),
|
2019-06-23 03:35:23 -07:00
|
|
|
nodesIssuesExist (): boolean {
|
|
|
|
return this.$store.getters.nodesIssuesExist;
|
|
|
|
},
|
|
|
|
isWorkflowActive (): boolean {
|
|
|
|
const activeWorkflows = this.$store.getters.getActiveWorkflows;
|
|
|
|
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';
|
|
|
|
},
|
2022-01-21 09:00:00 -08:00
|
|
|
isCurrentWorkflow(): boolean {
|
|
|
|
return this.$store.getters['workflowId'] === this.workflowId;
|
|
|
|
},
|
|
|
|
disabled(): boolean {
|
|
|
|
const isNewWorkflow = !this.workflowId;
|
|
|
|
if (isNewWorkflow || this.isCurrentWorkflow) {
|
|
|
|
return !this.workflowActive && !this.containsTrigger;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
containsTrigger(): boolean {
|
|
|
|
const foundTriggers = getActivatableTriggerNodes(this.$store.getters.workflowTriggerNodes);
|
|
|
|
return foundTriggers.length > 0;
|
|
|
|
},
|
2019-06-23 03:35:23 -07:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
async activeChanged (newActiveState: boolean) {
|
2022-06-20 12:39:24 -07:00
|
|
|
return this.updateWorkflowActivation(this.workflowId, newActiveState);
|
2019-06-23 03:35:23 -07:00
|
|
|
},
|
|
|
|
async displayActivationError () {
|
|
|
|
let errorMessage: string;
|
|
|
|
try {
|
|
|
|
const errorData = await this.restApi().getActivationError(this.workflowId);
|
|
|
|
|
|
|
|
if (errorData === undefined) {
|
2021-12-15 04:16:53 -08:00
|
|
|
errorMessage = this.$locale.baseText('workflowActivator.showMessage.displayActivationError.message.errorDataUndefined');
|
2019-06-23 03:35:23 -07:00
|
|
|
} else {
|
2021-12-15 04:16:53 -08:00
|
|
|
errorMessage = this.$locale.baseText(
|
2021-11-10 10:41:40 -08:00
|
|
|
'workflowActivator.showMessage.displayActivationError.message.errorDataNotUndefined',
|
|
|
|
{ interpolate: { message: errorData.error.message } },
|
|
|
|
);
|
2019-06-23 03:35:23 -07:00
|
|
|
}
|
|
|
|
} catch (error) {
|
2021-12-15 04:16:53 -08:00
|
|
|
errorMessage = this.$locale.baseText('workflowActivator.showMessage.displayActivationError.message.catchBlock');
|
2019-06-23 03:35:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
this.$showMessage({
|
2021-12-15 04:16:53 -08:00
|
|
|
title: this.$locale.baseText('workflowActivator.showMessage.displayActivationError.title'),
|
2019-06-23 03:35:23 -07:00
|
|
|
message: errorMessage,
|
|
|
|
type: 'warning',
|
|
|
|
duration: 0,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
2019-12-29 13:02:21 -08:00
|
|
|
},
|
2019-06-23 03:35:23 -07:00
|
|
|
);
|
|
|
|
</script>
|
|
|
|
|
2022-01-21 09:00:00 -08:00
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
2019-06-23 03:35:23 -07:00
|
|
|
.workflow-activator {
|
|
|
|
display: inline-block;
|
|
|
|
}
|
|
|
|
|
|
|
|
.could-not-be-started {
|
|
|
|
display: inline-block;
|
|
|
|
color: #ff4949;
|
|
|
|
margin-left: 0.5em;
|
|
|
|
}
|
|
|
|
|
2021-08-29 04:36:17 -07:00
|
|
|
::v-deep .el-loading-spinner {
|
2019-06-23 03:35:23 -07:00
|
|
|
margin-top: -10px;
|
|
|
|
}
|
2022-01-21 09:00:00 -08:00
|
|
|
|
2019-06-23 03:35:23 -07:00
|
|
|
</style>
|