Appearance
Helper Plugin
File Information
- Path:
plugins/helper.js - Purpose: Global utility function injection and workspace management
Overview
The Helper plugin injects utility functions globally, making them available throughout the application via $ prefix. It also provides workspace management functions, resource sorting, and file type utilities. All utility functions from @/utils are automatically injected.
Key Features
Utility Function Injection
- All utils functions injected globally
- Available as
$functionName - Automatic injection from utils module
Workspace Management
- Current workspace access
- Workspace switching
- Workspace ID retrieval
- User modules and roles
Resource Sorting
- Asset sorting
- Folder sorting
- Multi-criteria sorting
File Type Utilities
- File accept strings
- Image file types
Injected Functions
All functions from @/utils are injected. Common ones include:
Workspace Functions
$getWorkspaceId()
Gets current workspace ID:
- Returns workspace ID from auth storage
- Returns null if not available
Returns: Workspace ID string or null
$_auth()
Gets current workspace from auth:
- Returns current workspace object
- Returns null if not logged in
Returns: Workspace object or null
$setCurrentWorkspace(workspaceId)
Sets current workspace:
- Finds workspace in accessible workspaces
- Updates auth storage
- Resets DAM state if needed
- Sets workspace cookie
Parameters:
workspaceId(string|number): Workspace ID
$getUserModulesAndRoles(workspace)
Gets user modules and roles for workspace:
- Determines user permissions
- Sets role flags (isAdmin, isViewer, etc.)
- Returns user object with permissions
Parameters:
workspace(Object): Workspace object
Returns: User object with permissions
Resource Sorting
$sortResources(assets, sortBy, sortOrder)
Sorts resources (assets and folders):
- Sorts by specified field
- Handles file and folder objects
- Supports ascending/descending
Parameters:
assets(Array): Array of asset/folder objectssortBy(string): Field to sort bysortOrder(string): 'asc' or 'desc'
Returns: Sorted array
File Type Utilities
$fileAcceptInputImage
Injected constant for image file types:
- Value:
'image/jpeg,image/gif,image/png,image/svg,image/jpg' - Used in file input accept attribute
Vue Filters
shrinkString
String truncation filter:
- Truncates long strings
- Adds ellipsis
- Configurable length
Usage:
vue
{{ longString | shrinkString }}Usage Examples
Workspace ID
javascript
// In component
const workspaceId = this.$getWorkspaceId()Current Workspace
javascript
// In component
const workspace = this.$_auth()
if (workspace) {
console.log('Current workspace:', workspace.name)
}Set Workspace
javascript
// In component
this.$setCurrentWorkspace(newWorkspaceId)User Permissions
javascript
// In component
const workspace = this.$_auth()
const user = this.$getUserModulesAndRoles(workspace)
if (user.dam.isAdmin) {
// Admin actions
}Resource Sorting
javascript
// In component
const sorted = this.$sortResources(assets, 'display_file_name', 'asc')File Input
vue
<template>
<input
type="file"
:accept="$fileAcceptInputImage"
/>
</template>Utility Functions
All utility functions from @/utils are available:
- File type detection
- String manipulation
- Date formatting
- Number formatting
- Validation functions
- And more...
Integration Points
- All Components: Global utility access
- Workspace Management: Workspace operations
- File Operations: File type handling
- Sorting: Resource sorting
- Utils Module: Utility function source
Notes for Development
- All utils functions are automatically injected
- Functions available as
$functionName - Workspace functions use auth storage
- Resource sorting handles mixed types
- File accept strings are constants
- Vue filters are registered globally
Related Documentation
- Utils Documentation - Utility functions
- Current Workspace Mixin - Workspace mixin
- Multi-Workspace Feature - Workspace system