diff --git a/rocky/assets/css/components/system-tag.scss b/rocky/assets/css/components/system-tag.scss new file mode 100644 index 00000000000..3f7caab05eb --- /dev/null +++ b/rocky/assets/css/components/system-tag.scss @@ -0,0 +1,43 @@ +.system-tag, +span.system-tag { + background-color: var(--colors-white); + border: 2px solid; + border-radius: var(--border-radius-xl); + padding: var(--spacing-grid-025) var(--spacing-grid-100); + box-sizing: border-box; + width: auto; + + &::before { + content: none; + } + + &.color-1 { + color: var(--colors-blue-600); + border-color: var(--colors-blue-600); + } + + &.color-2 { + color: var(--colors-green-600); + border-color: var(--colors-green-600); + } + + &.color-3 { + color: var(--colors-ochre-500); + border-color: var(--colors-ochre-500); + } + + &.color-4 { + color: var(--colors-orange-600); + border-color: var(--colors-orange-600); + } + + &.color-5 { + color: var(--colors-red-600); + border-color: var(--colors-red-600); + } + + &.color-6 { + color: var(--colors-purrple-600); + border-color: var(--colors-purrple-600); + } +} diff --git a/rocky/assets/css/main.scss b/rocky/assets/css/main.scss index 4fb860423c0..1dd5615f43f 100644 --- a/rocky/assets/css/main.scss +++ b/rocky/assets/css/main.scss @@ -67,6 +67,7 @@ @import "components/sticky"; @import "components/sticky-column"; @import "components/state-tags"; +@import "components/system-tag"; @import "components/table"; @import "components/toggle"; @import "components/toolbar"; diff --git a/rocky/assets/css/themes/soft/fundamentals/border-radii.scss b/rocky/assets/css/themes/soft/fundamentals/border-radii.scss index 0ac5c9d7060..547a6f6d8bb 100644 --- a/rocky/assets/css/themes/soft/fundamentals/border-radii.scss +++ b/rocky/assets/css/themes/soft/fundamentals/border-radii.scss @@ -20,6 +20,10 @@ border-radius: var(--border-radius-l); } +.border-radius-xl { + border-radius: var(--border-radius-xl); +} + .border-radius-round { border-radius: var(--border-radius-round); } diff --git a/rocky/components/modal/README.md b/rocky/components/modal/README.md index b6f996e6dc4..ec49e5030a8 100644 --- a/rocky/components/modal/README.md +++ b/rocky/components/modal/README.md @@ -10,7 +10,7 @@ This outlines the basic usages and provides a code block example below, of how t ### Instantiate -First you need to add `{% load component_tags %}` at the top of your template. Next you need to add the following code block at the bottom, to include the corresponding JS (if you haven't already you also need to add `{% load compress %}`). +First you need to add `{% load component_tags %}` at the top of your template. Next you need to add the following code block at the bottom, to include the corresponding JS (if you haven't already you also need to add `{% load compress %}` and `{% load static %}`). ``` {% block html_at_end_body %} @@ -58,7 +58,7 @@ Including `{% component_css_dependencies %}` is needed to inject the reference t {% fill "content" %}
diff --git a/rocky/reports/templates/report_overview/modal_partials/enable_disable_schedule_modal.html b/rocky/reports/templates/report_overview/modal_partials/enable_disable_schedule_modal.html new file mode 100644 index 00000000000..6351601a78a --- /dev/null +++ b/rocky/reports/templates/report_overview/modal_partials/enable_disable_schedule_modal.html @@ -0,0 +1,24 @@ +{% load i18n %} + +{% component "modal" size="dialog-small" modal_id=modal_id %} +{% fill "header" %} +{% translate "Disable schedule" %} +{% endfill %} +{% fill "content" %} + +{% endfill %} +{% fill "footer_buttons" %} +{% translate "Disable schedule" %} + +{% endfill %} +{% endcomponent %} +{% component_css_dependencies %} diff --git a/rocky/reports/templates/report_overview/scheduled_reports_table.html b/rocky/reports/templates/report_overview/scheduled_reports_table.html index 41ed31ae923..7a824d2c39d 100644 --- a/rocky/reports/templates/report_overview/scheduled_reports_table.html +++ b/rocky/reports/templates/report_overview/scheduled_reports_table.html @@ -1,6 +1,9 @@ {% load i18n %} +{% load static %} {% load ooi_extra %} {% load report_extra %} +{% load compress %} +{% load component_tags %} {% if scheduled_reports %}@@ -11,10 +14,11 @@
{% translate "No scheduled reports have been generated yet." %}
{% endif %} +{% block html_at_end_body %} + {% compress js %} + + {% endcompress %} +{% endblock html_at_end_body %} diff --git a/rocky/reports/urls.py b/rocky/reports/urls.py index dcee21ad3d0..d7c809a31a9 100644 --- a/rocky/reports/urls.py +++ b/rocky/reports/urls.py @@ -25,12 +25,22 @@ ReportTypesSelectionMultiReportView, SetupScanMultiReportView, ) -from reports.views.report_overview import ReportHistoryView, ScheduledReportsView, SubreportView +from reports.views.report_overview import ( + ReportHistoryView, + ScheduledReportsEnableDisableView, + ScheduledReportsView, + SubreportView, +) # Report overview urls urlpatterns = [ path("", ReportsLandingView.as_view(), name="reports"), path("scheduled-reports/", ScheduledReportsView.as_view(), name="scheduled_reports"), + path( + "scheduled-reports/enable-disable", + ScheduledReportsEnableDisableView.as_view(), + name="enable_disable_scheduled_reports", + ), path("report-history/", ReportHistoryView.as_view(), name="report_history"), path("report-history/subreports", SubreportView.as_view(), name="subreports"), ] diff --git a/rocky/reports/views/report_overview.py b/rocky/reports/views/report_overview.py index e6ff232ed2c..269ac7dd036 100644 --- a/rocky/reports/views/report_overview.py +++ b/rocky/reports/views/report_overview.py @@ -4,6 +4,8 @@ import structlog from django.contrib import messages +from django.http import HttpResponse +from django.shortcuts import redirect from django.urls import reverse from django.utils.translation import gettext_lazy as _ from django.views.generic import ListView @@ -70,9 +72,11 @@ def get_queryset(self) -> list[dict[str, Any]]: recipe_tree = recipe_ooi_tree.store.values() recipe_ooi = next(ooi for ooi in recipe_tree if isinstance(ooi, ReportRecipe)) report_oois = [ooi for ooi in recipe_tree if isinstance(ooi, Report)] + report_oois.sort(key=lambda ooi: ooi.date_generated, reverse=True) recipes.append( { "schedule_id": schedule["id"], + "enabled": schedule["enabled"], "recipe": recipe_ooi, "cron": schedule["schedule"], "deadline_at": datetime.fromisoformat(schedule["deadline_at"]), @@ -88,6 +92,54 @@ def get_context_data(self, **kwargs): return context +class ScheduledReportsEnableDisableView(BreadcrumbsReportOverviewView, SchedulerView, ListView): + """ + Cancel the selected report(s) + """ + + task_type = "report" + template_name = "report_overview/scheduled_reports.html" + + def get_queryset(self) -> ReportList: + return ReportList(self.octopoes_api_connector, valid_time=self.observed_at) + + def get(self, request, *args, **kwargs) -> HttpResponse: + schedule_id = request.GET.get("schedule_id") + schedule = self.get_schedule_details(schedule_id) + is_schedule_enabled = schedule.enabled + + self.edit_report_schedule(schedule_id, {"enabled": not is_schedule_enabled}) + + logger.info( + _("Schedule {}").format("disabled" if is_schedule_enabled else "enabled"), + event_code="0800081" if is_schedule_enabled else "0800082", + schedule_id=schedule_id, + ) + + report_recipe_id = schedule.data["report_recipe_id"] + report_recipe = self.octopoes_api_connector.get( + Reference.from_str(f"ReportRecipe|{report_recipe_id}"), valid_time=datetime.now(timezone.utc) + ) + + if is_schedule_enabled: + messages.success( + self.request, + _( + "Schedule disabled successfully. '{}' will not be generated " + "automatically until the schedule is enabled again." + ).format(report_recipe.report_name_format), + ) + else: + messages.success( + self.request, + _("Schedule enabled successfully. '{}' will be generated according to schedule.").format( + report_recipe.report_name_format + ), + ) + + return redirect(reverse("scheduled_reports", kwargs={"organization_code": self.organization.code})) + + class ReportHistoryView(BreadcrumbsReportOverviewView, OctopoesView, ListView): """ Shows all the reports that have ever been generated for the organization. diff --git a/rocky/rocky/locale/django.pot b/rocky/rocky/locale/django.pot index 331596e4fe3..c896645a930 100644 --- a/rocky/rocky/locale/django.pot +++ b/rocky/rocky/locale/django.pot @@ -9,7 +9,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-11-18 15:24+0000\n" +"POT-Creation-Date: 2024-11-25 09:27+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME