Skip to content

Commit

Permalink
Merge pull request #10 from Wondro/develop
Browse files Browse the repository at this point in the history
[feat] Update AFC panel to current build format
  • Loading branch information
MG-longshot authored Jan 25, 2025
2 parents e736c83 + 3f3221c commit eef8d94
Show file tree
Hide file tree
Showing 14 changed files with 932 additions and 276 deletions.
103 changes: 65 additions & 38 deletions src/components/dialogs/AfcChangeSpoolDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,46 @@
hide-details
style="max-width: 300px" />
<v-spacer />
<v-btn
:title="$t('Panels.SpoolmanPanel.EjectSpool')"
class="px-2 minwidth-0 ml-3"
:loading="loadings.includes('ejectSpool')"
@click="ejectSpool">
<v-icon>{{ mdiEject }}</v-icon>
</v-btn>
<v-btn
v-if="spoolManagerUrl"
:title="$t('Panels.SpoolmanPanel.Refresh')"
class="px-2 minwidth-0 ml-3"
:loading="loadings.includes('refreshSpools')"
@click="refreshSpools">
<v-icon>{{ mdiRefresh }}</v-icon>
</v-btn>
<v-btn
v-if="spoolManagerUrl"
:title="$t('Panels.SpoolmanPanel.OpenSpoolManager')"
class="px-2 minwidth-0 ml-3"
@click="openSpoolManager">
<v-icon>{{ mdiDatabase }}</v-icon>
</v-btn>
<v-tooltip top>
<template #activator="{ on: onTooltip, attrs }">
<v-btn
v-bind="attrs"
class="px-2 minwidth-0 ml-3"
:loading="loadings.includes('ejectSpool')"
v-on="onTooltip"
@click="ejectSpool">
<v-icon>{{ mdiEject }}</v-icon>
</v-btn>
</template>
<span>{{ $t('Panels.AfcPanel.SpoolEject') }}</span>
</v-tooltip>
<v-tooltip top>
<template #activator="{ on: onTooltip, attrs }">
<v-btn
v-if="spoolManagerUrl"
v-bind="attrs"
class="px-2 minwidth-0 ml-3"
:loading="loadings.includes('refreshSpools')"
v-on="onTooltip"
@click="refreshSpools">
<v-icon>{{ mdiRefresh }}</v-icon>
</v-btn>
</template>
<span>{{ $t('Panels.SpoolmanPanel.Refresh') }}</span>
</v-tooltip>
<v-tooltip top>
<template #activator="{ on: onTooltip, attrs }">
<v-btn
v-if="spoolManagerUrl"
v-bind="attrs"
class="px-2 minwidth-0 ml-3"
v-on="onTooltip"
@click="openSpoolManager">
<v-icon>{{ mdiDatabase }}</v-icon>
</v-btn>
</template>
<span>{{ $t('Panels.SpoolmanPanel.OpenSpoolManager') }}</span>
</v-tooltip>
</v-card-title>
<v-card-text class="px-0 pb-0">
<v-data-table
Expand All @@ -64,11 +82,12 @@
</template>

<template #item="{ item }">
<SpoolmanChangeSpoolDialogRow
<AfcChangeSpoolDialogRow
:key="item.id"
:spool="item"
:max_id_digits="max_spool_id_digits"
@set-spool="setSpool" />
@set-spool="setSpool"
@open-spool-details="openSpoolDetails" />
</template>
</v-data-table>

