From bb03d06ebe52395ff08ad4f4c1f30647ae01e430 Mon Sep 17 00:00:00 2001 From: Kirill Izotov Date: Fri, 12 Sep 2014 16:28:26 +0700 Subject: [PATCH] Modify to use API v2 Change-Id: Iacaab88d7ce8618aa7331e8cb7f23c69191e5f49 Implements: blueprint mistral-ui --- mistraldashboard/api.py | 2 +- mistraldashboard/dashboard.py | 9 +--- mistraldashboard/default/__init__.py | 0 mistraldashboard/default/panel.py | 26 ++++++++++ .../default/templates/default/_humantime.html | 2 + .../default/templates/default/_label.html | 1 + .../templates/default/_prettyprint.html | 9 ++++ .../default/templates/default/base.html | 10 ++++ mistraldashboard/default/utils.py | 48 +++++++++++++++++++ mistraldashboard/executions/tables.py | 43 ++++++++++------- .../templates/executions/_label.html | 1 - .../templates/executions/index.html | 2 +- mistraldashboard/executions/views.py | 4 +- mistraldashboard/tasks/__init__.py | 0 mistraldashboard/tasks/panel.py | 28 +++++++++++ mistraldashboard/tasks/tables.py | 47 ++++++++++++++++++ .../tasks/templates/tasks/index.html | 11 +++++ mistraldashboard/tasks/urls.py | 25 ++++++++++ mistraldashboard/tasks/views.py | 29 +++++++++++ mistraldashboard/workbooks/tables.py | 10 +--- .../templates/workbooks/execute.html | 11 ----- .../workbooks/templates/workbooks/index.html | 2 +- mistraldashboard/workbooks/urls.py | 2 - mistraldashboard/workbooks/views.py | 20 -------- mistraldashboard/workflows/__init__.py | 0 .../{workbooks => workflows}/forms.py | 33 ++++--------- mistraldashboard/workflows/panel.py | 29 +++++++++++ mistraldashboard/workflows/tables.py | 44 +++++++++++++++++ .../templates/workflows}/_execute.html | 6 +-- .../templates/workflows/execute.html | 11 +++++ .../workflows/templates/workflows/index.html | 11 +++++ mistraldashboard/workflows/urls.py | 29 +++++++++++ mistraldashboard/workflows/views.py | 48 +++++++++++++++++++ 33 files changed, 456 insertions(+), 97 deletions(-) create mode 100644 mistraldashboard/default/__init__.py create mode 100644 mistraldashboard/default/panel.py create mode 100644 mistraldashboard/default/templates/default/_humantime.html create mode 100644 mistraldashboard/default/templates/default/_label.html create mode 100644 mistraldashboard/default/templates/default/_prettyprint.html create mode 100644 mistraldashboard/default/templates/default/base.html create mode 100644 mistraldashboard/default/utils.py delete mode 100644 mistraldashboard/executions/templates/executions/_label.html create mode 100644 mistraldashboard/tasks/__init__.py create mode 100644 mistraldashboard/tasks/panel.py create mode 100644 mistraldashboard/tasks/tables.py create mode 100644 mistraldashboard/tasks/templates/tasks/index.html create mode 100644 mistraldashboard/tasks/urls.py create mode 100644 mistraldashboard/tasks/views.py delete mode 100644 mistraldashboard/workbooks/templates/workbooks/execute.html create mode 100644 mistraldashboard/workflows/__init__.py rename mistraldashboard/{workbooks => workflows}/forms.py (55%) create mode 100644 mistraldashboard/workflows/panel.py create mode 100644 mistraldashboard/workflows/tables.py rename mistraldashboard/{workbooks/templates/workbooks => workflows/templates/workflows}/_execute.html (72%) create mode 100644 mistraldashboard/workflows/templates/workflows/execute.html create mode 100644 mistraldashboard/workflows/templates/workflows/index.html create mode 100644 mistraldashboard/workflows/urls.py create mode 100644 mistraldashboard/workflows/views.py diff --git a/mistraldashboard/api.py b/mistraldashboard/api.py index 32b80ff..8d610db 100644 --- a/mistraldashboard/api.py +++ b/mistraldashboard/api.py @@ -22,7 +22,7 @@ SERVICE_TYPE = 'workflow' def mistralclient(request): - return mistral_client.Client( + return mistral_client.client( username=request.user.username, auth_token=request.user.token.id, project_id=request.user.tenant_id, diff --git a/mistraldashboard/dashboard.py b/mistraldashboard/dashboard.py index ea9f1e8..19a1799 100644 --- a/mistraldashboard/dashboard.py +++ b/mistraldashboard/dashboard.py @@ -18,18 +18,13 @@ from django.utils.translation import ugettext_lazy as _ import horizon - -class Default(horizon.Panel): - name = _("Default") - slug = 'default' - urls = 'mistraldashboard.workbooks.urls' - nav = False +from mistraldashboard.default.panel import Default class MistralDashboard(horizon.Dashboard): name = _("Mistral") slug = "mistral" - panels = ('default', 'workbooks', 'executions',) + panels = ('default', 'workbooks', 'workflows', 'executions', 'tasks',) default_panel = 'default' roles = ('admin',) diff --git a/mistraldashboard/default/__init__.py b/mistraldashboard/default/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/mistraldashboard/default/panel.py b/mistraldashboard/default/panel.py new file mode 100644 index 0000000..3278085 --- /dev/null +++ b/mistraldashboard/default/panel.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +# +# Copyright 2014 - StackStorm, Inc. +# +# 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 + + +class Default(horizon.Panel): + name = _("Default") + slug = 'default' + urls = 'mistraldashboard.workbooks.urls' + nav = False diff --git a/mistraldashboard/default/templates/default/_humantime.html b/mistraldashboard/default/templates/default/_humantime.html new file mode 100644 index 0000000..299f5b0 --- /dev/null +++ b/mistraldashboard/default/templates/default/_humantime.html @@ -0,0 +1,2 @@ +{% load humanize %} + diff --git a/mistraldashboard/default/templates/default/_label.html b/mistraldashboard/default/templates/default/_label.html new file mode 100644 index 0000000..f9e92aa --- /dev/null +++ b/mistraldashboard/default/templates/default/_label.html @@ -0,0 +1 @@ +{{ label }} diff --git a/mistraldashboard/default/templates/default/_prettyprint.html b/mistraldashboard/default/templates/default/_prettyprint.html new file mode 100644 index 0000000..2d3290d --- /dev/null +++ b/mistraldashboard/default/templates/default/_prettyprint.html @@ -0,0 +1,9 @@ +{% if short %} +
+
{{ short }}
+
{{ full }}
+{% else %} +
+
{{ full }}
+{% endif %} +
diff --git a/mistraldashboard/default/templates/default/base.html b/mistraldashboard/default/templates/default/base.html new file mode 100644 index 0000000..99f3f0c --- /dev/null +++ b/mistraldashboard/default/templates/default/base.html @@ -0,0 +1,10 @@ +{% extends 'base.html' %} + +{% block css %} + {% include "_stylesheets.html" %} + + {% load compress %} + {% compress css %} + + {% endcompress %} +{% endblock %} diff --git a/mistraldashboard/default/utils.py b/mistraldashboard/default/utils.py new file mode 100644 index 0000000..a98de0d --- /dev/null +++ b/mistraldashboard/default/utils.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# +# Copyright 2014 - StackStorm, Inc. +# +# 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.template.loader import render_to_string +import iso8601 +import json + +TYPES = { + 'SUCCESS': 'label-success', + 'ERROR': 'label-important' +} + + +def label(x): + return render_to_string("mistral/default/_label.html", + {"label": x, + "type": TYPES.get(x)}) + + +def humantime(x): + return render_to_string("mistral/default/_humantime.html", + {"datetime": iso8601.parse_date(x)}) + + +def prettyprint(x): + short = None + full = json.dumps(json.loads(x), indent=4, ensure_ascii=False) + + lines = full.split('\n') + + if (len(lines) > 5): + short = '\n'.join(lines[:5] + ['...']) + + return render_to_string("mistral/default/_prettyprint.html", + {"full": full, "short": short}) diff --git a/mistraldashboard/executions/tables.py b/mistraldashboard/executions/tables.py index dde97f1..9d24194 100644 --- a/mistraldashboard/executions/tables.py +++ b/mistraldashboard/executions/tables.py @@ -15,28 +15,34 @@ # limitations under the License. from django.utils.translation import ugettext_lazy as _ -from django.template.loader import render_to_string from horizon import tables - -TYPES = { - 'SUCCESS': 'label-success', - 'ERROR': 'label-important' -} - - -def label(x): - return render_to_string("mistral/executions/_label.html", - {"label": x, - "type": TYPES.get(x)}) +from mistraldashboard.default.utils import label +from mistraldashboard.default.utils import humantime +from mistraldashboard.default.utils import prettyprint class ExecutionsTable(tables.DataTable): - id = tables.Column("id", - verbose_name=_("ID"), - link=("horizon:mistral:executions:tasks")) - wb_name = tables.Column("workbook_name", verbose_name=_("Workbook")) + id = tables.Column("id", verbose_name=_("ID")) # , + # link=("horizon:mistral:executions:tasks")) + + workflow_name = tables.Column("workflow_name", verbose_name=_("Workflow")) + + input = tables.Column("input", + verbose_name=_("Input"), + filters=[prettyprint]) + output = tables.Column("output", + verbose_name=_("Output"), + filters=[prettyprint]) + + created_at = tables.Column("created_at", + verbose_name=_("Created at"), + filters=[humantime]) + updated_at = tables.Column("updated_at", + verbose_name=_("Updated at"), + filters=[humantime]) + state = tables.Column("state", verbose_name=_("State"), filters=[label]) class Meta: @@ -47,8 +53,13 @@ class ExecutionsTable(tables.DataTable): class TaskTable(tables.DataTable): id = tables.Column("id", verbose_name=_("ID")) name = tables.Column("name", verbose_name=_("Name")) + parameters = tables.Column("parameters", verbose_name=_("Parameters")) output = tables.Column("output", verbose_name=_("Output")) + + created_at = tables.Column("created_at", verbose_name=_("Created at")) + updated_at = tables.Column("updated_at", verbose_name=_("Updated at")) + state = tables.Column("state", verbose_name=_("State"), filters=[label]) class Meta: diff --git a/mistraldashboard/executions/templates/executions/_label.html b/mistraldashboard/executions/templates/executions/_label.html deleted file mode 100644 index 0719889..0000000 --- a/mistraldashboard/executions/templates/executions/_label.html +++ /dev/null @@ -1 +0,0 @@ -{{ label }} \ No newline at end of file diff --git a/mistraldashboard/executions/templates/executions/index.html b/mistraldashboard/executions/templates/executions/index.html index 864a4d4..2969a5c 100644 --- a/mistraldashboard/executions/templates/executions/index.html +++ b/mistraldashboard/executions/templates/executions/index.html @@ -1,4 +1,4 @@ -{% extends 'base.html' %} +{% extends 'mistral/default/base.html' %} {% load i18n %} {% block title %}{% trans "Executions" %}{% endblock %} diff --git a/mistraldashboard/executions/views.py b/mistraldashboard/executions/views.py index a4ef9ae..9f72119 100644 --- a/mistraldashboard/executions/views.py +++ b/mistraldashboard/executions/views.py @@ -27,7 +27,7 @@ class IndexView(tables.DataTableView): def get_data(self): client = api.mistralclient(self.request) - return client.executions.list(None) + return client.executions.list() class TaskView(tables.DataTableView): @@ -36,4 +36,4 @@ class TaskView(tables.DataTableView): def get_data(self): client = api.mistralclient(self.request) - return client.tasks.list(None, self.kwargs['execution_id']) + return client.tasks.list() diff --git a/mistraldashboard/tasks/__init__.py b/mistraldashboard/tasks/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/mistraldashboard/tasks/panel.py b/mistraldashboard/tasks/panel.py new file mode 100644 index 0000000..3ce69ef --- /dev/null +++ b/mistraldashboard/tasks/panel.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +# +# Copyright 2014 - StackStorm, Inc. +# +# 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 Tasks(horizon.Panel): + name = _("Tasks") + slug = 'tasks' + + +dashboard.MistralDashboard.register(Tasks) diff --git a/mistraldashboard/tasks/tables.py b/mistraldashboard/tasks/tables.py new file mode 100644 index 0000000..76233c7 --- /dev/null +++ b/mistraldashboard/tasks/tables.py @@ -0,0 +1,47 @@ +# -*- coding: utf-8 -*- +# +# Copyright 2014 - StackStorm, Inc. +# +# 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 mistraldashboard.default.utils import label +from mistraldashboard.default.utils import humantime +from mistraldashboard.default.utils import prettyprint + + +class TaskTable(tables.DataTable): + id = tables.Column("id", verbose_name=_("ID")) + name = tables.Column("name", verbose_name=_("Name")) + + parameters = tables.Column("parameters", + verbose_name=_("Parameters"), + filters=[prettyprint]) + output = tables.Column("output", + verbose_name=_("Output"), + filters=[prettyprint]) + created_at = tables.Column("created_at", + verbose_name=_("Created at"), + filters=[humantime]) + updated_at = tables.Column("updated_at", + verbose_name=_("Updated at"), + filters=[humantime]) + + state = tables.Column("state", verbose_name=_("State"), filters=[label]) + + class Meta: + name = "tasks" + verbose_name = _("Tasks") diff --git a/mistraldashboard/tasks/templates/tasks/index.html b/mistraldashboard/tasks/templates/tasks/index.html new file mode 100644 index 0000000..89fd158 --- /dev/null +++ b/mistraldashboard/tasks/templates/tasks/index.html @@ -0,0 +1,11 @@ +{% extends 'mistral/default/base.html' %} +{% load i18n %} +{% block title %}{% trans "Tasks" %}{% endblock %} + +{% block page_header %} + {% include "horizon/common/_page_header.html" with title=_("Tasks") %} +{% endblock page_header %} + +{% block main %} + {{ table.render }} +{% endblock %} diff --git a/mistraldashboard/tasks/urls.py b/mistraldashboard/tasks/urls.py new file mode 100644 index 0000000..04cd970 --- /dev/null +++ b/mistraldashboard/tasks/urls.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# +# Copyright 2014 - StackStorm, Inc. +# +# 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.tasks.views import IndexView + +urlpatterns = patterns( + '', + url(r'^$', IndexView.as_view(), name='index'), +) diff --git a/mistraldashboard/tasks/views.py b/mistraldashboard/tasks/views.py new file mode 100644 index 0000000..9e67969 --- /dev/null +++ b/mistraldashboard/tasks/views.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +# +# Copyright 2014 - StackStorm, Inc. +# +# 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 import api +from mistraldashboard.tasks.tables import TaskTable + + +class IndexView(tables.DataTableView): + table_class = TaskTable + template_name = 'mistral/tasks/index.html' + + def get_data(self): + client = api.mistralclient(self.request) + return client.tasks.list() diff --git a/mistraldashboard/workbooks/tables.py b/mistraldashboard/workbooks/tables.py index 25b3319..4111e26 100644 --- a/mistraldashboard/workbooks/tables.py +++ b/mistraldashboard/workbooks/tables.py @@ -19,15 +19,8 @@ from django.utils.translation import ugettext_lazy as _ from horizon import tables -class ExecuteWorkflow(tables.LinkAction): - name = "execute" - verbose_name = _("Execute") - url = "horizon:mistral:workbooks:execute" - classes = ("ajax-modal", "btn-edit") - - def tags_to_string(workbook): - return ', '.join(workbook.tags) + return ', '.join(workbook.tags) if workbook.tags else None class WorkbooksTable(tables.DataTable): @@ -41,4 +34,3 @@ class WorkbooksTable(tables.DataTable): class Meta: name = "workbooks" verbose_name = _("Workbooks") - row_actions = (ExecuteWorkflow,) diff --git a/mistraldashboard/workbooks/templates/workbooks/execute.html b/mistraldashboard/workbooks/templates/workbooks/execute.html deleted file mode 100644 index 848d6c9..0000000 --- a/mistraldashboard/workbooks/templates/workbooks/execute.html +++ /dev/null @@ -1,11 +0,0 @@ -{% extends 'base.html' %} -{% load i18n %} -{% block title %}{% trans "Execute workbook" %}{% endblock %} - -{% block page_header %} - {% include "horizon/common/_page_header.html" with title=_("Execute workbook") %} -{% endblock page_header %} - -{% block main %} - {% include 'mistral/workbooks/_execute.html' %} -{% endblock %} diff --git a/mistraldashboard/workbooks/templates/workbooks/index.html b/mistraldashboard/workbooks/templates/workbooks/index.html index a7094d5..001447e 100644 --- a/mistraldashboard/workbooks/templates/workbooks/index.html +++ b/mistraldashboard/workbooks/templates/workbooks/index.html @@ -1,4 +1,4 @@ -{% extends 'base.html' %} +{% extends 'mistral/default/base.html' %} {% load i18n %} {% block title %}{% trans "Workbooks" %}{% endblock %} diff --git a/mistraldashboard/workbooks/urls.py b/mistraldashboard/workbooks/urls.py index d26a62c..eef3ca4 100644 --- a/mistraldashboard/workbooks/urls.py +++ b/mistraldashboard/workbooks/urls.py @@ -18,12 +18,10 @@ from django.conf.urls import patterns # noqa from django.conf.urls import url # noqa from mistraldashboard.workbooks.views import IndexView -from mistraldashboard.workbooks.views import ExecuteView WORKBOOKS = r'^(?P[^/]+)/%s$' urlpatterns = patterns( '', url(r'^$', IndexView.as_view(), name='index'), - url(WORKBOOKS % 'execute', ExecuteView.as_view(), name='execute'), ) diff --git a/mistraldashboard/workbooks/views.py b/mistraldashboard/workbooks/views.py index f6bfdba..e1804e5 100644 --- a/mistraldashboard/workbooks/views.py +++ b/mistraldashboard/workbooks/views.py @@ -14,14 +14,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -from django.core.urlresolvers import reverse_lazy - from horizon import tables -from horizon import forms from mistraldashboard import api from mistraldashboard.workbooks.tables import WorkbooksTable -from mistraldashboard.workbooks.forms import ExecuteForm class IndexView(tables.DataTableView): @@ -30,19 +26,3 @@ class IndexView(tables.DataTableView): def get_data(self): return api.mistralclient(self.request).workbooks.list() - - -class ExecuteView(forms.ModalFormView): - form_class = ExecuteForm - template_name = 'mistral/workbooks/execute.html' - success_url = reverse_lazy("horizon:mistral:executions:index") - - def get_context_data(self, **kwargs): - context = super(ExecuteView, self).get_context_data(**kwargs) - context["workbook_name"] = self.kwargs['workbook_name'] - return context - - def get_initial(self, **kwargs): - return { - 'workbook_name': self.kwargs['workbook_name'] - } diff --git a/mistraldashboard/workflows/__init__.py b/mistraldashboard/workflows/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/mistraldashboard/workbooks/forms.py b/mistraldashboard/workflows/forms.py similarity index 55% rename from mistraldashboard/workbooks/forms.py rename to mistraldashboard/workflows/forms.py index a65c3a9..fe45fc3 100644 --- a/mistraldashboard/workbooks/forms.py +++ b/mistraldashboard/workflows/forms.py @@ -16,7 +16,6 @@ from django.utils.translation import ugettext_lazy as _ from django.core.urlresolvers import reverse -import yaml from horizon import exceptions from horizon import forms @@ -26,29 +25,17 @@ from mistraldashboard import api class ExecuteForm(forms.SelfHandlingForm): - workbook_name = forms.CharField(label=_("Workbook"), + workflow_name = forms.CharField(label=_("Workflow"), required=True, widget=forms.TextInput( attrs={'readonly': 'readonly'})) - task = forms.ChoiceField(label=_("Task"), - required=True, - help_text=_("Task to start the execution")) - context = forms.CharField(label=_("Context"), - required=False, - initial="{}", - widget=forms.widgets.Textarea()) - - def __init__(self, request, *args, **kwargs): - super(ExecuteForm, self).__init__(request, *args, **kwargs) - client = api.mistralclient(request) - workbook_definition = client.workbooks.get_definition( - kwargs['initial']['workbook_name']) - workbook = yaml.safe_load(workbook_definition) - - task_choices = [('', _("Select a task"))] - for task in workbook['Workflow']['tasks']: - task_choices.append((task, task)) - self.fields['task'].choices = task_choices + workflow_input = forms.CharField(label=_("Input"), + required=False, + initial="{}", + widget=forms.widgets.Textarea()) + task_name = forms.CharField(label=_("Task name"), + required=False, + widget=forms.TextInput()) def handle(self, request, data): try: @@ -58,6 +45,6 @@ class ExecuteForm(forms.SelfHandlingForm): messages.success(request, msg) return True except Exception: - msg = _('Failed to execute workbook "%s".') % data['workbook_name'] - redirect = reverse('horizon:mistral:workbooks:index') + msg = _('Failed to execute workflow "%s".') % data['workflow_name'] + redirect = reverse('horizon:mistral:workflows:index') exceptions.handle(request, msg, redirect=redirect) diff --git a/mistraldashboard/workflows/panel.py b/mistraldashboard/workflows/panel.py new file mode 100644 index 0000000..faec2ee --- /dev/null +++ b/mistraldashboard/workflows/panel.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +# +# Copyright 2014 - StackStorm, Inc. +# +# 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 Workflows(horizon.Panel): + name = _("Workflows") + slug = 'workflows' + + +dashboard.MistralDashboard.register(Workflows) diff --git a/mistraldashboard/workflows/tables.py b/mistraldashboard/workflows/tables.py new file mode 100644 index 0000000..5c600b9 --- /dev/null +++ b/mistraldashboard/workflows/tables.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# +# Copyright 2014 - StackStorm, Inc. +# +# 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 + + +class ExecuteWorkflow(tables.LinkAction): + name = "execute" + verbose_name = _("Execute") + url = "horizon:mistral:workflows:execute" + classes = ("ajax-modal", "btn-edit") + + +def tags_to_string(workflow): + return ', '.join(workflow.tags) if workflow.tags else None + + +class WorkbooksTable(tables.DataTable): + name = tables.Column("name", verbose_name=_("Name")) + description = tables.Column("description", verbose_name=_("Description")) + tags = tables.Column(tags_to_string, verbose_name=_("Tags")) + + def get_object_id(self, datum): + return datum.name + + class Meta: + name = "workflows" + verbose_name = _("Workflows") + row_actions = (ExecuteWorkflow,) diff --git a/mistraldashboard/workbooks/templates/workbooks/_execute.html b/mistraldashboard/workflows/templates/workflows/_execute.html similarity index 72% rename from mistraldashboard/workbooks/templates/workbooks/_execute.html rename to mistraldashboard/workflows/templates/workflows/_execute.html index 94d3267..16c5d9f 100644 --- a/mistraldashboard/workbooks/templates/workbooks/_execute.html +++ b/mistraldashboard/workflows/templates/workflows/_execute.html @@ -3,7 +3,7 @@ {% load url from future %} {% block form_id %}execute_form{% endblock %} -{% block form_action %}{% url 'horizon:mistral:workbooks:execute' workbook_name %}{% endblock %} +{% block form_action %}{% url 'horizon:mistral:workflows:execute' workflow_name %}{% endblock %} {% block modal-header %}{% trans "Execute" %}{% endblock %} @@ -15,11 +15,11 @@

{% trans "Description:" %}

-

{% trans "From here you can execute a workbook." %}

+

{% trans "From here you can execute a workflow." %}

{% endblock %} {% block modal-footer %} - {% trans "Cancel" %} + {% trans "Cancel" %} {% endblock %} diff --git a/mistraldashboard/workflows/templates/workflows/execute.html b/mistraldashboard/workflows/templates/workflows/execute.html new file mode 100644 index 0000000..03d36e5 --- /dev/null +++ b/mistraldashboard/workflows/templates/workflows/execute.html @@ -0,0 +1,11 @@ +{% extends 'mistral/default/base.html' %} +{% load i18n %} +{% block title %}{% trans "Execute workflow" %}{% endblock %} + +{% block page_header %} + {% include "horizon/common/_page_header.html" with title=_("Execute workflow") %} +{% endblock page_header %} + +{% block main %} + {% include 'mistral/workflows/_execute.html' %} +{% endblock %} diff --git a/mistraldashboard/workflows/templates/workflows/index.html b/mistraldashboard/workflows/templates/workflows/index.html new file mode 100644 index 0000000..b689744 --- /dev/null +++ b/mistraldashboard/workflows/templates/workflows/index.html @@ -0,0 +1,11 @@ +{% extends 'mistral/default/base.html' %} +{% load i18n %} +{% block title %}{% trans "Workflows" %}{% endblock %} + +{% block page_header %} + {% include "horizon/common/_page_header.html" with title=_("Workflows") %} +{% endblock page_header %} + +{% block main %} + {{ table.render }} +{% endblock %} diff --git a/mistraldashboard/workflows/urls.py b/mistraldashboard/workflows/urls.py new file mode 100644 index 0000000..b416d43 --- /dev/null +++ b/mistraldashboard/workflows/urls.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +# +# Copyright 2014 - StackStorm, Inc. +# +# 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.workflows.views import IndexView +from mistraldashboard.workflows.views import ExecuteView + +WORKFLOWS = r'^(?P[^/]+)/%s$' + +urlpatterns = patterns( + '', + url(r'^$', IndexView.as_view(), name='index'), + url(WORKFLOWS % 'execute', ExecuteView.as_view(), name='execute'), +) diff --git a/mistraldashboard/workflows/views.py b/mistraldashboard/workflows/views.py new file mode 100644 index 0000000..0b1ce75 --- /dev/null +++ b/mistraldashboard/workflows/views.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# +# Copyright 2014 - StackStorm, Inc. +# +# 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_lazy + +from horizon import tables +from horizon import forms + +from mistraldashboard import api +from mistraldashboard.workflows.tables import WorkbooksTable +from mistraldashboard.workflows.forms import ExecuteForm + + +class IndexView(tables.DataTableView): + table_class = WorkbooksTable + template_name = 'mistral/workflows/index.html' + + def get_data(self): + return api.mistralclient(self.request).workflows.list() + + +class ExecuteView(forms.ModalFormView): + form_class = ExecuteForm + template_name = 'mistral/workflows/execute.html' + success_url = reverse_lazy("horizon:mistral:executions:index") + + def get_context_data(self, **kwargs): + context = super(ExecuteView, self).get_context_data(**kwargs) + context["workflow_name"] = self.kwargs['workflow_name'] + return context + + def get_initial(self, **kwargs): + return { + 'workflow_name': self.kwargs['workflow_name'] + }