diff --git a/app/blueprints/self_serve/data/data_access.py b/app/blueprints/self_serve/data/data_access.py index fd7509a..7e22e16 100644 --- a/app/blueprints/self_serve/data/data_access.py +++ b/app/blueprints/self_serve/data/data_access.py @@ -66,6 +66,7 @@ def save_page(page: dict): def get_list_by_id(id: str) -> dict: return LISTS.get(id, None) +# TODO Implement front end journey that can use the section/form/page/component CRUD operations # from app.db.queries.application import insert_new_section # from app.db.queries.application import insert_new_form # from app.db.queries.application import insert_new_page @@ -73,14 +74,34 @@ def get_list_by_id(id: str) -> dict: def save_template_component(component: dict): """ + TODO: Save a template component to the database Parameters: component: dict The component to save to the database as a template Returns: dict The saved component - """ - """ temp in memory solution """ + component_config = { + "page_id": component.get("page_id"), + "theme_id": component.get("theme_id"), + "title": component.get("title"), + "hint_text": component.get("hint"), + "options": component.get("options"), + "type": component.get("question_type"), + "template_name": component.get("template_name"), + "is_template": True, + "audit_info": component.get("audit_info"), + "page_index": component.get("page_index"), + "theme_index": component.get("theme_index"), + "conditions": component.get("conditions"), + "runner_component_name": component.get("runner_component_name"), + "list_id": component.get("list_id"), + } + + return insert_new_component(component_config) + """ + + # temp in memory solution COMPONENTS.append( { "json_snippet": { @@ -93,97 +114,90 @@ def save_template_component(component: dict): "builder_display_name": component["builder_display_name"], } ) - """ end temp """ - - # component_config = { - # "page_id": component.get("page_id"), - # "theme_id": component.get("theme_id"), - # "title": component.get("title"), - # "hint_text": component.get("hint"), - # "options": component.get("options"), - # "type": component.get("question_type"), - # "template_name": component.get("template_name"), - # "is_template": True, - # "audit_info": component.get("audit_info"), - # "page_index": component.get("page_index"), - # "theme_index": component.get("theme_index"), - # "conditions": component.get("conditions"), - # "runner_component_name": component.get("runner_component_name"), - # "list_id": component.get("list_id"), - # } - - # return insert_new_component(component_config) + + def save_template_page(page: dict): """ + TODO: Save a template page to the database Parameters: page: dict The page to save to the database as a template Returns: dict The saved page - """ - PAGES.append(page) # Temp in memory solution + page_config = { + "form_id": page.get("form_id"), + "name_in_apply_json": { + "en": page.get("form_display_name"), + }, + "template_name": page.get("builder_display_name"), + "is_template": True, + "audit_info": page.get("audit_info"), + "form_index": page.get("form_index"), + "display_path": page.get("display_path"), + "controller": page.get("controller"), + } + + return insert_new_page(page_config) + """ - # page_config = { - # "form_id": page.get("form_id"), - # "name_in_apply_json": { - # "en": page.get("form_display_name"), - # }, - # "template_name": page.get("builder_display_name"), - # "is_template": True, - # "audit_info": page.get("audit_info"), - # "form_index": page.get("form_index"), - # "display_path": page.get("display_path"), - # "controller": page.get("controller"), - # } + # Temp in memory solution + PAGES.append(page) - # return insert_new_page(page_config) def save_template_form(form: dict): """ + TODO: Save a template form to the database Parameters: form: dict The form to save to the database as a template Returns: dict The saved form + form_config = { + "name_in_apply_json": { + "en": form.get("form_title"), + }, + "is_template": True, + "template_name": form.get("builder_display_name"), + "audit_info": form.get("audit_info"), + "section_id": form.get("section_id"), + "section_index": form.get("section_index"), + "runner_publish_name": None # This is a template + } + + insert_new_form(form_config) """ - FORMS.append(form) # Temp in memory solution - - # form_config = { - # "name_in_apply_json": { - # "en": form.get("form_title"), - # }, - # "is_template": True, - # "template_name": form.get("builder_display_name"), - # "audit_info": form.get("audit_info"), - # "section_id": form.get("section_id"), - # "section_index": form.get("section_index"), - # "runner_publish_name": None # This is a template - # } - - # insert_new_form(form_config) + + # Temp in memory solution + FORMS.append(form) + + def save_template_section(section: dict): """ + TODO: Save a template section to the database Parameters: section: dict The section to save to the database as a template Returns: dict The saved section + + section_config = { + "name_in_apply_json": { + "en": section.get("section_display_name"), + }, + "is_template": True, # Assuming this remains a constant value + "template_name": section.get("builder_display_name"), + "description": section.get("description"), + "audit_info": section.get("audit_info"), + } + + return insert_new_section(section_config) """ - SECTIONS.append(section) # Temp in memory solution - - # section_config = { - # "name_in_apply_json": { - # "en": section.get("section_display_name"), - # }, - # "is_template": True, # Assuming this remains a constant value - # "template_name": section.get("builder_display_name"), - # "description": section.get("description"), - # "audit_info": section.get("audit_info"), - # } - - # return insert_new_section(section_config) + + # Temp in memory solution + SECTIONS.append(section) + diff --git a/app/blueprints/self_serve/routes.py b/app/blueprints/self_serve/routes.py index 9b0847a..009824b 100644 --- a/app/blueprints/self_serve/routes.py +++ b/app/blueprints/self_serve/routes.py @@ -118,8 +118,16 @@ def view_section_questions(): # CRUD routes # Create routes -@self_serve_bp.route("create_section", methods=["GET", "POST"]) -def create_section(): +@self_serve_bp.route("section", methods=["GET", "POST"]) +def crud_section(): + # TODO: Create frontend routes and connect to middleware + if request.method == "GET": + pass + if request.method == "PUT": + pass + if request.method == "DELETE": + pass + form = SectionForm() if form.validate_on_submit(): save_template_section(form.as_dict()) @@ -139,8 +147,16 @@ def create_section(): # save to db here return render_template("create_section.html", available_forms=available_forms, form=form) -@self_serve_bp.route("/create_form", methods=["GET", "POST"]) -def create_form(): +@self_serve_bp.route("/form", methods=["GET", "POST"]) +def crud_form(): + # TODO: Create frontend routes and connect to middleware + if request.method == "GET": + pass + if request.method == "PUT": + pass + if request.method == "DELETE": + pass + form = FormForm() if form.validate_on_submit(): new_form = { @@ -170,8 +186,16 @@ def create_form(): ) return render_template("create_form.html", available_pages=available_pages, form=form) -@self_serve_bp.route("/create_page", methods=["GET", "POST"]) -def create_page(): +@self_serve_bp.route("/page", methods=["GET", "POST", "PUT", "DELETE"]) +def crud_page(): + # TODO: Create frontend routes and connect to middleware + if request.method == "GET": + pass + if request.method == "PUT": + pass + if request.method == "DELETE": + pass + form = PageForm() if form.validate_on_submit(): new_page = { @@ -195,30 +219,9 @@ def create_page(): ] return render_template("create_page.html", form=form, available_questions=available_questions) -@self_serve_bp.route("/create_question", methods=["GET", "POST"]) -def create_question(): - form = QuestionForm() - question = form.as_dict() - if form.validate_on_submit(): - save_template_component(question) - flash(message=f"Question '{question['title']}' was saved") - return redirect(url_for("self_serve_bp.index")) - return render_template("create_question.html", form=form) - - - -# Edit and Delete routes -@self_serve_bp.route("/edit_section", methods=["GET", "PUT", "DELETE"]) -def edit_section(): - if request.method == "GET": - pass - if request.method == "PUT": - pass - if request.method == "DELETE": - pass - -@self_serve_bp.route("/edit_form", methods=["GET", "PUT", "DELETE"]) -def edit_form(): +@self_serve_bp.route("/question", methods=["GET", "PUT", "POST" "DELETE"]) +def crud_question(): + # TODO: Create frontend routes and connect to middleware if request.method == "GET": pass if request.method == "PUT": @@ -226,20 +229,11 @@ def edit_form(): if request.method == "DELETE": pass -@self_serve_bp.route("/edit_page", methods=["GET", "PUT", "DELETE"]) -def edit_page(): - if request.method == "GET": - pass - if request.method == "PUT": - pass - if request.method == "DELETE": - pass + form = QuestionForm() + question = form.as_dict() + if form.validate_on_submit(): + save_template_component(question) + flash(message=f"Question '{question['title']}' was saved") + return redirect(url_for("self_serve_bp.index")) + return render_template("create_question.html", form=form) -@self_serve_bp.route("/edit_question", methods=["GET", "PUT", "DELETE"]) -def edit_question(): - if request.method == "GET": - pass - if request.method == "PUT": - pass - if request.method == "DELETE": - pass diff --git a/app/blueprints/self_serve/templates/create_section.html b/app/blueprints/self_serve/templates/create_section.html index b085df5..d79fd61 100644 --- a/app/blueprints/self_serve/templates/create_section.html +++ b/app/blueprints/self_serve/templates/create_section.html @@ -207,7 +207,7 @@