Skip to content

Commit

Permalink
Code added for this bug fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
aunindadf committed May 25, 2016
1 parent 806fe5a commit 8d910bf
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 15 deletions.
19 changes: 17 additions & 2 deletions devtracker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
require "em-synchrony/em-http"
require 'oj'
require 'rss'
require "sinatra/json"

#helpers path
require_relative 'helpers/formatters.rb'
Expand Down Expand Up @@ -50,12 +51,12 @@

# Developer Machine: set global settings
#set :oipa_api_url, 'http://dfid-oipa.zz-clients.net/api/'
#set :oipa_api_url, 'https://devtracker.dfid.gov.uk/api/'
set :oipa_api_url, 'https://devtracker.dfid.gov.uk/api/'
#set :oipa_api_url, 'http://loadbalancer1-dfid.oipa.nl/api/'
#set :oipa_api_url, 'http://staging-dfid.oipa.nl/api/'

# Server Machine: set global settings to use varnish cache
set :oipa_api_url, 'http://127.0.0.1:6081/api/'
#set :oipa_api_url, 'http://127.0.0.1:6081/api/'

#ensures that we can use the extension html.erb rather than just .erb
Tilt.register Tilt::ERBTemplate, 'html.erb'
Expand Down Expand Up @@ -635,6 +636,20 @@
}
end


#####################################################################
# CURRENCY HANDLER
#####################################################################


get '/currency/?' do
settings.devtracker_page_title = 'Currency API'
amount = sanitize_input(params['amount'],"a")
currency = sanitize_input(params['currency'],"a")
returnCurrency = Money.new(amount.to_f*100,currency).format(:no_cents_if_whole => true,:sign_before_symbol => false)
json :output => returnCurrency
end

