Merge "Translate angular html with '-'."

This commit is contained in:
Jenkins 2015-09-18 19:56:52 +00:00 committed by Gerrit Code Review
commit 908a2a3bc1
5 changed files with 56 additions and 13 deletions

View File

@ -23,6 +23,7 @@
.filter('mb', mbFilter)
.filter('title', titleFilter)
.filter('noUnderscore', noUnderscoreFilter)
.filter('noValue', noValueFilter)
.filter('decode', decodeFilter)
.filter('bytes', bytesFilter)
.filter('itemCount', itemCountFilter);
@ -107,6 +108,23 @@
};
}
/**
* @ngdoc filter
* @name noValue
* @description
* Replaces null / undefined / empty string with translated '-'.
*/
function noValueFilter() {
return function (input) {
if (input === null || angular.isUndefined(input) ||
(angular.isString(input) && '' == input.trim())) {
return gettext('-');
} else {
return input;
}
};
}
/**
* @ngdoc filter
* @name decode
@ -161,7 +179,7 @@
*/
function itemCountFilter() {
function ensureNonNegative (input) {
function ensureNonNegative(input) {
var isNumeric = (input !== null && isFinite(input));
var number = isNumeric ? Math.round(input) : 0;
return (number > 0) ? number : 0;

View File

@ -127,6 +127,31 @@
});
});
describe('noValue', function () {
var noValueFilter;
beforeEach(inject(function (_noValueFilter_) {
noValueFilter = _noValueFilter_;
}));
it('returns value if there is a value', function () {
expect(noValueFilter('foo')).toBe('foo');
expect(noValueFilter(' foo ')).toBe(' foo ');
expect(noValueFilter(true)).toBe(true);
expect(noValueFilter(false)).toBe(false);
var object = {};
expect(noValueFilter(object)).toBe(object);
var array = [];
expect(noValueFilter(array)).toBe(array);
});
it('replaces undefined, null, blank with -', function () {
expect(noValueFilter(null)).toBe('-');
expect(noValueFilter()).toBe('-');
expect(noValueFilter('')).toBe('-');
expect(noValueFilter(' ')).toBe('-');
});
});
describe("decode", function () {
var decodeFilter;
beforeEach(inject(function (_decodeFilter_) {

View File

@ -82,13 +82,13 @@
</dl>
<dl class="col-sm-2">
<dt translate>Project ID</dt>
<dd>{$ user.tenantId || user.default_project_id || '-'$}</dd>
<dd>{$ user.tenantId || user.default_project_id | noValue $}</dd>
</dl>
<span class="rsp-alt-p2">
<dl class="col-sm-2">
<dt translate>Email</dt>
<dd>{$ user.email || '-' $}</dd>
<dd>{$ user.email | noValue $}</dd>
</dl>
<dl class="col-sm-2">
<dt translate>Enabled</dt>

View File

@ -10,11 +10,11 @@
</tr>
</thead>
<tr ng-repeat="d in row.security_group_rules">
<td>{$ d.direction || '-' $}</td>
<td>{$ d.ethertype || '-' $}</td>
<td>{$ d.protocol || '-' $}</td>
<td>{$ d.port_range_min || '-' $}</td>
<td>{$ d.port_range_max || '-' $}</td>
<td>{$ d.remote_ip_prefix || '-' $}</td>
<td>{$ d.direction | noValue $}</td>
<td>{$ d.ethertype | noValue $}</td>
<td>{$ d.protocol | noValue $}</td>
<td>{$ d.port_range_min | noValue $}</td>
<td>{$ d.port_range_max | noValue $}</td>
<td>{$ d.remote_ip_prefix | noValue $}</td>
</tr>
</table>

View File

@ -70,7 +70,7 @@
<td class="rsp-p1">{$ image.status | imageStatus $}</td>
<td class="rsp-p2">{$ image.is_public | yesno $}</td>
<td class="rsp-p2">{$ image.protected | yesno $}</td>
<td class="rsp-p2">{$ image.disk_format || '-' $}</td>
<td class="rsp-p2">{$ image.disk_format | noValue | uppercase $}</td>
<td class="rsp-p2">{$ image.size | bytes $}</td>
</tr>
@ -99,7 +99,7 @@
</dl>
<dl class="col-sm-2">
<dt translate>Format</dt>
<dd>{$ image.disk_format || '-' $}</dd>
<dd>{$ image.disk_format | noValue $}</dd>
</dl>
<dl class="col-sm-2">
<dt translate>Size</dt>
@ -111,11 +111,11 @@
<div class="row">
<dl class="col-sm-2">
<dt translate>Min Disk (GB)</dt>
<dd>{$ image.min_disk || '-' $}</dd>
<dd>{$ image.min_disk | noValue $}</dd>
</dl>
<dl class="col-sm-2">
<dt translate>Min RAM (MB)</dt>
<dd>{$ image.min_ram || '-' $}</dd>
<dd>{$ image.min_ram | noValue $}</dd>
</dl>
</div>