← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14596: responsive filtering for non-date dataelement types, date type filtering is WIP

 

------------------------------------------------------------
revno: 14596
committer: Abyot Asalefew Gizaw abyota@xxxxxxxxx
branch nick: dhis2
timestamp: Wed 2014-04-02 08:12:40 +0200
message:
  responsive filtering for non-date dataelement types, date type filtering is WIP
modified:
  dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/index.html
  dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/scripts/controllers.js
  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/index.html'
--- dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/index.html	2014-03-31 10:39:30 +0000
+++ dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/index.html	2014-04-02 06:12:40 +0000
@@ -1,6 +1,5 @@
 <!DOCTYPE html>
-<!--<html manifest="event-capture.appcache" ng-app="eventCapture">-->
-<html ng-app="eventCapture">
+<html manifest="event-capture.appcache" ng-app="eventCapture">
     <head>
         <title>Event Capture</title>
 
@@ -45,7 +44,7 @@
         <script type="text/javascript" src="../dhis-web-commons/javascripts/dhis2/dhis2.storage.memory.js"></script>
         <script type="text/javascript" src="../dhis-web-commons/javascripts/dhis2/dhis2.storage.js"></script>
         <script type="text/javascript" src="../dhis-web-commons/javascripts/dhis2/dhis2.contextmenu.js"></script>
-        <!--<script type="text/javascript" src="../dhis-web-commons/javascripts/dhis2/dhis2.appcache.js"></script>-->
+        <script type="text/javascript" src="../dhis-web-commons/javascripts/dhis2/dhis2.appcache.js"></script>
         <script type="text/javascript" src="../dhis-web-commons/ouwt/ouwt.js"></script>
         
         <script type="text/javascript" src="../dhis-web-commons/javascripts/angular/plugins/angularLocalStorage.js"></script>
@@ -186,23 +185,23 @@
                                                         <a href ng-click="searchInGrid(eventGridColumn)" title="{{'search'| translate}}"><span ng-class="{true: 'filter-without-content', false: 'filter-with-content'} [filterText[eventGridColumn.id] == undefined || filterText[eventGridColumn.id] == '']"><i class="fa fa-search"></i></span></a>
                                                     </span>
                                                     <span ng-show="eventGridColumn.type ==='date'">
-                                                        <a href ng-click="searchInGrid(eventGridColumn)" title="{{'search'| translate}}"><span ng-class="{true: 'filter-without-content', false: 'filter-with-content'} [(filterText[eventGridColumn.id].start == 'undefined' || filterText[eventGridColumn.id].start == '') && (filterText[eventGridColumn.id].end == 'undefined' || filterText[eventGridColumn.id].end == '')]"><i class="fa fa-search"></i></span></a>
+                                                        <a href ng-click="searchInGrid(eventGridColumn)" title="{{'search'| translate}}"><span ng-class="{true: 'filter-without-content', false: 'filter-with-content'} [(filterText[eventGridColumn.id].start == undefined || filterText[eventGridColumn.id].start == '') && (filterText[eventGridColumn.id].end == undefined || filterText[eventGridColumn.id].end == '')]"><i class="fa fa-search"></i></span></a>
                                                     </span>                                                    
                                                 </span>
                                                 <!-- filter icon ends -->
                                                 
                                                 <!-- filter input field begins -->
-                                                <span ng-show="eventGridColumn.showFilter">
+                                                <span ng-show="eventGridColumn.showFilter">                                                    
                                                     <span ng-show="eventGridColumn.type !=='date'">
                                                         <input type="text" style="width: 90%;" ng-model="filterText[eventGridColumn.id]" ng-blur="searchInGrid(eventGridColumn)">
                                                     </span>                                                    
                                                     <span ng-show="eventGridColumn.type ==='date'">
