Skip to content

Commit 2caccaa

Browse files
committed
fix: time estimations display Infinity
1 parent eed7c71 commit 2caccaa

6 files changed

Lines changed: 66 additions & 35 deletions

File tree

src/components/widgets/filesystem/FileSystemBrowser.vue

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,9 @@
188188
</v-list-item>
189189
</v-list>
190190
</v-col>
191-
<v-col class="px-2 d-none d-sm-flex">
191+
<v-col class="px-2 d-none d-sm-flex" v-if="contextMenu.item.thumbnails && contextMenu.item.thumbnails.length">
192192
<img
193-
v-if="contextMenu.item.thumbnails && contextMenu.item.thumbnails.length"
194-
class="mr-1 file-icon-thumb"
193+
class="mr-2 ml-2"
195194
:src="getThumb(contextMenu.item, true).data"
196195
:height="150"
197196
/>

src/plugins/filters.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import _Vue from 'vue'
2-
import { camelCase, startCase, capitalize } from 'lodash-es'
2+
import { camelCase, startCase, capitalize, isFinite } from 'lodash-es'
33

44
const Filters = {
55

@@ -8,8 +8,9 @@ const Filters = {
88
* Expects to be passed seconds.
99
*/
1010
formatCounterTime: (seconds: number) => {
11+
seconds = Number(seconds)
12+
if (isNaN(+seconds) || !isFinite(seconds)) seconds = 0
1113
let isNeg = false
12-
if (isNaN(seconds)) seconds = 0
1314
if (seconds < 0) {
1415
seconds = Math.abs(seconds)
1516
isNeg = true
@@ -22,7 +23,6 @@ const Filters = {
2223
if (m > 0) r = m + 'm ' + r
2324
if (h > 0) r = h + 'h ' + r
2425

25-
// const r = `${h}h ${m}m ${s}s`
2626
return (isNeg) ? '-' + r : r
2727
},
2828

src/scss/global.scss

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,7 @@
3737
user-select: none;
3838
}
3939

40-
// .v-data-table > .v-data-table__wrapper > table > tbody > tr > td,
41-
// .v-data-table > .v-data-table__wrapper > table > thead > tr > td,
42-
// .v-data-table > .v-data-table__wrapper > table > tfoot > tr > td {
43-
// height: 40px;
44-
// }
45-
40+
// gcode thumbnails in the file list
4641
.file-icon-thumb {
4742
align-items: center;
4843
display: inline-flex;

src/store/socket/actions.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ export const actions: ActionTree<SocketState, RootState> = {
4949
* Another case might be during a klippy disconnect.
5050
*/
5151
async onSocketError ({ commit }, payload) {
52-
if (payload.code >= 400 && payload.code < 500) {
53-
// clear any associated waits.
54-
if (payload.__request__ && payload.__request__.wait) {
55-
commit('removeWait', payload.__request__.wait)
56-
}
52+
// clear any associated waits.
53+
if (payload.__request__ && payload.__request__.wait) {
54+
commit('removeWait', payload.__request__.wait)
55+
}
5756

57+
if (payload.code >= 400 && payload.code < 500) {
5858
// If our message contains json, we should try to parse it.
5959
// This is pretty bad, should get moonraker to fix this response.
6060
let message = ''

src/store/socket/getters.ts

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Thumbnail } from '@/store/files/types'
55
import { RootState } from '../types'
66
import { chartConfiguration } from '@/globals'
77
import { TinyColor } from '@ctrl/tinycolor'
8-
import { get } from 'lodash-es'
8+
import { get, isFinite } from 'lodash-es'
99
import { getThumb } from '../helpers'
1010

1111
export const getters: GetterTree<SocketState, RootState> = {
@@ -120,21 +120,37 @@ export const getters: GetterTree<SocketState, RootState> = {
120120
* Returns an object representing the time estimates of a current print.
121121
*/
122122
getTimeEstimates: (state) => (type: 'slicer' | 'file' | 'filament' | 'totals'): TimeEstimates => {
123-
const progress = (state.printer.display_status.progress && !isNaN(state.printer.display_status.progress))
124-
? state.printer.display_status.progress
125-
: 0
126-
// state.printer.print_stats.total_duration
127-
const duration = (state.printer.print_stats.print_duration && !isNaN(state.printer.print_stats.print_duration))
128-
? state.printer.print_stats.print_duration
129-
: 0
130-
131-
const usedFilament = (state.printer.print_stats.filament_used && !isNaN(state.printer.print_stats.filament_used))
132-
? state.printer.print_stats.filament_used
133-
: 0
134-
135-
const estimatedFilament = (state.printer.current_file.filament_total && !isNaN(state.printer.current_file.filament_total))
136-
? state.printer.current_file.filament_total
137-
: 0
123+
const progress = (
124+
!state.printer.virtual_sdcard.progress ||
125+
isNaN(+state.printer.virtual_sdcard.progress) ||
126+
!isFinite(+state.printer.virtual_sdcard.progress)
127+
)
128+
? 0
129+
: state.printer.virtual_sdcard.progress
130+
131+
const duration = (
132+
!state.printer.print_stats.print_duration ||
133+
isNaN(+state.printer.print_stats.print_duration) ||
134+
!isFinite(+state.printer.print_stats.print_duration)
135+
)
136+
? 0
137+
: state.printer.print_stats.print_duration
138+
139+
const usedFilament = (
140+
!state.printer.print_stats.filament_used ||
141+
isNaN(+state.printer.print_stats.filament_used) ||
142+
!isFinite(+state.printer.print_stats.filament_used)
143+
)
144+
? 0
145+
: state.printer.print_stats.filament_used
146+
147+
const estimatedFilament = (
148+
!state.printer.current_file.filament_total ||
149+
isNaN(+state.printer.current_file.filament_total) ||
150+
!isFinite(+state.printer.current_file.filament_total)
151+
)
152+
? 0
153+
: state.printer.current_file.filament_total
138154

139155
let timeLeft = 0
140156
let totalDuration = 0
@@ -161,11 +177,25 @@ export const getters: GetterTree<SocketState, RootState> = {
161177
break
162178
}
163179
default: { // totals only.
164-
totalDuration = duration / (progress * 100) - duration
165-
timeLeft = totalDuration - duration
180+
totalDuration = 0
181+
timeLeft = 0
166182
}
167183
}
168184

185+
totalDuration = (
186+
isNaN(+totalDuration) ||
187+
!isFinite(+totalDuration)
188+
)
189+
? 0
190+
: totalDuration
191+
192+
timeLeft = (
193+
isNaN(+timeLeft) ||
194+
!isFinite(+timeLeft)
195+
)
196+
? 0
197+
: timeLeft
198+
169199
const o = {
170200
type,
171201
progress: (progress * 100).toFixed(),

src/store/socket/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,19 @@ export const getDefaultState = (): SocketState => {
5555
print_stats: {
5656
state: '',
5757
print_duration: 0,
58+
total_duration: 0,
59+
filament_used: 0,
5860
filename: ''
5961
},
6062
display_status: {
6163
progress: 0,
6264
message: ''
6365
},
66+
virtual_sdcard: {
67+
file_position: 0,
68+
is_active: false,
69+
progress: 0
70+
},
6471
toolhead: {
6572
estimated_print_time: 0,
6673
homed_axes: '',

0 commit comments

Comments
 (0)