diff --git a/mistraldashboard/actions/__init__.py b/mistraldashboard/actions/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/mistraldashboard/actions/panel.py b/mistraldashboard/actions/panel.py new file mode 100644 index 0000000..5e42d1f --- /dev/null +++ b/mistraldashboard/actions/panel.py @@ -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) diff --git a/mistraldashboard/actions/tables.py b/mistraldashboard/actions/tables.py new file mode 100644 index 0000000..7af8a35 --- /dev/null +++ b/mistraldashboard/actions/tables.py @@ -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") diff --git a/mistraldashboard/actions/templates/actions/index.html b/mistraldashboard/actions/templates/actions/index.html new file mode 100644 index 0000000..185c37b --- /dev/null +++ b/mistraldashboard/actions/templates/actions/index.html @@ -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 %} diff --git a/mistraldashboard/actions/urls.py b/mistraldashboard/actions/urls.py new file mode 100644 index 0000000..6f1c43e --- /dev/null +++ b/mistraldashboard/actions/urls.py @@ -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'), +) diff --git a/mistraldashboard/actions/views.py b/mistraldashboard/actions/views.py new file mode 100644 index 0000000..8f702f4 --- /dev/null +++ b/mistraldashboard/actions/views.py @@ -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) diff --git a/mistraldashboard/api.py b/mistraldashboard/api.py index 51a6124..32320fa 100644 --- a/mistraldashboard/api.py +++ b/mistraldashboard/api.py @@ -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() diff --git a/mistraldashboard/dashboard.py b/mistraldashboard/dashboard.py index 19a1799..ffa66f3 100644 --- a/mistraldashboard/dashboard.py +++ b/mistraldashboard/dashboard.py @@ -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',)