Merge "Remove the truncate function from horizon.quota.js"

This commit is contained in:
Jenkins 2016-01-29 08:04:27 +00:00 committed by Gerrit Code Review
commit 597dbcecc4
4 changed files with 11 additions and 44 deletions

View File

@ -239,7 +239,6 @@ horizon.Quota = {
this.getSelectedFlavor(); this.getSelectedFlavor();
if (this.selected_flavor) { if (this.selected_flavor) {
var name = horizon.Quota.truncate(this.selected_flavor.name, 14, true);
var vcpus = horizon.Quota.humanizeNumbers(this.selected_flavor.vcpus); var vcpus = horizon.Quota.humanizeNumbers(this.selected_flavor.vcpus);
var disk = horizon.Quota.humanizeNumbers(this.selected_flavor.disk); var disk = horizon.Quota.humanizeNumbers(this.selected_flavor.disk);
var ephemeral = horizon.Quota.humanizeNumbers(this.selected_flavor["OS-FLV-EXT-DATA:ephemeral"]); var ephemeral = horizon.Quota.humanizeNumbers(this.selected_flavor["OS-FLV-EXT-DATA:ephemeral"]);
@ -247,7 +246,7 @@ horizon.Quota = {
var disk_total_display = horizon.Quota.humanizeNumbers(disk_total); var disk_total_display = horizon.Quota.humanizeNumbers(disk_total);
var ram = horizon.Quota.humanizeNumbers(this.selected_flavor.ram); var ram = horizon.Quota.humanizeNumbers(this.selected_flavor.ram);
$("#flavor_name").html(name); $("#flavor_name").text(this.selected_flavor.name);
$("#flavor_vcpus").text(vcpus); $("#flavor_vcpus").text(vcpus);
$("#flavor_disk").text(disk); $("#flavor_disk").text(disk);
$("#flavor_ephemeral").text(ephemeral); $("#flavor_ephemeral").text(ephemeral);
@ -264,27 +263,6 @@ horizon.Quota = {
} }
}, },
/*
* Truncate a string at the desired length. Optionally append an ellipsis
* to the end of the string.
*
* Example:
* horizon.Quota.truncate("String that is too long.", 18, true); ->
* "String that is too…"
*
*/
truncate: function (string, size, includeEllipsis) {
if (string.length > size) {
if (includeEllipsis) {
return string.substring(0, (size - 3)) + '…';
}
return string.substring(0, size);
}
return string;
},
/* /*
* Adds commas to any integer or numbers within a string for human display. * Adds commas to any integer or numbers within a string for human display.
* *

View File

@ -20,22 +20,4 @@ describe("Quotas (horizon.quota.js)", function() {
}); });
describe("truncate", function() {
var string = 'This will be cut';
var ellipsis = '…';
it('should truncate a string at a given length', function () {
expect(horizon.Quota.truncate(string, 15)).toEqual(string.slice(0, 15));
expect(horizon.Quota.truncate(string, 20)).toEqual(string);
});
it('should add an ellipsis if needed ', function () {
expect(horizon.Quota.truncate(string, 15, true)).toEqual(string.slice(0, 12) + ellipsis);
expect(horizon.Quota.truncate(string, 20, true)).toEqual(string);
expect(horizon.Quota.truncate(string, 2, true)).toEqual(ellipsis);
});
});
}); });

View File

@ -4,9 +4,9 @@
{% endblock %} {% endblock %}
<h4>{% trans "Flavor Details" %}</h4> <h4>{% trans "Flavor Details" %}</h4>
<table class="flavor_table table table-striped"> <table class="flavor_table table table-striped table-fixed">
<tbody> <tbody>
<tr><td class="flavor_name">{% trans "Name" %}</td><td><span id="flavor_name"></span></td></tr> <tr><td class="flavor_name">{% trans "Name" %}</td><td><span id="flavor_name" class="truncate"></span></td></tr>
<tr><td class="flavor_name">{% trans "VCPUs" %}</td><td><span id="flavor_vcpus"></span></td></tr> <tr><td class="flavor_name">{% trans "VCPUs" %}</td><td><span id="flavor_vcpus"></span></td></tr>
<tr><td class="flavor_name">{% trans "Root Disk" %}</td><td><span id="flavor_disk"></span> {% trans "GB" %}</td></tr> <tr><td class="flavor_name">{% trans "Root Disk" %}</td><td><span id="flavor_disk"></span> {% trans "GB" %}</td></tr>
<tr><td class="flavor_name">{% trans "Ephemeral Disk" %}</td><td><span id="flavor_ephemeral"></span> {% trans "GB" %}</td></tr> <tr><td class="flavor_name">{% trans "Ephemeral Disk" %}</td><td><span id="flavor_ephemeral"></span> {% trans "GB" %}</td></tr>

View File

@ -51,3 +51,10 @@ input::-ms-clear, input::-ms-reveal {
width: 100%; width: 100%;
word-wrap: break-word; word-wrap: break-word;
} }
.truncate {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
display: block;
}