redirect export using djangoResolveUrl

This commit is contained in:
smilerz
2022-02-22 16:00:55 -06:00
parent a7d66fa850
commit f9a4521ca1

View File

@@ -3,9 +3,8 @@
<br /> <br />
<template v-if="export_info !== undefined"> <template v-if="export_info !== undefined">
<template v-if="export_info.running"> <template v-if="export_info.running">
<h5 style="text-align: center">{{ $t('Exporting') }}...</h5> <h5 style="text-align: center">{{ $t("Exporting") }}...</h5>
<b-progress :max="export_info.total_recipes"> <b-progress :max="export_info.total_recipes">
<b-progress-bar :value="export_info.exported_recipes" :label="`${export_info.exported_recipes}/${export_info.total_recipes}`"></b-progress-bar> <b-progress-bar :value="export_info.exported_recipes" :label="`${export_info.exported_recipes}/${export_info.total_recipes}`"></b-progress-bar>
@@ -16,31 +15,26 @@
<div class="row"> <div class="row">
<div class="col col-md-12" v-if="!export_info.running"> <div class="col col-md-12" v-if="!export_info.running">
<span>{{ $t('Export_finished') }}! </span> <a :href="`${resolveDjangoUrl('viewExport') }`">{{ $t('Return to export') }} </a><br><br> <span>{{ $t("Export_finished") }}! </span> <a :href="`${resolveDjangoUrl('viewExport')}`">{{ $t("Return to export") }} </a><br /><br />
{{ $t('If download did not start automatically: ') }} {{ $t("If download did not start automatically: ") }}
<template v-if="export_info.expired"> <template v-if="export_info.expired">
<a disabled><del>{{ $t('Download') }}</del></a> ({{ $t('Expired') }}) <a disabled
><del>{{ $t("Download") }}</del></a
>
({{ $t("Expired") }})
</template> </template>
<a v-else :href="`/export-file/${export_id}/`" ref="downloadAnchor" >{{ $t('Download') }}</a> <a v-else :href="`${resolveDjangoUrl('view_export_file', export_id)}`" ref="downloadAnchor">{{ $t("Download") }}</a>
<br> <br />
{{ $t('The link will remain active for') }} {{ $t("The link will remain active for") }}
<template v-if="export_info.cache_duration > 3600"> <template v-if="export_info.cache_duration > 3600"> {{ export_info.cache_duration / 3600 }}{{ $t("hr") }} </template>
{{ export_info.cache_duration/3600 }}{{ $t('hr') }} <template v-else-if="export_info.cache_duration > 60"> {{ export_info.cache_duration / 60 }}{{ $t("min") }} </template>
</template> <template v-else> {{ export_info.cache_duration }}{{ $t("sec") }} </template>
<template v-else-if="export_info.cache_duration > 60">
{{ export_info.cache_duration/60 }}{{ $t('min') }}
</template>
<template v-else>
{{ export_info.cache_duration }}{{ $t('sec') }}
</template>
<br>
<br />
</div> </div>
</div> </div>
@@ -48,43 +42,35 @@
<div class="row"> <div class="row">
<div class="col col-md-12"> <div class="col col-md-12">
<label for="id_textarea">{{ $t('Information') }}</label> <label for="id_textarea">{{ $t("Information") }}</label>
<textarea id="id_textarea" ref="output_text" class="form-control" style="height: 50vh" <textarea id="id_textarea" ref="output_text" class="form-control" style="height: 50vh" v-html="export_info.msg" disabled></textarea>
v-html="export_info.msg"
disabled></textarea>
</div> </div>
</div> </div>
<br /> <br />
<br /> <br />
</template> </template>
</div> </div>
</template> </template>
<script> <script>
import Vue from 'vue' import Vue from "vue"
import {BootstrapVue} from 'bootstrap-vue' import { BootstrapVue } from "bootstrap-vue"
import 'bootstrap-vue/dist/bootstrap-vue.css' import "bootstrap-vue/dist/bootstrap-vue.css"
import {ResolveUrlMixin, makeToast, ToastMixin} from "@/utils/utils"; import { ResolveUrlMixin, makeToast, ToastMixin } from "@/utils/utils"
import LoadingSpinner from "@/components/LoadingSpinner"; import LoadingSpinner from "@/components/LoadingSpinner"
import {ApiApiFactory} from "@/utils/openapi/api.ts"; import { ApiApiFactory } from "@/utils/openapi/api.ts"
Vue.use(BootstrapVue) Vue.use(BootstrapVue)
export default { export default {
name: 'ExportResponseView', name: "ExportResponseView",
mixins: [ mixins: [ResolveUrlMixin, ToastMixin],
ResolveUrlMixin,
ToastMixin,
],
components: { components: {
LoadingSpinner LoadingSpinner,
}, },
data() { data() {
return { return {
@@ -101,45 +87,40 @@ export default {
}, },
methods: { methods: {
dynamicInterval: function () { dynamicInterval: function () {
//update frequently at start but slowdown as it takes longer //update frequently at start but slowdown as it takes longer
this.dynamicIntervalTimeout = Math.round(this.dynamicIntervalTimeout * ((1 + Math.sqrt(5)) / 2)) this.dynamicIntervalTimeout = Math.round(this.dynamicIntervalTimeout * ((1 + Math.sqrt(5)) / 2))
if (this.dynamicIntervalTimeout > 5000) this.dynamicIntervalTimeout = 5000 if (this.dynamicIntervalTimeout > 5000) this.dynamicIntervalTimeout = 5000
clearInterval(this.run); clearInterval(this.run)
this.run = setInterval(this.dynamicInterval.bind(this), this.dynamicIntervalTimeout); this.run = setInterval(this.dynamicInterval.bind(this), this.dynamicIntervalTimeout)
if ((this.export_id !== null) && window.navigator.onLine && this.export_info.running) { if (this.export_id !== null && window.navigator.onLine && this.export_info.running) {
this.refreshData() this.refreshData()
let el = this.$refs.output_text let el = this.$refs.output_text
el.scrollTop = el.scrollHeight; el.scrollTop = el.scrollHeight
if(this.export_info.expired) if (this.export_info.expired) makeToast(this.$t("Error"), this.$t("The download link is expired!"), "danger")
makeToast(this.$t("Error"), this.$t("The download link is expired!"), "danger")
} }
}, },
startDownload: function () { startDownload: function () {
this.$refs['downloadAnchor'].click() this.$refs["downloadAnchor"].click()
}, },
refreshData: function () { refreshData: function () {
let apiClient = new ApiApiFactory() let apiClient = new ApiApiFactory()
apiClient.retrieveExportLog(this.export_id).then(result => { apiClient.retrieveExportLog(this.export_id).then((result) => {
this.export_info = result.data this.export_info = result.data
this.export_info.expired = !this.export_info.possibly_not_expired this.export_info.expired = !this.export_info.possibly_not_expired
if (!this.export_info.running) if (!this.export_info.running)
this.$nextTick(()=>{ this.startDownload(); } ) this.$nextTick(() => {
this.startDownload()
}) })
})
},
},
} }
}
}
</script> </script>
<style> <style></style>
</style>