diff options
author | Ladislav Smola <lsmola@redhat.com> | 2013-07-16 18:53:59 +0200 |
---|---|---|
committer | Tomas Sedovic <tomas@sedovic.cz> | 2013-08-01 16:18:57 +0200 |
commit | 0f006e27a5f3eaeed065839d4615328defbae0c4 (patch) | |
tree | ab2f5c39ee5d32d053d09e351294ff202f3ec8dd | |
parent | b8e3b6e8809f70ce711f3663c61072a01b79ff16 (diff) | |
download | tuskar-ui-0f006e27a5f3eaeed065839d4615328defbae0c4.tar.gz |
Resource class top right actions
- adding top right actions to resource class
- tests will be written as follow up patch
Change-Id: Iba3155c1f275ee9ee9416aba9baa46c69b69c28e
8 files changed, 169 insertions, 2 deletions
diff --git a/openstack_dashboard/api/tuskar.py b/openstack_dashboard/api/tuskar.py index c3281638..3d4d7370 100644 --- a/openstack_dashboard/api/tuskar.py +++ b/openstack_dashboard/api/tuskar.py @@ -448,6 +448,10 @@ class ResourceClass(StringIdAPIResourceWrapper): return resource_class + @property + def deletable(self): + return (len(self.list_racks) <= 0) + @classmethod def delete(cls, request, resource_class_id): tuskarclient(request).resource_classes.delete(resource_class_id) diff --git a/openstack_dashboard/dashboards/infrastructure/resource_management/resource_classes/forms.py b/openstack_dashboard/dashboards/infrastructure/resource_management/resource_classes/forms.py new file mode 100644 index 00000000..00dbda82 --- /dev/null +++ b/openstack_dashboard/dashboards/infrastructure/resource_management/resource_classes/forms.py @@ -0,0 +1,52 @@ +from django.core.urlresolvers import reverse +from django.utils.translation import ugettext_lazy as _ + +from horizon import exceptions +from horizon import forms +from horizon import messages + +from openstack_dashboard import api + +import logging + +LOG = logging.getLogger(__name__) + + +class DeleteForm(forms.SelfHandlingForm): + def __init__(self, request, *args, **kwargs): + super(DeleteForm, self).__init__(request, *args, **kwargs) + + resource_class = self.initial.get('resource_class', None) + self.command = DeleteCommand(request, resource_class) + + def handle(self, request, data): + try: + self.command.execute() + + messages.success(request, self.command.msg) + return True + except: + exceptions.handle(request, _("Unable to delete Resource Class.")) + + +# TODO this command will be reused in table, so code is not duplicated +class DeleteCommand(object): + def __init__(self, request, resource_class): + self.resource_class = resource_class + self.request = request + self.header = (_("Deleting resource class '%s.'") + % self.resource_class.name) + self.msg = "" + + def execute(self): + try: + api.tuskar.ResourceClass.delete(self.request, + self.resource_class.id) + self.msg = (_('Successfully deleted Class "%s".') + % self.resource_class.name) + except: + self.msg = _('Failed to delete Class %s') % self.resource_class.id + LOG.info(self.msg) + redirect = reverse( + "horizon:infrastructure:resource_management:index") + exceptions.handle(self.request, self.msg, redirect=redirect) diff --git a/openstack_dashboard/dashboards/infrastructure/resource_management/resource_classes/urls.py b/openstack_dashboard/dashboards/infrastructure/resource_management/resource_classes/urls.py index 8f4b4125..c4f48fcf 100644 --- a/openstack_dashboard/dashboards/infrastructure/resource_management/resource_classes/urls.py +++ b/openstack_dashboard/dashboards/infrastructure/resource_management/resource_classes/urls.py @@ -15,7 +15,7 @@ from django.conf.urls.defaults import patterns, url, include from .views import (CreateView, UpdateView, DetailView, UpdateRacksView, - UpdateFlavorsView) + UpdateFlavorsView, DetailUpdateView, DetailActionView) RESOURCE_CLASS = r'^(?P<resource_class_id>[^/]+)/%s$' VIEW_MOD = 'openstack_dashboard.dashboards.infrastructure.' \ @@ -27,6 +27,10 @@ urlpatterns = patterns( url(r'^(?P<resource_class_id>[^/]+)/$', DetailView.as_view(), name='detail'), url(RESOURCE_CLASS % 'update', UpdateView.as_view(), name='update'), + url(RESOURCE_CLASS % 'detail_action', DetailActionView.as_view(), + name='detail_action'), + url(RESOURCE_CLASS % 'detail_update', DetailUpdateView.as_view(), + name='detail_update'), url(RESOURCE_CLASS % 'update_racks', UpdateRacksView.as_view(), name='update_racks'), url(RESOURCE_CLASS % 'update_flavors', UpdateFlavorsView.as_view(), diff --git a/openstack_dashboard/dashboards/infrastructure/resource_management/resource_classes/views.py b/openstack_dashboard/dashboards/infrastructure/resource_management/resource_classes/views.py index 272057df..a8c9e89c 100644 --- a/openstack_dashboard/dashboards/infrastructure/resource_management/resource_classes/views.py +++ b/openstack_dashboard/dashboards/infrastructure/resource_management/resource_classes/views.py @@ -34,8 +34,10 @@ from horizon import workflows from openstack_dashboard import api +from .forms import DeleteForm from .workflows import (CreateResourceClass, UpdateResourceClass, - UpdateRacksWorkflow, UpdateFlavorsWorkflow) + UpdateRacksWorkflow, UpdateFlavorsWorkflow, + DetailUpdateWorkflow) from .tables import ResourceClassesTable from .tabs import ResourceClassDetailTabs @@ -79,6 +81,10 @@ class UpdateView(workflows.WorkflowView): 'service_type': resource_class.service_type} +class DetailUpdateView(UpdateView): + workflow_class = DetailUpdateWorkflow + + class UpdateRacksView(UpdateView): workflow_class = UpdateRacksWorkflow @@ -121,6 +127,46 @@ class DetailView(tabs.TabView): **kwargs) +class DetailActionView(forms.ModalFormView): + template_name = ('infrastructure/resource_management/' + 'resource_classes/action.html') + + def get_form(self, form_class): + """ + Returns an instance of the form to be used in this view. + """ + try: + action = self.request.GET.get('action') + if action == "delete": + form_class = DeleteForm + + return form_class(self.request, **self.get_form_kwargs()) + except: + exceptions.handle(self.request, _("Unable to build an Action.")) + + def get_success_url(self): + # FIXME this should be set on form level + return reverse("horizon:infrastructure:resource_management:index") + + def get_context_data(self, **kwargs): + context = super(DetailActionView, self).get_context_data(**kwargs) + context['resource_class_id'] = self.kwargs['resource_class_id'] + context['action'] = context['form'].initial.get('action', None) + context['header'] = context['form'].command.header + return context + + def get_initial(self): + try: + resource_class = api.tuskar.ResourceClass.get( + self.request, self.kwargs['resource_class_id']) + action = self.request.GET.get('action') + except: + exceptions.handle(self.request, + _("Unable to retrieve resource class data.")) + return {'resource_class': resource_class, + 'action': action} + + def rack_health(request, resource_class_id=None): # FIXME replace mock data random.seed() diff --git a/openstack_dashboard/dashboards/infrastructure/resource_management/resource_classes/workflows.py b/openstack_dashboard/dashboards/infrastructure/resource_management/resource_classes/workflows.py index 700d47bb..54b31c3f 100644 --- a/openstack_dashboard/dashboards/infrastructure/resource_management/resource_classes/workflows.py +++ b/openstack_dashboard/dashboards/infrastructure/resource_management/resource_classes/workflows.py @@ -293,6 +293,15 @@ class UpdateResourceClass(ResourceClassWorkflowMixin, workflows.Workflow): return True +class DetailUpdateWorkflow(UpdateResourceClass): + def get_index_url(self): + """This url is used both as success and failure url""" + url = "horizon:infrastructure:resource_management:resource_classes:"\ + "detail" + return "%s?tab=resource_class_details__overview" % ( + reverse(url, args=(self.context["resource_class_id"]))) + + class UpdateRacksWorkflow(UpdateResourceClass): def get_index_url(self): """This url is used both as success and failure url""" diff --git a/openstack_dashboard/dashboards/infrastructure/resource_management/templates/resource_management/resource_classes/_action.html b/openstack_dashboard/dashboards/infrastructure/resource_management/templates/resource_management/resource_classes/_action.html new file mode 100644 index 00000000..5f7108ea --- /dev/null +++ b/openstack_dashboard/dashboards/infrastructure/resource_management/templates/resource_management/resource_classes/_action.html @@ -0,0 +1,22 @@ +{% extends "horizon/common/_modal_form.html" %} +{% load i18n %} +{% load url from future %} +{% block form_id %}resource_class_action_form{% endblock %} +{% block form_action %} + {% url 'horizon:infrastructure:resource_management:resource_classes:detail_action' resource_class_id %}?action={{ action }} +{% endblock %} +{% block modal_id %}resource_class_action_modal{% endblock %} +{% block modal-header %}{{header}}{% endblock %} +{% block modal-body %} +<div> + {% trans "Are you sure?" %} + <fieldset> + {% include "horizon/common/_form_fields.html" %} + </fieldset> +</div> +{% endblock %} +{% block modal-footer %} + <input class="btn btn-primary" type="submit" value="{% trans "Yes" %}" /> + <a href="{% url 'horizon:infrastructure:resource_management:resource_classes:detail' resource_class_id %}" + class="btn secondary cancel close">{% trans "Cancel" %}</a> +{% endblock %} diff --git a/openstack_dashboard/dashboards/infrastructure/resource_management/templates/resource_management/resource_classes/action.html b/openstack_dashboard/dashboards/infrastructure/resource_management/templates/resource_management/resource_classes/action.html new file mode 100644 index 00000000..c2b03cf1 --- /dev/null +++ b/openstack_dashboard/dashboards/infrastructure/resource_management/templates/resource_management/resource_classes/action.html @@ -0,0 +1,9 @@ +{% extends 'infrastructure/base.html' %} +{% load i18n %} +{% block title %}{% trans "Resource Class Action Confirmation" %}{% endblock %} +{% block page_header %} + {% include "horizon/common/_page_header.html" with title=_("Resource Class Action") %} +{% endblock page_header %} +{% block infrastructure_main %} + {% include "infrastructure/resource_management/resource_classes/_edit_status.html" %} +{% endblock %} diff --git a/openstack_dashboard/dashboards/infrastructure/resource_management/templates/resource_management/resource_classes/detail.html b/openstack_dashboard/dashboards/infrastructure/resource_management/templates/resource_management/resource_classes/detail.html index 566929c4..ea39d5df 100644 --- a/openstack_dashboard/dashboards/infrastructure/resource_management/templates/resource_management/resource_classes/detail.html +++ b/openstack_dashboard/dashboards/infrastructure/resource_management/templates/resource_management/resource_classes/detail.html @@ -17,6 +17,27 @@ {% block name %}{{ resource_class.name }}{% endblock %} +{% block actions %} + <div class="btn-group"> + <a class="btn ajax-modal" + href="{% url 'horizon:infrastructure:resource_management:resource_classes:detail_update' resource_class.id %}"> + {% trans "Edit" %} + </a> + <a {% if resource_class.deletable %} + class="btn ajax-modal" + href="{% url 'horizon:infrastructure:resource_management:resource_classes:detail_action' resource_class.id %}?action=delete" + {% else %} + title="{% trans "Resource Class contains racks and can't be deleted." %}" + class="btn disabled" + href="#" + {% endif %} + > + {% trans "Delete" %} + </a> + </div> +{% endblock %} + + {% block overall_usage %} <table class="capacities overall_usage"> <tr> |