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

feature: yes/no site_name (hidden) #119

Open
wants to merge 8 commits into
base: master
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
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,9 @@ angular.module( 'ngm.widget.project.details', [ 'ngm.provider' ])
// Set limited amount of locations
$scope.paginated_target_locations = $scope.project.definition.target_locations.slice($scope.start, $scope.end);
// set admin1,2,3,4,5 && site_type && site_implementation
ngmClusterLocations.fetchInitialAdminSites($scope.project, $scope.project.definition.target_locations);
// set admin1,2,3,4,5 && site_type && site_implementation,
// comment this function, because move to fetchInitalAdminSites
ngmClusterLocations.setLocationAdminSelect($scope.project, $scope.project.definition.target_locations);
// documents uploads
$scope.project.setTokenUpload();
Expand Down Expand Up @@ -3018,6 +3021,14 @@ angular.module( 'ngm.widget.project.details', [ 'ngm.provider' ])
// },

// <++++++++++++++++++++++++++++++++++++++++++++++++++++++++>
// set location site_name_checked if not set before
setSiteNameChecked:function(location){
if (location.admin0pcode === 'ET'){
if (!location.site_name_checked){
location.site_name_checked = location.site_name? true: false;
}
}
},



Expand Down
148 changes: 136 additions & 12 deletions app/scripts/modules/cluster/reports/services/ngmClusterLocations.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
*/
angular.module( 'ngmReportHub' )
.factory( 'ngmClusterLocations', [ '$http', '$filter', '$timeout', 'ngmAuth','$translate', '$rootScope', 'ngmClusterBeneficiaries', 'ngmCbLocations', function( $http, $filter, $timeout, ngmAuth, $translate, $rootScope, ngmClusterBeneficiaries, ngmCbLocations ) {
.factory('ngmClusterLocations', ['$q', '$http', '$filter', '$timeout', 'ngmAuth', '$translate', '$rootScope', 'ngmClusterBeneficiaries', 'ngmCbLocations', function ($q, $http, $filter, $timeout, ngmAuth, $translate, $rootScope, ngmClusterBeneficiaries, ngmCbLocations ) {

ngmClusterLocations = {

Expand All @@ -26,8 +26,24 @@ angular.module( 'ngmReportHub' )
});
// trigger form update
ngmClusterLocations.adminOnChange( project.lists, 'admin3pcode', locations.length-1, ngmClusterLocations.new_location.admin3pcode, ngmClusterLocations.new_location );
ngmClusterLocations.filterLocations(project, 0, ngmClusterLocations.new_location)
// ngmClusterLocations.filterLocations(project, 0, ngmClusterLocations.new_location)
ngmClusterLocations.setSiteTypeAndImplementationSelect(project);
// check if this admin1pcode have adminsite or not
var selected_sites = $filter('filter')(project.lists.adminSites, { admin1pcode: ngmClusterLocations.new_location.admin1pcode }, true);
if(!selected_sites.length){
$http({
method: 'GET',
url: ngmAuth.LOCATION + '/api/list/getAdminSites?admin0pcode='
+ project.definition.admin0pcode
+ '&admin1pcode=' + ngmClusterLocations.new_location.admin1pcode
}).then(function (result) {
project.lists.adminSites = project.lists.adminSites.concat(result.data);
ngmClusterLocations.filterLocations(project, 0, ngmClusterLocations.new_location)

});
}else{
ngmClusterLocations.filterLocations(project, 0, ngmClusterLocations.new_location)
}
// lists, pcode, $index, $data, target_location
ngmClusterLocations.openAddNewLocation = !ngmClusterLocations.openAddNewLocation;
},
Expand Down Expand Up @@ -64,12 +80,12 @@ angular.module( 'ngmReportHub' )
username: project.username
}

// add site select if admin0pcode !== 'CB'
if ( project.admin0pcode !== 'CB' ) {
inserted.site_list_select_id = 'no';
inserted.site_list_select_yes = 'No';
inserted.site_list_select_disabled = true;
}
// // add site select if admin0pcode !== 'CB'
// if ( project.admin0pcode !== 'CB' ) {
// inserted.site_list_select_id = 'no';
// inserted.site_list_select_yes = 'No';
// inserted.site_list_select_disabled = true;
// }

// clone
var length = locations.length;
Expand All @@ -93,11 +109,19 @@ angular.module( 'ngmReportHub' )
inserted.implementing_partners = angular.copy(project.implementing_partners)
}

// add site select if admin0pcode !== 'CB'
if (project.admin0pcode !== 'CB') {
inserted.site_list_select_id = 'no';
inserted.site_list_select_yes = 'No';
inserted.site_list_select_disabled = true;
}

// set createdAt
inserted.createdAt = new Date().toISOString();

if (project.admin0pcode === 'ET') {
// inserted.site_name_checked = false;
// //hide feature , if new location admin0pcode is ET / ethiopia set attribute site_name_checked to true for now its hide
// inserted.site_name_checked = true;
inserted.site_name = '';
}
// set targets
Expand Down Expand Up @@ -510,7 +534,7 @@ angular.module( 'ngmReportHub' )
}, 10)
},
// to update site type
updateSiteType: function (lists, location) {
updateSiteType: function (project,lists, location,$index) {
$timeout(function () {
// attr
var selected = [];
Expand All @@ -529,6 +553,21 @@ angular.module( 'ngmReportHub' )
location.site_type_name = selected[0].site_type_name;
}
}

// to filter adminssites if site_type_id change;
ngmClusterLocations.filterLocations(project, $index, location);
// remove and set it like location do not have adminsite list if adminSitesSelect empty when site_type_id not on the lists
// and change from "yes" to "no" on site_list_select_id attributie;
if (!ngmClusterLocations.adminSitesSelect[$index].length && location.site_list_select_id === 'yes') {
location.site_list_select_id = 'no';
location.site_list_select_yes = 'No';
location.site_list_select_disabled = true;
// site
delete location.site_id;
delete location.site_name;
delete location.site_lng;
delete location.site_lat;
}
}, 10)
},
// to Update sit name
Expand All @@ -548,7 +587,7 @@ angular.module( 'ngmReportHub' )
delete selected[0].id;

