Skip to content

Commit

Permalink
Implement replacement of ou for mechanism that are acted upon from gl…
Browse files Browse the repository at this point in the history
…obal levels.
  • Loading branch information
Markionium committed Apr 30, 2015
1 parent 045eec1 commit f73e205
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 22 deletions.
9 changes: 4 additions & 5 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var dhis_directory = '/usr/local/apache-tomcat-8.0.5/webapps/dhis/dhis-web-pepfar-approvals/';
var dhis_directory = '/usr/local/apache-tomcat-8.0.5/webapps/dhis/apps/approvals/';
var build_directory = 'build';

var files = [
Expand Down Expand Up @@ -297,13 +297,12 @@ gulp.task('build-prod', function (cb) {
});

gulp.task('deploy', function () {
return gulp.src([
'build/**/*'
]).pipe(gulp.dest('/usr/local/apache-tomcat-8.0.5/webapps/dhis/apps/approvals'));
return gulp.src(['build-with-rev/**/*'])
.pipe(gulp.dest(dhis_directory));
});

gulp.task('default', function (cb) {
rimraf(dhis_directory, function () {});
rimraf(dhis_directory, cb);
runSequence('build', 'deploy', cb);
});

Expand Down
26 changes: 11 additions & 15 deletions src/main/dataview-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,17 @@ function dataViewController($scope, approvalsService, $translate, $log) {
return approvalParams;

function determineOu(mechanism, action) {
if (action === 'submit' && mechanism.level === 2 && isGlobal()) {
return $scope.globalUser.globalOUId;
if (isGlobal()) {
//Adjust the mechanisms ou for any actions that happen on the global level
if (mechanism.level === 1) {
//Adjust the mechanisms ou for any actions that happen on the global level
$log.info(mechanism, 'is on level 1 therefore we replace the ou with', $scope.globalUser.globalOUId);
return $scope.globalUser.globalOUId;
}
if (mechanism.level === 2 && mechanism.accepted === true && action === 'submit') {
$log.info(mechanism, 'is about to be submitted from level 2 and is accepted therefore we replace the ou with', $scope.globalUser.globalOUId);
return $scope.globalUser.globalOUId;
}
}

return mechanism.organisationUnit;
Expand All @@ -124,15 +133,6 @@ function dataViewController($scope, approvalsService, $translate, $log) {
}
}

function replaceOuWithGlobalOu(approvalParams) {
if ($scope.globalUser && $scope.globalUser.isGlobalUser && $scope.globalUser.globalOUId) {
$log.info('Replace the ou for each of the mechanisms with the global ou id: ' + $scope.globalUser.globalOUId);
approvalParams.approvals.forEach(function (approvalRecord) {
approvalRecord.ou = $scope.globalUser.globalOUId;
});
}
}

this.submit = function (ids) {
var params = this.getParamsForMechanism();
var mechanisms = this.getMechanismsByIds(ids);
Expand All @@ -143,8 +143,6 @@ function dataViewController($scope, approvalsService, $translate, $log) {
if (this.isParamsComplete()) {
approvalParams = prepareApprovalServiceParams(params, mechanisms, 'submit');

replaceOuWithGlobalOu(approvalParams);

if (approvalParams.approvals.length > 0) {
approvalsService.approve(approvalParams).then(getActionCallBackFor('submit', mechanisms), actionErrorCallBack);
}
Expand Down Expand Up @@ -177,8 +175,6 @@ function dataViewController($scope, approvalsService, $translate, $log) {
if (this.isParamsComplete()) {
approvalParams = prepareApprovalServiceParams(params, mechanisms, 'unapprove');

replaceOuWithGlobalOu(approvalParams);

if (approvalParams.approvals.length > 0) {
approvalsService.unapprove(approvalParams).then(getActionCallBackFor('unsubmit', mechanisms), actionErrorCallBack);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/manifest.webapp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version":"0.3.4","name":"Data Approval","description":"Approvals app for PEPFAR","icons":{"48":"img/icons/dataapproval.png"},"developer":{"url":"http://www.dhis2.org","name":"Mark Polak","company":"DHIS2 Core Team","email":"[email protected]"},"launch_path":"index.html","default_locale":"en","activities":{"dhis":{"href":"*"}}}
{"version":"0.4.0","name":"Data Approval","description":"Approvals app for PEPFAR","icons":{"48":"img/icons/dataapproval.png"},"developer":{"url":"http://www.dhis2.org","name":"Mark Polak","company":"DHIS2 Core Team","email":"[email protected]"},"launch_path":"index.html","default_locale":"en","activities":{"dhis":{"href":"*"}}}
4 changes: 3 additions & 1 deletion src/main/mechanism/mechanisms-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ function mechanismsService(d2Api, $log, $q, approvalLevelsService, request, cate
mechanisms = [];

//TODO: Refactor this function
//jshint maxcomplexity:16, maxstatements:41
//jshint maxcomplexity:16, maxstatements:43
_.each(mechanismsStatuses, function (mechanismStatus) {
var actions = [];
var status = [];
Expand Down Expand Up @@ -264,8 +264,10 @@ function mechanismsService(d2Api, $log, $q, approvalLevelsService, request, cate
mechanism.mayReadData = false;
}

mechanism.accepted = false;
if (approvalLevel) {
if (mechanismStatus.accepted === true) {
mechanism.accepted = true;
status.push('Accepted');
if (mechanismStatus.level && mechanismStatus.level.level) {
approvalLevel = _.find(approvalLevels, {level: (parseInt(mechanismStatus.level.level) - 1)});
Expand Down

0 comments on commit f73e205

Please sign in to comment.