diff --git a/cms/dynamic_content/blocks.py b/cms/dynamic_content/blocks.py index 23b945a21..e02c22e6b 100644 --- a/cms/dynamic_content/blocks.py +++ b/cms/dynamic_content/blocks.py @@ -13,6 +13,13 @@ MAXIMUM_ROWS_NUMBER_BLOCK_COUNT: int = 2 +class TrendNumberBlockType(blocks.StreamBlock): + trend_number = TrendNumberComponent(help_text=help_texts.TREND_BLOCK_FIELD) + + class Meta: + icon = "trend_down" + + class HeadlineNumberBlockTypes(blocks.StreamBlock): headline_number = HeadlineNumberComponent(help_text=help_texts.HEADLINE_BLOCK_FIELD) trend_number = TrendNumberComponent(help_text=help_texts.TREND_BLOCK_FIELD) diff --git a/cms/dynamic_content/cards.py b/cms/dynamic_content/cards.py index 4fff759b8..f62131a3c 100644 --- a/cms/dynamic_content/cards.py +++ b/cms/dynamic_content/cards.py @@ -2,8 +2,16 @@ from cms.common.models import AVAILABLE_RICH_TEXT_FEATURES from cms.dynamic_content import help_texts -from cms.dynamic_content.blocks import HeadlineNumberBlockTypes, MetricNumberBlock -from cms.dynamic_content.components import ChartComponent, HeadlineChartComponent +from cms.dynamic_content.blocks import ( + HeadlineNumberBlockTypes, + MetricNumberBlock, + TrendNumberBlockType, +) +from cms.dynamic_content.components import ( + ChartComponent, + HeadlineChartComponent, + SimplifiedChartComponent, +) from cms.metrics_interface.field_choices_callables import get_possible_axis_choices @@ -25,6 +33,12 @@ class Meta: MINIMUM_COLUMNS_CHART_COLUMNS_COUNT: int = 1 MAXIMUM_COLUMNS_CHART_COLUMNS_COUNT: int = 2 +MAXIMUM_TOPIC_TREND_CARD_CHARTS: int = 1 +MAXIMUM_TREND_NUMBER: int = 1 + +DEFAULT_SIMPLE_CHART_X_AXIS = "date" +DEFAULT_SIMPLE_CHART_Y_AXIS = "metric" + class HeadlineNumbersRowCard(blocks.StructBlock): columns = MetricNumberBlock( @@ -71,6 +85,47 @@ class Meta: icon = "chart_with_headline_and_trend_card" +class TropicTrendChartAndLink(blocks.StructBlock): + title = blocks.TextBlock(required=True, help_text=help_texts.TITLE_FIELD) + body = blocks.TextBlock(required=False, help_text=help_texts.OPTIONAL_BODY_FIELD) + tag_manager_event_id = blocks.CharBlock( + required=False, + help_text=help_texts.TAG_MANAGER_EVENT_ID_FIELD, + label="Tag manager event ID", + ) + topic_page = blocks.PageChooserBlock( + page_type="topic.TopicPage", + required=True, + help_text=help_texts.TOPIC_PAGE_FIELD, + ) + x_axis = blocks.ChoiceBlock( + required=True, + choices=get_possible_axis_choices, + help_text=help_texts.REQUIRED_CHART_X_AXIS, + default=DEFAULT_SIMPLE_CHART_X_AXIS, + ready_only=True, + ) + y_axis = blocks.ChoiceBlock( + required=True, + choices=get_possible_axis_choices, + help_text=help_texts.REQUIRED_CHART_Y_AXIS, + default=DEFAULT_SIMPLE_CHART_Y_AXIS, + ) + chart = SimplifiedChartComponent( + help_text=help_texts.CHART_BLOCK_FIELD, + required=True, + max_num=MAXIMUM_TOPIC_TREND_CARD_CHARTS, + ) + trend_number = TrendNumberBlockType( + required=True, + max_num=MAXIMUM_TREND_NUMBER, + help_text=help_texts.TREND_BLOCK_FIELD, + ) + + class Meta: + icon = "chart_with_headline_and_trend_card" + + class ChartCard(blocks.StructBlock): title = blocks.TextBlock(required=True, help_text=help_texts.TITLE_FIELD) body = blocks.TextBlock(required=False, help_text=help_texts.OPTIONAL_BODY_FIELD) @@ -111,6 +166,7 @@ class ChartRowBlockTypes(blocks.StreamBlock): chart_card = ChartCard() headline_chart_card = HeadlineChartCard() chart_with_headline_and_trend_card = ChartWithHeadlineAndTrendCard() + topic_trend_chart_and_link = TropicTrendChartAndLink() class ChartRowCard(blocks.StructBlock): diff --git a/cms/dynamic_content/components.py b/cms/dynamic_content/components.py index 02a7908fa..9ceb8da7d 100644 --- a/cms/dynamic_content/components.py +++ b/cms/dynamic_content/components.py @@ -21,6 +21,13 @@ class Meta: icon = "standalone_chart" +class SimplifiedChartComponent(blocks.StreamBlock): + plot = elements.SimplifiedChartPlotElement() + + class Meta: + icon = "standalone_chart" + + class HeadlineNumberComponent(elements.BaseMetricsElement): body = blocks.TextBlock(required=False, help_text=help_texts.OPTIONAL_BODY_FIELD) diff --git a/cms/dynamic_content/elements.py b/cms/dynamic_content/elements.py index 301657990..ed6bccdf1 100644 --- a/cms/dynamic_content/elements.py +++ b/cms/dynamic_content/elements.py @@ -23,6 +23,7 @@ DEFAULT_AGE = "all" DEFAULT_STRATUM = "default" DEFAULT_HEADLINE_CHART_TYPE = "bar" +DEFAULT_SIMPLIFIED_CHART_TYPE = "line_single_simplified" class BaseMetricsElement(blocks.StructBlock): @@ -142,3 +143,11 @@ class HeadlineChartPlotElement(BaseMetricsElement): class Meta: icon = "chart_plot" + + +class SimplifiedChartPlotElement(BaseMetricsElement): + metric = blocks.ChoiceBlock( + required=True, + choices=get_all_timeseries_metric_names, + help_text=help_texts.METRIC_FIELD, + ) diff --git a/cms/dynamic_content/help_texts.py b/cms/dynamic_content/help_texts.py index 5459e347a..5b960bfeb 100644 --- a/cms/dynamic_content/help_texts.py +++ b/cms/dynamic_content/help_texts.py @@ -27,6 +27,10 @@ for that plot. """ +TOPIC_PAGE_FIELD: str = """ +The related topic page you want to link to. +""" + HEADLINE_BLOCK_FIELD: str = """ This component will display a key headline number type metric. You can also optionally add a body of text to accompany that headline number. @@ -183,6 +187,10 @@ If nothing is provided, `metric value` will be used by default. """ +REQUIRED_CHART_Y_AXIS: str = """ +A required choice of what to display along the y-axis of the chart. +""" + USE_SMOOTH_LINES: str = """ If set to true, draws the plot as a spline line, resulting in smooth curves between data points. If set to false, draws the plot as a linear line,