Skip to content

Commit

Permalink
Resolved conflict in devtracker.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
aunindadf committed Oct 12, 2015
2 parents 095cc41 + 4ca3518 commit 7775207
Show file tree
Hide file tree
Showing 17 changed files with 1,255 additions and 337 deletions.
89 changes: 64 additions & 25 deletions devtracker.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# devtracker.rb
#require 'rubygems'
#require 'bundler'
#Bundler.setup
require 'sinatra'
require 'json'
require 'rest-client'
Expand All @@ -15,13 +11,16 @@
require_relative 'helpers/oipa_helpers.rb'
require_relative 'helpers/codelists.rb'
require_relative 'helpers/lookups.rb'
require_relative 'helpers/common_helpers.rb'
require_relative 'helpers/project_helpers.rb'
require_relative 'helpers/sector_helpers.rb'
require_relative 'helpers/country_helpers.rb'
require_relative 'helpers/document_helpers.rb'
require_relative 'helpers/common_helpers.rb'
require_relative 'helpers/results_helper.rb'



#Helper Modules
include CountryHelpers
include Formatters
Expand All @@ -31,11 +30,10 @@
include ResultsHelper

# Developer Machine: set global settings
#set :oipa_api_url, 'http://dfid-oipa.zz-clients.net/api/'
# set :oipa_api_url, 'http://dfid-oipa.zz-clients.net/api/'

set :current_first_day_of_financial_year, first_day_of_financial_year(DateTime.now)
set :current_last_day_of_financial_year, last_day_of_financial_year(DateTime.now)
# Server Machine: set global settings

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 All @@ -45,6 +43,10 @@
# Common Variable Assingment
#####################################################################

set :current_first_day_of_financial_year, first_day_of_financial_year(DateTime.now)
set :current_last_day_of_financial_year, last_day_of_financial_year(DateTime.now)


#####################################################################
# HOME PAGE
#####################################################################
Expand All @@ -54,17 +56,15 @@
# top5countries = JSON.parse(File.read('data/top5countries.json'))
top5sectors = JSON.parse(File.read('data/top5sectors.json'))
top5results = JSON.parse(File.read('data/top5results.json'))
#current_first_day_of_financial_year = first_day_of_financial_year(DateTime.now)
#current_last_day_of_financial_year = last_day_of_financial_year(DateTime.now)


countriesJSON = RestClient.get settings.oipa_api_url + "activities/aggregations?reporting_organisation=GB-1&group_by=recipient_country&aggregations=budget&budget_period_start=#{settings.current_first_day_of_financial_year}&budget_period_end=#{settings.current_last_day_of_financial_year}&order_by=-budget&page_size=5"
top5countries = JSON.parse(countriesJSON)

erb :index,
:layout => :'layouts/layout',
:locals => {
top_5_countries: top5countries,
what_we_do: high_level_sector_list,
what_we_do: high_level_sector_list( settings.oipa_api_url, "top_five_sectors", "High Level Code (L1)", "High Level Sector Description"),
what_we_achieve: top5results
}
end
Expand All @@ -83,8 +83,8 @@
total_projects = JSON.parse(oipa_total_projects)
oipa_active_projects = RestClient.get settings.oipa_api_url + "activities?reporting_organisation=GB-1&hierarchy=1&related_activity_recipient_country=#{n}&activity_status=2&format=json"
active_projects = JSON.parse(oipa_active_projects)
oipa_total_project_budgets = RestClient.get settings.oipa_api_url + "activities/aggregations?format=json&reporting_organisation=GB-1&budget_period_start=#{settings.current_first_day_of_financial_year}&budget_period_end=#{settings.current_last_day_of_financial_year}&group_by=recipient_country&aggregations=budget&recipient_country=#{n}"
total_project_budgets= JSON.parse(oipa_total_project_budgets)
oipa_total_project_budgets = RestClient.get settings.oipa_api_url + "activities/aggregations?format=json&reporting_organisation=GB-1&budget_period_start=#{settings.current_first_day_of_financial_year}&budget_period_end=#{settings.current_last_day_of_financial_year}&group_by=recipient_country&aggregations=budget&recipient_country=#{n}"
total_project_budgets= JSON.parse(oipa_total_project_budgets)
oipa_year_wise_budgets=RestClient.get settings.oipa_api_url + "activities/aggregations?format=json&reporting_organisation=GB-1&group_by=budget_per_quarter&aggregations=budget&recipient_country=#{n}&order_by=year,quarter"
year_wise_budgets= JSON.parse(oipa_year_wise_budgets)

