Skip to content

Commit

Permalink
beer-garden#325 - cleanup and layout improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
obr42 committed Apr 14, 2023
1 parent 1c78714 commit 39abede
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 117 deletions.
24 changes: 10 additions & 14 deletions functionary/ui/templates/core/function_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,16 @@ <h2 class="mt-2 mb-1">
</div>
{% endif %}
{% if form.fields %}
<div class="border border-dark-subtle rounded form-fill">
<div class="row mx-2 mt-3">
<div class="col col-lg-10 col-xl-9 col-xxl-8">
<form id="taskCreateForm"
method="post"
action="{% url 'ui:function-execute' %}"
enctype="multipart/form-data">
{% csrf_token %}
<input type="hidden" name="function_id" value="{{ function.id }}"/>
{{ form.non_field_errors }}
{{ form }}
</form>
</div>
</div>
<div class="border border-dark-subtle rounded form-fill px-4 pt-3">
<form id="taskCreateForm"
method="post"
action="{% url 'ui:function-execute' %}"
enctype="multipart/form-data">
{% csrf_token %}
<input type="hidden" name="function_id" value="{{ function.id }}"/>
{{ form.non_field_errors }}
{{ form }}
</form>
</div>
{% endif %}
<div>
Expand Down
41 changes: 26 additions & 15 deletions functionary/ui/templates/core/workflow_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,19 @@ <h2 class="mt-2 mb-1">
</ul>
</div>
{% endif %}
<div class="border border-dark-subtle rounded form-fill">
<div class="border border-dark-subtle rounded form-fill px-4 pt-3">
{% if form.fields %}
<div class="row mx-2 mt-3">
<div class="col col-lg-10 col-xl-9 col-xxl-8">
<form id="taskCreateForm"
method="post"
action="{% url 'ui:function-execute' %}"
enctype="multipart/form-data">
{% csrf_token %}
<input type="hidden" name="workflow_id" value="{{ workflow.id }}"/>
{{ form.non_field_errors }}
{{ form }}
</form>
</div>
</div>
<form id="taskCreateForm"
method="post"
action="{% url 'ui:function-execute' %}"
enctype="multipart/form-data">
{% csrf_token %}
<input type="hidden" name="workflow_id" value="{{ workflow.id }}"/>
{{ form.non_field_errors }}
{{ form }}
</form>
{% else %}
<p class="font-monospace m-4">No parameters defined.</p>
<p class="font-monospace m-0 mb-4">No parameters defined.</p>
{% endif %}
</div>
{% if workflow.first_step %}
Expand All @@ -70,6 +66,21 @@ <h2 class="mt-2 mb-1">
</div>
{% endif %}
{% endif %}
{% if workflow.first_step %}
<div>
<h3 class="fw-semibold">
<i class="fa fa-stairs fa-sm fa-fw me-1"></i>Steps
</h3>
<ul id="envs" class="list-group list-group-flush">
{% for step in workflow.ordered_steps %}
<li class="list-group-item">
<p class="fw-bold mb-0">{{ step.name }}</p>
<p class="ms-4 mb-0">{{ step.function }}</p>
</li>
{% endfor %}
</ul>
</div>
{% endif %}
</div>
</div>
</div>
Expand Down
62 changes: 29 additions & 33 deletions functionary/ui/templates/forms/workflow/workflow_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,40 +30,36 @@ <h2 class="my-2">
<div class="vstack gap-4 my-4">
{% if form %}
<div class="border border-dark-subtle rounded form-fill pt-3 px-4">
<div class="row">
<div class="col col-lg-10 col-xl-9 col-xxl-8">
<form id="workflow-form"
method="post"
hx-post="{% if workflow %}{% url 'ui:workflow-update' workflow.id %}{% else %}{% url 'ui:workflow-create' %}{% endif %}">
{% csrf_token %}
<div class="mb-3">
<label for="{{ form.name.id_for_label }}" class="form-label">{{ form.name.label }}</label>
{% render_field form.name class="form-control" placeholder=form.name.label %}
</div>
{{ form.name.errors }}
<div class="mb-3">
<label for="{{ form.description.id_for_label }}" class="form-label">{{ form.description.label }}</label>
{% render_field form.description class="form-control" rows=2 cols=40 placeholder=form.description.label %}
</div>
{{ form.description.errors }}
<input type="hidden"
name="environment"
value="{{ request.session.environment_id }}"/>
{{ form.non_field_errors }}
</form>
<div class="mb-4">
<button class="btn btn-primary"
type="submit"
form="workflow-form"
title="{% if workflow %}Save{% else %}Next{% endif %}">
{% if workflow %}
Save
{% else %}
Next
{% endif %}
</button>
</div>
<form id="workflow-form"
method="post"
hx-post="{% if workflow %}{% url 'ui:workflow-update' workflow.id %}{% else %}{% url 'ui:workflow-create' %}{% endif %}">
{% csrf_token %}
<div class="mb-3">
<label for="{{ form.name.id_for_label }}" class="form-label">{{ form.name.label }}</label>
{% render_field form.name class="form-control" placeholder=form.name.label %}
</div>
{{ form.name.errors }}
<div class="mb-3">
<label for="{{ form.description.id_for_label }}" class="form-label">{{ form.description.label }}</label>
{% render_field form.description class="form-control" rows=2 cols=40 placeholder=form.description.label %}
</div>
{{ form.description.errors }}
<input type="hidden"
name="environment"
value="{{ request.session.environment_id }}"/>
{{ form.non_field_errors }}
</form>
<div class="mb-4">
<button class="btn btn-primary"
type="submit"
form="workflow-form"
title="{% if workflow %}Save{% else %}Next{% endif %}">
{% if workflow %}
Save
{% else %}
Next
{% endif %}
</button>
</div>
</div>
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<td class="text-center">
{% if parameter.required %}<i class="fa fa-check"/>{% endif %}
</td>
<td hx-target="closest tr" hx-swap="outerHTML">
<td class="text-end" hx-target="closest tr" hx-swap="outerHTML">
<button class="btn btn-small text-info fa fa-pencil-alt"
type="button"
title="Edit"
Expand All @@ -28,7 +28,7 @@
hx-get="{% url 'ui:workflowparameter-update' workflow.pk parameter.pk %}"/>
<button class="btn btn-small text-danger fa fa-trash"
type="button"
hx-confirm="Are you sure you want to delete parameter {{ parameter.name }}?"
hx-confirm="Are you sure you want to delete {{ parameter.name }}?"
title="Delete"
hx-delete="{% url 'ui:workflowparameter-delete' workflow.pk parameter.pk %}"/>
</td>
Expand Down
4 changes: 2 additions & 2 deletions functionary/ui/templates/partials/workflows/step_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<td>{{ step.name }}</td>
<td>{{ step.function }}</td>
<td class="json-container">{{ step.parameter_template }}</td>
<td>
<td class="text-end">
<button class="btn btn-small text-success fa fa-plus"
type="button"
title="Add Step Below"
Expand All @@ -57,7 +57,7 @@
hx-get="{% url 'ui:workflowstep-update' workflow.pk step.pk %}"/>
<button class="btn btn-small text-danger fa fa-trash"
type="button"
hx-confirm="Are you sure you want to delete step {{ step.name }}?"
hx-confirm="Are you sure you want to delete {{ step.name }}?"
title="Delete"
hx-target="#workflow-steps"
hx-swap="outerHTML"
Expand Down
33 changes: 0 additions & 33 deletions functionary/ui/tests/views/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,39 +247,6 @@ def test_update_view_returns_403_for_post_without_access(
assert response.status_code == 403


@pytest.mark.django_db
def test_delete_view_allows_post_with_access(client, workflow, user_with_edit_access):
"""PermissionedDeleteView allows POST for a user with access"""
client.force_login(user_with_edit_access)

session = client.session
session["environment_id"] = str(workflow.environment.id)
session.save()

url = reverse("ui:workflow-delete", kwargs={"pk": workflow.pk})
response = client.post(url)

# 302 expected for redirect to "success_url"
assert response.status_code == 302


@pytest.mark.django_db
def test_delete_view_returns_403_for_post_without_access(
client, workflow, user_with_read_access
):
"""PermissionedDeleteView allows POST for a user with access"""
client.force_login(user_with_read_access)

session = client.session
session["environment_id"] = str(workflow.environment.id)
session.save()

url = reverse("ui:workflow-delete", kwargs={"pk": workflow.pk})
response = client.post(url)

assert response.status_code == 403


@pytest.mark.django_db
def test_nested_route_filters_by_parent_object(
client,
Expand Down
15 changes: 0 additions & 15 deletions functionary/ui/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,6 @@
(task.TaskResultsView.as_view()),
name="task-results",
),
path(
"variables/<parent_id>",
(variable.all_variables),
name="all-variables",
),
path(
"add_variable/<parent_id>",
(variable.VariableView.as_view()),
Expand All @@ -104,11 +99,6 @@
(variable.delete_variable),
name="variable-delete",
),
path(
"detail_variable/<pk>",
(variable.VariableView.as_view()),
name="variable-detail",
),
path(
"environment_select/",
(environment_select.EnvironmentSelectView.as_view()),
Expand Down Expand Up @@ -242,11 +232,6 @@
(workflow.WorkflowUpdateView.as_view()),
name="workflow-update",
),
path(
"workflow/<uuid:pk>/delete",
(workflow.WorkflowDeleteView.as_view()),
name="workflow-delete",
),
path(
"workflow/<uuid:workflow_pk>/parameter/create",
(workflow.WorkflowParameterCreateView.as_view()),
Expand Down
2 changes: 1 addition & 1 deletion functionary/ui/views/workflow/detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


class WorkflowDetailView(PermissionedDetailView):
"""Task create view for Workflows"""
"""Workflow detail and task creation view"""

model = Workflow
template_name = "core/workflow_detail.html"
Expand Down
4 changes: 2 additions & 2 deletions functionary/ui/views/workflow/update.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.urls import reverse_lazy
from django.urls import reverse
from django_htmx.http import HttpResponseClientRedirect

from core.models import Workflow
Expand All @@ -14,6 +14,6 @@ class WorkflowUpdateView(PermissionedUpdateView):

def form_valid(self, form):
form.save()
success_url = reverse_lazy("ui:workflow-list")
success_url = reverse("ui:workflow-list")

return HttpResponseClientRedirect(success_url)

0 comments on commit 39abede

Please sign in to comment.