← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17884: adding new relative through registration

 

------------------------------------------------------------
revno: 17884
committer: Abyot Asalefew Gizaw <abyota@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2015-01-05 16:31:59 +0100
message:
  adding new relative through registration
modified:
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/registration/registration-controller.js
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/registration/registration.html
  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/registration.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/relationship.html
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/controllers.js
  dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/services.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-apps/src/main/webapp/dhis-web-tracker-capture/components/registration/registration-controller.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/registration/registration-controller.js	2014-12-19 16:52:40 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/registration/registration-controller.js	2015-01-05 15:31:59 +0000
@@ -10,12 +10,26 @@
                 EnrollmentService,
                 DialogService,
                 CurrentSelection,
+                OptionSetService,
                 EventUtils,
                 DateUtils,
                 storage) {
     
     $scope.today = DateUtils.getToday();
     
+    $scope.optionSets = CurrentSelection.getOptionSets();
+            
+    if(!$scope.optionSets){
+        $scope.optionSets = [];
+        OptionSetService.getAll().then(function(optionSets){
+            angular.forEach(optionSets, function(optionSet){                        
+                $scope.optionSets[optionSet.id] = optionSet;
+            });
+
+            CurrentSelection.setOptionSets($scope.optionSets);
+        });
+    }
+    
     $scope.selectedOrgUnit = storage.get('SELECTED_OU');
     $scope.enrollment = {dateOfEnrollment: '', dateOfIncident: ''};   
     
@@ -73,26 +87,11 @@
         
         //get tei attributes and their values
         //but there could be a case where attributes are non-mandatory and
-        //registration form comes empty, in this case enforce at least one value
-        $scope.valueExists = false;          
-        var result = TEIService.reconstructForWebApi($scope.attributes, $scope.attributesById, $scope.optionSets);
-        $scope.valueExists = result.formEmpty;
-        /*angular.forEach($scope.attributes, function(attribute){            
-            var val = attribute.value;
-            if(!angular.isUndefined(val)){
-                
-                if(attribute.valueType === 'date'){
-                    val = DateUtils.formatFromUserToApi(val);
-                }
-                if(attribute.valueType === 'optionSet' && $scope.optionSets.optionCodesByName[  '"' + val + '"']){   
-                    val = $scope.optionSets.optionCodesByName[  '"' + val + '"'];
-                }
-                registrationAttributes.push({attribute: attribute.id, value: val});
-                $scope.valueExists = true;
-            } 
-        });*/       
+        //registration form comes empty, in this case enforce at least one value        
+        var result = TEIService.reconstructForWebApi($scope.attributes, $scope.attributesById, $scope.optionSets);        
+        $scope.formEmpty = result.formEmpty;
         
-        if(!$scope.valueExists){
+        if($scope.formEmpty){
             //registration form is empty
             return false;
         }

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/registration/registration.html'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/registration/registration.html	2014-10-22 14:22:06 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/registration/registration.html	2015-01-05 15:31:59 +0000
@@ -48,17 +48,17 @@
                                        name="foo"
                                        class="form-control"
                                        ng-model="attribute.value"                                                 
-                                       typeahead="option.name as option.name for option in optionSets.optionSets[attribute.optionSet.id].options | filter:$viewValue | limitTo:20" 
+                                       typeahead="option.name as option.name for option in optionSets[attribute.optionSet.id].options | filter:$viewValue | limitTo:20" 
                                        typeahead-open-on-focus
                                        ng-required="attribute.mandatory"/>
                                 </div>
                                 <div ng-if="selectedProgram">
-                                    <div ng-if="!selectedProgram.dataEntryMethod || optionSets.optionSets[attribute.optionSet.id].options.length >= 7">
+                                    <div ng-if="!selectedProgram.dataEntryMethod || optionSets[attribute.optionSet.id].options.length >= 7">
                                         <input type="text" 
                                            name="foo"
                                            class="form-control"
                                            ng-model="attribute.value"                                                 
-                                           typeahead="option.name as option.name for option in optionSets.optionSets[attribute.optionSet.id].options | filter:$viewValue | limitTo:20" 
+                                           typeahead="option.name as option.name for option in optionSets[attribute.optionSet.id].options | filter:$viewValue | limitTo:20" 
                                            typeahead-open-on-focus
                                            typeahead-editable=false
                                            ng-required="attribute.mandatory"/>
@@ -71,7 +71,7 @@
                                                 ng-model="attribute.value"
                                                 value=""> {{'no_value' | translate}}<br>                                       
                                         </label><br>
-                                        <span ng-repeat="option in optionSets.optionSets[attribute.optionSet.id].options">
+                                        <span ng-repeat="option in optionSets[attribute.optionSet.id].options">
                                             <label>
                                                 <input type="radio"
                                                     name={{attribute.id}}
@@ -141,7 +141,7 @@
             </table>
         </div>
 
-        <div ng-if="!valueExists  && outerForm.submitted">
+        <div ng-if="formEmpty  && outerForm.submitted">
             <div class="alert alert-warning">{{'form_is_empty_fill_at_least_one'| translate}}</div> 
         </div>
 

=== 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	2014-11-28 14:54:12 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/relationship/add-relationship.html	2015-01-05 15:31:59 +0000
@@ -51,7 +51,7 @@
                         <option value="">{{'please_select_source'| translate}}</option>
                     </select>
                     <div class="input-group vertical-spacing" ng-if="selectedRelationshipSource.value === 'search_from_existing'">
-                        <input type="text" placeholder="{{'type_here_for_simple_search'| translate}}" ng-model="searchText.value" class="form-control expanded" ng-class="{true: 'invalid - input'} [!searchText && emptySearchText]" ng-focus="showHideSearch(true)">
+                        <input type="text" placeholder="{{'type_here_for_simple_search'| translate}}" ng-model="searchText.value" d2-enter="search(searchMode.freeText)" class="form-control expanded" ng-class="{true: 'invalid - input'} [!searchText && emptySearchText]" ng-focus="showHideSearch(true)">
                         <div class="input-group-btn">
                             <button class="btn btn-default without-border-radius trim" type="button" title="{{'advanced_search'| translate}}" ng-click="showHideSearch(false)"><i class="fa fa-caret-down"></i></button>
                             <button class="btn btn-primary trim" type="button" title="{{'search'| translate}}" ng-click="search(searchMode.freeText)"><i class="fa fa-search"></i></button>                            

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/relationship/registration.html'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/relationship/registration.html	2014-12-19 16:52:40 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/relationship/registration.html	2015-01-05 15:31:59 +0000
@@ -56,17 +56,17 @@
                                        name="foo"
                                        class="form-control"
                                        ng-model="attribute.value"                                                 
-                                       typeahead="option.name as option.name for option in optionSets.optionSets[attribute.optionSet.id].options | filter:$viewValue | limitTo:20" 
+                                       typeahead="option.name as option.name for option in optionSets[attribute.optionSet.id].options | filter:$viewValue | limitTo:20" 
                                        typeahead-open-on-focus
                                        ng-required="attribute.mandatory"/>
                                 </div>
                                 <div ng-if="selectedProgramForRelative">
-                                    <div ng-if="!selectedProgramForRelative.dataEntryMethod || optionSets.optionSets[attribute.optionSet.id].options.length >= 7">
+                                    <div ng-if="!selectedProgramForRelative.dataEntryMethod || optionSets[attribute.optionSet.id].options.length >= 7">
                                         <input type="text" 
                                            name="foo"
                                            class="form-control"
                                            ng-model="attribute.value"                                                 
-                                           typeahead="option.name as option.name for option in optionSets.optionSets[attribute.optionSet.id].options | filter:$viewValue | limitTo:20" 
+                                           typeahead="option.name as option.name for option in optionSets[attribute.optionSet.id].options | filter:$viewValue | limitTo:20" 
                                            typeahead-open-on-focus
                                            typeahead-editable=false
                                            ng-required="attribute.mandatory"/>
@@ -79,7 +79,7 @@
                                                 ng-model="attribute.value"
                                                 value=""> {{'no_value' | translate}}<br>                                       
                                         </label><br>
-                                        <span ng-repeat="option in optionSets.optionSets[attribute.optionSet.id].options">
+                                        <span ng-repeat="option in optionSets[attribute.optionSet.id].options">
                                             <label>
                                                 <input type="radio"
                                                     name={{attribute.id}}

=== 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-01-05 10:20:46 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/relationship/relationship-controller.js	2015-01-05 15:31:59 +0000
@@ -22,7 +22,7 @@
     
     //listen for the selected entity       
     $scope.$on('dashboardWidgets', function(event, args) { 
-         $scope.relatedTeis = [];
+        $scope.relatedTeis = [];
         $scope.selections = CurrentSelection.get();
         $scope.optionSets = $scope.selections.optionSets;
         $scope.selectedTei = angular.copy($scope.selections.tei);        
@@ -38,16 +38,8 @@
             $scope.addRelationshipLabel = $translate('add');
         }
         
-        angular.forEach($scope.selectedTei.relationships, function(rel){
-            var teiId = rel.trackedEntityInstanceA;
-            if($scope.selectedTei.trackedEntityInstance === rel.trackedEntityInstanceA){
-                teiId = rel.trackedEntityInstanceB;
-            }
-            
-            TEIService.get(teiId, $scope.optionSets).then(function(tei){
-                $scope.relatedTeis[teiId] = tei.data;
-            });
-        });
+        setRelationships();
+        
     });
     
     $scope.showAddRelationship = function() {
@@ -75,31 +67,47 @@
             });
 
             modalInstance.result.then(function (relationships) {
-                $scope.selectedTei.relationships = relationships;           
+                $scope.selectedTei.relationships = relationships;
+                
+                setRelationships();
             });
