2023-05-15 09:41:13 -07:00
|
|
|
import { defineComponent } from 'vue';
|
2023-07-06 07:01:52 -07:00
|
|
|
import { mapStores } from 'pinia';
|
2023-01-10 07:28:15 -08:00
|
|
|
import dateformat from 'dateformat';
|
|
|
|
import { VIEWS } from '@/constants';
|
2023-05-15 09:41:13 -07:00
|
|
|
import { useToast } from '@/composables';
|
2023-07-06 07:01:52 -07:00
|
|
|
import { useSourceControlStore } from '@/stores';
|
2019-06-23 03:35:23 -07:00
|
|
|
|
2023-05-15 09:41:13 -07:00
|
|
|
export const genericHelpers = defineComponent({
|
|
|
|
setup() {
|
|
|
|
return {
|
|
|
|
...useToast(),
|
|
|
|
};
|
|
|
|
},
|
2022-12-14 01:04:10 -08:00
|
|
|
data() {
|
2019-06-23 03:35:23 -07:00
|
|
|
return {
|
2022-12-15 05:06:00 -08:00
|
|
|
loadingService: null as any | null,
|
2019-06-23 03:35:23 -07:00
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
2023-07-06 07:01:52 -07:00
|
|
|
...mapStores(useSourceControlStore),
|
2023-06-27 04:05:20 -07:00
|
|
|
isReadOnlyRoute(): boolean {
|
2023-01-04 00:47:48 -08:00
|
|
|
return ![VIEWS.WORKFLOW, VIEWS.NEW_WORKFLOW, VIEWS.LOG_STREAMING_SETTINGS].includes(
|
|
|
|
this.$route.name as VIEWS,
|
|
|
|
);
|
2019-06-23 03:35:23 -07:00
|
|
|
},
|
2023-07-06 07:01:52 -07:00
|
|
|
readOnlyEnv(): boolean {
|
|
|
|
return this.sourceControlStore.preferences.branchReadOnly;
|
|
|
|
},
|
2019-06-23 03:35:23 -07:00
|
|
|
},
|
|
|
|
methods: {
|
2022-12-14 01:04:10 -08:00
|
|
|
displayTimer(msPassed: number, showMs = false): string {
|
2019-07-24 05:25:30 -07:00
|
|
|
if (msPassed < 60000) {
|
2022-10-24 11:17:25 -07:00
|
|
|
if (!showMs) {
|
2023-01-10 07:28:15 -08:00
|
|
|
return `${Math.floor(msPassed / 1000)}${this.$locale.baseText(
|
|
|
|
'genericHelpers.secShort',
|
|
|
|
)}`;
|
2019-07-24 05:25:30 -07:00
|
|
|
}
|
2019-06-23 03:35:23 -07:00
|
|
|
|
2023-01-10 07:28:15 -08:00
|
|
|
return `${msPassed / 1000}${this.$locale.baseText('genericHelpers.secShort')}`;
|
2019-07-24 05:25:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
const secondsPassed = Math.floor(msPassed / 1000);
|
|
|
|
const minutesPassed = Math.floor(secondsPassed / 60);
|
2022-12-14 01:04:10 -08:00
|
|
|
const secondsLeft = (secondsPassed - minutesPassed * 60).toString().padStart(2, '0');
|
2019-07-24 05:25:30 -07:00
|
|
|
|
2023-01-10 07:28:15 -08:00
|
|
|
return `${minutesPassed}:${secondsLeft}${this.$locale.baseText('genericHelpers.minShort')}`;
|
|
|
|
},
|
2023-01-11 06:08:00 -08:00
|
|
|
convertToDisplayDate(fullDate: Date | string | number): { date: string; time: string } {
|
|
|
|
const mask = `d mmm${
|
|
|
|
new Date(fullDate).getFullYear() === new Date().getFullYear() ? '' : ', yyyy'
|
|
|
|
}#HH:MM:ss`;
|
|
|
|
const formattedDate = dateformat(fullDate, mask);
|
2023-01-10 07:28:15 -08:00
|
|
|
const [date, time] = formattedDate.split('#');
|
|
|
|
return { date, time };
|
2019-07-24 05:25:30 -07:00
|
|
|
},
|
2019-06-23 03:35:23 -07:00
|
|
|
|
2023-05-31 06:01:57 -07:00
|
|
|
/**
|
|
|
|
* @note Loading helpers extracted as composable in useLoadingService
|
|
|
|
*/
|
|
|
|
|
2022-12-14 01:04:10 -08: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
|
2022-12-14 01:04:10 -08:00
|
|
|
this.loadingService = this.$loading({
|
|
|
|
lock: true,
|
|
|
|
text: text || this.$locale.baseText('genericHelpers.loading'),
|
|
|
|
spinner: 'el-icon-loading',
|
|
|
|
background: 'rgba(255, 255, 255, 0.8)',
|
|
|
|
});
|
2019-06-23 03:35:23 -07:00
|
|
|
},
|
2022-12-14 01:04:10 -08:00
|
|
|
setLoadingText(text: string) {
|
2021-06-22 10:33:07 -07:00
|
|
|
this.loadingService.text = text;
|
|
|
|
},
|
2022-12-14 01:04:10 -08:00
|
|
|
stopLoading() {
|
2019-06-23 03:35:23 -07:00
|
|
|
if (this.loadingService !== null) {
|
|
|
|
this.loadingService.close();
|
|
|
|
this.loadingService = null;
|
|
|
|
}
|
|
|
|
},
|
2023-08-23 19:59:16 -07:00
|
|
|
isRedirectSafe() {
|
|
|
|
const redirect = this.getRedirectQueryParameter();
|
|
|
|
return redirect.startsWith('/');
|
|
|
|
},
|
|
|
|
getRedirectQueryParameter() {
|
|
|
|
let redirect = '';
|
|
|
|
if (typeof this.$route.query.redirect === 'string') {
|
|
|
|
redirect = decodeURIComponent(this.$route.query.redirect);
|
|
|
|
}
|
|
|
|
return redirect;
|
|
|
|
},
|
2019-06-23 03:35:23 -07:00
|
|
|
},
|
|
|
|
});
|