diff --git a/app/all_questions/metadata_utils.py b/app/all_questions/metadata_utils.py index 08f1c15c..5247ce8d 100644 --- a/app/all_questions/metadata_utils.py +++ b/app/all_questions/metadata_utils.py @@ -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 @@ -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 diff --git a/app/blueprints/fund_builder/routes.py b/app/blueprints/fund_builder/routes.py index a0574558..978d4ae5 100644 --- a/app/blueprints/fund_builder/routes.py +++ b/app/blueprints/fund_builder/routes.py @@ -33,7 +33,6 @@ 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 @@ -56,24 +55,6 @@ ) -@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("/fund/round//section", methods=["GET", "POST"]) def section(round_id): form: SectionForm = SectionForm() @@ -103,8 +84,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.view_app_config", round_id=round.round_id)) if section_id := request.args.get("section_id"): existing_section = get_section_by_id(section_id) form.section_id.data = section_id @@ -154,7 +135,7 @@ def view_fund(): params["fund"] = fund params["selected_fund_id"] = fund_id - return render_template("view_fund_config.html", **params) + return render_template("fund_config.html", **params) @build_fund_bp.route("/fund/round//application_config") @@ -164,7 +145,7 @@ def view_app_config(round_id): """ 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) + return render_template("build_application.html", round=round, fund=fund) @build_fund_bp.route("/fund//round//clone") @@ -176,16 +157,6 @@ def clone_round(round_id, fund_id): return redirect(url_for("build_fund_bp.view_fund", fund_id=fund_id)) -@build_fund_bp.route("/fund/round//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(): """ @@ -305,7 +276,13 @@ 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//all_questions/", methods=["GET"]) @@ -328,8 +305,10 @@ def view_form_questions(round_id, form_id): section_data, lang="en", ) - html = print_html(print_data) - return render_template("view_questions.html", round=round, fund=fund, question_html=html) + 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/", methods=["GET"]) diff --git a/app/blueprints/fund_builder/templates/application.html b/app/blueprints/fund_builder/templates/application.html deleted file mode 100644 index cae3082f..00000000 --- a/app/blueprints/fund_builder/templates/application.html +++ /dev/null @@ -1,49 +0,0 @@ -{% 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 %} -
-
-

Configure Round Application

-
- {{ govukSelect({ - "id": "round_id", - "name": "round_id", - "label": { - "text": "Select Round" - }, - "items": all_rounds, "value":selected_round_id}) }} - {{ govukButton({"text": "Configure Application"}) }} -
-
-
- {% if round %} - {% for section in round.sections %} -
-
-

{{ section.index }}. {{ section.name_in_apply_json["en"] }}

- {{ govukButton({ - "text": "Edit", - "href": url_for("build_fund_bp.section", round_id=round.round_id, section_id=section.section_id) , - "classes": "govuk-button--secondary" - }) - }} - {{ govukButton({ - "text": "Remove", - "href": url_for("build_fund_bp.section",round_id=round.round_id, section_id=section.section_id, action="remove") , - "classes": "govuk-button--secondary" - }) - }} -
-
- {% endfor %} - {{ govukButton({ - "text": "Add Section", - "href": url_for("build_fund_bp.section", round_id=round.round_id) , - "classes": "govuk-button--secondary" - }) - }} - {% endif %} -{% endblock %} diff --git a/app/blueprints/fund_builder/templates/build_application.html b/app/blueprints/fund_builder/templates/build_application.html new file mode 100644 index 00000000..2a3a13d7 --- /dev/null +++ b/app/blueprints/fund_builder/templates/build_application.html @@ -0,0 +1,61 @@ +{% 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 %} +
+
+

Build Application

+

{{ fund.short_name }} - {{ round.short_name }}

