Skip to content

Commit

Permalink
feat(controller): added updating image badge during image upgrade (#398)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tbaile authored Oct 10, 2024
1 parent 6401c2c commit 05bb433
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 5 deletions.
4 changes: 3 additions & 1 deletion public/i18n/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -2208,7 +2208,9 @@
"batch_update_system": "You are about to update the system for multiple units. The units that are available for an update are shown inside the combobox below.",
"batch_updated_systems": "System update sent to the unit | System update sent to {n} units",
"error_batch_updating_systems": "Some systems failed to update.",
"error_batch_updating_systems_description": "Some units failed to get the update from the controller. Please check below the ones that failed and try again."
"error_batch_updating_systems_description": "Some units failed to get the update from the controller. Please check below the ones that failed and try again.",
"updating_image": "Update in progress",
"updating_image_description": "The unit is updating the image. The unit may be not available for a few minutes while the update is being installed."
},
"unit_terminal": {
"name_unit_terminal": "{name} unit terminal",
Expand Down
4 changes: 3 additions & 1 deletion src/components/controller/units/BatchUnitImageUpdate.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ function updateUnits() {
Promise.allSettled(
selectedUnits.value.map((unit) => {
if (updateMode.value === 'now') {
return upgradeUnitImage(unit)
return upgradeUnitImage(unit).then(() => {
unitsStore.addUnitUpgradingImage(unit.id)
})
} else {
return scheduleUpgradeUnitImage(scheduledUpdate.value, unit)
}
Expand Down
1 change: 1 addition & 0 deletions src/components/controller/units/ScheduleUpdateDrawer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ async function updateUnit() {
sendingError.value = undefined
if (updateMode.value == 'now') {
await upgradeUnitImage(_unit.value)
unitsStore.addUnitUpgradingImage(_unit.value!.id)
} else {
await scheduleUpgradeUnitImage(scheduledUpdate.value, _unit.value)
}
Expand Down
22 changes: 20 additions & 2 deletions src/components/controller/units/UnitsTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
faCalendarXmark,
faClock,
faCloudArrowUp,
faSync,
faWarning
} from '@fortawesome/free-solid-svg-icons'
import { library } from '@fortawesome/fontawesome-svg-core'
Expand Down Expand Up @@ -169,7 +170,7 @@ function getKebabMenuItems(unit: Unit) {
icon: unit.info.scheduled_update > 0 ? 'pen-to-square' : 'circle-arrow-up',
iconStyle: 'fas',
action: () => emit('scheduleUpdate', unit),
disabled: !unit.connected
disabled: !unit.connected || unitsStore.unitUpgradingImage.find((id) => id == unit.id)
})
}
if (unit.info.scheduled_update > 0) {
Expand Down Expand Up @@ -453,7 +454,24 @@ function showRemoveUnitModal(unit: Unit) {
<span v-if="item.info.version" class="flex flex-wrap items-center gap-2">
<span>{{ item.info.version }}</span>
<template v-if="item.connected">
<template v-if="item.info.scheduled_update > 0">
<template v-if="unitsStore.unitUpgradingImage.find((id) => id == item.id)">
<NeTooltip>
<template #trigger>
<NeBadge
:icon="faSync"
:text="t('controller.units.updating_image')"
clickable
kind="info"
/>
</template>
<template #content>
<div>
{{ t('controller.units.updating_image_description') }}
</div>
</template>
</NeTooltip>
</template>
<template v-else-if="item.info.scheduled_update > 0">
<NeTooltip>
<template #trigger>
<NeBadge
Expand Down
17 changes: 16 additions & 1 deletion src/stores/controller/units.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export const useUnitsStore = defineStore('units', () => {
const errorListUnits = ref('')
const errorListUnitsDetails = ref('')
const unitUpdatingPackages = ref<string[]>([])
const unitUpgradingImage = ref<string[]>([])

const getUnits = async () => {
loadingListUnits.value = true
Expand All @@ -78,6 +79,11 @@ export const useUnitsStore = defineStore('units', () => {
unit.connected = !isEmpty(unit.vpn)
}

// if version_update is empty, remove the unit from the unitUpgradingImage list
unitUpgradingImage.value = unitUpgradingImage.value.filter((unit) => {
return unitsList.find((u) => u.id === unit)?.info.version_update !== ''
})

units.value = unitsList.sort(sortUnits)
} catch (err: any) {
console.error(err)
Expand Down Expand Up @@ -220,6 +226,13 @@ export const useUnitsStore = defineStore('units', () => {
}, 10000)
}

function addUnitUpgradingImage(unitId: string) {
unitUpgradingImage.value.push(unitId)
setTimeout(() => {
unitUpgradingImage.value = unitUpgradingImage.value.filter((unit) => unit !== unitId)
}, 60000)
}

return {
units,
getUnits,
Expand All @@ -234,6 +247,8 @@ export const useUnitsStore = defineStore('units', () => {
errorListUnitsDetails,
getUnitInfo,
unitUpdatingPackages,
addUnitUpdating
addUnitUpdating,
unitUpgradingImage,
addUnitUpgradingImage
}
})

0 comments on commit 05bb433

Please sign in to comment.