Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(HistoryPanel): Fix History thumbnails of files in folders #2010

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 16 additions & 22 deletions src/components/panels/History/HistoryListEntryJob.vue
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ import { Component, Mixins, Prop } from 'vue-property-decorator'
import HistoryListPanelDetailsDialog from '@/components/dialogs/HistoryListPanelDetailsDialog.vue'
import Panel from '@/components/ui/Panel.vue'
import BaseMixin from '@/components/mixins/base'
import { FileStateFileThumbnail } from '@/store/files/types'
import { ServerHistoryStateJob } from '@/store/server/history/types'
import { thumbnailBigMin, thumbnailSmallMax, thumbnailSmallMin } from '@/store/variables'
import {
Expand Down Expand Up @@ -187,40 +188,22 @@ export default class HistoryListPanel extends Mixins(BaseMixin) {
if ((this.item.metadata?.thumbnails?.length ?? 0) < 1) return false

const thumbnail = this.item.metadata?.thumbnails?.find(
(thumb: any) =>
(thumb) =>
thumb.width >= thumbnailSmallMin &&
thumb.width <= thumbnailSmallMax &&
thumb.height >= thumbnailSmallMin &&
thumb.height <= thumbnailSmallMax
)

let relative_url = ''
if (this.item.filename.lastIndexOf('/') !== -1) {
relative_url = this.item.filename.substring(0, this.item.filename.lastIndexOf('/'))
}

if ((thumbnail?.relative_path ?? null) === null) return false

return `${this.apiUrl}/server/files/gcodes/${encodeURI(relative_url + thumbnail?.relative_path)}?timestamp=${
this.item.metadata.modified
}`
return thumbnail ? this.createThumbnailUrl(thumbnail) : false
}

get bigThumbnail() {
if ((this.item.metadata?.thumbnails?.length ?? 0) < 1) return false

const thumbnail = this.item.metadata?.thumbnails?.find((thumb: any) => thumb.width >= thumbnailBigMin)

let relative_url = ''
if (this.item.filename.lastIndexOf('/') !== -1) {
relative_url = this.item.filename.substring(0, this.item.filename.lastIndexOf('/') + 1)
}

if ((thumbnail?.relative_path ?? null) === null) return false
const thumbnail = this.item.metadata?.thumbnails?.find((thumb) => thumb.width >= thumbnailBigMin)

return `${this.apiUrl}/server/files/gcodes/${encodeURI(relative_url + thumbnail?.relative_path)}?timestamp=${
this.item.metadata.modified
}`
return thumbnail ? this.createThumbnailUrl(thumbnail) : false
}

get statusIcon() {
Expand Down Expand Up @@ -331,5 +314,16 @@ export default class HistoryListPanel extends Mixins(BaseMixin) {
return value
}
}

createThumbnailUrl(thumbnail: FileStateFileThumbnail) {
let relative_url = ''
if (this.item.filename.lastIndexOf('/') !== -1) {
relative_url = this.item.filename.substring(0, this.item.filename.lastIndexOf('/') + 1)
}

return `${this.apiUrl}/server/files/gcodes/${encodeURI(relative_url + thumbnail.relative_path)}?timestamp=${
this.item.metadata.modified
}`
}
}
</script>
Loading