From cd4942c640b39f41b97d235699ba8497335fc80c Mon Sep 17 00:00:00 2001 From: Rajat Vig Date: Wed, 2 Sep 2015 11:33:42 -0700 Subject: [PATCH] Remove the truncate function from horizon.quota.js The function is replaced by using CSS rules This was inspired off comments in https://review.openstack.org/#/c/207549 Change-Id: Id433b3988ea1007cba942f1e5d200d5e6972edf2 Co-Authored-By: Kyle Olivo Co-Authored-By: Diana Whitten Closes-Bug: #1480106 --- horizon/static/horizon/js/horizon.quota.js | 24 +------------------ .../tests/jasmine/quota.legacy-spec.js | 18 -------------- .../instances/_flavors_and_quotas.html | 4 ++-- .../static/dashboard/scss/_util.scss | 9 ++++++- 4 files changed, 11 insertions(+), 44 deletions(-) diff --git a/horizon/static/horizon/js/horizon.quota.js b/horizon/static/horizon/js/horizon.quota.js index bf5b03a1e..2bd630210 100644 --- a/horizon/static/horizon/js/horizon.quota.js +++ b/horizon/static/horizon/js/horizon.quota.js @@ -239,7 +239,6 @@ horizon.Quota = { this.getSelectedFlavor(); 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 disk = horizon.Quota.humanizeNumbers(this.selected_flavor.disk); 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 ram = horizon.Quota.humanizeNumbers(this.selected_flavor.ram); - $("#flavor_name").html(name); + $("#flavor_name").text(this.selected_flavor.name); $("#flavor_vcpus").text(vcpus); $("#flavor_disk").text(disk); $("#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. * diff --git a/horizon/static/horizon/tests/jasmine/quota.legacy-spec.js b/horizon/static/horizon/tests/jasmine/quota.legacy-spec.js index f07b3cc05..9ec7bc7be 100644 --- a/horizon/static/horizon/tests/jasmine/quota.legacy-spec.js +++ b/horizon/static/horizon/tests/jasmine/quota.legacy-spec.js @@ -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); - }); - }); - }); diff --git a/openstack_dashboard/dashboards/project/instances/templates/instances/_flavors_and_quotas.html b/openstack_dashboard/dashboards/project/instances/templates/instances/_flavors_and_quotas.html index ca3e42ba9..53ecb6e3c 100644 --- a/openstack_dashboard/dashboards/project/instances/templates/instances/_flavors_and_quotas.html +++ b/openstack_dashboard/dashboards/project/instances/templates/instances/_flavors_and_quotas.html @@ -4,9 +4,9 @@ {% endblock %}

{% trans "Flavor Details" %}

- +
- + diff --git a/openstack_dashboard/static/dashboard/scss/_util.scss b/openstack_dashboard/static/dashboard/scss/_util.scss index c8233a053..1e1813a7a 100644 --- a/openstack_dashboard/static/dashboard/scss/_util.scss +++ b/openstack_dashboard/static/dashboard/scss/_util.scss @@ -21,4 +21,11 @@ .word-wrap { width: 100%; word-wrap: break-word; -} \ No newline at end of file +} + +.truncate { + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + display: block; +}
{% trans "Name" %}
{% trans "Name" %}
{% trans "VCPUs" %}
{% trans "Root Disk" %} {% trans "GB" %}
{% trans "Ephemeral Disk" %} {% trans "GB" %}