Skip to content

Commit

Permalink
Merge c84e7a4 into aa46ff2
Browse files Browse the repository at this point in the history
  • Loading branch information
fredkingham committed Oct 15, 2018
2 parents aa46ff2 + c84e7a4 commit 6a339a4
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 3 deletions.
2 changes: 2 additions & 0 deletions changelog.md
Expand Up @@ -11,6 +11,8 @@
takes a user and by default returns True. Override this
to decide if a menu item should be shown in the nav bar.

* Adds a `populated` angular filter that returns True if an object is populated

### 0.11.2 (Bugfix Release)

Includes referencedata JSON files in Manifest.
Expand Down
9 changes: 9 additions & 0 deletions doc/docs/reference/javascript/javascript_helpers.md
Expand Up @@ -166,6 +166,15 @@ Converts strings with underscores (e.g. variable names etc) to words with spaces
->> some underscore string
```

#### populated

Checks to see if an object is populated

```html
[[ {} | populated ]]
->> false
```


### Angular HTTP Interceptors

Expand Down
11 changes: 9 additions & 2 deletions opal/static/js/opal/filters.js
Expand Up @@ -20,8 +20,8 @@ filters.filter('boxed', function(){
return '[X]'
}
return '[ ]'
}
})
}
});

filters.filter('plural', function(){
return function(someWord, count, plural){
Expand Down Expand Up @@ -262,3 +262,10 @@ filters.filter('totalDays', function(toMomentFilter){
}
};
});

filters.filter('populated', function(){
// returns true if an object is populated
return function(something){
return !_.isEmpty(something);
};
});
22 changes: 22 additions & 0 deletions opal/static/js/test/filters.test.js
Expand Up @@ -499,4 +499,26 @@ describe('filters', function() {

});

describe('populated', function(){
var populated;

beforeEach(function(){
inject(function($injector){
populated = $injector.get('populatedFilter')
});
});

it('should return true if the object is populated', function(){
expect(populated({hello: 1})).toBe(true);
expect(populated({hello: null})).toBe(true);
expect(populated({hello: undefined})).toBe(true);
expect(populated({hello: NaN})).toBe(true);
});

it('should return false if the object is not populated', function(){
expect(populated({})).toBe(false);
expect(populated(null)).toBe(false);
});
});

});
Expand Up @@ -53,7 +53,7 @@ <h1>
</a>
</p>
</li>
<li class="list-group-item" ng-show="profile.can_see_pid()">
<li class="list-group-item" ng-show="profile.can_see_pid() && metadata.tags|populated">
<h4>
<i class="fa fa-users"></i> Teams
{% if patient_list.allow_edit_teams %}
Expand Down

0 comments on commit 6a339a4

Please sign in to comment.