← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18845: some refactoring in tei relationship searching/registration

 

------------------------------------------------------------
revno: 18845
committer: Abyot Asalefew Gizaw <abyota@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2015-04-09 12:18:52 +0200
message:
  some refactoring in tei relationship searching/registration
modified:
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/relationship/add-relationship.html
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/relationship/relationship-controller.js
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/relationship/search.html


--
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-apps/src/main/webapp/dhis-web-tracker-capture/components/relationship/add-relationship.html'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/relationship/add-relationship.html	2015-04-09 09:31:35 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/relationship/add-relationship.html	2015-04-09 10:18:52 +0000
@@ -66,7 +66,8 @@
                         <select ng-model="selectedProgramForRelative"
                                 class="form-control"
                                 ng-disabled="programs.length < 1 || (selectedProgramForRelative && selectedProgram.relatedProgram && relatedProgramRelationship)"
-                                ng-options="program as program.name for program in programs | orderBy: 'name'">
+                                ng-options="program as program.name for program in programs | orderBy: 'name'" 
+                                ng-change="setAttributesForSearch(selectedProgramForRelative)">
                             <option value="">{{'please_select_a_program'| translate}}</option>
                         </select>                
                     </div>

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/relationship/relationship-controller.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/relationship/relationship-controller.js	2015-04-09 09:31:35 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/relationship/relationship-controller.js	2015-04-09 10:18:52 +0000
@@ -192,32 +192,33 @@
     $scope.relatedProgramRelationship = relatedProgramRelationship;
     $scope.selectedTei = selectedTei;
     $scope.programs = selections.prs;
-
-    $scope.relationshipSources = ['search_from_existing','register_new'];
+    
     $scope.selectedRelationship = {};
     $scope.relationship = {};
-    
-    
-    //watch for selection of relationship
-    $scope.$watch('relationship.selected', function() {        
-        if( angular.isObject($scope.relationship.selected)){
-            $scope.selectedRelationship = {aIsToB: $scope.relationship.selected.aIsToB, bIsToA: $scope.relationship.selected.bIsToA};  
-        }
-    });
-    
-    $scope.setRelationshipSides = function(side){
-        if(side === 'A'){            
-            $scope.selectedRelationship.bIsToA = $scope.selectedRelationship.aIsToB === $scope.relationship.selected.aIsToB ? $scope.relationship.selected.bIsToA : $scope.relationship.selected.aIsToB;
-        }
-        if(side === 'B'){
-            $scope.selectedRelationship.aIsToB = $scope.selectedRelationship.bIsToA === $scope.relationship.selected.bIsToA ? $scope.relationship.selected.aIsToB : $scope.relationship.selected.bIsToA;
-        }
-    };
-    
-    //Selection
+
+    //Selections
     $scope.selectedOrgUnit = SessionStorageService.get('SELECTED_OU');
     $scope.optionSets = selections.optionSets;
     $scope.selectedTeiForDisplay = angular.copy($scope.selectedTei);
+    $scope.ouModes = [{name: 'SELECTED'}, {name: 'CHILDREN'}, {name: 'DESCENDANTS'}, {name: 'ACCESSIBLE'}];         
+    $scope.selectedOuMode = $scope.ouModes[0];
+    
+    //Paging
+    $scope.pager = {pageSize: 50, page: 1, toolBarDisplay: 5}; 
+    
+    //Searching
+    $scope.showAdvancedSearchDiv = false;
+    $scope.searchText = {value: null};
+    $scope.emptySearchText = false;
+    $scope.searchFilterExists = false;   
+    $scope.defaultOperators = OperatorFactory.defaultOperators;
+    $scope.boolOperators = OperatorFactory.boolOperators;
+    
+    $scope.trackedEntityList = null; 
+    $scope.enrollment = {programStartDate: '', programEndDate: '', operator: $scope.defaultOperators[0]};
+   
+    $scope.searchMode = {listAll: 'LIST_ALL', freeText: 'FREE_TEXT', attributeBased: 'ATTRIBUTE_BASED'};
+    $scope.selectedSearchMode = $scope.searchMode.listAll;
     
     if(angular.isObject($scope.programs) && $scope.programs.length === 1){
         $scope.selectedProgramForRelative = $scope.programs[0];        
@@ -239,18 +240,17 @@
                 }
             });
         }
-    }    
+    }
     
