From 9d60d9a9cf6ee034f73f1573a24a35ffdf8f253d Mon Sep 17 00:00:00 2001
From: fredkingham
Date: Mon, 15 Oct 2018 15:24:17 +0100
Subject: [PATCH 1/2] only show the teams view if there is at least one team
refs #1602
---
changelog.md | 2 ++
.../javascript/javascript_helpers.md | 9 ++++++++
opal/static/js/opal/filters.js | 12 ++++++++--
opal/static/js/test/filters.test.js | 22 +++++++++++++++++++
.../layouts/spreadsheet_list_base.html | 2 +-
5 files changed, 44 insertions(+), 3 deletions(-)
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..e73577d81 100644
--- a/opal/static/js/opal/filters.js
+++ b/opal/static/js/opal/filters.js
@@ -20,8 +20,9 @@ filters.filter('boxed', function(){
return '[X]'
}
return '[ ]'
- }
-})
+ }
+ debugger;
+});
filters.filter('plural', function(){
return function(someWord, count, plural){
@@ -262,3 +263,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 %}
From c84e7a497882714f65ae66f5d884ab3fd239fe9f Mon Sep 17 00:00:00 2001
From: fredkingham
Date: Mon, 15 Oct 2018 15:26:51 +0100
Subject: [PATCH 2/2] remove debugger statement
---
opal/static/js/opal/filters.js | 1 -
1 file changed, 1 deletion(-)
diff --git a/opal/static/js/opal/filters.js b/opal/static/js/opal/filters.js
index e73577d81..94ccddcf9 100644
--- a/opal/static/js/opal/filters.js
+++ b/opal/static/js/opal/filters.js
@@ -21,7 +21,6 @@ filters.filter('boxed', function(){
}
return '[ ]'
}
- debugger;
});
filters.filter('plural', function(){