Skip to content

Commit

Permalink
merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
NarenderRajuB committed Sep 18, 2024
2 parents fea7a55 + ad837de commit 80ac962
Show file tree
Hide file tree
Showing 37 changed files with 652 additions and 619 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/copilot_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
version_to_build: sha-${{ github.sha }}
owner: ${{ github.repository_owner }}
application: funding-service-design-fund-application-builder
assets_required: false
assets_required: true

dev_deploy:
needs: [ pre_deploy_tests, paketo_build, setup ]
Expand All @@ -76,6 +76,7 @@ jobs:
environment: dev
app_name: fund-application-builder
version: sha-${{ github.sha }}
db_name: fsd-fund-application-builder

post_dev_deploy_tests:
needs: dev_deploy
Expand Down Expand Up @@ -103,6 +104,7 @@ jobs:
environment: test
app_name: fund-application-builder
version: sha-${{ github.sha }}
db_name: fsd-fund-application-builder

post_test_deploy_tests:
needs: test_deploy
Expand Down Expand Up @@ -131,6 +133,7 @@ jobs:
environment: uat
app_name: fund-application-builder
version: sha-${{ github.sha }}
db_name: fsd-fund-application-builder

post_uat_deploy_tests:
needs: uat_deploy
Expand Down Expand Up @@ -159,3 +162,4 @@ jobs:
environment: prod
app_name: fund-application-builder
version: sha-${{ github.sha }}
db_name: fsd-fund-application-builder
10 changes: 7 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{ "workbench.colorCustomizations": {
"titleBar.activeBackground": "#bf4bb7",
"titleBar.activeForeground": "#fdfbfb",
{
"workbench.colorCustomizations": {
"titleBar.activeBackground": "#bf4bb7",
"titleBar.activeForeground": "#fdfbfb",
},
"python.testing.pytestArgs": [
"tests"
Expand All @@ -13,4 +14,7 @@
"strings": false
},
"editor.quickSuggestionsDelay": 10,
"black-formatter.interpreter": [
"/usr/local/bin/python",
],
}
2 changes: 2 additions & 0 deletions app/all_questions/metadata_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ def build_components_from_page(
title, text = determine_title_and_text_for_component(
c, include_html_components=include_html_components, form_lists=form_lists
)
field_type = c["type"]
if not title and not text:
continue

Expand Down Expand Up @@ -386,6 +387,7 @@ def build_components_from_page(
"title": title,
"text": text,
"hide_title": c["options"]["hideTitle"] if "hideTitle" in c["options"] else False,
"type": field_type,
}
components.append(component)
return components
Expand Down
116 changes: 74 additions & 42 deletions app/blueprints/fund_builder/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@
from app.db.models.round import Round
from app.db.queries.application import clone_single_form
from app.db.queries.application import clone_single_round
from app.db.queries.application import delete_form
from app.db.queries.application import delete_section
from app.db.queries.application import get_all_template_forms
from app.db.queries.application import get_form_by_id
from app.db.queries.application import get_section_by_id
from app.db.queries.application import insert_new_section
from app.db.queries.application import update_form
from app.db.queries.application import update_section
from app.db.queries.fund import add_fund
from app.db.queries.fund import get_all_funds
from app.db.queries.fund import get_fund_by_id
from app.db.queries.round import add_round
from app.db.queries.round import get_all_rounds
from app.db.queries.round import get_round_by_id
from app.export_config.generate_all_questions import print_html
from app.export_config.generate_form import build_form_json
Expand All @@ -56,37 +56,26 @@
)


@build_fund_bp.route("/fund/round/configure", methods=["GET", "POST"])
def configure_round():
"""
Renders a template providing a drop down list of funds. If a fund is selected, renders its config info
"""
all_rounds = get_all_rounds()

params = {
"all_rounds": [{"text": f"{r.short_name} - {r.title_json['en']}", "value": str(r.round_id)} for r in all_rounds]
}
if round_id := request.form.get("round_id") or request.args.get("round_id"):
round = get_round_by_id(round_id)
params["round"] = round
params["selected_round_id"] = round_id

return render_template("application.html", **params)
@build_fund_bp.route("/")
def index():
return render_template("index.html")


@build_fund_bp.route("/fund/round/<round_id>/section", methods=["GET", "POST"])
def section(round_id):
round_obj = get_round_by_id(round_id)
fund_obj = get_fund_by_id(round_obj.fund_id)
form: SectionForm = SectionForm()
form.round_id.data = round_id
params = {
"round_id": str(round_id),
}
existing_section = None
if request.args.get("action") == "remove":
update_section(request.args.get("section_id"), {"round_id": None}) # TODO remove properly
return redirect(url_for("build_fund_bp.configure_round", round_id=round_id, _method="POST", code=307))
delete_section(section_id=request.args.get("section_id"), cascade=True)
return redirect(url_for("build_fund_bp.build_application", round_id=round_id))
if form.validate_on_submit():
round = get_round_by_id(form.round_id.data)
count_existing_sections = len(round.sections)
count_existing_sections = len(round_obj.sections)
if form.section_id.data:
update_section(
form.section_id.data,
Expand All @@ -103,8 +92,8 @@ def section(round_id):
}
)

flash(f"Saved section {form.name_in_apply_en.data}")
return redirect(url_for("build_fund_bp.configure_round"), code=307)
# flash(f"Saved section {form.name_in_apply_en.data}")
return redirect(url_for("build_fund_bp.build_application", round_id=round_obj.round_id))
if section_id := request.args.get("section_id"):
existing_section = get_section_by_id(section_id)
form.section_id.data = section_id
Expand All @@ -115,6 +104,14 @@ def section(round_id):
for f in get_all_template_forms()
]

