Mistral-dashboard: Actions screen
Added “Run Action” screen to each row which allows of a specific action execution run. Added "Filter Action" to actions list. Print screen http://pasteboard.co/vRURv4E.png http://pasteboard.co/VqKFjEw.png Partially implements blueprint: Actions-screen-improvements Closes-Bug: #1505665 Change-Id: I359b402bbb60defe40112c7c95c7e18351277107
This commit is contained in:
parent
c56d137a90
commit
e93c979197
@ -12,6 +12,8 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import json
|
||||
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
@ -22,6 +24,58 @@ from horizon import messages
|
||||
from mistraldashboard import api
|
||||
|
||||
|
||||
class RunForm(forms.SelfHandlingForm):
|
||||
action_name = forms.CharField(
|
||||
label=_("Action"),
|
||||
required=True,
|
||||
widget=forms.TextInput(attrs={'readonly': 'readonly'})
|
||||
)
|
||||
input = forms.CharField(
|
||||
label=_("Input"),
|
||||
required=False,
|
||||
initial="{}",
|
||||
widget=forms.widgets.Textarea()
|
||||
)
|
||||
save_result = forms.CharField(
|
||||
label=_("Save result to DB"),
|
||||
required=False,
|
||||
widget=forms.CheckboxInput()
|
||||
)
|
||||
|
||||
def handle(self, request, data):
|
||||
try:
|
||||
input = json.loads(data['input'])
|
||||
except Exception as e:
|
||||
msg = _('Action input is invalid JSON: %s') % str(e)
|
||||
messages.error(request, msg)
|
||||
|
||||
return False
|
||||
|
||||
try:
|
||||
params = {"save_result": data['save_result'] == 'True'}
|
||||
action = api.action_run(
|
||||
request,
|
||||
data['action_name'],
|
||||
input,
|
||||
params
|
||||
)
|
||||
msg = _('Run action has been created with name '
|
||||
'"%s".') % action.name
|
||||
messages.success(request, msg)
|
||||
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
# In case of a failure, keep the dialog open and show the error
|
||||
msg = _('Failed to run action "%(action_name)s"'
|
||||
' %(e)s:') % {'action_name': data['action_name'],
|
||||
'e': str(e)
|
||||
}
|
||||
messages.error(request, msg)
|
||||
|
||||
return False
|
||||
|
||||
|
||||
class CreateForm(forms.SelfHandlingForm):
|
||||
definition_source = forms.ChoiceField(
|
||||
label=_('Definition Source'),
|
||||
|
@ -77,6 +77,13 @@ def cut(action, length=100):
|
||||
return inputs
|
||||
|
||||
|
||||
class RunAction(tables.LinkAction):
|
||||
name = "run"
|
||||
verbose_name = _("Run")
|
||||
url = "horizon:mistral:actions:run"
|
||||
classes = ("ajax-modal",)
|
||||
|
||||
|
||||
class ActionsTable(tables.DataTable):
|
||||
name = tables.Column(
|
||||
"name",
|
||||
@ -109,5 +116,10 @@ class ActionsTable(tables.DataTable):
|
||||
class Meta(object):
|
||||
name = "actions"
|
||||
verbose_name = _("Actions")
|
||||
table_actions = (CreateAction, UpdateAction, DeleteAction)
|
||||
row_actions = (DeleteAction, tables.FilterAction)
|
||||
table_actions = (
|
||||
CreateAction,
|
||||
UpdateAction,
|
||||
DeleteAction,
|
||||
tables.FilterAction,
|
||||
)
|
||||
row_actions = (RunAction, DeleteAction)
|
||||
|
7
mistraldashboard/actions/templates/actions/_run.html
Normal file
7
mistraldashboard/actions/templates/actions/_run.html
Normal file
@ -0,0 +1,7 @@
|
||||
{% extends "horizon/common/_modal_form.html" %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block modal-body-right %}
|
||||
<h3>{% trans "Description:" %}</h3>
|
||||
<p>{% trans "From here you can run an action." %}</p>
|
||||
{% endblock %}
|
@ -15,8 +15,6 @@
|
||||
<dd>{{ action.name }}</dd>
|
||||
<dt>{% trans "ID" %}</dt>
|
||||
<dd>{{ action.id }}</dd>
|
||||
<dt>{% trans "Description" %}</dt>
|
||||
<dd>{{ action.description }}</dd>
|
||||
<dt>{% trans "Tags" %}</dt>
|
||||
<dd>{{ action.tags }}</dd>
|
||||
<dt>{% trans "Created at" %}</dt>
|
||||
@ -29,6 +27,11 @@
|
||||
<dd>{{ action.scope }}</dd>
|
||||
<dt>{% trans "Input" %}</dt>
|
||||
<dd>{{ action.input }}</dd>
|
||||
<dt>{% trans "Description" %}</dt>
|
||||
<dd>{{ action.description }}</dd>
|
||||
<dt>{% trans "Definition" %}</dt>
|
||||
<dd><pre>{{ action.definition }}</pre></dd>
|
||||
|
||||
</dl>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
11
mistraldashboard/actions/templates/actions/run.html
Normal file
11
mistraldashboard/actions/templates/actions/run.html
Normal file
@ -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/actions/_run.html' %}
|
||||
{% endblock %}
|
@ -23,6 +23,7 @@ urlpatterns = patterns(
|
||||
'',
|
||||
url(r'^$', views.IndexView.as_view(), name='index'),
|
||||
url(ACTIONS % 'detail', views.DetailView.as_view(), name='detail'),
|
||||
url(ACTIONS % 'run', views.RunView.as_view(), name='run'),
|
||||
url(r'^create$', views.CreateView.as_view(), name='create'),
|
||||
url(r'^update$', views.UpdateView.as_view(), name='update'),
|
||||
)
|
||||
|
@ -77,3 +77,26 @@ class DetailView(generic.TemplateView):
|
||||
exceptions.handle(self.request, msg, redirect=redirect)
|
||||
|
||||
return action
|
||||
|
||||
|
||||
class RunView(forms.ModalFormView):
|
||||
form_class = mistral_forms.RunForm
|
||||
template_name = 'mistral/actions/run.html'
|
||||
form_id = "run_action"
|
||||
success_url = reverse_lazy("horizon:mistral:actions:index")
|
||||
submit_label = _("Run")
|
||||
modal_header = _("Run Action")
|
||||
page_title = _("Run Action")
|
||||
submit_url = "horizon:mistral:actions:run"
|
||||
|
||||
def get_initial(self, **kwargs):
|
||||
return {'action_name': self.kwargs['action_name']}
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(RunView, self).get_context_data(**kwargs)
|
||||
context['submit_url'] = reverse(
|
||||
self.submit_url,
|
||||
args=[self.kwargs["action_name"]]
|
||||
)
|
||||
|
||||
return context
|
||||
|
@ -332,3 +332,18 @@ def cron_trigger_delete(request, cron_trigger_name):
|
||||
"""
|
||||
|
||||
return mistralclient(request).cron_triggers.delete(cron_trigger_name)
|
||||
|
||||
|
||||
def action_run(request, action_name, input, params):
|
||||
"""Run specific action execution.
|
||||
|
||||
:param action_name: Action name
|
||||
:param input: input
|
||||
:param params: params
|
||||
"""
|
||||
|
||||
return mistralclient(request).action_executions.create(
|
||||
action_name,
|
||||
input,
|
||||
**params
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user