Skip to content

Commit

Permalink
Fix broken rulefield after to PR #467 (#510)
Browse files Browse the repository at this point in the history
* Providing default value to get() to prevent a runtime error

* Fix sc
  • Loading branch information
allan.silva authored and bhearsum committed Mar 21, 2018
1 parent 916b587 commit 7c6574c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
15 changes: 14 additions & 1 deletion ui/app/js/directives/rule_field.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,22 @@ angular.module("app").directive("rulefield", function() {
fieldname: "@",
fieldtitle: "@",
help: "@",
limittextto: "@?",
limittextto: "@",
},
templateUrl: "rule_field.html",
link: function(scope, element, attr) {
attr.$observe('limittextto', function(value) {
scope.limittextto_sc = scope.limittextto;

if(!value && scope.rule[scope.fieldname] !== null && scope.rule[scope.fieldname] !== undefined) {
scope.limittextto = scope.rule[scope.fieldname].toString().length;
}

if(scope.rule.scheduled_change && scope.rule.scheduled_change[scope.fieldname] !== null && scope.rule.scheduled_change[scope.fieldname] !== undefined) {
scope.limittextto_sc = scope.limittextto_sc ? scope.limittextto_sc : scope.rule.scheduled_change[scope.fieldname].toString().length;
}
});
},
controller: function($scope) {
// For some reason directives don't inherit the Parent controller
// so we need to explicit set this here.
Expand Down
10 changes: 4 additions & 6 deletions ui/app/templates/rule_field.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,15 @@ <h5 ng-show="(rule[fieldname] !== null && rule[fieldname] !== undefined) || (sho
being shown, we just show the current value plainly -->

{{field_value=rule[fieldname] === true ? "Yes" : (rule[fieldname] === false ? "No" : rule[fieldname]);""}}
{{limit=(limittextto === undefined ? field_value.length : limittextto);""}}
<span tooltip="{{field_value.length > limit ? field_value : ''}}" ng-style="showdiff && showsc && (fieldIsChanging(rule, fieldname) || rule.scheduled_change.change_type === 'delete')
<span tooltip="{{field_value.length > limittextto ? field_value : ''}}" ng-style="showdiff && showsc && (fieldIsChanging(rule, fieldname) || rule.scheduled_change.change_type === 'delete')
? {'text-decoration': 'line-through', 'color': 'red'} : {};">

{{field_value | limitTo:limit}} {{field_value.length > limit ? '...' : ''}}
{{field_value | limitTo:limittextto}} {{field_value.length > limittextto ? '...' : ''}}
</span>

{{sc_field_value=rule.scheduled_change[fieldname] === true ? "Yes" : (rule.scheduled_change[fieldname] === false ? "No" : rule.scheduled_change[fieldname]);""}}
{{limit=(limittextto === undefined ? sc_field_value.length : limittextto);""}}
<span tooltip="{{sc_field_value.length > limit ? sc_field_value : ''}}" style="color: green" ng-show="showdiff && showsc && fieldIsChanging(rule, fieldname)">
{{sc_field_value | limitTo:limit}} {{sc_field_value.length > limit ? '...' : ''}}
<span tooltip="{{sc_field_value.length > limittextto_sc ? sc_field_value : ''}}" style="color: green" ng-show="showdiff && showsc && fieldIsChanging(rule, fieldname)">
{{sc_field_value | limitTo:limittextto_sc}} {{sc_field_value.length > limittextto_sc ? '...' : ''}}
</span>
</b>
</h5>

0 comments on commit 7c6574c

Please sign in to comment.