Skip to content

Commit

Permalink
feat(controller): added additional unit version and update info
Browse files Browse the repository at this point in the history
Added next available version and if update is scheduled for the unit.
  • Loading branch information
Tbaile committed Sep 27, 2024
1 parent 09918e4 commit d3c0530
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 3 deletions.
6 changes: 5 additions & 1 deletion public/i18n/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -2128,7 +2128,11 @@
"cannot_open_unit_description": "The unit {name} must be updated before opening it. Access the unit UI directly and go to System > Updates page.",
"open_anyway": "Open anyway",
"warning_open_unit": "Controller is not up-to-date",
"warning_open_unit_description": "It appears that the controller is not up-to-date. It's recommended to update the controller instance on your NethServer 8 cluster before opening this unit to avoid compatibility issues."
"warning_open_unit_description": "It appears that the controller is not up-to-date. It's recommended to update the controller instance on your NethServer 8 cluster before opening this unit to avoid compatibility issues.",
"scheduled_update": "Update scheduled",
"scheduled_update_tooltip": "The unit has been scheduled for an update on the {date}.",
"update_available": "Update available",
"update_available_tooltip": "{version} is available for download."
},
"unit_terminal": {
"name_unit_terminal": "{name} unit terminal",
Expand Down
49 changes: 47 additions & 2 deletions src/components/controller/units/UnitsTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
NeTableHeadCell,
NeTableRow,
NeTooltip,
NeBadge,
savePreference,
useItemPagination
} from '@nethesis/vue-components'
Expand All @@ -34,6 +35,8 @@ import { onMounted, type PropType, ref } from 'vue'
import { useLoginStore } from '@/stores/controller/controllerLogin'
import RemoveUnitModal from '@/components/controller/units/RemoveUnitModal.vue'
import { coerce, outside, satisfies } from 'semver'
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'
import { faClock, faWarning } from '@fortawesome/free-solid-svg-icons'

const props = defineProps({
filteredUnits: {
Expand Down Expand Up @@ -400,9 +403,51 @@ function showRemoveUnitModal(unit: Unit) {
</NeTableCell>
<!-- installed version -->
<NeTableCell :data-label="t('controller.units.installed_version')">
<template v-if="item.info.version">
<span v-if="item.info.version" class="flex flex-wrap items-center gap-2">
<span>{{ item.info.version }}</span>
</template>
<template v-if="item.info.scheduled_update > 0">
<NeTooltip>
<template #trigger>
<NeBadge
:icon="faClock"
:text="t('controller.units.scheduled_update')"
clickable
kind="info"
/>
</template>
<template #content>
<div>
{{
t('controller.units.scheduled_update_tooltip', {
date: new Date(item.info.scheduled_update * 1000).toLocaleString()
})
}}
</div>
</template>
</NeTooltip>
</template>
<template v-else-if="item.info.version_update">
<NeTooltip>
<template #trigger>
<NeBadge
:icon="faWarning"
:text="t('controller.units.update_available')"
clickable
kind="warning"
/>
</template>
<template #content>
<div>
{{
t('controller.units.update_available_tooltip', {
version: item.info.version_update
})
}}
</div>
</template>
</NeTooltip>
</template>
</span>
<template v-else-if="item.connected">
<div class="space-x-2">
<span>{{ t('controller.units.syncing_data') }}</span>
Expand Down
92 changes: 92 additions & 0 deletions src/composables/useUpdates.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import type { Unit } from '@/stores/controller/units'
import { ubusCall, ubusCallFromController } from '@/lib/standalone/ubus'
import type { AxiosResponse } from 'axios'

type SuccessfulResponse = AxiosResponse<{
message: string
}>

type UpdateResponse = AxiosResponse<{
updates: {
currentVersion: string
latestVersion: string
package: string
}[]
}>

type CheckSystemUpdateResponse = AxiosResponse<{
currentVersion: string
lastVersion: string
scheduleAt: number
}>

/**
* Composable that provides update for units.
*/
export function useUpdates() {
/**
* Update the package index
*/
function updatePackageIndex(unit?: Unit): Promise<UpdateResponse> {
if (unit) {
return ubusCallFromController('ns.update', 'check-package-updates', {}, unit.id)
}
return ubusCall('ns.update', 'check-package-updates', {})
}

/**
* Upgrade all packages
*/
function upgradePackages(unit?: Unit): Promise<SuccessfulResponse> {
if (unit) {
return ubusCallFromController('ns.update', 'install-package-updates', {}, unit.id)
}
return ubusCall('ns.update', 'install-package-updates')
}

/**
* Check for image system update
*/
function updateUnitImage(unit?: Unit): Promise<CheckSystemUpdateResponse> {
if (unit) {
return ubusCallFromController('ns.update', 'check-system-update', {}, unit.id)
}
return ubusCall('ns.update', 'check-system-update')
}

/**
* Upgrade the system
*/
function upgradeUnitImage(unit?: Unit): Promise<SuccessfulResponse> {
if (unit) {
return ubusCallFromController('ns.update', 'update-system', {}, unit.id)
} else {
return ubusCall('ns.update', 'update-system')
}
}

/**
* Schedule a system upgrade
*/
function scheduleUpgradeUnitImage(scheduleAt: Date, unit?: Unit): Promise<SuccessfulResponse> {
const scheduleAtTimestamp = Math.floor(scheduleAt.getTime() / 1000)
if (unit) {
return ubusCallFromController(
'ns.update',
'schedule-system-update',
{ scheduleAt: scheduleAtTimestamp },
unit.id
)
} else {
return ubusCall('ns.update', 'schedule-system-update', { scheduleAt: scheduleAtTimestamp })
}
}

return {
updatePackageIndex,
upgradePackages,
updateUnitImage,
upgradeUnitImage,
scheduleUpgradeUnitImage
}
}
2 changes: 2 additions & 0 deletions src/stores/controller/units.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ interface UnitInfo {
unit_name: string
version: string
api_version: string
version_update: string
scheduled_update: number
}

interface UnitVpnData {
Expand Down

0 comments on commit d3c0530

Please sign in to comment.