Skip to content

Commit

Permalink
FS:4616: FS-Feature/refactor import script for builder adapter (#31)
Browse files Browse the repository at this point in the history
* Update datetime formats for round config

* make outputsas empty []

* Add multiline text component and fix org question template

* add multilinetext field component type

* remove backlinktext references

* format date fields and add docker compose with form runner
  • Loading branch information
NarenderRajuB committed Sep 16, 2024
1 parent 2301735 commit ae74a1e
Show file tree
Hide file tree
Showing 19 changed files with 634 additions and 146 deletions.
53 changes: 5 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,55 +48,12 @@ Below is a docker-compose file that will start both the FAB app, and the form ru
```
workspace
| - dc
| - docker-compose.yml
| - digital-form-builder
| - docker-compose-dev.yml
| - digital-form-builder-adapter
| - funding-service-design-fund-application-builder
```
To run locally using digital-form-builder-adapter

docker-compose -f docker-compose-dev.yml up

```
services:
fab:
hostname: fab
build:
context: ../funding-service-design-fund-application-builder
dockerfile: Dockerfile
command: ["sh", "-c", "python -m flask db upgrade && inv create-test-data && python -m flask run --host 0.0.0.0 --port 8080"]
ports:
- 8080:8080
environment:
- FORM_RUNNER_INTERNAL_HOST=http://form-runner:3009
- FORM_RUNNER_EXTERNAL_HOST=http://localhost:3009
- DATABASE_URL=postgresql://postgres:password@fab-db:5432/fund_builder # pragma: allowlist secret
depends_on: [fab-db]
fab-db:
image: postgres
environment:
- POSTGRES_PASSWORD=password
- POSTGRES_DB=fund_builder
form-runner:
build:
context: ../digital-form-builder
dockerfile: ./fsd_config/Dockerfile
command: yarn runner startdebug
links:
- fab:fab
ports:
- 3009:3009
- 9228:9228
environment:
- LOG_LEVEL=debug
- 'NODE_CONFIG={"safelist": ["fab"]}'
- CONTACT_US_URL=http://localhost:3008/contact_us
- FEEDBACK_LINK=http://localhost:3008/feedback
- COOKIE_POLICY_URL=http://localhost:3008/cookie_policy
- ACCESSIBILITY_STATEMENT_URL=http://localhost:3008/accessibility_statement
- SERVICE_START_PAGE=http://localhost:3008/account
- MULTIFUND_URL=http://localhost:3008/account
- LOGOUT_URL=http://localhost:3004/sessions/sign-out
- PRIVACY_POLICY_URL=http://localhost:3008/privacy
- ELIGIBILITY_RESULT_URL=http://localhost:3008/eligibility-result
- PREVIEW_MODE=true
- NODE_ENV=development
```
1 change: 1 addition & 0 deletions app/all_questions/metadata_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,7 @@ def generate_print_data_for_form(section_idx: int, form_metadata: dict, form_idx
"freetextfield": "free_text",
"checkboxesfield": "list",
"multiinputfield": "table",
"multilinetextfield": "text",
"clientsidefileuploadfield": "s3bucketPath",
"radiosfield": "text",
"emailaddressfield": "text",
Expand Down
15 changes: 10 additions & 5 deletions app/blueprints/fund_builder/forms/round.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@ class RoundForm(FlaskForm):
description="Choose a unique short name with 6 or fewer characters",
validators=[DataRequired(), Length(max=6)],
)
opens = DateTimeField("Opens", format="%d-%m-%Y %H:%M", validators=[DataRequired()])
deadline = DateTimeField("Deadline", format="%d-%m-%Y %H:%M", validators=[DataRequired()])
assessment_start = DateTimeField("Assessment Start", format="%d-%m-%Y %H:%M", validators=[DataRequired()])
reminder_date = DateTimeField("Reminder Date", format="%d-%m-%Y %H:%M", validators=[DataRequired()])
assessment_deadline = DateTimeField("Assessment Deadline", format="%d-%m-%Y %H:%M", validators=[DataRequired()])
opens = DateTimeField("Opens", description="Enter date in dd-mm-yyyy hh:mi format",
format="%d-%m-%Y %H:%M", validators=[DataRequired()])
deadline = DateTimeField("Deadline", description="Enter date in dd-mm-yyyy hh:mi format",
format="%d-%m-%Y %H:%M", validators=[DataRequired()])
assessment_start = DateTimeField("Assessment Start", description="Enter date in dd-mm-yyyy hh:mi format",
format="%d-%m-%Y %H:%M", validators=[DataRequired()])
reminder_date = DateTimeField("Reminder Date", description="Enter date in dd-mm-yyyy hh:mi format",
format="%d-%m-%Y %H:%M", validators=[DataRequired()])
assessment_deadline = DateTimeField("Assessment Deadline", description="Enter date in dd-mm-yyyy hh:mi format",
format="%d-%m-%Y %H:%M", validators=[DataRequired()])
prospectus_link = URLField("Prospectus Link", validators=[DataRequired(), URL()])
privacy_notice_link = URLField("Privacy Notice Link", validators=[DataRequired(), URL()])
7 changes: 0 additions & 7 deletions app/blueprints/fund_builder/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,6 @@ def preview_form(form_id):
form = get_form_by_id(form_id)
form_json = build_form_json(form)

# Update the savePerPageUrl to point at the dev route to save responses
form_json["outputs"][0]["outputConfiguration"][
"savePerPageUrl"
] = f"http://{Config.FAB_HOST}{Config.FAB_SAVE_PER_PAGE}"
try:
publish_response = requests.post(
url=f"{Config.FORM_RUNNER_URL}/publish", json={"id": form.runner_publish_name, "configuration": form_json}
Expand All @@ -276,9 +272,6 @@ def download_form_json(form_id):
form = get_form_by_id(form_id)
form_json = build_form_json(form)

form_json["outputs"][0]["outputConfiguration"][
"savePerPageUrl"
] = f"http://{Config.FAB_HOST}{Config.FAB_SAVE_PER_PAGE}"
return Response(
response=json.dumps(form_json),
mimetype="application/json",
Expand Down
11 changes: 6 additions & 5 deletions app/blueprints/fund_builder/templates/round.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{% extends "base.html" %}
{% from "macros/wtfToGovUk.html" import input %}
{% from "macros/wtfToGovUk.html" import dateinput %}
{% from "macros/wtfToGovUk.html" import yes_no %}
{%- from "govuk_frontend_jinja/components/button/macro.html" import govukButton -%}
{%- from "govuk_frontend_jinja/components/select/macro.html" import govukSelect -%}
Expand All @@ -20,11 +21,11 @@ <h1 class="govuk-heading-l">Create a Round</h1>
"items": all_funds})}}
{{input(form.title_en)}}
{{input(form.short_name)}}
{{input(form.opens)}}
{{input(form.deadline)}}
{{input(form.assessment_start)}}
{{input(form.reminder_date)}}
{{input(form.assessment_deadline)}}
{{dateinput(form.opens)}}
{{dateinput(form.deadline)}}
{{dateinput(form.assessment_start)}}
{{dateinput(form.reminder_date)}}
{{dateinput(form.assessment_deadline)}}
{{input(form.prospectus_link)}}
{{input(form.privacy_notice_link)}}

