-
-
Notifications
You must be signed in to change notification settings - Fork 261
Feat(activity-log): Add event-based icons to activity log entries #2015
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -143,7 +143,66 @@ protected static function boot(): void | |||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Icon mapping for activity event groups. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Consistent with icons used throughout the panel (SubuserPermission, Resources, etc.) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| private const EVENT_ICON_MAP = [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'backup' => 'tabler-file-zip', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'file' => 'tabler-files', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'database' => 'tabler-database', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'schedule' => 'tabler-clock', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'allocation' => 'tabler-network', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'startup' => 'tabler-player-play', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'settings' => 'tabler-settings', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'subuser' => 'tabler-users', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'console' => 'tabler-terminal-2', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'control' => 'tabler-terminal-2', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'power' => 'tabler-power', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'sftp' => 'tabler-folder-share', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'server' => 'tabler-server', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'auth' => 'tabler-shield', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'user' => 'tabler-user', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'api-key' => 'tabler-key', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'reset-password' => 'tabler-key', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'ssh' => 'tabler-terminal', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Get the icon for this activity log entry based on the event type. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Parses the event string to extract the event group and returns the | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| * corresponding icon from EVENT_ICON_MAP. Falls back to actor-based | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| * icon if no specific mapping exists. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @return string The tabler icon name for this activity | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| public function getIcon(): string | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Extract the event group (e.g., "server:backup.create" → "backup") | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| $eventParts = explode(':', $this->event); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| $group = count($eventParts) > 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ? explode('.', $eventParts[1])[0] | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| : explode('.', $eventParts[0])[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Return event-specific icon if available | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (isset(self::EVENT_ICON_MAP[$group])) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| return self::EVENT_ICON_MAP[$group]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Fallback to actor-based icon | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| return $this->getActorIcon(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
180
to
+195
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Simplify this by using the Laravel String library instead:
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Get icon based on the actor type. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Returns an icon representing who performed the action when the event | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| * group doesn't have a specific icon mapping. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| * @return string The tabler icon name based on actor type | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| private function getActorIcon(): string | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ($this->apiKey) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| return 'tabler-api'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -160,7 +219,7 @@ public function getLabel(): string | |||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| $properties = $this->wrapProperties(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| return trans_choice('activity.'.str($this->event)->replace(':', '.'), array_key_exists('count', $properties) ? $properties['count'] : 1, $properties); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| return trans_choice('activity.' . str($this->event)->replace(':', '.'), array_key_exists('count', $properties) ? $properties['count'] : 1, $properties); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
use laravel's helper instead of ternary |
||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| public function getIp(): ?string | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -249,7 +308,7 @@ public function hasAdditionalMetadata(): bool | |||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| $properties = $this->wrapProperties(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| $event = trans_choice('activity.'.str($this->event)->replace(':', '.'), array_key_exists('count', $properties) ? $properties['count'] : 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| $event = trans_choice('activity.' . str($this->event)->replace(':', '.'), array_key_exists('count', $properties) ? $properties['count'] : 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| preg_match_all('/:(?<key>[\w.-]+\w)(?:[^\w:]?|$)/', $event, $matches); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please translate this into a new enum! Something like ActivityEventIcon
TYVM