Skip to content
This repository has been archived by the owner on Nov 7, 2018. It is now read-only.

Commit

Permalink
added policy markers widget
Browse files Browse the repository at this point in the history
  • Loading branch information
benfoxall committed Nov 8, 2012
1 parent 052c309 commit 57589f6
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 9 deletions.
90 changes: 90 additions & 0 deletions codelists.js
@@ -0,0 +1,90 @@
// TODO - this should be dynamic, or augmented with eXist

// our underscore
var _ = require('./lib/underscore_mixins.js').init(require('underscore'));

// Following a similiar structure that the serialised
// json would have.

var codelists = {};


// http://iatistandard.org/codelists/policy_marker
codelists.policyMarker = [{
code:1,
name:"Gender Equality"
},{
code:2,
name:"Aid to Environment"
},{
code:3,
name:"Participatory Development/Good Governance"
},{
code:4,
name:"Trade Development"
},{
code:5,
name:"Aid Targeting the Objectives of the Convention on Biological Diversity"
},{
code:6,
name:"Aid Targeting the Objectives of the Framework Convention on Climate Change - Mitigation"
},{
code:7,
name:"Aid Targeting the Objectives of the Framework Convention on Climate Change - Adaptation"
},{
code:8,
name:"Aid Targeting the Objectives of the Convention to Combat Desertification"
}];


// http://iatistandard.org/codelists/policy_significance
codelists.policy_significance = [{
code:0,
name:"not targeted",
description:"The score \"not targeted\" means that the activity was examined but found not to target the policy objective."
},{
code:1,
name:"significant objective",
description:"Significant (secondary) policy objectives are those which, although important, were not the prime motivation for undertaking the activity."
},{
code:2,
name:"principal objective",
description:"Principal (primary) policy objectives are those which can be identified as being fundamental in the design and impact of the activity and which are an explicit objective of the activity. They may be selected by answering the question \"Would the activity have been undertaken without this objective?\""
},{
code:3,
name:"principal objective AND in support of an action programme",
description:"For desertification-related aid only"
}];


// returns a function that will populate an
// object from the codelists
var populator = function(opts){
return function(object){
_.each(opts, function(listname, code){

var object_value = object[code];

// find the matching code
var value = _.find(codelists[listname], function(item){
return item.code == object_value;
});

// if it was @code, store the value under .code
if(code.charAt(0) == '@')
code = code.slice(1);

// update the object with it
object[code] = value || {};


});
return object;
};
};

module.exports = {
populator:populator,
lists: codelists
};

15 changes: 13 additions & 2 deletions lib/accessors.js
@@ -1,5 +1,6 @@
var _ = require('./underscore_mixins.js').init(require('underscore'));
var replacements = require('../config/replacements.js').replacements;
var _ = require('./underscore_mixins.js').init(require('underscore')),
replacements = require('../config/replacements.js').replacements,
codelistPopulator = require('../codelists.js').populator;

//Extracts text from a node which may be text or an object containing text
var textVal = function(node) {
Expand Down Expand Up @@ -134,6 +135,16 @@ exports.activity = function(data) {
})
.value();
},

policyMarkers: function(){
return _(this.data['policy-marker']).chain()
.as_array()
.map(codelistPopulator({
'@code': 'policyMarker',
'@significance': 'policy_significance'
}))
.value();
},

//Returns a list of sectors for an activity
sectors: function() {
Expand Down
15 changes: 8 additions & 7 deletions views/activity.jade
Expand Up @@ -128,13 +128,14 @@ section.activity.slide-panel.clearfix
.widget(data-href=url_with('/widgets/transactions', {ID: activity.id(), view:'full'}))
!=partial('embed_widget', {locals: {widget_url: url_with('/widgets/transactions', {ID: activity.id()}), links: true, padding: 0, width: 260}})
.half.left
.widget
h3 Aid flows
img(src='/images/mockups/aid_flows.png')
.half.left
.widget
h3 Results
p Coming soon
.widget(data-href=url_with('/widgets/policy_markers', {ID: activity.id(), view:'full'}))
!=partial('embed_widget', {locals: {widget_url: url_with('/widgets/policy_markers', {ID: activity.id()}), links: true, padding: 0, width: 260}})

// mock-placeholder
.half.left
.widget
h3 Aid flows
img(src='/images/mockups/aid_flows.png')
script
inlines.push(function() {
Expand Down
11 changes: 11 additions & 0 deletions views/widgets/policy_markers.jade
@@ -0,0 +1,11 @@
.widget_content
h3.title Policy Markers

if !markers.length
p None supplied

for marker in markers
p
strong #{marker['#text'] || marker.code.name}
em (#{marker.significance.name})
// long version - (#{marker.significance.name} - #{marker.significance.description})
23 changes: 23 additions & 0 deletions widgets.js
@@ -1,3 +1,5 @@
var codelists = require('./codelists.js');

(function(exports) {
// default to site layout when view=full and allow no layout on
// ajax requests
Expand Down Expand Up @@ -247,6 +249,27 @@
.end();
});

// displaying policy-thematic-markers
app.get('/widgets/policy_markers', function(req, res, next) {
var id = req.query.ID;

api.Request({ID: id, result: 'full'})
.on('success', function(data) {
var activity = accessors.activity(data);
var markers = activity.policyMarkers();

res.render('widgets/policy_markers', {
markers: markers,
layout: widgetLayout(req)
});
})
.on('error', function(e) {
next(e);
})
.end();
});





Expand Down

0 comments on commit 57589f6

Please sign in to comment.