-    AttributesFactory.getByProgram($scope.selectedProgramForRelative).then(function(atts){
-        $scope.attributes = atts;
-        $scope.attributes = $scope.generateAttributeFilters($scope.attributes);
-        $scope.gridColumns = $scope.generateGridColumns($scope.attributes);
-        
-        resetFields();    
-        $scope.search($scope.searchMode.listAll);
+    //watch for selection of relationship
+    $scope.$watch('relationship.selected', function() {        
+        if( angular.isObject($scope.relationship.selected)){
+            $scope.selectedRelationship = {aIsToB: $scope.relationship.selected.aIsToB, bIsToA: $scope.relationship.selected.bIsToA};  
+        }
     });
     
     function resetFields(){
+        
         $scope.teiForRelationship = null;
         $scope.teiFetched = false;    
         $scope.emptySearchText = false;
@@ -266,51 +266,12 @@
         $scope.attributeUrl = {url: null, hasValue: false};
     }
     
-    //set attributes as per selected program
-    $scope.setAttributesForSearch = function(program){
-        
-        $scope.selectedProgramForRelative = program;
-        if( angular.isObject($scope.selectedProgramForRelative)){
-            AttributesFactory.getByProgram($scope.selectedProgramForRelative).then(function(atts){
-                $scope.attributes = atts;
-                $scope.attributes = $scope.generateAttributeFilters($scope.attributes);
-                $scope.gridColumns = $scope.generateGridColumns($scope.attributes);
-            });
-        }
-        else{
-            AttributesFactory.getWithoutProgram().then(function(atts){
-                $scope.attributes = atts;
-                $scope.attributes = $scope.generateAttributeFilters($scope.attributes);
-                $scope.gridColumns = $scope.generateGridColumns($scope.attributes);
-            });
-        }
-    };
-    
-    $scope.ouModes = [{name: 'SELECTED'}, {name: 'CHILDREN'}, {name: 'DESCENDANTS'}, {name: 'ACCESSIBLE'}];         
-    $scope.selectedOuMode = $scope.ouModes[0];
-    
-    //Paging
-    $scope.pager = {pageSize: 50, page: 1, toolBarDisplay: 5}; 
-    
-    //Searching
-    $scope.showAdvancedSearchDiv = false;
-    $scope.searchText = {value: null};
-    $scope.emptySearchText = false;
-    $scope.searchFilterExists = false;   
-    $scope.defaultOperators = OperatorFactory.defaultOperators;
-    $scope.boolOperators = OperatorFactory.boolOperators;
-    
-    $scope.trackedEntityList = null; 
-    $scope.enrollment = {programStartDate: '', programEndDate: '', operator: $scope.defaultOperators[0]};
-   
-    $scope.searchMode = {listAll: 'LIST_ALL', freeText: 'FREE_TEXT', attributeBased: 'ATTRIBUTE_BASED'};      
-    
     //listen for selections
     $scope.$on('relationship', function() { 
         var relationshipInfo = CurrentSelection.getRelationshipInfo();
         $scope.teiForRelationship = relationshipInfo.tei;
-    });    
-
+    });
+    
     $scope.search = function(mode){ 
         
         resetFields();
@@ -380,6 +341,21 @@
         });
     };
     
+    //set attributes as per selected program
+    $scope.setAttributesForSearch = function(program){
+        
+        $scope.selectedProgramForRelative = program;
+        AttributesFactory.getByProgram($scope.selectedProgramForRelative).then(function(atts){
+            $scope.attributes = atts;
+            $scope.attributes = $scope.generateAttributeFilters($scope.attributes);
+            $scope.gridColumns = $scope.generateGridColumns($scope.attributes);
+        });
+        
+        $scope.search( $scope.selectedSearchMode );        
+    }; 
+    
+    $scope.setAttributesForSearch( $scope.selectedProgramForRelative );
+    
     $scope.jumpToPage = function(){
         console.log(' am I here... ');
         if($scope.pager && $scope.pager.page && $scope.pager.pageCount && $scope.pager.page > $scope.pager.pageCount){
@@ -472,6 +448,15 @@
         $rootScope.showAddRelationshipDiv = !$rootScope.showAddRelationshipDiv;
     };
     
+    $scope.setRelationshipSides = function(side){
+        if(side === 'A'){            
+            $scope.selectedRelationship.bIsToA = $scope.selectedRelationship.aIsToB === $scope.relationship.selected.aIsToB ? $scope.relationship.selected.bIsToA : $scope.relationship.selected.aIsToB;
+        }
+        if(side === 'B'){
+            $scope.selectedRelationship.aIsToB = $scope.selectedRelationship.bIsToA === $scope.relationship.selected.bIsToA ? $scope.relationship.selected.aIsToB : $scope.relationship.selected.bIsToA;
+        }
+    };
+    
     $scope.assignRelationship = function(relativeTei){
         $scope.teiForRelationship = relativeTei;
         $rootScope.showAddRelationshipDiv = !$rootScope.showAddRelationshipDiv;

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/relationship/search.html'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/relationship/search.html	2015-02-24 13:10:51 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/relationship/search.html	2015-04-09 10:18:52 +0000
@@ -9,21 +9,7 @@
                     <label><input type="radio" ng-model="selectedOuMode.name" name="descendants" value="DESCENDANTS"> {{'DESCENDANTS'| translate}}</label><br/>
                     <label><input type="radio" ng-model="selectedOuMode.name" name="accessible" value="ACCESSIBLE"> {{'ACCESSIBLE'| translate}}</label>
                 </td>
-            </tr>
-            <tr>
-                <td>
-                    {{'program' | translate}}
-                </td>
-                <td>
-                    <select ng-model="selectedProgramForRelative"
-                            class="form-control"
-                            ng-options="program as program.name for program in programs | orderBy: 'name'" 
-                            ng-disabled="programs.length < 1 || (selectedProgramForRelative && selectedProgram.relatedProgram && relatedProgramRelationship)"
-                            ng-change="setAttributesForSearch(selectedProgramForRelative)">
-                        <option value="">{{programs.length > 0 ? 'please_select_a_program' : 'no_program_exists' | translate}}</option>
-                    </select>                    
-                </td>
-            </tr>
+            </tr>            
             <tr ng-if="selectedProgramForRelative">
                 <td>{{'enrollment_date'| translate}}</td>
                 <td>