-        }        
-    };    
+        }
+    };
     
-    $scope.showDashboard = function(rel){
+    $scope.showDashboard = function(teiId, relId){
         
-        var dashboardProgram = null, relativeTeiId = '';
+        var dashboardProgram = null;
         
         if($scope.selectedProgram && $scope.selectedProgram.relationshipType){
-            if($scope.selectedProgram.relationshipType.id === rel.relationship && $scope.selectedProgram.relatedProgram ){
+            if($scope.selectedProgram.relationshipType.id === relId && $scope.selectedProgram.relatedProgram ){
                 dashboardProgram = $scope.selectedProgram.relatedProgram.id;
             }
         }        
-        
-        if($scope.selectedTei.trackedEntityInstance === rel.trackedEntityInstanceA){
-            relativeTeiId = rel.trackedEntityInstanceB;
-        }
-        else{
-            relativeTeiId = rel.trackedEntityInstanceA;
-        }          
     
-        $location.path('/dashboard').search({tei: relativeTeiId, program: dashboardProgram}); 
+        $location.path('/dashboard').search({tei: teiId, program: dashboardProgram}); 
         $route.reload();                                 
     };
+    
+    var setRelationships = function(){
+        $scope.relatedTeis = [];
+        angular.forEach($scope.selectedTei.relationships, function(rel){            
+            var teiId = rel.trackedEntityInstanceA;
+            var relName = $scope.relationships[rel.relationship].aIsToB;
+            if($scope.selectedTei.trackedEntityInstance === rel.trackedEntityInstanceA){
+                teiId = rel.trackedEntityInstanceB;
+                relName = $scope.relationships[rel.relationship].bIsToA;
+            }
+            var relative = {trackedEntityInstance: teiId, relName: relName, relId: rel.relationship};
+            $scope.relatedTeis.push(relative);
+            
+            /*TEIService.get(teiId, $scope.optionSets).then(function(tei){               
+               var relative = tei.data;
+               relative.relName = relName;
+               relative.relId = rel.relationship;               
+               $scope.relatedTeis.push(relative);
+            });*/
+        });
+    };
 })
 
 //Controller for adding new relationship
