diff --git a/changelog.md b/changelog.md index 3503d998c..8dd480ad0 100644 --- a/changelog.md +++ b/changelog.md @@ -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. diff --git a/doc/docs/reference/javascript/javascript_helpers.md b/doc/docs/reference/javascript/javascript_helpers.md index 5d04e38eb..887b37ff5 100644 --- a/doc/docs/reference/javascript/javascript_helpers.md +++ b/doc/docs/reference/javascript/javascript_helpers.md @@ -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 diff --git a/opal/static/js/opal/filters.js b/opal/static/js/opal/filters.js index 1eecca46a..94ccddcf9 100644 --- a/opal/static/js/opal/filters.js +++ b/opal/static/js/opal/filters.js @@ -20,8 +20,8 @@ filters.filter('boxed', function(){ return '[X]' } return '[ ]' - } -}) + } +}); filters.filter('plural', function(){ return function(someWord, count, plural){ @@ -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); + }; +}); \ No newline at end of file diff --git a/opal/static/js/test/filters.test.js b/opal/static/js/test/filters.test.js index 71b4b263a..a28f98827 100644 --- a/opal/static/js/test/filters.test.js +++ b/opal/static/js/test/filters.test.js @@ -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); + }); + }); + }); diff --git a/opal/templates/patient_lists/layouts/spreadsheet_list_base.html b/opal/templates/patient_lists/layouts/spreadsheet_list_base.html index c93d18595..bdad0ff60 100644 --- a/opal/templates/patient_lists/layouts/spreadsheet_list_base.html +++ b/opal/templates/patient_lists/layouts/spreadsheet_list_base.html @@ -53,7 +53,7 @@

-
  • +
  • Teams {% if patient_list.allow_edit_teams %}