2019-06-23 03:35:23 -07:00
|
|
|
import { showMessage } from '@/components/mixins/showMessage';
|
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-12-07 07:14:40 -08:00
|
|
|
export const genericHelpers = mixins(showMessage).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) {
|
2021-12-15 04:16:53 -08:00
|
|
|
return `${this.$n(Math.floor(msPassed / 1000), 'decimal')} ${this.$locale.baseText('genericHelpers.sec')}`;
|
2019-07-24 05:25:30 -07:00
|
|
|
}
|
2019-06-23 03:35:23 -07:00
|
|
|
|
2021-12-15 04:16:53 -08:00
|
|
|
return `${this.$locale.number(msPassed / 1000, 'decimal')} ${this.$locale.baseText('genericHelpers.sec')}`;
|
2019-07-24 05:25:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
const secondsPassed = Math.floor(msPassed / 1000);
|
|
|
|
const minutesPassed = Math.floor(secondsPassed / 60);
|
|
|
|
|
2021-12-15 04:16:53 -08:00
|
|
|
return `${this.$locale.number(minutesPassed, 'decimal')}:${this.$locale.number(secondsPassed, 'decimal')} ${this.$locale.baseText('genericHelpers.min')}`;
|
2019-07-24 05:25:30 -07:00
|
|
|
},
|
2019-06-23 03:35:23 -07:00
|
|
|
editAllowedCheck (): boolean {
|
|
|
|
if (this.isReadOnly) {
|
|
|
|
this.$showMessage({
|
2021-11-10 10:41:40 -08:00
|
|
|
// title: 'Workflow can not be changed!',
|
2021-12-15 04:16:53 -08:00
|
|
|
title: this.$locale.baseText('genericHelpers.showMessage.title'),
|
|
|
|
message: this.$locale.baseText('genericHelpers.showMessage.message'),
|
2019-06-23 03:35:23 -07:00
|
|
|
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-12-15 04:16:53 -08:00
|
|
|
text: text || this.$locale.baseText('genericHelpers.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
|
|
|
},
|
|
|
|
});
|