Add actions panel

Partially implements blueprint mistral-dashboard-crud-operations

Change-Id: I943c11c63dd5f12df82058a10bfd015d50d41d8c
This commit is contained in:
Zhenguo Niu 2015-07-31 11:34:36 +08:00
parent 054f579494
commit c4822e3314
8 changed files with 165 additions and 3 deletions

View File

View File

@ -0,0 +1,27 @@
# Copyright 2015 Huawei Technologies Co., Ltd.
#
# 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.utils.translation import ugettext_lazy as _
import horizon
from mistraldashboard import dashboard
class Actions(horizon.Panel):
name = _("Actions")
slug = 'actions'
dashboard.MistralDashboard.register(Actions)

View File

@ -0,0 +1,62 @@
# Copyright 2015 Huawei Technologies Co., Ltd.
#
# 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.utils.translation import ugettext_lazy as _
from horizon import tables
from horizon.utils import filters
def tags_to_string(action):
return ', '.join(action.tags) if action.tags else None
def cut(action, length=100):
inputs = action.input
if inputs and len(inputs) > length:
return "%s..." % inputs[:length]
else:
return inputs
class ActionsTable(tables.DataTable):
name = tables.Column("name", verbose_name=_("Name"))
description = tables.Column("description", verbose_name=_("Description"))
is_system = tables.Column("is_system", verbose_name=_("Is System"))
tags = tables.Column(tags_to_string, verbose_name=_("Tags"))
inputs = tables.Column(cut, verbose_name=_("Input"))
created = tables.Column(
"created_at",
verbose_name=_("Created"),
filters=(
filters.parse_isotime,
filters.timesince_or_never
)
)
updated = tables.Column(
"updated_at",
verbose_name=_("Updated"),
filters=(
filters.parse_isotime,
filters.timesince_or_never
)
)
def get_object_id(self, datum):
return datum.name
class Meta(object):
name = "actions"
verbose_name = _("Actions")

View File

@ -0,0 +1,11 @@
{% extends 'mistral/default/base.html' %}
{% load i18n %}
{% block title %}{% trans "Actions" %}{% endblock %}
{% block page_header %}
{% include "horizon/common/_page_header.html" with title=_("Actions") %}
{% endblock page_header %}
{% block main %}
{{ table.render }}
{% endblock %}

View File

@ -0,0 +1,24 @@
# Copyright 2015 Huawei Technologies Co., Ltd.
#
# 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.conf.urls import patterns # noqa
from django.conf.urls import url # noqa
from mistraldashboard.actions import views
urlpatterns = patterns(
'',
url(r'^$', views.IndexView.as_view(), name='index'),
)

View File

@ -0,0 +1,26 @@
# Copyright 2015 Huawei Technologies Co., Ltd.
#
# 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 horizon import tables
from mistraldashboard.actions.tables import ActionsTable
from mistraldashboard import api
class IndexView(tables.DataTableView):
table_class = ActionsTable
template_name = 'mistral/actions/index.html'
def get_data(self):
return api.action_list(self.request)

View File

@ -187,3 +187,10 @@ def workbook_update(request, workbook_definition):
"""
return mistralclient(request).workbooks.update(workbook_definition)
@handle_errors(_("Unable to retrieve actions."), [])
def action_list(request):
"""Returns all actions."""
return mistralclient(request).actions.list()

View File

@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
#
# Copyright 2014 - StackStorm, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
@ -24,7 +22,14 @@ from mistraldashboard.default.panel import Default
class MistralDashboard(horizon.Dashboard):
name = _("Mistral")
slug = "mistral"
panels = ('default', 'workbooks', 'workflows', 'executions', 'tasks',)
panels = (
'default',
'workbooks',
'workflows',
'executions',
'tasks',
'actions'
)
default_panel = 'default'
roles = ('admin',)