Skip to content

Commit

Permalink
Merge af90055 into 69e68ee
Browse files Browse the repository at this point in the history
  • Loading branch information
musamusa committed Jun 13, 2015
2 parents 69e68ee + af90055 commit 9130bbe
Show file tree
Hide file tree
Showing 4 changed files with 299 additions and 24 deletions.
195 changes: 183 additions & 12 deletions app/scripts/controllers/app-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@ angular.module('lmisChromeApp')
$scope.isSubmitted = false;
$scope.preSelectProductProfileCheckBox = {};
$scope.stockCountIntervals = appConfigService.stockCountIntervals;
$scope.serialNumber = {};
$scope.errorMsg = {};
$scope.firstConfig = true;

//TODO: load state id dynamically.
locationService.getLgas("f87ed3e017cf4f8db26836fd910e4cc8")
.then(function(res) {
$scope.lgaList = res;
})
.catch(function(err) {
console.error(err);
});

$scope.currentStep = $scope.STEP_ONE; //set initial step

Expand Down Expand Up @@ -211,14 +223,14 @@ angular.module('lmisChromeApp')
$scope.ccuProfilesCategories = Object.keys(result);
$scope.ccuProfilesGroupedByCategory = result;
});
};
}
function productProfilesGroupedByCategory () {
$q.when(productProfileFactory.getAllGroupedByCategory())
.then(function(result){
$scope.productProfileCategories = Object.keys(result);
$scope.productProfilesGroupedByCategory = result;
});
};
}


//TODO: load state id dynamically.
Expand Down Expand Up @@ -248,6 +260,7 @@ angular.module('lmisChromeApp')


$scope.onCcuSelection = function(ccuProfile) {
toggleRow(ccuProfile);
$scope.appConfig.selectedCcuProfiles =
utility.addObjectToCollection(ccuProfile, $scope.appConfig.selectedCcuProfiles, 'dhis2_modelid');
$scope.preSelectCcuProfiles = utility.castArrayToObject($scope.appConfig.selectedCcuProfiles, 'dhis2_modelid');
Expand All @@ -271,7 +284,7 @@ angular.module('lmisChromeApp')
$scope.appConfig.facility.selectedZones = utility.addObjectToCollection(zone, $scope.appConfig.facility.selectedZones, '_id');
$scope.preSelectZoneCheckBox = utility.castArrayToObject($scope.appConfig.facility.selectedZones, '_id');

}
};
$scope.save = function() {
$scope.isSaving = true;
var nearbyLgas = $scope.appConfig.facility.selectedLgas
Expand Down Expand Up @@ -299,8 +312,83 @@ angular.module('lmisChromeApp')
});
});
};

$scope.addSerialNumber = function() {
var ccuItemID = Object.keys($scope.selectedCCEItem)[0];
var ccuProfile = $scope.preSelectCcuProfiles[ccuItemID];
ccuProfile.serialNumbers = ccuProfile.serialNumbers || [];
$scope.errorMsg[ccuItemID] = '';

if (ccuProfile.serialNumbers.indexOf($scope.serialNumber[ccuItemID]) !== -1) {
$scope.errorMsg[ccuItemID] = 'Duplicate entry! serial already exist';
return;
}

if ($scope.serialNumber[ccuItemID] === '' || angular.isUndefined($scope.serialNumber[ccuItemID]) ||
ccuProfile.serialNumbers.indexOf($scope.serialNumber[ccuItemID]) !== -1) {
growl.error('enter a value to add');
return;
}

ccuProfile.serialNumbers.push($scope.serialNumber[ccuItemID]);
$scope.preSelectCcuProfiles = utility.castArrayToObject($scope.appConfig.selectedCcuProfiles, 'dhis2_modelid');

$scope.serialNumber[ccuItemID] = '';
};

$scope.removeSerial = function(ccuProfile, index) {
$scope.errorMsg[ccuProfile.dhis2_modelid] = '';
var confirmationTitle = 'Remove Serial Number';
var confirmationQuestion = i18n('dialogConfirmationQuestion');
var buttonLabels = [i18n('yes'), i18n('no')];

notificationService.getConfirmDialog(confirmationTitle, confirmationQuestion, buttonLabels)
.then(function(isConfirmed) {
if (isConfirmed === true) {
ccuProfile.serialNumbers.splice(index, 1);
}
})
.catch(function(reason) {

});
};

function resetRowState() {
$scope.selectedCCEItem = {};
}