Expand Down
10 changes: 5 additions & 5 deletions app/blueprints/fund_builder/templates/view_fund_config.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ <h2 class="govuk-heading-m">{{round.title_json["en"]}}</h2>
"text": "Opens Date"
},
"value": {
"text": round.opens
"text": round.opens.strftime('%d-%m-%Y %H:%M')
},

},
Expand All @@ -99,7 +99,7 @@ <h2 class="govuk-heading-m">{{round.title_json["en"]}}</h2>
"text": "Deadline Date"
},
"value": {
"text": round.deadline
"text": round.deadline.strftime('%d-%m-%Y %H:%M')
},

},
Expand All @@ -108,7 +108,7 @@ <h2 class="govuk-heading-m">{{round.title_json["en"]}}</h2>
"text": "Assessment Start Date"
},
"value": {
"text": round.assessment_start
"text": round.assessment_start.strftime('%d-%m-%Y %H:%M')
},

},
Expand All @@ -117,7 +117,7 @@ <h2 class="govuk-heading-m">{{round.title_json["en"]}}</h2>
"text": "Assessment Deadline Date"
},
"value": {
"text": round.assessment_deadline
"text": round.assessment_deadline.strftime('%d-%m-%Y %H:%M')
},

},
Expand All @@ -126,7 +126,7 @@ <h2 class="govuk-heading-m">{{round.title_json["en"]}}</h2>
"text": "Reminder Date"
},
"value": {
"text": round.reminder_date
"text": round.reminder_date.strftime('%d-%m-%Y %H:%M')
},
},
{
Expand Down
24 changes: 24 additions & 0 deletions app/db/migrations/versions/~2024_09_10_1717-d69508409404_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""empty message
Revision ID: d69508409404
Revises: 117417bed885
Create Date: 2024-09-10 17:17:58.014693
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = 'd69508409404'
down_revision = '117417bed885'
branch_labels = None
depends_on = None


def upgrade():
op.execute("ALTER TYPE componenttype ADD VALUE 'MULTILINE_TEXT_FIELD';")


def downgrade():
pass
4 changes: 4 additions & 0 deletions app/db/models/application_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class ComponentType(Enum):
CHECKBOXES_FIELD = "CheckboxesField"
CLIENT_SIDE_FILE_UPLOAD_FIELD = "ClientSideFileUploadField"
WEBSITE_FIELD = "WebsiteField"
MULTILINE_TEXT_FIELD = "MultilineTextField"



@dataclass
Expand Down Expand Up @@ -226,6 +228,8 @@ def assessment_display_type(self):
"yesnofield": "text",
"freetextfield": "free_text",
"checkboxesfield": "list",
#TODO add multilinetext field and update types of components in sync with formrunner
#"multilinetextfield": "list",
"multiinputfield": "table",
"clientsidefileuploadfield": "s3bucketPath",
"radiosfield": "text",
Expand Down
10 changes: 1 addition & 9 deletions app/export_config/generate_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,12 @@
BASIC_FORM_STRUCTURE = {
"metadata": {},
"startPage": None,
"backLinkText": "Go back to application overview",
"pages": [],
"lists": [],
"conditions": [],
"fees": [],
"sections": [],
"outputs": [
{
"name": "update-form",
"title": "Update form in application store",
"type": "savePerPage",
"outputConfiguration": {"savePerPageUrl": True},
}
],
"outputs": [],
"skipSummary": False,
"name": "",
}
Expand Down
16 changes: 0 additions & 16 deletions app/export_config/generate_fund_round_form_jsons.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"name": {"type": "string"},
"metadata": {"type": "object"},
"startPage": {"type": "string"},
"backLinkText": {"type": "string"},
"sections": {"type": "array"},
"pages": {
"type": "array",
Expand Down Expand Up @@ -52,28 +51,13 @@
"fees": {"type": "array"},
"outputs": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {"type": "string"},
"title": {"type": "string"},
"type": {"type": "string"},
"outputConfiguration": {
"type": "object",
"properties": {"savePerPageUrl": {"type": "boolean"}},
"required": ["savePerPageUrl"],
},
},
"required": ["name", "title", "type", "outputConfiguration"],
},
},
"skipSummary": {"type": "boolean"},
# Add other top-level keys as needed
},
"required": [
"metadata",
"startPage",
"backLinkText",
"pages",
"lists",
"conditions",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"metadata": {},
"startPage": "/asset-information",
"backLinkText": "Go back to application overview",
"pages": [
{
"title": "Asset information",
Expand Down Expand Up @@ -980,16 +979,7 @@
}
],
"fees": [],
"outputs": [
{
"name": "update-form",
"title": "Update form in application store",
"type": "savePerPage",
"outputConfiguration": {
"savePerPageUrl": "True"
}
}
],
"outputs": [],
"version": 2,
"skipSummary": false,
"name": "Apply for funding to save an asset in your community",
Expand Down
Loading

0 comments on commit ae74a1e

Please sign in to comment.