Skip to content

Commit

Permalink
document type filter as well as the date range filter is completed in…
Browse files Browse the repository at this point in the history
… this branch.
  • Loading branch information
aunindadf committed Apr 13, 2016
1 parent 5c0fe1c commit aca404b
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 39 deletions.
21 changes: 15 additions & 6 deletions helpers/country_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -304,14 +304,23 @@ def get_country_all_projects_data(countryCode)
end
allProjectsData['actualStartDate'] = RestClient.get settings.oipa_api_url + "activities?format=json&page_size=1&fields=activity_dates&reporting_organisation=GB-GOV-1&hierarchy=1&related_activity_recipient_country=#{countryCode}&ordering=actual_start_date&start_date_gte=1900-01-02"
allProjectsData['actualStartDate'] = JSON.parse(allProjectsData['actualStartDate'])
unless allProjectsData['actualStartDate']['results'][0].nil?
allProjectsData['actualStartDate'] = allProjectsData['actualStartDate']['results'][0]['activity_dates'][1]['iso_date']
tempStartDate = allProjectsData['actualStartDate']['results'][0]['activity_dates'].select{|activityDate| activityDate['type']['code'] == '2'}.first
if (tempStartDate.nil?)
tempStartDate = allProjectsData['actualStartDate']['results'][0]['activity_dates'].select{|activityDate| activityDate['type']['code'] == '1'}.first
end
allProjectsData['plannedEndDate'] = RestClient.get settings.oipa_api_url + "activities?format=json&page_size=1&fields=activity_dates&reporting_organisation=GB-GOV-1&hierarchy=1&related_activity_recipient_country=#{countryCode}&ordering=-planned_end_date"
allProjectsData['actualStartDate'] = tempStartDate
allProjectsData['actualStartDate'] = allProjectsData['actualStartDate']['iso_date']