+
+
+ {{ 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" + }) + }} +
    + {{ 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 %} +
  • + +

    {{ section.index }}. {{ section.name_in_apply_json["en"] }}

    +
    + + Edit + Remove + +
      + {% for form in section.forms %} +
    • + +

      + {{ section.index }}. {{ form.section_index }}. {{ form.name_in_apply_json["en"] }} +

      +
      + + View  + Download  + Preview  + Remove  + +
    • + {% endfor %} +
    +
  • + {% endfor %} +
+{% endblock content %} diff --git a/app/blueprints/fund_builder/templates/fund_config.html b/app/blueprints/fund_builder/templates/fund_config.html new file mode 100644 index 00000000..123646c4 --- /dev/null +++ b/app/blueprints/fund_builder/templates/fund_config.html @@ -0,0 +1,170 @@ +{% 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 %} +
+
+

Fund Settings

+
+ {{ govukSelect({ + "id": "fund_id", + "name": "fund_id", + "label": { + "text": "Select Fund" + }, + "items": all_funds, "value":selected_fund_id}) }} + {{ govukButton({"text": "View Fund Config"}) }} +
+
+
+ {% if fund %} +
+
+

Fund Meta Data

+ {{ govukSummaryList({ + "classes": "govuk-!-margin-bottom-9", + "rows": [ + { + "key": { + "text": "Name" + }, + "value": { + "text": fund.name_json["en"] + }, + }, + { + "key": { + "text": "Short Name" + }, + "value": { + "text": fund.short_name + }, + }, + { + "key": { + "text": "Title" + }, + "value": { + "text": fund.title_json["en"] + }, + }, + { + "key": { + "text": "Description" + }, + "value": { + "text": fund.description_json["en"] + }, + }, + { + "key": { + "text": "Welsh Available" + }, + "value": { + "text": fund.welsh_available + }, + } + ] + }) }} +

Application Rounds

+ {% set rounds_content = [] %} + {% for round in fund.rounds %} + {% do rounds_content.append({"heading":{"text":round.title_json["en"]}, "content":{"expanded": False, "html": + govukSummaryList({ + "classes": "govuk-!-margin-bottom-9", + "rows": [ + { + "key": { + "text": "Short Name" + }, + "value": { + "text": round.short_name + }, + }, + + { + "key": { + "text": "Opens Date" + }, + "value": { + "text": round.opens + }, + + }, + { + "key": { + "text": "Deadline Date" + }, + "value": { + "text": round.deadline + }, + + }, + { + "key": { + "text": "Assessment Start Date" + }, + "value": { + "text": round.assessment_start + }, + + }, + { + "key": { + "text": "Assessment Deadline Date" + }, + "value": { + "text": round.assessment_deadline + }, + + }, + { + "key": { + "text": "Reminder Date" + }, + "value": { + "text": round.reminder_date + }, + }, + { + "key": { + "text": "Prospectus Link" + }, + "value": { + "text": round.prospectus_link + }, + }, + { + "key": { + "text": "Privacy Notice Link" + }, + "value": { + "text": round.privacy_notice_link + }, + }, + ] + }) + govukButton({ + "text": "Build Application", + "href": url_for("build_fund_bp.view_app_config", round_id=round.round_id), + "classes": "govuk-button--secondary" + }) + govukButton({ + "text": "Clone this round", + "href": url_for("build_fund_bp.clone_round", round_id=round.round_id, fund_id=fund.fund_id), + "classes": "govuk-button--secondary" + }) + + } }) %} + {% endfor %} + {{ govukAccordion({ + "id": "accordion-default", + "items": rounds_content + }) + }} +
+
+ {% endif %} + + +{% endblock content %} diff --git a/app/blueprints/self_serve/templates/index.html b/app/blueprints/fund_builder/templates/index.html similarity index 90% rename from app/blueprints/self_serve/templates/index.html rename to app/blueprints/fund_builder/templates/index.html index 15eb3ec3..248c31ca 100644 --- a/app/blueprints/self_serve/templates/index.html +++ b/app/blueprints/fund_builder/templates/index.html @@ -19,6 +19,14 @@

What do you want to do?

+

Fund Configuration (PoC)

+

Template Management (post PoC)

-

Fund Configuration (PoC)

-
diff --git a/app/blueprints/fund_builder/templates/view_application_config.html b/app/blueprints/fund_builder/templates/view_application_config.html deleted file mode 100644 index 849f9ee0..00000000 --- a/app/blueprints/fund_builder/templates/view_application_config.html +++ /dev/null @@ -1,63 +0,0 @@ -{% 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 %} -
-
-

View Full Application Config

-

{{ fund.short_name }} - {{ round.short_name }}

-
-
- {{ 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" - }) - }} -
    - {% for section in round.sections %} -
  1. -

    {{ section.index }}. {{ section.name_in_apply_json["en"] }}

    - {{ govukButton({ - "text": "Remove", - "href": url_for("build_fund_bp.section",round_id=round.round_id, section_id=section.section_id, action="remove") , - "classes": "govuk-button--warning" - }) }} -
      - {% for form in section.forms %} -
    • - - {{ section.index }}. {{ form.section_index }}. {{ form.name_in_apply_json["en"] }} - - - {{ govukButton({ - "text": "Download JSON", - "href": url_for("build_fund_bp.download_form_json", form_id=form.form_id) , - "classes": "govuk-button--secondary" - }) }} - {{ govukButton({ - "text": "Preview", - "href": url_for("build_fund_bp.preview_form", form_id=form.form_id) , - "classes": "govuk-button--secondary" - }) }} -
      - {{ govukButton({"text": "Remove", "classes": "govuk-button--warning"}) }} -
      -
      -
    • - {% endfor %} - - {% endfor %} -
- - {% endblock content %} diff --git a/app/blueprints/fund_builder/templates/view_fund_config.html b/app/blueprints/fund_builder/templates/view_fund_config.html deleted file mode 100644 index 2986137c..00000000 --- a/app/blueprints/fund_builder/templates/view_fund_config.html +++ /dev/null @@ -1,186 +0,0 @@ -{% 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 %} -
-
-

View Full Fund Config

-
- {{ govukSelect({ - "id": "fund_id", - "name": "fund_id", - "label": { - "text": "Select Fund" - }, - "items": all_funds, "value":selected_fund_id}) }} - {{ govukButton({"text": "View Fund Config"}) }} -
-
-
- {% if fund %} -
-
- {% set fund_content %} - {{ govukSummaryList({ - "classes": "govuk-!-margin-bottom-9", - "rows": [ - { - "key": { - "text": "Name" - }, - "value": { - "text": fund.name_json["en"] - }, - }, - { - "key": { - "text": "Short Name" - }, - "value": { - "text": fund.short_name - }, - }, - { - "key": { - "text": "Title" - }, - "value": { - "text": fund.title_json["en"] - }, - }, - { - "key": { - "text": "Description" - }, - "value": { - "text": fund.description_json["en"] - }, - }, - { - "key": { - "text": "Welsh Available" - }, - "value": { - "text": fund.welsh_available - }, - } - ] - }) }} - {% endset %} - {% set rounds_content %} - {% for round in fund.rounds %} -

{{round.title_json["en"]}}

- {{ govukSummaryList({ - "classes": "govuk-!-margin-bottom-9", - "rows": [ - { - "key": { - "text": "Short Name" - }, - "value": { - "text": round.short_name - }, - - }, - - { - "key": { - "text": "Opens Date" - }, - "value": { - "text": round.opens - }, - - }, - { - "key": { - "text": "Deadline Date" - }, - "value": { - "text": round.deadline - }, - - }, - { - "key": { - "text": "Assessment Start Date" - }, - "value": { - "text": round.assessment_start - }, - - }, - { - "key": { - "text": "Assessment Deadline Date" - }, - "value": { - "text": round.assessment_deadline - }, - - }, - { - "key": { - "text": "Reminder Date" - }, - "value": { - "text": round.reminder_date - }, - }, - { - "key": { - "text": "Prospectus Link" - }, - "value": { - "text": round.prospectus_link - }, - }, - { - "key": { - "text": "Privacy Notice Link" - }, - "value": { - "text": round.privacy_notice_link - }, - }, - ] - }) - }} - - {{ govukButton({ - "text": "View Application Config", - "href": url_for("build_fund_bp.view_app_config", round_id=round.round_id), - "classes": "govuk-button--secondary" - }) }} - {{ govukButton({ - "text": "View Assessment Config", - "href": url_for("build_fund_bp.view_assess_config", round_id=round.round_id), - "classes": "govuk-button--secondary" - }) }} - - {{ govukButton({ - "text": "Clone this round", - "href": url_for("build_fund_bp.clone_round", round_id=round.round_id, fund_id=fund.fund_id), - "classes": "govuk-button--secondary" - }) }} - {% endfor %} - - {% endset %} - {{ govukAccordion({ - "id": "accordion-default", - "items": [ - { - "heading": {"text":"Fund Meta Data" }, - "content": {"html": fund_content} - }, - {"heading": {"text":"Rounds" }, "content": {"html": rounds_content}}] - }) - }} -
-
- {% endif %} - - -{% endblock content %} diff --git a/app/blueprints/fund_builder/templates/view_questions.html b/app/blueprints/fund_builder/templates/view_questions.html index 07757485..fbfc09e4 100644 --- a/app/blueprints/fund_builder/templates/view_questions.html +++ b/app/blueprints/fund_builder/templates/view_questions.html @@ -1,9 +1,9 @@ {% extends "base.html" %} -{% set pageHeading %}All Questions for Round {{fund.short_name}} - {{round.short_name}} {% endset %} +{% set pageHeading %}{{title}} {% endset %} {% block content %}
- [Preview] Full list of application questions + [Preview] Application questions

{{pageHeading}}

{{ question_html|safe}}
diff --git a/app/blueprints/self_serve/templates/view_questions.html b/app/blueprints/self_serve/templates/view_questions.html deleted file mode 100644 index 19671c69..00000000 --- a/app/blueprints/self_serve/templates/view_questions.html +++ /dev/null @@ -1,11 +0,0 @@ -{% extends "base.html" %} -{% set pageHeading %}Selected Questions for {{section_name}}{% endset %} -{% block content %} -
-
- [Preview] Full list of application questions -

{{pageHeading}}

- {{ question_html|safe}} -
-
-{% endblock %} diff --git a/app/create_app.py b/app/create_app.py index d0a8b710..91bf3ea3 100644 --- a/app/create_app.py +++ b/app/create_app.py @@ -57,6 +57,7 @@ def create_app() -> Flask: PrefixLoader({"govuk_frontend_jinja": PackageLoader("govuk_frontend_jinja")}), ] ) + flask_app.jinja_env.add_extension("jinja2.ext.do") return flask_app diff --git a/app/export_config/generate_all_questions.py b/app/export_config/generate_all_questions.py index 824fc210..ad73faed 100644 --- a/app/export_config/generate_all_questions.py +++ b/app/export_config/generate_all_questions.py @@ -42,7 +42,7 @@ def print_html_toc(air: Airium, sections: dict): air(details["title_text"]) -def print_components(air: Airium, components: list): +def print_components(air: Airium, components: list, show_field_types: bool = False): """Prints the components within a page Args: @@ -51,24 +51,27 @@ def print_components(air: Airium, components: list): """ for c in components: # Print the title - if not c["hide_title"] and c["title"] is not None: - with air.p(klass="govuk-body"): - air(f"{c['title']}") - - for t in c["text"]: - # Print lists as
    bullet lists - if isinstance(t, list): - with air.ul(klass="govuk-list govuk-list--bullet"): - for bullet in t: - with air.li(klass=""): - air(bullet) - else: - # Just print the text + with air.div(klass="govuk-body all-questions-component"): + if not c["hide_title"] and c["title"] is not None: with air.p(klass="govuk-body"): - air(t) + air(f"{c['title']}") + if show_field_types: + air(f" [{c['type']}]") + + for t in c["text"]: + # Print lists as
      bullet lists + if isinstance(t, list): + with air.ul(klass="govuk-list govuk-list--bullet"): + for bullet in t: + with air.li(klass=""): + air(bullet) + else: + # Just print the text + with air.p(klass="govuk-body"): + air(t) -def print_html(sections: dict) -> str: +def print_html(sections: dict, show_field_types=False) -> str: """Prints the html for the supplied sections Args: @@ -110,7 +113,7 @@ def print_html(sections: dict) -> str: air(f"{header_info['heading_number']}. {header_info['title']}") # Print components within this form - print_components(air, header_info["components"]) + print_components(air, header_info["components"], show_field_types) idx_section += 1 diff --git a/app/static/src/styles/fab.css b/app/static/src/styles/fab.css index b5c12396..33320451 100644 --- a/app/static/src/styles/fab.css +++ b/app/static/src/styles/fab.css @@ -46,16 +46,23 @@ border-top: 1px solid #b1b4b6; } -.app-task-list__task-name { +.app-task-list__task-name h3 { display: inline; } -.app-task-list__task-actions { +.app-task-list__task-actions, .app-task-list__section-actions { float: right; margin-top: 0; margin-bottom: 0; } -.app-task-list__task-actions form { +.app-task-list__task-actions { display: inline; } +.app-task-list__section { + display:inline; +} + +.all-questions-component { + border-bottom: 1px solid #b1b4b6; +} diff --git a/tests/test_config_export.py b/tests/test_config_export.py index 4fc873a4..100730b7 100644 --- a/tests/test_config_export.py +++ b/tests/test_config_export.py @@ -205,6 +205,7 @@ def test_generate_form_jsons_for_round_invalid_input(seed_dynamic_data): def test_generate_fund_round_html(seed_dynamic_data): + # Setup: Prepare valid input parameters round_id = seed_dynamic_data["rounds"][0].round_id round_short_name = seed_dynamic_data["rounds"][0].short_name @@ -214,7 +215,7 @@ def test_generate_fund_round_html(seed_dynamic_data): expected_files = [ { "path": output_base_path / round_short_name / "html" / "full_application.html", - "expected_output": '
      \n

      \n Table of contents\n

      \n
        \n
      1. \n \n Organisation Information\n \n
      2. \n
      \n
      \n

      \n 1. Organisation Information\n

      \n

      \n 1.1. About your organisation\n

      \n

      \n 1.1.1. Organisation Name\n

      \n

      \n What is your organisation\'s name?\n

      \n

      \n This must match the regsitered legal organisation name\n

      \n

      \n How is your organisation classified?\n

      \n
        \n
      • \n Charity\n
      • \n
      • \n Public Limited Company\n
      • \n
      \n
      ', # noqa: E501 + "expected_output": '
      \n

      \n Table of contents\n

      \n
        \n
      1. \n \n Organisation Information\n \n
      2. \n
      \n
      \n

      \n 1. Organisation Information\n

      \n

      \n 1.1. About your organisation\n

      \n

      \n 1.1.1. Organisation Name\n

      \n
      \n

      \n What is your organisation\'s name?\n

      \n

      \n This must match the regsitered legal organisation name\n

      \n
      \n
      \n

      \n How is your organisation classified?\n

      \n
        \n
      • \n Charity\n
      • \n
      • \n Public Limited Company\n
      • \n
      \n
      \n
      ', # noqa: E501 } ] try: