Skip to content

Commit

Permalink
Added a print progress bar instead of a spinner
Browse files Browse the repository at this point in the history
The progress bar is degressive and it's completion time is set based on the
number of layer to print
  • Loading branch information
ltshb committed Jun 26, 2024
1 parent 4ff2d2a commit cc1946b
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/modules/menu/components/print/MenuPrintSection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
usePrint,
} from '@/modules/map/components/openlayers/utils/usePrint.composable'
import MenuSection from '@/modules/menu/components/menu/MenuSection.vue'
import ProgressBar from '@/utils/components/ProgressBar.vue'
import log from '@/utils/logging'
import { formatThousand } from '@/utils/numberUtils'
Expand All @@ -27,6 +28,8 @@ const store = useStore()
const availablePrintLayouts = computed(() => store.state.print.layouts)
const selectedLayout = computed(() => store.state.print.selectedLayout)
const scales = computed(() => selectedLayout.value?.scales || [])
// approximate print duration := 8s per layer (+1 is for the background layer and to avoid 0 duration)
const printDuration = computed(() => 8 * (store.getters.visibleLayers.length + 1))
const selectedLayoutName = computed({
get() {
Expand Down Expand Up @@ -198,6 +201,12 @@ defineExpose({
<div class="valid-feedback">{{ i18n.t('operation_successful') }}</div>
</div>
<div class="full-width justify-content-center">
<ProgressBar
v-if="printStatus === PrintStatus.PRINTING"
:duration="printDuration"
bar-class="bg-danger"
class="mb-2"
/>
<button
v-if="printStatus === PrintStatus.PRINTING"
type="button"
Expand All @@ -206,7 +215,6 @@ defineExpose({
@click="abortCurrentJob"
>
{{ i18n.t('abort') }}
<font-awesome-icon spin :icon="['fa', 'spinner']" class="ms-2" />
</button>
<button
v-else
Expand Down
71 changes: 71 additions & 0 deletions src/utils/components/ProgressBar.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<script setup>
import { onBeforeUnmount, onMounted, ref, toRefs } from 'vue'
import log from '@/utils/logging'
const props = defineProps({
duration: {
type: Number,
required: true,
},
barClass: {
type: String,
default: '',
},
})
const { duration, barClass } = toRefs(props)
const value = ref(0)
const waitTime = ref(0)
const totalTime = ref(0)
const slot = ref(0)
const maxValue = 100
let started = null
let timer = null
onMounted(() => {
started = Date.now()
totalTime.value = duration.value * 1000
slot.value = Math.floor((maxValue * 2) / 3)
waitTime.value = (totalTime.value * 2) / 3 / slot.value
log.debug(
`progress value=${value.value} slot=${slot.value} duration=${duration.value} waitTime=${waitTime.value}`
)
timer = setTimeout(progress, waitTime.value)
})
onBeforeUnmount(() => {
clearTimeout(timer)
log.debug(`progress finished after ${Date.now() - started}ms`)
})
function progress() {
value.value += 1
if (value.value < maxValue) {
if (value.value === slot.value) {
slot.value = Math.floor((100 - slot.value) / 2 + slot.value)
waitTime.value *= 2
log.debug(
`progress value=${value.value} slot=${slot.value} new waitTime=${waitTime.value}`
)
}
timer = setTimeout(progress, waitTime.value)
}
}
</script>

<template>
<div class="progress">
<div
class="progress-bar"
:class="barClass"
role="progressbar"
:style="`width: ${value}%`"
:aria-valuenow="value"
aria-valuemin="0"
aria-valuemax="100"
/>
</div>
</template>

0 comments on commit cc1946b

Please sign in to comment.