From f79130519f8883d91db07d125122363f86baa4fc Mon Sep 17 00:00:00 2001 From: bencroker Date: Thu, 12 Sep 2024 21:49:02 +0200 Subject: [PATCH] Add and improve status colours --- CHANGELOG.md | 8 +++- composer.json | 2 +- src/controllers/CampaignsController.php | 2 +- src/controllers/MailingListsController.php | 2 +- src/controllers/SendoutsController.php | 4 +- src/controllers/TrackerController.php | 2 +- src/elements/CampaignElement.php | 22 ++++++++--- src/elements/ContactElement.php | 21 ++++++++-- src/elements/MailingListElement.php | 2 +- src/elements/SegmentElement.php | 10 ++++- src/elements/SendoutElement.php | 46 +++++++++++++++++----- src/resources/css/campaign.css | 40 ------------------- 12 files changed, 94 insertions(+), 67 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b4457e34..de4d1180 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,15 @@ # Release Notes for Campaign -## 3.4.4 - Unreleased +## 3.5.0 - Unreleased + +### Added + +- Added status colours to the “Status” column in element index pages. ### Changed +- Campaign now requires Craft CMS 5.2.0 or later. +- Improved the status colours of element types. - Improved the French translation ([#484](https://github.com/putyourlightson/craft-campaign/issues/484)). - Improved the German translation. diff --git a/composer.json b/composer.json index 07faca60..7282972d 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ "php": "^8.2", "ext-dom": "*", "aws/aws-php-sns-message-validator": "^1.5", - "craftcms/cms": "^5.0", + "craftcms/cms": "^5.2", "html2text/html2text": "^4.3.1", "matomo/device-detector": "^3.9.1|^4.0|^5.0|^6.0", "starkbank/ecdsa": "0.*" diff --git a/src/controllers/CampaignsController.php b/src/controllers/CampaignsController.php index 4d8474aa..1272511c 100644 --- a/src/controllers/CampaignsController.php +++ b/src/controllers/CampaignsController.php @@ -34,7 +34,7 @@ public function actionCreate(string $campaignTypeHandle): Response { $campaignType = Campaign::$plugin->campaignTypes->getCampaignTypeByHandle($campaignTypeHandle); if (!$campaignType) { - throw new BadRequestHttpException("Invalid campaign type handle: $campaignTypeHandle"); + throw new BadRequestHttpException('Invalid campaign type handle: ' . $campaignTypeHandle); } $site = Cp::requestedSite(); diff --git a/src/controllers/MailingListsController.php b/src/controllers/MailingListsController.php index b5261fc1..a678a335 100644 --- a/src/controllers/MailingListsController.php +++ b/src/controllers/MailingListsController.php @@ -31,7 +31,7 @@ public function actionCreate(string $mailingListTypeHandle): Response { $mailingListType = Campaign::$plugin->mailingListTypes->getMailingListTypeByHandle($mailingListTypeHandle); if (!$mailingListType) { - throw new BadRequestHttpException("Invalid mailing list type handle: $mailingListType"); + throw new BadRequestHttpException('Invalid mailing list type handle: ' . $mailingListType); } $site = Cp::requestedSite(); diff --git a/src/controllers/SendoutsController.php b/src/controllers/SendoutsController.php index bb2c7169..63afe44b 100755 --- a/src/controllers/SendoutsController.php +++ b/src/controllers/SendoutsController.php @@ -124,7 +124,7 @@ public function actionGetPlaintextBody(): Response public function actionCreate(string $sendoutType = null): Response { if (!isset(SendoutElement::sendoutTypes()[$sendoutType])) { - throw new BadRequestHttpException("Invalid sendout type: $sendoutType"); + throw new BadRequestHttpException('Invalid sendout type: ' . $sendoutType); } $site = Cp::requestedSite(); @@ -196,7 +196,7 @@ public function actionPreview(int $sendoutId): Response $sendout = Campaign::$plugin->sendouts->getSendoutById($sendoutId); if ($sendout === null) { - throw new BadRequestHttpException("Invalid sendout ID: $sendoutId"); + throw new BadRequestHttpException('Invalid sendout ID: ' . $sendoutId); } $this->view->registerAssetBundle(SendoutPreflightAsset::class); diff --git a/src/controllers/TrackerController.php b/src/controllers/TrackerController.php index 5166cddb..caba6f20 100644 --- a/src/controllers/TrackerController.php +++ b/src/controllers/TrackerController.php @@ -83,7 +83,7 @@ public function actionClick(): ?Response // Split the URL on the anchor hashtag, so we can add it at the end. // https://github.com/putyourlightson/craft-campaign/issues/383 - $urlParts = explode("#", $url); + $urlParts = explode('#', $url); $url = $urlParts[0]; $hashtag = !empty($urlParts[1]) ? '#' . $urlParts[1] : ''; diff --git a/src/elements/CampaignElement.php b/src/elements/CampaignElement.php index 4f819577..f469bafe 100755 --- a/src/elements/CampaignElement.php +++ b/src/elements/CampaignElement.php @@ -13,6 +13,7 @@ use craft\elements\actions\Restore; use craft\elements\Entry; use craft\elements\User; +use craft\enums\Color; use craft\helpers\Cp; use craft\helpers\Html; use craft\helpers\UrlHelper; @@ -152,10 +153,21 @@ public static function hasStatuses(): bool public static function statuses(): array { return [ - self::STATUS_SENT => Craft::t('campaign', 'Sent'), - self::STATUS_PENDING => Craft::t('campaign', 'Pending'), - self::STATUS_CLOSED => Craft::t('campaign', 'Closed'), - self::STATUS_DISABLED => Craft::t('app', 'Disabled'), + self::STATUS_SENT => [ + 'label' => Craft::t('campaign', 'Sent'), + 'color' => Color::Teal, + ], + self::STATUS_PENDING => [ + 'label' => Craft::t('campaign', 'Pending'), + 'color' => Color::Orange, + ], + self::STATUS_CLOSED => [ + 'label' => Craft::t('campaign', 'Closed'), + 'color' => Color::Red, + ], + self::STATUS_DISABLED => [ + 'label' => Craft::t('app', 'Disabled'), + ], ]; } @@ -765,7 +777,7 @@ public function getPostEditUrl(): ?string { $campaignType = $this->getCampaignType(); - return UrlHelper::cpUrl("campaign/campaigns/$campaignType->handle"); + return UrlHelper::cpUrl('campaign/campaigns/' . $campaignType->handle); } /** diff --git a/src/elements/ContactElement.php b/src/elements/ContactElement.php index 99633ca8..3d0bd19e 100755 --- a/src/elements/ContactElement.php +++ b/src/elements/ContactElement.php @@ -12,6 +12,7 @@ use craft\elements\actions\Restore; use craft\elements\conditions\ElementConditionInterface; use craft\elements\User; +use craft\enums\Color; use craft\helpers\ArrayHelper; use craft\helpers\Cp; use craft\helpers\Html; @@ -175,10 +176,22 @@ public static function hasThumbs(): bool public static function statuses(): array { return [ - self::STATUS_ACTIVE => Craft::t('campaign', 'Active'), - self::STATUS_COMPLAINED => Craft::t('campaign', 'Complained'), - self::STATUS_BOUNCED => Craft::t('campaign', 'Bounced'), - self::STATUS_BLOCKED => Craft::t('campaign', 'Blocked'), + self::STATUS_ACTIVE => [ + 'label' => Craft::t('campaign', 'Active'), + 'color' => Color::Teal, + ], + self::STATUS_COMPLAINED => [ + 'label' => Craft::t('campaign', 'Complained'), + 'color' => Color::Orange, + ], + self::STATUS_BOUNCED => [ + 'label' => Craft::t('campaign', 'Bounced'), + 'color' => Color::Red, + ], + self::STATUS_BLOCKED => [ + 'label' => Craft::t('campaign', 'Blocked'), + 'color' => Color::Black, + ], ]; } diff --git a/src/elements/MailingListElement.php b/src/elements/MailingListElement.php index b0253b80..ea4436e2 100755 --- a/src/elements/MailingListElement.php +++ b/src/elements/MailingListElement.php @@ -574,7 +574,7 @@ public function getPostEditUrl(): ?string { $mailingListType = $this->getMailingListType(); - return UrlHelper::cpUrl("campaign/mailinglists/$mailingListType->handle"); + return UrlHelper::cpUrl('campaign/mailinglists/' . $mailingListType->handle); } /** diff --git a/src/elements/SegmentElement.php b/src/elements/SegmentElement.php index 91b57eb9..fc85ba77 100755 --- a/src/elements/SegmentElement.php +++ b/src/elements/SegmentElement.php @@ -73,6 +73,14 @@ public static function refHandle(): ?string return 'segment'; } + /** + * @inheritdoc + */ + public static function hasDrafts(): bool + { + return true; + } + /** * @inheritdoc */ @@ -261,7 +269,7 @@ protected function defineRules(): array */ public function getPostEditUrl(): ?string { - return UrlHelper::cpUrl("campaign/segments"); + return UrlHelper::cpUrl('campaign/segments'); } /** diff --git a/src/elements/SendoutElement.php b/src/elements/SendoutElement.php index fbf14edd..ee904aea 100755 --- a/src/elements/SendoutElement.php +++ b/src/elements/SendoutElement.php @@ -12,6 +12,7 @@ use craft\elements\actions\Restore; use craft\elements\User; use craft\enums\CmsEdition; +use craft\enums\Color; use craft\helpers\Cp; use craft\helpers\DateTimeHelper; use craft\helpers\Json; @@ -155,6 +156,14 @@ public static function refHandle(): ?string return 'sendout'; } + /** + * @inheritdoc + */ + public static function hasDrafts(): bool + { + return true; + } + /** * @inheritdoc */ @@ -185,14 +194,33 @@ public static function hasStatuses(): bool public static function statuses(): array { return [ - self::STATUS_SENT => Craft::t('campaign', 'Sent'), - self::STATUS_SENDING => Craft::t('campaign', 'Sending'), - self::STATUS_QUEUED => Craft::t('campaign', 'Queued'), - self::STATUS_PENDING => Craft::t('campaign', 'Pending'), - self::STATUS_PAUSED => Craft::t('campaign', 'Paused'), - self::STATUS_CANCELLED => Craft::t('campaign', 'Cancelled'), - self::STATUS_FAILED => Craft::t('campaign', 'Failed'), - self::STATUS_DRAFT => Craft::t('campaign', 'Draft'), + self::STATUS_SENT => [ + 'label' => Craft::t('campaign', 'Sent'), + 'color' => Color::Teal, + ], + self::STATUS_SENDING => [ + 'label' => Craft::t('campaign', 'Sending'), + 'color' => Color::Lime, + ], + self::STATUS_QUEUED => [ + 'label' => Craft::t('campaign', 'Queued'), + 'color' => Color::Yellow, + ], + self::STATUS_PENDING => [ + 'label' => Craft::t('campaign', 'Pending'), + ], + self::STATUS_PAUSED => [ + 'label' => Craft::t('campaign', 'Paused'), + 'color' => Color::Fuchsia, + ], + self::STATUS_CANCELLED => [ + 'label' => Craft::t('campaign', 'Cancelled'), + 'color' => Color::Red, + ], + self::STATUS_FAILED => [ + 'label' => Craft::t('campaign', 'Failed'), + 'color' => Color::Black, + ], ]; } @@ -565,7 +593,7 @@ protected function defineRules(): array */ public function getPostEditUrl(): ?string { - return UrlHelper::cpUrl("campaign/sendouts"); + return UrlHelper::cpUrl('campaign/sendouts'); } /** diff --git a/src/resources/css/campaign.css b/src/resources/css/campaign.css index fbf17e1b..493f2f18 100644 --- a/src/resources/css/campaign.css +++ b/src/resources/css/campaign.css @@ -173,46 +173,6 @@ table th.thin, table td.thin { cursor: help; } -.status.sent { - background-color: var(--enabled-color); - border-color: transparent !important; -} - -.status.sending { - background-color: rgb(32, 160, 123, 0.3); - border-color: var(--enabled-color) !important; -} - -.status.queued { - background-color: rgb(203, 110, 23, 0.3); - border-color: var(--pending-color) !important; -} - -.status.blocked, .status.closed, .status.cancelled, .status.paused { - background-color: var(--disabled-color); - border-color: transparent !important; -} - -.status.paused { - background-color: rgb(207, 17, 36, 0.3); - border-color: var(--disabled-color) !important; -} - -.status.complained { - background-color: var(--amber-800); - border-color: transparent !important; -} - -.status.bounced, .status.failed { - background-color: var(--gray-800); - border-color: transparent !important; -} - -.status.draft { - --outline-color: var(--gray-500); - box-shadow: inset 0 0 0 2px var(--outline-color); -} - label.subscriptionStatus { display: inline-block; border-radius: 3px;