This commit is contained in:
parent
65981099b6
commit
156c9ec3ab
|
@ -1,6 +1,12 @@
|
|||
<section class="ellipsize">
|
||||
<vn-label></vn-label>
|
||||
<span></span>
|
||||
<a
|
||||
ng-show="$ctrl.state"
|
||||
ui-sref="{{$ctrl.state}}($ctrl.stateParams)">
|
||||
</a>
|
||||
<span
|
||||
ng-show="!$ctrl.state">
|
||||
</span>
|
||||
<vn-icon
|
||||
ng-if="$ctrl.hasInfo"
|
||||
vn-tooltip="{{$ctrl.info}}"
|
||||
|
|
|
@ -19,17 +19,24 @@ export default class Controller {
|
|||
return this._label;
|
||||
}
|
||||
|
||||
set value(value) {
|
||||
let span = this.element.querySelector('span');
|
||||
span.title = value;
|
||||
span.textContent = value ? value : '-';
|
||||
this._value = value;
|
||||
get state() {
|
||||
return this._state;
|
||||
}
|
||||
|
||||
set state(value) {
|
||||
this._state = value;
|
||||
this.applyTextContent();
|
||||
}
|
||||
|
||||
get value() {
|
||||
return this._value;
|
||||
}
|
||||
|
||||
set value(value) {
|
||||
this._value = value;
|
||||
this.applyTextContent();
|
||||
}
|
||||
|
||||
get title() {
|
||||
return this._title;
|
||||
}
|
||||
|
@ -39,6 +46,14 @@ export default class Controller {
|
|||
span.title = value;
|
||||
this._title = value;
|
||||
}
|
||||
|
||||
applyTextContent() {
|
||||
const targetElement = this.state ? 'a' : 'span';
|
||||
const element = this.element.querySelector(targetElement);
|
||||
const hasValue = this.value && this.value != '';
|
||||
element.title = this.value;
|
||||
element.textContent = hasValue ? this.value : '-';
|
||||
}
|
||||
}
|
||||
Controller.$inject = ['$element', '$translate', '$attrs'];
|
||||
|
||||
|
@ -48,6 +63,8 @@ ngModule.component('vnLabelValue', {
|
|||
bindings: {
|
||||
title: '@?',
|
||||
label: '@',
|
||||
value: '@'
|
||||
value: '@',
|
||||
state: '@?',
|
||||
stateParams: '<?'
|
||||
}
|
||||
});
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
import './label-value.js';
|
||||
import template from './label-value.html';
|
||||
|
||||
describe('Component vnInputTime', () => {
|
||||
let $element;
|
||||
let controller;
|
||||
|
||||
beforeEach(angular.mock.module('vnCore', $translateProvider => {
|
||||
$translateProvider.translations('en', {});
|
||||
}));
|
||||
|
||||
beforeEach(angular.mock.inject($componentController => {
|
||||
const $attrs = {};
|
||||
$element = angular.element(`${template}`);
|
||||
controller = $componentController('vnLabelValue', {$element, $attrs});
|
||||
}));
|
||||
|
||||
describe('applyTextContent()', () => {
|
||||
it(`should set the value on the span element as there's no navigation setted`, () => {
|
||||
const value = 'I am the value';
|
||||
controller.value = value;
|
||||
controller.title = value;
|
||||
controller.applyTextContent();
|
||||
|
||||
expect(controller.element.querySelector('span').textContent).toEqual(value);
|
||||
expect(controller.element.querySelector('span').title).toEqual(value);
|
||||
});
|
||||
|
||||
it(`should set the value on the anchor element as there's a navigation setted`, () => {
|
||||
const value = 'I am the value';
|
||||
controller.value = value;
|
||||
controller.title = value;
|
||||
controller.state = 'some.state.to.go';
|
||||
controller.applyTextContent();
|
||||
|
||||
expect(controller.element.querySelector('a').textContent).toEqual(value);
|
||||
expect(controller.element.querySelector('a').title).toEqual(value);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -36,7 +36,9 @@
|
|||
value="{{$ctrl.summary.landed | dateTime: 'dd/MM/yyyy'}}">
|
||||
</vn-label-value>
|
||||
<vn-label-value label="Route"
|
||||
value="{{$ctrl.summary.routeFk}}">
|
||||
value="{{$ctrl.summary.routeFk}}"
|
||||
state="route.card.summary"
|
||||
state-params="{id: $ctrl.summary.routeFk}">
|
||||
</vn-label-value>
|
||||
<vn-label-value label="Address"
|
||||
value="{{$ctrl.formattedAddress}}">
|
||||
|
|
Loading…
Reference in New Issue