diff --git a/ui/app/controllers/topology.js b/ui/app/controllers/topology.js index 193685727fe5..0e8759c5d7b0 100644 --- a/ui/app/controllers/topology.js +++ b/ui/app/controllers/topology.js @@ -4,9 +4,12 @@ import { alias } from '@ember/object/computed'; import { inject as service } from '@ember/service'; import { tracked } from '@glimmer/tracking'; import classic from 'ember-classic-decorator'; -import { reduceBytes } from 'nomad-ui/utils/units'; +import { reduceBytes, reduceHertz } from 'nomad-ui/utils/units'; const sumAggregator = (sum, value) => sum + (value || 0); +const formatter = new Intl.NumberFormat(window.navigator.locale || 'en', { + maximumFractionDigits: 2, +}); @classic export default class TopologyControllers extends Controller { @@ -39,7 +42,7 @@ export default class TopologyControllers extends Controller { @computed('totalMemory') get totalMemoryFormatted() { - return reduceBytes(this.totalMemory)[0].toFixed(2); + return formatter.format(reduceBytes(this.totalMemory)[0]); } @computed('totalMemory') @@ -47,6 +50,17 @@ export default class TopologyControllers extends Controller { return reduceBytes(this.totalMemory)[1]; } + @computed('totalCPU') + get totalCPUFormatted() { + console.log('wat?', this.totalCPU); + return formatter.format(reduceHertz(this.totalCPU, null, 'MHz')[0]); + } + + @computed('totalCPU') + get totalCPUUnits() { + return reduceHertz(this.totalCPU, null, 'MHz')[1]; + } + @computed('scheduledAllocations.@each.allocatedResources') get totalReservedMemory() { const mibs = this.scheduledAllocations diff --git a/ui/app/templates/topology.hbs b/ui/app/templates/topology.hbs index ba4044b1bae5..59f509a4c075 100644 --- a/ui/app/templates/topology.hbs +++ b/ui/app/templates/topology.hbs @@ -205,7 +205,7 @@
-

{{this.totalCPU}} MHz of CPU

+

{{this.totalCPUFormatted}} {{this.totalCPUUnits}} of CPU

diff --git a/ui/app/utils/units.js b/ui/app/utils/units.js index a4cb24a88498..d5c6284fc19e 100644 --- a/ui/app/utils/units.js +++ b/ui/app/utils/units.js @@ -39,7 +39,7 @@ export function reduceBytes(bytes = 0, maxUnitSize, startingUnitSize) { return unitReducer(bytes, 1024, BYTES_UNITS, maxUnitSize, startingUnitSize); } -export function reduceHertz(hertz, maxUnitSize, startingUnitSize) { +export function reduceHertz(hertz = 0, maxUnitSize, startingUnitSize) { return unitReducer(hertz, 1000, HERTZ_UNITS, maxUnitSize, startingUnitSize); }