@memberjunction/ng-link-directives 0.9.35 → 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/dist/lib/ng-base-link.d.ts +5 -0
- package/dist/lib/ng-base-link.js +11 -0
- package/dist/lib/ng-email-link.d.ts +13 -0
- package/dist/lib/ng-email-link.js +29 -0
- package/dist/lib/ng-field-link.d.ts +22 -0
- package/dist/lib/ng-field-link.js +84 -0
- package/dist/lib/ng-link-directives.module.d.ts +10 -0
- package/dist/lib/ng-link-directives.module.js +34 -0
- package/dist/lib/ng-web-link.d.ts +13 -0
- package/dist/lib/ng-web-link.js +29 -0
- package/dist/public-api.d.ts +5 -0
- package/{src/public-api.ts → dist/public-api.js} +3 -4
- package/package.json +5 -2
- 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/tsconfig.json +0 -24
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ElementRef, Renderer2 } from '@angular/core';
|
|
2
|
+
import { EntityField } from '@memberjunction/core';
|
|
3
|
+
export declare abstract class BaseLink {
|
|
4
|
+
protected CreateLink(el: ElementRef, field: EntityField, renderer: Renderer2, href: string, newTab?: boolean): void;
|
|
5
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export class BaseLink {
|
|
2
|
+
CreateLink(el, field, renderer, href, newTab = false) {
|
|
3
|
+
const parent = el.nativeElement.parentNode;
|
|
4
|
+
const a = renderer.createElement('a');
|
|
5
|
+
renderer.setAttribute(a, 'href', href);
|
|
6
|
+
if (newTab)
|
|
7
|
+
renderer.setAttribute(a, 'target', '_blank');
|
|
8
|
+
renderer.insertBefore(parent, a, el.nativeElement);
|
|
9
|
+
renderer.appendChild(a, el.nativeElement);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ElementRef, Renderer2, OnInit } from '@angular/core';
|
|
2
|
+
import { EntityField } from '@memberjunction/core';
|
|
3
|
+
import { BaseLink } from './ng-base-link';
|
|
4
|
+
import * as i0 from "@angular/core";
|
|
5
|
+
export declare class EmailLink extends BaseLink implements OnInit {
|
|
6
|
+
private el;
|
|
7
|
+
private renderer;
|
|
8
|
+
field: EntityField;
|
|
9
|
+
constructor(el: ElementRef, renderer: Renderer2);
|
|
10
|
+
ngOnInit(): void;
|
|
11
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<EmailLink, never>;
|
|
12
|
+
static ɵdir: i0.ɵɵDirectiveDeclaration<EmailLink, "[mjEmailLink]", never, { "field": "field"; }, {}, never, never, false, never>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Directive, Input } from '@angular/core';
|
|
2
|
+
import { LogError } from '@memberjunction/core';
|
|
3
|
+
import { BaseLink } from './ng-base-link';
|
|
4
|
+
import * as i0 from "@angular/core";
|
|
5
|
+
export class EmailLink extends BaseLink {
|
|
6
|
+
constructor(el, renderer) {
|
|
7
|
+
super();
|
|
8
|
+
this.el = el;
|
|
9
|
+
this.renderer = renderer;
|
|
10
|
+
}
|
|
11
|
+
ngOnInit() {
|
|
12
|
+
const extendedType = this.field.EntityFieldInfo.ExtendedType;
|
|
13
|
+
if (extendedType && extendedType.trim().toLowerCase() === 'email')
|
|
14
|
+
this.CreateLink(this.el, this.field, this.renderer, 'mailto:' + this.field.Value, true);
|
|
15
|
+
else
|
|
16
|
+
LogError('Entity Field must have ExtendedType of URL to use the mjWebLink directive. Field:' + this.field.Name);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
EmailLink.ɵfac = function EmailLink_Factory(t) { return new (t || EmailLink)(i0.ɵɵdirectiveInject(i0.ElementRef), i0.ɵɵdirectiveInject(i0.Renderer2)); };
|
|
20
|
+
EmailLink.ɵdir = /*@__PURE__*/ i0.ɵɵdefineDirective({ type: EmailLink, selectors: [["", "mjEmailLink", ""]], inputs: { field: "field" }, features: [i0.ɵɵInheritDefinitionFeature] });
|
|
21
|
+
(function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(EmailLink, [{
|
|
22
|
+
type: Directive,
|
|
23
|
+
args: [{
|
|
24
|
+
selector: '[mjEmailLink]'
|
|
25
|
+
}]
|
|
26
|
+
}], function () { return [{ type: i0.ElementRef }, { type: i0.Renderer2 }]; }, { field: [{
|
|
27
|
+
type: Input,
|
|
28
|
+
args: ['field']
|
|
29
|
+
}] }); })();
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ElementRef, Renderer2, OnInit } from '@angular/core';
|
|
2
|
+
import { ActivatedRoute, Router } from '@angular/router';
|
|
3
|
+
import { BaseEntity, EntityField } from '@memberjunction/core';
|
|
4
|
+
import { BaseLink } from './ng-base-link';
|
|
5
|
+
import * as i0 from "@angular/core";
|
|
6
|
+
export declare class FieldLink extends BaseLink implements OnInit {
|
|
7
|
+
private el;
|
|
8
|
+
private renderer;
|
|
9
|
+
private route;
|
|
10
|
+
private router;
|
|
11
|
+
record: BaseEntity;
|
|
12
|
+
fieldName: string;
|
|
13
|
+
replaceText: boolean;
|
|
14
|
+
private _targetEntity;
|
|
15
|
+
private _targetRecordID;
|
|
16
|
+
constructor(el: ElementRef, renderer: Renderer2, route: ActivatedRoute, router: Router);
|
|
17
|
+
get field(): EntityField;
|
|
18
|
+
ngOnInit(): void;
|
|
19
|
+
onClick(event: Event): void;
|
|
20
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<FieldLink, never>;
|
|
21
|
+
static ɵdir: i0.ɵɵDirectiveDeclaration<FieldLink, "[mjFieldLink]", never, { "record": "record"; "fieldName": "fieldName"; "replaceText": "replaceText"; }, {}, never, never, false, never>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { Directive, Input, HostListener } from '@angular/core';
|
|
2
|
+
import { LogStatus, Metadata } from '@memberjunction/core';
|
|
3
|
+
import { BaseLink } from './ng-base-link';
|
|
4
|
+
import * as i0 from "@angular/core";
|
|
5
|
+
import * as i1 from "@angular/router";
|
|
6
|
+
export class FieldLink extends BaseLink {
|
|
7
|
+
constructor(el, renderer, route, router) {
|
|
8
|
+
super();
|
|
9
|
+
this.el = el;
|
|
10
|
+
this.renderer = renderer;
|
|
11
|
+
this.route = route;
|
|
12
|
+
this.router = router;
|
|
13
|
+
this.replaceText = true; //
|
|
14
|
+
this._targetEntity = '';
|
|
15
|
+
this._targetRecordID = 0;
|
|
16
|
+
}
|
|
17
|
+
get field() {
|
|
18
|
+
if (!this.record)
|
|
19
|
+
throw new Error('entity not set');
|
|
20
|
+
if (!this.fieldName)
|
|
21
|
+
throw new Error('fieldName not set');
|
|
22
|
+
const field = this.record.Fields.find(f => f.Name === this.fieldName);
|
|
23
|
+
if (!field)
|
|
24
|
+
throw new Error(`Unable to find field ${this.fieldName} in entity ${this.record.EntityInfo.Name}`);
|
|
25
|
+
return field;
|
|
26
|
+
}
|
|
27
|
+
ngOnInit() {
|
|
28
|
+
const relatedEntity = this.field.EntityFieldInfo.RelatedEntity;
|
|
29
|
+
if (relatedEntity && relatedEntity.length > 0) {
|
|
30
|
+
this._targetEntity = relatedEntity;
|
|
31
|
+
this._targetRecordID = this.field.Value;
|
|
32
|
+
this.CreateLink(this.el, this.field, this.renderer, '', false);
|
|
33
|
+
if (this.replaceText) {
|
|
34
|
+
// replace the value of the field with the record name
|
|
35
|
+
// first see if we already have the value locally using metadata for RelatedEntityNameFieldMap
|
|
36
|
+
if (this.field.EntityFieldInfo.RelatedEntityNameFieldMap &&
|
|
37
|
+
this.field.EntityFieldInfo.RelatedEntityNameFieldMap.length > 0) {
|
|
38
|
+
const nameField = this.field.EntityFieldInfo.RelatedEntityNameFieldMap;
|
|
39
|
+
const nameFieldValue = this.record.Get(nameField);
|
|
40
|
+
if (nameFieldValue && nameFieldValue.length > 0)
|
|
41
|
+
this.renderer.setProperty(this.el.nativeElement, 'textContent', nameFieldValue);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
// no luck, no related entity name field map provided in the entity field metadata, so do a lookup
|
|
45
|
+
// requires a server round trip and hitting the DB, so we try to avoid this
|
|
46
|
+
const md = new Metadata();
|
|
47
|
+
md.GetEntityRecordName(relatedEntity, this.field.Value).then(recordName => {
|
|
48
|
+
if (recordName && recordName.length > 0)
|
|
49
|
+
this.renderer.setProperty(this.el.nativeElement, 'textContent', recordName);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
LogStatus('no linked entity found for field: ' + this.field.Name);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
onClick(event) {
|
|
59
|
+
event.preventDefault();
|
|
60
|
+
this.router.navigate(['resource', 'record', this._targetRecordID], { queryParams: { Entity: this._targetEntity } });
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
FieldLink.ɵfac = function FieldLink_Factory(t) { return new (t || FieldLink)(i0.ɵɵdirectiveInject(i0.ElementRef), i0.ɵɵdirectiveInject(i0.Renderer2), i0.ɵɵdirectiveInject(i1.ActivatedRoute), i0.ɵɵdirectiveInject(i1.Router)); };
|
|
64
|
+
FieldLink.ɵdir = /*@__PURE__*/ i0.ɵɵdefineDirective({ type: FieldLink, selectors: [["", "mjFieldLink", ""]], hostBindings: function FieldLink_HostBindings(rf, ctx) { if (rf & 1) {
|
|
65
|
+
i0.ɵɵlistener("click", function FieldLink_click_HostBindingHandler($event) { return ctx.onClick($event); });
|
|
66
|
+
} }, inputs: { record: "record", fieldName: "fieldName", replaceText: "replaceText" }, features: [i0.ɵɵInheritDefinitionFeature] });
|
|
67
|
+
(function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(FieldLink, [{
|
|
68
|
+
type: Directive,
|
|
69
|
+
args: [{
|
|
70
|
+
selector: '[mjFieldLink]'
|
|
71
|
+
}]
|
|
72
|
+
}], function () { return [{ type: i0.ElementRef }, { type: i0.Renderer2 }, { type: i1.ActivatedRoute }, { type: i1.Router }]; }, { record: [{
|
|
73
|
+
type: Input,
|
|
74
|
+
args: ['record']
|
|
75
|
+
}], fieldName: [{
|
|
76
|
+
type: Input,
|
|
77
|
+
args: ['fieldName']
|
|
78
|
+
}], replaceText: [{
|
|
79
|
+
type: Input,
|
|
80
|
+
args: ['replaceText']
|
|
81
|
+
}], onClick: [{
|
|
82
|
+
type: HostListener,
|
|
83
|
+
args: ['click', ['$event']]
|
|
84
|
+
}] }); })();
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as i0 from "@angular/core";
|
|
2
|
+
import * as i1 from "./ng-email-link";
|
|
3
|
+
import * as i2 from "./ng-field-link";
|
|
4
|
+
import * as i3 from "./ng-web-link";
|
|
5
|
+
import * as i4 from "@angular/common";
|
|
6
|
+
export declare class LinkDirectivesModule {
|
|
7
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<LinkDirectivesModule, never>;
|
|
8
|
+
static ɵmod: i0.ɵɵNgModuleDeclaration<LinkDirectivesModule, [typeof i1.EmailLink, typeof i2.FieldLink, typeof i3.WebLink], [typeof i4.CommonModule], [typeof i1.EmailLink, typeof i2.FieldLink, typeof i3.WebLink]>;
|
|
9
|
+
static ɵinj: i0.ɵɵInjectorDeclaration<LinkDirectivesModule>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
import * as i0 from "@angular/core";
|
|
7
|
+
export class LinkDirectivesModule {
|
|
8
|
+
}
|
|
9
|
+
LinkDirectivesModule.ɵfac = function LinkDirectivesModule_Factory(t) { return new (t || LinkDirectivesModule)(); };
|
|
10
|
+
LinkDirectivesModule.ɵmod = /*@__PURE__*/ i0.ɵɵdefineNgModule({ type: LinkDirectivesModule });
|
|
11
|
+
LinkDirectivesModule.ɵinj = /*@__PURE__*/ i0.ɵɵdefineInjector({ imports: [CommonModule] });
|
|
12
|
+
(function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(LinkDirectivesModule, [{
|
|
13
|
+
type: NgModule,
|
|
14
|
+
args: [{
|
|
15
|
+
declarations: [
|
|
16
|
+
EmailLink,
|
|
17
|
+
FieldLink,
|
|
18
|
+
WebLink
|
|
19
|
+
],
|
|
20
|
+
imports: [
|
|
21
|
+
CommonModule
|
|
22
|
+
],
|
|
23
|
+
exports: [
|
|
24
|
+
EmailLink,
|
|
25
|
+
FieldLink,
|
|
26
|
+
WebLink
|
|
27
|
+
]
|
|
28
|
+
}]
|
|
29
|
+
}], null, null); })();
|
|
30
|
+
(function () { (typeof ngJitMode === "undefined" || ngJitMode) && i0.ɵɵsetNgModuleScope(LinkDirectivesModule, { declarations: [EmailLink,
|
|
31
|
+
FieldLink,
|
|
32
|
+
WebLink], imports: [CommonModule], exports: [EmailLink,
|
|
33
|
+
FieldLink,
|
|
34
|
+
WebLink] }); })();
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ElementRef, Renderer2, OnInit } from '@angular/core';
|
|
2
|
+
import { EntityField } from '@memberjunction/core';
|
|
3
|
+
import { BaseLink } from './ng-base-link';
|
|
4
|
+
import * as i0 from "@angular/core";
|
|
5
|
+
export declare class WebLink extends BaseLink implements OnInit {
|
|
6
|
+
private el;
|
|
7
|
+
private renderer;
|
|
8
|
+
field: EntityField;
|
|
9
|
+
constructor(el: ElementRef, renderer: Renderer2);
|
|
10
|
+
ngOnInit(): void;
|
|
11
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<WebLink, never>;
|
|
12
|
+
static ɵdir: i0.ɵɵDirectiveDeclaration<WebLink, "[mjWebLink]", never, { "field": "field"; }, {}, never, never, false, never>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Directive, Input } from '@angular/core';
|
|
2
|
+
import { LogError } from '@memberjunction/core';
|
|
3
|
+
import { BaseLink } from './ng-base-link';
|
|
4
|
+
import * as i0 from "@angular/core";
|
|
5
|
+
export class WebLink extends BaseLink {
|
|
6
|
+
constructor(el, renderer) {
|
|
7
|
+
super();
|
|
8
|
+
this.el = el;
|
|
9
|
+
this.renderer = renderer;
|
|
10
|
+
}
|
|
11
|
+
ngOnInit() {
|
|
12
|
+
const extendedType = this.field.EntityFieldInfo.ExtendedType;
|
|
13
|
+
if (extendedType && extendedType.trim().toLowerCase() === 'url')
|
|
14
|
+
this.CreateLink(this.el, this.field, this.renderer, this.field.Value, true);
|
|
15
|
+
else
|
|
16
|
+
LogError('Entity Field must have ExtendedType of URL to use the mjWebLink directive. Field:' + this.field.Name);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
WebLink.ɵfac = function WebLink_Factory(t) { return new (t || WebLink)(i0.ɵɵdirectiveInject(i0.ElementRef), i0.ɵɵdirectiveInject(i0.Renderer2)); };
|
|
20
|
+
WebLink.ɵdir = /*@__PURE__*/ i0.ɵɵdefineDirective({ type: WebLink, selectors: [["", "mjWebLink", ""]], inputs: { field: "field" }, features: [i0.ɵɵInheritDefinitionFeature] });
|
|
21
|
+
(function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(WebLink, [{
|
|
22
|
+
type: Directive,
|
|
23
|
+
args: [{
|
|
24
|
+
selector: '[mjWebLink]'
|
|
25
|
+
}]
|
|
26
|
+
}], function () { return [{ type: i0.ElementRef }, { type: i0.Renderer2 }]; }, { field: [{
|
|
27
|
+
type: Input,
|
|
28
|
+
args: ['field']
|
|
29
|
+
}] }); })();
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* Public API Surface of ng-link-directives
|
|
3
3
|
*/
|
|
4
|
-
|
|
5
4
|
export * from './lib/ng-link-directives.module';
|
|
6
5
|
export * from './lib/ng-base-link';
|
|
7
|
-
export * from './lib/ng-email-link';
|
|
8
|
-
export * from './lib/ng-web-link';
|
|
9
|
-
export * from './lib/ng-field-link';
|
|
6
|
+
export * from './lib/ng-email-link';
|
|
7
|
+
export * from './lib/ng-web-link';
|
|
8
|
+
export * from './lib/ng-field-link';
|
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"
|
|
@@ -27,7 +30,7 @@
|
|
|
27
30
|
},
|
|
28
31
|
"dependencies": {
|
|
29
32
|
"tslib": "^2.3.0",
|
|
30
|
-
"@memberjunction/core": "^0.9.
|
|
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/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
|
-
|