#####################################################################
# STATIC PAGES
#####################################################################
Expand Down
2 changes: 1 addition & 1 deletion helpers/input_sanitizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def sanitize_input(string,type)
return string.gsub(/[^a-z0-9\s+_.@-]/,'')
when "a"
#Handles the free text search inputs
return string.gsub(/[^a-zA-Z0-9\s_\/\-]/,'')
return string.gsub(/[^a-zA-Z0-9.\s_\/\-]/,'')
when "t"
#Handles the telephone number inputs
return string.gsub(/[^0-9+\s]/,'')
Expand Down
50 changes: 47 additions & 3 deletions public/javascripts/searchPageFilters.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ $(document).ready(function() {
// $('.search-result h3 a small[class^="GB-"]').parent().parent().parent().show();
// $('.search-result h3 a small[class^="XM-DAC-12-"]').parent().parent().parent().show();
// $('.search-result h3 a small').hasClass('GB-*').show();
var currencyLink = '/currency';
switch (window.searchType){
case 'C':
oipaLink = window.oipaApiUrl + 'activities/?hierarchy=1&page_size=10&format=json&reporting_organisation=GB-GOV-1&fields=aggregations,activity_status,id,iati_identifier,url,title,reporting_organisations,activity_plus_child_aggregation,descriptions&activity_status='+$('#activity_status_states').val()+'&ordering='+$('#sort_results_type').val()+'&activity_plus_child_aggregation_budget_value_gte='+$('#budget_lower_bound').val()+'&activity_plus_child_aggregation_budget_value_lte='+$('#budget_higher_bound').val()+'&actual_start_date_gte='+$('#date_lower_bound').val()+'&planned_end_date_lte='+$('#date_higher_bound').val()+'&sector='+$('#selected_sectors').val()+'&related_activity_recipient_country='+window.CountryCode+'&document_link_category='+$('#selected_document_type').val() +'&participating_organisation='+$('#selected_implementingOrg_type').val();
Expand Down Expand Up @@ -53,6 +54,7 @@ $(document).ready(function() {
refreshOipaLink(window.searchType);
//refreshPagination(returnedProjectCount);
generateProjectListAjax(oipaLink);
//generateBudgetValues();
$(this).text('▲');
}
else
Expand All @@ -61,6 +63,7 @@ $(document).ready(function() {
refreshOipaLink(window.searchType);
//refreshPagination(returnedProjectCount);
generateProjectListAjax(oipaLink);
//generateBudgetValues();
$(this).text('▼');
}

Expand All @@ -76,6 +79,7 @@ $(document).ready(function() {
refreshOipaLink(window.searchType);
//refreshPagination(returnedProjectCount);
generateProjectListAjax(oipaLink);
//generateBudgetValues();
$(this).text('▲');
}
else
Expand All @@ -84,6 +88,7 @@ $(document).ready(function() {
refreshOipaLink(window.searchType);
//refreshPagination(returnedProjectCount);
generateProjectListAjax(oipaLink);
//generateBudgetValues();
$(this).text('▼');
}

Expand All @@ -102,27 +107,31 @@ $(document).ready(function() {
}
refreshOipaLink(window.searchType);
generateProjectListAjax(oipaLink);
//generateBudgetValues();
});

$('.document_type').click(function(){
var tmpDocumentTypeList = $('.document_type:checked').map(function(){return $(this).val()}).get().join();
$('#selected_document_type').val(tmpDocumentTypeList);
refreshOipaLink(window.searchType);
generateProjectListAjax(oipaLink);
//generateBudgetValues();
});

$('.implementingOrg_type').click(function(){
var tmpDocumentTypeList = $('.implementingOrg_type:checked').map(function(){return $(this).val()}).get().join();
$('#selected_implementingOrg_type').val(tmpDocumentTypeList);
refreshOipaLink(window.searchType);
generateProjectListAjax(oipaLink);
//generateBudgetValues();
});

$('.sector').click(function(){
var tmpSectorList = $('.sector:checked').map(function(){return $(this).val()}).get().join();
$('#selected_sectors').val(tmpSectorList);
refreshOipaLink(window.searchType);
generateProjectListAjax(oipaLink);
//generateBudgetValues();
});

//The following updates the result based on selected location country filter
Expand All @@ -131,6 +140,7 @@ $(document).ready(function() {
$('#locationCountryFilterStates').val(tmpCountryList);
refreshOipaLink(window.searchType);
generateProjectListAjax(oipaLink);
//generateBudgetValues();
});

//The following updates the result based on selected location region filter
Expand All @@ -139,6 +149,7 @@ $(document).ready(function() {
$('#locationRegionFilterStates').val(tmpRegionList);
refreshOipaLink(window.searchType);
generateProjectListAjax(oipaLink);
//generateBudgetValues();
});

$("#slider-vertical").slider({
Expand All @@ -156,6 +167,7 @@ $(document).ready(function() {
$('#budget_higher_bound').val(ui.values[1]);
refreshOipaLink(window.searchType);
generateProjectListAjax(oipaLink);
//generateBudgetValues();
}
});
$( "#amount" ).html( "£" + addCommas($( "#slider-vertical" ).slider( "values", 0 )) + " - £" + addCommas($( "#slider-vertical" ).slider( "values", 1 )) );
Expand Down Expand Up @@ -188,6 +200,7 @@ $(document).ready(function() {
$('#date_higher_bound').val(tempEndDt.customFormat("#YYYY#-#MM#-#DD#"));
refreshOipaLink(window.searchType);
generateProjectListAjax(oipaLink);
//generateBudgetValues();
}
/*change: function(event, ui){
//TO DO
Expand Down Expand Up @@ -232,6 +245,9 @@ $(document).ready(function() {
}
//validResults['title'] = !isEmpty(result.title.narratives[0]) ? result.title.narratives[0].text : "";
validResults['total_plus_child_budget_value'] = !isEmpty(result.aggregations.activity_children.budget_value) ? result.aggregations.activity_children.budget_value : 0;
validResults['total_plus_child_budget_currency'] = !isEmpty(result.aggregations.activity_children.budget_currency) ? result.aggregations.activity_children.budget_currency : !isEmpty(result.aggregations.activity_children.incoming_funds_currency)? result.aggregations.activity_children.incoming_funds_currency: !isEmpty(result.aggregations.activity_children.expenditure_currency)? result.aggregations.activity_children.expenditure_currency: !isEmpty(result.aggregations.activity_children.disbursement_currency)? result.aggregations.activity_children.disbursement_currency: !isEmpty(result.aggregations.activity_children.commitment_currency)? result.aggregations.activity_children.commitment_currency: "GBP";
validResults['total_plus_child_budget_currency_value'] = '';
//$.getJSON(currencyLink,{amount: validResults['total_plus_child_budget_value'], currency: validResults['total_plus_child_budget_currency']}).done(function(json){validResults['total_plus_child_budget_currency_value'] = json.output});
validResults['activity_status'] = !isEmpty(result.activity_status.name) ? result.activity_status.name : "";
//Check reporting organization
if(!isEmpty(result.reporting_organisations)){
Expand Down Expand Up @@ -259,9 +275,11 @@ $(document).ready(function() {
validResults['description'] = "";
}
//validResults['description'] = !isEmpty(result.description[0].narratives[0]) ? result.description[0].narratives[0].text : "";
var tempString = '<div class="search-result"><h3><a href="/projects/'+validResults['id']+'">'+validResults['title']+' <small>['+ validResults['iati_identifier'] +']</small></a></h3><span class="budget">Budget: <em> '+addCommas(validResults['total_plus_child_budget_value'],'B')+'</em></span><span>Status: <em>'+validResults['activity_status']+'</em></span><span>Reporting Org: <em>'+validResults['reporting_organisations']+'</em></span><p class="description">'+validResults['description']+'</p></div>';
//var tempString = '<div class="search-result"><h3><a href="/projects/'+validResults['id']+'">'+validResults['title']+' <small>['+ validResults['iati_identifier'] +']</small></a></h3><span class="budget">Budget: <em> '+addCommas(validResults['total_plus_child_budget_value'],'B')+'</em></span><span>Status: <em>'+validResults['activity_status']+'</em></span><span>Reporting Org: <em>'+validResults['reporting_organisations']+'</em></span><p class="description">'+validResults['description']+'</p></div>';
var tempString = '<div class="search-result"><h3><a href="/projects/'+validResults['id']+'">'+validResults['title']+' <small>['+ validResults['iati_identifier'] +']</small></a></h3><span class="budget">Budget: <em> '+'<div class="tpcbcv"><span class="total_plus_child_budget_currency_value_amount">'+validResults['total_plus_child_budget_value']+'</span><span class="total_plus_child_budget_currency_value_cur">'+validResults['total_plus_child_budget_currency']+'</span></div>'+'</em></span><span>Status: <em>'+validResults['activity_status']+'</em></span><span>Reporting Org: <em>'+validResults['reporting_organisations']+'</em></span><p class="description">'+validResults['description']+'</p></div>';
$('#showResults').append(tempString);
});
generateBudgetValues();
})
.fail(function(error){
$('#showResults').text(error.toSource());
Expand All @@ -273,11 +291,31 @@ $(document).ready(function() {
// $('.search-result h3 a small[class^="XM-DAC-12-"]').parent().parent().parent().show();
};

function generateBudgetValues(){
$('.tpcbcv').each(function(){
//$.getJSON(currencyLink,{amount: $(this).children('.total_plus_child_budget_currency_value_amount').text(), currency: $(this).children('.total_plus_child_budget_currency_value_cur').text()}).done(function(json){$(this).parent().before("asasxasxsxs")}).fail(function(error){console.log("AJAX error in request: " + JSON.stringify(error, null, 2));});
var temp_amount = $(this).children('.total_plus_child_budget_currency_value_amount').text();
var temp_currency = $(this).children('.total_plus_child_budget_currency_value_cur').text();
var temp_response = '';
$.ajax({
method: "GET",
async: false,
url: "/currency",
data: {amount: temp_amount, currency: temp_currency},
}).done(function(msg){
console.log("saved: " + msg.output);
temp_response = msg.output;
});
$(this).before(temp_response);
});
}

/*generateProjectListAjax function re-populates the project list based on the new api call when clicked on a filter or order*/

function generateProjectListAjax(oipaLink){
$.getJSON(oipaLink,{
format: "json"
format: "json",
async: false,
})
.done(function(json){
$('#showResults').html("");
Expand Down Expand Up @@ -316,6 +354,9 @@ $(document).ready(function() {
}
//validResults['title'] = !isEmpty(result.title.narratives[0]) ? result.title.narratives[0].text : "";
validResults['total_plus_child_budget_value'] = !isEmpty(result.aggregations.activity_children.budget_value) ? result.aggregations.activity_children.budget_value : 0;
validResults['total_plus_child_budget_currency'] = !isEmpty(result.aggregations.activity_children.budget_currency) ? result.aggregations.activity_children.budget_currency : !isEmpty(result.aggregations.activity_children.incoming_funds_currency)? result.aggregations.activity_children.incoming_funds_currency: !isEmpty(result.aggregations.activity_children.expenditure_currency)? result.aggregations.activity_children.expenditure_currency: !isEmpty(result.aggregations.activity_children.disbursement_currency)? result.aggregations.activity_children.disbursement_currency: !isEmpty(result.aggregations.activity_children.commitment_currency)? result.aggregations.activity_children.commitment_currency: "GBP";
validResults['total_plus_child_budget_currency_value'] = '';
//$.getJSON(currencyLink,{amount: validResults['total_plus_child_budget_value'], currency: validResults['total_plus_child_budget_currency']}).done(function(json){validResults['total_plus_child_budget_currency_value'] = json.output});
validResults['activity_status'] = !isEmpty(result.activity_status.name) ? result.activity_status.name : "";
//Check reporting organization
if(!isEmpty(result.reporting_organisations)){
Expand Down Expand Up @@ -343,11 +384,14 @@ $(document).ready(function() {
validResults['description'] = "";
}
//validResults['description'] = !isEmpty(result.description[0].narratives[0]) ? result.description[0].narratives[0].text : "";
var tempString = '<div class="search-result"><h3><a href="/projects/'+validResults['id']+'">'+validResults['title']+' <small>['+ validResults['iati_identifier'] +']</small></a></h3><span class="budget">Budget: <em> '+addCommas(validResults['total_plus_child_budget_value'],'B')+'</em></span><span>Status: <em>'+validResults['activity_status']+'</em></span><span>Reporting Org: <em>'+validResults['reporting_organisations']+'</em></span><p class="description">'+validResults['description']+'</p></div>';
//var tempString = '<div class="search-result"><h3><a href="/projects/'+validResults['id']+'">'+validResults['title']+' <small>['+ validResults['iati_identifier'] +']</small></a></h3><span class="budget">Budget: <em> '+addCommas(validResults['total_plus_child_budget_value'],'B')+'</em></span><span>Status: <em>'+validResults['activity_status']+'</em></span><span>Reporting Org: <em>'+validResults['reporting_organisations']+'</em></span><p class="description">'+validResults['description']+'</p></div>';
//var tempString = '<div class="search-result"><h3><a href="/projects/'+validResults['id']+'">'+validResults['title']+' <small>['+ validResults['iati_identifier'] +']</small></a></h3><span class="budget">Budget: <em> '+validResults['total_plus_child_budget_currency_value']+'</em></span><span>Status: <em>'+validResults['activity_status']+'</em></span><span>Reporting Org: <em>'+validResults['reporting_organisations']+'</em></span><p class="description">'+validResults['description']+'</p></div>';
var tempString = '<div class="search-result"><h3><a href="/projects/'+validResults['id']+'">'+validResults['title']+' <small>['+ validResults['iati_identifier'] +']</small></a></h3><span class="budget">Budget: <em> '+'<div class="tpcbcv"><span class="total_plus_child_budget_currency_value_amount">'+validResults['total_plus_child_budget_value']+'</span><span class="total_plus_child_budget_currency_value_cur">'+validResults['total_plus_child_budget_currency']+'</span></div>'+'</em></span><span>Status: <em>'+validResults['activity_status']+'</em></span><span>Reporting Org: <em>'+validResults['reporting_organisations']+'</em></span><p class="description">'+validResults['description']+'</p></div>';
$('#showResults').append(tempString);
});
// $('.search-result h3 a small[class^="GB-"]').parent().parent().parent().show();
// $('.search-result h3 a small[class^="XM-DAC-12-"]').parent().parent().parent().show();
generateBudgetValues();
})
.fail(function(error){
//$('#showResults').text(error.toSource());
Expand Down
4 changes: 4 additions & 0 deletions public/stylesheets/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -660,4 +660,8 @@ g.c3-axis-y > g:last-child {

.filter-header {
margin-bottom: 10px;
}

.tpcbcv {
display: none;
}
4 changes: 2 additions & 2 deletions views/layouts/layout.erb
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@
});
//This stores the base url inside a global variable so that we can make the oipa calls through the varnish
var tempGetUrl = window.location;
window.baseUrl = tempGetUrl.protocol + "//" + tempGetUrl.host + "/" + "api/";
//window.baseUrl = 'http://staging-dfid.oipa.nl/api/';
//window.baseUrl = tempGetUrl.protocol + "//" + tempGetUrl.host + "/" + "api/";
window.baseUrl = 'http://devtracker.dfid.gov.uk/api/';
$('#search').submit(function(){
$('.modal_free_text_search').show();
setTimeout(patience,10000);
Expand Down
4 changes: 2 additions & 2 deletions views/layouts/layout_forms.erb
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@
});
//This stores the base url inside a global variable so that we can make the oipa calls through the varnish
var tempGetUrl = window.location;
window.baseUrl = tempGetUrl.protocol + "//" + tempGetUrl.host + "/" + "api/";
//window.baseUrl = 'http://staging-dfid.oipa.nl/api/';
//window.baseUrl = tempGetUrl.protocol + "//" + tempGetUrl.host + "/" + "api/";
window.baseUrl = 'http://devtracker.dfid.gov.uk/api/';
$('#search').submit(function(){
$('.modal_free_text_search').show();
setTimeout(patience,10000);
Expand Down
6 changes: 4 additions & 2 deletions views/partials/_project_list.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,8 @@
<script src="/javascripts/jquery.simplePagination.js" type="text/javascript"></script>
<script type='text/javascript'>
$(document).ready(function() {
//window.oipaApiUrl = "<%#= oipa_api_url %>";
window.oipaApiUrl = window.baseUrl;
window.oipaApiUrl = "<%= oipa_api_url %>";
//window.oipaApiUrl = window.baseUrl;
window.project_count = "<%= total_projects %>";
window.maxBudget = <%= budgetHigherBound %>;
window.StartDate = '<%= actualStartDate %>';
Expand All @@ -253,5 +253,7 @@
<% end %>
});
</script>
<script src="/javascripts/accounting.min.js" type="text/javascript"></script>
<script src="/javascripts/commonCurrencies.js" type="text/javascript"></script>
<script src="/javascripts/searchPageFilters.js" type="text/javascript"></script>
</div>
Loading

0 comments on commit 8d910bf

Please sign in to comment.