Skip to content

Commit

Permalink
refactor: simplify some code parts
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Dej <[email protected]>
  • Loading branch information
meteyou committed Dec 31, 2024
1 parent 4430b85 commit 8db8de9
Showing 1 changed file with 9 additions and 29 deletions.
38 changes: 9 additions & 29 deletions src/components/panels/Machine/UpdatePanel/Entry.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
{{ versionOutput }}
</a>
</template>
<template v-else-if="type === 'web' && webUpdatable">
<template v-else-if="type === 'web' && semverUpdatable">
<a class="info--text text-decoration-none" :href="webLinkRelease" target="_blank">
<v-icon small color="info" class="mr-1">{{ mdiUpdate }}</v-icon>
{{ versionOutput }}
</a>
</template>
<template v-else-if="type === 'python' && pythonUpdateable">
<template v-else-if="type === 'python' && semverUpdatable">
<a class="info--text text-decoration-none" :href="pythonChangelog" target="_blank">
<v-icon small color="info" class="mr-1">{{ mdiUpdate }}</v-icon>
{{ versionOutput }}
Expand Down Expand Up @@ -275,22 +275,16 @@ export default class UpdatePanelEntry extends Mixins(BaseMixin) {
if (['printing', 'paused'].includes(this.printer_state)) return true
if (!this.isValid || this.isCorrupt || this.isDirty || this.commitsBehind.length) return false
if (this.type === 'web') return !this.webUpdatable
if (this.type === 'python') return !this.pythonUpdateable
if (['python', 'web'].includes(this.type)) return !this.semverUpdatable
return this.commitsBehind.length === 0
}
get btnIcon() {
if (this.isDetached || !this.isValid || this.isCorrupt || this.isDirty) return mdiCloseCircle
if (this.type === 'web') {
if (this.webUpdatable) return mdiProgressUpload
else if (this.localVersion === null || this.remoteVersion === null) return mdiHelpCircleOutline
}
if (this.type === 'python') {
if (this.pythonUpdateable) return mdiProgressUpload
if (['python', 'web'].includes(this.type)) {
if (this.semverUpdatable) return mdiProgressUpload
else if (this.localVersion === null || this.remoteVersion === null) return mdiHelpCircleOutline
}
Expand All @@ -302,8 +296,7 @@ export default class UpdatePanelEntry extends Mixins(BaseMixin) {
get btnColor() {
if (this.isCorrupt || this.isDetached || this.isDirty || !this.isValid) return 'orange'
if (this.type === 'web' && this.webUpdatable) return 'primary'
if (this.type === 'python' && this.pythonUpdateable) return 'primary'
if (['python', 'web'].includes(this.type) && this.semverUpdatable) return 'primary'
if (this.type === 'git_repo' && this.commitsBehind.length) return 'primary'
return 'green'
Expand All @@ -315,14 +308,8 @@ export default class UpdatePanelEntry extends Mixins(BaseMixin) {
if (this.isDirty) return this.$t('Machine.UpdatePanel.Dirty')
if (!this.isValid) return this.$t('Machine.UpdatePanel.Invalid')
if (this.type === 'web') {
if (this.webUpdatable) return this.$t('Machine.UpdatePanel.Update')
else if (this.localVersion === null || this.remoteVersion === null)
return this.$t('Machine.UpdatePanel.Unknown')
}
if (this.type === 'python') {
if (this.pythonUpdateable) return this.$t('Machine.UpdatePanel.Update')
if (['python', 'web'].includes(this.type)) {
if (this.semverUpdatable) return this.$t('Machine.UpdatePanel.Update')
else if (this.localVersion === null || this.remoteVersion === null)
return this.$t('Machine.UpdatePanel.Unknown')
}
Expand All @@ -340,14 +327,7 @@ export default class UpdatePanelEntry extends Mixins(BaseMixin) {
return this.repo.warnings ?? []
}
get webUpdatable() {
if (!this.localVersion) return false
if (!this.remoteVersion) return false
return semver.gt(this.remoteVersion, this.localVersion)
}
get pythonUpdateable() {
get semverUpdatable() {
if (!this.localVersion) return false
if (!this.remoteVersion) return false
Expand Down

0 comments on commit 8db8de9

Please sign in to comment.