console.log( selected[0].site_name )

angular.merge(location, selected[0]);
}
}
Expand All @@ -569,7 +608,11 @@ angular.module( 'ngmReportHub' )
selected = $filter('filter')(lists.site_list_select, { site_list_select_id: location.site_list_select_id }, true);
location.site_list_select_name = selected[0].site_list_select_name;
}


if (location.site_list_select_id && location.site_list_select_id === 'no'){
location.site_name = '';
location.site_id = '';
}
}, 10)
},
// fail
Expand Down Expand Up @@ -743,6 +786,17 @@ angular.module( 'ngmReportHub' )
return i.admin5pcode === location.admin5pcode;
});
}
if(ngmClusterLocations.adminSitesSelect[$index].length){
// to ensure the site_id is string
ngmClusterLocations.adminSitesSelect[$index].map((x) => {if (typeof x.site_id === 'number' ){ x.site_id = x.site_id.toString();} return x});


// filter based on site_type_id
ngmClusterLocations.adminSitesSelect[$index] = ngmClusterLocations.adminSitesSelect[$index].filter(function (i) {
return i.site_type_id === location.site_type_id;
});
// }
}
},
// reset location property
resetLocations: function (project, type, location) {
Expand Down Expand Up @@ -805,6 +859,26 @@ angular.module( 'ngmReportHub' )
angular.forEach(locations, function (location, $index) {
ngmClusterLocations.filterLocations(project, $index, location);
});

// var locationAdmin1pcodeTag = [];
// angular.forEach(locations, function (location, $index) {

// $http({
// method: 'GET',
// url: ngmAuth.LOCATION + '/api/list/getAdminSites?admin0pcode='
// + project.definition.admin0pcode
// + '&admin1pcode=' + location.admin1pcode
// }).then(function (result) {
// if (locationAdmin1pcodeTag.indexOf(location.admin1pcode) < 0) {
// project.lists.adminSites = project.lists.adminSites.concat(result.data);
// ngmClusterLocations.filterLocations(project, $index, location);
// locationAdmin1pcodeTag.push(location.admin1pcode)
// }
// ngmClusterLocations.filterLocations(project, $index, location);
// });


// });
},
// to set list of site_type && site_implementation
setSiteTypeAndImplementationSelect: function (project) {
Expand Down Expand Up @@ -842,6 +916,56 @@ angular.module( 'ngmReportHub' )
ngmClusterLocations.site_implementationFilter = ngmClusterLocations.site_implementationFilter.filter((item, index) => ngmClusterLocations.site_implementationFilter.indexOf(item) === index);
ngmClusterLocations.site_typeFilter = ngmClusterLocations.site_typeFilter.filter((item, index) => ngmClusterLocations.site_typeFilter.indexOf(item) === index);
}
},
// site_namechecked field show
// function to reset attribute site_name,site_list_select_id,site_list_select_name, site_list_select_disabled, when site_name_checked attrbute set to false/unchecked
siteNameCheckedReset:function(location){
if (!location.site_name_checked){
location.site_name ='';
if (location.site_list_select_id){
location.site_list_select_id = 'no';
location.site_list_select_name = 'No';
location.site_list_select_disabled = true;
}
}
},
fetchInitialAdminSites:function(project,locations){

var admin1=[];
var req_adminsites =[]
if(locations.length){
angular.forEach(locations, function (location, $index) {
if (((location.site_list_select_id)) || location.site_type){
var selected_sites = $filter('filter')(project.lists.adminSites, { admin1pcode: location.admin1pcode }, true);
// check if adminsites for admin1pcode is on the list, if not on the list make request
if (!selected_sites.length && admin1.indexOf(location.admin1pcode) < 0) {
admin1.push(location.admin1pcode)
var request = $http({
method: 'GET',
url: ngmAuth.LOCATION + '/api/list/getAdminSites?admin0pcode='
+ project.definition.admin0pcode
+ '&admin1pcode=' + location.admin1pcode
})
req_adminsites.push(request);
}
}

});

// make request
if(req_adminsites.length){
$q.all(req_adminsites).then(function (results) {

for(var i=0;i<results.length ;i++){
project.lists.adminSites = project.lists.adminSites.concat(results[i].data)
}
// set admin1, 2, 3, 4, 5 && site_type && site_implementation
ngmClusterLocations.setLocationAdminSelect(project, locations)

})
}
}

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ angular.module( 'ngmReportHub' )
var rowComplete = 0;
angular.forEach( project.target_locations, function( d, i ){
if ( d.admin1pcode && d.admin1name && d.admin2pcode && d.admin2name){
if (d.admin0pcode === 'ET') {
if ((d.admin0pcode === 'NG') || (d.admin0pcode === 'ET' && !d.site_name_checked)) {
rowComplete++;
}else{
if (d.site_name) {
Expand Down Expand Up @@ -268,7 +268,7 @@ angular.module( 'ngmReportHub' )
}
// console.log('targetlocation-complete02');
// console.log(complete);
if (l.admin0pcode !== 'ET'){
if ((l.admin0pcode !== 'ET') || (l.admin0pcode === 'ET' && l.site_name_checked)){
if (!l.site_name) {
id = "label[for='" + 'ngm-site_name-' + i + "']";
$(id).addClass('error');
Expand Down Expand Up @@ -3029,7 +3029,7 @@ angular.module( 'ngmReportHub' )
complete = false;
}

if (l.admin0pcode !== 'ET') {
if (l.admin0pcode !== 'ET' || (l.admin0pcode === 'ET' && l.site_name_checked)) {
if(!l.site_name){
id = "label[for='ngm-new_location-site_name']";
$(id).addClass('error');
Expand Down
Loading