@@ -294,7 +302,7 @@
             }
             
             //process tei grid
-            $scope.trackedEntityList = TEIGridService.format(data,false, null);
+            $scope.trackedEntityList = TEIGridService.format(data,false, $scope.optionSets);
             $scope.showTrackedEntityDiv = true;
             $scope.teiFetched = true;            
         });
@@ -385,7 +393,7 @@
                 $scope.selectedTei.relationships = [relationship];
             }
             
-            TEIService.update($scope.selectedTei).then(function(response){
+            TEIService.update($scope.selectedTei, $scope.optionSets).then(function(response){
                 if(response.status !== 'SUCCESS'){//update has failed
                     var dialogOptions = {
                             headerText: 'relationship_error',

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/relationship/relationship.html'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/relationship/relationship.html	2014-12-19 16:52:40 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/relationship/relationship.html	2015-01-05 15:31:59 +0000
@@ -19,6 +19,11 @@
 
         <div ng-show="selectedTei" class="remove-default-padding">
             <table class="table table-striped dhis2-table-hover">
+                <tr ng-click="showDashboard(rel.trackedEntityInstance, rel.relId)" ng-repeat="rel in relatedTeis" title="{{'go_to_dashboard'| translate}}">
+                    <td>{{rel.relName}}</td> 
+                </tr>
+            </table>
+            <!--<table class="table table-striped dhis2-table-hover">
                 <tr ng-click="showDashboard(rel)" ng-repeat="rel in selectedTei.relationships" title="{{'go_to_dashboard'| translate}}">
                      <td>                        
                         <d2-pop-over content="relatedTeis[rel.trackedEntityInstanceB]" template="popover.html" details="{{'details'| translate}}" ng-if="selectedTei.trackedEntityInstance === rel.trackedEntityInstanceA">
@@ -29,7 +34,7 @@
                             <div>{{relationships[rel.relationship].aIsToB}}</div>
                         </d2-pop-over>                
                         
-                        <script type="text/ng-template" id="popover.html">                            
+                        <script type="text/ng-template" id="popover.html">
                             <table class="table table-striped table-bordered">
                                 <tr ng-repeat="att in content.attributes">
                                     <td>
@@ -40,11 +45,10 @@
                                     </td>                                    
                                 </tr>
                             </table>
-                        </script>
-                        
+                        </script>                        
                     </td> 
                 </tr>
-            </table>
+            </table>-->
         </div>
     </div>
 </div>
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/controllers.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/controllers.js	2014-12-19 16:52:40 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/controllers.js	2015-01-05 15:31:59 +0000
@@ -15,6 +15,7 @@
                 ProgramFactory,
                 AttributesFactory,
                 EntityQueryFactory,
+                CurrentSelection,
                 TEIGridService,
                 TEIService) {  
                     
@@ -57,18 +58,16 @@
             
             $scope.trackedEntityList = [];
             
+            $scope.optionSets = CurrentSelection.getOptionSets();
+            
             if(!$scope.optionSets){
-                $scope.optionSets = {optionSets: [], optionNamesByCode: new Object(), optionCodesByName: new Object()};
+                $scope.optionSets = [];
                 OptionSetService.getAll().then(function(optionSets){
-                    angular.forEach(optionSets, function(optionSet){
-                        angular.forEach(optionSet.options, function(option){
-                            if(option.name && option.code){
-                                $scope.optionSets.optionNamesByCode[ '"' + option.code + '"'] = option.name;
-                                $scope.optionSets.optionCodesByName[ '"' + option.name + '"'] = option.code;
-                            }                       
-                        });
-                        $scope.optionSets.optionSets[optionSet.id] = optionSet;
+                    angular.forEach(optionSets, function(optionSet){                        
+                        $scope.optionSets[optionSet.id] = optionSet;
                     });
+                    
+                    CurrentSelection.setOptionSets($scope.optionSets);
                 });
             }
             $scope.loadPrograms($scope.selectedOrgUnit);                                
@@ -262,7 +261,7 @@
             }
             
             //process tei grid
-            $scope.trackedEntityList = TEIGridService.format(data,false, $scope.optionSets.optionNamesByCode);
+            $scope.trackedEntityList = TEIGridService.format(data,false, $scope.optionSets);
             $scope.showTrackedEntityDiv = true;
             $scope.teiFetched = true;  
             $scope.doSearch = true;

=== modified file 'dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/services.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/services.js	2014-12-19 16:52:40 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/scripts/services.js	2015-01-05 15:31:59 +0000
@@ -368,7 +368,7 @@
 })
 
 /* Service for getting tracked entity instances */
-.factory('TEIService', function($http, $q, AttributesFactory, OptionSetService, DateUtils) {
+.factory('TEIService', function($http, $q, AttributesFactory, OptionSetService, CurrentSelection, DateUtils) {
 
     return {        
         convertFromApiToUser: function(promise, optionSets){            
@@ -527,29 +527,31 @@
             }       
             return def.promise;
         },
-        reconstructForWebApi: function(tei, attributes, attributesById, optionSets){
+        reconstructForWebApi: function(attributes, attributesById, optionSets){
+            
             var registrationAttributes = [];
             var formEmpty = true;
-            angular.forEach(attributes, function(att){            
-                if(att.valueType === 'trueOnly'){ 
-                    if(!tei[att.id]){
+            angular.forEach(attributes, function(att){
+                if(att.valueType === 'trueOnly'){
+                    if(att.value){
                         registrationAttributes.push({attribute: att.id, value: ''});
-                        formEmpty = false;                    
                     }
                     else{
                         registrationAttributes.push({attribute: att.id, value: 'true'});
-                        formEmpty = false;
                     }
+                    
+                    formEmpty = false;
                 }            
                 else{
-                    if(tei[att.id] !== '' && tei[att.id]){
-
-                        var val = tei[att.id];                    
+                    var val = att.value;
+                    if(val){
                         if(att.valueType === 'date'){   
                             val = DateUtils.formatFromUserToApi(val);
-                        }   
-
-                        if(att.valueType === 'optionSet' && attributesById[att.id] && attributesById[att.id].optionSet && optionSets[attributesById[att.id].optionSet.id]){                        
+                        }
+                        if(att.valueType === 'optionSet' && 
+                                attributesById[att.id] && 
+                                attributesById[att.id].optionSet && 
+                                optionSets[attributesById[att.id].optionSet.id]){                        
                             val = OptionSetService.getCode(optionSets[attributesById[att.id].optionSet.id].options, val);
                         }
 
@@ -951,28 +953,34 @@
 .service('CurrentSelection', function(){
     this.currentSelection = '';
     this.relationshipInfo = '';
+    this.optionSets = null;
     
     this.set = function(currentSelection){  
         this.currentSelection = currentSelection;        
-    };
-    
+    };    
     this.get = function(){
         return this.currentSelection;
     };
     
     this.setRelationshipInfo = function(relationshipInfo){  
         this.relationshipInfo = relationshipInfo;        
-    };
-    
+    };    
     this.getRelationshipInfo = function(){
         return this.relationshipInfo;
     };
+    
+    this.setOptionSets = function(optionSets){
+        this.optionSets = optionSets;
+    };
+    this.getOptionSets = function(){
+        return this.optionSets;
+    };    
 })
 
-.service('TEIGridService', function(OrgUnitService, DateUtils, $translate, AttributesFactory){
+.service('TEIGridService', function(OrgUnitService, OptionSetService, DateUtils, $translate, AttributesFactory){
     
     return {
-        format: function(grid, map, optionNamesByCode){
+        format: function(grid, map, optionSets){
             if(!grid || !grid.rows){
                 return;
             }
@@ -1014,11 +1022,13 @@
                             if(row[i] && row[i] !== ''){
                                 isEmpty = false;
                                 var val = row[i];
+                                
                                 if(attributes[grid.headers[i].name] && 
                                         attributes[grid.headers[i].name].valueType === 'optionSet' && 
-                                        optionNamesByCode &&    
-                                        optionNamesByCode[  '"' + val + '"']){
-                                    val = optionNamesByCode[  '"' + val + '"'];
+                                        optionSets &&    
+                                        attributes[grid.headers[i].name].optionSet &&
+                                        optionSets[attributes[grid.headers[i].name].optionSet.id] ){
+                                    val = OptionSetService.getName(optionSets[attributes[grid.headers[i].name].optionSet.id].options, val);
                                 }
                                 if(attributes[grid.headers[i].name] && attributes[grid.headers[i].name].valueType === 'date'){                                    
                                     val = DateUtils.formatFromApiToUser( val );
@@ -1035,7 +1045,7 @@
                             else{
                                 entityList.push(entity);
                             }
-                        }        
+                        }
                     });                
                 });
             });