diff --git a/app/config/locale/templates/badge.svg.tpl b/app/config/locale/templates/badge.svg.tpl index e11152e802..a6e2df3743 100644 --- a/app/config/locale/templates/badge.svg.tpl +++ b/app/config/locale/templates/badge.svg.tpl @@ -1,5 +1,5 @@ - - appwrite: {{message}} + + {{label}}: {{message}} @@ -8,15 +8,15 @@ - - + + - - appwrite - - {{message}} + + {{label}} + + {{message}} diff --git a/src/Appwrite/Platform/Modules/Badge/Http/Action.php b/src/Appwrite/Platform/Modules/Badge/Http/Action.php index 6e00016ea9..254d07e280 100644 --- a/src/Appwrite/Platform/Modules/Badge/Http/Action.php +++ b/src/Appwrite/Platform/Modules/Badge/Http/Action.php @@ -6,7 +6,10 @@ use Utopia\Platform\Action as UtopiaAction; abstract class Action extends UtopiaAction { - protected const LABEL_WIDTH = 77; + protected const LABEL_FONT_SIZE = 110; + protected const LABEL_TEXT_X = 260; + protected const TEXT_PADDING = 10; + protected const FALLBACK_CHAR_WIDTH = 7; protected const COLOR_BRIGHTGREEN = '#4c1'; protected const COLOR_GREEN = '#97ca00'; protected const COLOR_YELLOW = '#dfb317'; diff --git a/src/Appwrite/Platform/Modules/Badge/Http/Functions/Get.php b/src/Appwrite/Platform/Modules/Badge/Http/Functions/Get.php index d9b6551153..b5ae133d20 100644 --- a/src/Appwrite/Platform/Modules/Badge/Http/Functions/Get.php +++ b/src/Appwrite/Platform/Modules/Badge/Http/Functions/Get.php @@ -11,6 +11,19 @@ use Utopia\Validator\Text; class Get extends Action { + private const LABEL = 'appwrite functions'; + private const LABEL_WIDTH = 137; + private const MESSAGE_WIDTHS = [ + 'not found' => 75, + 'disabled' => 75, + 'no deployment' => 112, + 'unknown' => 74, + 'ready' => 60, + 'building' => 76, + 'waiting' => 70, + 'failed' => 60, + ]; + public static function getName(): string { return 'getFunctionBadge'; @@ -37,6 +50,7 @@ class Get extends Action public function action(string $functionId, Response $response, Database $dbForProject, Authorization $authorization): void { $function = $authorization->skip(fn () => $dbForProject->getDocument('functions', $functionId)); + $label = self::LABEL; switch (true) { case $function->isEmpty(): @@ -81,13 +95,20 @@ class Get extends Action } $colorCode = self::COLOR_BY_NAME[$color] ?? self::COLOR_LIGHTGREY; - $totalWidth = self::LABEL_WIDTH + (\strlen($message) * 6) + 10; + $messageWidth = self::MESSAGE_WIDTHS[$message] ?? ((\strlen($message) * self::FALLBACK_CHAR_WIDTH) + (self::TEXT_PADDING * 2)); + $totalWidth = self::LABEL_WIDTH + $messageWidth; + $messageTextX = (self::LABEL_WIDTH + self::TEXT_PADDING) * 10; $templatePath = \dirname(__DIR__, 7) . '/app/config/locale/templates/badge.svg.tpl'; $template = Template::fromFile($templatePath); $template + ->setParam('{{label}}', $label) ->setParam('{{message}}', $message) ->setParam('{{colorCode}}', $colorCode) + ->setParam('{{labelWidth}}', (string)self::LABEL_WIDTH) + ->setParam('{{labelFontSize}}', (string)self::LABEL_FONT_SIZE) + ->setParam('{{labelTextX}}', (string)self::LABEL_TEXT_X) + ->setParam('{{messageTextX}}', (string)$messageTextX) ->setParam('{{totalWidth}}', (string) $totalWidth); $svg = $template->render(); diff --git a/src/Appwrite/Platform/Modules/Badge/Http/Sites/Get.php b/src/Appwrite/Platform/Modules/Badge/Http/Sites/Get.php index 86d62478c1..c565cd0de1 100644 --- a/src/Appwrite/Platform/Modules/Badge/Http/Sites/Get.php +++ b/src/Appwrite/Platform/Modules/Badge/Http/Sites/Get.php @@ -11,6 +11,19 @@ use Utopia\Validator\Text; class Get extends Action { + private const LABEL = 'appwrite sites'; + private const LABEL_WIDTH = 110; + private const MESSAGE_WIDTHS = [ + 'not found' => 75, + 'disabled' => 75, + 'no deployment' => 112, + 'unknown' => 74, + 'ready' => 60, + 'building' => 76, + 'waiting' => 70, + 'failed' => 60, + ]; + public static function getName(): string { return 'getSiteBadge'; @@ -37,6 +50,7 @@ class Get extends Action public function action(string $siteId, Response $response, Database $dbForProject, Authorization $authorization): void { $site = $authorization->skip(fn () => $dbForProject->getDocument('sites', $siteId)); + $label = self::LABEL; switch (true) { case $site->isEmpty(): @@ -81,13 +95,20 @@ class Get extends Action } $colorCode = self::COLOR_BY_NAME[$color] ?? self::COLOR_LIGHTGREY; - $totalWidth = self::LABEL_WIDTH + (\strlen($message) * 6) + 10; + $messageWidth = self::MESSAGE_WIDTHS[$message] ?? ((\strlen($message) * self::FALLBACK_CHAR_WIDTH) + (self::TEXT_PADDING * 2)); + $totalWidth = self::LABEL_WIDTH + $messageWidth; + $messageTextX = (self::LABEL_WIDTH + self::TEXT_PADDING) * 10; $templatePath = \dirname(__DIR__, 7) . '/app/config/locale/templates/badge.svg.tpl'; $template = Template::fromFile($templatePath); $template + ->setParam('{{label}}', $label) ->setParam('{{message}}', $message) ->setParam('{{colorCode}}', $colorCode) + ->setParam('{{labelWidth}}', (string)self::LABEL_WIDTH) + ->setParam('{{labelFontSize}}', (string)self::LABEL_FONT_SIZE) + ->setParam('{{labelTextX}}', (string)self::LABEL_TEXT_X) + ->setParam('{{messageTextX}}', (string)$messageTextX) ->setParam('{{totalWidth}}', (string) $totalWidth); $svg = $template->render();