generated from dxw/rails-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(fworks): download frameworks register csv
- Loading branch information
1 parent
7492361
commit a6a9dcc
Showing
13 changed files
with
192 additions
and
12 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,5 +1,12 @@ | ||
class Frameworks::DashboardsController < Frameworks::ApplicationController | ||
before_action { @back_url = nil } | ||
|
||
def index; end | ||
def index | ||
respond_to do |format| | ||
format.html | ||
format.csv do | ||
send_data Frameworks::FrameworkDatum.to_csv, filename: "frameworks_data.csv", type: "text/csv" | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
require "csv" | ||
|
||
module Frameworks | ||
class FrameworkDatum < ApplicationRecord | ||
self.primary_key = :framework_id | ||
|
||
# Since these are all coming from other records, there is a risk of method collision | ||
# To avoid this, prefixes are used | ||
enum source: Framework.sources, _prefix: :framework | ||
enum status: Framework.statuses, _prefix: :framework | ||
enum lot: Framework.lots, _prefix: :framework | ||
|
||
def readonly? | ||
true | ||
end | ||
|
||
# @return [String] | ||
def self.to_csv | ||
CSV.generate(headers: true) do |csv| | ||
csv << column_names | ||
|
||
find_each { |record| csv << record.attributes.values } | ||
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
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
5 changes: 5 additions & 0 deletions
5
db/migrate/20240415143752_create_frameworks_framework_data.rb
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,5 @@ | ||
class CreateFrameworksFrameworkData < ActiveRecord::Migration[7.1] | ||
def change | ||
create_view :frameworks_framework_data | ||
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,51 @@ | ||
SELECT ff.id AS "framework_id", | ||
ff.source, | ||
ff.status, | ||
ff.name, | ||
ff.short_name, | ||
ff.url, | ||
ff.reference, | ||
fp.name AS "provider_name", | ||
fp.short_name AS "provider_short_name", | ||
fpc.name AS "provider_contact_name", | ||
fpc.email AS "provider_contact_email", | ||
ff.provider_start_date::DATE, | ||
ff.provider_end_date::DATE, | ||
ff.dfe_start_date::DATE, | ||
ff.dfe_review_date::DATE, | ||
ff.sct_framework_owner, | ||
ff.sct_framework_provider_lead, | ||
sap.first_name || ' ' || sap.last_name AS "procops_lead_name", | ||
sap.email AS "procops_lead_email", | ||
saeo.first_name || ' ' || saeo.last_name AS "e_and_o_lead_name", | ||
saeo.email AS "e_and_o_lead_email", | ||
ff.created_at::DATE, | ||
ff.updated_at::DATE, | ||
ff.dps, | ||
ff.lot, | ||
ff.provider_reference, | ||
ff.faf_added_date::DATE, | ||
ff.faf_end_date::DATE, | ||
cats.categories, | ||
(CASE | ||
WHEN evals.has_evaluation IS NOT NULL THEN 'Yes' | ||
ELSE 'No' | ||
END) AS "has_evaluation" | ||
FROM frameworks_frameworks AS ff | ||
LEFT JOIN frameworks_providers AS fp ON ff.provider_id = fp.id | ||
LEFT JOIN frameworks_provider_contacts AS fpc ON ff.provider_contact_id = fpc.id | ||
LEFT JOIN support_agents AS sap ON ff.proc_ops_lead_id = sap.id | ||
LEFT JOIN support_agents AS saeo ON ff.e_and_o_lead_id = saeo.id | ||
LEFT JOIN ( | ||
SELECT ffc.framework_id, | ||
jsonb_agg(sc.title) AS "categories" | ||
FROM frameworks_framework_categories AS ffc | ||
LEFT JOIN support_categories AS sc ON sc.id = ffc.support_category_id | ||
GROUP BY ffc.framework_id | ||
) AS cats ON cats.framework_id = ff.id | ||
LEFT JOIN ( | ||
SELECT ffe.framework_id, | ||
COUNT(ffe.id) AS "has_evaluation" | ||
FROM frameworks_evaluations AS ffe | ||
GROUP BY ffe.framework_id | ||
) AS evals ON evals.framework_id = ff.id |
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
15 changes: 15 additions & 0 deletions
15
spec/features/frameworks/register/agent_can_download_frameworks_register_csv_spec.rb
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,15 @@ | ||
require "rails_helper" | ||
|
||
describe "Agent can download frameworks register csv", js: true do | ||
include_context "with a framework evaluation agent" | ||
|
||
before do | ||
visit frameworks_root_path | ||
end | ||
|
||
it "has a link to download the CSV of the frameworks data" do | ||
within "#frameworks-register" do | ||
expect(page).to have_link "Download Frameworks CSV", class: "govuk-button", href: frameworks_root_path(format: :csv) | ||
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,9 @@ | ||
RSpec.describe Frameworks::FrameworkDatum, type: :model do | ||
describe "#to_csv" do | ||
it "includes headers" do | ||
expect(described_class.to_csv).to eql( | ||
"framework_id,source,status,name,short_name,url,reference,provider_name,provider_short_name,provider_contact_name,provider_contact_email,provider_start_date,provider_end_date,dfe_start_date,dfe_review_date,sct_framework_owner,sct_framework_provider_lead,procops_lead_name,procops_lead_email,e_and_o_lead_name,e_and_o_lead_email,created_at,updated_at,dps,lot,provider_reference,faf_added_date,faf_end_date,categories,has_evaluation\n", | ||
) | ||
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,14 @@ | ||
require "rails_helper" | ||
|
||
describe "Agent can download frameworks register csv" do | ||
before do | ||
agent_is_signed_in(roles: %w[procops framework_evaluator]) | ||
end | ||
|
||
it "provides a framework register CSV download" do | ||
get "/frameworks.csv" | ||
expect(response.headers["Content-Type"]).to eq "text/csv" | ||
expect(response.headers["Content-Disposition"]).to match(/^attachment/) | ||
expect(response.headers["Content-Disposition"]).to match(/filename="frameworks_data.csv"/) | ||
end | ||
end |