2019-06-23 03:35:23 -07:00
< template >
2021-05-29 11:31:21 -07:00
< Modal
: name = "modalName"
size = "xl"
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" >
< div class = "title" >
< h1 > Open Workflow < / h1 >
< / div >
< div class = "tags-filter" >
2021-05-29 11:37:04 -07:00
< TagsDropdown
2021-05-29 11:31:21 -07:00
placeholder = "Filter by tags..."
: currentTagIds = "filterTagIds"
: createEnabled = "false"
@ update = "updateTagsFilter"
@ esc = "onTagsFilterEsc"
@ blur = "onTagsFilterBlur"
/ >
< / div >
< div class = "search-filter" >
2021-08-29 04:36:17 -07:00
< n8n -input placeholder = "Search workflows..." ref = "inputFieldFilter" v-model ="filterText" >
< font -awesome -icon slot = "prefix" icon = "search" > < / f o n t - a w e s o m e - i c o n >
< / n 8 n - i n p u t >
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" >
< el -table -column property = "name" label = "Name" class -name = " clickable " sortable >
< 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 >
< / e l - t a b l e - c o l u m n >
< el -table -column property = "createdAt" label = "Created" class -name = " clickable " width = "155" sortable > < / e l - t a b l e - c o l u m n >
< el -table -column property = "updatedAt" label = "Updated" class -name = " clickable " width = "155" sortable > < / e l - t a b l e - c o l u m n >
< el -table -column label = "Active" width = "75" >
< template slot -scope = " scope " >
< workflow -activator :workflow-active ="scope.row.active" :workflow-id ="scope.row.id" @workflowActiveChanged ="workflowActiveChanged" / >
< / template >
< / e l - t a b l e - c o l u m n >
< / e l - t a b l e >
< / 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' ;
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 [ ] ,
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 ) ;
}
} ,
2020-07-09 13:54:50 -07:00
async openWorkflow ( data : IWorkflowShortResponse , column : any ) { // 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 ;
if ( data . id === currentWorkflowId ) {
this . $showMessage ( {
title : 'Already open' ,
message : 'This is the current workflow' ,
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 ) {
const importConfirm = await this . confirmMessage ( ` When you switch workflows your current workflow changes will be lost. ` , 'Save your Changes?' , 'warning' , 'Yes, switch workflows and forget changes' ) ;
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
}
2021-05-29 11:31:21 -07:00
this . $store . commit ( 'ui/closeTopModal' ) ;
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 ) => {
this . $showError ( error , 'Problem loading workflows' , 'There was a problem loading the workflows:' ) ;
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 ;
. title {
flex - grow : 1 ;
h1 {
line - height : 24 px ;
font - size : 18 px ;
}
}
. search - filter {
margin - left : 10 px ;
min - width : 160 px ;
}
. tags - filter {
flex - grow : 1 ;
max - width : 270 px ;
min - width : 220 px ;
}
2019-06-23 03:35:23 -07:00
}
2021-05-29 11:31:21 -07:00
. search - table . name {
font - weight : 400 ;
margin - right : 10 px ;
2019-06-23 03:35:23 -07:00
}
< / style >