Skip to content

Commit

Permalink
Refactor graph component to break less
Browse files Browse the repository at this point in the history
Switching from assuming true to assuming false, ensures we don't throw erros running calculations on values that don't exist
  • Loading branch information
AllenBW committed Nov 14, 2017
1 parent f26f719 commit 4fc9a01
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions client/app/services/usage-graphs/usage-graphs.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,30 @@ export const UsageGraphsComponent = {
/** @ngInject */
function ComponentController () {
const vm = this
vm.$onChanges = activate

function activate () {
vm.$onChanges = () => {
angular.extend(vm, {
cpuChart: vm.cpuChart || {data: {total: 0}},
memoryChart: vm.memoryChart || {data: {total: 0}},
storageChart: vm.storageChart || {data: {total: 0}},
cpuDataExists: true,
memoryDataExists: true,
storageDataExists: true,
emptyState: {icon: 'pficon pficon-help', title: 'No Information Available'}

cpuDataExists: false,
memoryDataExists: false,
storageDataExists: false,
emptyState: {icon: 'pficon pficon-help', title: __('No Information Available')}
})

if (vm.cpuChart.data.total === 0) {
vm.cpuDataExists = false
if (vm.cpuChart.data.total > 0) {
vm.cpuDataExists = true
vm.availableCPU = vm.cpuChart.data.total - vm.cpuChart.data.used
}
if (vm.memoryChart.data.total === 0) {
vm.memoryDataExists = false

if (vm.memoryChart.data.total > 0) {
vm.memoryDataExists = true
vm.availableMemory = vm.memoryChart.data.total - vm.memoryChart.data.used
}
if (vm.storageChart.data.total === 0) {
vm.storageDataExists = false

if (vm.storageChart.data.total > 0) {
vm.storageDataExists = true
vm.availableStorage = vm.storageChart.data.total - vm.storageChart.data.used
}
vm.availableCPU = vm.cpuChart.data.total - vm.cpuChart.data.used
vm.availableMemory = vm.memoryChart.data.total - vm.memoryChart.data.used
vm.availableStorage = vm.storageChart.data.total - vm.storageChart.data.used
}
}

0 comments on commit 4fc9a01

Please sign in to comment.