2019-06-23 03:35:23 -07:00
< template >
< span >
< el -dialog :visible ="dialogVisible" append -to -body width = "80%" title = "Open Workflow" :before-close ="closeDialog" top = "5vh" >
< div class = "text-very-light" >
Select a workflow to open :
< / div >
< div class = "search-wrapper ignore-key-press" >
< el -input placeholder = "Workflow filter..." ref = "inputFieldFilter" v-model ="filterText" >
< i slot = "prefix" class = "el-input__icon el-icon-search" > < / i >
< / e l - i n p u t >
< / div >
< 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 > < / e l - t a b l e - c o l u m n >
< el -table -column property = "createdAt" label = "Created" class -name = " clickable " width = "225" 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 = "225" sortable > < / e l - t a b l e - c o l u m n >
< el -table -column label = "Active" width = "90" >
< 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 >
< / e l - d i a l o g >
< / span >
< / template >
< script lang = "ts" >
import Vue from 'vue' ;
import WorkflowActivator from '@/components/WorkflowActivator.vue' ;
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' ;
2020-08-25 11:38:09 -07:00
import { titleChange } from '@/components/mixins/titleChange' ;
2019-06-23 03:35:23 -07:00
import { IWorkflowShortResponse } from '@/Interface' ;
import mixins from 'vue-typed-mixins' ;
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' ,
props : [
'dialogVisible' ,
] ,
components : {
WorkflowActivator ,
} ,
data ( ) {
return {
filterText : '' ,
isDataLoading : false ,
workflows : [ ] as IWorkflowShortResponse [ ] ,
} ;
} ,
computed : {
filteredWorkflows ( ) : IWorkflowShortResponse [ ] {
return this . workflows . filter ( ( workflow : IWorkflowShortResponse ) => {
if ( this . filterText === '' || workflow . name . toLowerCase ( ) . indexOf ( this . filterText . toLowerCase ( ) ) !== - 1 ) {
return true ;
}
return false ;
} ) ;
} ,
} ,
watch : {
dialogVisible ( newValue , oldValue ) {
if ( newValue ) {
this . filterText = '' ;
this . openDialog ( ) ;
Vue . nextTick ( ( ) => {
// Make sure that users can directly type in the filter
( this . $refs . inputFieldFilter as HTMLInputElement ) . focus ( ) ;
} ) ;
}
} ,
} ,
methods : {
closeDialog ( ) {
// Handle the close externally as the visible parameter is an external prop
// and is so not allowed to be changed here.
this . $emit ( 'closeDialog' ) ;
return false ;
} ,
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-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 {
this . $emit ( 'openWorkflow' , data . id ) ;
}
} else {
this . $emit ( 'openWorkflow' , data . id ) ;
}
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 ) => {
workflowData . createdAt = this . convertToDisplayDate ( workflowData . createdAt as number ) ;
workflowData . updatedAt = this . convertToDisplayDate ( workflowData . updatedAt as number ) ;
} ) ;
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 ;
}
}
} ,
} ,
} ) ;
< / script >
< style scoped lang = "scss" >
. search - wrapper {
position : absolute ;
right : 20 px ;
top : 20 px ;
width : 200 px ;
}
. search - table {
margin - top : 2 em ;
}
< / style >