Expand Down Expand Up @@ -132,11 +151,11 @@ import BaseMixin from '@/components/mixins/base'
import Panel from '@/components/ui/Panel.vue'
import { mdiCloseThick, mdiAdjust, mdiDatabase, mdiMagnify, mdiRefresh, mdiEject } from '@mdi/js'
import { ServerSpoolmanStateSpool } from '@/store/server/spoolman/types'
import SpoolmanChangeSpoolDialogRow from '@/components/dialogs/SpoolmanChangeSpoolDialogRow.vue'
import AfcChangeSpoolDialogRow from '@/components/dialogs/SpoolmanChangeSpoolDialogRow.vue'
import { Lane } from '@/store/server/afc/types'
@Component({
components: { SpoolmanChangeSpoolDialogRow, Panel },
components: { AfcChangeSpoolDialogRow, Panel },
})
export default class AfcChangeSpoolDialog extends Mixins(BaseMixin) {
@Prop({ type: Object, required: true }) laneData!: Lane
Expand Down Expand Up @@ -196,6 +215,12 @@ export default class AfcChangeSpoolDialog extends Mixins(BaseMixin) {
align: 'end',
value: 'remaining_weight',
},
{
text: this.$t('Panels.AfcPanel.SpoolInfo'),
align: 'center',
value: '',
sortable: false,
},
]
}
Expand All @@ -212,9 +237,9 @@ export default class AfcChangeSpoolDialog extends Mixins(BaseMixin) {
if (this.laneData != null) {
const cleanedColor = this.spoolColor.replace('#', '')
const setColor = `SET_COLOR LANE=${this.laneData.laneName} COLOR=${cleanedColor}`
const setWeight = `SET_WEIGHT LANE=${this.laneData.laneName} WEIGHT=${this.remainingWeight}`
const setMaterial = `SET_MATERIAL LANE=${this.laneData.laneName} MATERIAL=${this.filamentType}`
const setColor = `SET_COLOR LANE=${this.laneData.name} COLOR=${cleanedColor}`
const setWeight = `SET_WEIGHT LANE=${this.laneData.name} WEIGHT=${this.remainingWeight}`
const setMaterial = `SET_MATERIAL LANE=${this.laneData.name} MATERIAL=${this.filamentType}`
this.$nextTick(async () => {
try {
Expand All @@ -236,9 +261,9 @@ export default class AfcChangeSpoolDialog extends Mixins(BaseMixin) {
manualyClearSpool() {
if (this.laneData != null) {
const setColor = `SET_COLOR LANE=${this.laneData.laneName} COLOR=000000`
const setWeight = `SET_WEIGHT LANE=${this.laneData.laneName} WEIGHT=0`
const setMaterial = `SET_MATERIAL LANE=${this.laneData.laneName} MATERIAL=`
const setColor = `SET_COLOR LANE=${this.laneData.name} COLOR=000000`
const setWeight = `SET_WEIGHT LANE=${this.laneData.name} WEIGHT=0`
const setMaterial = `SET_MATERIAL LANE=${this.laneData.name} MATERIAL=`
this.$nextTick(async () => {
try {
Expand All @@ -260,6 +285,10 @@ export default class AfcChangeSpoolDialog extends Mixins(BaseMixin) {
window.open(this.spoolManagerUrl, '_blank')
}
openSpoolDetails(spoolId: string) {
window.open(this.spoolManagerUrl + '/spool/show/' + spoolId, '_blank')
}
mounted() {
this.refresh()
}
Expand All @@ -276,17 +305,15 @@ export default class AfcChangeSpoolDialog extends Mixins(BaseMixin) {
ejectSpool() {
if (this.laneData != null) {
const unloadLane = `LANE_UNLOAD LANE=${this.laneData.laneName}`
console.log('Dispatching G-code:', unloadLane)
const ejectSpoolman = `SET_SPOOL_ID LANE=${this.laneData.name} SPOOL_ID=`
this.$nextTick(async () => {
try {
this.$socket.emit(
'printer.gcode.script',
{ script: unloadLane },
{ loading: 'macro_' + unloadLane }
{ script: ejectSpoolman },
{ loading: 'macro_' + ejectSpoolman }
)
console.log('UNLOAD_LANE sent successfully')
} catch (error) {
console.error('Failed to send G-code:', error)
}
Expand Down Expand Up @@ -333,7 +360,7 @@ export default class AfcChangeSpoolDialog extends Mixins(BaseMixin) {
setSpool(spool: any) {
console.log('Spool set as:', spool)
console.log('Lane data received:', this.laneData)
const gcode = `SET_SPOOL_ID LANE=${this.laneData.laneName} SPOOL_ID=${spool.id}`
const gcode = `SET_SPOOL_ID LANE=${this.laneData.name} SPOOL_ID=${spool.id}`
console.log('Dispatching G-code:', gcode)
this.$nextTick(async () => {
Expand Down
163 changes: 163 additions & 0 deletions src/components/dialogs/AfcChangeSpoolDialogRow.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
<template>
<tr class="cursor-pointer" @click="setSpoolRow">
<td style="width: 50px" class="pr-0 py-2">
<spool-icon :color="color" style="width: 50px; float: left" class="mr-3" />
</td>

<td class="py-2" style="min-width: 300px">
<v-list-item two-line>
<v-list-item-content class="no--padding">
<div class="text--disabled mb-1">#{{ id }} | {{ vendor }}</div>
<v-list-item-title class="mb-1">
<span class="text--filament">{{ name }}</span>
<template v-if="location">
<br />
<small>{{ $t('Panels.SpoolmanPanel.Location') }}: {{ location }}</small>
</template>
<template v-if="spool.comment">
<br />
<small class="comment">{{ spool.comment }}</small>
</template>
</v-list-item-title>
</v-list-item-content>
</v-list-item>
</td>
<td class="text-center text-no-wrap">{{ material }}</td>
<td class="text-right text-no-wrap">{{ last_used }}</td>
<td class="text-right text-no-wrap">
<strong>{{ remaining_weight_format }}</strong>
<small class="ml-1">/ {{ total_weight_format }}</small>
</td>
<td class="text-right text-no-wrap">
<v-tooltip top>
<template #activator="{ on: onTooltip, attrs }">
<td
style="width: 50px"
class="pr-0 py-2"
v-bind="attrs"
@click.stop="openSpoolDetails"
v-on="onTooltip">
<v-btn icon @click.stop="openSpoolDetails">
<v-icon>{{ mdiDatabase }}</v-icon>
</v-btn>
</td>
</template>
<span>{{ $t('Panels.AfcPanel.OpenSpoolInfo') }}</span>
</v-tooltip>
</td>
</tr>
</template>

<script lang="ts">
import Component from 'vue-class-component'
import { Mixins, Prop } from 'vue-property-decorator'
import BaseMixin from '@/components/mixins/base'
import { mdiDatabase } from '@mdi/js'
import { ServerSpoolmanStateSpool } from '@/store/server/spoolman/types'
@Component({})
export default class AfcChangeSpoolDialogRow extends Mixins(BaseMixin) {
@Prop({ required: true }) declare readonly spool: ServerSpoolmanStateSpool
@Prop({ required: false }) declare readonly max_id_digits: number
mdiDatabase = mdiDatabase
get color() {
const color = this.spool.filament?.color_hex ?? '000'
return `#${color}`
}
get id() {
// add leading zeros depending on max_id digit count
let id: string = this.spool.id.toString()
while (id.length < this.max_id_digits) {
id = '0' + id
}
return id
}
get vendor() {
return this.spool.filament?.vendor?.name ?? 'Unknown'
}
get name() {
return this.spool.filament?.name ?? 'Unknown'
}
get location() {
return this.spool.location
}
get material() {
return this.spool.filament?.material ?? '--'
}
get remaining_weight() {
return this.spool.remaining_weight ?? 0
}
get total_weight() {
return this.spool.filament?.weight ?? 0
}
get remaining_weight_format() {
return `${this.remaining_weight.toFixed(0)}g`
}
get total_weight_format() {
if (this.total_weight < 1000) {
return `${this.total_weight.toFixed(0)}g`
}
let totalRound = Math.round(this.total_weight / 1000)
if (totalRound !== this.total_weight / 1000) {
totalRound = Math.round(this.total_weight / 100) / 10
}
return `${totalRound}kg`
}
get last_used() {
const last_used = this.spool.last_used ?? null
if (!last_used) return this.$t('Panels.SpoolmanPanel.Never')
const date = new Date(this.spool.last_used)
const now = new Date()
const diff = now.getTime() - date.getTime()
if (diff <= 1000 * 60 * 60 * 24) return this.$t('Panels.SpoolmanPanel.Today')
if (diff <= 1000 * 60 * 60 * 24 * 2) return this.$t('Panels.SpoolmanPanel.Yesterday')
if (diff <= 1000 * 60 * 60 * 24 * 14) {
const days = Math.floor(diff / (1000 * 60 * 60 * 24))
return this.$t('Panels.SpoolmanPanel.DaysAgo', { days })
}
return date.toLocaleDateString()
}
setSpoolRow() {
this.$emit('set-spool', this.spool)
}
openSpoolDetails() {
this.$emit('open-spool-details', this.spool.id)
}
}
</script>
<style scoped>
.text--filament {
font-size: 1.1rem;
}
.no--padding {
padding: 0;
}
.comment {
white-space: pre-wrap;
overflow-wrap: anywhere;
}
</style>
7 changes: 3 additions & 4 deletions src/components/panels/Afc/AfcExtruderTools.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<template>
<div class="tool-container">
<afc-extruder-tools-item
v-for="(tool, toolName) in tools"
:key="toolName"
v-for="tool in tools"
:key="tool.name"
:tool="tool"
:tool-name="toolName"
class="tool-card rounded-lg shadow-md" />
</div>
</template>
Expand All @@ -20,7 +19,7 @@ import { Extruder } from '@/store/server/afc/types'
components: { AfcExtruderToolsItem },
})
export default class AfcExtruderTools extends Mixins(BaseMixin) {
@Prop({ type: Object, required: true }) readonly tools!: Extruder[]
@Prop({ type: Array, required: true }) readonly tools!: Extruder[]
}
</script>

Expand Down
Loading

0 comments on commit eef8d94

Please sign in to comment.