params["breadcrumb_items"] = [
{"text": fund_obj.name_json["en"], "href": url_for("build_fund_bp.view_fund", fund_id=fund_obj.fund_id)},
{
"text": round_obj.title_json["en"],
"href": url_for("build_fund_bp.build_application", fund_id=fund_obj.fund_id, round_id=round_obj.round_id),
},
{"text": existing_section.name_in_apply_json["en"] if existing_section else "Add Section", "href": "#"},
]
return render_template("section.html", form=form, **params)


Expand All @@ -123,8 +120,7 @@ def configure_forms_in_section(round_id, section_id):
if request.method == "POST":
if request.args.get("action") == "remove":
form_id = request.args.get("form_id")
# TODO figure out if we want to do a soft or hard delete here
update_form(form_id, {"section_id": None})
delete_form(form_id=form_id, cascade=True)
else:
template_id = request.form.get("template_id")
section = get_section_by_id(section_id=section_id)
Expand All @@ -148,44 +144,48 @@ def view_fund():
Renders a template providing a drop down list of funds. If a fund is selected, renders its config info
"""
params = {"all_funds": all_funds_as_govuk_select_items(get_all_funds())}
fund = None
if request.method == "POST":
fund_id = request.form.get("fund_id")
else:
fund_id = request.args.get("fund_id")
if fund_id:
fund = get_fund_by_id(fund_id)
params["fund"] = fund
params["selected_fund_id"] = fund_id
params["breadcrumb_items"] = [
{"text": "Home", "href": url_for("build_fund_bp.index")},
{"text": fund.title_json["en"] if fund else "Manage Application Configuration", "href": "#"},
]

return render_template("view_fund_config.html", **params)
return render_template("fund_config.html", **params)


@build_fund_bp.route("/fund/round/<round_id>/application_config")
def view_app_config(round_id):
def build_application(round_id):
"""
Renders a template displaying application configuration info for the chosen round
"""
round = get_round_by_id(round_id)
fund = get_fund_by_id(round.fund_id)
return render_template("view_application_config.html", round=round, fund=fund)
breadcrumb_items = [
{"text": fund.name_json["en"], "href": url_for("build_fund_bp.view_fund", fund_id=fund.fund_id)},
{"text": round.title_json["en"], "href": "#"},
]
return render_template("build_application.html", round=round, fund=fund, breadcrumb_items=breadcrumb_items)


@build_fund_bp.route("/fund/<fund_id>/round/<round_id>/clone")
def clone_round(round_id, fund_id):

cloned = clone_single_round(round_id=round_id, new_fund_id=fund_id, new_short_name=f"R-C{randint(0,999)}")
cloned = clone_single_round(
round_id=round_id, new_fund_id=fund_id, new_short_name=f"R-C{randint(0,999)}" # nosec B311
)
flash(f"Cloned new round: {cloned.short_name}")

return redirect(url_for("build_fund_bp.view_fund", fund_id=fund_id))


@build_fund_bp.route("/fund/round/<round_id>/assessment_config")
def view_assess_config(round_id):
"""
Renders a template displaying assessment configuration info for the chosen round
"""
round = get_round_by_id(round_id)
fund = get_fund_by_id(round.fund_id)
return render_template("view_assessment_config.html", round=round, fund=fund)


@build_fund_bp.route("/fund", methods=["GET", "POST"])
def fund():
"""
Expand Down Expand Up @@ -294,7 +294,7 @@ def download_form_json(form_id):
return Response(
response=json.dumps(form_json),
mimetype="application/json",
headers={"Content-Disposition": f"attachment;filename=form-{randint(0,999)}.json"},
headers={"Content-Disposition": f"attachment;filename=form-{randint(0,999)}.json"}, # nosec B311
)