function toggleRow(ccuProfile) {
$scope.errorMsg[ccuProfile.dhis2_modelid] = '';
if (!angular.isObject(ccuProfile)) {
ccuProfile = JSON.parse(ccuProfile);
}

if (!$scope.preSelectCcuProfiles[ccuProfile.dhis2_modelid]) {
growl.error('Equipment need to be selected to add serial number');
}

if (utility.isEmptyObject($scope.selectedCCEItem)) {
$scope.selectedCCEItem[ccuProfile.dhis2_modelid] = true;
} else if ($scope.selectedCCEItem.hasOwnProperty(ccuProfile.dhis2_modelid)) {
$scope.selectedCCEItem[ccuProfile.dhis2_modelid] = !$scope.selectedCCEItem[ccuProfile.dhis2_modelid];
} else {
resetRowState();
$scope.selectedCCEItem[ccuProfile.dhis2_modelid] = true;
}

if ($scope.ccuProfileCheckBoxes[ccuProfile.dhis2_modelid]) {
var selectedCCU = JSON.parse($scope.ccuProfileCheckBoxes[ccuProfile.dhis2_modelid]);
if (selectedCCU.deSelected) {
resetRowState();
}
}
}

$scope.toggleRow = toggleRow;
resetRowState();

})
.controller('EditAppConfigCtrl', function($scope, fixtureLoaderService, locationService, $rootScope, appConfigService, growl, $log, i18n, $state, appConfig, ccuProfilesGroupedByCategory, productProfilesGroupedByCategory, utility, alertFactory, $filter) {
.controller('EditAppConfigCtrl', function($scope, fixtureLoaderService, locationService, $rootScope, appConfigService, growl, $log, i18n, $state, appConfig, ccuProfilesGroupedByCategory, productProfilesGroupedByCategory, utility, alertFactory, $filter, notificationService) {

$scope.spaceOutUpperCaseWords = utility.spaceOutUpperCaseWords;
var oldLgas = [];
Expand Down Expand Up @@ -342,6 +430,8 @@ angular.module('lmisChromeApp')
$scope.developerMode = false;
$rootScope.developerMode = false;
$scope.lgaList = [];
$scope.serialNumber = {};
$scope.errorMsg = {};


var noOfAttempts = 0;
Expand All @@ -356,6 +446,81 @@ angular.module('lmisChromeApp')
}
};

$scope.addSerialNumber = function() {
var ccuItemID = Object.keys($scope.selectedCCEItem)[0];
var ccuProfile = $scope.preSelectCcuProfiles[ccuItemID];
ccuProfile.serialNumbers = ccuProfile.serialNumbers || [];
$scope.errorMsg[ccuItemID] = '';

if (ccuProfile.serialNumbers.indexOf($scope.serialNumber[ccuItemID]) !== -1) {
$scope.errorMsg[ccuItemID] = 'Duplicate entry! serial already exist';
return;
}

if ($scope.serialNumber[ccuItemID] === '' || angular.isUndefined($scope.serialNumber[ccuItemID]) ||
ccuProfile.serialNumbers.indexOf($scope.serialNumber[ccuItemID]) !== -1) {
growl.error('enter a value to add');
return;
}

ccuProfile.serialNumbers.push($scope.serialNumber[ccuItemID]);
$scope.preSelectCcuProfiles = utility.castArrayToObject($scope.appConfig.selectedCcuProfiles, 'dhis2_modelid');

$scope.serialNumber[ccuItemID] = '';
};

$scope.removeSerial = function(ccuProfile, index) {
$scope.errorMsg[ccuProfile.dhis2_modelid] = '';
var confirmationTitle = 'Remove Serial Number';
var confirmationQuestion = i18n('dialogConfirmationQuestion');
var buttonLabels = [i18n('yes'), i18n('no')];

notificationService.getConfirmDialog(confirmationTitle, confirmationQuestion, buttonLabels)
.then(function(isConfirmed) {
if (isConfirmed === true) {
ccuProfile.serialNumbers.splice(index, 1);
}
})
.catch(function(reason) {

});
};

function resetRowState() {
$scope.selectedCCEItem = {};
}

function toggleRow(ccuProfile) {

if (!$scope.preSelectCcuProfiles[ccuProfile.dhis2_modelid]) {
growl.error('Equipment need to be selected to add serial number');
}

$scope.errorMsg[ccuProfile.dhis2_modelid] = '';
if (!angular.isObject(ccuProfile)) {
ccuProfile = JSON.parse(ccuProfile);
}

if (utility.isEmptyObject($scope.selectedCCEItem)) {
$scope.selectedCCEItem[ccuProfile.dhis2_modelid] = true;
} else if ($scope.selectedCCEItem.hasOwnProperty(ccuProfile.dhis2_modelid)) {
$scope.selectedCCEItem[ccuProfile.dhis2_modelid] = !$scope.selectedCCEItem[ccuProfile.dhis2_modelid];
} else {
resetRowState();
$scope.selectedCCEItem[ccuProfile.dhis2_modelid] = true;
}

if ($scope.ccuProfileCheckBoxes[ccuProfile.dhis2_modelid]) {
var selectedCCU = JSON.parse($scope.ccuProfileCheckBoxes[ccuProfile.dhis2_modelid]);
if (selectedCCU.deSelected) {
resetRowState();
}
}
}

$scope.toggleRow = toggleRow;
resetRowState();

var setAppConfigLastUpdatedViewInfo = function(appConfig) {
if (utility.has(appConfig, 'lastUpdated')) {
var updatedDate = $filter('date')(new Date(appConfig.lastUpdated), 'yyyy-MM-dd HH:mm:ss');
Expand All @@ -382,7 +547,6 @@ angular.module('lmisChromeApp')
$scope.preSelectCcuProfiles = utility.castArrayToObject(appConfig.selectedCcuProfiles, 'dhis2_modelid');
$scope.preSelectProductProfileCheckBox = utility.castArrayToObject($scope.appConfig.facility.selectedProductProfiles, 'uuid');
}

//pre-load edit app facility profile config form with existing config.
preLoadConfigForm(appConfig);
//TODO: load state id dynamically.
Expand All @@ -403,6 +567,7 @@ angular.module('lmisChromeApp')
});

$scope.onCcuSelection = function(ccuProfile) {
toggleRow(ccuProfile);
$scope.appConfig.selectedCcuProfiles =
utility.addObjectToCollection(ccuProfile, $scope.appConfig.selectedCcuProfiles, 'dhis2_modelid');
$scope.preSelectCcuProfiles = utility.castArrayToObject($scope.appConfig.selectedCcuProfiles, 'dhis2_modelid');
Expand All @@ -425,7 +590,7 @@ angular.module('lmisChromeApp')
$scope.appConfig.facility.selectedZones =
utility.addObjectToCollection(zone, $scope.appConfig.facility.selectedZones, '_id');
$scope.preSelectZoneCheckBox = utility.castArrayToObject($scope.appConfig.facility.selectedZones, '_id');
}
};

