UI: Execution update - table actions

* added table action buttons to pause resume and cancel execution

Screenshots:
http://pasteboard.co/2benOWcT.png

Partially implements blueprint: mistral-dashboard-executions-screen

Change-Id: I3b0b475f7e9e24f90396d145c453544cfcfe71ac
This commit is contained in:
Gal Margalit 2015-11-16 13:53:57 +00:00
parent d77840ff95
commit 936548c1e5
4 changed files with 107 additions and 6 deletions

View File

@ -66,6 +66,23 @@ def execution_get(request, execution_id):
return mistralclient(request).executions.get(execution_id) return mistralclient(request).executions.get(execution_id)
def execution_update(request, execution_id, field, value):
"""update specific execution field, either state or description
:param request: Request data
:param execution_id: Execution ID
:param field: flag - either Execution state or description
:param value: new update value
"""
if field == "state":
return mistralclient(request).\
executions.update(execution_id, value)
elif field == "description":
return mistralclient(request).\
executions.update(execution_id, None, value)
def execution_delete(request, execution_name): def execution_delete(request, execution_name):
"""Delete execution. """Delete execution.

View File

@ -22,7 +22,8 @@ TYPES = {
'SUCCESS': 'label-success', 'SUCCESS': 'label-success',
'ERROR': 'label-danger', 'ERROR': 'label-danger',
'DELAYED': 'label-default', 'DELAYED': 'label-default',
'RUNNING': 'label-info' 'RUNNING': 'label-info',
'PAUSED': 'label-warning'
} }

View File

@ -45,6 +45,91 @@ class DeleteExecution(tables.DeleteAction):
api.execution_delete(request, execution_name) api.execution_delete(request, execution_name)
class CancelExecution(tables.BatchAction):
name = "cancel execution"
classes = ("btn-danger",)
@staticmethod
def action_present(count):
return ungettext_lazy(
u"Cancel Execution",
u"Cancel Executions",
count
)
@staticmethod
def action_past(count):
return ungettext_lazy(
u"Canceled Execution",
u"Canceled Executions",
count
)
def allowed(self, request, instance):
if instance.state == "RUNNING":
return True
return False
def action(self, request, obj_id):
api.execution_update(request, obj_id, "state", "ERROR")
class PauseExecution(tables.BatchAction):
name = "pause execution"
@staticmethod
def action_present(count):
return ungettext_lazy(
u"Pause Execution",
u"Pause Executions",
count
)
@staticmethod
def action_past(count):
return ungettext_lazy(
u"Paused Execution",
u"Paused Executions",
count
)
def allowed(self, request, instance):
if instance.state == "RUNNING":
return True
return False
def action(self, request, obj_id):
api.execution_update(request, obj_id, "state", "PAUSED")
class ResumeExecution(tables.BatchAction):
name = "resume execution"
@staticmethod
def action_present(count):
return ungettext_lazy(
u"Resume Execution",
u"Resume Executions",
count
)
@staticmethod
def action_past(count):
return ungettext_lazy(
u"Resumed Execution",
u"Resumed Executions",
count
)
def allowed(self, request, instance):
if instance.state == "PAUSED":
return True
return False
def action(self, request, obj_id):
api.execution_update(request, obj_id, "state", "RUNNING")
class ExecutionsTable(tables.DataTable): class ExecutionsTable(tables.DataTable):
id = tables.Column( id = tables.Column(
"id", "id",
@ -100,4 +185,5 @@ class ExecutionsTable(tables.DataTable):
name = "executions" name = "executions"
verbose_name = _("Executions") verbose_name = _("Executions")
table_actions = (DeleteExecution, tables.FilterAction) table_actions = (DeleteExecution, tables.FilterAction)
row_actions = (DeleteExecution,) row_actions = (DeleteExecution, PauseExecution,
CancelExecution, ResumeExecution, DeleteExecution)

View File

@ -87,7 +87,6 @@ class DetailView(generic.TemplateView):
context = super(DetailView, self).get_context_data(**kwargs) context = super(DetailView, self).get_context_data(**kwargs)
task = {} task = {}
execution = {} execution = {}
if 'caller' in kwargs: if 'caller' in kwargs:
if kwargs['caller'] == 'task': if kwargs['caller'] == 'task':
kwargs['task_id'] = kwargs['execution_id'] kwargs['task_id'] = kwargs['execution_id']
@ -135,20 +134,18 @@ class CodeView(forms.ModalFormView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super(CodeView, self).get_context_data(**kwargs) context = super(CodeView, self).get_context_data(**kwargs)
column = self.kwargs['column']
execution = get_single_data( execution = get_single_data(
self.request, self.request,
self.kwargs['execution_id'], self.kwargs['execution_id'],
) )
column = self.kwargs['column']
io = {} io = {}
if column == 'input': if column == 'input':
io['name'] = _('Input') io['name'] = _('Input')
io['value'] = execution.input = prettyprint(execution.input) io['value'] = execution.input = prettyprint(execution.input)
elif column == 'output': elif column == 'output':
io['name'] = _('Output') io['name'] = _('Output')
io['value'] = execution.output = prettyprint(execution.output) io['value'] = execution.output = prettyprint(execution.output)
context['io'] = io context['io'] = io
return context return context