← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14597: date filtering for event grid

 

------------------------------------------------------------
revno: 14597
committer: Abyot Asalefew Gizaw abyota@xxxxxxxxx
branch nick: dhis2
timestamp: Wed 2014-04-02 10:26:45 +0200
message:
  date filtering for event grid
modified:
  dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/scripts/filters.js


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/scripts/filters.js'
--- dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/scripts/filters.js	2014-04-02 06:12:40 +0000
+++ dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/scripts/filters.js	2014-04-02 08:26:45 +0000
@@ -6,36 +6,54 @@
 
 .filter('gridFilter', function($filter){    
     
-    return function(data, filterText, filterTypes){
+    return function(data, filters, filterTypes){
         
         if(!data ){
             return;
         }
         
-        if(!filterText){
+        if(!filters){
             return data;
         }        
         else{            
             
-            var dateFilter = {}, nonDateFilter = {}, filteredData = data;
+            var dateFilter = {}, 
+                textFilter = {}, 
+                filteredData = data;
             
-            for(var key in filterText){
+            for(var key in filters){
                 
                 if(filterTypes[key] === 'date'){
-                    if( filterText[key].start || filterText[key].end){
-                        dateFilter[key] = filterText[key];
+                    if(filters[key].start || filters[key].end){
+                        dateFilter[key] = filters[key];
                     }
                 }
+                else if(filterTypes[key] === 'date'){
+                    
+                }
                 else{
-                    nonDateFilter[key] = filterText[key];
+                    textFilter[key] = filters[key];
                 }
-            }           
-                      
-            filteredData = $filter('filter')(filteredData, nonDateFilter);             
+            }
+            
+            filteredData = $filter('filter')(filteredData, textFilter);               
+ 
+            filteredData = $filter('filter')(filteredData, dateFilter, dateComparator);            
                         
             return filteredData;
         } 
-    };   
+    }; 
+    
+    function dateComparator(data,filter){
+        var start = moment(filter.start, 'YYYY-MM-DD');
+        var end = moment(filter.end, 'YYYY-MM-DD');  
+        var date = moment(data, 'YYYY-MM-DD'); 
+        
+        if(filter.start && filter.end){
+            return ( Date.parse(date) <= Date.parse(end) ) && (Date.parse(date) >= Date.parse(start));
+        }        
+        return ( Date.parse(date) <= Date.parse(end) ) || (Date.parse(date) >= Date.parse(start));
+    }
 })
 
 .filter('paginate', function(Paginator) {