Expand Down Expand Up @@ -200,11 +200,11 @@
else
oipaTransactionsJSON = RestClient.get settings.oipa_api_url + "transactions?format=json&activity=#{n}&page_size=400&fields=activity,description,provider_organisation_name,provider_activity,receiver_organisation_name,transaction_date,transaction_type,value,currency"
oipaYearWiseBudgets=RestClient.get settings.oipa_api_url + "activities/aggregations?format=json&group_by=budget_per_quarter&aggregations=budget&id=#{n}&order_by=year,quarter"
end
end

transactionsJSON = JSON.parse(oipaTransactionsJSON)
transactions = transactionsJSON['results']
yearWiseBudgets= JSON.parse(oipaYearWiseBudgets)
transactions = transactionsJSON['results']
yearWiseBudgets= JSON.parse(oipaYearWiseBudgets)

#get details of H2 Activities from the API
oipaH2ActivitiesJSON = RestClient.get settings.oipa_api_url + "activities?format=json&related_activity_id=#{n}&page_size=400"
Expand Down Expand Up @@ -244,16 +244,56 @@
fundedProjectsCount: fundedProjectsData['count']
}
end

#####################################################################
# SECTOR PAGES
#####################################################################
# examples:
# http://devtracker.dfid.gov.uk/sector/

# High Level Sector summary page
get '/sector/?' do
# Get the high level sector data from the API
erb :'sector/index',
:layout => :'layouts/layout',
:locals => {
high_level_sector_list: high_level_sector_list( settings.oipa_api_url, "all_sectors", "High Level Code (L1)", "High Level Sector Description")
}
end

# Category Page (e.g. Three Digit DAC Sector)
get '/sector/:high_level_sector_code/?' do
# Get the three digit DAC sector data from the API
erb :'sector/categories',
:layout => :'layouts/layout',
:locals => {
category_list: sector_parent_data_list( settings.oipa_api_url, "category", "Category (L2)", "Category Name", "High Level Code (L1)", "High Level Sector Description", params[:high_level_sector_code], "category")
}
end

# Sector Page (e.g. Five Digit DAC Sector)
get '/sector/:high_level_sector_code/categories/:category_code/?' do
# Get the three digit DAC sector data from the API
erb :'sector/sectors',
:layout => :'layouts/layout',
:locals => {
sector_list: sector_parent_data_list(settings.oipa_api_url, "sector", "Code (L3)", "Name", "Category (L2)", "Category Name", params[:high_level_sector_code], params[:category_code])
}
end




#####################################################################
# STATIC PAGES
#####################################################################

#Aid By Location Page
get '/location/country/?' do
#current_first_day_of_financial_year = first_day_of_financial_year(DateTime.now)
#current_last_day_of_financial_year = last_day_of_financial_year(DateTime.now)
current_first_day_of_financial_year = first_day_of_financial_year(DateTime.now)
current_last_day_of_financial_year = last_day_of_financial_year(DateTime.now)
oipa_countries = RestClient.get settings.oipa_api_url + "activities/aggregations?format=json&reporting_organisation=GB-1&budget_period_start=#{settings.current_first_day_of_financial_year}&budget_period_end=#{settings.current_last_day_of_financial_year}&group_by=recipient_country&aggregations=count,budget&order_by=recipient_country"
countries = JSON.parse(oipa_countries)
countries = JSON.parse(oipa_countries)

erb :'location/country/index',
:layout => :'layouts/layout',
Expand All @@ -262,20 +302,20 @@
}
end

get '/department' do
erb :'department/index', :layout => :'layouts/layout'
get '/department' do
erb :'department/department', :layout => :'layouts/layout'
end

get '/about/?' do
erb :'about/index', :layout => :'layouts/layout'
erb :'about/about', :layout => :'layouts/layout'
end

get '/cookies/?' do
erb :'cookies/index', :layout => :'layouts/layout'
end

get '/faq/?' do
erb :'faq/index', :layout => :'layouts/layout'
erb :'faq/faq', :layout => :'layouts/layout'
end

get '/feedback/?' do
Expand All @@ -300,4 +340,3 @@
})
redirect '/'
end

Loading

0 comments on commit 7775207

Please sign in to comment.