← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15276: searching tracked entity - wip

 

------------------------------------------------------------
revno: 15276
committer: Abyot Asalefew Gizaw abyota@xxxxxxxxx
branch nick: dhis2
timestamp: Thu 2014-05-15 14:45:17 +0200
message:
  searching tracked entity - wip
modified:
  dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/i18n/en.json
  dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/controllers.js
  dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/services.js
  dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/styles/style.css
  dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/views/home.html
  dhis-2/dhis-web/pom.xml


--
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-tracker-capture/src/main/webapp/dhis-web-tracker-capture/i18n/en.json'
--- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/i18n/en.json	2014-05-14 13:04:39 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/i18n/en.json	2014-05-15 12:45:17 +0000
@@ -12,6 +12,7 @@
     "advanced_search": "Advanced search",
     "search_for": "Search for",
     "your_search_input_here": "Your search input here",
+    "search_input_required": "Please specify a search criteria",
     "registered_entities": "Registered Entities",
     "empty_entity_list": "There are no reigstered entities",
     "empty": "Empty",

=== modified file 'dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/controllers.js'
--- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/controllers.js	2014-05-14 15:42:24 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/controllers.js	2014-05-15 12:45:17 +0000
@@ -13,6 +13,7 @@
                 SelectedEntity,
                 storage,
                 AttributesFactory,
+                EntityQueryFactory,
                 TrackedEntityInstanceService) {   
    
     //Selection
@@ -35,6 +36,7 @@
     //Searching
     $scope.showSearchDiv = false;
     $scope.searchText = null;
+    $scope.emptySearchText = false;
     $scope.searchFilterExists = false;
     $scope.attributes = AttributesFactory.getWithoutProgram();    
     $scope.searchMode = {listAll: 'LIST_ALL', freeText: 'FREE_TEXT', attributeBased: 'ATTRIBUTE_BASED'};
@@ -99,7 +101,9 @@
         }
     };
     
