@memberjunction/ng-link-directives 2.32.1 → 2.33.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +144 -0
- package/package.json +2 -2
package/README.md
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# @memberjunction/ng-link-directives
|
|
2
|
+
|
|
3
|
+
The `@memberjunction/ng-link-directives` package provides a set of Angular directives that transform text elements into different types of links based on MemberJunction entity field metadata. This makes it easy to display email addresses, URLs, and entity relationships as clickable links in your application.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Email link directive for fields with "email" extended type
|
|
8
|
+
- Web link directive for fields with "url" extended type
|
|
9
|
+
- Field link directive for related entity fields that navigates to the related record
|
|
10
|
+
- Automatic value resolution for field links (displays the related entity's name)
|
|
11
|
+
- Target control for web links (opens in new tab)
|
|
12
|
+
- Styling options for all link types
|
|
13
|
+
- Leverages MemberJunction's metadata system
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install @memberjunction/ng-link-directives
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Requirements
|
|
22
|
+
|
|
23
|
+
- Angular 18+
|
|
24
|
+
- @memberjunction/core
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
### Basic Setup
|
|
29
|
+
|
|
30
|
+
First, import the LinkDirectivesModule in your module:
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
import { LinkDirectivesModule } from '@memberjunction/ng-link-directives';
|
|
34
|
+
|
|
35
|
+
@NgModule({
|
|
36
|
+
imports: [
|
|
37
|
+
// other imports...
|
|
38
|
+
LinkDirectivesModule
|
|
39
|
+
],
|
|
40
|
+
})
|
|
41
|
+
export class YourModule { }
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Email Link Directive
|
|
45
|
+
|
|
46
|
+
The email link directive converts text into a mailto: link when the field has an extended type of "email".
|
|
47
|
+
|
|
48
|
+
```html
|
|
49
|
+
<span [mjEmailLink]="field">{{ field.Value }}</span>
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Where `field` is an EntityField object from a MemberJunction entity with ExtendedType of "email".
|
|
53
|
+
|
|
54
|
+
### Web Link Directive
|
|
55
|
+
|
|
56
|
+
The web link directive converts text into an external URL link when the field has an extended type of "url".
|
|
57
|
+
|
|
58
|
+
```html
|
|
59
|
+
<span [mjWebLink]="field">{{ field.Value }}</span>
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Where `field` is an EntityField object from a MemberJunction entity with ExtendedType of "url".
|
|
63
|
+
|
|
64
|
+
### Field Link Directive
|
|
65
|
+
|
|
66
|
+
The field link directive creates a link to another entity record when the field is a foreign key to another entity.
|
|
67
|
+
|
|
68
|
+
```html
|
|
69
|
+
<span [mjFieldLink]="true" [record]="customerRecord" [fieldName]="'AssignedUserID'">
|
|
70
|
+
{{ customerRecord.Get('AssignedUserID') }}
|
|
71
|
+
</span>
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
This will display the AssignedUserID field value but link to the User entity record. The directive will attempt to replace the ID with the related entity's name when [replaceText]="true" is set.
|
|
75
|
+
|
|
76
|
+
## API Reference
|
|
77
|
+
|
|
78
|
+
### EmailLink Directive
|
|
79
|
+
|
|
80
|
+
| Input | Type | Description |
|
|
81
|
+
|-------|------|-------------|
|
|
82
|
+
| `field` | `EntityField` | The entity field object containing email data |
|
|
83
|
+
|
|
84
|
+
### WebLink Directive
|
|
85
|
+
|
|
86
|
+
| Input | Type | Description |
|
|
87
|
+
|-------|------|-------------|
|
|
88
|
+
| `field` | `EntityField` | The entity field object containing URL data |
|
|
89
|
+
|
|
90
|
+
### FieldLink Directive
|
|
91
|
+
|
|
92
|
+
| Input | Type | Default | Description |
|
|
93
|
+
|-------|------|---------|-------------|
|
|
94
|
+
| `record` | `BaseEntity` | (required) | The entity record object |
|
|
95
|
+
| `fieldName` | `string` | (required) | The name of the field that contains the foreign key |
|
|
96
|
+
| `replaceText` | `boolean` | `true` | Whether to replace the field value with the related entity's name |
|
|
97
|
+
|
|
98
|
+
## How It Works
|
|
99
|
+
|
|
100
|
+
### Base Link Class
|
|
101
|
+
|
|
102
|
+
All directives extend the BaseLink abstract class, which provides a common CreateLink method:
|
|
103
|
+
|
|
104
|
+
```typescript
|
|
105
|
+
protected CreateLink(el: ElementRef, field: EntityField, renderer: Renderer2, href: string, newTab: boolean = false) {
|
|
106
|
+
// Creates an <a> element and wraps the original element
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Email Links
|
|
111
|
+
|
|
112
|
+
The EmailLink directive prepends "mailto:" to the field value and creates a link that opens the user's email client when clicked.
|
|
113
|
+
|
|
114
|
+
### Web Links
|
|
115
|
+
|
|
116
|
+
The WebLink directive uses the field value as the URL and creates a link that opens in a new tab when clicked.
|
|
117
|
+
|
|
118
|
+
### Field Links
|
|
119
|
+
|
|
120
|
+
The FieldLink directive:
|
|
121
|
+
1. Identifies the related entity from the field metadata
|
|
122
|
+
2. Gets the primary key of the related record
|
|
123
|
+
3. Creates a link to navigate to that record in the application
|
|
124
|
+
4. Optionally replaces the ID with the related record's name
|
|
125
|
+
5. Intercepts click events to handle navigation within the Angular app
|
|
126
|
+
|
|
127
|
+
## Styling
|
|
128
|
+
|
|
129
|
+
All links use the CSS class `link-text`, which you can style in your application:
|
|
130
|
+
|
|
131
|
+
```css
|
|
132
|
+
.link-text {
|
|
133
|
+
color: #0066cc;
|
|
134
|
+
text-decoration: underline;
|
|
135
|
+
cursor: pointer;
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Dependencies
|
|
140
|
+
|
|
141
|
+
- @angular/common
|
|
142
|
+
- @angular/core
|
|
143
|
+
- @angular/router
|
|
144
|
+
- @memberjunction/core
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@memberjunction/ng-link-directives",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.33.0",
|
|
4
4
|
"description": "MemberJunction: Angular Link Directives for turning an element in an angular app into an email, web, or record link",
|
|
5
5
|
"main": "./dist/public-api.js",
|
|
6
6
|
"typings": "./dist/public-api.d.ts",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"tslib": "^2.3.0",
|
|
33
|
-
"@memberjunction/core": "2.
|
|
33
|
+
"@memberjunction/core": "2.33.0"
|
|
34
34
|
},
|
|
35
35
|
"sideEffects": false
|
|
36
36
|
}
|