Skip to content

Commit

Permalink
A lot of pinwheel on project and country pages #222
Browse files Browse the repository at this point in the history
  • Loading branch information
KseniyaKuprina committed Nov 8, 2016
1 parent 3d2016e commit 765d6e6
Show file tree
Hide file tree
Showing 8 changed files with 504 additions and 477 deletions.
22 changes: 5 additions & 17 deletions public/app/dynamic/projects/nrgiProjectDetailCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,11 @@ angular.module('app')
$routeParams
) {
nrgiProjectsSrvc.get({_id: $routeParams.id}, function (success) {
//var _ = $rootScope._;
$scope.project = success;
// console.log(success.proj_operated_by);
//_.each($scope.project.companies, function(company) {
// company.operator = false;
// _.each($scope.project.proj_company_share, function(company_share) {
// if (company._id==company_share.company) {
// company.stake = {share: company_share.number, timestamp: company_share.timestamp}
// }
// });
//
// // _.each($scope.project.proj_operated_by, function(company_op) {
// // if (company._id==company_op.company) {
// // company.operator = true;
// // }
// // })
//});
if(success.error) {
$scope.error= success.error;
}else{
$scope.project = success;
}
});
});

Expand Down
7 changes: 6 additions & 1 deletion public/app/dynamic/projects/project-detail.jade
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
.container
.container(ng-if="error")
.pagetitle
.row
.col-lg-12.text-center.not_found.
Project not found
.container(ng-if="project")
.pagetitle
h1
span(ng-bind-html="project.proj_name|sanitize")
Expand Down
4 changes: 3 additions & 1 deletion public/css/modules/tables.styl
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,6 @@ table .table-header-fixed
margin-bottom 90px !important
.transfer_value
text-align justify
direction rtl
direction rtl
.not_found
padding 15%
3 changes: 3 additions & 0 deletions public/css/site.css
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,9 @@ table .table-header-fixed {
text-align: justify;
direction: rtl;
}
.not_found {
padding: 15%;
}
@-moz-keyframes sk-bounce {
0%, 100% {
transform: scale(0);
Expand Down
228 changes: 116 additions & 112 deletions server/controllers/concessions.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,132 +250,136 @@ exports.getConcessionByID = function(req, res) {
if(concession) {
callback(null, concession);
} else {
callback(err);
callback(null, concession);
}
});
}