#unless allProjectsData['actualStartDate']['results'][0].nil?
# allProjectsData['actualStartDate'] = allProjectsData['actualStartDate']['results'][0]['activity_dates'][1]['iso_date']
#end
allProjectsData['plannedEndDate'] = RestClient.get settings.oipa_api_url + "activities?format=json&page_size=1&fields=activity_dates&reporting_organisation=GB-GOV-1&hierarchy=1&related_activity_recipient_country=#{countryCode}&ordering=-planned_end_date&end_date_isnull=False"
allProjectsData['plannedEndDate'] = JSON.parse(allProjectsData['plannedEndDate'])
unless allProjectsData['plannedEndDate']['results'][0].nil?
allProjectsData['plannedEndDate'] = allProjectsData['plannedEndDate']['results'][0]['activity_dates'][2]['iso_date']
end
allProjectsData['plannedEndDate'] = allProjectsData['plannedEndDate']['results'][0]['activity_dates'].select{|activityDate| activityDate['type']['code'] == '3'}.first
allProjectsData['plannedEndDate'] = allProjectsData['plannedEndDate']['iso_date']
#unless allProjectsData['plannedEndDate']['results'][0].nil?
# allProjectsData['plannedEndDate'] = allProjectsData['plannedEndDate']['results'][0]['activity_dates'][2]['iso_date']
#end
oipa_document_type_list = RestClient.get settings.oipa_api_url + "activities/aggregations/?format=json&group_by=document_link_category&aggregations=count&reporting_organisation=GB-GOV-1&related_activity_recipient_country=#{countryCode}"
document_type_list = JSON.parse(oipa_document_type_list)
allProjectsData['document_types'] = document_type_list['results']
Expand Down
28 changes: 18 additions & 10 deletions helpers/region_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,19 +119,27 @@ def get_region_projects(n)
end
results['actualStartDate'] = RestClient.get settings.oipa_api_url + "activities/?format=json&page_size=1&fields=activity_dates&reporting_organisation=GB-GOV-1&hierarchy=1&related_activity_recipient_region=#{n}&ordering=actual_start_date&start_date_gte=1900-01-02"
results['actualStartDate'] = JSON.parse(results['actualStartDate'])
unless results['actualStartDate']['results'][0].nil?
results['actualStartDate'] = results['actualStartDate']['results'][0]['activity_dates'][1]['iso_date']
tempStartDate = results['actualStartDate']['results'][0]['activity_dates'].select{|activityDate| activityDate['type']['code'] == '2'}.first
if (tempStartDate.nil?)
tempStartDate = results['actualStartDate']['results'][0]['activity_dates'].select{|activityDate| activityDate['type']['code'] == '1'}.first
end
results['plannedEndDate'] = RestClient.get settings.oipa_api_url + "activities/?format=json&page_size=1&fields=activity_dates&reporting_organisation=GB-GOV-1&hierarchy=1&related_activity_recipient_region=#{n}&ordering=-planned_end_date"
results['actualStartDate'] = tempStartDate
results['actualStartDate'] = results['actualStartDate']['iso_date']
#unless results['actualStartDate']['results'][0].nil?
# results['actualStartDate'] = results['actualStartDate']['results'][0]['activity_dates'][1]['iso_date']
#end
results['plannedEndDate'] = RestClient.get settings.oipa_api_url + "activities/?format=json&page_size=1&fields=activity_dates&reporting_organisation=GB-GOV-1&hierarchy=1&related_activity_recipient_region=#{n}&ordering=-planned_end_date&end_date_isnull=False"
results['plannedEndDate'] = JSON.parse(results['plannedEndDate'])
unless results['plannedEndDate']['results'][0].nil?
if !results['plannedEndDate']['results'][0]['activity_dates'][2].nil?
results['plannedEndDate'] = results['plannedEndDate']['results'][0]['activity_dates'][2]['iso_date']
else
results['plannedEndDate'] = results['plannedEndDate']['results'][0]['activity_dates'].select{|activityDate| activityDate['type']['code'] == '3'}.first
results['plannedEndDate'] = results['plannedEndDate']['iso_date']
#unless results['plannedEndDate']['results'][0].nil?
# if !results['plannedEndDate']['results'][0]['activity_dates'][2].nil?
# results['plannedEndDate'] = results['plannedEndDate']['results'][0]['activity_dates'][2]['iso_date']
# else
#This is an issue. For now it's a temporary remedy used to avoid a ruby error but, this needs to be fixed once zz helps out with the api call to return the actual/planned end date.
results['plannedEndDate'] = '2050-12-31T00:00:00'
end
end
# results['plannedEndDate'] = '2050-12-31T00:00:00'
# end
#end
results['projects'] = projects
#This code is created for generating the left hand side document type filter list
oipa_document_type_list = RestClient.get settings.oipa_api_url + "activities/aggregations/?format=json&group_by=document_link_category&aggregations=count&reporting_organisation=GB-GOV-1&related_activity_recipient_region=#{n}"
Expand Down
35 changes: 24 additions & 11 deletions helpers/search_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,21 +122,34 @@ def generate_searched_data(query)
searchedData['plannedEndDate'] = '2000-01-01T00:00:00'
# Pulling json data with an order by on actual start date to get the starting bound for the LHS date range slider.
searchedData['actualStartDate'] = RestClient.get settings.oipa_api_url + "activities/?format=json&page_size=1&fields=activity_dates&hierarchy=1&q=#{query}&ordering=actual_start_date&start_date_gte=1900-01-02"
searchedData['actualStartDate'] = JSON.parse(searchedData['actualStartDate'])
unless searchedData['actualStartDate']['results'][0].nil?
searchedData['actualStartDate'] = searchedData['actualStartDate']['results'][0]['activity_dates'][1]['iso_date']
searchedData['actualStartDate'] = JSON.parse(searchedData['actualStartDate'])
tempStartDate = searchedData['actualStartDate']['results'][0]['activity_dates'].select{|activityDate| activityDate['type']['code'] == '2'}.first
if (tempStartDate.nil?)
tempStartDate = searchedData['actualStartDate']['results'][0]['activity_dates'].select{|activityDate| activityDate['type']['code'] == '1'}.first
end
searchedData['actualStartDate'] = tempStartDate
searchedData['actualStartDate'] = searchedData['actualStartDate']['iso_date']
#unless searchedData['actualStartDate']['results'][0].nil?
# searchedData['actualStartDate'] = searchedData['actualStartDate']['results'][0]['activity_dates'][1]['iso_date']
#end
# Pulling json data with an order by on planned end date (DSC) to get the ending bound for the LHS date range slider.
searchedData['plannedEndDate'] = RestClient.get settings.oipa_api_url + "activities/?format=json&page_size=1&fields=activity_dates&hierarchy=1&q=#{query}&ordering=-planned_end_date"
searchedData['plannedEndDate'] = RestClient.get settings.oipa_api_url + "activities/?format=json&page_size=1&fields=activity_dates&hierarchy=1&q=#{query}&ordering=-planned_end_date&end_date_isnull=False"
searchedData['plannedEndDate'] = JSON.parse(searchedData['plannedEndDate'])
unless searchedData['plannedEndDate']['results'][0].nil?
if !searchedData['plannedEndDate']['results'][0]['activity_dates'][2].nil?
searchedData['plannedEndDate'] = searchedData['plannedEndDate']['results'][0]['activity_dates'][2]['iso_date']
else
#This is an issue. For now it's a temporary remedy used to avoid a ruby error but, this needs to be fixed once zz helps out with the api call to return the actual/planned end date.
searchedData['plannedEndDate'] = '2050-12-31T00:00:00'
end
#puts searchedData['plannedEndDate']
tempEndDate = searchedData['plannedEndDate']['results'][0]['activity_dates'].select{|activityDate| activityDate['type']['code'] == '3'}.first
if (tempEndDate.nil?)
tempEndDate = searchedData['plannedEndDate']['results'][0]['activity_dates'].select{|activityDate| activityDate['type']['code'] == '4'}.first
end
searchedData['plannedEndDate'] = tempEndDate
searchedData['plannedEndDate'] = searchedData['plannedEndDate']['iso_date']
#unless searchedData['plannedEndDate']['results'][0].nil?
# if !searchedData['plannedEndDate']['results'][0]['activity_dates'][2].nil?
# searchedData['plannedEndDate'] = searchedData['plannedEndDate']['results'][0]['activity_dates'][2]['iso_date']
# else
#This is an issue. For now it's a temporary remedy used to avoid a ruby error but, this needs to be fixed once zz helps out with the api call to return the actual/planned end date.
# searchedData['plannedEndDate'] = '2050-12-31T00:00:00'
# end
#end
#This code is created for generating the left hand side document type filter list
oipa_document_type_list = RestClient.get settings.oipa_api_url + "activities/aggregations/?format=json&group_by=document_link_category&aggregations=count&reporting_organisation=GB-GOV-1&q=#{query}"
document_type_list = JSON.parse(oipa_document_type_list)
Expand Down
33 changes: 21 additions & 12 deletions helpers/sector_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,21 +164,30 @@ def get_sector_projects(n)
unless projects['results'][0].nil?
results['project_budget_higher_bound'] = projects['results'][0]['aggregations']['activity_children']['budget_value']
end
results['actualStartDate'] = RestClient.get settings.oipa_api_url + "activities/?format=json&page_size=1&fields=activity_dates&reporting_organisation=GB-GOV-1&hierarchy=1&related_activity_sector=#{n}&ordering=actual_start_date&start_date_gte=1900-01-02"
results['actualStartDate'] = JSON.parse(results['actualStartDate'])
unless results['actualStartDate']['results'][0].nil?
results['actualStartDate'] = results['actualStartDate']['results'][0]['activity_dates'][1]['iso_date']
results['actualStartDate'] = RestClient.get settings.oipa_api_url + "activities/?format=json&page_size=1&fields=activity_dates&reporting_organisation=GB-GOV-1&hierarchy=1&related_activity_sector=#{n}&ordering=actual_start_date&start_date_gte=1900-01-02"
results['actualStartDate'] = JSON.parse(results['actualStartDate'])
tempStartDate = results['actualStartDate']['results'][0]['activity_dates'].select{|activityDate| activityDate['type']['code'] == '2'}.first
if (tempStartDate.nil?)
tempStartDate = results['actualStartDate']['results'][0]['activity_dates'].select{|activityDate| activityDate['type']['code'] == '1'}.first
end
results['plannedEndDate'] = RestClient.get settings.oipa_api_url + "activities/?format=json&page_size=1&fields=activity_dates&reporting_organisation=GB-GOV-1&hierarchy=1&related_activity_sector=#{n}&ordering=-planned_end_date"
results['actualStartDate'] = tempStartDate
results['actualStartDate'] = results['actualStartDate']['iso_date']

