From 869baa4875a74cb815a7f15c9b5a58543ec41b1a Mon Sep 17 00:00:00 2001 From: Italo Lemos Date: Tue, 26 Mar 2024 16:15:51 -0300 Subject: [PATCH] Change Patches Tab to Releases Tab This is part of the changes required to implement USM in GUI (Horizon). In order to improve the user experience, some labels have been modified as part of the USM integration. Change-Id: If412e1954474a4350e1cbd6b73f6a8e82cfbf070 --- .../admin/software_management/tables.py | 199 ++++++++++++++++++ .../admin/software_management/tabs.py | 24 +-- .../{_patches.html => _releases.html} | 40 ++-- .../dc_admin/dc_software_management/tabs.py | 2 +- 4 files changed, 232 insertions(+), 33 deletions(-) rename starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/admin/software_management/templates/software_management/{_patches.html => _releases.html} (96%) diff --git a/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/admin/software_management/tables.py b/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/admin/software_management/tables.py index 65c45837..fff5469a 100644 --- a/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/admin/software_management/tables.py +++ b/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/admin/software_management/tables.py @@ -20,6 +20,205 @@ from starlingx_dashboard import api as stx_api LOG = logging.getLogger(__name__) +#Release + +class UploadRelease(tables.LinkAction): + name = "releaseupload" + verbose_name = _("Upload Releases") + url = "horizon:admin:software_management:patchupload" + classes = ("ajax-modal", "btn-create") + icon = "plus" + +class ApplyRelease(tables.BatchAction): + name = "apply" + + @staticmethod + def action_present(count): + return ungettext_lazy( + "Apply Release", + "Apply Releases", + count + ) + + @staticmethod + def action_past(count): + return ungettext_lazy( + "Applied Release", + "Applied Releases", + count + ) + + def allowed(self, request, release=None): + if release is None: + return True + return release.state == "available" + + def handle(self, table, request, obj_ids): + try: + result = stx_api.patch.patch_apply_req(request, obj_ids) + messages.success(request, result) + except Exception as ex: + messages.error(request, str(ex)) + + url = reverse(table.index_url) + return shortcuts.redirect(url) + + +class RemoveRelease(tables.BatchAction): + name = "remove" + classes = () + + @staticmethod + def action_present(count): + return ungettext_lazy( + "Remove Release", + "Remove Releases", + count + ) + + @staticmethod + def action_past(count): + return ungettext_lazy( + "Removed Release", + "Removed Releases", + count + ) + + def allowed(self, request, release=None): + if release is None: + return True + + if release.unremovable == "Y": + if "disabled" not in self.classes: + self.classes = [c for c in self.classes] + ["disabled"] + else: + self.classes = [c for c in self.classes if c != "disabled"] + + return release.state == "Applied" + + def handle(self, table, request, obj_ids): + try: + result = stx_api.patch.patch_remove_req(request, obj_ids) + messages.success(request, result) + except Exception as ex: + messages.error(request, str(ex)) + + url = reverse(table.index_url) + return shortcuts.redirect(url) + + +class DeleteRelease(tables.BatchAction): + name = "delete" + icon = 'trash' + action_type = 'danger' + + @staticmethod + def action_present(count): + return ungettext_lazy( + "Delete Release", + "Delete Releases", + count + ) + + @staticmethod + def action_past(count): + return ungettext_lazy( + "Deleted Release", + "Deleted Releases", + count + ) + + def allowed(self, request, release=None): + if release is None: + return True + return release.state == "available" + + def handle(self, table, request, obj_ids): + try: + result = stx_api.patch.patch_delete_req(request, obj_ids) + messages.success(request, result) + except Exception as ex: + messages.error(request, str(ex)) + + url = reverse(table.index_url) + return shortcuts.redirect(url) + +class UpdateReleaseRow(tables.Row): + ajax = True + + def get_data(self, request, release_id): + print('TESTE') + release = stx_api.usm.get_release(request, release_id) + return release + +class ReleaseFilterAction(tables.FilterAction): + def filter(self, table, patches, filter_string): + """Naive case-insensitive search.""" + q = filter_string.lower() + + def comp(patch): + if q in patch.patch_id.lower(): + return True + return False + + return list(filter(comp, patches)) + +class ReleasesTable(tables.DataTable): + index_url = 'horizon:admin:software_management:index' + RELEASE_STATE_CHOICES = ( + (None, True), + ("", True), + ("none", True), + ("available", True), + ("Deployed", True), + ("Partial-Remove", True), + ("Applied", True), + ("Committed", True) + ) + COMMITTED_STATE_CHOICES = ( + (None, True), + ("", True), + ("none", True), + ("Committed", True), + ("Not Committed", True), + ) + release_id = tables.Column('release_id', + link="horizon:admin:software_management:" + "patchdetail", + verbose_name=_('Release ID')) + reboot_required = tables.Column('reboot_required', + verbose_name=_('RR')) + sw_version = tables.Column('sw_version', + verbose_name=_('Version')) + state = tables.Column('state', + verbose_name=_('State'), + status=True, + status_choices=RELEASE_STATE_CHOICES, + classes=['text-capitalize']) + committed_state = tables.Column('committed_state', + verbose_name=_('Committed State'), + status=True, + status_choices=COMMITTED_STATE_CHOICES) + summary = tables.Column('summary', + verbose_name=_('Summary')) + + def get_object_id(self, obj): + return obj.release_id + + def get_object_display(self, obj): + return obj.release_id + + class Meta(object): + name = "releases" + multi_select = True + row_class = UpdateReleaseRow + status_columns = ['state'] + row_actions = (ApplyRelease, RemoveRelease, DeleteRelease) + table_actions = ( + ReleaseFilterAction, UploadRelease, ApplyRelease, RemoveRelease, + DeleteRelease) + verbose_name = _("Releases") + hidden_title = False class UploadPatch(tables.LinkAction): name = "patchupload" diff --git a/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/admin/software_management/tabs.py b/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/admin/software_management/tabs.py index 301234a8..88b3d320 100644 --- a/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/admin/software_management/tabs.py +++ b/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/admin/software_management/tabs.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2013-2018 Wind River Systems, Inc. +# Copyright (c) 2013-2024 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -18,14 +18,14 @@ from starlingx_dashboard.dashboards.admin.software_management import \ LOG = logging.getLogger(__name__) -class PatchesTab(tabs.TableTab): +class ReleasesTab(tabs.TableTab): table_classes = (toplevel_tables.PatchesTable,) - name = _("Patches") - slug = "patches" - template_name = ("admin/software_management/_patches.html") + name = _("Releases") + slug = "releases" + template_name = "admin/software_management/_releases.html" def get_context_data(self, request): - context = super(PatchesTab, self).get_context_data(request) + context = super(ReleasesTab, self).get_context_data(request) phosts = [] try: @@ -39,16 +39,16 @@ class PatchesTab(tabs.TableTab): return context - def get_patches_data(self): + def get_releases_data(self): request = self.request - patches = [] + releases = [] try: - patches = stx_api.patch.get_patches(request) + releases = stx_api.patch.get_patches(request) except Exception: exceptions.handle(self.request, - _('Unable to retrieve patch list.')) + _('Unable to retrieve release list.')) - return patches + return releases class PatchOrchestrationTab(tabs.TableTab): @@ -137,5 +137,5 @@ class UpgradeOrchestrationTab(tabs.TableTab): class SoftwareManagementTabs(tabs.TabGroup): slug = "software_management_tabs" - tabs = (PatchesTab, PatchOrchestrationTab, UpgradeOrchestrationTab) + tabs = (ReleasesTab, PatchOrchestrationTab, UpgradeOrchestrationTab) sticky = True diff --git a/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/admin/software_management/templates/software_management/_patches.html b/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/admin/software_management/templates/software_management/_releases.html similarity index 96% rename from starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/admin/software_management/templates/software_management/_patches.html rename to starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/admin/software_management/templates/software_management/_releases.html index 11fbb2bb..a76c23db 100644 --- a/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/admin/software_management/templates/software_management/_patches.html +++ b/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/admin/software_management/templates/software_management/_releases.html @@ -1,20 +1,20 @@ -{% load i18n sizeformat %} - -{% block main %} -
-
- - {% if patch_current %} - {% trans "System is Patch Current" %} - {% else %} - {% trans "System is Not Patch Current" %} - {% endif %} - -
- - {{ patches_table.render }} -
-{% endblock %} - - - +{% load i18n sizeformat %} + +{% block main %} +
+
+ + {% if patch_current %} + {% trans "System is Patch Current" %} + {% else %} + {% trans "System is Not Patch Current" %} + {% endif %} + +
+ + {{ patches_table.render }} +
+{% endblock %} + + + diff --git a/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/dc_admin/dc_software_management/tabs.py b/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/dc_admin/dc_software_management/tabs.py index 073402b1..d7932c71 100644 --- a/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/dc_admin/dc_software_management/tabs.py +++ b/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/dashboards/dc_admin/dc_software_management/tabs.py @@ -21,7 +21,7 @@ class PatchesTab(tabs.TableTab): table_classes = (tables.PatchesTable,) name = _("Patches") slug = "patches" - template_name = ("dc_admin/dc_software_management/_patches.html") + template_name = ("dc_admin/dc_software_management/_releases.html") preload = False def get_dc_patches_data(self):