@memberjunction/ng-link-directives 0.9.34 → 0.9.36
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/package.json +7 -4
- package/src/lib/ng-base-link.ts +0 -14
- package/src/lib/ng-email-link.ts +0 -22
- package/src/lib/ng-field-link.ts +0 -69
- package/src/lib/ng-link-directives.module.ts +0 -22
- package/src/lib/ng-web-link.ts +0 -22
- package/src/public-api.ts +0 -9
- package/tsconfig.json +0 -24
package/package.json
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@memberjunction/ng-link-directives",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.36",
|
|
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",
|
|
7
|
+
"files": [
|
|
8
|
+
"/dist"
|
|
9
|
+
],
|
|
7
10
|
"scripts": {
|
|
8
11
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
9
12
|
"build": "ngc"
|
|
@@ -23,11 +26,11 @@
|
|
|
23
26
|
"peerDependencies": {
|
|
24
27
|
"@angular/common": "^15.2.0",
|
|
25
28
|
"@angular/core": "^15.2.0",
|
|
26
|
-
"@angular/router": "^15.2.0"
|
|
27
|
-
"@memberjunction/core": "^0.9.49"
|
|
29
|
+
"@angular/router": "^15.2.0"
|
|
28
30
|
},
|
|
29
31
|
"dependencies": {
|
|
30
|
-
"tslib": "^2.3.0"
|
|
32
|
+
"tslib": "^2.3.0",
|
|
33
|
+
"@memberjunction/core": "^0.9.59"
|
|
31
34
|
},
|
|
32
35
|
"sideEffects": false
|
|
33
36
|
}
|
package/src/lib/ng-base-link.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { ElementRef, Renderer2 } from '@angular/core';
|
|
2
|
-
import { EntityField } from '@memberjunction/core';
|
|
3
|
-
|
|
4
|
-
export abstract class BaseLink {
|
|
5
|
-
protected CreateLink(el: ElementRef, field: EntityField, renderer: Renderer2, href: string, newTab: boolean = false) {
|
|
6
|
-
const parent = el.nativeElement.parentNode;
|
|
7
|
-
const a = renderer.createElement('a');
|
|
8
|
-
renderer.setAttribute(a, 'href', href);
|
|
9
|
-
if (newTab)
|
|
10
|
-
renderer.setAttribute(a, 'target', '_blank');
|
|
11
|
-
renderer.insertBefore(parent, a, el.nativeElement);
|
|
12
|
-
renderer.appendChild(a, el.nativeElement);
|
|
13
|
-
}
|
|
14
|
-
}
|
package/src/lib/ng-email-link.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { Directive, ElementRef, Renderer2, Input, OnInit } from '@angular/core';
|
|
2
|
-
import { EntityField, LogError } from '@memberjunction/core';
|
|
3
|
-
import { BaseLink } from './ng-base-link';
|
|
4
|
-
|
|
5
|
-
@Directive({
|
|
6
|
-
selector: '[mjEmailLink]'
|
|
7
|
-
})
|
|
8
|
-
export class EmailLink extends BaseLink implements OnInit {
|
|
9
|
-
@Input('field') field!: EntityField; // Input variable to get the fieldInfo
|
|
10
|
-
|
|
11
|
-
constructor(private el: ElementRef, private renderer: Renderer2) {
|
|
12
|
-
super();
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
ngOnInit() {
|
|
16
|
-
const extendedType = this.field.EntityFieldInfo.ExtendedType;
|
|
17
|
-
if (extendedType && extendedType.trim().toLowerCase() === 'email')
|
|
18
|
-
this.CreateLink(this.el, this.field, this.renderer, 'mailto:' + this.field.Value, true);
|
|
19
|
-
else
|
|
20
|
-
LogError('Entity Field must have ExtendedType of URL to use the mjWebLink directive. Field:' + this.field.Name);
|
|
21
|
-
}
|
|
22
|
-
}
|
package/src/lib/ng-field-link.ts
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { Directive, ElementRef, Renderer2, Input, OnInit, HostListener } from '@angular/core';
|
|
2
|
-
import { ActivatedRoute, Router } from '@angular/router';
|
|
3
|
-
import { BaseEntity, EntityField, LogStatus, Metadata } from '@memberjunction/core';
|
|
4
|
-
import { BaseLink } from './ng-base-link';
|
|
5
|
-
|
|
6
|
-
@Directive({
|
|
7
|
-
selector: '[mjFieldLink]'
|
|
8
|
-
})
|
|
9
|
-
export class FieldLink extends BaseLink implements OnInit {
|
|
10
|
-
|
|
11
|
-
@Input('record') record!: BaseEntity; // Input variable to get the entity record
|
|
12
|
-
@Input('fieldName') fieldName!: string; // Input variable to get the fieldInfo
|
|
13
|
-
@Input('replaceText') replaceText: boolean = true ; //
|
|
14
|
-
|
|
15
|
-
private _targetEntity: string = '';
|
|
16
|
-
private _targetRecordID: number = 0;
|
|
17
|
-
|
|
18
|
-
constructor(private el: ElementRef, private renderer: Renderer2, private route: ActivatedRoute, private router: Router) {
|
|
19
|
-
super();
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
public get field(): EntityField {
|
|
23
|
-
if (!this.record) throw new Error('entity not set');
|
|
24
|
-
if (!this.fieldName) throw new Error('fieldName not set');
|
|
25
|
-
const field = this.record.Fields.find(f => f.Name === this.fieldName);
|
|
26
|
-
if (!field) throw new Error(`Unable to find field ${this.fieldName} in entity ${this.record.EntityInfo.Name}`);
|
|
27
|
-
return field;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
ngOnInit() {
|
|
31
|
-
const relatedEntity = this.field.EntityFieldInfo.RelatedEntity;
|
|
32
|
-
if (relatedEntity && relatedEntity.length > 0) {
|
|
33
|
-
this._targetEntity = relatedEntity;
|
|
34
|
-
this._targetRecordID = this.field.Value;
|
|
35
|
-
this.CreateLink(this.el, this.field, this.renderer, '', false);
|
|
36
|
-
|
|
37
|
-
if (this.replaceText) {
|
|
38
|
-
// replace the value of the field with the record name
|
|
39
|
-
// first see if we already have the value locally using metadata for RelatedEntityNameFieldMap
|
|
40
|
-
if (this.field.EntityFieldInfo.RelatedEntityNameFieldMap &&
|
|
41
|
-
this.field.EntityFieldInfo.RelatedEntityNameFieldMap.length > 0) {
|
|
42
|
-
const nameField = this.field.EntityFieldInfo.RelatedEntityNameFieldMap;
|
|
43
|
-
const nameFieldValue = this.record.Get(nameField)
|
|
44
|
-
if (nameFieldValue && nameFieldValue.length > 0)
|
|
45
|
-
this.renderer.setProperty(this.el.nativeElement, 'textContent', nameFieldValue);
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
// no luck, no related entity name field map provided in the entity field metadata, so do a lookup
|
|
49
|
-
// requires a server round trip and hitting the DB, so we try to avoid this
|
|
50
|
-
const md = new Metadata();
|
|
51
|
-
md.GetEntityRecordName(relatedEntity, this.field.Value).then(recordName => {
|
|
52
|
-
if (recordName && recordName.length > 0)
|
|
53
|
-
this.renderer.setProperty(this.el.nativeElement, 'textContent', recordName);
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
LogStatus('no linked entity found for field: ' + this.field.Name);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
@HostListener('click', ['$event'])
|
|
64
|
-
onClick(event: Event) {
|
|
65
|
-
event.preventDefault();
|
|
66
|
-
this.router.navigate(['resource', 'record', this._targetRecordID], { queryParams: { Entity: this._targetEntity } })
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { NgModule } from '@angular/core';
|
|
2
|
-
import { CommonModule } from '@angular/common';
|
|
3
|
-
import { EmailLink } from './ng-email-link';
|
|
4
|
-
import { FieldLink } from './ng-field-link';
|
|
5
|
-
import { WebLink } from './ng-web-link';
|
|
6
|
-
|
|
7
|
-
@NgModule({
|
|
8
|
-
declarations: [
|
|
9
|
-
EmailLink,
|
|
10
|
-
FieldLink,
|
|
11
|
-
WebLink
|
|
12
|
-
],
|
|
13
|
-
imports: [
|
|
14
|
-
CommonModule
|
|
15
|
-
],
|
|
16
|
-
exports: [
|
|
17
|
-
EmailLink,
|
|
18
|
-
FieldLink,
|
|
19
|
-
WebLink
|
|
20
|
-
]
|
|
21
|
-
})
|
|
22
|
-
export class LinkDirectivesModule { }
|
package/src/lib/ng-web-link.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { Directive, ElementRef, Renderer2, Input, OnInit } from '@angular/core';
|
|
2
|
-
import { EntityField, LogError } from '@memberjunction/core';
|
|
3
|
-
import { BaseLink } from './ng-base-link';
|
|
4
|
-
|
|
5
|
-
@Directive({
|
|
6
|
-
selector: '[mjWebLink]'
|
|
7
|
-
})
|
|
8
|
-
export class WebLink extends BaseLink implements OnInit {
|
|
9
|
-
@Input('field') field!: EntityField; // Input variable to get the fieldInfo
|
|
10
|
-
|
|
11
|
-
constructor(private el: ElementRef, private renderer: Renderer2) {
|
|
12
|
-
super();
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
ngOnInit() {
|
|
16
|
-
const extendedType = this.field.EntityFieldInfo.ExtendedType;
|
|
17
|
-
if (extendedType && extendedType.trim().toLowerCase() === 'url')
|
|
18
|
-
this.CreateLink(this.el, this.field, this.renderer, this.field.Value, true);
|
|
19
|
-
else
|
|
20
|
-
LogError('Entity Field must have ExtendedType of URL to use the mjWebLink directive. Field:' + this.field.Name);
|
|
21
|
-
}
|
|
22
|
-
}
|
package/src/public-api.ts
DELETED
package/tsconfig.json
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "es2015",
|
|
4
|
-
"module": "es2020",
|
|
5
|
-
"moduleResolution": "node",
|
|
6
|
-
"declaration": true,
|
|
7
|
-
"experimentalDecorators": true,
|
|
8
|
-
"outDir": "./dist",
|
|
9
|
-
"strict": true,
|
|
10
|
-
"lib": [
|
|
11
|
-
"es2018",
|
|
12
|
-
"dom"
|
|
13
|
-
]
|
|
14
|
-
},
|
|
15
|
-
"angularCompilerOptions": {
|
|
16
|
-
"skipTemplateCodegen": true,
|
|
17
|
-
"strictMetadataEmit": true,
|
|
18
|
-
"enableResourceInlining": true
|
|
19
|
-
},
|
|
20
|
-
"include": [
|
|
21
|
-
"src/**/*.ts"
|
|
22
|
-
]
|
|
23
|
-
}
|
|
24
|
-
|