-    $scope.search = function(mode){     
+    $scope.search = function(mode){ 
+        
+        $scope.emptySearchText = false;
         var queryUrl = null, 
             programUrl = null, 
             attributeUrl = null;
@@ -125,52 +129,20 @@
         if( mode === $scope.searchMode.freeText ){            
             $scope.trackedEntityList = null;
             
-            if(!$scope.searchText){
-                console.log('empty search query');
+            if(!$scope.searchText){                
+                $scope.emptySearchText = true;
                 return;
             }       
             
             $scope.showTrackedEntityDiv = true;      
-            queryUrl = 'query=' + $scope.searchText;
-                     
+            queryUrl = 'query=' + $scope.searchText;                     
         }
         else if( mode === $scope.searchMode.attributeBased ){
             $scope.showTrackedEntityDiv = true;      
             
-            angular.forEach($scope.attributes, function(attribute){
-               
-                if(attribute.value && attribute.value !== ""){                    
-                    $scope.searchFilterExists = true;
-                    if(angular.isArray(attribute.value)){
-                        angular.forEach(attribute.value, function(val){                            
-                            if(attributeUrl){
-                                attributeUrl = attributeUrl + '&attribute=' + attribute.id + ':EQ:' + val;
-                            }
-                            else{
-                                attributeUrl = 'attribute=' + attribute.id + ':EQ:' + val;
-                            }
-                        });
-                    }
-                    else{                        
-                        if(attributeUrl){
-                            attributeUrl = attributeUrl + '&attribute=' + attribute.id + ':EQ:' + attribute.value;
-                        }
-                        else{
-                            attributeUrl = 'attribute=' + attribute.id + ':EQ:' + attribute.value;
-                        }
-                    }
-                }
-                else{
-                    if(attributeUrl){
-                        attributeUrl = attributeUrl + '&attribute=' + attribute.id;
-                    }
-                    else{
-                        attributeUrl = 'attribute=' + attribute.id;
-                    }
-                }
-            });
-            
-            if(!$scope.searchFilterExists){
+            attributeUrl = EntityQueryFactory.getQueryForAttributes($scope.attributes);
+          
+            if(!attributeUrl.hasValue){
                 console.log('empty search filter');
                 return;
             }
@@ -186,7 +158,7 @@
                                             $scope.ouMode,
                                             queryUrl,
                                             programUrl,
-                                            attributeUrl).then(function(data){
+                                            attributeUrl.url).then(function(data){
             $scope.trackedEntityList = data;
         });
     };

=== modified file 'dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/services.js'
--- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/services.js	2014-05-14 15:42:24 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/scripts/services.js	2014-05-15 12:45:17 +0000
@@ -338,8 +338,52 @@
     };    
 })
 
-.service('ProgramAttributes', function(){
-    
+.service('EntityQueryFactory', function(){
+    
+    var query = {url: null, hasValue: false};
+    
+    this.getQueryForAttributes = function(attributes){
+        
+        angular.forEach(attributes, function(attribute){
+                
+            //console.log('attribute', attribute.valueType);
+
+            if(attribute.value && attribute.value !== ""){                    
+                query.hasValue = true;
+                if(angular.isArray(attribute.value)){
+                    var index = 0;
+
+                    angular.forEach(attribute.value, function(val){                            
+                        if(query.url){
+                            query.url = query.url + '&attribute=' + attribute.id + ':LIKE:' + val;
+                        }
+                        else{
+                            query.url = 'attribute=' + attribute.id + ':LIKE:' + val;
+                        }
+                        index++;
+                    });
+                }
+                else{                        
+                    if(query.url){
+                        query.url = query.url + '&attribute=' + attribute.id + ':LIKE:' + attribute.value;
+                    }
+                    else{
+                        query.url = 'attribute=' + attribute.id + ':LIKE:' + attribute.value;
+                    }
+                }
+            }
+            else{
+                if(query.url){
+                    query.url = query.url + '&attribute=' + attribute.id;
+                }
+                else{
+                    query.url = 'attribute=' + attribute.id;
+                }
+            }
+        });
+            
+        return query;
+    };    
 })
 
 /* Modal service for user interaction */

=== modified file 'dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/styles/style.css'
--- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/styles/style.css	2014-05-14 13:04:39 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/styles/style.css	2014-05-15 12:45:17 +0000
@@ -776,6 +776,14 @@
     padding-left: 5px;
 }
 
+.invalid-input {
+    border-style:solid;
+    border-color:red;
+}
+
+.alert {
+    padding: 5px;
+}
 .input-field {
     border: 1px solid #aaa;
     padding: 4px 1px;

=== modified file 'dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/views/home.html'
--- dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/views/home.html	2014-05-14 13:09:15 +0000
+++ dhis-2/dhis-web/dhis-web-tracker-capture/src/main/webapp/dhis-web-tracker-capture/views/home.html	2014-05-15 12:45:17 +0000
@@ -22,11 +22,11 @@
     <div class="row">
         <input type="text" selected-org-unit ng-model="selectedOrgUnit.name" ng-hide=true>
         <div class="input-group col-md-6">
-            <input type="text" placeholder="{{'your_search_input_here'| translate}}" ng-model="searchText" class="form-control" ng-focus="hideSearch()" ng-disabled="showRegistrationDiv">
+            <input type="text" placeholder="{{'your_search_input_here'| translate}}" ng-model="searchText" class="form-control" ng-class="{true: 'invalid-input'} [!searchText && emptySearchText]" ng-focus="hideSearch()" ng-disabled="showRegistrationDiv">
             <span class="input-group-btn">
                 <button class="btn btn-default" type="button" title="{{'more' | translate}}" ng-click="showSearch()" ng-disabled="showRegistrationDiv"><i class="fa fa-caret-down"></i></button>
             </span>                
-        </div>
+        </div>        
         <div class="btn-group col-md-6">
             <button type="button" 
                     class="btn btn-default"
@@ -44,6 +44,11 @@
                     ng-click="showRegistration()">
                 {{'add_new'| translate}}
             </button>
+        </div>        
+    </div>
+    <div class="row" ng-if="!searchText && emptySearchText">
+        <div class="col-md-6">
+            <div class="alert alert-danger">{{'search_input_required' | translate}}</div>         
         </div>
     </div>
     

=== modified file 'dhis-2/dhis-web/pom.xml'
--- dhis-2/dhis-web/pom.xml	2014-05-14 13:04:39 +0000
+++ dhis-2/dhis-web/pom.xml	2014-05-15 12:45:17 +0000
@@ -30,6 +30,7 @@
     <module>dhis-web-light</module>
     <module>dhis-web-mobile</module>
     <module>dhis-web-sms</module>
+    <module>dhis-web-event-capture</module>
     <module>dhis-web-event-reports</module>
     <module>dhis-web-tracker-capture</module>
     <module>dhis-web-portal</module>