From 143ad65de6c81d1ed8abf3eca8f547a639cabea4 Mon Sep 17 00:00:00 2001 From: Gal Margalit Date: Thu, 19 Nov 2015 15:21:28 +0000 Subject: [PATCH] UI: Execution update - update description modal * added table action button and a modal to update execution description Screenshots: http://pasteboard.co/2fTvPcAA.png http://pasteboard.co/2fTCIKAL.png http://pasteboard.co/2fTENJz7.png Partially implements blueprint: mistral-dashboard-executions-screen Change-Id: If0e096b674640e12a095607c333954719a5ad594 --- mistraldashboard/executions/forms.py | 45 +++++++++++++++++++ mistraldashboard/executions/tables.py | 12 ++++- .../executions/_update_description.html | 7 +++ .../executions/update_description.html | 11 +++++ mistraldashboard/executions/urls.py | 3 ++ mistraldashboard/executions/views.py | 25 +++++++++++ 6 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 mistraldashboard/executions/forms.py create mode 100644 mistraldashboard/executions/templates/executions/_update_description.html create mode 100644 mistraldashboard/executions/templates/executions/update_description.html diff --git a/mistraldashboard/executions/forms.py b/mistraldashboard/executions/forms.py new file mode 100644 index 0000000..34d06da --- /dev/null +++ b/mistraldashboard/executions/forms.py @@ -0,0 +1,45 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from django.core.urlresolvers import reverse +from django.utils.translation import ugettext_lazy as _ + +from horizon import exceptions +from horizon import forms +from horizon import messages + +from mistraldashboard import api + + +class UpdateDescriptionForm(forms.SelfHandlingForm): + execution_id = forms.CharField(label=_("Execution ID"), + widget=forms.HiddenInput(), + required=False) + description = forms.CharField(max_length=255, + label=_("Execution description")) + + def handle(self, request, data): + try: + api.execution_update( + request, + data["execution_id"], + "description", + data["description"]) + msg = _('Successfully updated execution description.') + messages.success(request, msg) + + return True + + except Exception: + msg = _('Failed to update execution description.') + redirect = reverse('horizon:mistral:executions:index') + exceptions.handle(request, msg, redirect=redirect) diff --git a/mistraldashboard/executions/tables.py b/mistraldashboard/executions/tables.py index fe0caa7..edf193f 100644 --- a/mistraldashboard/executions/tables.py +++ b/mistraldashboard/executions/tables.py @@ -130,6 +130,13 @@ class ResumeExecution(tables.BatchAction): api.execution_update(request, obj_id, "state", "RUNNING") +class UpdateDescription(tables.LinkAction): + name = "updateDescription" + verbose_name = _("Update Description") + url = "horizon:mistral:executions:update_description" + classes = ("ajax-modal",) + + class ExecutionsTable(tables.DataTable): id = tables.Column( "id", @@ -185,5 +192,6 @@ class ExecutionsTable(tables.DataTable): name = "executions" verbose_name = _("Executions") table_actions = (DeleteExecution, tables.FilterAction) - row_actions = (DeleteExecution, PauseExecution, - CancelExecution, ResumeExecution, DeleteExecution) + row_actions = (DeleteExecution, UpdateDescription, + PauseExecution, CancelExecution, + ResumeExecution, DeleteExecution) diff --git a/mistraldashboard/executions/templates/executions/_update_description.html b/mistraldashboard/executions/templates/executions/_update_description.html new file mode 100644 index 0000000..129644d --- /dev/null +++ b/mistraldashboard/executions/templates/executions/_update_description.html @@ -0,0 +1,7 @@ +{% extends "horizon/common/_modal_form.html" %} +{% load i18n %} + +{% block modal-body-right %} +

{% trans "Description:" %}

+

{% trans "Enter execution description." %}

+{% endblock %} \ No newline at end of file diff --git a/mistraldashboard/executions/templates/executions/update_description.html b/mistraldashboard/executions/templates/executions/update_description.html new file mode 100644 index 0000000..ff54acf --- /dev/null +++ b/mistraldashboard/executions/templates/executions/update_description.html @@ -0,0 +1,11 @@ +{% extends 'base.html' %} +{% load i18n %} +{% block title %}{% endblock %} + +{% block page_header %} + {% include "horizon/common/_page_header.html" %} +{% endblock page_header %} + +{% block main %} + {% include 'mistral/executions/_update_description.html' %} +{% endblock %} \ No newline at end of file diff --git a/mistraldashboard/executions/urls.py b/mistraldashboard/executions/urls.py index a6185aa..6218e04 100644 --- a/mistraldashboard/executions/urls.py +++ b/mistraldashboard/executions/urls.py @@ -31,4 +31,7 @@ urlpatterns = patterns( {'column': 'output'}, name='output'), url(EXECUTIONS % 'input', views.CodeView.as_view(), {'column': 'input'}, name='input'), + url(EXECUTIONS % 'update_description', + views.UpdateDescriptionView.as_view(), + name='update_description'), ) diff --git a/mistraldashboard/executions/views.py b/mistraldashboard/executions/views.py index 68227b7..3415fa6 100644 --- a/mistraldashboard/executions/views.py +++ b/mistraldashboard/executions/views.py @@ -26,6 +26,7 @@ from horizon import tables from mistraldashboard import api from mistraldashboard.default.utils import prettyprint +from mistraldashboard.executions.forms import UpdateDescriptionForm from mistraldashboard.executions.tables import ExecutionsTable from mistraldashboard import forms as mistral_forms @@ -149,3 +150,27 @@ class CodeView(forms.ModalFormView): context['io'] = io return context + + +class UpdateDescriptionView(forms.ModalFormView): + template_name = 'mistral/executions/update_description.html' + modal_header = _("Update Execution Description") + form_id = "update_execution_description" + form_class = UpdateDescriptionForm + submit_label = _("Update") + success_url = reverse_lazy("horizon:mistral:executions:index") + submit_url = "horizon:mistral:executions:update_description" + cancel_url = "horizon:mistral:executions:index" + page_title = _("Update Execution Description") + + def get_initial(self): + return {"execution_id": self.kwargs["execution_id"]} + + def get_context_data(self, **kwargs): + context = super(UpdateDescriptionView, self).get_context_data(**kwargs) + context['submit_url'] = reverse( + self.submit_url, + args=[self.kwargs["execution_id"]] + ) + + return context