ngx-beacon-notify 1.0.0 → 1.2.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/esm2022/lib/beacon/beacon.component.mjs +142 -0
- package/esm2022/lib/beacon-notify.module.mjs +58 -0
- package/esm2022/lib/beacon-notify.service.mjs +605 -0
- package/esm2022/lib/container/container.component.mjs +71 -0
- package/esm2022/lib/icons/beacon-icon-alert/beacon-icon-alert.component.mjs +11 -0
- package/esm2022/lib/icons/beacon-icon-error/beacon-icon-error.component.mjs +11 -0
- package/esm2022/lib/icons/beacon-icon-info/beacon-icon-info.component.mjs +11 -0
- package/esm2022/lib/icons/beacon-icon-success/beacon-icon-success.component.mjs +11 -0
- package/esm2022/lib/icons/beacon-icon-warning/beacon-icon-warning.component.mjs +11 -0
- package/esm2022/lib/index.mjs +3 -0
- package/esm2022/lib/pipes/beacon-type-resolve.pipe.mjs +39 -0
- package/esm2022/lib/types/constants/index.mjs +6 -0
- package/esm2022/lib/types/index.mjs +3 -0
- package/esm2022/lib/types/interfaces/index.mjs +2 -0
- package/esm2022/ngx-beacon-notify.mjs +5 -0
- package/esm2022/public-api.mjs +9 -0
- package/fesm2022/ngx-beacon-notify.mjs +941 -0
- package/fesm2022/ngx-beacon-notify.mjs.map +1 -0
- package/index.d.ts +5 -1
- package/lib/beacon/beacon.component.d.ts +22 -0
- package/lib/beacon-notify.module.d.ts +18 -0
- package/lib/beacon-notify.service.d.ts +103 -0
- package/lib/container/container.component.d.ts +18 -0
- package/lib/icons/beacon-icon-alert/beacon-icon-alert.component.d.ts +5 -0
- package/lib/icons/beacon-icon-error/beacon-icon-error.component.d.ts +5 -0
- package/lib/icons/beacon-icon-info/beacon-icon-info.component.d.ts +5 -0
- package/lib/icons/beacon-icon-success/beacon-icon-success.component.d.ts +5 -0
- package/lib/icons/beacon-icon-warning/beacon-icon-warning.component.d.ts +5 -0
- package/lib/index.d.ts +2 -0
- package/lib/pipes/beacon-type-resolve.pipe.d.ts +9 -0
- package/lib/types/constants/index.d.ts +6 -0
- package/lib/types/index.d.ts +2 -0
- package/lib/types/interfaces/index.d.ts +99 -0
- package/package.json +35 -6
- package/public-api.d.ts +8 -0
- package/beacon/beacon.component.css +0 -175
- package/beacon/beacon.component.html +0 -46
- package/beacon/beacon.component.spec.ts +0 -21
- package/beacon/beacon.component.ts +0 -142
- package/beacon-notify.module.ts +0 -43
- package/beacon-notify.service.ts +0 -634
- package/container/container.component.css +0 -10
- package/container/container.component.html +0 -3
- package/container/container.component.spec.ts +0 -21
- package/container/container.component.ts +0 -62
- package/icons/beacon-icon-alert/beacon-icon-alert.component.css +0 -6
- package/icons/beacon-icon-alert/beacon-icon-alert.component.html +0 -10
- package/icons/beacon-icon-alert/beacon-icon-alert.component.spec.ts +0 -21
- package/icons/beacon-icon-alert/beacon-icon-alert.component.ts +0 -10
- package/icons/beacon-icon-error/beacon-icon-error.component.css +0 -6
- package/icons/beacon-icon-error/beacon-icon-error.component.html +0 -13
- package/icons/beacon-icon-error/beacon-icon-error.component.spec.ts +0 -21
- package/icons/beacon-icon-error/beacon-icon-error.component.ts +0 -10
- package/icons/beacon-icon-info/beacon-icon-info.component.css +0 -6
- package/icons/beacon-icon-info/beacon-icon-info.component.html +0 -14
- package/icons/beacon-icon-info/beacon-icon-info.component.spec.ts +0 -21
- package/icons/beacon-icon-info/beacon-icon-info.component.ts +0 -10
- package/icons/beacon-icon-success/beacon-icon-success.component.css +0 -6
- package/icons/beacon-icon-success/beacon-icon-success.component.html +0 -13
- package/icons/beacon-icon-success/beacon-icon-success.component.spec.ts +0 -21
- package/icons/beacon-icon-success/beacon-icon-success.component.ts +0 -9
- package/icons/beacon-icon-warning/beacon-icon-warning.component.css +0 -6
- package/icons/beacon-icon-warning/beacon-icon-warning.component.html +0 -15
- package/icons/beacon-icon-warning/beacon-icon-warning.component.spec.ts +0 -21
- package/icons/beacon-icon-warning/beacon-icon-warning.component.ts +0 -10
- package/index.ts +0 -2
- package/pipes/beacon-type-resolve.pipe.spec.ts +0 -8
- package/pipes/beacon-type-resolve.pipe.ts +0 -33
- package/types/constants/index.ts +0 -8
- package/types/index.ts +0 -3
- package/types/interfaces/index.ts +0 -110
package/beacon-notify.service.ts
DELETED
|
@@ -1,634 +0,0 @@
|
|
|
1
|
-
import { Injectable, Inject, ViewChild, EventEmitter, ElementRef } from '@angular/core';
|
|
2
|
-
import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
|
|
3
|
-
import { BeaconNotifyComponent } from './beacon/beacon.component';
|
|
4
|
-
import { Buffer } from 'buffer';
|
|
5
|
-
import {
|
|
6
|
-
IBeaconConfig,
|
|
7
|
-
IBeaconInlineConfig,
|
|
8
|
-
IBeaconGlobalConfig,
|
|
9
|
-
IBeaconType,
|
|
10
|
-
IBeaconPositionConfig,
|
|
11
|
-
IBeaconEvent,
|
|
12
|
-
IBeaconWatchedEvent,
|
|
13
|
-
IBeaconEventMessage,
|
|
14
|
-
IBeaconTypeIcon,
|
|
15
|
-
IBeaconButtonType,
|
|
16
|
-
BEACON_GLOBAL_CONFIG,
|
|
17
|
-
BEACON_OVERLAY_COLOR,
|
|
18
|
-
BEACON_OVERLAY_ID
|
|
19
|
-
} from './types';
|
|
20
|
-
|
|
21
|
-
@Injectable({
|
|
22
|
-
providedIn: 'root'
|
|
23
|
-
})
|
|
24
|
-
export class BeaconNotifyService {
|
|
25
|
-
private beaconDefaultIconKeys = ['a.a', 'a.e', 'a.i', 'a.s', 'a.w']
|
|
26
|
-
private beaconConfigMap: { [key: string]: { [key: string]: string } } = {
|
|
27
|
-
alert: { icon: this.beaconDefaultIconKeys[0], fontIcon: 'false', class: 'beacon-message-alert', title: 'Alert', style: '', animation: '', type: 'alert' },
|
|
28
|
-
error: { icon: this.beaconDefaultIconKeys[1], fontIcon: 'false', class: 'beacon-message-error', title: 'Error', style: '', animation: '', type: 'error' },
|
|
29
|
-
info: { icon: this.beaconDefaultIconKeys[2], fontIcon: 'false', class: 'beacon-message-info', title: 'Information', style: '', animation: '', type: 'info' },
|
|
30
|
-
success: { icon: this.beaconDefaultIconKeys[3], fontIcon: 'false', class: 'beacon-message-success', title: 'Success', style: '', animation: '', type: 'success' },
|
|
31
|
-
warning: { icon: this.beaconDefaultIconKeys[4], fontIcon: 'false', class: 'beacon-message-warning', title: 'Warning', style: '', animation: '', type: 'warning' }
|
|
32
|
-
}
|
|
33
|
-
private beaconTypeMap: { [key: string]: string } = {
|
|
34
|
-
a: 'success', b: 'error', c: 'warning', d: 'info', e: 'alert'
|
|
35
|
-
}
|
|
36
|
-
private beaconTitle?: string
|
|
37
|
-
private beaconMessage?: string
|
|
38
|
-
private beaconIcon?: string
|
|
39
|
-
private beaconManualId?: string
|
|
40
|
-
private beaconSelectedManualId?: string
|
|
41
|
-
private beaconIconFromFont?: true
|
|
42
|
-
private beaconStatic?: true | number
|
|
43
|
-
private beaconFixed?: true
|
|
44
|
-
private beaconBlockOthers?: true
|
|
45
|
-
private beaconPreventClickClose?: true
|
|
46
|
-
private beaconAllowDuplicate?: true
|
|
47
|
-
private beaconFocus?: true
|
|
48
|
-
private beaconFocusShine?: true
|
|
49
|
-
private beaconOverlayColor?: string
|
|
50
|
-
private beaconStyleClass?: string
|
|
51
|
-
private beaconReplacementClass?: string
|
|
52
|
-
private beaconAnimationClass?: string
|
|
53
|
-
private beaconNoHoverEffect?: true
|
|
54
|
-
private beaconGlobalStatic?: true | number
|
|
55
|
-
private beaconGlobalFixed?: true
|
|
56
|
-
private beaconGlobalBlockOthers?: true
|
|
57
|
-
private beaconGlobalPreventClickClose?: true
|
|
58
|
-
private beaconGlobalDuplicate?: boolean
|
|
59
|
-
private beaconGlobalNoHoverEffect?: true
|
|
60
|
-
private beaconGlobalPositioning?: IBeaconPositionConfig
|
|
61
|
-
private beaconGlobalFocusOverlayColor?: string
|
|
62
|
-
private beaconContainer!: ElementRef
|
|
63
|
-
private beaconDefaultAnimationClassName: string = 'beacon-message-control-animate'
|
|
64
|
-
private beaconSuccessorBlockerAutoId?: string
|
|
65
|
-
private beaconWithActiveFocusAutoId?: string
|
|
66
|
-
private beaconButtons: IBeaconButtonType = {}
|
|
67
|
-
private beaconFocusOrderLibrary: Array<string> = []
|
|
68
|
-
private beaconSubscribedEventLibrary: { [key: string]: { [key: string]: string | EventEmitter<IBeaconEvent> } } = {}
|
|
69
|
-
private beaconWatchedEventLibrary: Map<string, string> = new Map<string, string>([])
|
|
70
|
-
private beaconWatchedEventTaskMaster: EventEmitter<IBeaconWatchedEvent> = new EventEmitter<IBeaconWatchedEvent>()
|
|
71
|
-
private beaconAllEventTaskMaster: EventEmitter<IBeaconWatchedEvent> = new EventEmitter<IBeaconWatchedEvent>()
|
|
72
|
-
private beaconFocusOverlayDOM?: HTMLElement
|
|
73
|
-
public beaconEventTaskMaster: EventEmitter<{ [key: string]: boolean| string }> = new EventEmitter<{ [key: string]: boolean | string }>()
|
|
74
|
-
public beaconLibrary: Array<IBeaconConfig> = []
|
|
75
|
-
public beaconLibraryQueue: Array<IBeaconConfig> = []
|
|
76
|
-
|
|
77
|
-
constructor(private sanitizer: DomSanitizer,
|
|
78
|
-
@Inject(BEACON_GLOBAL_CONFIG) private globalConfig?: IBeaconGlobalConfig) {
|
|
79
|
-
this.globalConfig && this.resolveGlobalConfig(this.globalConfig)
|
|
80
|
-
// Resolve events
|
|
81
|
-
this.resolveBeaconEvents()
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// Resolve global config
|
|
85
|
-
private resolveGlobalConfig(globalConfig: IBeaconGlobalConfig): void {
|
|
86
|
-
if (globalConfig.static) {
|
|
87
|
-
if (typeof globalConfig.static == 'boolean') {
|
|
88
|
-
this.beaconGlobalFixed = undefined
|
|
89
|
-
this.beaconGlobalStatic = true
|
|
90
|
-
} else this.beaconGlobalStatic = globalConfig.static
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
if (globalConfig.fixed) {
|
|
94
|
-
this.beaconGlobalStatic = undefined
|
|
95
|
-
this.beaconGlobalFixed = true
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
globalConfig.preventClickClose && (this.beaconGlobalPreventClickClose = globalConfig.preventClickClose)
|
|
99
|
-
globalConfig.blockOthers && (this.beaconGlobalBlockOthers = globalConfig.blockOthers)
|
|
100
|
-
globalConfig.overlayColor && (this.beaconGlobalFocusOverlayColor = globalConfig.overlayColor)
|
|
101
|
-
globalConfig.duplicate && (this.beaconGlobalDuplicate = globalConfig.duplicate)
|
|
102
|
-
globalConfig.icon && this.resolveGlobalIconConfig(globalConfig.icon)
|
|
103
|
-
globalConfig.styleClass && this.resolveGlobalPropertyConfig(globalConfig.styleClass, 'style')
|
|
104
|
-
globalConfig.replacementClass && this.resolveGlobalPropertyConfig(globalConfig.replacementClass, 'class')
|
|
105
|
-
globalConfig.animationClass && this.resolveGlobalPropertyConfig(globalConfig.animationClass, 'animation')
|
|
106
|
-
globalConfig.position && (this.beaconGlobalPositioning = globalConfig.position)
|
|
107
|
-
globalConfig.noHoverEffect && (this.beaconGlobalNoHoverEffect = globalConfig.noHoverEffect)
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// Resolve global config / for property
|
|
111
|
-
private resolveGlobalPropertyConfig(config: IBeaconType, property: string): void {
|
|
112
|
-
config.alert && (this.beaconConfigMap.alert[property] = config.alert)
|
|
113
|
-
config.error && (this.beaconConfigMap.error[property] = config.error)
|
|
114
|
-
config.info && (this.beaconConfigMap.info[property] = config.info)
|
|
115
|
-
config.success && (this.beaconConfigMap.success[property] = config.success)
|
|
116
|
-
config.warning && (this.beaconConfigMap.warning[property] = config.warning)
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// Resolve global config / for icons
|
|
120
|
-
private resolveGlobalIconConfig(config: IBeaconTypeIcon): void {
|
|
121
|
-
config?.alert?.icon && (this.beaconConfigMap.alert.icon = config.alert.icon) && (this.beaconConfigMap.alert.fontIcon = String((config?.alert?.fontIcon || false)))
|
|
122
|
-
config?.error?.icon && (this.beaconConfigMap.error.icon = config.error.icon) && (this.beaconConfigMap.error.fontIcon = String((config?.error?.fontIcon || false)))
|
|
123
|
-
config?.info?.icon && (this.beaconConfigMap.info.icon = config.info.icon) && (this.beaconConfigMap.info.fontIcon = String((config.info.fontIcon || false)))
|
|
124
|
-
config?.success?.icon && (this.beaconConfigMap.success.icon = config.success.icon) && (this.beaconConfigMap.success.fontIcon = String((config.success.fontIcon || false)))
|
|
125
|
-
config?.warning?.icon && (this.beaconConfigMap.warning.icon = config.warning.icon) && (this.beaconConfigMap.warning.fontIcon = String((config.warning.fontIcon || false)))
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
// Resolve beacon events
|
|
129
|
-
private resolveBeaconEvents(): void {
|
|
130
|
-
this.beaconEventTaskMaster.subscribe((message: IBeaconEventMessage) => {
|
|
131
|
-
const id = String(message.id)
|
|
132
|
-
if (message.delete) {
|
|
133
|
-
this.resolvePossibleBlockedBeacons(id)
|
|
134
|
-
this.resolvePossibleQueuedFocus(id)
|
|
135
|
-
this.performEventTask(id, { on: false, off: true })
|
|
136
|
-
delete this.beaconSubscribedEventLibrary[id]
|
|
137
|
-
} else if (message.mount) {
|
|
138
|
-
this.performEventTask(id, { on: true, off: false })
|
|
139
|
-
}
|
|
140
|
-
})
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// Perform event task
|
|
144
|
-
private performEventTask(id: string, eventObject: IBeaconEvent): void {
|
|
145
|
-
const stamp = this.beaconSubscribedEventLibrary[id]
|
|
146
|
-
const event = <EventEmitter<IBeaconEvent>>stamp.event
|
|
147
|
-
const manualId = stamp?.manualId?.toString().replace(/undefined/, '')
|
|
148
|
-
event.emit(eventObject)
|
|
149
|
-
this.beaconAllEventTaskMaster.emit({ id: manualId || null, type: String(stamp.type), ...eventObject })
|
|
150
|
-
|
|
151
|
-
// Check if this manual id is watched
|
|
152
|
-
if (manualId && this.beaconWatchedEventLibrary.has(manualId)) {
|
|
153
|
-
this.beaconWatchedEventTaskMaster.emit({ id: manualId, type: String(stamp.type), ...eventObject })
|
|
154
|
-
// Check if beacon is off
|
|
155
|
-
if (eventObject.off)
|
|
156
|
-
this.beaconWatchedEventLibrary.delete(manualId)
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// Resolve possible blocked beacons
|
|
161
|
-
private resolvePossibleBlockedBeacons(id: string): void {
|
|
162
|
-
// Check if this id is blocking others
|
|
163
|
-
if (id == this.beaconSuccessorBlockerAutoId) {
|
|
164
|
-
if (this.beaconLibraryQueue.length) {
|
|
165
|
-
const queueLength = this.beaconLibraryQueue.length
|
|
166
|
-
// Loop through queue
|
|
167
|
-
for (let x = 0; x < queueLength; x++) {
|
|
168
|
-
const nextInLine = <IBeaconConfig>this.beaconLibraryQueue.shift()
|
|
169
|
-
|
|
170
|
-
// Add message to library
|
|
171
|
-
if (this.getBeaconGlobalPositionConfig?.topBottom == 'top')
|
|
172
|
-
this.beaconLibrary.unshift(nextInLine)
|
|
173
|
-
else this.beaconLibrary.push(nextInLine)
|
|
174
|
-
|
|
175
|
-
// Check if set to block
|
|
176
|
-
if (nextInLine.blockOthers) {
|
|
177
|
-
this.beaconSuccessorBlockerAutoId = nextInLine.bid
|
|
178
|
-
break
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
// Check if no new beacon is set as blocker and unset previous value
|
|
183
|
-
if (id == this.beaconSuccessorBlockerAutoId)
|
|
184
|
-
this.beaconSuccessorBlockerAutoId = undefined
|
|
185
|
-
}
|
|
186
|
-
else this.beaconSuccessorBlockerAutoId = undefined
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
// Resolve queued beacon focus
|
|
191
|
-
private resolvePossibleQueuedFocus(id: string): void {
|
|
192
|
-
// Check if this id is active focus beacon
|
|
193
|
-
if (id == this.beaconWithActiveFocusAutoId) {
|
|
194
|
-
if (this.beaconFocusOrderLibrary.length) {
|
|
195
|
-
// Pass the next focus
|
|
196
|
-
this.beaconWithActiveFocusAutoId = this.beaconFocusOrderLibrary.shift()
|
|
197
|
-
this.beaconEventTaskMaster.emit({ autoDetectNextFocusBeacon: true })
|
|
198
|
-
}
|
|
199
|
-
else {
|
|
200
|
-
this.beaconWithActiveFocusAutoId = undefined
|
|
201
|
-
this.destroyBeaconFocusOverlay()
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
// Generate unique id for item
|
|
207
|
-
private get getId(): string {
|
|
208
|
-
return crypto.getRandomValues(new Uint32Array(2)).toString().split(',').join('')
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
// Set beacon container
|
|
212
|
-
public setBeaconContainer(container: ElementRef): void {
|
|
213
|
-
this.beaconContainer = container
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
// Get beacon container
|
|
217
|
-
public get getBeaconContainer(): ElementRef {
|
|
218
|
-
return this.beaconContainer
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
// Get beacon global position config
|
|
222
|
-
public get getBeaconGlobalPositionConfig(): IBeaconPositionConfig | undefined {
|
|
223
|
-
return this.beaconGlobalPositioning
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
// Get default icon keys
|
|
227
|
-
public get getBeaconDefaultIconKeys(): string[] {
|
|
228
|
-
return this.beaconDefaultIconKeys
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
// Get active focus beacon id
|
|
232
|
-
public get getActiveFocusBeaconId(): string | undefined {
|
|
233
|
-
return this.beaconWithActiveFocusAutoId
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
// Create overlay for focused beacon
|
|
237
|
-
public createBeaconFocusOverlay(overlayColor?: string): void {
|
|
238
|
-
const overlay = document.createElement('div')
|
|
239
|
-
overlay.setAttribute('id', BEACON_OVERLAY_ID)
|
|
240
|
-
overlay.style.position = 'fixed'
|
|
241
|
-
overlay.style.top = '0'
|
|
242
|
-
overlay.style.bottom = '0'
|
|
243
|
-
overlay.style.right = '0'
|
|
244
|
-
overlay.style.left = '0'
|
|
245
|
-
overlay.style.zIndex = '9002'
|
|
246
|
-
overlay.style.background = overlayColor || this.beaconGlobalFocusOverlayColor || BEACON_OVERLAY_COLOR
|
|
247
|
-
document.body.style.overflow = 'hidden'
|
|
248
|
-
|
|
249
|
-
// Pass overlay element
|
|
250
|
-
this.beaconFocusOverlayDOM = overlay
|
|
251
|
-
|
|
252
|
-
this.beaconContainer.nativeElement.appendChild(overlay)
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
// Repaint overlay for focused beacon
|
|
256
|
-
public repaintBeaconFocusOverlay(overlayColor?: string): void {
|
|
257
|
-
if (this.beaconFocusOverlayDOM)
|
|
258
|
-
this.beaconFocusOverlayDOM.style.background = overlayColor || this.beaconGlobalFocusOverlayColor || BEACON_OVERLAY_COLOR
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
// Destroy overlay for focused beacon
|
|
262
|
-
public destroyBeaconFocusOverlay(): void {
|
|
263
|
-
document.body.style.overflow = 'auto'
|
|
264
|
-
this.beaconContainer.nativeElement.querySelector('div#' + BEACON_OVERLAY_ID).remove()
|
|
265
|
-
this.beaconFocusOverlayDOM = undefined
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
// Set id for beacon
|
|
269
|
-
public id(id: string): BeaconNotifyService {
|
|
270
|
-
id && (this.beaconManualId = id)
|
|
271
|
-
return this
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
// Set notification title
|
|
275
|
-
public title(title: string): BeaconNotifyService {
|
|
276
|
-
title && (this.beaconTitle = title)
|
|
277
|
-
return this
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
// Set notification message
|
|
281
|
-
public message(message: string): BeaconNotifyService {
|
|
282
|
-
message && (this.beaconMessage = message)
|
|
283
|
-
return this
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
// Highlight id of beacon to update
|
|
287
|
-
public select(id: string): BeaconNotifyService {
|
|
288
|
-
id && (this.beaconSelectedManualId = id)
|
|
289
|
-
return this
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
// Change notification title
|
|
293
|
-
public setTitle(title: string): void {
|
|
294
|
-
// Check for active manual id / and if a beacon is tied to it
|
|
295
|
-
if (this.beaconSelectedManualId) {
|
|
296
|
-
const beaconIndex = this.beaconLibrary.findIndex(x => x.mid == this.beaconSelectedManualId)
|
|
297
|
-
if (beaconIndex >= 0)
|
|
298
|
-
this.beaconLibrary[beaconIndex].title = title
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
// Change notification message
|
|
303
|
-
public setMessage(message: string): void {
|
|
304
|
-
// Check for active manual id / and if a beacon is tied to it
|
|
305
|
-
if (this.beaconSelectedManualId) {
|
|
306
|
-
const beaconIndex = this.beaconLibrary.findIndex(x => x.mid == this.beaconSelectedManualId)
|
|
307
|
-
if (beaconIndex >= 0)
|
|
308
|
-
this.beaconLibrary[beaconIndex].body = message
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
// Change notification title & message
|
|
313
|
-
public setContent(title: string, message: string): void {
|
|
314
|
-
// Check for active manual id / and if a beacon is tied to it
|
|
315
|
-
if (this.beaconSelectedManualId) {
|
|
316
|
-
const beaconIndex = this.beaconLibrary.findIndex(x => x.mid == this.beaconSelectedManualId)
|
|
317
|
-
if (beaconIndex >= 0)
|
|
318
|
-
this.beaconLibrary[beaconIndex].title = title
|
|
319
|
-
this.beaconLibrary[beaconIndex].body = message
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
// Update beacon button 1
|
|
324
|
-
public setButtonOne(text: string, canDismiss?: boolean | null, callback?: any, callbackArgs?: any[] | null, position?: 'left' | 'center' | 'right'): void {
|
|
325
|
-
// Check for active manual id / and if a beacon is tied to it
|
|
326
|
-
if (this.beaconSelectedManualId) {
|
|
327
|
-
const beaconIndex = this.beaconLibrary.findIndex(x => x.mid == this.beaconSelectedManualId)
|
|
328
|
-
if (beaconIndex >= 0) {
|
|
329
|
-
(<IBeaconButtonType>this.beaconLibrary[beaconIndex].buttons).one = {
|
|
330
|
-
text: text.substring(0, 15),
|
|
331
|
-
canDismiss,
|
|
332
|
-
callback,
|
|
333
|
-
callbackArgs,
|
|
334
|
-
position
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
// Update beacon button 2
|
|
341
|
-
public setButtonTwo(text: string, canDismiss?: boolean | null, callback?: any, callbackArgs?: any[] | null, position?: 'left' | 'center' | 'right'): void {
|
|
342
|
-
// Check for active manual id / and if a beacon is tied to it
|
|
343
|
-
if (this.beaconSelectedManualId) {
|
|
344
|
-
const beaconIndex = this.beaconLibrary.findIndex(x => x.mid == this.beaconSelectedManualId)
|
|
345
|
-
if (beaconIndex >= 0) {
|
|
346
|
-
if (this.beaconLibrary[beaconIndex].buttons?.one) {
|
|
347
|
-
(<IBeaconButtonType>this.beaconLibrary[beaconIndex].buttons).two = {
|
|
348
|
-
text: text.substring(0, 15),
|
|
349
|
-
canDismiss,
|
|
350
|
-
callback,
|
|
351
|
-
callbackArgs,
|
|
352
|
-
position
|
|
353
|
-
}
|
|
354
|
-
} else this.setButtonOne(text, canDismiss, callback, callbackArgs, position)
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
// Set beacon as static or with delay
|
|
360
|
-
public static(delay?: number): BeaconNotifyService {
|
|
361
|
-
this.beaconStatic = delay || true
|
|
362
|
-
this.beaconFixed = undefined
|
|
363
|
-
return this
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
// Set beacon as fixed which removes the close button and disallows close on click
|
|
367
|
-
public fixed(): BeaconNotifyService {
|
|
368
|
-
this.beaconStatic = undefined
|
|
369
|
-
this.beaconFixed = true
|
|
370
|
-
return this
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
// Allow beacon to block others
|
|
374
|
-
public block(): BeaconNotifyService {
|
|
375
|
-
this.beaconBlockOthers = true
|
|
376
|
-
return this
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
// Focus on beacon
|
|
380
|
-
public focus(overlayColor?: string): BeaconNotifyService {
|
|
381
|
-
overlayColor && (this.beaconOverlayColor = overlayColor)
|
|
382
|
-
this.beaconFocus = true
|
|
383
|
-
return this
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
// Focus beacon on center screen
|
|
387
|
-
public shine(overlayColor?: string): BeaconNotifyService {
|
|
388
|
-
overlayColor && (this.beaconOverlayColor = overlayColor)
|
|
389
|
-
this.beaconFocusShine = this.beaconFocus = true
|
|
390
|
-
return this
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
// Add button for beacon
|
|
394
|
-
public button(text: string, canDismiss?: boolean | null, callback?: any, callbackArgs?: any[] | null, position?: 'left' | 'center' | 'right'): BeaconNotifyService {
|
|
395
|
-
if (!this.beaconButtons?.one) {
|
|
396
|
-
this.beaconButtons.one = {
|
|
397
|
-
text: text.substring(0, 15),
|
|
398
|
-
canDismiss,
|
|
399
|
-
callback,
|
|
400
|
-
callbackArgs,
|
|
401
|
-
position
|
|
402
|
-
}
|
|
403
|
-
} else if (this.beaconButtons.one && !this.beaconButtons.two) {
|
|
404
|
-
this.beaconButtons.two = {
|
|
405
|
-
text: text.substring(0, 15),
|
|
406
|
-
canDismiss,
|
|
407
|
-
callback,
|
|
408
|
-
callbackArgs,
|
|
409
|
-
position
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
return this
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
// Allow duplicate for beacon
|
|
417
|
-
public duplicate(): BeaconNotifyService {
|
|
418
|
-
this.beaconAllowDuplicate = true
|
|
419
|
-
return this
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
// Set config values for beacon
|
|
423
|
-
public build(config: IBeaconInlineConfig): BeaconNotifyService {
|
|
424
|
-
if (config.static) {
|
|
425
|
-
if (typeof config.static == 'boolean')
|
|
426
|
-
this.static()
|
|
427
|
-
else this.static(Number(config.static))
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
config.fixed && this.fixed()
|
|
431
|
-
config.duplicate && this.duplicate()
|
|
432
|
-
config.preventClickClose && (this.beaconPreventClickClose = config.preventClickClose)
|
|
433
|
-
config.blockOthers && (this.beaconBlockOthers = config.blockOthers)
|
|
434
|
-
config.focus && (this.beaconFocus = config.focus)
|
|
435
|
-
config.shine && (this.beaconFocusShine = this.beaconFocus = config.shine)
|
|
436
|
-
config.icon && (this.beaconIcon = config.icon)
|
|
437
|
-
config.fontIcon && (this.beaconIconFromFont = config.fontIcon)
|
|
438
|
-
config.styleClass && (this.beaconStyleClass = config.styleClass)
|
|
439
|
-
config.replacementClass && (this.beaconReplacementClass = config.replacementClass)
|
|
440
|
-
config.animationClass && (this.beaconAnimationClass = config.animationClass)
|
|
441
|
-
config.animationClass && (this.beaconAnimationClass = config.animationClass)
|
|
442
|
-
config.overlayColor && (this.beaconOverlayColor = config.overlayColor)
|
|
443
|
-
config.noHoverEffect && (this.beaconNoHoverEffect = config.noHoverEffect)
|
|
444
|
-
return this
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
// create notification beacon
|
|
448
|
-
private beacon(message: string, type: string): EventEmitter<IBeaconEvent> {
|
|
449
|
-
// Get signature
|
|
450
|
-
const signature = Buffer.from((this.beaconTitle || this.beaconConfigMap[type].title) + '.' + message).toString('base64')
|
|
451
|
-
// Generate beacon id
|
|
452
|
-
const beaconId = this.getId
|
|
453
|
-
// Register beacon in event library
|
|
454
|
-
this.beaconSubscribedEventLibrary[beaconId] = Object.create({})
|
|
455
|
-
// Check for duplicate if set to prevent or proceed if turned off
|
|
456
|
-
if (this.beaconAllowDuplicate || (([undefined, false].includes(this.beaconGlobalDuplicate) && this.isNewBeaconADuplicate(signature) == !1) || this.beaconGlobalDuplicate)) {
|
|
457
|
-
const beaconObject: IBeaconConfig = {
|
|
458
|
-
bid: beaconId,
|
|
459
|
-
mid: this.beaconManualId,
|
|
460
|
-
type: this.beaconConfigMap[type].class,
|
|
461
|
-
icon: this.beaconIcon || this.beaconConfigMap[type].icon,
|
|
462
|
-
fontIcon: this.beaconIconFromFont || (this.beaconConfigMap[type].fontIcon == 'true' ? true : undefined),
|
|
463
|
-
title: this.beaconTitle || this.beaconConfigMap[type].title,
|
|
464
|
-
static: this.beaconStatic || this.beaconGlobalStatic,
|
|
465
|
-
fixed: this.beaconFixed || this.beaconGlobalFixed,
|
|
466
|
-
preventClickClose: this.beaconPreventClickClose || this.beaconGlobalPreventClickClose,
|
|
467
|
-
styleClass: this.beaconStyleClass || this.beaconConfigMap[type].style,
|
|
468
|
-
replacementClass: this.beaconReplacementClass,
|
|
469
|
-
animationClass: this.beaconAnimationClass || this.beaconConfigMap[type].animation || this.beaconDefaultAnimationClassName,
|
|
470
|
-
blockOthers: this.beaconBlockOthers || this.beaconGlobalBlockOthers,
|
|
471
|
-
buttons: this.beaconButtons,
|
|
472
|
-
overlayColor: this.beaconOverlayColor,
|
|
473
|
-
bodyHtml: <SafeHtml>this.sanitizer.bypassSecurityTrustHtml(message),
|
|
474
|
-
body: message,
|
|
475
|
-
focus: this.beaconFocus,
|
|
476
|
-
shine: this.beaconFocusShine,
|
|
477
|
-
noHoverEffect: this.beaconNoHoverEffect || this.beaconGlobalNoHoverEffect,
|
|
478
|
-
signature
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
// Sanitize icon if passed
|
|
482
|
-
if (!beaconObject.fontIcon && beaconObject.icon && !this.beaconDefaultIconKeys.includes(beaconObject.icon)) {
|
|
483
|
-
beaconObject.svgIcon = <SafeHtml>this.sanitizer.bypassSecurityTrustHtml(beaconObject.icon)
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
// Check if there is an active beacon blocking others and add build beacon to queue
|
|
487
|
-
if (this.beaconSuccessorBlockerAutoId) {
|
|
488
|
-
this.beaconLibraryQueue.push(beaconObject)
|
|
489
|
-
} else {
|
|
490
|
-
// Check if beacon can block and register id
|
|
491
|
-
if (beaconObject.blockOthers)
|
|
492
|
-
this.beaconSuccessorBlockerAutoId = beaconObject.bid
|
|
493
|
-
|
|
494
|
-
// Add message to library
|
|
495
|
-
if (this.getBeaconGlobalPositionConfig?.topBottom == 'top')
|
|
496
|
-
this.beaconLibrary.unshift(beaconObject)
|
|
497
|
-
else this.beaconLibrary.push(beaconObject)
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
// Check if beacon has focus
|
|
501
|
-
if (this.beaconFocus) {
|
|
502
|
-
if (this.beaconWithActiveFocusAutoId)
|
|
503
|
-
this.beaconFocusOrderLibrary.push(beaconObject.bid)
|
|
504
|
-
else
|
|
505
|
-
this.beaconWithActiveFocusAutoId = beaconObject.bid
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
// Check if id is set and register it
|
|
509
|
-
if (this.beaconManualId) {
|
|
510
|
-
this.beaconSubscribedEventLibrary[beaconId].manualId = this.beaconManualId
|
|
511
|
-
// Map the defined id to the auto-gen id
|
|
512
|
-
this.beaconWatchedEventLibrary.set(this.beaconManualId, beaconId)
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
// Register beacon type
|
|
516
|
-
this.beaconSubscribedEventLibrary[beaconId].type = this.beaconConfigMap[type].type
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
// Register event for beacon
|
|
520
|
-
this.beaconSubscribedEventLibrary[beaconId].event = new EventEmitter<IBeaconEvent>()
|
|
521
|
-
|
|
522
|
-
// Reset
|
|
523
|
-
this.beaconTitle = undefined
|
|
524
|
-
this.beaconMessage = undefined
|
|
525
|
-
this.beaconStatic = undefined
|
|
526
|
-
this.beaconFixed = undefined
|
|
527
|
-
this.beaconBlockOthers = undefined
|
|
528
|
-
this.beaconManualId = undefined
|
|
529
|
-
this.beaconFocus = undefined
|
|
530
|
-
this.beaconFocusShine = undefined
|
|
531
|
-
this.beaconOverlayColor = undefined
|
|
532
|
-
this.beaconAllowDuplicate = undefined
|
|
533
|
-
this.beaconNoHoverEffect = undefined
|
|
534
|
-
this.beaconIcon = undefined
|
|
535
|
-
this.beaconIconFromFont = undefined
|
|
536
|
-
this.beaconStyleClass = undefined
|
|
537
|
-
this.beaconReplacementClass = undefined
|
|
538
|
-
this.beaconAnimationClass = undefined
|
|
539
|
-
this.beaconButtons = {}
|
|
540
|
-
|
|
541
|
-
return <EventEmitter<IBeaconEvent>>this.beaconSubscribedEventLibrary[beaconId].event
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
// Set notification message / success
|
|
545
|
-
public success(...message: string[]): EventEmitter<IBeaconEvent> {
|
|
546
|
-
// Set title
|
|
547
|
-
(message.length > 1) && message[0] && this.title(message[0])
|
|
548
|
-
// Set body
|
|
549
|
-
return this.beacon(message[1] || message[0] || this.beaconMessage || this.beaconConfigMap.success.title, this.beaconTypeMap.a)
|
|
550
|
-
}
|
|
551
|
-
|
|
552
|
-
// Set notification message / error
|
|
553
|
-
public error(...message: string[]): EventEmitter<IBeaconEvent> {
|
|
554
|
-
// Set title
|
|
555
|
-
(message.length > 1) && message[0] && this.title(message[0])
|
|
556
|
-
// Set body
|
|
557
|
-
return this.beacon(message[1] || message[0] || this.beaconMessage || this.beaconConfigMap.error.title, this.beaconTypeMap.b)
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
// Set notification message / warning
|
|
561
|
-
public warning(...message: string[]): EventEmitter<IBeaconEvent> {
|
|
562
|
-
// Set title
|
|
563
|
-
(message.length > 1) && message[0] && this.title(message[0])
|
|
564
|
-
// Set body
|
|
565
|
-
return this.beacon(message[1] || message[0] || this.beaconMessage || this.beaconConfigMap.warning.title, this.beaconTypeMap.c)
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
// Set notification message / info
|
|
569
|
-
public info(...message: string[]): EventEmitter<IBeaconEvent> {
|
|
570
|
-
// Set title
|
|
571
|
-
(message.length > 1) && message[0] && this.title(message[0])
|
|
572
|
-
// Set body
|
|
573
|
-
return this.beacon(message[1] || message[0] || this.beaconMessage || this.beaconConfigMap.info.title, this.beaconTypeMap.d)
|
|
574
|
-
}
|
|
575
|
-
|
|
576
|
-
// Set notification message / alert
|
|
577
|
-
public alert(...message: string[]): EventEmitter<IBeaconEvent> {
|
|
578
|
-
// Set title
|
|
579
|
-
(message.length > 1) && message[0] && this.title(message[0])
|
|
580
|
-
// Set body
|
|
581
|
-
return this.beacon(message[1] || message[0] || this.beaconMessage || this.beaconConfigMap.alert.title, this.beaconTypeMap.e)
|
|
582
|
-
}
|
|
583
|
-
|
|
584
|
-
// Watch events for beacon with specified id
|
|
585
|
-
public watch(id: string | string[]): EventEmitter<IBeaconWatchedEvent> {
|
|
586
|
-
// Register watched id
|
|
587
|
-
if (Array.isArray(id))
|
|
588
|
-
id.forEach(k => this.beaconWatchedEventLibrary.set(k, String()))
|
|
589
|
-
else this.beaconWatchedEventLibrary.set(id, String())
|
|
590
|
-
|
|
591
|
-
return this.beaconWatchedEventTaskMaster
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
// Watch events for all beacons
|
|
595
|
-
public events(): EventEmitter<IBeaconWatchedEvent> {
|
|
596
|
-
return this.beaconAllEventTaskMaster
|
|
597
|
-
}
|
|
598
|
-
|
|
599
|
-
// Close beacon with id
|
|
600
|
-
public closeOne(id: string): void {
|
|
601
|
-
if (this.beaconWatchedEventLibrary.has(id)) {
|
|
602
|
-
const autoId = <string>this.beaconWatchedEventLibrary.get(id)
|
|
603
|
-
|
|
604
|
-
// Remove the beacon
|
|
605
|
-
this.beaconLibrary = this.beaconLibrary.filter(x => {
|
|
606
|
-
return (x.bid != autoId)
|
|
607
|
-
})
|
|
608
|
-
|
|
609
|
-
this.beaconEventTaskMaster.emit({
|
|
610
|
-
delete: true,
|
|
611
|
-
id: autoId
|
|
612
|
-
})
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
// Close all beacons
|
|
617
|
-
public closeAll(): void {
|
|
618
|
-
this.beaconLibrary = this.beaconLibrary.filter(x => {
|
|
619
|
-
this.beaconEventTaskMaster.emit({
|
|
620
|
-
delete: true,
|
|
621
|
-
id: x.bid
|
|
622
|
-
})
|
|
623
|
-
|
|
624
|
-
return !(x.bid)
|
|
625
|
-
})
|
|
626
|
-
}
|
|
627
|
-
|
|
628
|
-
// Check for possible duplicate
|
|
629
|
-
private isNewBeaconADuplicate(signature: string): boolean {
|
|
630
|
-
const duplicate = this.beaconLibrary.find(x => x.signature == signature)
|
|
631
|
-
const beacon = this.beaconContainer.nativeElement.querySelector(`div#bc_${duplicate?.bid}`)
|
|
632
|
-
return Boolean(beacon && window.getComputedStyle(beacon).opacity == '1')
|
|
633
|
-
}
|
|
634
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
|
2
|
-
|
|
3
|
-
import { BeaconNotifyContainerComponent } from './container.component';
|
|
4
|
-
|
|
5
|
-
describe('BeaconNotifyContainerComponent', () => {
|
|
6
|
-
let component: BeaconNotifyContainerComponent;
|
|
7
|
-
let fixture: ComponentFixture<BeaconNotifyContainerComponent>;
|
|
8
|
-
|
|
9
|
-
beforeEach(() => {
|
|
10
|
-
TestBed.configureTestingModule({
|
|
11
|
-
declarations: [BeaconNotifyContainerComponent]
|
|
12
|
-
});
|
|
13
|
-
fixture = TestBed.createComponent(BeaconNotifyContainerComponent);
|
|
14
|
-
component = fixture.componentInstance;
|
|
15
|
-
fixture.detectChanges();
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it('should create', () => {
|
|
19
|
-
expect(component).toBeTruthy();
|
|
20
|
-
});
|
|
21
|
-
});
|