function getConcessionLinks(concession, callback) {
concession.contracts = [];
concession.source_type = {p: false, c: false};
concession.polygon=[];
concession.proj_coordinates = [];
var commodities=concession.concession_commodity;
concession.concession_commodity=[];
_.each(commodities,function(commodity){
concession.concession_commodity.push({
_id: commodity.commodity._id,
commodity_name: commodity.commodity.commodity_name,
commodity_type: commodity.commodity.commodity_type,
commodity_id: commodity.commodity.commodity_id
});
})
if (concession.concession_polygon && concession.concession_polygon.length>0) {
var len=concession.concession_polygon.length;
var counter=0;
var coordinate=[];
concession.concession_polygon.forEach(function (con_loc) {
++counter;
if(con_loc && con_loc.loc) {
coordinate.push({
'lat': con_loc.loc[0],
'lng': con_loc.loc[1]
});
}
if(len==counter){
concession.polygon.push({coordinate:coordinate});
}
if(concession) {
concession.contracts = [];
concession.source_type = {p: false, c: false};
concession.polygon = [];
concession.proj_coordinates = [];
var commodities = concession.concession_commodity;
concession.concession_commodity = [];
_.each(commodities, function (commodity) {
concession.concession_commodity.push({
_id: commodity.commodity._id,
commodity_name: commodity.commodity.commodity_name,
commodity_type: commodity.commodity.commodity_type,
commodity_id: commodity.commodity.commodity_id
});
})
}
Link.find({concession: concession._id})
.populate('contract company')
.deepPopulate('project.proj_country.country project.proj_commodity.commodity site.site_commodity.commodity source.source_type_id')
.exec(function(err, links) {
link_len = links.length;
link_counter = 0;
if(link_len>0) {
links.forEach(function (link) {
++link_counter;
var entity = _.without(link.entities, 'concession')[0];
if (!concession.source_type.p || !concession.source_type.c) {
if(link.source!=null) {
if (link.source.source_type_id.source_type_authority === 'authoritative') {
concession.source_type.c = true;
} else if (link.source.source_type_id.source_type_authority === 'non-authoritative') {
concession.source_type.c = true;
} else if (link.source.source_type_id.source_type_authority === 'disclosure') {
concession.source_type.p = true;
if (concession.concession_polygon && concession.concession_polygon.length > 0) {
var len = concession.concession_polygon.length;
var counter = 0;
var coordinate = [];
concession.concession_polygon.forEach(function (con_loc) {
++counter;
if (con_loc && con_loc.loc) {
coordinate.push({
'lat': con_loc.loc[0],
'lng': con_loc.loc[1]
});
}
if (len == counter) {
concession.polygon.push({coordinate: coordinate});
}
})
}
Link.find({concession: concession._id})
.populate('contract company')
.deepPopulate('project.proj_country.country project.proj_commodity.commodity site.site_commodity.commodity source.source_type_id')
.exec(function (err, links) {
link_len = links.length;
link_counter = 0;
if (link_len > 0) {
links.forEach(function (link) {
++link_counter;
var entity = _.without(link.entities, 'concession')[0];
if (!concession.source_type.p || !concession.source_type.c) {
if (link.source != null) {
if (link.source.source_type_id.source_type_authority === 'authoritative') {
concession.source_type.c = true;
} else if (link.source.source_type_id.source_type_authority === 'non-authoritative') {
concession.source_type.c = true;
} else if (link.source.source_type_id.source_type_authority === 'disclosure') {
concession.source_type.p = true;
}
}
}
}
switch (entity) {
case 'contract':
if (!_.contains(concession.contracts, link.contract.contract_id)) {
concession.contracts.push(link.contract);
}
break;
case 'project':
if (link.project.proj_commodity.length>0) {
if (_.where(concession.concession_commodity, {_id:_.last(link.project.proj_commodity).commodity._id}).length<1) {
concession.concession_commodity.push({
_id: _.last(link.project.proj_commodity).commodity._id,
commodity_name: _.last(link.project.proj_commodity).commodity.commodity_name,
commodity_type: _.last(link.project.proj_commodity).commodity.commodity_type,
commodity_id: _.last(link.project.proj_commodity).commodity.commodity_id
});
switch (entity) {
case 'contract':
if (!_.contains(concession.contracts, link.contract.contract_id)) {
concession.contracts.push(link.contract);
}
}
break;
case 'site':
if (link.site.field && link.site.site_coordinates.length>0) {
link.site.site_coordinates.forEach(function (loc) {
if(loc && loc.loc) {
concession.proj_coordinates.push({
'lat': loc.loc[0],
'lng': loc.loc[1],
'message': link.site.site_name,
'timestamp': loc.timestamp,
'type': 'field',
'id': link.site._id
break;
case 'project':
if (link.project.proj_commodity.length > 0) {
if (_.where(concession.concession_commodity, {_id: _.last(link.project.proj_commodity).commodity._id}).length < 1) {
concession.concession_commodity.push({
_id: _.last(link.project.proj_commodity).commodity._id,
commodity_name: _.last(link.project.proj_commodity).commodity.commodity_name,
commodity_type: _.last(link.project.proj_commodity).commodity.commodity_type,
commodity_id: _.last(link.project.proj_commodity).commodity.commodity_id
});
}
});
} else if (!link.site.field && link.site.site_coordinates.length>0) {
link.site.site_coordinates.forEach(function (loc) {
if(loc && loc.loc) {
concession.proj_coordinates.push({
'lat': loc.loc[0],
'lng': loc.loc[1],
'message': link.site.site_name,
'timestamp': loc.timestamp,
'type': 'site',
'id': link.site._id
}
break;
case 'site':
if (link.site.field && link.site.site_coordinates.length > 0) {
link.site.site_coordinates.forEach(function (loc) {
if (loc && loc.loc) {
concession.proj_coordinates.push({
'lat': loc.loc[0],
'lng': loc.loc[1],
'message': link.site.site_name,
'timestamp': loc.timestamp,
'type': 'field',
'id': link.site._id
});
}
});
} else if (!link.site.field && link.site.site_coordinates.length > 0) {
link.site.site_coordinates.forEach(function (loc) {
if (loc && loc.loc) {
concession.proj_coordinates.push({
'lat': loc.loc[0],
'lng': loc.loc[1],
'message': link.site.site_name,
'timestamp': loc.timestamp,
'type': 'site',
'id': link.site._id
});
}
});
}
if (link.site.site_commodity.length > 0) {
if (_.where(concession.concession_commodity, {_id: _.last(link.site.site_commodity).commodity._id}).length < 1) {
concession.concession_commodity.push({
_id: _.last(link.site.site_commodity).commodity._id,
commodity_name: _.last(link.site.site_commodity).commodity.commodity_name,
commodity_type: _.last(link.site.site_commodity).commodity.commodity_type,
commodity_id: _.last(link.site.site_commodity).commodity.commodity_id
});
}
});
}
if (link.site.site_commodity.length>0) {
if (_.where(concession.concession_commodity, {_id:_.last(link.site.site_commodity).commodity._id}).length<1) {
concession.concession_commodity.push({
_id: _.last(link.site.site_commodity).commodity._id,
commodity_name: _.last(link.site.site_commodity).commodity.commodity_name,
commodity_type: _.last(link.site.site_commodity).commodity.commodity_type,
commodity_id: _.last(link.site.site_commodity).commodity.commodity_id
});
}
}
break;
default:
console.log(entity, 'link skipped...');
}
if (link_counter == link_len) {
callback(null, concession);
}
});
} else{
callback(null, concession);
}
});
break;
default:
console.log(entity, 'link skipped...');
}
if (link_counter == link_len) {
callback(null, concession);
}
});
} else {
callback(null, concession);
}
});
} else {
callback(null, {error:"Error"});
}
}
};

Expand Down
Loading

0 comments on commit 765d6e6

Please sign in to comment.