-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
201 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
# 0.1.5 | ||
|
||
- Assign bar chart colours cosistently based on Actor id | ||
|
||
# 0.1.4 | ||
|
||
- Form error styling | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -308,6 +308,7 @@ GEM | |
nokogiri (~> 1.8) | ||
|
||
PLATFORMS | ||
x86_64-darwin-19 | ||
x86_64-linux | ||
|
||
DEPENDENCIES | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module Api | ||
module V1 | ||
class ApiController < ActionController::Base | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# frozen_string_literal: true | ||
|
||
module Api | ||
module V1 | ||
class CommitmentsController < ApiController | ||
skip_before_action :verify_authenticity_token | ||
before_action :validate_params | ||
|
||
def index | ||
commitments = Commitment.api_records | ||
|
||
if params[:updated_after].present? | ||
commitments = commitments.where('commitments.updated_at > ?', params[:updated_after].to_datetime) | ||
end | ||
|
||
commitments = commitments.paginate( | ||
page: params[:page] || 1, | ||
per_page: params[:per_page] || 10 | ||
) | ||
|
||
render json: commitments_to_json(commitments), status: :ok | ||
rescue StandardError => e | ||
render json: { message: e }, status: :unprocessable_entity | ||
end | ||
|
||
private | ||
|
||
def validate_params | ||
return unless params[:per_page].to_i > 50 | ||
|
||
render json: { | ||
message: I18n.t('controllers.api.v1.commitments.per_page.exceeds_maximum') | ||
}, status: :unprocessable_entity | ||
end | ||
|
||
def commitments_to_json(commitments) | ||
commitments.eager_load(:managers, | ||
:actions, | ||
:countries, | ||
:objectives, | ||
:threats, | ||
:links).as_json( | ||
only: %i[ | ||
id | ||
area_owner_and_role | ||
committed_year | ||
current_area_ha | ||
description | ||
duration_years | ||
geospatial_file | ||
implementation_year | ||
latitude | ||
longitude | ||
name | ||
responsible_group | ||
stage | ||
created_at | ||
updated_at | ||
], | ||
include: { | ||
managers: { only: %i[id name] }, | ||
actions: { only: %i[id name] }, | ||
countries: { only: %i[id name iso] }, | ||
objectives: { only: %i[id name] }, | ||
threats: { only: %i[id name] }, | ||
links: { only: %i[id url] } | ||
} | ||
) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const CHART_COLORS = { | ||
1: "#97001F", | ||
2: "#6054BA", | ||
3: "#00483A", | ||
4: "#E7C802", | ||
5: "#4BC0C0", | ||
6: "#43B2ED", | ||
7: "#6380FF", | ||
8: "#FF6384", | ||
9: "#FFA040", | ||
10: "#003E78", | ||
} | ||
|
||
export default CHART_COLORS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.