Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1019250: Showing/fixing system info #3241

Merged
merged 1 commit into from Oct 23, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/models/system.rb
Expand Up @@ -193,7 +193,7 @@ def as_json(options)
end

def type
if respond_to?(:guest) && guest == 'true'
if respond_to?(:guest) && guest
_("Guest")
else
case self
Expand Down
Expand Up @@ -206,5 +206,64 @@ angular.module('Bastion.systems').controller('SystemDetailsInfoController',
Object.keys($scope.advancedInfoRight).length > 0;

}

$scope.memory = function(facts) {
var mem;
if (facts !== undefined) {
if (facts.memory !== undefined) {
mem = facts.memory["memtotal"];
}
if (mem === undefined && facts.dmi !== undefined &&
facts.dmi.memory !== undefined) {
mem = facts.dmi.memory["size"];
}
return memoryInGigabytes(mem);
} else {
return "0";
}
};

function memoryInGigabytes(memStr) {
var mems,
memory,
unit;

if (memStr === undefined || memStr === "") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space after if

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bah you updated before my comment posted.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

smile

return "0";
}

mems = memStr.split(/\s+/);
memory = parseFloat(mems[0]);
unit = mems[1];

switch(unit) {
case 'B':
memory = 0;
break;

case 'kB':
memory = 0;
break;

case 'MB':
memory /= 1024;
break;

case 'GB':
break;

case 'TB':
memory *= 1024;
break;

default:
// by default memory is in kB
memory /= (1024 * 1024);
break;
}

memory = Math.round(memory * 100) / 100;
return memory;
}
}]
);
Expand Up @@ -138,12 +138,12 @@ <h4>{{ "System Properties" | i18n }}</h4>

<div class="detail">
<span class="info-label">{{ "OS" | i18n }} </span>
<span class="info-value">{{ system.distribution_name }}</span>
<span class="info-value">{{ systemFacts.distribution["name"] }}</span>
</div>

<div class="detail">
<span class="info-label">{{ "Release" | i18n }}</span>
<span class="info-value">{{ system.kernel }}</span>
<span class="info-value">{{ systemFacts.uname["release"] }}</span>
</div>

<div class="detail">
Expand All @@ -157,7 +157,7 @@ <h4>{{ "System Properties" | i18n }}</h4>

<div class="detail">
<span class="info-label">{{ "Arch" | i18n }}</span>
<span class="info-value">{{ system.arch }}</span>
<span class="info-value">{{ systemFacts.uname["machine"] }}</span>
</div>

<div class="detail">
Expand All @@ -176,8 +176,8 @@ <h4>{{ "System Properties" | i18n }}</h4>
</div>

<div class="detail">
<span class="info-label">{{ "RAM" | i18n }}</span>
<span class="info-value">{{ system.memory }}</span>
<span class="info-label">{{ "RAM (GB)" | i18n }}</span>
<span class="info-value">{{ memory(systemFacts) }}</span>
</div>

<div class="divider"></div>
Expand Down
Expand Up @@ -110,6 +110,13 @@ describe('Controller: SystemDetailsInfoController', function() {
expect($scope.editContentView).toBe(false);
});

it("pulls and converts memory from system facts.", function() {
var facts = {memory: {memtotal: "6857687"}, dmi: {memory: {size: "1 TB"}}};
expect($scope.memory(facts)).toEqual(6.54);
facts = {dmi: {memory: {size: "1 TB"}}};
expect($scope.memory(facts)).toEqual(1024);
});

describe("populates advanced system information", function () {
it("creates the system facts object by converting dot notation response to an object.", function() {
expect(typeof $scope.systemFacts).toBe("object");
Expand Down