-                                                        <input style="width: 90%;" placeholder="{{'start_date' | translate}}" type="text" ng-model="filterText[eventGridColumn.id].start" data-ng-date readonly="readonly">
-                                                        <span ng-hide="filterText[eventGridColumn.id].start == 'undefined' || filterText[eventGridColumn.id].start == ''">
+                                                        <input style="width: 70%;" placeholder="{{'start_date' | translate}}" type="text" ng-model="filterText[eventGridColumn.id].start" data-ng-date readonly="readonly">
+                                                        <span ng-hide="filterText[eventGridColumn.id].start == undefined || filterText[eventGridColumn.id].start == ''">
                                                             <a href ng-click='removeStartFilterText(eventGridColumn.id)'><span class='black'><i class="fa fa-trash-o"></i></span></a>                                                        
                                                         </span>
-                                                        <input style="width: 90%;" placeholder="{{'end_date' | translate}}" type="text" ng-model="filterText[eventGridColumn.id].end" data-ng-date readonly="readonly">
-                                                        <span ng-hide="filterText[eventGridColumn.id].end == 'undefined' || filterText[eventGridColumn.id].end == ''">
+                                                        <input style="width: 70%;" placeholder="{{'end_date' | translate}}" type="text" ng-model="filterText[eventGridColumn.id].end" data-ng-date readonly="readonly">
+                                                        <span ng-hide="filterText[eventGridColumn.id].end == undefined || filterText[eventGridColumn.id].end == ''">
                                                             <a href ng-click='removeEndFilterText(eventGridColumn.id)'><span class='black'><i class="fa fa-trash-o"></i></span></a>                                                        
                                                         </span>
                                                     </span>
@@ -214,7 +213,8 @@
                                         </tr>                        
                                     </thead>
                                     <tbody id="list">                                        
-                                        <tr ng-repeat="dhis2Event in dhis2Events | orderBy:sortHeader:reverse | gridFilter:filterText:programStageDataElements"                                        
+                                        <!--<tr ng-repeat="dhis2Event in dhis2Events | orderBy:sortHeader:reverse | gridFilter:filterText:filterTypes"      -->
+                                        <tr ng-repeat="dhis2Event in dhis2Events | orderBy:sortHeader:reverse | gridFilter:filterText:filterTypes"                                        
                                             ng-click="showContextMenu(dhis2Event)">
 
                                             <!-- Visible when event is not under editing -->
@@ -292,8 +292,8 @@
                                                         </div>
                                                         <div ng-switch-when="trueOnly">
                                                             <input type="checkbox"
-                                                                   ng-model="currentEvent[eventGridColumn.id]"
-                                                                   ng-change="updateEventDataValue(currentEvent, eventGridColumn.id)"
+                                                                   ng-model="dhis2Event[eventGridColumn.id]"
+                                                                   ng-change="updateEventDataValue(dhis2Event, eventGridColumn.id)" 
                                                                    ng-required={{eventGridColumn.compulsory}}
                                                                    name="foo" 
                                                                    ng-class="{true: 'update-success'} [updateSuccess && currentGridColumnId == eventGridColumn.id]"

=== modified file 'dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/scripts/controllers.js'
--- dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/scripts/controllers.js	2014-03-31 10:39:30 +0000
+++ dhis-2/dhis-web/dhis-web-event-capture/src/main/webapp/dhis-web-event-capture/scripts/controllers.js	2014-04-02 06:12:40 +0000
@@ -21,11 +21,7 @@
     $scope.selectedOrgUnit = '';
     
     //Paging
-    $scope.pager = {pageSize: 50, page: 1, toolBarDisplay: 5};
-    
-    //Filtering
-    $scope.reverse = false;
-    $scope.filterText = {}; 
+    $scope.pager = {pageSize: 50, page: 1, toolBarDisplay: 5};   
     
     //Editing
     $scope.eventRegistration = false;
@@ -88,6 +84,10 @@
     //get events for the selected program (and org unit)
     $scope.loadEvents = function(program, pager){   
         
+        //Filtering
+        $scope.reverse = false;
+        $scope.filterText = {}; 
+    
         $scope.dhis2Events = [];
         $scope.eventLength = 0;
 
@@ -119,8 +119,9 @@
                 $scope.filterTypes[dataElement.id] = dataElement.type;
                 
                 if(dataElement.type === 'date'){
-                     $scope.filterText[dataElement.id]= {start: '', end: ''};
-                }               
+                     $scope.filterText[dataElement.id]= {};
+                }
+                //$scope.filterText[dataElement.id]= '';
                 
             });           
 