#unless results['actualStartDate']['results'][0].nil?
# results['actualStartDate'] = results['actualStartDate']['results'][0]['activity_dates'][1]['iso_date']
#end
results['plannedEndDate'] = RestClient.get settings.oipa_api_url + "activities/?format=json&page_size=1&fields=activity_dates&reporting_organisation=GB-GOV-1&hierarchy=1&related_activity_sector=#{n}&ordering=-planned_end_date&end_date_isnull=False"
results['plannedEndDate'] = JSON.parse(results['plannedEndDate'])
unless results['plannedEndDate']['results'][0].nil?
if !results['plannedEndDate']['results'][0]['activity_dates'][2].nil?
results['plannedEndDate'] = results['plannedEndDate']['results'][0]['activity_dates'][2]['iso_date']
else
results['plannedEndDate'] = results['plannedEndDate']['results'][0]['activity_dates'].select{|activityDate| activityDate['type']['code'] == '3'}.first
results['plannedEndDate'] = results['plannedEndDate']['iso_date']
#unless results['plannedEndDate']['results'][0].nil?
# if !results['plannedEndDate']['results'][0]['activity_dates'][2].nil?
# results['plannedEndDate'] = results['plannedEndDate']['results'][0]['activity_dates'][2]['iso_date']
# else
#This is an issue. For now it's a temporary remedy used to avoid a ruby error but, this needs to be fixed once zz helps out with the api call to return the actual/planned end date.
results['plannedEndDate'] = '2050-12-31T00:00:00'
end
end
# results['plannedEndDate'] = '2050-12-31T00:00:00'
# end
#end
results['projects'] = projects
#This code is created for generating the left hand side document type filter list
oipa_document_type_list = RestClient.get settings.oipa_api_url + "activities/aggregations/?format=json&group_by=document_link_category&aggregations=count&reporting_organisation=GB-GOV-1&related_activity_sector=#{n}"
Expand Down
1 change: 1 addition & 0 deletions public/javascripts/searchPageFilters.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ $(document).ready(function() {
$('#date-range').html(tempStartDt.customFormat("#DD# #MMM# #YYYY#") + ' - ' + tempEndDt.customFormat("#DD# #MMM# #YYYY#"));
},
change: function(event, ui){
$('#date-slider-disclaimer').show();
var tempStartDt = new Date(ui.values[0]);
var tempEndDt = new Date(ui.values[1]);
$('#date_lower_bound').val(tempStartDt.customFormat("#YYYY#-#MM#-#DD#"));
Expand Down
1 change: 1 addition & 0 deletions views/partials/_project_list.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@
</div>
<span id="date-range" style="border: 0; font-weight: bold;"></span>
<div id="date-slider-vertical" style="height: 13px;width : 80%; margin-top: 10px;"></div>
<div style="text-align: left; color: rgb(180, 20, 20); margin-top: 15px; display: none" id="date-slider-disclaimer"><span style="margin-top: 4px; float: left; text-align: center; width: 186px;">Note: Projects without an end date have been removed from the result set.</span></div>
</div>
</div>
<script src="/javascripts/jquery.simplePagination.js" type="text/javascript"></script>
Expand Down
1 change: 1 addition & 0 deletions views/search/search.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@
</div>
<span id="date-range" style="border: 0; font-weight: bold;"></span>
<div id="date-slider-vertical" style="height: 13px;width : 80%; margin-top: 10px;"></div>
<div style="text-align: left; color: rgb(180, 20, 20); margin-top: 15px; display: none" id="date-slider-disclaimer"><span style="margin-top: 4px; float: left; text-align: center; width: 186px;">Note: Projects without an end date have been removed from the result set.</span></div>
</div>
</div>
<script src="/javascripts/jquery.simplePagination.js" type="text/javascript"></script>
Expand Down

0 comments on commit aca404b

Please sign in to comment.