Skip to content

Commit

Permalink
Merge pull request #3 from DFID/initial-tx-test
Browse files Browse the repository at this point in the history
fixed transactions
  • Loading branch information
johnadamsDFID committed Jul 20, 2015
2 parents f8b2c36 + 955ce42 commit 66ea4d4
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 149 deletions.
34 changes: 29 additions & 5 deletions site/devtracker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
require 'sinatra'
require 'json'
require 'rest-client'
#require 'sinatra-partial'
#require 'money'
#require 'active_support'
#require 'strftime'
require 'active_support'

#helpers
require_relative 'helpers/formatters.rb'
Expand All @@ -17,13 +14,15 @@
require_relative 'helpers/lookups.rb'
require_relative 'helpers/project_helpers.rb'

#ensures that we can use the extension html.erb rather than just .erb
Tilt.register Tilt::ERBTemplate, 'html.erb'

#####################################################################
# HOME PAGE
#####################################################################

get '/' do #homepage
#read static data from JSON files for the front page
top5countries = JSON.parse(File.read('data/top5countries.json'))
top5sectors = JSON.parse(File.read('data/top5sectors.json'))
top5results = JSON.parse(File.read('data/top5results.json'))
Expand Down Expand Up @@ -90,10 +89,35 @@
oipa = RestClient.get "http://149.210.176.175/api/activities/#{n}?format=json"
project = JSON.parse(oipa)

# get the transactions from the API
oipa_tx = RestClient.get "http://149.210.176.175/api/activities/#{n}-101/transactions?format=json" #TEST: hard-coding -101
tx = JSON.parse(oipa_tx)
transactions = tx['results']

erb :'projects/transactions',
:layout => :'layouts/layout',
:locals => {
project: project
project: project,
transactions: transactions
}
end

#Project transactions page (test)
get '/projects/:proj_id/txtest/?' do |n|
# get the project data from the API
oipa = RestClient.get "http://149.210.176.175/api/activities/#{n}?format=json"
project = JSON.parse(oipa)

# get the transactions from the API
oipa_tx = RestClient.get "http://149.210.176.175/api/activities/#{n}-101/transactions?format=json" #TEST: hard-coding -101
tx = JSON.parse(oipa_tx)
transactions = tx['results']

erb :'projects/testtx',
:layout => :'layouts/layout',
:locals => {
project: project,
transactions: transactions
}
end

Expand Down
2 changes: 1 addition & 1 deletion site/views/partials/_projects-header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<div>
<div class="breadcrumb">
<ul>
<li><a href="/index.html">Home</a></li>
<li><a href="/">Home</a></li>
<li><a href="/countries/<%= project['recipient_countries']%>/index.html"><%= project['recipient_countries'] || "" %></a></li>
<li title="<%= project['title']['narratives'][0]['text'] %>"><%= project['title']['narratives'][0]['text'] %></li>
</ul>
Expand Down
4 changes: 3 additions & 1 deletion site/views/projects/documents.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ title: Development Tracker
<tr class="result-list-row">
<th scope="row"><a href="<%=document['url']%>"><%= document['title']['narratives'][0]['text'].gsub(/\.[^.]*$/, '') %></a></th>
<td scope="col">
<%=document['format']%>
<%document['format'].each do |item| %>
<%=item[1]%>
<% end %>
</td>
<td scope="col">
<% document['category'].each do |category| %>
Expand Down
4 changes: 2 additions & 2 deletions site/views/projects/test.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
<!-- ---
title: Development Tracker
---
--- -->

<%= erb :'partials/_projects-header', :locals => { :project => project, :active => "summary"} %>

Expand Down
29 changes: 29 additions & 0 deletions site/views/projects/testtx.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
title: Development Tracker
---

<%= erb :'partials/_projects-header', :locals => { :project => project, :active => "summary"} %>


<% #transactions.sort_by { | tx | -tx['transaction_date'] }.select {|group| group['transaction_type']['code'] == 'D' }.each do |commitment| %>

<% transactions.select {|group| group['transaction_type']['code'] == 'D' }.each do |commitment| %>


<% #transactions.each do |commitment| %>
<div class="row">
<div class="twelve columns summary">
<table>
<tr>
<td><%= commitment['transaction_type']['code'] %></td>
<td><%= commitment['value_date'] %></td>
<td><%= commitment['value'] %></td>
</tr>
</table>
</div>
</div>
<% end %>



Loading

0 comments on commit 66ea4d4

Please sign in to comment.