@@ -166,8 +167,15 @@
                                         }
                                         else{
                                             dataValue.value = '';
-                                        }
-                                        
+                                        }                                        
+                                    }
+                                    else if( dataElement.type == 'trueOnly'){
+                                        if(dataValue.value == 'true'){
+                                            dataValue.value = true;
+                                        }
+                                        else{
+                                            dataValue.value = false;
+                                        }
                                     }
                                     
                                     $scope.dhis2Events[i][dataValue.dataElement] = dataValue.value; 
@@ -259,11 +267,11 @@
     };    
     
     $scope.removeStartFilterText = function(gridColumnId){
-        $scope.filterText[gridColumnId].start = '';
+        $scope.filterText[gridColumnId].start = undefined;
     };
     
     $scope.removeEndFilterText = function(gridColumnId){
-        $scope.filterText[gridColumnId].end = '';
+        $scope.filterText[gridColumnId].end = undefined;
     };
     
     $scope.showEventList = function(){
@@ -367,7 +375,7 @@
     }; 
        
     $scope.updateEventDataValue = function(currentEvent, dataElement){
-        
+
         //get current column
         $scope.currentGridColumnId = dataElement;
         
@@ -375,6 +383,9 @@
         var newValue = currentEvent[dataElement];
         var oldValue = $scope.currentEventOrginialValue[dataElement];
         
+        console.log('old:  ', oldValue);
+        console.log('new:  ', newValue);
+        
         //check for form validity
         $scope.outerForm.submitted = true;        
         if( $scope.outerForm.$invalid ){

=== 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-03-19 08:22:59 +0000
+++ 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
@@ -4,9 +4,9 @@
 
 var eventCaptureFilters = angular.module('eventCaptureFilters', [])
 
-.filter('gridFilter', function(){    
+.filter('gridFilter', function($filter){    
     
-    return function(data, filterText, filterObjectTypes){
+    return function(data, filterText, filterTypes){
         
         if(!data ){
             return;
@@ -17,47 +17,25 @@
         }        
         else{            
             
-            var keys = [];
-            var filteredData = data;
+            var dateFilter = {}, nonDateFilter = {}, filteredData = data;
             
             for(var key in filterText){
-                keys.push(key);
                 
-                for(var i=0; i<filteredData.length; i++){
-                    
-                    var val = filteredData[i][key];
-                    
-                    if( filterObjectTypes[key].dataElement.type === 'date'){
-                        
-                        if( filterText[key].start || filterText[key].end){
-                            var start = moment(filterText[key].start, 'YYYY-MM-DD');
-                            var end = moment(filterText[key].end, 'YYYY-MM-DD');  
-                            var date = moment(val, 'YYYY-MM-DD');                              
-                            
-                            if( ( Date.parse(date) > Date.parse(end) ) || (Date.parse(date) < Date.parse(start)) ){  
-                                filteredData.splice(i,1);
-                                i--;
-                            }                                                        
-                        }
-                        
-                    }
-                    else{
-                        if( filterObjectTypes[key].dataElement.type === 'int'){
-                            val = val.toString();
-                        }
-
-                        val = val.toLowerCase();
-                        if( val.indexOf(filterText[key].toLowerCase()) === -1 ){
-                            filteredData.splice(i,1);
-                            i--;
-                        }                        
-                    }
-                                        
-                }
-            }            
+                if(filterTypes[key] === 'date'){
+                    if( filterText[key].start || filterText[key].end){
+                        dateFilter[key] = filterText[key];
+                    }
+                }
+                else{
+                    nonDateFilter[key] = filterText[key];
+                }
+            }           
+                      
+            filteredData = $filter('filter')(filteredData, nonDateFilter);             
+                        
             return filteredData;
         } 
-    };    
+    };   
 })
 
 .filter('paginate', function(Paginator) {