Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: auto switch orgunit from search modal #1268

Open
wants to merge 2 commits into
base: v35
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions components/home/search/search-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ trackerCapture.controller('SearchController',function(
//Open TEI if unique and in same search scope and in selected org unit
if(gridData.rows.own.length ===1 && res.callingScope === res.resultScope && searchGroup.uniqueGroup){
$scope.searching = null;
openTei(gridData.rows.own[0]);
openTei(gridData.rows.own[0], [$scope.selectedOrgUnit.id]);
return;
}
} else if(rowsCnt > 0){
Expand All @@ -230,14 +230,18 @@ trackerCapture.controller('SearchController',function(
}
}

var openTei = function(tei, fromAudit){
var openTei = function(tei, programOwners, fromAudit){
if($scope.searchingForRelatedTei) {
$rootScope.$broadcast('assignRelationshipTei', tei);
} else {
$location.path('/dashboard').search({tei: tei.id,
program: $scope.base.selectedProgramForSearch ? $scope.base.selectedProgramForSearch.id: null,
ou: $scope.selectedOrgUnit.id,
fromAudit: fromAudit});
AccessUtils.withinUserHierarchy(programOwners[0].ownerOrgUnit).then(function(response) {
$location.path('/dashboard').search({tei: tei.id,
program: $scope.base.selectedProgramForSearch ? $scope.base.selectedProgramForSearch.id: null,
ou: response ? programOwners[0].ownerOrgUnit : $scope.selectedOrgUnit.id,
fromAudit: fromAudit});
}).catch(function(error) {
console.log("error opening TEI from search modal: ", error);
});
}
}

Expand Down Expand Up @@ -385,7 +389,7 @@ trackerCapture.controller('SearchController',function(
$scope.openTei = function(tei){
if(internalService.base.selectedProgramForSearch && internalService.base.selectedProgramForSearch.id){
TEIService.getWithProgramData(tei.id, internalService.base.selectedProgramForSearch.id, internalService.base.optionSets, internalService.base.attributesById).then(function(resultTei){
$modalInstance.close({ action: "OPENTEI", tei: tei, fromAudit: true});
$modalInstance.close({ action: "OPENTEI", tei: tei, programOwners: resultTei.programOwners, fromAudit: true});
}, function(error){
if(error && !error.auditDismissed && error.data && error.data.message){
var headerText = $translate.instant('open_tei_error');
Expand Down Expand Up @@ -444,7 +448,7 @@ trackerCapture.controller('SearchController',function(
var def = $q.defer();
def.resolve();
if(res.action === "OPENTEI"){
openTei(res.tei, res.fromAudit);
openTei(res.tei, res.programOwners, res.fromAudit);
}else if(res.action === "OPENREGISTRATION")
{
var registrationPrefill = getRegistrationPrefill(searchGroup);
Expand Down
8 changes: 7 additions & 1 deletion scripts/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -3311,7 +3311,7 @@ i
}
}
})
.service('AccessUtils', function($q, TCStorageService){
.service('AccessUtils', function($http, $q, TCStorageService){

this.anyWritable = function(accessKeyValuePair){
if(accessKeyValuePair){
Expand Down Expand Up @@ -3346,6 +3346,12 @@ i
});
return writable;
}

this.withinUserHierarchy = function(ou) {
return $http.get(DHIS2URL + '/organisationUnits?withinUserHierarchy=true&fields=id&filter=id:eq:' + ou).then(function(response) {
return response.data.organisationUnits.length !== 0;
});
}
})
.service('TCOrgUnitService', function($q, $rootScope, TCStorageService, OrgUnitFactory){
this.get = function(uid) {
Expand Down