@mosa-ng/core 17.0.0 → 19.0.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/fesm2022/mosa-ng-core.mjs +1448 -0
- package/fesm2022/mosa-ng-core.mjs.map +1 -0
- package/index.d.ts +5 -0
- package/lib/constants/local-storage.constant.d.ts +2 -0
- package/lib/enums/browser.enum.d.ts +9 -0
- package/lib/enums/content-position.enum.d.ts +11 -0
- package/lib/enums/i18n-supported.enum.d.ts +10 -0
- package/lib/enums/theme.enum.d.ts +4 -0
- package/{src/lib/models/api-options.model.ts → lib/models/api-options.model.d.ts} +2 -6
- package/{src/lib/models/dictionary-item.model.ts → lib/models/dictionary-item.model.d.ts} +1 -2
- package/lib/models/key-map.model.d.ts +3 -0
- package/{src/lib/models/logger/log-event.model.ts → lib/models/logger/log-event.model.d.ts} +0 -1
- package/{src/lib/models/logger/log-message-data.model.ts → lib/models/logger/log-message-data.model.d.ts} +0 -1
- package/{src/lib/models/logger/log.model.ts → lib/models/logger/log.model.d.ts} +0 -1
- package/{src/lib/models/logger/logger-config.model.ts → lib/models/logger/logger-config.model.d.ts} +0 -1
- package/{src/lib/models/logger/logger-default-config.model.ts → lib/models/logger/logger-default-config.model.d.ts} +0 -1
- package/lib/models/mosa-duration.model.d.ts +1 -0
- package/{src/lib/models/sieve/sieve-filter.model.ts → lib/models/sieve/sieve-filter.model.d.ts} +0 -1
- package/lib/models/sieve/sieve-operator.model.d.ts +69 -0
- package/{src/lib/models/sieve/sieve-options.model.ts → lib/models/sieve/sieve-options.model.d.ts} +0 -1
- package/{src/lib/mosa-core.module.ts → lib/mosa-core.module.d.ts} +10 -47
- package/lib/pipes/dictionary-item-pipe/dictionary-item-pipe.module.d.ts +8 -0
- package/lib/pipes/dictionary-item-pipe/dictionary-item.pipe.d.ts +8 -0
- package/lib/pipes/find-in-array/find-in-array-pipe.module.d.ts +8 -0
- package/lib/pipes/find-in-array/find-in-array.pipe.d.ts +7 -0
- package/lib/pipes/join/join-pipe.module.d.ts +8 -0
- package/lib/pipes/join/join.pipe.d.ts +13 -0
- package/lib/pipes/mosa-date-pipe/mosa-date-pipe.module.d.ts +8 -0
- package/lib/pipes/mosa-date-pipe/mosa-date.pipe.d.ts +18 -0
- package/lib/pipes/mosa-duration-pipe/mosa-duration-pipe.module.d.ts +8 -0
- package/lib/pipes/mosa-duration-pipe/mosa-duration.pipe.d.ts +27 -0
- package/lib/services/api.service.d.ts +110 -0
- package/lib/services/core-logger.service.d.ts +80 -0
- package/lib/services/guards/can-deactivate.guard.d.ts +11 -0
- package/lib/services/mosa-socket.service.d.ts +11 -0
- package/lib/services/translation/assets-i18n-loader.service.d.ts +16 -0
- package/lib/services/translation/custom-translate-loader.service.d.ts +9 -0
- package/lib/services/translation/translate-collector.service.d.ts +15 -0
- package/lib/utils/commons.util.d.ts +47 -0
- package/lib/utils/dictionary.util.d.ts +70 -0
- package/{src/lib/utils/item.util.ts → lib/utils/item.util.d.ts} +1 -1
- package/lib/utils/promise.util.d.ts +2 -0
- package/lib/utils/prototypes.util.d.ts +80 -0
- package/lib/utils/sieve.util.d.ts +71 -0
- package/{src/lib/utils/size.util.ts → lib/utils/size.util.d.ts} +1 -1
- package/package.json +21 -10
- package/public-api.d.ts +1 -0
- package/.eslintrc.json +0 -31
- package/ng-package.json +0 -10
- package/src/lib/constants/local-storage.constant.ts +0 -4
- package/src/lib/enums/browser.enum.ts +0 -9
- package/src/lib/enums/content-position.enum.ts +0 -11
- package/src/lib/enums/i18n-supported.enum.ts +0 -10
- package/src/lib/enums/theme.enum.ts +0 -4
- package/src/lib/models/key-map.model.ts +0 -3
- package/src/lib/models/mosa-duration.model.ts +0 -1
- package/src/lib/models/sieve/sieve-operator.model.ts +0 -69
- package/src/lib/pipes/dictionary-item-pipe/dictionary-item-pipe.module.ts +0 -15
- package/src/lib/pipes/dictionary-item-pipe/dictionary-item.pipe.ts +0 -14
- package/src/lib/pipes/find-in-array/find-in-array-pipe.module.ts +0 -17
- package/src/lib/pipes/find-in-array/find-in-array.pipe.spec.ts +0 -8
- package/src/lib/pipes/find-in-array/find-in-array.pipe.ts +0 -34
- package/src/lib/pipes/join/join-pipe.module.ts +0 -17
- package/src/lib/pipes/join/join.pipe.spec.ts +0 -8
- package/src/lib/pipes/join/join.pipe.ts +0 -20
- package/src/lib/pipes/mosa-date-pipe/mosa-date-pipe.module.ts +0 -14
- package/src/lib/pipes/mosa-date-pipe/mosa-date.pipe.ts +0 -102
- package/src/lib/pipes/mosa-duration-pipe/mosa-duration-pipe.module.ts +0 -13
- package/src/lib/pipes/mosa-duration-pipe/mosa-duration.pipe.ts +0 -106
- package/src/lib/services/api.service.ts +0 -270
- package/src/lib/services/core-logger.service.ts +0 -219
- package/src/lib/services/guards/can-deactivate.guard.ts +0 -18
- package/src/lib/services/mosa-socket.service.ts +0 -46
- package/src/lib/services/translation/assets-i18n-loader.service.ts +0 -67
- package/src/lib/services/translation/custom-translate-loader.service.ts +0 -27
- package/src/lib/services/translation/translate-collector.service.ts +0 -60
- package/src/lib/utils/commons.util.ts +0 -100
- package/src/lib/utils/dictionary.util.ts +0 -140
- package/src/lib/utils/promise.util.ts +0 -3
- package/src/lib/utils/prototypes.util.ts +0 -167
- package/src/lib/utils/sieve.util.ts +0 -169
- package/src/public-api.ts +0 -1
- package/tsconfig.lib.json +0 -16
- package/tsconfig.lib.prod.json +0 -10
- package/tsconfig.spec.json +0 -14
- /package/{src/lib/models/logger/log-type.model.ts → lib/models/logger/log-type.model.d.ts} +0 -0
- /package/{src/lib/models/logger/logger-base-config.model.ts → lib/models/logger/logger-base-config.model.d.ts} +0 -0
- /package/{src/lib/models/sieve/sieve-response.model.ts → lib/models/sieve/sieve-response.model.d.ts} +0 -0
- /package/{src/lib/models/sieve/sieve-sort.model.ts → lib/models/sieve/sieve-sort.model.d.ts} +0 -0
- /package/{src/lib/models/token-settings.model.ts → lib/models/token-settings.model.d.ts} +0 -0
- /package/{src/lib/models/transform-matrix.model.ts → lib/models/transform-matrix.model.d.ts} +0 -0
|
@@ -0,0 +1,1448 @@
|
|
|
1
|
+
import * as i2 from '@angular/common';
|
|
2
|
+
import { CommonModule, DatePipe } from '@angular/common';
|
|
3
|
+
import * as i0 from '@angular/core';
|
|
4
|
+
import { Injectable, Pipe, NgModule, provideAppInitializer, inject } from '@angular/core';
|
|
5
|
+
import { firstValueFrom, of, BehaviorSubject, throwError, Observable, Subject } from 'rxjs';
|
|
6
|
+
import { share, tap, catchError, map } from 'rxjs/operators';
|
|
7
|
+
import * as i1$1 from '@angular/common/http';
|
|
8
|
+
import { HttpErrorResponse, HttpResponse, HttpHeaders } from '@angular/common/http';
|
|
9
|
+
import * as i1 from '@ngx-translate/core';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Checks if an object is null or undefined. Does not check for
|
|
13
|
+
* empty strings, or false booleans
|
|
14
|
+
* @param val
|
|
15
|
+
*/
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
17
|
+
function isNullOrUndefined(val) {
|
|
18
|
+
return val === null || val === undefined;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Checks if a string is null or empty
|
|
22
|
+
* @param str
|
|
23
|
+
*/
|
|
24
|
+
function isNullOrEmpty(str) {
|
|
25
|
+
return !str?.trim();
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Checks if a string or number is zero or higher
|
|
29
|
+
* @param num
|
|
30
|
+
*/
|
|
31
|
+
function isZeroOrHigher(num) {
|
|
32
|
+
return num !== null && +num >= 0;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Checks if an object is a number
|
|
36
|
+
* @param num
|
|
37
|
+
*/
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
39
|
+
function isNumber(num) {
|
|
40
|
+
return num !== null && !isNaN(+num);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Round to nearest number given
|
|
44
|
+
* @param value
|
|
45
|
+
* @param round
|
|
46
|
+
*/
|
|
47
|
+
function roundNearest(value) {
|
|
48
|
+
return Math.ceil(value / 5) * 5;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Merge a two dimensional array
|
|
52
|
+
* @param array
|
|
53
|
+
*/
|
|
54
|
+
function mergeArray(array) {
|
|
55
|
+
return array.reduce((flat, toFlatten) => flat.concat(Array.isArray(toFlatten) ? mergeArray(toFlatten) : toFlatten), []);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Get CSS Transform matrix from an element
|
|
59
|
+
* @param element
|
|
60
|
+
*/
|
|
61
|
+
function getTransformMatrix(element) {
|
|
62
|
+
const values = element.style.transform.split(/\w+\(|\);?/);
|
|
63
|
+
const transform = values[1].split(/,\s?/g).map((numStr) => parseInt(numStr, 10));
|
|
64
|
+
return {
|
|
65
|
+
x: transform[0],
|
|
66
|
+
y: transform[1],
|
|
67
|
+
z: transform[2],
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Generates a random string with numbers and letters
|
|
72
|
+
* @param length
|
|
73
|
+
*/
|
|
74
|
+
function getRandomString(length = 10) {
|
|
75
|
+
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
76
|
+
let result = '';
|
|
77
|
+
for (let i = 0; i < length; i++) {
|
|
78
|
+
result += characters.charAt(Math.floor(Math.random() * characters.length));
|
|
79
|
+
}
|
|
80
|
+
return result;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Trys to convert a json string. If it fails it returns [null] or a given fallback of [T]
|
|
84
|
+
*/
|
|
85
|
+
function tryJsonParse(data, fallback) {
|
|
86
|
+
try {
|
|
87
|
+
if (!isNullOrEmpty(data)) {
|
|
88
|
+
return JSON.parse(data);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
catch (err) {
|
|
92
|
+
// Ignore - go on with fallback check
|
|
93
|
+
}
|
|
94
|
+
if (fallback) {
|
|
95
|
+
return fallback();
|
|
96
|
+
}
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
var I18nSupported;
|
|
101
|
+
(function (I18nSupported) {
|
|
102
|
+
I18nSupported["enUS"] = "en-US";
|
|
103
|
+
I18nSupported["deDE"] = "de-DE";
|
|
104
|
+
I18nSupported["deCH"] = "de-CH";
|
|
105
|
+
I18nSupported["deAT"] = "de-AT";
|
|
106
|
+
I18nSupported["enGB"] = "en-GB";
|
|
107
|
+
I18nSupported["frFR"] = "fr-FR";
|
|
108
|
+
I18nSupported["esES"] = "es-ES";
|
|
109
|
+
I18nSupported["ptPT"] = "pt-PT";
|
|
110
|
+
})(I18nSupported || (I18nSupported = {}));
|
|
111
|
+
|
|
112
|
+
const MOSA_MERGED_TRANSLATION = (lang) => `mosa_${lang}_merged_${location.host}`;
|
|
113
|
+
const MOSA_FALLBACK_TRANSLATION = `mosa_${I18nSupported.enUS}_merged_${location.host}`;
|
|
114
|
+
|
|
115
|
+
class TranslateCollectorService {
|
|
116
|
+
constructor(myTranslateService) {
|
|
117
|
+
this.myTranslateService = myTranslateService;
|
|
118
|
+
this.translationMap = {};
|
|
119
|
+
}
|
|
120
|
+
addTranslations(translation, lang, priority) {
|
|
121
|
+
if (isNullOrUndefined(this.translationMap[lang])) {
|
|
122
|
+
this.translationMap[lang] = [];
|
|
123
|
+
}
|
|
124
|
+
this.translationMap[lang].push({ priority, translation });
|
|
125
|
+
this.translationMap[lang].sort((a, b) => a.priority - b.priority);
|
|
126
|
+
const merged = JSON.parse(localStorage.getItem(MOSA_MERGED_TRANSLATION(lang))) || {};
|
|
127
|
+
for (const translationsData of this.translationMap[lang]) {
|
|
128
|
+
const translations = translationsData.translation;
|
|
129
|
+
if (translations != null) {
|
|
130
|
+
Object.keys(translations).forEach((key) => void (merged[key] = translations[key]));
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
let trans = true;
|
|
134
|
+
let count = 0;
|
|
135
|
+
while (trans) {
|
|
136
|
+
count++;
|
|
137
|
+
trans = false;
|
|
138
|
+
if (count >= 10) {
|
|
139
|
+
console.warn('Limit reached! Please check translation file! Last replaced values:');
|
|
140
|
+
}
|
|
141
|
+
Object.keys(merged).forEach((key) => {
|
|
142
|
+
if (merged[key].startsWith('@:')) {
|
|
143
|
+
merged[key] = merged[merged[key].substring(2, merged[key].length)];
|
|
144
|
+
trans = count < 10;
|
|
145
|
+
if (count > 10) {
|
|
146
|
+
console.warn(merged[key]);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
localStorage.setItem(MOSA_MERGED_TRANSLATION(lang), JSON.stringify(merged));
|
|
152
|
+
this.myTranslateService.reloadLang(lang);
|
|
153
|
+
}
|
|
154
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: TranslateCollectorService, deps: [{ token: i1.TranslateService }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
155
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: TranslateCollectorService, providedIn: 'root' }); }
|
|
156
|
+
}
|
|
157
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: TranslateCollectorService, decorators: [{
|
|
158
|
+
type: Injectable,
|
|
159
|
+
args: [{
|
|
160
|
+
providedIn: 'root',
|
|
161
|
+
}]
|
|
162
|
+
}], ctorParameters: () => [{ type: i1.TranslateService }] });
|
|
163
|
+
|
|
164
|
+
class AssetsI18nLoaderService {
|
|
165
|
+
constructor(myHttpClient, myTranslateCollectorService) {
|
|
166
|
+
this.myHttpClient = myHttpClient;
|
|
167
|
+
this.myTranslateCollectorService = myTranslateCollectorService;
|
|
168
|
+
this.priority = 0;
|
|
169
|
+
}
|
|
170
|
+
init(path, libName, priority) {
|
|
171
|
+
return new Promise(async (resolve) => {
|
|
172
|
+
if (this.supportedLanguages) {
|
|
173
|
+
for (let i = 0; i < this.supportedLanguages.length; i++) {
|
|
174
|
+
await firstValueFrom(this.loadTranslations(this.supportedLanguages[i], path, libName, priority));
|
|
175
|
+
}
|
|
176
|
+
resolve();
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
if (!this.subLanguages) {
|
|
180
|
+
this.subLanguages = this.myHttpClient.get(`assets/i18n/supported-languages.json?v=${getRandomString()}`)
|
|
181
|
+
.pipe(share());
|
|
182
|
+
}
|
|
183
|
+
this.subLanguages.subscribe(async (res) => {
|
|
184
|
+
this.subLanguages = null;
|
|
185
|
+
this.supportedLanguages = res.languages;
|
|
186
|
+
for (let i = 0; i < this.supportedLanguages.length; i++) {
|
|
187
|
+
await firstValueFrom(this.loadTranslations(this.supportedLanguages[i], path, libName, priority));
|
|
188
|
+
}
|
|
189
|
+
resolve();
|
|
190
|
+
}, () => {
|
|
191
|
+
this.subLanguages = null;
|
|
192
|
+
console.error('Missing file -> assets/i18n/supported-languages.json <-- FIX THIS!');
|
|
193
|
+
resolve();
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
loadTranslations(lang, path, libName, priority) {
|
|
198
|
+
const filename = libName ? `${libName}-${lang}.json` : `${lang}.json`;
|
|
199
|
+
return this.myHttpClient.get(`${(path || './assets/i18n/') + filename}?v=${getRandomString()}`)
|
|
200
|
+
.pipe(tap((response) => this.myTranslateCollectorService.addTranslations(response, lang, priority || this.priority)), catchError(() => {
|
|
201
|
+
console.error(`Missing file -> ${filename} <-- FIX THIS!`);
|
|
202
|
+
return of(null);
|
|
203
|
+
}));
|
|
204
|
+
}
|
|
205
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: AssetsI18nLoaderService, deps: [{ token: i1$1.HttpClient }, { token: TranslateCollectorService }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
206
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: AssetsI18nLoaderService, providedIn: 'root' }); }
|
|
207
|
+
}
|
|
208
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: AssetsI18nLoaderService, decorators: [{
|
|
209
|
+
type: Injectable,
|
|
210
|
+
args: [{
|
|
211
|
+
providedIn: 'root',
|
|
212
|
+
}]
|
|
213
|
+
}], ctorParameters: () => [{ type: i1$1.HttpClient }, { type: TranslateCollectorService }] });
|
|
214
|
+
|
|
215
|
+
class CoreLoggerService {
|
|
216
|
+
/**
|
|
217
|
+
* Default constructor
|
|
218
|
+
*/
|
|
219
|
+
constructor() {
|
|
220
|
+
this.uiLogs$ = new BehaviorSubject(null);
|
|
221
|
+
}
|
|
222
|
+
subUiLogs() {
|
|
223
|
+
return this.uiLogs$.asObservable();
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Gets the error message from any type of object
|
|
227
|
+
*/
|
|
228
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
229
|
+
getErrorMsg(err) {
|
|
230
|
+
let msg = 'Unknown Error';
|
|
231
|
+
if (!err) {
|
|
232
|
+
return msg;
|
|
233
|
+
}
|
|
234
|
+
if (err instanceof HttpErrorResponse) {
|
|
235
|
+
if (typeof err.error !== 'string') {
|
|
236
|
+
return `mosa.commons.errors.status[${err.status}].message`;
|
|
237
|
+
}
|
|
238
|
+
return err.error;
|
|
239
|
+
}
|
|
240
|
+
if (typeof err === 'string') {
|
|
241
|
+
msg = err;
|
|
242
|
+
}
|
|
243
|
+
else if (err.msg) {
|
|
244
|
+
msg = err.msg;
|
|
245
|
+
}
|
|
246
|
+
else if (err.error?.msg) {
|
|
247
|
+
msg = err.error.msg;
|
|
248
|
+
}
|
|
249
|
+
else if (err.error?.message) {
|
|
250
|
+
msg = err.error.message;
|
|
251
|
+
}
|
|
252
|
+
else if (err.error?.errors && err.error?.errors[0]?.message) {
|
|
253
|
+
msg = err.error.errors[0].message;
|
|
254
|
+
}
|
|
255
|
+
else if (err.message) {
|
|
256
|
+
msg = err.message;
|
|
257
|
+
}
|
|
258
|
+
else if (err.Message) {
|
|
259
|
+
msg = err.Message;
|
|
260
|
+
}
|
|
261
|
+
if (typeof err.error === 'string') {
|
|
262
|
+
msg = err.error;
|
|
263
|
+
}
|
|
264
|
+
return msg;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Get the title to be shown in logger toast
|
|
268
|
+
* @param err
|
|
269
|
+
*/
|
|
270
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
271
|
+
getErrorTitle(err) {
|
|
272
|
+
let title = 'mosa.commons.logs.error.label';
|
|
273
|
+
if (err?.label) {
|
|
274
|
+
title = err.label;
|
|
275
|
+
}
|
|
276
|
+
else if (err?.title) {
|
|
277
|
+
title = err.title;
|
|
278
|
+
}
|
|
279
|
+
else if (err?.error?.label) {
|
|
280
|
+
title = err.error.label;
|
|
281
|
+
}
|
|
282
|
+
else if (err?.error?.title) {
|
|
283
|
+
title = err.error.title;
|
|
284
|
+
}
|
|
285
|
+
return title;
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Logs an error to the user
|
|
289
|
+
* @param data
|
|
290
|
+
* @param showUser
|
|
291
|
+
* @param config
|
|
292
|
+
*/
|
|
293
|
+
logError(config) {
|
|
294
|
+
config = this.serializeConfig(config);
|
|
295
|
+
config.msg = this.getErrorMsg(config.msg);
|
|
296
|
+
if (!config.title) {
|
|
297
|
+
config.title = this.getErrorTitle(config.msg);
|
|
298
|
+
}
|
|
299
|
+
config.className = 'snackbar-error';
|
|
300
|
+
this.show(config, 'error');
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Logs a success message to the user
|
|
304
|
+
* @param data
|
|
305
|
+
* @param config
|
|
306
|
+
*/
|
|
307
|
+
logSuccess(config) {
|
|
308
|
+
config = this.serializeConfig(config);
|
|
309
|
+
config.className = 'snackbar-success';
|
|
310
|
+
this.show(config, 'success');
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Logs a warning to the user
|
|
314
|
+
* @param data
|
|
315
|
+
* @param showUser
|
|
316
|
+
* @param config
|
|
317
|
+
*/
|
|
318
|
+
logWarning(config) {
|
|
319
|
+
config = this.serializeConfig(config);
|
|
320
|
+
config.className = 'snackbar-warning';
|
|
321
|
+
this.show(config, 'warning');
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Logs an info to the user
|
|
325
|
+
* @param data
|
|
326
|
+
* @param config
|
|
327
|
+
*/
|
|
328
|
+
logInfo(config) {
|
|
329
|
+
config = this.serializeConfig(config);
|
|
330
|
+
config.className = 'snackbar-info';
|
|
331
|
+
this.show(config, 'info');
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Logs any kind of message to the user
|
|
335
|
+
* @param data
|
|
336
|
+
* @param config
|
|
337
|
+
*/
|
|
338
|
+
log(config) {
|
|
339
|
+
config = this.serializeConfig(config);
|
|
340
|
+
config.className = 'snackbar-default';
|
|
341
|
+
this.show(config, 'default');
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Show the log
|
|
345
|
+
* @requires @mosa-ng/material
|
|
346
|
+
* @param data
|
|
347
|
+
* @param type
|
|
348
|
+
* @param config
|
|
349
|
+
*/
|
|
350
|
+
show(config, type) {
|
|
351
|
+
this.uiLogs$.next({ title: config.title, msg: config.msg, type, config });
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* Serializes empty values, so no error is being returned
|
|
355
|
+
* @param config
|
|
356
|
+
* @private
|
|
357
|
+
*/
|
|
358
|
+
serializeConfig(config) {
|
|
359
|
+
// Check if user has default config
|
|
360
|
+
if (!this.defaultConfig) {
|
|
361
|
+
this.defaultConfig = {
|
|
362
|
+
debug: true,
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
if (!config) {
|
|
366
|
+
// Get user default config
|
|
367
|
+
config = {
|
|
368
|
+
showDismiss: this.defaultConfig.showDismiss,
|
|
369
|
+
closeOnClick: isNullOrUndefined(this.defaultConfig.closeOnClick) ? true : this.defaultConfig.closeOnClick,
|
|
370
|
+
className: this.defaultConfig.className,
|
|
371
|
+
duration: this.defaultConfig.duration || 4,
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
// Serialize configuration
|
|
375
|
+
config.duration = CoreLoggerService.getValue(config.duration, this.defaultConfig.duration, 4);
|
|
376
|
+
config.className = CoreLoggerService.getValue(config.className, this.defaultConfig.className, null);
|
|
377
|
+
config.showDismiss = CoreLoggerService.getValue(config.showDismiss, this.defaultConfig.showDismiss, false);
|
|
378
|
+
config.closeOnClick = CoreLoggerService.getValue(config.closeOnClick, this.defaultConfig.closeOnClick, true);
|
|
379
|
+
return config;
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Gets a value which is not undefined or null
|
|
383
|
+
* @param val
|
|
384
|
+
* @param val1
|
|
385
|
+
* @param def
|
|
386
|
+
* @private
|
|
387
|
+
*/
|
|
388
|
+
static getValue(val, val1, def) {
|
|
389
|
+
if (isNullOrUndefined(val)) {
|
|
390
|
+
if (isNullOrUndefined(val1)) {
|
|
391
|
+
return def;
|
|
392
|
+
}
|
|
393
|
+
return val1;
|
|
394
|
+
}
|
|
395
|
+
return val;
|
|
396
|
+
}
|
|
397
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: CoreLoggerService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
398
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: CoreLoggerService, providedIn: 'root' }); }
|
|
399
|
+
}
|
|
400
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: CoreLoggerService, decorators: [{
|
|
401
|
+
type: Injectable,
|
|
402
|
+
args: [{
|
|
403
|
+
providedIn: 'root',
|
|
404
|
+
}]
|
|
405
|
+
}], ctorParameters: () => [] });
|
|
406
|
+
|
|
407
|
+
const LOCAL_STORAGE_TOKEN_KEY = 'tokenSettings';
|
|
408
|
+
class ApiService {
|
|
409
|
+
constructor(myCoreLoggerService, myHttpClient) {
|
|
410
|
+
this.myCoreLoggerService = myCoreLoggerService;
|
|
411
|
+
this.myHttpClient = myHttpClient;
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* Gets an access token
|
|
415
|
+
* @deprecated use getToken()
|
|
416
|
+
*/
|
|
417
|
+
getAccessToken() {
|
|
418
|
+
return window.localStorage.getItem('jwtAccessToken');
|
|
419
|
+
}
|
|
420
|
+
/**
|
|
421
|
+
* Sets an access token
|
|
422
|
+
* @param token
|
|
423
|
+
* @deprecated use setToken()
|
|
424
|
+
*/
|
|
425
|
+
setAccessToken(token) {
|
|
426
|
+
window.localStorage.setItem('jwtAccessToken', token);
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* Removes an access token from local storage
|
|
430
|
+
* @deprecated use deleteAccessToken()
|
|
431
|
+
*/
|
|
432
|
+
removeAccessToken() {
|
|
433
|
+
window.localStorage.removeItem('jwtAccessToken');
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* Sets the token
|
|
437
|
+
* @param tokenSettings
|
|
438
|
+
*/
|
|
439
|
+
setToken(tokenSettings) {
|
|
440
|
+
window.localStorage.setItem(LOCAL_STORAGE_TOKEN_KEY, JSON.stringify(tokenSettings));
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Gets token
|
|
444
|
+
*/
|
|
445
|
+
getToken() {
|
|
446
|
+
const tokenSettings = window.localStorage.getItem(LOCAL_STORAGE_TOKEN_KEY);
|
|
447
|
+
if (isNullOrEmpty(tokenSettings)) {
|
|
448
|
+
return null;
|
|
449
|
+
}
|
|
450
|
+
return JSON.parse(tokenSettings);
|
|
451
|
+
}
|
|
452
|
+
/**
|
|
453
|
+
* Deletes token
|
|
454
|
+
*/
|
|
455
|
+
deleteToken() {
|
|
456
|
+
window.localStorage.removeItem(LOCAL_STORAGE_TOKEN_KEY);
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* Makes an http get call
|
|
460
|
+
* @param url
|
|
461
|
+
* @param headers
|
|
462
|
+
* @param options
|
|
463
|
+
*/
|
|
464
|
+
get(url, headers, options) {
|
|
465
|
+
options = ApiService.serializeOptions(options);
|
|
466
|
+
headers = this.getHeaders(headers, options);
|
|
467
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
468
|
+
return this.myHttpClient.get(url, { ...options.httpOptions, headers })
|
|
469
|
+
.pipe(map((response) => this.handleResponse(response)), catchError((err) => this.handleError(err, options)));
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* Makes an async http get call, which also includes the response headers
|
|
473
|
+
* @param url
|
|
474
|
+
* @param headers
|
|
475
|
+
* @param options
|
|
476
|
+
*/
|
|
477
|
+
async getWithHeadersAsync(url, headers, options) {
|
|
478
|
+
return this.getWithHeaders(url, headers, options).toPromise();
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
481
|
+
* Makes an http get call, which also includes the response headers
|
|
482
|
+
* @param url
|
|
483
|
+
* @param headers
|
|
484
|
+
* @param options
|
|
485
|
+
*/
|
|
486
|
+
getWithHeaders(url, headers, options) {
|
|
487
|
+
options = ApiService.serializeOptions(options);
|
|
488
|
+
headers = this.getHeaders(headers, options);
|
|
489
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
490
|
+
return this.myHttpClient.get(url, { ...options.httpOptions, headers, observe: 'response' })
|
|
491
|
+
.pipe(catchError((err) => this.handleError(err, options)));
|
|
492
|
+
}
|
|
493
|
+
/**
|
|
494
|
+
* Makes an http patch call (For partial updates)
|
|
495
|
+
* @param url
|
|
496
|
+
* @param data
|
|
497
|
+
* @param headers
|
|
498
|
+
* @param options
|
|
499
|
+
*/
|
|
500
|
+
patch(url, data, headers, options) {
|
|
501
|
+
options = ApiService.serializeOptions(options);
|
|
502
|
+
headers = this.getHeaders(headers, options);
|
|
503
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
504
|
+
return this.myHttpClient.patch(url, data, { ...options.httpOptions, headers })
|
|
505
|
+
.pipe(map((response) => this.handleResponse(response)), catchError((err) => this.handleError(err, options)));
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* Makes an http put call
|
|
509
|
+
* @param url
|
|
510
|
+
* @param data
|
|
511
|
+
* @param headers
|
|
512
|
+
* @param options
|
|
513
|
+
*/
|
|
514
|
+
put(url, data, headers, options) {
|
|
515
|
+
options = ApiService.serializeOptions(options);
|
|
516
|
+
headers = this.getHeaders(headers, options);
|
|
517
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
518
|
+
return this.myHttpClient.put(url, data, { ...options.httpOptions, headers })
|
|
519
|
+
.pipe(map((response) => this.handleResponse(response)), catchError((err) => this.handleError(err, options)));
|
|
520
|
+
}
|
|
521
|
+
/**
|
|
522
|
+
* Makes an http post call
|
|
523
|
+
* @param url
|
|
524
|
+
* @param data
|
|
525
|
+
* @param headers
|
|
526
|
+
* @param options
|
|
527
|
+
*/
|
|
528
|
+
post(url, data, headers, options) {
|
|
529
|
+
options = ApiService.serializeOptions(options);
|
|
530
|
+
headers = this.getHeaders(headers, options);
|
|
531
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
532
|
+
return this.myHttpClient.post(url, data, { ...options.httpOptions, headers })
|
|
533
|
+
.pipe(map((response) => this.handleResponse(response)), catchError((err) => this.handleError(err, options)));
|
|
534
|
+
}
|
|
535
|
+
/**
|
|
536
|
+
* makes an http delete call
|
|
537
|
+
* @param url
|
|
538
|
+
* @param headers
|
|
539
|
+
* @param options
|
|
540
|
+
* @returns Observable
|
|
541
|
+
*/
|
|
542
|
+
delete(url, headers, options) {
|
|
543
|
+
options = ApiService.serializeOptions(options);
|
|
544
|
+
headers = this.getHeaders(headers, options);
|
|
545
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
546
|
+
return this.myHttpClient.delete(url, { ...options.httpOptions, headers })
|
|
547
|
+
.pipe(catchError((err) => this.handleError(err, options)));
|
|
548
|
+
}
|
|
549
|
+
/**
|
|
550
|
+
* Appends a script to the html body
|
|
551
|
+
* @param path
|
|
552
|
+
* @param attributes
|
|
553
|
+
* @param onLoad
|
|
554
|
+
*/
|
|
555
|
+
loadExternalScript(path, attributes,
|
|
556
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
557
|
+
onLoad) {
|
|
558
|
+
const script = document.createElement('script');
|
|
559
|
+
script.type = 'text/javascript';
|
|
560
|
+
script.src = path;
|
|
561
|
+
script.async = true;
|
|
562
|
+
if (onLoad) {
|
|
563
|
+
script.onload = onLoad;
|
|
564
|
+
}
|
|
565
|
+
if (attributes) {
|
|
566
|
+
for (const attribute of attributes) {
|
|
567
|
+
script.setAttribute(attribute.key, attribute.value);
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
document.body.append(script);
|
|
571
|
+
}
|
|
572
|
+
handleError(err, options) {
|
|
573
|
+
if (!options?.skipErrorHandling) {
|
|
574
|
+
this.myCoreLoggerService.logError({ msg: err });
|
|
575
|
+
}
|
|
576
|
+
return throwError(err);
|
|
577
|
+
}
|
|
578
|
+
handleResponse(response) {
|
|
579
|
+
if (response instanceof HttpResponse) {
|
|
580
|
+
return response.body;
|
|
581
|
+
}
|
|
582
|
+
return response;
|
|
583
|
+
}
|
|
584
|
+
getHeaders(headers, options) {
|
|
585
|
+
if (!headers) {
|
|
586
|
+
headers = new HttpHeaders();
|
|
587
|
+
}
|
|
588
|
+
if (!options.skipContentType) {
|
|
589
|
+
if (!headers.get('Content-Type')) {
|
|
590
|
+
headers = headers.set('Content-Type', 'application/json');
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
if (!options?.skipAuth) {
|
|
594
|
+
if (this.getToken()) {
|
|
595
|
+
const tokenSettings = this.getToken();
|
|
596
|
+
headers = headers.set('Authorization', `${tokenSettings.tokenType} ${tokenSettings.token}`);
|
|
597
|
+
}
|
|
598
|
+
else {
|
|
599
|
+
// Deprecated. Use ITokenSettings
|
|
600
|
+
headers = headers.set('Authorization', `Bearer ${this.getAccessToken()}`);
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
return headers;
|
|
604
|
+
}
|
|
605
|
+
static serializeOptions(options) {
|
|
606
|
+
if (!options) {
|
|
607
|
+
options = {};
|
|
608
|
+
}
|
|
609
|
+
if (!options.httpOptions) {
|
|
610
|
+
options.httpOptions = {};
|
|
611
|
+
}
|
|
612
|
+
return options;
|
|
613
|
+
}
|
|
614
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: ApiService, deps: [{ token: CoreLoggerService }, { token: i1$1.HttpClient }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
615
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: ApiService, providedIn: 'root' }); }
|
|
616
|
+
}
|
|
617
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: ApiService, decorators: [{
|
|
618
|
+
type: Injectable,
|
|
619
|
+
args: [{
|
|
620
|
+
providedIn: 'root',
|
|
621
|
+
}]
|
|
622
|
+
}], ctorParameters: () => [{ type: CoreLoggerService }, { type: i1$1.HttpClient }] });
|
|
623
|
+
|
|
624
|
+
class MosaSocketService {
|
|
625
|
+
constructor() {
|
|
626
|
+
}
|
|
627
|
+
connect(url) {
|
|
628
|
+
if (!this.subject) {
|
|
629
|
+
this.subject = this.create(url);
|
|
630
|
+
}
|
|
631
|
+
return this.subject;
|
|
632
|
+
}
|
|
633
|
+
send(data) {
|
|
634
|
+
this.subject.next(data);
|
|
635
|
+
}
|
|
636
|
+
create(url) {
|
|
637
|
+
const ws = new WebSocket(url);
|
|
638
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
639
|
+
const observable = new Observable((obs) => {
|
|
640
|
+
ws.onmessage = obs.next.bind(obs);
|
|
641
|
+
ws.onerror = obs.error.bind(obs);
|
|
642
|
+
ws.onclose = obs.complete.bind(obs);
|
|
643
|
+
return ws.close.bind(ws);
|
|
644
|
+
});
|
|
645
|
+
const observer = {
|
|
646
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
647
|
+
next: (data) => {
|
|
648
|
+
if (ws.readyState === WebSocket.OPEN) {
|
|
649
|
+
ws.send(JSON.stringify(data));
|
|
650
|
+
}
|
|
651
|
+
},
|
|
652
|
+
};
|
|
653
|
+
return Subject.create(observer, observable);
|
|
654
|
+
}
|
|
655
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: MosaSocketService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
656
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: MosaSocketService, providedIn: 'root' }); }
|
|
657
|
+
}
|
|
658
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: MosaSocketService, decorators: [{
|
|
659
|
+
type: Injectable,
|
|
660
|
+
args: [{
|
|
661
|
+
providedIn: 'root',
|
|
662
|
+
}]
|
|
663
|
+
}], ctorParameters: () => [] });
|
|
664
|
+
|
|
665
|
+
class CustomTranslateLoaderService {
|
|
666
|
+
getTranslation(lang) {
|
|
667
|
+
return new Observable((observer) => {
|
|
668
|
+
const item = localStorage.getItem(MOSA_MERGED_TRANSLATION(lang));
|
|
669
|
+
const responseObj = tryJsonParse(item, () => this.loadFallbackLanguage());
|
|
670
|
+
observer.next(responseObj);
|
|
671
|
+
observer.complete();
|
|
672
|
+
});
|
|
673
|
+
}
|
|
674
|
+
loadFallbackLanguage() {
|
|
675
|
+
const defaultTranslation = localStorage.getItem(MOSA_FALLBACK_TRANSLATION);
|
|
676
|
+
return isNullOrEmpty(defaultTranslation) ? {} : JSON.parse(defaultTranslation);
|
|
677
|
+
}
|
|
678
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: CustomTranslateLoaderService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
679
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: CustomTranslateLoaderService, providedIn: 'root' }); }
|
|
680
|
+
}
|
|
681
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: CustomTranslateLoaderService, decorators: [{
|
|
682
|
+
type: Injectable,
|
|
683
|
+
args: [{
|
|
684
|
+
providedIn: 'root',
|
|
685
|
+
}]
|
|
686
|
+
}] });
|
|
687
|
+
|
|
688
|
+
class CanDeactivateGuard {
|
|
689
|
+
canDeactivate(component) {
|
|
690
|
+
return component.canDeactivate ? component.canDeactivate() : true;
|
|
691
|
+
}
|
|
692
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: CanDeactivateGuard, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
693
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: CanDeactivateGuard, providedIn: 'root' }); }
|
|
694
|
+
}
|
|
695
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: CanDeactivateGuard, decorators: [{
|
|
696
|
+
type: Injectable,
|
|
697
|
+
args: [{
|
|
698
|
+
providedIn: 'root',
|
|
699
|
+
}]
|
|
700
|
+
}] });
|
|
701
|
+
|
|
702
|
+
class Dictionary {
|
|
703
|
+
/**
|
|
704
|
+
* Default constructor.
|
|
705
|
+
* @param data Requires an array of IDictionaryItem with a key and a value
|
|
706
|
+
*/
|
|
707
|
+
constructor(...data) {
|
|
708
|
+
this.dictionaryItems$ = new BehaviorSubject(data);
|
|
709
|
+
}
|
|
710
|
+
/**
|
|
711
|
+
* Observable to subscribe to dictionary changes
|
|
712
|
+
*/
|
|
713
|
+
valueChanges() {
|
|
714
|
+
return this.dictionaryItems$.asObservable();
|
|
715
|
+
}
|
|
716
|
+
/**
|
|
717
|
+
* Observable to subscribe to dictionary as object changes
|
|
718
|
+
*/
|
|
719
|
+
objectArray() {
|
|
720
|
+
return this.dictionaryItems$.asObservable()
|
|
721
|
+
.pipe(map((items) => this.toObject(items)));
|
|
722
|
+
}
|
|
723
|
+
/**
|
|
724
|
+
* Gets the items of the dictionary
|
|
725
|
+
* @returns dictionary items
|
|
726
|
+
*/
|
|
727
|
+
get items() {
|
|
728
|
+
return this.dictionaryItems$.value;
|
|
729
|
+
}
|
|
730
|
+
/**
|
|
731
|
+
* Gets a dictionary item by key
|
|
732
|
+
* @param key
|
|
733
|
+
* @returns single dictionary item
|
|
734
|
+
*/
|
|
735
|
+
get(key) {
|
|
736
|
+
return this.dictionaryItems$.value.find((item) => item.key === key);
|
|
737
|
+
}
|
|
738
|
+
/**
|
|
739
|
+
* Checks if dictionary contains item
|
|
740
|
+
* @param key
|
|
741
|
+
*/
|
|
742
|
+
contains(key) {
|
|
743
|
+
return this.get(key) != null;
|
|
744
|
+
}
|
|
745
|
+
/**
|
|
746
|
+
* Adds a dictionary item
|
|
747
|
+
* @param key
|
|
748
|
+
* @param value
|
|
749
|
+
*/
|
|
750
|
+
add(key, value) {
|
|
751
|
+
const dictionaryItems = [...this.dictionaryItems$.value];
|
|
752
|
+
dictionaryItems.push({ key, value });
|
|
753
|
+
this.updateItems(dictionaryItems);
|
|
754
|
+
}
|
|
755
|
+
/**
|
|
756
|
+
* Updates a dictionary item
|
|
757
|
+
* @param data
|
|
758
|
+
* @param index
|
|
759
|
+
*/
|
|
760
|
+
update(data, index) {
|
|
761
|
+
const dictionaryItems = [...this.dictionaryItems$.value];
|
|
762
|
+
if (!index) {
|
|
763
|
+
index = this.getIndex(data.key);
|
|
764
|
+
}
|
|
765
|
+
if (index !== -1) {
|
|
766
|
+
dictionaryItems[index] = data;
|
|
767
|
+
}
|
|
768
|
+
else {
|
|
769
|
+
console.warn('Dictionary: Index not found');
|
|
770
|
+
}
|
|
771
|
+
this.updateItems(dictionaryItems);
|
|
772
|
+
}
|
|
773
|
+
/**
|
|
774
|
+
* Gets an index with a specific key
|
|
775
|
+
* @param key
|
|
776
|
+
*/
|
|
777
|
+
getIndex(key) {
|
|
778
|
+
return this.dictionaryItems$.value.findIndex((val) => val.key === key);
|
|
779
|
+
}
|
|
780
|
+
/**
|
|
781
|
+
* Removes an item from the dictionary
|
|
782
|
+
* @param value
|
|
783
|
+
* @param index
|
|
784
|
+
*/
|
|
785
|
+
remove(value, index) {
|
|
786
|
+
const dictionaryItems = [...this.dictionaryItems$.value];
|
|
787
|
+
if (!index) {
|
|
788
|
+
index = this.getIndex(value);
|
|
789
|
+
}
|
|
790
|
+
if (index !== -1) {
|
|
791
|
+
dictionaryItems.splice(index, 1);
|
|
792
|
+
}
|
|
793
|
+
else {
|
|
794
|
+
console.warn('Dictionary: Index not found');
|
|
795
|
+
}
|
|
796
|
+
this.updateItems(dictionaryItems);
|
|
797
|
+
}
|
|
798
|
+
/**
|
|
799
|
+
* Private function to cast array to an object
|
|
800
|
+
* @param items
|
|
801
|
+
* @private
|
|
802
|
+
*/
|
|
803
|
+
toObject(items) {
|
|
804
|
+
const obj = {};
|
|
805
|
+
for (const item of items) {
|
|
806
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
807
|
+
obj[item.key] = item.value;
|
|
808
|
+
}
|
|
809
|
+
return obj;
|
|
810
|
+
}
|
|
811
|
+
/**
|
|
812
|
+
* Private function to update dictionary items
|
|
813
|
+
* @param items
|
|
814
|
+
* @private
|
|
815
|
+
*/
|
|
816
|
+
updateItems(items) {
|
|
817
|
+
this.dictionaryItems$.next(items);
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
/* eslint-disable @typescript-eslint/unbound-method */
|
|
822
|
+
/**
|
|
823
|
+
* Cast any type
|
|
824
|
+
* @param data to be casted
|
|
825
|
+
* @returns casted data
|
|
826
|
+
*/
|
|
827
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any,max-classes-per-file
|
|
828
|
+
function cast(data) {
|
|
829
|
+
return data;
|
|
830
|
+
}
|
|
831
|
+
class StringExtensions {
|
|
832
|
+
getPart(maxChars, appendDot) {
|
|
833
|
+
let newStr = cast(this).replace(/\\n/g, ' ');
|
|
834
|
+
if (newStr.length > maxChars) {
|
|
835
|
+
newStr = newStr.substring(0, maxChars);
|
|
836
|
+
if (appendDot && newStr.length > maxChars - 3) {
|
|
837
|
+
newStr += '...';
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
return newStr;
|
|
841
|
+
}
|
|
842
|
+
fromJSON() {
|
|
843
|
+
let str = cast(this);
|
|
844
|
+
if (typeof this !== 'string') {
|
|
845
|
+
str = JSON.stringify(str);
|
|
846
|
+
}
|
|
847
|
+
try {
|
|
848
|
+
str = JSON.parse(str);
|
|
849
|
+
}
|
|
850
|
+
catch (e) {
|
|
851
|
+
return null;
|
|
852
|
+
}
|
|
853
|
+
if (typeof str === 'object') {
|
|
854
|
+
return str;
|
|
855
|
+
}
|
|
856
|
+
return null;
|
|
857
|
+
}
|
|
858
|
+
toCSSClass() {
|
|
859
|
+
return cast(this)?.replace(/([a-z])([A-Z])/, '$1-$2').toLowerCase();
|
|
860
|
+
}
|
|
861
|
+
toUTC() {
|
|
862
|
+
return `${cast(this)}Z`;
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
class ArrayExtensions {
|
|
866
|
+
hasChanges(data) {
|
|
867
|
+
return JSON.stringify(this) !== JSON.stringify(data);
|
|
868
|
+
}
|
|
869
|
+
replaceRange(data, start, end) {
|
|
870
|
+
const array = cast(this);
|
|
871
|
+
let replaceDataIndex = 0;
|
|
872
|
+
for (let i = start; i < end; i++) {
|
|
873
|
+
if (!array[i] && !data[replaceDataIndex]) {
|
|
874
|
+
array.splice(i, 1);
|
|
875
|
+
continue;
|
|
876
|
+
}
|
|
877
|
+
array[i] = data[replaceDataIndex];
|
|
878
|
+
replaceDataIndex++;
|
|
879
|
+
}
|
|
880
|
+
return array;
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
class NumberExtensions {
|
|
884
|
+
between(start, end) {
|
|
885
|
+
const num = cast(this);
|
|
886
|
+
return num >= start && num <= end;
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
class Prototypes {
|
|
890
|
+
/**
|
|
891
|
+
* Initialize prototypes
|
|
892
|
+
*/
|
|
893
|
+
static init() {
|
|
894
|
+
const stringExtensions = new StringExtensions();
|
|
895
|
+
const arrayExtensions = new ArrayExtensions();
|
|
896
|
+
const numberExtensions = new NumberExtensions();
|
|
897
|
+
String.prototype.getPart = stringExtensions.getPart;
|
|
898
|
+
String.prototype.fromJSON = stringExtensions.fromJSON;
|
|
899
|
+
String.prototype.toCSSClass = stringExtensions.toCSSClass;
|
|
900
|
+
String.prototype.toUTC = stringExtensions.toUTC;
|
|
901
|
+
Array.prototype.hasChanges = arrayExtensions.hasChanges;
|
|
902
|
+
Array.prototype.replaceRange = arrayExtensions.replaceRange;
|
|
903
|
+
Number.prototype.between = numberExtensions.between;
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
class Sieve {
|
|
908
|
+
constructor(options) {
|
|
909
|
+
this.options = options;
|
|
910
|
+
this.options.baseUrl = options.baseUrl || '';
|
|
911
|
+
this.options.filters = options.filters || [];
|
|
912
|
+
this.options.sorts = options.sorts || [];
|
|
913
|
+
}
|
|
914
|
+
/**
|
|
915
|
+
* public getter to get page size
|
|
916
|
+
*/
|
|
917
|
+
get pageSize() {
|
|
918
|
+
return this.options.pageSize;
|
|
919
|
+
}
|
|
920
|
+
/**
|
|
921
|
+
* Setter to set page size
|
|
922
|
+
*/
|
|
923
|
+
set pageSize(pageSize) {
|
|
924
|
+
this.options.pageSize = pageSize;
|
|
925
|
+
}
|
|
926
|
+
/**
|
|
927
|
+
* public getter to get page
|
|
928
|
+
*/
|
|
929
|
+
get page() {
|
|
930
|
+
return this.options.page;
|
|
931
|
+
}
|
|
932
|
+
/**
|
|
933
|
+
* Setter to set page
|
|
934
|
+
*/
|
|
935
|
+
set page(page) {
|
|
936
|
+
this.options.page = page;
|
|
937
|
+
}
|
|
938
|
+
/**
|
|
939
|
+
* public getter to get filters
|
|
940
|
+
*/
|
|
941
|
+
get filters() {
|
|
942
|
+
return this.options.filters;
|
|
943
|
+
}
|
|
944
|
+
/**
|
|
945
|
+
* Setter to set filters
|
|
946
|
+
*/
|
|
947
|
+
set filters(filters) {
|
|
948
|
+
this.options.filters = filters;
|
|
949
|
+
}
|
|
950
|
+
/**
|
|
951
|
+
* public getter to get sorts
|
|
952
|
+
*/
|
|
953
|
+
get sorts() {
|
|
954
|
+
return this.options.sorts;
|
|
955
|
+
}
|
|
956
|
+
/**
|
|
957
|
+
* Setter to set sorts
|
|
958
|
+
*/
|
|
959
|
+
set sorts(sorts) {
|
|
960
|
+
this.options.sorts = sorts;
|
|
961
|
+
}
|
|
962
|
+
/**
|
|
963
|
+
* method to add a sort option
|
|
964
|
+
* @param name of the item to sort
|
|
965
|
+
* @param desc sort descending
|
|
966
|
+
*/
|
|
967
|
+
addSort(name, desc) {
|
|
968
|
+
this.options.sorts.push({
|
|
969
|
+
name,
|
|
970
|
+
desc,
|
|
971
|
+
});
|
|
972
|
+
}
|
|
973
|
+
/**
|
|
974
|
+
* method to add a filter option
|
|
975
|
+
* @param key of the item
|
|
976
|
+
* @param operator { SieveOperator }
|
|
977
|
+
* @param value filtered value
|
|
978
|
+
*/
|
|
979
|
+
addFilter(key, operator, value) {
|
|
980
|
+
this.options.filters.push({
|
|
981
|
+
key,
|
|
982
|
+
operator,
|
|
983
|
+
value,
|
|
984
|
+
});
|
|
985
|
+
}
|
|
986
|
+
/**
|
|
987
|
+
* Getter for base url
|
|
988
|
+
*/
|
|
989
|
+
get baseUrl() {
|
|
990
|
+
return this.options.baseUrl;
|
|
991
|
+
}
|
|
992
|
+
/**
|
|
993
|
+
* Setter for base url
|
|
994
|
+
* @param url
|
|
995
|
+
*/
|
|
996
|
+
set baseUrl(url) {
|
|
997
|
+
this.options.baseUrl = url;
|
|
998
|
+
}
|
|
999
|
+
/**
|
|
1000
|
+
* Convert to queried string
|
|
1001
|
+
*/
|
|
1002
|
+
getUrl() {
|
|
1003
|
+
return `${this.options.baseUrl}${this.toQuery()}`;
|
|
1004
|
+
}
|
|
1005
|
+
/**
|
|
1006
|
+
* to Query
|
|
1007
|
+
* @private converts options to actual query
|
|
1008
|
+
*/
|
|
1009
|
+
toQuery() {
|
|
1010
|
+
let query = '?';
|
|
1011
|
+
if (this.page) {
|
|
1012
|
+
query += `page=${this.page}`;
|
|
1013
|
+
}
|
|
1014
|
+
if (this.pageSize) {
|
|
1015
|
+
query += `&pageSize=${this.pageSize}`;
|
|
1016
|
+
}
|
|
1017
|
+
if (this.filters?.length) {
|
|
1018
|
+
let filterQuery = '&filters=';
|
|
1019
|
+
for (const filter of this.filters) {
|
|
1020
|
+
if (filter.value) {
|
|
1021
|
+
filterQuery += `${filter.key}${filter.operator}${filter.value},`;
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
if (filterQuery !== '&filters=') {
|
|
1025
|
+
filterQuery = filterQuery.slice(0, -1);
|
|
1026
|
+
query += filterQuery;
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
if (this.sorts?.length) {
|
|
1030
|
+
let sortQuery = '&sorts=';
|
|
1031
|
+
for (const sort of this.sorts) {
|
|
1032
|
+
sortQuery += `${sort.desc ? '-' : '+'}${sort.name},`;
|
|
1033
|
+
}
|
|
1034
|
+
sortQuery = sortQuery.slice(0, -1);
|
|
1035
|
+
query += sortQuery;
|
|
1036
|
+
}
|
|
1037
|
+
if (query.startsWith('&')) {
|
|
1038
|
+
query = query.slice(1);
|
|
1039
|
+
}
|
|
1040
|
+
return query;
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
var Theme;
|
|
1045
|
+
(function (Theme) {
|
|
1046
|
+
Theme[Theme["light"] = 0] = "light";
|
|
1047
|
+
Theme[Theme["dark"] = 1] = "dark";
|
|
1048
|
+
})(Theme || (Theme = {}));
|
|
1049
|
+
|
|
1050
|
+
var ContentPosition;
|
|
1051
|
+
(function (ContentPosition) {
|
|
1052
|
+
ContentPosition["top"] = "top";
|
|
1053
|
+
ContentPosition["topLeft"] = "top-left";
|
|
1054
|
+
ContentPosition["topRight"] = "top-right";
|
|
1055
|
+
ContentPosition["bottom"] = "bottom";
|
|
1056
|
+
ContentPosition["bottomLeft"] = "bottom-left";
|
|
1057
|
+
ContentPosition["bottomRight"] = "bottom-right";
|
|
1058
|
+
ContentPosition["center"] = "center";
|
|
1059
|
+
ContentPosition["centerLeft"] = "center-left";
|
|
1060
|
+
ContentPosition["centerRight"] = "center-right";
|
|
1061
|
+
})(ContentPosition || (ContentPosition = {}));
|
|
1062
|
+
|
|
1063
|
+
var Browser;
|
|
1064
|
+
(function (Browser) {
|
|
1065
|
+
Browser[Browser["chrome"] = 0] = "chrome";
|
|
1066
|
+
Browser[Browser["firefox"] = 1] = "firefox";
|
|
1067
|
+
Browser[Browser["internetExplorer"] = 2] = "internetExplorer";
|
|
1068
|
+
Browser[Browser["opera"] = 3] = "opera";
|
|
1069
|
+
Browser[Browser["edge"] = 4] = "edge";
|
|
1070
|
+
Browser[Browser["safari"] = 5] = "safari";
|
|
1071
|
+
Browser[Browser["other"] = 6] = "other";
|
|
1072
|
+
})(Browser || (Browser = {}));
|
|
1073
|
+
|
|
1074
|
+
class MosaDatePipe {
|
|
1075
|
+
constructor(myTranslateService, myDatePipe) {
|
|
1076
|
+
this.myTranslateService = myTranslateService;
|
|
1077
|
+
this.myDatePipe = myDatePipe;
|
|
1078
|
+
this.store$ = new BehaviorSubject(null);
|
|
1079
|
+
this.updateTemplates();
|
|
1080
|
+
setInterval(() => {
|
|
1081
|
+
this.store$.next(new Date().getTime());
|
|
1082
|
+
}, 10);
|
|
1083
|
+
this.myTranslateService.onLangChange.subscribe(() => {
|
|
1084
|
+
this.updateTemplates();
|
|
1085
|
+
this.store$.next(new Date().getTime());
|
|
1086
|
+
});
|
|
1087
|
+
}
|
|
1088
|
+
transform(date, mode = 'timeSince') {
|
|
1089
|
+
return this.store$.pipe(map((currentDate) => this.calcDate(currentDate, date, mode)));
|
|
1090
|
+
}
|
|
1091
|
+
calcDate(currentDate, date, mode) {
|
|
1092
|
+
let parsed;
|
|
1093
|
+
if (date instanceof Date) {
|
|
1094
|
+
parsed = new Date(date.toString()).getTime();
|
|
1095
|
+
}
|
|
1096
|
+
else {
|
|
1097
|
+
parsed = new Date(date).getTime();
|
|
1098
|
+
}
|
|
1099
|
+
if (!currentDate) {
|
|
1100
|
+
currentDate = new Date().getTime();
|
|
1101
|
+
}
|
|
1102
|
+
const convertedDate = this.myDatePipe.transform(parsed, 'dd. MMM. yyyy hh:mm aaa');
|
|
1103
|
+
if (mode === 'full' || mode === 'timeSince') {
|
|
1104
|
+
const seconds = ((currentDate - parsed) * .001) >> 0;
|
|
1105
|
+
const minutes = seconds / 60;
|
|
1106
|
+
const hours = minutes / 60;
|
|
1107
|
+
const days = hours / 24;
|
|
1108
|
+
const years = days / 365;
|
|
1109
|
+
const timeSince = this.templates['prefix'] + (seconds < 60 && this.template('seconds', seconds) ||
|
|
1110
|
+
seconds < 120 && this.template('minute', 1) ||
|
|
1111
|
+
minutes < 60 && this.template('minutes', minutes) ||
|
|
1112
|
+
minutes < 120 && this.template('hour', 1) ||
|
|
1113
|
+
hours < 24 && this.template('hours', hours) ||
|
|
1114
|
+
hours < 42 && this.template('day', 1) ||
|
|
1115
|
+
days < 30 && this.template('days', days) ||
|
|
1116
|
+
days < 45 && this.template('month', 1) ||
|
|
1117
|
+
days < 365 && this.template('months', days / 30) ||
|
|
1118
|
+
years < 1.5 && this.template('year', 1) ||
|
|
1119
|
+
this.template('years', years)) + this.templates['prefix'];
|
|
1120
|
+
if (mode === 'timeSince') {
|
|
1121
|
+
return timeSince;
|
|
1122
|
+
}
|
|
1123
|
+
if (mode === 'full') {
|
|
1124
|
+
return `${convertedDate} (${timeSince})`;
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
return convertedDate;
|
|
1128
|
+
}
|
|
1129
|
+
template(key, val) {
|
|
1130
|
+
return this.templates[key] && this.templates[key].replace(/%d/i, String(Math.abs(Math.round(val))));
|
|
1131
|
+
}
|
|
1132
|
+
updateTemplates() {
|
|
1133
|
+
this.templates = {
|
|
1134
|
+
prefix: this.myTranslateService.instant('mosa.pipes.timeSince.prefix'),
|
|
1135
|
+
suffix: this.myTranslateService.instant('mosa.pipes.timeSince.suffix'),
|
|
1136
|
+
seconds: this.myTranslateService.instant('mosa.pipes.timeSince.seconds'),
|
|
1137
|
+
minute: this.myTranslateService.instant('mosa.pipes.timeSince.minute'),
|
|
1138
|
+
minutes: this.myTranslateService.instant('mosa.pipes.timeSince.minutes'),
|
|
1139
|
+
hour: this.myTranslateService.instant('mosa.pipes.timeSince.hour'),
|
|
1140
|
+
hours: this.myTranslateService.instant('mosa.pipes.timeSince.hours'),
|
|
1141
|
+
day: this.myTranslateService.instant('mosa.pipes.timeSince.day'),
|
|
1142
|
+
days: this.myTranslateService.instant('mosa.pipes.timeSince.days'),
|
|
1143
|
+
month: this.myTranslateService.instant('mosa.pipes.timeSince.month'),
|
|
1144
|
+
months: this.myTranslateService.instant('mosa.pipes.timeSince.months'),
|
|
1145
|
+
year: this.myTranslateService.instant('mosa.pipes.timeSince.year'),
|
|
1146
|
+
years: this.myTranslateService.instant('mosa.pipes.timeSince.years'),
|
|
1147
|
+
};
|
|
1148
|
+
}
|
|
1149
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: MosaDatePipe, deps: [{ token: i1.TranslateService }, { token: i2.DatePipe }], target: i0.ɵɵFactoryTarget.Pipe }); }
|
|
1150
|
+
static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "19.0.5", ngImport: i0, type: MosaDatePipe, isStandalone: false, name: "mosaDate" }); }
|
|
1151
|
+
}
|
|
1152
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: MosaDatePipe, decorators: [{
|
|
1153
|
+
type: Pipe,
|
|
1154
|
+
args: [{
|
|
1155
|
+
name: 'mosaDate',
|
|
1156
|
+
standalone: false,
|
|
1157
|
+
}]
|
|
1158
|
+
}], ctorParameters: () => [{ type: i1.TranslateService }, { type: i2.DatePipe }] });
|
|
1159
|
+
|
|
1160
|
+
class MosaDatePipeModule {
|
|
1161
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: MosaDatePipeModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
|
1162
|
+
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "19.0.5", ngImport: i0, type: MosaDatePipeModule, declarations: [MosaDatePipe], imports: [CommonModule], exports: [MosaDatePipe] }); }
|
|
1163
|
+
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: MosaDatePipeModule, providers: [DatePipe], imports: [CommonModule] }); }
|
|
1164
|
+
}
|
|
1165
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: MosaDatePipeModule, decorators: [{
|
|
1166
|
+
type: NgModule,
|
|
1167
|
+
args: [{
|
|
1168
|
+
declarations: [MosaDatePipe],
|
|
1169
|
+
imports: [
|
|
1170
|
+
CommonModule,
|
|
1171
|
+
],
|
|
1172
|
+
exports: [MosaDatePipe],
|
|
1173
|
+
providers: [DatePipe],
|
|
1174
|
+
}]
|
|
1175
|
+
}] });
|
|
1176
|
+
|
|
1177
|
+
class DictionaryItemPipe {
|
|
1178
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1179
|
+
transform(key, dictionary) {
|
|
1180
|
+
return dictionary.get(key)?.value;
|
|
1181
|
+
}
|
|
1182
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: DictionaryItemPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); }
|
|
1183
|
+
static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "19.0.5", ngImport: i0, type: DictionaryItemPipe, isStandalone: false, name: "dictionaryItem" }); }
|
|
1184
|
+
}
|
|
1185
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: DictionaryItemPipe, decorators: [{
|
|
1186
|
+
type: Pipe,
|
|
1187
|
+
args: [{
|
|
1188
|
+
name: 'dictionaryItem',
|
|
1189
|
+
standalone: false,
|
|
1190
|
+
}]
|
|
1191
|
+
}] });
|
|
1192
|
+
|
|
1193
|
+
class DictionaryItemPipeModule {
|
|
1194
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: DictionaryItemPipeModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
|
1195
|
+
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "19.0.5", ngImport: i0, type: DictionaryItemPipeModule, declarations: [DictionaryItemPipe], imports: [CommonModule], exports: [DictionaryItemPipe] }); }
|
|
1196
|
+
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: DictionaryItemPipeModule, imports: [CommonModule] }); }
|
|
1197
|
+
}
|
|
1198
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: DictionaryItemPipeModule, decorators: [{
|
|
1199
|
+
type: NgModule,
|
|
1200
|
+
args: [{
|
|
1201
|
+
declarations: [DictionaryItemPipe],
|
|
1202
|
+
imports: [
|
|
1203
|
+
CommonModule,
|
|
1204
|
+
],
|
|
1205
|
+
exports: [
|
|
1206
|
+
DictionaryItemPipe,
|
|
1207
|
+
],
|
|
1208
|
+
}]
|
|
1209
|
+
}] });
|
|
1210
|
+
|
|
1211
|
+
class MosaDurationPipe {
|
|
1212
|
+
constructor(myTranslateService) {
|
|
1213
|
+
this.myTranslateService = myTranslateService;
|
|
1214
|
+
this.store$ = new BehaviorSubject(new Date().getTime());
|
|
1215
|
+
this.interval = setInterval(() => {
|
|
1216
|
+
this.store$.next(new Date().getTime());
|
|
1217
|
+
}, 1000);
|
|
1218
|
+
this.myTranslateService.onLangChange.subscribe(() => {
|
|
1219
|
+
this.store$.next(new Date().getTime());
|
|
1220
|
+
});
|
|
1221
|
+
}
|
|
1222
|
+
/**
|
|
1223
|
+
* Converts a timestamp to a duration in the given format
|
|
1224
|
+
* @param millis
|
|
1225
|
+
* @param format
|
|
1226
|
+
* @returns
|
|
1227
|
+
* auto: 15000 -> 15 seconds
|
|
1228
|
+
* seconds: 15000 -> 15 seconds
|
|
1229
|
+
* minutes: 60000 -> 1 minute
|
|
1230
|
+
* hours: 7200000 -> 2 hours
|
|
1231
|
+
* days: 172800000 -> 2 days
|
|
1232
|
+
*/
|
|
1233
|
+
transform(millis, format = 'auto') {
|
|
1234
|
+
return this.store$.pipe(map((currentDate) => {
|
|
1235
|
+
if (!millis) {
|
|
1236
|
+
clearInterval(this.interval);
|
|
1237
|
+
return null;
|
|
1238
|
+
}
|
|
1239
|
+
if (millis - currentDate < 0) {
|
|
1240
|
+
clearInterval(this.interval);
|
|
1241
|
+
return null;
|
|
1242
|
+
}
|
|
1243
|
+
return this.calcDuration(currentDate, millis, format);
|
|
1244
|
+
}));
|
|
1245
|
+
}
|
|
1246
|
+
getTranslation(num, format) {
|
|
1247
|
+
if (num === 1) {
|
|
1248
|
+
return `${num.toFixed(0)} ${this.myTranslateService.instant(`mosa.commons.dateTime[${format}].label`)}`;
|
|
1249
|
+
}
|
|
1250
|
+
return `${num.toFixed(0)} ${this.myTranslateService.instant(`mosa.commons.dateTime[${format}].plural.label`)}`;
|
|
1251
|
+
}
|
|
1252
|
+
calcDuration(currentDate, millis, format) {
|
|
1253
|
+
millis = millis - currentDate;
|
|
1254
|
+
const seconds = millis / 1000;
|
|
1255
|
+
if (format === 'seconds') {
|
|
1256
|
+
return this.getTranslation(seconds, 'seconds');
|
|
1257
|
+
}
|
|
1258
|
+
const minutes = seconds / 60;
|
|
1259
|
+
if (format === 'minutes') {
|
|
1260
|
+
return this.getTranslation(minutes, 'minutes');
|
|
1261
|
+
}
|
|
1262
|
+
const hours = minutes / 60;
|
|
1263
|
+
if (format === 'hours') {
|
|
1264
|
+
return this.getTranslation(hours, 'hours');
|
|
1265
|
+
}
|
|
1266
|
+
const days = hours / 24;
|
|
1267
|
+
if (format === 'days') {
|
|
1268
|
+
return this.getTranslation(days, 'days');
|
|
1269
|
+
}
|
|
1270
|
+
if (format === 'auto') {
|
|
1271
|
+
if (seconds < 60) {
|
|
1272
|
+
return this.getTranslation(seconds, 'seconds');
|
|
1273
|
+
}
|
|
1274
|
+
if (minutes < 60) {
|
|
1275
|
+
return this.getTranslation(minutes, 'minutes');
|
|
1276
|
+
}
|
|
1277
|
+
if (hours < 24) {
|
|
1278
|
+
return this.getTranslation(hours, 'hours');
|
|
1279
|
+
}
|
|
1280
|
+
return this.getTranslation(days, 'days');
|
|
1281
|
+
}
|
|
1282
|
+
return null;
|
|
1283
|
+
}
|
|
1284
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: MosaDurationPipe, deps: [{ token: i1.TranslateService }], target: i0.ɵɵFactoryTarget.Pipe }); }
|
|
1285
|
+
static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "19.0.5", ngImport: i0, type: MosaDurationPipe, isStandalone: false, name: "mosaDuration" }); }
|
|
1286
|
+
}
|
|
1287
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: MosaDurationPipe, decorators: [{
|
|
1288
|
+
type: Pipe,
|
|
1289
|
+
args: [{
|
|
1290
|
+
name: 'mosaDuration',
|
|
1291
|
+
standalone: false,
|
|
1292
|
+
}]
|
|
1293
|
+
}], ctorParameters: () => [{ type: i1.TranslateService }] });
|
|
1294
|
+
|
|
1295
|
+
class MosaDurationPipeModule {
|
|
1296
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: MosaDurationPipeModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
|
1297
|
+
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "19.0.5", ngImport: i0, type: MosaDurationPipeModule, declarations: [MosaDurationPipe], imports: [CommonModule], exports: [MosaDurationPipe] }); }
|
|
1298
|
+
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: MosaDurationPipeModule, imports: [CommonModule] }); }
|
|
1299
|
+
}
|
|
1300
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: MosaDurationPipeModule, decorators: [{
|
|
1301
|
+
type: NgModule,
|
|
1302
|
+
args: [{
|
|
1303
|
+
declarations: [MosaDurationPipe],
|
|
1304
|
+
imports: [
|
|
1305
|
+
CommonModule,
|
|
1306
|
+
],
|
|
1307
|
+
exports: [MosaDurationPipe],
|
|
1308
|
+
}]
|
|
1309
|
+
}] });
|
|
1310
|
+
|
|
1311
|
+
class FindInArrayPipe {
|
|
1312
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1313
|
+
transform(searchValue, array, searchKey, returnElements) {
|
|
1314
|
+
// Return if array is empty or null
|
|
1315
|
+
if (!array || !array.length) {
|
|
1316
|
+
return null;
|
|
1317
|
+
}
|
|
1318
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1319
|
+
const foundItem = array.find((val) => (searchKey ? val[searchKey] : val) === searchValue);
|
|
1320
|
+
if (!foundItem) {
|
|
1321
|
+
return null;
|
|
1322
|
+
}
|
|
1323
|
+
// Return whole item
|
|
1324
|
+
if (!returnElements) {
|
|
1325
|
+
return foundItem;
|
|
1326
|
+
}
|
|
1327
|
+
if (returnElements.length === 1) {
|
|
1328
|
+
return foundItem[returnElements[0]];
|
|
1329
|
+
}
|
|
1330
|
+
// Return given values to the keys
|
|
1331
|
+
return returnElements.map((val) => foundItem[val]);
|
|
1332
|
+
}
|
|
1333
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: FindInArrayPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); }
|
|
1334
|
+
static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "19.0.5", ngImport: i0, type: FindInArrayPipe, isStandalone: false, name: "findInArray" }); }
|
|
1335
|
+
}
|
|
1336
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: FindInArrayPipe, decorators: [{
|
|
1337
|
+
type: Pipe,
|
|
1338
|
+
args: [{
|
|
1339
|
+
name: 'findInArray',
|
|
1340
|
+
standalone: false,
|
|
1341
|
+
}]
|
|
1342
|
+
}] });
|
|
1343
|
+
|
|
1344
|
+
class FindInArrayPipeModule {
|
|
1345
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: FindInArrayPipeModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
|
1346
|
+
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "19.0.5", ngImport: i0, type: FindInArrayPipeModule, declarations: [FindInArrayPipe], imports: [CommonModule], exports: [FindInArrayPipe] }); }
|
|
1347
|
+
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: FindInArrayPipeModule, imports: [CommonModule] }); }
|
|
1348
|
+
}
|
|
1349
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: FindInArrayPipeModule, decorators: [{
|
|
1350
|
+
type: NgModule,
|
|
1351
|
+
args: [{
|
|
1352
|
+
declarations: [
|
|
1353
|
+
FindInArrayPipe,
|
|
1354
|
+
],
|
|
1355
|
+
imports: [
|
|
1356
|
+
CommonModule,
|
|
1357
|
+
],
|
|
1358
|
+
exports: [
|
|
1359
|
+
FindInArrayPipe,
|
|
1360
|
+
],
|
|
1361
|
+
}]
|
|
1362
|
+
}] });
|
|
1363
|
+
|
|
1364
|
+
class JoinPipe {
|
|
1365
|
+
/**
|
|
1366
|
+
* Join array by separator
|
|
1367
|
+
* @param array
|
|
1368
|
+
* @param returnField
|
|
1369
|
+
* @param separator
|
|
1370
|
+
*/
|
|
1371
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1372
|
+
transform(array, returnField, separator = ', ') {
|
|
1373
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1374
|
+
return array.map((val) => returnField ? val[returnField] : val).join(separator);
|
|
1375
|
+
}
|
|
1376
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: JoinPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe }); }
|
|
1377
|
+
static { this.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "19.0.5", ngImport: i0, type: JoinPipe, isStandalone: false, name: "join" }); }
|
|
1378
|
+
}
|
|
1379
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: JoinPipe, decorators: [{
|
|
1380
|
+
type: Pipe,
|
|
1381
|
+
args: [{
|
|
1382
|
+
name: 'join',
|
|
1383
|
+
standalone: false,
|
|
1384
|
+
}]
|
|
1385
|
+
}] });
|
|
1386
|
+
|
|
1387
|
+
class JoinPipeModule {
|
|
1388
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: JoinPipeModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
|
1389
|
+
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "19.0.5", ngImport: i0, type: JoinPipeModule, declarations: [JoinPipe], imports: [CommonModule], exports: [JoinPipe] }); }
|
|
1390
|
+
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: JoinPipeModule, imports: [CommonModule] }); }
|
|
1391
|
+
}
|
|
1392
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: JoinPipeModule, decorators: [{
|
|
1393
|
+
type: NgModule,
|
|
1394
|
+
args: [{
|
|
1395
|
+
declarations: [
|
|
1396
|
+
JoinPipe,
|
|
1397
|
+
],
|
|
1398
|
+
exports: [
|
|
1399
|
+
JoinPipe,
|
|
1400
|
+
],
|
|
1401
|
+
imports: [
|
|
1402
|
+
CommonModule,
|
|
1403
|
+
],
|
|
1404
|
+
}]
|
|
1405
|
+
}] });
|
|
1406
|
+
|
|
1407
|
+
function initI18n(i18n) {
|
|
1408
|
+
return () => i18n.init(null, null, 1);
|
|
1409
|
+
}
|
|
1410
|
+
function initI18nCore(i18n) {
|
|
1411
|
+
return () => i18n.init(null, 'mosa');
|
|
1412
|
+
}
|
|
1413
|
+
class MosaCoreModule {
|
|
1414
|
+
static forRoot() {
|
|
1415
|
+
return {
|
|
1416
|
+
ngModule: MosaCoreModule,
|
|
1417
|
+
providers: [
|
|
1418
|
+
provideAppInitializer(() => {
|
|
1419
|
+
const initializerFn = (initI18n)(inject(AssetsI18nLoaderService));
|
|
1420
|
+
return initializerFn();
|
|
1421
|
+
}),
|
|
1422
|
+
provideAppInitializer(() => {
|
|
1423
|
+
const initializerFn = (initI18nCore)(inject(AssetsI18nLoaderService));
|
|
1424
|
+
return initializerFn();
|
|
1425
|
+
}),
|
|
1426
|
+
],
|
|
1427
|
+
};
|
|
1428
|
+
}
|
|
1429
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: MosaCoreModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
|
1430
|
+
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "19.0.5", ngImport: i0, type: MosaCoreModule, imports: [CommonModule] }); }
|
|
1431
|
+
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: MosaCoreModule, imports: [CommonModule] }); }
|
|
1432
|
+
}
|
|
1433
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.5", ngImport: i0, type: MosaCoreModule, decorators: [{
|
|
1434
|
+
type: NgModule,
|
|
1435
|
+
args: [{
|
|
1436
|
+
declarations: [],
|
|
1437
|
+
imports: [
|
|
1438
|
+
CommonModule,
|
|
1439
|
+
],
|
|
1440
|
+
}]
|
|
1441
|
+
}] });
|
|
1442
|
+
|
|
1443
|
+
/**
|
|
1444
|
+
* Generated bundle index. Do not edit.
|
|
1445
|
+
*/
|
|
1446
|
+
|
|
1447
|
+
export { ApiService, ArrayExtensions, AssetsI18nLoaderService, Browser, CanDeactivateGuard, ContentPosition, CoreLoggerService, CustomTranslateLoaderService, Dictionary, DictionaryItemPipe, DictionaryItemPipeModule, FindInArrayPipe, FindInArrayPipeModule, I18nSupported, JoinPipe, JoinPipeModule, LOCAL_STORAGE_TOKEN_KEY, MOSA_FALLBACK_TRANSLATION, MOSA_MERGED_TRANSLATION, MosaCoreModule, MosaDatePipe, MosaDatePipeModule, MosaDurationPipe, MosaDurationPipeModule, MosaSocketService, NumberExtensions, Prototypes, Sieve, StringExtensions, Theme, TranslateCollectorService, cast, getRandomString, getTransformMatrix, initI18n, initI18nCore, isNullOrEmpty, isNullOrUndefined, isNumber, isZeroOrHigher, mergeArray, roundNearest, tryJsonParse };
|
|
1448
|
+
//# sourceMappingURL=mosa-ng-core.mjs.map
|