2019-06-23 03:35:23 -07:00
import { showMessage } from '@/components/mixins/showMessage' ;
2021-11-09 00:59:48 -08:00
import { translate } from '@/components/mixins/translate' ;
2021-05-29 11:31:21 -07:00
import { debounce } from 'lodash' ;
2019-06-23 03:35:23 -07:00
import mixins from 'vue-typed-mixins' ;
2021-11-09 00:59:48 -08:00
export const genericHelpers = mixins ( showMessage , translate ) . extend ( {
2019-06-23 03:35:23 -07:00
data ( ) {
return {
loadingService : null as any | null , // tslint:disable-line:no-any
2021-05-29 11:31:21 -07:00
debouncedFunctions : [ ] as any [ ] , // tslint:disable-line:no-any
2019-06-23 03:35:23 -07:00
} ;
} ,
computed : {
isReadOnly ( ) : boolean {
if ( [ 'NodeViewExisting' , 'NodeViewNew' ] . includes ( this . $route . name as string ) ) {
return false ;
}
return true ;
} ,
} ,
methods : {
2019-07-24 05:25:30 -07:00
displayTimer ( msPassed : number , showMs = false ) : string {
if ( msPassed < 60000 ) {
if ( showMs === false ) {
return ` ${ Math . floor ( msPassed / 1000 ) } sec. ` ;
}
2019-06-23 03:35:23 -07:00
2019-07-24 05:25:30 -07:00
return ` ${ msPassed / 1000 } sec. ` ;
}
const secondsPassed = Math . floor ( msPassed / 1000 ) ;
const minutesPassed = Math . floor ( secondsPassed / 60 ) ;
const secondsLeft = ( secondsPassed - ( minutesPassed * 60 ) ) . toString ( ) . padStart ( 2 , '0' ) ;
return ` ${ minutesPassed } : ${ secondsLeft } min. ` ;
} ,
2019-06-23 03:35:23 -07:00
editAllowedCheck ( ) : boolean {
if ( this . isReadOnly ) {
this . $showMessage ( {
title : 'Workflow can not be changed!' ,
message : ` The workflow can not be edited as a past execution gets displayed. To make changed either open the original workflow of which the execution gets displayed or save it under a new name first. ` ,
type : 'error' ,
duration : 0 ,
} ) ;
return false ;
}
return true ;
} ,
2021-05-04 08:55:39 -07:00
startLoading ( text? : string ) {
2019-06-23 03:35:23 -07:00
if ( this . loadingService !== null ) {
return ;
}
2021-08-29 04:36:17 -07:00
// @ts-ignore
2019-06-23 03:35:23 -07:00
this . loadingService = this . $loading (
{
lock : true ,
2021-05-04 08:55:39 -07:00
text : text || 'Loading' ,
2019-06-23 03:35:23 -07:00
spinner : 'el-icon-loading' ,
background : 'rgba(255, 255, 255, 0.8)' ,
2019-12-29 13:02:21 -08:00
} ,
2019-06-23 03:35:23 -07:00
) ;
} ,
2021-06-22 10:33:07 -07:00
setLoadingText ( text : string ) {
this . loadingService . text = text ;
} ,
2019-06-23 03:35:23 -07:00
stopLoading ( ) {
if ( this . loadingService !== null ) {
this . loadingService . close ( ) ;
this . loadingService = null ;
}
} ,
2021-05-29 11:31:21 -07:00
async callDebounced ( . . . inputParameters : any [ ] ) : Promise < void > { // tslint:disable-line:no-any
const functionName = inputParameters . shift ( ) as string ;
const debounceTime = inputParameters . shift ( ) as number ;
// @ts-ignore
if ( this . debouncedFunctions [ functionName ] === undefined ) {
// @ts-ignore
this . debouncedFunctions [ functionName ] = debounce ( this [ functionName ] , debounceTime , { leading : true } ) ;
}
// @ts-ignore
await this . debouncedFunctions [ functionName ] . apply ( this , inputParameters ) ;
} ,
2019-06-23 03:35:23 -07:00
} ,
} ) ;