From 7321b63630f1eaabd676219e2f8df5c881a71417 Mon Sep 17 00:00:00 2001 From: Carmelo Romeo Date: Tue, 11 Dec 2018 21:54:43 +0100 Subject: [PATCH] Restyled some menus and minor fixes. Change-Id: Idd6cb9c8af0cd525c262229241aa8af5981bbb5f --- iotronic_ui/iot/boards/forms.py | 55 -------------- iotronic_ui/iot/boards/tables.py | 25 ++---- iotronic_ui/iot/boards/urls.py | 18 ++--- iotronic_ui/iot/boards/views.py | 110 +++++++++------------------ iotronic_ui/iot/webservices/forms.py | 7 +- iotronic_ui/iot/webservices/views.py | 5 +- 6 files changed, 61 insertions(+), 159 deletions(-) diff --git a/iotronic_ui/iot/boards/forms.py b/iotronic_ui/iot/boards/forms.py index 6af8a9c..4e12756 100644 --- a/iotronic_ui/iot/boards/forms.py +++ b/iotronic_ui/iot/boards/forms.py @@ -217,7 +217,6 @@ class EnableServiceForm(forms.SelfHandlingForm): exceptions.handle(request, _(message_text)) -""" class DisableServiceForm(forms.SelfHandlingForm): uuid = forms.CharField(label=_("Board ID"), widget=forms.HiddenInput) @@ -259,7 +258,6 @@ class DisableServiceForm(forms.SelfHandlingForm): except Exception: message_text = "Unable to disable service." exceptions.handle(request, _(message_text)) -""" class AttachPortForm(forms.SelfHandlingForm): @@ -461,56 +459,3 @@ class RemovePluginsForm(forms.SelfHandlingForm): exceptions.handle(request, _(message_text)) break - - -class RemoveServicesForm(forms.SelfHandlingForm): - - uuid = forms.CharField(label=_("Board ID"), widget=forms.HiddenInput) - - name = forms.CharField( - label=_('Board Name'), - widget=forms.TextInput(attrs={'readonly': 'readonly'}) - ) - - service_list = forms.MultipleChoiceField( - label=_("Services List"), - widget=forms.SelectMultiple( - attrs={'class': 'switchable', - 'data-slug': 'slug-remove-services'}), - help_text=_("Select services in this pool") - ) - - def __init__(self, *args, **kwargs): - - super(RemoveServicesForm, self).__init__(*args, **kwargs) - # input=kwargs.get('initial',{}) - self.fields["service_list"].choices = kwargs["initial"]["service_list"] - - def handle(self, request, data): - - counter = 0 - - for service in data["service_list"]: - for key, value in self.fields["service_list"].choices: - if key == service: - - try: - disable = iotronic.service_action(request, - data["uuid"], - key, - "ServiceDisable") - - message_text = disable - messages.success(request, _(message_text)) - - if counter != len(data["service_list"]) - 1: - counter += 1 - else: - return True - - except Exception: - message_text = "Unable to disable service " \ - + str(value) + "." - exceptions.handle(request, _(message_text)) - - break diff --git a/iotronic_ui/iot/boards/tables.py b/iotronic_ui/iot/boards/tables.py index da022ca..654d7f2 100644 --- a/iotronic_ui/iot/boards/tables.py +++ b/iotronic_ui/iot/boards/tables.py @@ -51,11 +51,11 @@ class RestoreServices(tables.BatchAction): @staticmethod def action_present(count): - return u"Restore Services" + return u"Restore ALL Services" @staticmethod def action_past(count): - return u"Restore Services" + return u"Restored ALL Services" def allowed(self, request, board=None): return True @@ -73,7 +73,6 @@ class EnableServiceLink(tables.LinkAction): # policy_rules = (("iot", "iot:service_action"),) -""" class DisableServiceLink(tables.LinkAction): name = "disableservice" verbose_name = _("Disable Service(s)") @@ -81,7 +80,6 @@ class DisableServiceLink(tables.LinkAction): classes = ("ajax-modal",) # icon = "plus" # policy_rules = (("iot", "iot:service_action"),) -""" class RemovePluginsLink(tables.LinkAction): @@ -93,15 +91,6 @@ class RemovePluginsLink(tables.LinkAction): # policy_rules = (("iot", "iot:remove_plugins"),) -class RemoveServicesLink(tables.LinkAction): - name = "removeservices" - verbose_name = _("Remove Service(s)") - url = "horizon:iot:boards:removeservices" - classes = ("ajax-modal",) - icon = "plus" - # policy_rules = (("iot", "iot:remove_services"),) - - class AttachPortLink(tables.LinkAction): name = "attachport" verbose_name = _("Attach Port") @@ -120,7 +109,7 @@ class DetachPortLink(tables.LinkAction): class EnableWebServiceLink(tables.LinkAction): name = "enablewebservice" - verbose_name = _("Enable Web Services") + verbose_name = _("Enable Web Services Manager") url = "horizon:iot:boards:enablewebservice" classes = ("ajax-modal",) icon = "plus" @@ -128,7 +117,7 @@ class EnableWebServiceLink(tables.LinkAction): class DisableWebServiceLink(tables.LinkAction): name = "disablewebservice" - verbose_name = _("Disable Web Services") + verbose_name = _("Disable Web Services Manager") url = "horizon:iot:boards:disablewebservice" classes = ("ajax-modal",) icon = "plus" @@ -209,11 +198,9 @@ class BoardsTable(tables.DataTable): class Meta(object): name = "boards" verbose_name = _("boards") - # row_actions = (EditBoardLink, EnableServiceLink, DisableServiceLink, - row_actions = (EditBoardLink, EnableServiceLink, + row_actions = (EditBoardLink, EnableServiceLink, DisableServiceLink, RestoreServices, AttachPortLink, DetachPortLink, EnableWebServiceLink, DisableWebServiceLink, - RemovePluginsLink, RemoveServicesLink, - DeleteBoardsAction) + RemovePluginsLink, DeleteBoardsAction) table_actions = (BoardFilterAction, CreateBoardLink, DeleteBoardsAction) diff --git a/iotronic_ui/iot/boards/urls.py b/iotronic_ui/iot/boards/urls.py index 679a7b4..1758165 100644 --- a/iotronic_ui/iot/boards/urls.py +++ b/iotronic_ui/iot/boards/urls.py @@ -20,22 +20,20 @@ urlpatterns = [ url(r'^create/$', views.CreateView.as_view(), name='create'), url(r'^(?P[^/]+)/update/$', views.UpdateView.as_view(), name='update'), - url(r'^(?P[^/]+)/removeplugins/$', - views.RemovePluginsView.as_view(), name='removeplugins'), - url(r'^(?P[^/]+)/removeservices/$', - views.RemoveServicesView.as_view(), name='removeservices'), url(r'^(?P[^/]+)/enableservice/$', views.EnableServiceView.as_view(), name='enableservice'), - # url(r'^(?P[^/]+)/disableservice/$', - # views.DisableServiceView.as_view(), name='disableservice'), + url(r'^(?P[^/]+)/disableservice/$', + views.DisableServiceView.as_view(), name='disableservice'), url(r'^(?P[^/]+)/attachport/$', - views.EnableWebServiceView.as_view(), name='enablewebservice'), - url(r'^(?P[^/]+)/enablewebservice/$', - views.DisableWebServiceView.as_view(), name='disablewebservice'), - url(r'^(?P[^/]+)/disablewebservice/$', views.AttachPortView.as_view(), name='attachport'), url(r'^(?P[^/]+)/detachport/$', views.DetachPortView.as_view(), name='detachport'), + url(r'^(?P[^/]+)/enablewebservice/$', + views.EnableWebServiceView.as_view(), name='enablewebservice'), + url(r'^(?P[^/]+)/disablewebservice/$', + views.DisableWebServiceView.as_view(), name='disablewebservice'), + url(r'^(?P[^/]+)/removeplugins/$', + views.RemovePluginsView.as_view(), name='removeplugins'), url(r'^(?P[^/]+)/detail/$', views.BoardDetailView.as_view(), name='detail'), ] diff --git a/iotronic_ui/iot/boards/views.py b/iotronic_ui/iot/boards/views.py index 1b660c9..a48f4fc 100644 --- a/iotronic_ui/iot/boards/views.py +++ b/iotronic_ui/iot/boards/views.py @@ -99,6 +99,7 @@ class IndexView(tables.DataTableView): else: board.fleet_name = None + boards.sort(key=lambda b: b.name) return boards @@ -193,14 +194,26 @@ class EnableServiceView(forms.ModalFormView): board_services = api.iotronic.services_on_board(self.request, board.uuid, True) - + cloud_services.sort(key=lambda b: b.name) service_list = [] + # LOG.debug('CLOUD SERVICES: %s', cloud_services) for cloud_service in cloud_services: + uuid = cloud_service._info["uuid"] + name = cloud_service._info["name"] + if len(board_services) == 0: - service_list.append((cloud_service._info["uuid"], - _(cloud_service._info["name"]))) + + # BEFORE filtering necessity + # service_list.append((cloud_service._info["uuid"], + # _(cloud_service._info["name"]))) + + # AFTER filtering necessity + # We are filtering the services that starts with "webservice" + if ((name != "webservice") and (name != "webservice_ssl")): + service_list.append((uuid, _(name))) + else: counter = 0 for board_service in board_services: @@ -209,15 +222,22 @@ class EnableServiceView(forms.ModalFormView): elif counter != len(board_services) - 1: counter += 1 else: - service_list.append((cloud_service._info["uuid"], - _(cloud_service._info["name"]))) + # BEFORE filtering necessity + # service_list.append((uuid, _(name))) + # AFTER filtering necessity + # We are filtering the services that starts + # with "webservice" + if ((name != "webservice") and + ("name" != "webservice_ssl")): + service_list.append((uuid, _(name))) + + # LOG.debug('SERVICES: %s', service_list) return {'uuid': board.uuid, 'name': board.name, 'service_list': service_list} -""" class DisableServiceView(forms.ModalFormView): template_name = 'iot/boards/disableservice.html' modal_header = _("Disable Service(s)") @@ -256,21 +276,21 @@ class DisableServiceView(forms.ModalFormView): board_services = api.iotronic.services_on_board(self.request, board.uuid, True) - + cloud_services.sort(key=lambda b: b.name) service_list = [] - # BEFORE filtering necessity - # for cloud_service in cloud_services: - # for board_service in board_services: - # if board_service["uuid"] == cloud_service._info["uuid"]: - # service_list.append((cloud_service._info["uuid"], - # _(cloud_service._info["name"]))) + """ + for cloud_service in cloud_services: + for board_service in board_services: + if board_service["uuid"] == cloud_service._info["uuid"]: + service_list.append((cloud_service._info["uuid"], + _(cloud_service._info["name"]))) + """ # AFTER filtering necessity # We are filtering the services that starts with "webservice" # ------------------------------------------------------------ - for cloud_service in cloud_services: for board_service in board_services: if ((board_service["uuid"] == cloud_service._info["uuid"]) and @@ -283,7 +303,6 @@ class DisableServiceView(forms.ModalFormView): return {'uuid': board.uuid, 'name': board.name, 'service_list': service_list} -""" class AttachPortView(forms.ModalFormView): @@ -322,6 +341,7 @@ class AttachPortView(forms.ModalFormView): networks = api.neutron.network_list(self.request) net_choices = [] + networks.sort(key=lambda b: b.name) for net in networks: for subnet in net["subnets"]: net_choices.append((net["id"] + ':' + subnet["id"], @@ -371,6 +391,7 @@ class DetachPortView(forms.ModalFormView): # ################################################################ # LOG.debug("PORTS: %s", ports) + ports.sort(key=lambda b: b.name) filtered_ports = [] for port in ports: if port._info["board_uuid"] == board.uuid: @@ -388,7 +409,7 @@ class DetachPortView(forms.ModalFormView): class EnableWebServiceView(forms.ModalFormView): template_name = 'iot/boards/enablewebservice.html' - modal_header = _("Enable Web Service(s)") + modal_header = _("Enable Web Services Manager") form_id = "webservice_enable_form" form_class = project_forms.EnableWebServiceForm submit_label = _("Enable") @@ -425,7 +446,7 @@ class EnableWebServiceView(forms.ModalFormView): class DisableWebServiceView(forms.ModalFormView): template_name = 'iot/boards/disablewebservice.html' - modal_header = _("Disable Web Service(s)") + modal_header = _("Disable Web Services Manager") form_id = "webservice_disable_form" form_class = project_forms.DisableWebServiceForm submit_label = _("Disable") @@ -508,61 +529,6 @@ class RemovePluginsView(forms.ModalFormView): 'plugin_list': plugin_list} -class RemoveServicesView(forms.ModalFormView): - template_name = 'iot/boards/removeservices.html' - modal_header = _("Remove Services from board") - form_id = "remove_boardservices_form" - form_class = project_forms.RemoveServicesForm - submit_label = _("Remove") - # submit_url = reverse_lazy("horizon:iot:boards:removeservices") - submit_url = "horizon:iot:boards:removeservices" - success_url = reverse_lazy('horizon:iot:boards:index') - page_title = _("Remove Services from board") - - @memoized.memoized_method - def get_object(self): - try: - return api.iotronic.board_get(self.request, - self.kwargs['board_id'], - None) - except Exception: - redirect = reverse("horizon:iot:boards:index") - exceptions.handle(self.request, - _('Unable to get board information.'), - redirect=redirect) - - def get_context_data(self, **kwargs): - context = super(RemoveServicesView, self).get_context_data(**kwargs) - args = (self.get_object().uuid,) - context['submit_url'] = reverse(self.submit_url, args=args) - return context - - def get_initial(self): - board = self.get_object() - - # Populate services - services = api.iotronic.services_on_board(self.request, - board.uuid, - True) - services.sort(key=lambda b: b["name"]) - - service_list = [] - for service in services: - # service_list.append((service["uuid"], _(service["name"]))) - - # TO BE REMOVED - # ########################################################### - # We are filtering the services that starts with "webservice" - if ((service["name"] != "webservice") and - (service["name"] != "webservice_ssl")): - service_list.append((service["uuid"], _(service["name"]))) - # ########################################################### - - return {'uuid': board.uuid, - 'name': board.name, - 'service_list': service_list} - - class DetailView(tabs.TabView): tab_group_class = project_tabs.BoardDetailTabs template_name = 'horizon/common/_detail.html' diff --git a/iotronic_ui/iot/webservices/forms.py b/iotronic_ui/iot/webservices/forms.py index 8a18f01..b3d1c40 100644 --- a/iotronic_ui/iot/webservices/forms.py +++ b/iotronic_ui/iot/webservices/forms.py @@ -33,11 +33,15 @@ class ExposeWebserviceForm(forms.SelfHandlingForm): widget=forms.TextInput(attrs={'readonly': 'readonly'}) ) + zone = forms.CharField(label=_("Zone"), + widget=forms.TextInput(attrs={'readonly': + 'readonly'})) + ws_name = forms.CharField(label=_("Web Service Name")) port = forms.IntegerField( label=_("Port"), - help_text=_("The port used by the service") + help_text=_("The local port used by the service") ) secure = forms.BooleanField(label=_("Secure"), initial=True) @@ -98,6 +102,5 @@ class UnexposeWebserviceForm(forms.SelfHandlingForm): return True except Exception: - LOG.debug("HERE") message_text = "Unable to unexpose web service." exceptions.handle(request, _(message_text)) diff --git a/iotronic_ui/iot/webservices/views.py b/iotronic_ui/iot/webservices/views.py index 0b84bcc..32a59ad 100644 --- a/iotronic_ui/iot/webservices/views.py +++ b/iotronic_ui/iot/webservices/views.py @@ -129,8 +129,11 @@ class ExposeView(forms.ModalFormView): def get_initial(self): board = self.get_object() + board_exp_info = iotronic.webservice_get_enabled_info(self.request, + board.uuid) + zone = board_exp_info.dns + "." + board_exp_info.zone - return {'uuid': board.uuid, 'name': board.name} + return {'uuid': board.uuid, 'name': board.name, 'zone': zone} class UnexposeView(forms.ModalFormView):