var isSameLgas = function(old, recent) {
if (old.length !== recent.length) {
Expand All @@ -443,13 +608,19 @@ angular.module('lmisChromeApp')
return hasOddElem;
};

var saveAppConfig = function() {
var saveAppConfig = function(forSerial) {
appConfigService.setup($scope.appConfig)
.then(function(result) {
if (typeof result !== 'undefined') {
$scope.appConfig = result;
alertFactory.success(i18n('appConfigSuccessMsg'));
$state.go('home.index.home.mainActivity');
if (forSerial) {
growl.success(i18n('appConfigSuccessMsg'));
}
if (!forSerial) {
$scope.appConfig = result;
alertFactory.success(i18n('appConfigSuccessMsg'));
$state.go('home.index.home.mainActivity');
}

} else {
growl.error(i18n('appConfigFailedMsg'));
}
Expand All @@ -469,10 +640,10 @@ angular.module('lmisChromeApp')
});
};

$scope.save = function() {
$scope.save = function(forSerial) {
$scope.isSaving = true;
if (isSameLgas(oldLgas, $scope.appConfig.facility.selectedLgas)) {
saveAppConfig();
saveAppConfig(forSerial);
} else {
var nearbyLgas = $scope.appConfig.facility.selectedLgas
.map(function(lga) {
Expand Down
11 changes: 11 additions & 0 deletions app/scripts/services/utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,4 +258,15 @@ angular.module('lmisChromeApp')
});
return picked;
};

/**
*
* @param object
* @returns {boolean}
*/

this.isEmptyObject = function(object) {
object = angular.isObject(object) ? object : {};
return (Object.keys(object)).length === 0 ;
}
});
19 changes: 17 additions & 2 deletions app/styles/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ accordion .panel-heading:hover {
}
.counter-btn {
font-size: 25.5pt;
padding: 0.1em, 0.2em;
padding: 0.1em 0.2em;
height: 2.2em;
}
.counter-input{
Expand Down Expand Up @@ -243,7 +243,7 @@ tr.disabled, tr.disabled span.text-info{
.cold-store-vaccines{
border-color: #157085;
}
.dry-store-safety-boxes>.panel-heading, .dry-store-syringes>.panel-heading, tr.dry-store-syringes, tr dry-store-syringes {
.dry-store-safety-boxes>.panel-heading, .dry-store-syringes>.panel-heading, tr.dry-store-syringes, tr .dry-store-syringes {
background-color: #8B4A09;
color: #FFFFFF;
}
Expand Down Expand Up @@ -278,3 +278,18 @@ tr.disabled, tr.disabled span.text-info{
border-left: 4px solid #6eca97 !important;
border-right: 4px solid #6eca97 !important;
}
.serial-list{
position: relative;
display: block;
padding: 5px 15px;
margin-bottom: -1px;
background-color: #f1f1f1;
border: 2px solid #dddddd;
}
.serial-btn{
margin-top: 3px;
margin-right: 3px;
}
.pb10{
padding-bottom: 10px;
}

0 comments on commit 9130bbe

Please sign in to comment.