dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #35917
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18394: tracker-capture: displayInListNoProgram attributes are now used to provide more details about rel...
------------------------------------------------------------
revno: 18394
committer: Abyot Asalefew Gizaw <abyota@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2015-02-24 17:15:59 +0100
message:
tracker-capture: displayInListNoProgram attributes are now used to provide more details about relatives in relationship widget
modified:
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
--
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/relationship-controller.js'
--- dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/relationship/relationship-controller.js 2015-02-24 13:10:51 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/relationship/relationship-controller.js 2015-02-24 16:15:59 +0000
@@ -3,6 +3,8 @@
$rootScope,
$modal,
$location,
+ DateUtils,
+ OptionSetService,
CurrentSelection,
RelationshipFactory) {
$rootScope.showAddRelationshipDiv = false;
@@ -15,9 +17,16 @@
$scope.relatedTeis = [];
$scope.selections = CurrentSelection.get();
$scope.optionSets = $scope.selections.optionSets;
- $scope.selectedTei = angular.copy($scope.selections.tei);
+ $scope.selectedTei = angular.copy($scope.selections.tei);
$scope.attributesById = CurrentSelection.getAttributesById();
+ $scope.attributes = [];
+ for(var key in $scope.attributesById){
+ if($scope.attributesById.hasOwnProperty(key)){
+ $scope.attributes.push($scope.attributesById[key]);
+ }
+ }
+
$scope.trackedEntity = $scope.selections.te;
$scope.selectedEnrollment = $scope.selections.selectedEnrollment;
$scope.selectedProgram = $scope.selections.pr;
@@ -84,24 +93,52 @@
var setRelationships = function(){
$scope.relatedTeis = [];
- angular.forEach($scope.selectedTei.relationships, function(rel){
+ 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};
+ var relative = {trackedEntityInstance: teiId, relName: relName, relId: rel.relationship, attributes: getRelativeAttributes(rel)};
$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);
- });*/
});
};
+
+ var getRelativeAttributes = function(tei){
+
+ var attributes = {};
+
+ if(tei && tei.relative && tei.relative.attributes && !tei.relative.processed){
+ angular.forEach(tei.relative.attributes, function(att){
+ var val = att.value;
+ if(att.type === 'trueOnly'){
+ val = val === 'true' ? true : '';
+ }
+ else{
+ if(val){
+ if(att.type === 'date'){
+ val = DateUtils.formatFromApiToUser(val);
+ }
+ if(att.type === 'optionSet' &&
+ $scope.attributesById[att.attribute] &&
+ $scope.attributesById[att.attribute].optionSet &&
+ $scope.attributesById[att.attribute].optionSet.id &&
+ $scope.optionSets[$scope.attributesById[att.attribute].optionSet.id]){
+ val = OptionSetService.getName($scope.optionSets[$scope.attributesById[att.attribute].optionSet.id].options, val);
+ }
+ }
+ }
+ attributes[att.attribute] = val;
+ });
+ }
+
+ if(tei && tei.relative && tei.relative.processed){
+ attributes = tei.relative.attributes;
+ }
+
+ return attributes;
+ };
})
//Controller for adding new relationship
@@ -384,23 +421,24 @@
};
$scope.addRelationship = function(){
- if($scope.selectedTei && $scope.teiForRelationship && $scope.relationship.selected){
-
+ if($scope.selectedTei && $scope.teiForRelationship && $scope.relationship.selected){
+ var tei = angular.copy($scope.selectedTei);
var relationship = {};
relationship.relationship = $scope.relationship.selected.id;
relationship.displayName = $scope.relationship.selected.name;
+ relationship.relative = {};
+
relationship.trackedEntityInstanceA = $scope.selectedRelationship.aIsToB === $scope.relationship.selected.aIsToB ? $scope.selectedTei.trackedEntityInstance : $scope.teiForRelationship.id;
relationship.trackedEntityInstanceB = $scope.selectedRelationship.bIsToA === $scope.relationship.selected.bIsToA ? $scope.teiForRelationship.id : $scope.selectedTei.trackedEntityInstance;
-
- if($scope.selectedTei.relationships){
- $scope.selectedTei.relationships.push(relationship);
- }
- else{
- $scope.selectedTei.relationships = [relationship];
- }
-
- TEIService.update($scope.selectedTei, $scope.optionSets).then(function(response){
+
+ tei.relationships = [];
+ angular.forEach($scope.selectedTei.relationships, function(rel){
+ tei.relationships.push({relationship: rel.relationship, displayName: rel.displayName, trackedEntityInstanceA: rel.trackedEntityInstanceA, trackedEntityInstanceB: rel.trackedEntityInstanceB});
+ });
+ tei.relationships.push(relationship);
+
+ TEIService.update(tei, $scope.optionSets).then(function(response){
if(response.status !== 'SUCCESS'){//update has failed
var dialogOptions = {
headerText: 'relationship_error',
@@ -410,6 +448,16 @@
return;
}
+ relationship.relative.processed = true;
+ relationship.relative.attributes = $scope.teiForRelationship;
+
+ if($scope.selectedTei.relationships){
+ $scope.selectedTei.relationships.push(relationship);
+ }
+ else{
+ $scope.selectedTei.relationships = [relationship];
+ }
+
$modalInstance.close($scope.selectedTei.relationships);
});
}
=== 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 2015-02-24 13:10:51 +0000
+++ dhis-2/dhis-web/dhis-web-apps/src/main/webapp/dhis-web-tracker-capture/components/relationship/relationship.html 2015-02-24 16:15:59 +0000
@@ -21,12 +21,23 @@
<div ng-show="selectedTei && !selectedTei.relationships || selectedTei.relationships.length < 1" class="alert alert-warning">{{'no_relationship'| translate}}</div>
<div ng-show="!selectedTei" class="alert alert-danger">{{'relationship_not_possible'| translate}}</div>
- <div ng-show="selectedTei" class="remove-default-padding">
- <table class="table table-striped dhis2-table-hover">
+ <div ng-if="relatedTeis">
+ <table class="table table-striped dhis2-table-hover table-bordered">
+ <tr>
+ <th>
+ {{'relationship' | translate}}
+ </th>
+ <th ng-repeat="att in attributes" ng-if="att.displayInListNoProgram">
+ {{att.name}}
+ </th>
+ </tr>
<tr ng-click="showDashboard(rel.trackedEntityInstance, rel.relId)" ng-repeat="rel in relatedTeis" title="{{'go_to_dashboard'| translate}}">
<td>{{rel.relName}}</td>
+ <td ng-repeat="att in attributes" ng-if="att.displayInListNoProgram">
+ {{rel.attributes[att.id]}}
+ </td>
</tr>
- </table>
+ </table>
</div>
</div>
</div>
\ No newline at end of file