Expand All @@ -317,7 +317,39 @@ def view_all_questions(round_id):
lang="en",
)
html = print_html(print_data)
return render_template("view_questions.html", round=round, fund=fund, question_html=html)
return render_template(
"view_questions.html",
round=round,
fund=fund,
question_html=html,
title=f"All Questions for {fund.short_name} - {round.short_name}",
)


@build_fund_bp.route("/fund/round/<round_id>/all_questions/<form_id>", methods=["GET"])
def view_form_questions(round_id, form_id):
"""
Generates the form data for this form, then uses that to generate the 'All Questions'
data for that form and returns that to render in a template.
"""
round = get_round_by_id(round_id)
fund = get_fund_by_id(round.fund_id)
form = get_form_by_id(form_id=form_id)
section_data = [
{
"section_title": f"Preview of form [{form.name_in_apply_json['en']}]",
"forms": [{"name": form.runner_publish_name, "form_data": build_form_json(form)}],
}
]

print_data = generate_print_data_for_sections(
section_data,
lang="en",
)
html = print_html(print_data, True)
return render_template(
"view_questions.html", round=round, fund=fund, question_html=html, title=form.name_in_apply_json["en"]
)


@build_fund_bp.route("/create_export_files/<round_id>", methods=["GET"])
Expand Down
49 changes: 0 additions & 49 deletions app/blueprints/fund_builder/templates/application.html

This file was deleted.

60 changes: 60 additions & 0 deletions app/blueprints/fund_builder/templates/build_application.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{% extends "base.html" %}
{%- from "govuk_frontend_jinja/components/button/macro.html" import govukButton -%}
{%- from "govuk_frontend_jinja/components/accordion/macro.html" import govukAccordion -%}
{%- from "govuk_frontend_jinja/components/summary-list/macro.html" import govukSummaryList -%}
{%- from "govuk_frontend_jinja/components/select/macro.html" import govukSelect -%}
{% block content %}
<div class="govuk-grid-row">
<div class="govuk-grid-column-full">
<h1 class="govuk-heading-l">Build Application</h1>
<h2 class="govuk-heading-m">{{ fund.short_name }} - {{round.title_json["en"]}} ({{ round.short_name }})</h2>
</div>
</div>
{{ govukButton({
"text": "View All Questions",
"href": url_for("build_fund_bp.view_all_questions", round_id=round.round_id) ,
"classes": "govuk-button--secondary"
})
}}
{{ govukButton({
"text": "Create export files for round",
"href": url_for("build_fund_bp.create_export_files", round_id=round.round_id) ,
"classes": "govuk-button--secondary"
})
}}
<ul class="app-task-list__items">
{{ govukButton({
"text": "Add Section",
"href": url_for("build_fund_bp.section", round_id=round.round_id) ,
"classes": "govuk-button--secondary"
})
}}
{% for section in round.sections %}
<li class="">
<span class="app-task-list__task-name">
<h3 class="govuk-heading-m">{{ section.index }}. {{ section.name_in_apply_json["en"] }}</h3>
</span>
<span class="app-task-list__task-actions">
<a href='{{ url_for("build_fund_bp.section", round_id=round.round_id, section_id=section.section_id) }}'>Edit</a>
<a href='{{ url_for("build_fund_bp.section",round_id=round.round_id, section_id=section.section_id, action="remove") }}'>Remove</a>
</span>
<ul class="app-task-list__items">
{% for form in section.forms %}
<li class="app-task-list__item task-list__new-design">
<span class="app-task-list__task-name">
<h3 class="govuk-body">
{{ section.index }}.&nbsp;{{ form.section_index }}.&nbsp;{{ form.name_in_apply_json["en"] }}
</h3>
</span>
<span class="app-task-list__task-actions">
<a href="{{ url_for('build_fund_bp.view_form_questions', round_id=round.round_id, form_id=form.form_id) }}">View</a>&nbsp;
<a href='{{ url_for("build_fund_bp.download_form_json", form_id=form.form_id) }}'>Download</a>&nbsp;
<a href='{{ url_for("build_fund_bp.preview_form", form_id=form.form_id) }}'>Preview</a>&nbsp;
</span>
</li>
{% endfor %}
</ul>
</li>
{% endfor %}
</ul>
{% endblock content %}
Loading

0 comments on commit 80ac962

Please sign in to comment.