2019-06-23 03:35:23 -07:00
|
|
|
<template>
|
2021-05-29 11:31:21 -07:00
|
|
|
<Modal
|
2021-10-18 20:57:49 -07:00
|
|
|
:name="WORKFLOW_OPEN_MODAL_KEY"
|
2021-09-22 00:23:37 -07:00
|
|
|
width="80%"
|
|
|
|
minWidth="620px"
|
2021-09-11 01:15:36 -07:00
|
|
|
:classic="true"
|
2021-05-29 11:31:21 -07:00
|
|
|
>
|
|
|
|
<template v-slot:header>
|
|
|
|
<div class="workflows-header">
|
2021-10-18 20:57:49 -07:00
|
|
|
<n8n-heading tag="h1" size="xlarge" class="title">
|
2021-12-15 04:16:53 -08:00
|
|
|
{{ $locale.baseText('workflowOpen.openWorkflow') }}
|
2021-10-18 20:57:49 -07:00
|
|
|
</n8n-heading>
|
2021-05-29 11:31:21 -07:00
|
|
|
<div class="tags-filter">
|
2021-05-29 11:37:04 -07:00
|
|
|
<TagsDropdown
|
2021-12-15 04:16:53 -08:00
|
|
|
:placeholder="$locale.baseText('workflowOpen.openWorkflow')"
|
2021-05-29 11:31:21 -07:00
|
|
|
:currentTagIds="filterTagIds"
|
|
|
|
:createEnabled="false"
|
|
|
|
@update="updateTagsFilter"
|
|
|
|
@esc="onTagsFilterEsc"
|
|
|
|
@blur="onTagsFilterBlur"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div class="search-filter">
|
2021-12-15 04:16:53 -08:00
|
|
|
<n8n-input :placeholder="$locale.baseText('workflowOpen.searchWorkflows')" ref="inputFieldFilter" v-model="filterText">
|
2021-08-29 04:36:17 -07:00
|
|
|
<font-awesome-icon slot="prefix" icon="search"></font-awesome-icon>
|
|
|
|
</n8n-input>
|
2021-05-29 11:31:21 -07:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<template v-slot:content>
|
|
|
|
<el-table class="search-table" :data="filteredWorkflows" stripe @cell-click="openWorkflow" :default-sort = "{prop: 'updatedAt', order: 'descending'}" v-loading="isDataLoading">
|
2021-12-15 04:16:53 -08:00
|
|
|
<el-table-column property="name" :label="$locale.baseText('workflowOpen.name')" class-name="clickable" sortable>
|
2021-05-29 11:31:21 -07:00
|
|
|
<template slot-scope="scope">
|
|
|
|
<div :key="scope.row.id">
|
|
|
|
<span class="name">{{scope.row.name}}</span>
|
2021-07-01 01:15:28 -07:00
|
|
|
<TagsContainer class="hidden-sm-and-down" :tagIds="getIds(scope.row.tags)" :limit="3" @click="onTagClick" :clickable="true" :hoverable="true" />
|
2021-05-29 11:31:21 -07:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
</el-table-column>
|
2021-12-15 04:16:53 -08:00
|
|
|
<el-table-column property="createdAt" :label="$locale.baseText('workflowOpen.created')" class-name="clickable" width="155" sortable></el-table-column>
|
|
|
|
<el-table-column property="updatedAt" :label="$locale.baseText('workflowOpen.updated')" class-name="clickable" width="155" sortable></el-table-column>
|
|
|
|
<el-table-column :label="$locale.baseText('workflowOpen.active')" width="75">
|
2021-05-29 11:31:21 -07:00
|
|
|
<template slot-scope="scope">
|
|
|
|
<workflow-activator :workflow-active="scope.row.active" :workflow-id="scope.row.id" @workflowActiveChanged="workflowActiveChanged" />
|
|
|
|
</template>
|
|
|
|
</el-table-column>
|
|
|
|
</el-table>
|
|
|
|
</template>
|
|
|
|
</Modal>
|
2019-06-23 03:35:23 -07:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import Vue from 'vue';
|
2021-05-29 11:31:21 -07:00
|
|
|
import mixins from 'vue-typed-mixins';
|
2019-06-23 03:35:23 -07:00
|
|
|
|
2021-05-29 11:31:21 -07:00
|
|
|
import { ITag, IWorkflowShortResponse } from '@/Interface';
|
2019-06-23 03:35:23 -07:00
|
|
|
|
|
|
|
import { restApi } from '@/components/mixins/restApi';
|
|
|
|
import { genericHelpers } from '@/components/mixins/genericHelpers';
|
2020-07-09 13:54:50 -07:00
|
|
|
import { workflowHelpers } from '@/components/mixins/workflowHelpers';
|
2019-06-23 03:35:23 -07:00
|
|
|
import { showMessage } from '@/components/mixins/showMessage';
|
|
|
|
|
2021-05-29 11:31:21 -07:00
|
|
|
import Modal from '@/components/Modal.vue';
|
|
|
|
import TagsContainer from '@/components/TagsContainer.vue';
|
|
|
|
import TagsDropdown from '@/components/TagsDropdown.vue';
|
|
|
|
import WorkflowActivator from '@/components/WorkflowActivator.vue';
|
2021-09-11 01:15:36 -07:00
|
|
|
import { convertToDisplayDate } from './helpers';
|
2021-10-18 20:57:49 -07:00
|
|
|
import { WORKFLOW_OPEN_MODAL_KEY } from '../constants';
|
2019-06-23 03:35:23 -07:00
|
|
|
|
|
|
|
export default mixins(
|
|
|
|
genericHelpers,
|
|
|
|
restApi,
|
|
|
|
showMessage,
|
2020-07-09 13:54:50 -07:00
|
|
|
workflowHelpers,
|
2019-06-23 03:35:23 -07:00
|
|
|
).extend({
|
|
|
|
name: 'WorkflowOpen',
|
|
|
|
components: {
|
|
|
|
WorkflowActivator,
|
2021-05-29 11:31:21 -07:00
|
|
|
TagsContainer,
|
|
|
|
TagsDropdown,
|
|
|
|
Modal,
|
2019-06-23 03:35:23 -07:00
|
|
|
},
|
2021-05-29 11:31:21 -07:00
|
|
|
props: ['modalName'],
|
2019-06-23 03:35:23 -07:00
|
|
|
data () {
|
|
|
|
return {
|
|
|
|
filterText: '',
|
|
|
|
isDataLoading: false,
|
|
|
|
workflows: [] as IWorkflowShortResponse[],
|
2021-05-29 11:31:21 -07:00
|
|
|
filterTagIds: [] as string[],
|
|
|
|
prevFilterTagIds: [] as string[],
|
2021-10-18 20:57:49 -07:00
|
|
|
WORKFLOW_OPEN_MODAL_KEY,
|
2019-06-23 03:35:23 -07:00
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
filteredWorkflows (): IWorkflowShortResponse[] {
|
2021-05-29 11:31:21 -07:00
|
|
|
return this.workflows
|
|
|
|
.filter((workflow: IWorkflowShortResponse) => {
|
|
|
|
if (this.filterText && !workflow.name.toLowerCase().includes(this.filterText.toLowerCase())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.filterTagIds.length === 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!workflow.tags || workflow.tags.length === 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.filterTagIds.reduce((accu: boolean, id: string) => accu && !!workflow.tags.find(tag => tag.id === id), true);
|
2019-06-23 03:35:23 -07:00
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
2021-05-29 11:31:21 -07:00
|
|
|
mounted() {
|
|
|
|
this.filterText = '';
|
|
|
|
this.filterTagIds = [];
|
|
|
|
this.openDialog();
|
|
|
|
|
|
|
|
Vue.nextTick(() => {
|
|
|
|
// Make sure that users can directly type in the filter
|
|
|
|
(this.$refs.inputFieldFilter as HTMLInputElement).focus();
|
|
|
|
});
|
|
|
|
},
|
2019-06-23 03:35:23 -07:00
|
|
|
methods: {
|
2021-05-29 11:31:21 -07:00
|
|
|
getIds(tags: ITag[] | undefined) {
|
|
|
|
return (tags || []).map((tag) => tag.id);
|
|
|
|
},
|
|
|
|
updateTagsFilter(tags: string[]) {
|
|
|
|
this.filterTagIds = tags;
|
|
|
|
},
|
2021-07-01 01:15:28 -07:00
|
|
|
onTagClick(tagId: string) {
|
|
|
|
if (tagId !== 'count' && !this.filterTagIds.includes(tagId)) {
|
|
|
|
this.filterTagIds.push(tagId);
|
|
|
|
}
|
|
|
|
},
|
2021-12-03 04:59:15 -08:00
|
|
|
async openWorkflow (data: IWorkflowShortResponse, column: any, cell: any, e: PointerEvent) { // tslint:disable-line:no-any
|
2019-06-23 03:35:23 -07:00
|
|
|
if (column.label !== 'Active') {
|
2020-10-25 04:47:49 -07:00
|
|
|
|
|
|
|
const currentWorkflowId = this.$store.getters.workflowId;
|
|
|
|
|
2021-12-03 04:59:15 -08:00
|
|
|
if (e.metaKey || e.ctrlKey) {
|
|
|
|
const route = this.$router.resolve({name: 'NodeViewExisting', params: {name: data.id}});
|
|
|
|
window.open(route.href, '_blank');
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-25 04:47:49 -07:00
|
|
|
if (data.id === currentWorkflowId) {
|
|
|
|
this.$showMessage({
|
2021-12-15 04:16:53 -08:00
|
|
|
title: this.$locale.baseText('workflowOpen.showMessage.title'),
|
|
|
|
message: this.$locale.baseText('workflowOpen.showMessage.message'),
|
2020-10-25 04:47:49 -07:00
|
|
|
type: 'error',
|
2020-10-25 04:58:02 -07:00
|
|
|
duration: 1500,
|
2020-10-25 04:47:49 -07:00
|
|
|
});
|
|
|
|
// Do nothing if current workflow is the one user chose to open
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-09-01 07:06:08 -07:00
|
|
|
const result = this.$store.getters.getStateIsDirty;
|
2020-07-09 13:54:50 -07:00
|
|
|
if(result) {
|
2021-11-10 10:41:40 -08:00
|
|
|
const importConfirm = await this.confirmMessage(
|
2021-12-15 04:16:53 -08:00
|
|
|
this.$locale.baseText('workflowOpen.confirmMessage.message'),
|
|
|
|
this.$locale.baseText('workflowOpen.confirmMessage.headline'),
|
2021-11-10 10:41:40 -08:00
|
|
|
'warning',
|
2021-12-15 04:16:53 -08:00
|
|
|
this.$locale.baseText('workflowOpen.confirmMessage.confirmButtonText'),
|
|
|
|
this.$locale.baseText('workflowOpen.confirmMessage.cancelButtonText'),
|
2021-11-10 10:41:40 -08:00
|
|
|
);
|
2020-07-09 13:54:50 -07:00
|
|
|
if (importConfirm === false) {
|
|
|
|
return;
|
|
|
|
} else {
|
2020-10-25 04:47:49 -07:00
|
|
|
// This is used to avoid duplicating the message
|
|
|
|
this.$store.commit('setStateDirty', false);
|
2021-05-29 11:31:21 -07:00
|
|
|
|
|
|
|
this.$router.push({
|
|
|
|
name: 'NodeViewExisting',
|
|
|
|
params: { name: data.id },
|
|
|
|
});
|
2020-07-09 13:54:50 -07:00
|
|
|
}
|
|
|
|
} else {
|
2021-05-29 11:31:21 -07:00
|
|
|
this.$router.push({
|
|
|
|
name: 'NodeViewExisting',
|
|
|
|
params: { name: data.id },
|
|
|
|
});
|
2020-07-09 13:54:50 -07:00
|
|
|
}
|
2022-01-21 09:00:00 -08:00
|
|
|
this.$store.commit('ui/closeAllModals');
|
2019-06-23 03:35:23 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
openDialog () {
|
|
|
|
this.isDataLoading = true;
|
|
|
|
this.restApi().getWorkflows()
|
|
|
|
.then(
|
|
|
|
(data) => {
|
|
|
|
this.workflows = data;
|
|
|
|
|
|
|
|
this.workflows.forEach((workflowData: IWorkflowShortResponse) => {
|
2021-09-11 01:15:36 -07:00
|
|
|
workflowData.createdAt = convertToDisplayDate(workflowData.createdAt as number);
|
|
|
|
workflowData.updatedAt = convertToDisplayDate(workflowData.updatedAt as number);
|
2019-06-23 03:35:23 -07:00
|
|
|
});
|
|
|
|
this.isDataLoading = false;
|
2019-12-29 13:02:21 -08:00
|
|
|
},
|
2019-06-23 03:35:23 -07:00
|
|
|
)
|
|
|
|
.catch(
|
|
|
|
(error: Error) => {
|
2021-11-10 10:41:40 -08:00
|
|
|
this.$showError(
|
|
|
|
error,
|
2021-12-15 04:16:53 -08:00
|
|
|
this.$locale.baseText('workflowOpen.showError.title'),
|
|
|
|
this.$locale.baseText('workflowOpen.showError.message') + ':',
|
2021-11-10 10:41:40 -08:00
|
|
|
);
|
2019-06-23 03:35:23 -07:00
|
|
|
this.isDataLoading = false;
|
2019-12-29 13:02:21 -08:00
|
|
|
},
|
2019-06-23 03:35:23 -07:00
|
|
|
);
|
|
|
|
},
|
|
|
|
workflowActiveChanged (data: { id: string, active: boolean }) {
|
|
|
|
for (const workflow of this.workflows) {
|
|
|
|
if (workflow.id === data.id) {
|
|
|
|
workflow.active = data.active;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2021-05-29 11:31:21 -07:00
|
|
|
onTagsFilterBlur() {
|
|
|
|
this.prevFilterTagIds = this.filterTagIds;
|
|
|
|
},
|
|
|
|
onTagsFilterEsc() {
|
|
|
|
// revert last applied tags
|
|
|
|
this.filterTagIds = this.prevFilterTagIds;
|
|
|
|
},
|
2019-06-23 03:35:23 -07:00
|
|
|
},
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
2021-05-29 11:31:21 -07:00
|
|
|
.workflows-header {
|
|
|
|
display: flex;
|
|
|
|
|
2021-10-18 20:57:49 -07:00
|
|
|
> *:first-child {
|
2021-05-29 11:31:21 -07:00
|
|
|
flex-grow: 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
.search-filter {
|
|
|
|
margin-left: 10px;
|
|
|
|
min-width: 160px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.tags-filter {
|
|
|
|
flex-grow: 1;
|
|
|
|
max-width: 270px;
|
|
|
|
min-width: 220px;
|
|
|
|
}
|
2019-06-23 03:35:23 -07:00
|
|
|
}
|
|
|
|
|
2021-05-29 11:31:21 -07:00
|
|
|
.search-table .name {
|
|
|
|
font-weight: 400;
|
|
|
|
margin-right: 10px;
|
2019-06-23 03:35:23 -07:00
|
|
|
}
|
|
|
|
</style>
|