@stemy/ngx-utils 13.1.3 → 13.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/bundles/stemy-ngx-utils.umd.js +6254 -0
- package/bundles/stemy-ngx-utils.umd.js.map +1 -0
- package/esm2015/ngx-utils/common-types.js +116 -0
- package/esm2015/ngx-utils/components/dynamic-table/dynamic-table.component.js +139 -0
- package/esm2015/ngx-utils/components/pagination-menu/pagination-menu.component.js +96 -0
- package/esm2015/ngx-utils/components/unordered-list/unordered-list.component.js +51 -0
- package/esm2015/ngx-utils/directives/async-method.base.js +54 -0
- package/esm2015/ngx-utils/directives/async-method.directive.js +24 -0
- package/esm2015/ngx-utils/directives/background.directive.js +51 -0
- package/esm2015/ngx-utils/directives/dynamic-table-template.directive.js +19 -0
- package/esm2015/ngx-utils/directives/global-template.directive.js +27 -0
- package/esm2015/ngx-utils/directives/icon.directive.js +59 -0
- package/esm2015/ngx-utils/directives/ngx-template-outlet.directive.js +88 -0
- package/esm2015/ngx-utils/directives/pagination-item.directive.js +33 -0
- package/esm2015/ngx-utils/directives/pagination.directive.js +76 -0
- package/esm2015/ngx-utils/directives/resource-if.directive.js +51 -0
- package/esm2015/ngx-utils/directives/sticky-class.directive.js +35 -0
- package/esm2015/ngx-utils/directives/sticky.directive.js +48 -0
- package/esm2015/ngx-utils/directives/unordered-list-item.directive.js +70 -0
- package/esm2015/ngx-utils/directives/unordered-list-template.directive.js +26 -0
- package/esm2015/ngx-utils/ngx-utils.module.js +244 -0
- package/esm2015/ngx-utils/pipes/chunk.pipe.js +21 -0
- package/esm2015/ngx-utils/pipes/entries.pipe.js +24 -0
- package/esm2015/ngx-utils/pipes/extra-item-properties.pipe.js +27 -0
- package/esm2015/ngx-utils/pipes/filter.pipe.js +38 -0
- package/esm2015/ngx-utils/pipes/find.pipe.js +25 -0
- package/esm2015/ngx-utils/pipes/format-number.pipe.js +19 -0
- package/esm2015/ngx-utils/pipes/get-offset.pipe.js +13 -0
- package/esm2015/ngx-utils/pipes/get-type.pipe.js +12 -0
- package/esm2015/ngx-utils/pipes/global-template.pipe.js +37 -0
- package/esm2015/ngx-utils/pipes/group-by.pipe.js +23 -0
- package/esm2015/ngx-utils/pipes/is-type.pipe.js +12 -0
- package/esm2015/ngx-utils/pipes/join.pipe.js +15 -0
- package/esm2015/ngx-utils/pipes/keys.pipe.js +18 -0
- package/esm2015/ngx-utils/pipes/map.pipe.js +25 -0
- package/esm2015/ngx-utils/pipes/max.pipe.js +22 -0
- package/esm2015/ngx-utils/pipes/min.pipe.js +22 -0
- package/esm2015/ngx-utils/pipes/pop.pipe.js +12 -0
- package/esm2015/ngx-utils/pipes/reduce.pipe.js +26 -0
- package/esm2015/ngx-utils/pipes/remap.pipe.js +28 -0
- package/esm2015/ngx-utils/pipes/replace.pipe.js +12 -0
- package/esm2015/ngx-utils/pipes/reverse.pipe.js +20 -0
- package/esm2015/ngx-utils/pipes/round.pipe.js +19 -0
- package/esm2015/ngx-utils/pipes/safe-html.pipe.js +32 -0
- package/esm2015/ngx-utils/pipes/shift.pipe.js +12 -0
- package/esm2015/ngx-utils/pipes/split.pipe.js +12 -0
- package/esm2015/ngx-utils/pipes/translate.pipe.js +81 -0
- package/esm2015/ngx-utils/pipes/values.pipe.js +18 -0
- package/esm2015/ngx-utils/plugins/resize-event.plugin.js +56 -0
- package/esm2015/ngx-utils/plugins/scroll-event.plugin.js +36 -0
- package/esm2015/ngx-utils/services/acl.service.js +81 -0
- package/esm2015/ngx-utils/services/api.service.js +35 -0
- package/esm2015/ngx-utils/services/auth.service.js +14 -0
- package/esm2015/ngx-utils/services/base-http.client.js +46 -0
- package/esm2015/ngx-utils/services/base-http.service.js +285 -0
- package/esm2015/ngx-utils/services/config.service.js +124 -0
- package/esm2015/ngx-utils/services/error-handler.service.js +49 -0
- package/esm2015/ngx-utils/services/events.service.js +24 -0
- package/esm2015/ngx-utils/services/formatter.service.js +45 -0
- package/esm2015/ngx-utils/services/global-template.service.js +35 -0
- package/esm2015/ngx-utils/services/icon.service.js +24 -0
- package/esm2015/ngx-utils/services/language.service.js +117 -0
- package/esm2015/ngx-utils/services/open-api.service.js +41 -0
- package/esm2015/ngx-utils/services/promise.service.js +52 -0
- package/esm2015/ngx-utils/services/state.service.js +181 -0
- package/esm2015/ngx-utils/services/static-language.service.js +152 -0
- package/esm2015/ngx-utils/services/storage.service.js +48 -0
- package/esm2015/ngx-utils/services/toaster.service.js +29 -0
- package/esm2015/ngx-utils/services/translated-url.serializer.js +70 -0
- package/esm2015/ngx-utils/services/universal.service.js +75 -0
- package/esm2015/ngx-utils/utils/ajax-request-handler.js +40 -0
- package/esm2015/ngx-utils/utils/array.utils.js +107 -0
- package/esm2015/ngx-utils/utils/auth.guard.js +156 -0
- package/esm2015/ngx-utils/utils/canvas.utils.js +388 -0
- package/esm2015/ngx-utils/utils/date.utils.js +28 -0
- package/esm2015/ngx-utils/utils/file-system.js +25 -0
- package/esm2015/ngx-utils/utils/file.utils.js +90 -0
- package/esm2015/ngx-utils/utils/generic-value.js +20 -0
- package/esm2015/ngx-utils/utils/geometry.js +132 -0
- package/esm2015/ngx-utils/utils/initializer.js +20 -0
- package/esm2015/ngx-utils/utils/loader.utils.js +55 -0
- package/esm2015/ngx-utils/utils/math.utils.js +45 -0
- package/esm2015/ngx-utils/utils/object.utils.js +274 -0
- package/esm2015/ngx-utils/utils/observable.utils.js +63 -0
- package/esm2015/ngx-utils/utils/reflect.utils.js +33 -0
- package/esm2015/ngx-utils/utils/set.utils.js +20 -0
- package/esm2015/ngx-utils/utils/string.utils.js +28 -0
- package/esm2015/ngx-utils/utils/timer.utils.js +52 -0
- package/esm2015/ngx-utils/utils/unique.utils.js +24 -0
- package/esm2015/ngx-utils/utils/vector.js +77 -0
- package/esm2015/public_api.js +88 -0
- package/esm2015/stemy-ngx-utils.js +7 -0
- package/esm2020/ngx-utils/components/unordered-list/unordered-list.component.mjs +3 -3
- package/esm2020/ngx-utils/ngx-utils.imports.mjs +7 -1
- package/esm2020/ngx-utils/ngx-utils.module.mjs +31 -28
- package/esm2020/ngx-utils/pipes/pop.pipe.mjs +16 -0
- package/esm2020/ngx-utils/pipes/shift.pipe.mjs +16 -0
- package/esm2020/ngx-utils/pipes/split.pipe.mjs +16 -0
- package/esm2020/ngx-utils/services/acl.service.mjs +3 -1
- package/esm2020/ngx-utils/services/config.service.mjs +6 -5
- package/esm2020/ngx-utils/services/formatter.service.mjs +3 -2
- package/esm2020/ngx-utils/utils/array.utils.mjs +8 -1
- package/esm2020/ngx-utils/utils/file-system.mjs +25 -0
- package/esm2020/ngx-utils/utils/math.utils.mjs +31 -2
- package/esm2020/ngx-utils/utils/object.utils.mjs +36 -25
- package/esm2020/public_api.mjs +5 -1
- package/fesm2015/stemy-ngx-utils.js +4974 -0
- package/fesm2015/stemy-ngx-utils.js.map +1 -0
- package/fesm2015/stemy-ngx-utils.mjs +157 -35
- package/fesm2015/stemy-ngx-utils.mjs.map +1 -1
- package/fesm2020/stemy-ngx-utils.mjs +156 -35
- package/fesm2020/stemy-ngx-utils.mjs.map +1 -1
- package/ngx-utils/ngx-utils.module.d.ts +31 -28
- package/ngx-utils/pipes/pop.pipe.d.ts +7 -0
- package/ngx-utils/pipes/shift.pipe.d.ts +7 -0
- package/ngx-utils/pipes/split.pipe.d.ts +7 -0
- package/ngx-utils/services/config.service.d.ts +4 -2
- package/ngx-utils/utils/array.utils.d.ts +1 -0
- package/ngx-utils/utils/file-system.d.ts +16 -0
- package/ngx-utils/utils/math.utils.d.ts +3 -0
- package/ngx-utils/utils/object.utils.d.ts +1 -1
- package/package.json +10 -10
- package/public_api.d.ts +4 -0
- package/stemy-ngx-utils.metadata.json +1 -0
- package/tools/circular.js +117 -0
- package/tools/circular.js.map +1 -0
- package/tools/config.js +79 -0
- package/tools/config.js.map +1 -0
- package/tools/icons.js +14 -0
- package/tools/icons.js.map +1 -0
|
@@ -0,0 +1,4974 @@
|
|
|
1
|
+
import { InjectionToken, TemplateRef, Injectable, Inject, PLATFORM_ID, Injector, NgZone, Optional, EventEmitter, isDevMode, ErrorHandler, Pipe, ChangeDetectorRef, Input, Output, HostBinding, HostListener, Directive, ElementRef, Renderer2, ViewContainerRef, Component, ContentChildren, ViewChild, ContentChild, APP_INITIALIZER, NgModule } from '@angular/core';
|
|
2
|
+
import 'reflect-metadata';
|
|
3
|
+
import { utc } from 'moment';
|
|
4
|
+
import { first, skipWhile, mergeMap, timeout, map } from 'rxjs/operators';
|
|
5
|
+
import { Subject, BehaviorSubject, Observable, Subscription, from, TimeoutError, combineLatest } from 'rxjs';
|
|
6
|
+
import { Invokable } from 'invokable';
|
|
7
|
+
import { __awaiter, __decorate } from 'tslib';
|
|
8
|
+
import { ActivatedRouteSnapshot, NavigationEnd, Router, DefaultUrlSerializer, UrlTree, UrlSegmentGroup, UrlSegment, UrlSerializer } from '@angular/router';
|
|
9
|
+
import { isPlatformBrowser, isPlatformServer, DOCUMENT, CommonModule } from '@angular/common';
|
|
10
|
+
import { DeviceDetectorService } from 'ngx-device-detector';
|
|
11
|
+
import { HttpClient, HttpHeaders, HttpParams, HttpUrlEncodingCodec, HttpHandler, HttpEventType } from '@angular/common/http';
|
|
12
|
+
import { ɵangular_packages_platform_browser_platform_browser_g, DomSanitizer, EVENT_MANAGER_PLUGINS } from '@angular/platform-browser';
|
|
13
|
+
import { addListener, removeListener } from 'resize-detector';
|
|
14
|
+
import { FormsModule } from '@angular/forms';
|
|
15
|
+
|
|
16
|
+
const defaultPredicate = () => true;
|
|
17
|
+
const ɵ0 = defaultPredicate;
|
|
18
|
+
const hasBlob = typeof Blob !== "undefined";
|
|
19
|
+
const hasFile = typeof File !== "undefined";
|
|
20
|
+
class ObjectUtils {
|
|
21
|
+
static compare(a, b) {
|
|
22
|
+
if ((a === null || b === null) || (typeof a != typeof b)) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
if (typeof a === "string") {
|
|
26
|
+
return (a).localeCompare(b);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
if (a instanceof Date) {
|
|
30
|
+
a = a.getTime();
|
|
31
|
+
b = b.getTime();
|
|
32
|
+
}
|
|
33
|
+
if (a > b) {
|
|
34
|
+
return 1;
|
|
35
|
+
}
|
|
36
|
+
else if (a < b) {
|
|
37
|
+
return -1;
|
|
38
|
+
}
|
|
39
|
+
return 0;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
static getProperties(obj) {
|
|
43
|
+
if (!ObjectUtils.isObject(obj) && !ObjectUtils.isFunction(obj))
|
|
44
|
+
return [];
|
|
45
|
+
const props = new Set();
|
|
46
|
+
Object.keys(obj).forEach(p => props.add(p));
|
|
47
|
+
Object.getOwnPropertyNames(obj).forEach(p => props.add(p));
|
|
48
|
+
return Array.from(props);
|
|
49
|
+
}
|
|
50
|
+
static equals(a, b, visited = null) {
|
|
51
|
+
visited = visited || new Set();
|
|
52
|
+
if (visited.has(a) && visited.has(b))
|
|
53
|
+
return true;
|
|
54
|
+
if (a === b)
|
|
55
|
+
return true;
|
|
56
|
+
if (a === null || b === null)
|
|
57
|
+
return false;
|
|
58
|
+
if (a !== a && b !== b)
|
|
59
|
+
return true; // NaN === NaN
|
|
60
|
+
const at = typeof a, bt = typeof b;
|
|
61
|
+
let length, key, keySet;
|
|
62
|
+
if (at == bt && at == "object") {
|
|
63
|
+
visited.add(a);
|
|
64
|
+
visited.add(b);
|
|
65
|
+
if (Array.isArray(a)) {
|
|
66
|
+
if (!Array.isArray(b))
|
|
67
|
+
return false;
|
|
68
|
+
if ((length = a.length) == b.length) {
|
|
69
|
+
for (key = 0; key < length; key++) {
|
|
70
|
+
if (!ObjectUtils.equals(a[key], b[key], visited))
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
if (Array.isArray(b)) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
keySet = Object.create(null);
|
|
81
|
+
for (key in a) {
|
|
82
|
+
if (a.hasOwnProperty(key)) {
|
|
83
|
+
if (!ObjectUtils.equals(a[key], b[key], visited)) {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
keySet[key] = true;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
for (key in b) {
|
|
90
|
+
if (b.hasOwnProperty(key) && !(key in keySet) && typeof b[key] !== "undefined") {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
static evaluate(expr, context = {}, res = {}) {
|
|
100
|
+
expr = Object.keys(context).reduce((res, key) => `var ${key} = this['${key}'];\n${res}`, expr);
|
|
101
|
+
const lines = expr.split("\n");
|
|
102
|
+
const lastLine = "return " + lines.pop().replace("return ", "");
|
|
103
|
+
lines.push(lastLine);
|
|
104
|
+
expr = lines.join("\n");
|
|
105
|
+
let result = null;
|
|
106
|
+
try {
|
|
107
|
+
result = new Function(expr).call(context);
|
|
108
|
+
}
|
|
109
|
+
catch (e) {
|
|
110
|
+
res.exception = e;
|
|
111
|
+
console.log(`Failed to parse expression: ${e.message}`, expr, context);
|
|
112
|
+
}
|
|
113
|
+
res.result = result;
|
|
114
|
+
return result;
|
|
115
|
+
}
|
|
116
|
+
static empty(obj) {
|
|
117
|
+
return !obj || Object.keys(obj).length == 0;
|
|
118
|
+
}
|
|
119
|
+
static iterate(obj, cb) {
|
|
120
|
+
if (!obj)
|
|
121
|
+
return;
|
|
122
|
+
const keys = Array.isArray(obj) ? Array.from(obj.keys()) : Object.keys(obj);
|
|
123
|
+
keys.forEach(
|
|
124
|
+
// @dynamic
|
|
125
|
+
key => {
|
|
126
|
+
cb(obj[key], key);
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
static getValue(obj, key, defaultValue, treeFallback = false) {
|
|
130
|
+
key = key || "";
|
|
131
|
+
const keys = key.split(".");
|
|
132
|
+
let curKey = "";
|
|
133
|
+
do {
|
|
134
|
+
curKey += keys.shift();
|
|
135
|
+
if (ObjectUtils.isDefined(obj) && ObjectUtils.isDefined(obj[curKey]) && (typeof obj[curKey] === "object" || !keys.length)) {
|
|
136
|
+
obj = obj[curKey];
|
|
137
|
+
curKey = "";
|
|
138
|
+
}
|
|
139
|
+
else if (!keys.length) {
|
|
140
|
+
defaultValue = typeof defaultValue == "undefined" ? key.replace(new RegExp(`${curKey}$`), `{${curKey}}`) : defaultValue;
|
|
141
|
+
obj = treeFallback ? obj || defaultValue : defaultValue;
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
curKey += ".";
|
|
145
|
+
}
|
|
146
|
+
} while (keys.length);
|
|
147
|
+
return obj;
|
|
148
|
+
}
|
|
149
|
+
static mapToPath(target, source, path) {
|
|
150
|
+
if (typeof source === "undefined")
|
|
151
|
+
return target;
|
|
152
|
+
if (path.length == 0)
|
|
153
|
+
return source;
|
|
154
|
+
const key = path.shift();
|
|
155
|
+
if (key == "*") {
|
|
156
|
+
if (ObjectUtils.isArray(source)) {
|
|
157
|
+
target = ObjectUtils.isArray(target) ? target : [];
|
|
158
|
+
return source.map((item, index) => {
|
|
159
|
+
return ObjectUtils.mapToPath(target[index], item, Array.from(path));
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
if (ObjectUtils.isObject(source)) {
|
|
163
|
+
target = ObjectUtils.isObject(target) ? target : {};
|
|
164
|
+
return Object.keys(source).reduce((result, key) => {
|
|
165
|
+
result[key] = ObjectUtils.mapToPath(target[key], source[key], Array.from(path));
|
|
166
|
+
return result;
|
|
167
|
+
}, {});
|
|
168
|
+
}
|
|
169
|
+
return ObjectUtils.isNullOrUndefined(target) ? null : target;
|
|
170
|
+
}
|
|
171
|
+
const isArray = ObjectUtils.isArray(target);
|
|
172
|
+
target = ObjectUtils.isObject(target) || isArray ? target : {};
|
|
173
|
+
target[key] = ObjectUtils.mapToPath(target[key], source, Array.from(path));
|
|
174
|
+
return isNaN(key) || isArray ? target : Object.values(target);
|
|
175
|
+
}
|
|
176
|
+
static filter(obj, predicate) {
|
|
177
|
+
return ObjectUtils.copyRecursive(null, obj, predicate, new Map());
|
|
178
|
+
}
|
|
179
|
+
static copy(obj) {
|
|
180
|
+
return ObjectUtils.copyRecursive(null, obj, null, new Map());
|
|
181
|
+
}
|
|
182
|
+
static assign(target, source, predicate) {
|
|
183
|
+
return ObjectUtils.copyRecursive(target, source, predicate, new Map());
|
|
184
|
+
}
|
|
185
|
+
static getType(obj) {
|
|
186
|
+
const regex = new RegExp("\\s([a-zA-Z]+)");
|
|
187
|
+
return Object.prototype.toString.call(obj).match(regex)[1].toLowerCase();
|
|
188
|
+
}
|
|
189
|
+
static isPrimitive(value) {
|
|
190
|
+
const type = typeof value;
|
|
191
|
+
return value == null || (type !== "object" && type !== "function");
|
|
192
|
+
}
|
|
193
|
+
static isObject(value) {
|
|
194
|
+
return ObjectUtils.getType(value) === "object";
|
|
195
|
+
}
|
|
196
|
+
static isDefined(value) {
|
|
197
|
+
return typeof value !== "undefined" && value !== null;
|
|
198
|
+
}
|
|
199
|
+
static isNullOrUndefined(value) {
|
|
200
|
+
return typeof value == "undefined" || value == null;
|
|
201
|
+
}
|
|
202
|
+
static isString(value) {
|
|
203
|
+
return typeof value === "string";
|
|
204
|
+
}
|
|
205
|
+
static isFunction(value) {
|
|
206
|
+
return typeof value === "function";
|
|
207
|
+
}
|
|
208
|
+
static isDate(value) {
|
|
209
|
+
return null !== value && !isNaN(value) && "undefined" !== typeof value.getDate;
|
|
210
|
+
}
|
|
211
|
+
static isBlob(value) {
|
|
212
|
+
return (hasBlob && value instanceof Blob) || (hasFile && value instanceof File);
|
|
213
|
+
}
|
|
214
|
+
static isBoolean(value) {
|
|
215
|
+
return typeof (value) == typeof (true);
|
|
216
|
+
}
|
|
217
|
+
static isNumber(value) {
|
|
218
|
+
if (typeof value !== "number")
|
|
219
|
+
return false;
|
|
220
|
+
const num = +value;
|
|
221
|
+
if ((num - num) !== 0) {
|
|
222
|
+
return false;
|
|
223
|
+
}
|
|
224
|
+
if (num === value) {
|
|
225
|
+
return true;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
static isArray(value) {
|
|
229
|
+
return Array.isArray(value);
|
|
230
|
+
}
|
|
231
|
+
static isSet(value) {
|
|
232
|
+
return value instanceof Set;
|
|
233
|
+
}
|
|
234
|
+
static checkInterface(obj, interFaceObject) {
|
|
235
|
+
return ObjectUtils.isInterface(obj, interFaceObject);
|
|
236
|
+
}
|
|
237
|
+
static isInterface(obj, interFaceObject) {
|
|
238
|
+
if (!obj || typeof obj !== "object" || ObjectUtils.isArray(obj) || !ObjectUtils.isObject(interFaceObject))
|
|
239
|
+
return false;
|
|
240
|
+
const keys = Object.keys(interFaceObject);
|
|
241
|
+
for (const key of keys) {
|
|
242
|
+
let type = interFaceObject[key] || "";
|
|
243
|
+
if (type.startsWith("*")) {
|
|
244
|
+
type = type.substr(1);
|
|
245
|
+
if (obj.hasOwnProperty(key) && ObjectUtils.getType(obj[key]) !== type)
|
|
246
|
+
return false;
|
|
247
|
+
}
|
|
248
|
+
else if (!obj.hasOwnProperty(key) || ObjectUtils.getType(obj[key]) !== type) {
|
|
249
|
+
return false;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return true;
|
|
253
|
+
}
|
|
254
|
+
static pad(obj, width, chr = "0") {
|
|
255
|
+
const str = ObjectUtils.isDefined(obj) ? obj.toString() : "";
|
|
256
|
+
return str.length >= width ? str : new Array(width - str.length + 1).join(chr) + str;
|
|
257
|
+
}
|
|
258
|
+
static copyRecursive(target, source, predicate, copies) {
|
|
259
|
+
predicate = predicate || defaultPredicate;
|
|
260
|
+
if (ObjectUtils.isPrimitive(source) || ObjectUtils.isDate(source) || ObjectUtils.isBlob(source) || ObjectUtils.isFunction(source))
|
|
261
|
+
return source;
|
|
262
|
+
if (!copies.has(source)) {
|
|
263
|
+
if (ObjectUtils.isArray(source)) {
|
|
264
|
+
target = ObjectUtils.isArray(target) ? Array.from(target) : [];
|
|
265
|
+
copies.set(source, target);
|
|
266
|
+
source.forEach((item, index) => {
|
|
267
|
+
if (!predicate(item, index, target, source))
|
|
268
|
+
return;
|
|
269
|
+
if (target.length > index)
|
|
270
|
+
target[index] = ObjectUtils.copyRecursive(target[index], item, predicate, copies);
|
|
271
|
+
else
|
|
272
|
+
target.push(ObjectUtils.copyRecursive(null, item, predicate, copies));
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
target = Object.assign({}, target);
|
|
277
|
+
copies.set(source, target);
|
|
278
|
+
Object.keys(source).forEach((key) => {
|
|
279
|
+
if (!predicate(source[key], key, target, source))
|
|
280
|
+
return;
|
|
281
|
+
target[key] = ObjectUtils.copyRecursive(target[key], source[key], predicate, copies);
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
return copies.get(source);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
class ReflectUtils {
|
|
290
|
+
static defineMetadata(key, data, target, name) {
|
|
291
|
+
Reflect.defineMetadata(key, data, target, name);
|
|
292
|
+
}
|
|
293
|
+
static getMetadata(key, target, name) {
|
|
294
|
+
return Reflect.getMetadata(key, target, name);
|
|
295
|
+
}
|
|
296
|
+
static getOwnMetadata(key, target, name) {
|
|
297
|
+
return Reflect.getOwnMetadata(key, target, name);
|
|
298
|
+
}
|
|
299
|
+
static resolve(obj, injector) {
|
|
300
|
+
if (!ObjectUtils.checkInterface(obj, { func: "function" }))
|
|
301
|
+
return obj;
|
|
302
|
+
const factory = obj;
|
|
303
|
+
let depends = [];
|
|
304
|
+
if (factory.type) {
|
|
305
|
+
const method = ObjectUtils.getProperties(factory.type).find(function (key) {
|
|
306
|
+
return factory.type[key] === factory.func;
|
|
307
|
+
});
|
|
308
|
+
depends = ReflectUtils.getMetadata("factoryDependencies", factory.type, method) || [];
|
|
309
|
+
}
|
|
310
|
+
else {
|
|
311
|
+
depends = ReflectUtils.getMetadata("factoryDependencies", factory.func) || [];
|
|
312
|
+
}
|
|
313
|
+
const parameters = depends.map(function (dep) {
|
|
314
|
+
return injector.get(dep);
|
|
315
|
+
}).concat(factory.params);
|
|
316
|
+
return factory.func.apply(null, parameters);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
class CanvasColor {
|
|
321
|
+
constructor(r, g, b, a = 255) {
|
|
322
|
+
this.r = r;
|
|
323
|
+
this.g = g;
|
|
324
|
+
this.b = b;
|
|
325
|
+
this.a = a;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
const ICON_SERVICE = new InjectionToken("icon-service");
|
|
329
|
+
const LANGUAGE_SERVICE = new InjectionToken("language-service");
|
|
330
|
+
const AUTH_SERVICE = new InjectionToken("auth-service");
|
|
331
|
+
// --- Storage Service ---
|
|
332
|
+
var StorageMode;
|
|
333
|
+
(function (StorageMode) {
|
|
334
|
+
StorageMode[StorageMode["Local"] = 0] = "Local";
|
|
335
|
+
StorageMode[StorageMode["Session"] = 1] = "Session";
|
|
336
|
+
})(StorageMode || (StorageMode = {}));
|
|
337
|
+
const TOASTER_SERVICE = new InjectionToken("toaster-service");
|
|
338
|
+
const PROMISE_SERVICE = new InjectionToken("promise-service");
|
|
339
|
+
// --- Unordered list ---
|
|
340
|
+
class UnorederedListTemplate extends TemplateRef {
|
|
341
|
+
}
|
|
342
|
+
// --- Reflect utils ---
|
|
343
|
+
function FactoryDependencies(...dependencies) {
|
|
344
|
+
return function (target, method) {
|
|
345
|
+
ReflectUtils.defineMetadata("factoryDependencies", dependencies, target, method);
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
class PaginationItemContext {
|
|
349
|
+
constructor(item, parallelItem, count, index, dataIndex) {
|
|
350
|
+
this.item = item;
|
|
351
|
+
this.parallelItem = parallelItem;
|
|
352
|
+
this.count = count;
|
|
353
|
+
this.index = index;
|
|
354
|
+
this.dataIndex = dataIndex;
|
|
355
|
+
}
|
|
356
|
+
get first() {
|
|
357
|
+
return this.index === 0;
|
|
358
|
+
}
|
|
359
|
+
get last() {
|
|
360
|
+
return this.index === this.count - 1;
|
|
361
|
+
}
|
|
362
|
+
get even() {
|
|
363
|
+
return this.index % 2 === 0;
|
|
364
|
+
}
|
|
365
|
+
get odd() {
|
|
366
|
+
return !this.even;
|
|
367
|
+
}
|
|
368
|
+
// Support for old dynamic table implementation
|
|
369
|
+
get row() {
|
|
370
|
+
console.log("DynamicTable row is deprecated use item instead");
|
|
371
|
+
return this.item;
|
|
372
|
+
}
|
|
373
|
+
// Support for old dynamic table implementation
|
|
374
|
+
get parallelRow() {
|
|
375
|
+
console.log("DynamicTable parallelRow is deprecated use parallelItem instead");
|
|
376
|
+
return this.parallelItem;
|
|
377
|
+
}
|
|
378
|
+
filter(filterRx) {
|
|
379
|
+
const keys = Object.keys(this.item);
|
|
380
|
+
for (const key of keys) {
|
|
381
|
+
const value = this.item[key];
|
|
382
|
+
if (ObjectUtils.isNullOrUndefined(value) || ObjectUtils.isObject(value))
|
|
383
|
+
continue;
|
|
384
|
+
const testValue = ObjectUtils.isString(value) ? value : value.toString();
|
|
385
|
+
if (testValue.match(filterRx))
|
|
386
|
+
return true;
|
|
387
|
+
}
|
|
388
|
+
return false;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
class HttpPromise extends Promise {
|
|
392
|
+
constructor(rejectHandler, executor) {
|
|
393
|
+
super(executor);
|
|
394
|
+
this.rejectHandler = rejectHandler;
|
|
395
|
+
this.attachCount = 0;
|
|
396
|
+
this.runCount = 0;
|
|
397
|
+
}
|
|
398
|
+
then(onFulfilled, onRejected) {
|
|
399
|
+
this.attachCount++;
|
|
400
|
+
return super.then(value => {
|
|
401
|
+
this.runCount++;
|
|
402
|
+
return onFulfilled ? onFulfilled(value) : null;
|
|
403
|
+
}, (reason) => {
|
|
404
|
+
const result = onRejected ? onRejected(reason) : null;
|
|
405
|
+
this.hasRejectHandler = this.hasRejectHandler || (onRejected && result !== false);
|
|
406
|
+
this.runCount++;
|
|
407
|
+
this.rejectHandler(this.runCount == this.attachCount && !this.hasRejectHandler ? reason : null);
|
|
408
|
+
return result;
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
catch(onRejected) {
|
|
412
|
+
return this.then(null, onRejected);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
const EXPRESS_REQUEST = new InjectionToken("express-request");
|
|
416
|
+
const API_SERVICE = new InjectionToken("api-service");
|
|
417
|
+
// --- Resource if ---
|
|
418
|
+
class ResourceIfContext {
|
|
419
|
+
}
|
|
420
|
+
// --- ConfigService ---
|
|
421
|
+
class IConfiguration {
|
|
422
|
+
}
|
|
423
|
+
const CONFIG_SERVICE = new InjectionToken("config-service");
|
|
424
|
+
const BASE_CONFIG = new InjectionToken("base-config");
|
|
425
|
+
const SCRIPT_PARAMS = new InjectionToken("script-params");
|
|
426
|
+
const ROOT_ELEMENT = new InjectionToken("app-root-element");
|
|
427
|
+
const ERROR_HANDLER = new InjectionToken("error-handler-callback");
|
|
428
|
+
const GLOBAL_TEMPLATES = new InjectionToken("global-templates");
|
|
429
|
+
// --- Valued promise ---
|
|
430
|
+
class ValuedPromise extends Promise {
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
class AjaxRequestHandler {
|
|
434
|
+
constructor(pattern, callback) {
|
|
435
|
+
this.pattern = pattern;
|
|
436
|
+
this.callback = callback;
|
|
437
|
+
this.listener = (event) => {
|
|
438
|
+
const details = event.detail;
|
|
439
|
+
if (this.pattern.test(details.url))
|
|
440
|
+
this.callback(details, this.params);
|
|
441
|
+
};
|
|
442
|
+
this.params = {};
|
|
443
|
+
if (typeof XMLHttpRequest !== "undefined" && !AjaxRequestHandler.isOverridden) {
|
|
444
|
+
AjaxRequestHandler.isOverridden = true;
|
|
445
|
+
const originalOpen = XMLHttpRequest.prototype.open;
|
|
446
|
+
XMLHttpRequest.prototype.open = function (method, url, async, user, password) {
|
|
447
|
+
originalOpen.apply(this, arguments);
|
|
448
|
+
window.dispatchEvent(new CustomEvent("ajaxRequest", {
|
|
449
|
+
detail: {
|
|
450
|
+
request: this,
|
|
451
|
+
method: method,
|
|
452
|
+
url: url
|
|
453
|
+
}
|
|
454
|
+
}));
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
listen() {
|
|
459
|
+
if (typeof window === "undefined")
|
|
460
|
+
return this;
|
|
461
|
+
window.addEventListener("ajaxRequest", this.listener);
|
|
462
|
+
return this;
|
|
463
|
+
}
|
|
464
|
+
forget() {
|
|
465
|
+
if (typeof window === "undefined")
|
|
466
|
+
return;
|
|
467
|
+
window.removeEventListener("ajaxRequest", this.listener);
|
|
468
|
+
return this;
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
AjaxRequestHandler.isOverridden = false;
|
|
472
|
+
|
|
473
|
+
class DateUtils {
|
|
474
|
+
static isHoliday(date) {
|
|
475
|
+
return utc(date).isoWeekday() > 5;
|
|
476
|
+
}
|
|
477
|
+
static isBusinessDay(date) {
|
|
478
|
+
return utc(date).isoWeekday() < 6;
|
|
479
|
+
}
|
|
480
|
+
static add(date, amount, unit) {
|
|
481
|
+
return utc(date).add(amount, unit).toDate();
|
|
482
|
+
}
|
|
483
|
+
static businessAdd(date, amount, unit) {
|
|
484
|
+
const signal = amount < 0 ? -1 : 1;
|
|
485
|
+
let remaining = Math.abs(amount);
|
|
486
|
+
let day = date;
|
|
487
|
+
while (remaining) {
|
|
488
|
+
day = DateUtils.add(day, signal, unit);
|
|
489
|
+
if (DateUtils.isBusinessDay(day)) {
|
|
490
|
+
remaining--;
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
return day;
|
|
494
|
+
}
|
|
495
|
+
static businessSubtract(date, amount, unit) {
|
|
496
|
+
return DateUtils.businessAdd(date, -amount, unit);
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
class BlurStack {
|
|
501
|
+
constructor() {
|
|
502
|
+
this.r = 0;
|
|
503
|
+
this.g = 0;
|
|
504
|
+
this.b = 0;
|
|
505
|
+
this.a = 0;
|
|
506
|
+
this.next = null;
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
const mul_table = [
|
|
510
|
+
512, 512, 456, 512, 328, 456, 335, 512, 405, 328, 271, 456, 388, 335, 292, 512,
|
|
511
|
+
454, 405, 364, 328, 298, 271, 496, 456, 420, 388, 360, 335, 312, 292, 273, 512,
|
|
512
|
+
482, 454, 428, 405, 383, 364, 345, 328, 312, 298, 284, 271, 259, 496, 475, 456,
|
|
513
|
+
437, 420, 404, 388, 374, 360, 347, 335, 323, 312, 302, 292, 282, 273, 265, 512,
|
|
514
|
+
497, 482, 468, 454, 441, 428, 417, 405, 394, 383, 373, 364, 354, 345, 337, 328,
|
|
515
|
+
320, 312, 305, 298, 291, 284, 278, 271, 265, 259, 507, 496, 485, 475, 465, 456,
|
|
516
|
+
446, 437, 428, 420, 412, 404, 396, 388, 381, 374, 367, 360, 354, 347, 341, 335,
|
|
517
|
+
329, 323, 318, 312, 307, 302, 297, 292, 287, 282, 278, 273, 269, 265, 261, 512,
|
|
518
|
+
505, 497, 489, 482, 475, 468, 461, 454, 447, 441, 435, 428, 422, 417, 411, 405,
|
|
519
|
+
399, 394, 389, 383, 378, 373, 368, 364, 359, 354, 350, 345, 341, 337, 332, 328,
|
|
520
|
+
324, 320, 316, 312, 309, 305, 301, 298, 294, 291, 287, 284, 281, 278, 274, 271,
|
|
521
|
+
268, 265, 262, 259, 257, 507, 501, 496, 491, 485, 480, 475, 470, 465, 460, 456,
|
|
522
|
+
451, 446, 442, 437, 433, 428, 424, 420, 416, 412, 408, 404, 400, 396, 392, 388,
|
|
523
|
+
385, 381, 377, 374, 370, 367, 363, 360, 357, 354, 350, 347, 344, 341, 338, 335,
|
|
524
|
+
332, 329, 326, 323, 320, 318, 315, 312, 310, 307, 304, 302, 299, 297, 294, 292,
|
|
525
|
+
289, 287, 285, 282, 280, 278, 275, 273, 271, 269, 267, 265, 263, 261, 259
|
|
526
|
+
];
|
|
527
|
+
const shg_table = [
|
|
528
|
+
9, 11, 12, 13, 13, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 17,
|
|
529
|
+
17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 18, 19,
|
|
530
|
+
19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 20, 20, 20,
|
|
531
|
+
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 21,
|
|
532
|
+
21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21,
|
|
533
|
+
21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22,
|
|
534
|
+
22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
|
|
535
|
+
22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23,
|
|
536
|
+
23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
|
|
537
|
+
23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
|
|
538
|
+
23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
|
|
539
|
+
23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
|
|
540
|
+
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
|
|
541
|
+
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
|
|
542
|
+
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
|
|
543
|
+
24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24
|
|
544
|
+
];
|
|
545
|
+
class CanvasUtils {
|
|
546
|
+
static manipulatePixels(canvas, ctx, colorTransformer) {
|
|
547
|
+
const imgData = ctx.getImageData(0, 0, canvas.width, canvas.height);
|
|
548
|
+
const pixels = imgData.data;
|
|
549
|
+
for (let i = 0, n = pixels.length; i < n; i += 4) {
|
|
550
|
+
const clr = new CanvasColor(pixels[i], pixels[i + 1], pixels[i + 2], pixels[i + 3]);
|
|
551
|
+
const greyscale = clr.r * .3 + clr.g * .59 + clr.b * .11;
|
|
552
|
+
const color = colorTransformer(clr, greyscale);
|
|
553
|
+
pixels[i] = color.r;
|
|
554
|
+
pixels[i + 1] = color.g;
|
|
555
|
+
pixels[i + 2] = color.b;
|
|
556
|
+
pixels[i + 3] = color.a;
|
|
557
|
+
}
|
|
558
|
+
ctx.putImageData(imgData, 0, 0);
|
|
559
|
+
}
|
|
560
|
+
static thresholding(canvas, ctx, threshold = 50, colorTransformer) {
|
|
561
|
+
const min = new CanvasColor(0, 0, 0, 255);
|
|
562
|
+
const max = new CanvasColor(0, 0, 0, 0);
|
|
563
|
+
colorTransformer = ObjectUtils.isFunction(colorTransformer) ? colorTransformer : ((color, limit) => {
|
|
564
|
+
return limit ? max : min;
|
|
565
|
+
});
|
|
566
|
+
CanvasUtils.manipulatePixels(canvas, ctx, (color, greyscale) => {
|
|
567
|
+
return colorTransformer(color, greyscale > threshold, greyscale);
|
|
568
|
+
});
|
|
569
|
+
}
|
|
570
|
+
static stackBlur(canvas, ctx, radius = 10) {
|
|
571
|
+
if (isNaN(radius) || radius < 1)
|
|
572
|
+
return;
|
|
573
|
+
radius |= 0;
|
|
574
|
+
const top_x = 0;
|
|
575
|
+
const top_y = 0;
|
|
576
|
+
const width = canvas.width;
|
|
577
|
+
const height = canvas.height;
|
|
578
|
+
let imageData = null;
|
|
579
|
+
try {
|
|
580
|
+
try {
|
|
581
|
+
imageData = ctx.getImageData(top_x, top_y, width, height);
|
|
582
|
+
}
|
|
583
|
+
catch (e) {
|
|
584
|
+
// NOTE: this part is supposedly only needed if you want to work with local files
|
|
585
|
+
// so it might be okay to remove the whole try/catch block and just use
|
|
586
|
+
// imageData = ctx.getImageData( top_x, top_y, width, height );
|
|
587
|
+
try {
|
|
588
|
+
netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
|
|
589
|
+
imageData = ctx.getImageData(top_x, top_y, width, height);
|
|
590
|
+
}
|
|
591
|
+
catch (e) {
|
|
592
|
+
alert("Cannot access local image");
|
|
593
|
+
throw new Error("unable to access local image data: " + e);
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
catch (e) {
|
|
598
|
+
alert("Cannot access image");
|
|
599
|
+
throw new Error("unable to access image data: " + e);
|
|
600
|
+
}
|
|
601
|
+
const pixels = imageData.data;
|
|
602
|
+
let x, y, i, p, yp, yi, yw, r_sum, g_sum, b_sum, a_sum, r_out_sum, g_out_sum, b_out_sum, a_out_sum, r_in_sum, g_in_sum, b_in_sum, a_in_sum, pr, pg, pb, pa, rbs;
|
|
603
|
+
const div = radius + radius + 1;
|
|
604
|
+
const widthMinus1 = width - 1;
|
|
605
|
+
const heightMinus1 = height - 1;
|
|
606
|
+
const radiusPlus1 = radius + 1;
|
|
607
|
+
const sumFactor = radiusPlus1 * (radiusPlus1 + 1) / 2;
|
|
608
|
+
const stackStart = new BlurStack();
|
|
609
|
+
let stackEnd = null;
|
|
610
|
+
let stack = stackStart;
|
|
611
|
+
for (i = 1; i < div; i++) {
|
|
612
|
+
stack = stack.next = new BlurStack();
|
|
613
|
+
if (i == radiusPlus1) {
|
|
614
|
+
stackEnd = stack;
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
stack.next = stackStart;
|
|
618
|
+
let stackIn = null;
|
|
619
|
+
let stackOut = null;
|
|
620
|
+
yw = yi = 0;
|
|
621
|
+
const mul_sum = mul_table[radius];
|
|
622
|
+
const shg_sum = shg_table[radius];
|
|
623
|
+
for (y = 0; y < height; y++) {
|
|
624
|
+
r_in_sum = g_in_sum = b_in_sum = a_in_sum = r_sum = g_sum = b_sum = a_sum = 0;
|
|
625
|
+
r_out_sum = radiusPlus1 * (pr = pixels[yi]);
|
|
626
|
+
g_out_sum = radiusPlus1 * (pg = pixels[yi + 1]);
|
|
627
|
+
b_out_sum = radiusPlus1 * (pb = pixels[yi + 2]);
|
|
628
|
+
a_out_sum = radiusPlus1 * (pa = pixels[yi + 3]);
|
|
629
|
+
r_sum += sumFactor * pr;
|
|
630
|
+
g_sum += sumFactor * pg;
|
|
631
|
+
b_sum += sumFactor * pb;
|
|
632
|
+
a_sum += sumFactor * pa;
|
|
633
|
+
stack = stackStart;
|
|
634
|
+
for (i = 0; i < radiusPlus1; i++) {
|
|
635
|
+
stack.r = pr;
|
|
636
|
+
stack.g = pg;
|
|
637
|
+
stack.b = pb;
|
|
638
|
+
stack.a = pa;
|
|
639
|
+
stack = stack.next;
|
|
640
|
+
}
|
|
641
|
+
for (i = 1; i < radiusPlus1; i++) {
|
|
642
|
+
p = yi + ((widthMinus1 < i ? widthMinus1 : i) << 2);
|
|
643
|
+
r_sum += (stack.r = (pr = pixels[p])) * (rbs = radiusPlus1 - i);
|
|
644
|
+
g_sum += (stack.g = (pg = pixels[p + 1])) * rbs;
|
|
645
|
+
b_sum += (stack.b = (pb = pixels[p + 2])) * rbs;
|
|
646
|
+
a_sum += (stack.a = (pa = pixels[p + 3])) * rbs;
|
|
647
|
+
r_in_sum += pr;
|
|
648
|
+
g_in_sum += pg;
|
|
649
|
+
b_in_sum += pb;
|
|
650
|
+
a_in_sum += pa;
|
|
651
|
+
stack = stack.next;
|
|
652
|
+
}
|
|
653
|
+
stackIn = stackStart;
|
|
654
|
+
stackOut = stackEnd;
|
|
655
|
+
for (x = 0; x < width; x++) {
|
|
656
|
+
pixels[yi + 3] = pa = (a_sum * mul_sum) >> shg_sum;
|
|
657
|
+
if (pa != 0) {
|
|
658
|
+
pa = 255 / pa;
|
|
659
|
+
pixels[yi] = ((r_sum * mul_sum) >> shg_sum) * pa;
|
|
660
|
+
pixels[yi + 1] = ((g_sum * mul_sum) >> shg_sum) * pa;
|
|
661
|
+
pixels[yi + 2] = ((b_sum * mul_sum) >> shg_sum) * pa;
|
|
662
|
+
}
|
|
663
|
+
else {
|
|
664
|
+
pixels[yi] = pixels[yi + 1] = pixels[yi + 2] = 0;
|
|
665
|
+
}
|
|
666
|
+
r_sum -= r_out_sum;
|
|
667
|
+
g_sum -= g_out_sum;
|
|
668
|
+
b_sum -= b_out_sum;
|
|
669
|
+
a_sum -= a_out_sum;
|
|
670
|
+
r_out_sum -= stackIn.r;
|
|
671
|
+
g_out_sum -= stackIn.g;
|
|
672
|
+
b_out_sum -= stackIn.b;
|
|
673
|
+
a_out_sum -= stackIn.a;
|
|
674
|
+
p = (yw + ((p = x + radius + 1) < widthMinus1 ? p : widthMinus1)) << 2;
|
|
675
|
+
r_in_sum += (stackIn.r = pixels[p]);
|
|
676
|
+
g_in_sum += (stackIn.g = pixels[p + 1]);
|
|
677
|
+
b_in_sum += (stackIn.b = pixels[p + 2]);
|
|
678
|
+
a_in_sum += (stackIn.a = pixels[p + 3]);
|
|
679
|
+
r_sum += r_in_sum;
|
|
680
|
+
g_sum += g_in_sum;
|
|
681
|
+
b_sum += b_in_sum;
|
|
682
|
+
a_sum += a_in_sum;
|
|
683
|
+
stackIn = stackIn.next;
|
|
684
|
+
r_out_sum += (pr = stackOut.r);
|
|
685
|
+
g_out_sum += (pg = stackOut.g);
|
|
686
|
+
b_out_sum += (pb = stackOut.b);
|
|
687
|
+
a_out_sum += (pa = stackOut.a);
|
|
688
|
+
r_in_sum -= pr;
|
|
689
|
+
g_in_sum -= pg;
|
|
690
|
+
b_in_sum -= pb;
|
|
691
|
+
a_in_sum -= pa;
|
|
692
|
+
stackOut = stackOut.next;
|
|
693
|
+
yi += 4;
|
|
694
|
+
}
|
|
695
|
+
yw += width;
|
|
696
|
+
}
|
|
697
|
+
for (x = 0; x < width; x++) {
|
|
698
|
+
g_in_sum = b_in_sum = a_in_sum = r_in_sum = g_sum = b_sum = a_sum = r_sum = 0;
|
|
699
|
+
yi = x << 2;
|
|
700
|
+
r_out_sum = radiusPlus1 * (pr = pixels[yi]);
|
|
701
|
+
g_out_sum = radiusPlus1 * (pg = pixels[yi + 1]);
|
|
702
|
+
b_out_sum = radiusPlus1 * (pb = pixels[yi + 2]);
|
|
703
|
+
a_out_sum = radiusPlus1 * (pa = pixels[yi + 3]);
|
|
704
|
+
r_sum += sumFactor * pr;
|
|
705
|
+
g_sum += sumFactor * pg;
|
|
706
|
+
b_sum += sumFactor * pb;
|
|
707
|
+
a_sum += sumFactor * pa;
|
|
708
|
+
stack = stackStart;
|
|
709
|
+
for (i = 0; i < radiusPlus1; i++) {
|
|
710
|
+
stack.r = pr;
|
|
711
|
+
stack.g = pg;
|
|
712
|
+
stack.b = pb;
|
|
713
|
+
stack.a = pa;
|
|
714
|
+
stack = stack.next;
|
|
715
|
+
}
|
|
716
|
+
yp = width;
|
|
717
|
+
for (i = 1; i <= radius; i++) {
|
|
718
|
+
yi = (yp + x) << 2;
|
|
719
|
+
r_sum += (stack.r = (pr = pixels[yi])) * (rbs = radiusPlus1 - i);
|
|
720
|
+
g_sum += (stack.g = (pg = pixels[yi + 1])) * rbs;
|
|
721
|
+
b_sum += (stack.b = (pb = pixels[yi + 2])) * rbs;
|
|
722
|
+
a_sum += (stack.a = (pa = pixels[yi + 3])) * rbs;
|
|
723
|
+
r_in_sum += pr;
|
|
724
|
+
g_in_sum += pg;
|
|
725
|
+
b_in_sum += pb;
|
|
726
|
+
a_in_sum += pa;
|
|
727
|
+
stack = stack.next;
|
|
728
|
+
if (i < heightMinus1) {
|
|
729
|
+
yp += width;
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
yi = x;
|
|
733
|
+
stackIn = stackStart;
|
|
734
|
+
stackOut = stackEnd;
|
|
735
|
+
for (y = 0; y < height; y++) {
|
|
736
|
+
p = yi << 2;
|
|
737
|
+
pixels[p + 3] = pa = (a_sum * mul_sum) >> shg_sum;
|
|
738
|
+
if (pa > 0) {
|
|
739
|
+
pa = 255 / pa;
|
|
740
|
+
pixels[p] = ((r_sum * mul_sum) >> shg_sum) * pa;
|
|
741
|
+
pixels[p + 1] = ((g_sum * mul_sum) >> shg_sum) * pa;
|
|
742
|
+
pixels[p + 2] = ((b_sum * mul_sum) >> shg_sum) * pa;
|
|
743
|
+
}
|
|
744
|
+
else {
|
|
745
|
+
pixels[p] = pixels[p + 1] = pixels[p + 2] = 0;
|
|
746
|
+
}
|
|
747
|
+
r_sum -= r_out_sum;
|
|
748
|
+
g_sum -= g_out_sum;
|
|
749
|
+
b_sum -= b_out_sum;
|
|
750
|
+
a_sum -= a_out_sum;
|
|
751
|
+
r_out_sum -= stackIn.r;
|
|
752
|
+
g_out_sum -= stackIn.g;
|
|
753
|
+
b_out_sum -= stackIn.b;
|
|
754
|
+
a_out_sum -= stackIn.a;
|
|
755
|
+
p = (x + (((p = y + radiusPlus1) < heightMinus1 ? p : heightMinus1) * width)) << 2;
|
|
756
|
+
r_sum += (r_in_sum += (stackIn.r = pixels[p]));
|
|
757
|
+
g_sum += (g_in_sum += (stackIn.g = pixels[p + 1]));
|
|
758
|
+
b_sum += (b_in_sum += (stackIn.b = pixels[p + 2]));
|
|
759
|
+
a_sum += (a_in_sum += (stackIn.a = pixels[p + 3]));
|
|
760
|
+
stackIn = stackIn.next;
|
|
761
|
+
r_out_sum += (pr = stackOut.r);
|
|
762
|
+
g_out_sum += (pg = stackOut.g);
|
|
763
|
+
b_out_sum += (pb = stackOut.b);
|
|
764
|
+
a_out_sum += (pa = stackOut.a);
|
|
765
|
+
r_in_sum -= pr;
|
|
766
|
+
g_in_sum -= pg;
|
|
767
|
+
b_in_sum -= pb;
|
|
768
|
+
a_in_sum -= pa;
|
|
769
|
+
stackOut = stackOut.next;
|
|
770
|
+
yi += width;
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
ctx.putImageData(imageData, top_x, top_y);
|
|
774
|
+
}
|
|
775
|
+
static measureTextFontSize(maxWidth, maxHeight, lines, font, lineHeightPercent = 1.1, canvas) {
|
|
776
|
+
const startSize = maxHeight;
|
|
777
|
+
const context = canvas.getContext("2d");
|
|
778
|
+
if (!canvas) {
|
|
779
|
+
canvas = document.createElement("canvas");
|
|
780
|
+
document.body.appendChild(canvas);
|
|
781
|
+
}
|
|
782
|
+
canvas.width = maxWidth + maxHeight;
|
|
783
|
+
canvas.height = maxHeight * 2;
|
|
784
|
+
let fontSize = CanvasUtils.halveValidateFontSize(startSize, (size) => {
|
|
785
|
+
CanvasUtils.setFontProps(context, font, size);
|
|
786
|
+
const maxTextLinesWidth = CanvasUtils.getTextWidth(context, lines);
|
|
787
|
+
return maxWidth - maxTextLinesWidth;
|
|
788
|
+
});
|
|
789
|
+
const bitmapHeight = CanvasUtils.getTextBitmapHeight(canvas, context, lines, font, fontSize, lineHeightPercent);
|
|
790
|
+
if (bitmapHeight > maxHeight) {
|
|
791
|
+
fontSize = CanvasUtils.halveValidateFontSize(fontSize, (size) => {
|
|
792
|
+
return maxHeight - CanvasUtils.getTextBitmapHeight(canvas, context, lines, font, size, lineHeightPercent);
|
|
793
|
+
});
|
|
794
|
+
}
|
|
795
|
+
return fontSize;
|
|
796
|
+
}
|
|
797
|
+
static drawLines(context, lines, font, size, lineHeightPercent = 1.1, align = "left", baseLine = "top", x = 0, y = 0) {
|
|
798
|
+
CanvasUtils.setFontProps(context, font, size, align, baseLine);
|
|
799
|
+
for (let i = 0; i < lines.length; i++) {
|
|
800
|
+
const line = lines[i];
|
|
801
|
+
context.fillText(line, x, y);
|
|
802
|
+
if (i < lines.length - 1) {
|
|
803
|
+
y += size * lineHeightPercent;
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
return y;
|
|
807
|
+
}
|
|
808
|
+
static wrapText(context, text, x, y, maxWidth) {
|
|
809
|
+
const words = text.split(" ");
|
|
810
|
+
const lineHeight = context.measureText("M").width * 1.3;
|
|
811
|
+
const lines = [];
|
|
812
|
+
let line = "";
|
|
813
|
+
for (let n = 0; n < words.length; n++) {
|
|
814
|
+
const testLine = line + words[n] + " ";
|
|
815
|
+
const metrics = context.measureText(testLine);
|
|
816
|
+
const testWidth = metrics.width;
|
|
817
|
+
if (testWidth > maxWidth && n > 0) {
|
|
818
|
+
lines.push(line);
|
|
819
|
+
line = words[n] + " ";
|
|
820
|
+
}
|
|
821
|
+
else {
|
|
822
|
+
line = testLine;
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
lines.push(line);
|
|
826
|
+
y -= lineHeight * .5 * lines.length;
|
|
827
|
+
lines.forEach(l => {
|
|
828
|
+
context.fillText(l, x, y);
|
|
829
|
+
y += lineHeight;
|
|
830
|
+
});
|
|
831
|
+
}
|
|
832
|
+
static setFontProps(context, font, fontSize, align = "left", baseLine = "top") {
|
|
833
|
+
context.font = `${fontSize}px ${font}`;
|
|
834
|
+
context.textAlign = align;
|
|
835
|
+
context.textBaseline = baseLine;
|
|
836
|
+
}
|
|
837
|
+
static getTextWidth(context, lines) {
|
|
838
|
+
let maxWidth = 0;
|
|
839
|
+
for (let i = 0; i < lines.length; i++) {
|
|
840
|
+
const line = lines[i];
|
|
841
|
+
maxWidth = Math.max(maxWidth, context.measureText(line).width);
|
|
842
|
+
}
|
|
843
|
+
return maxWidth;
|
|
844
|
+
}
|
|
845
|
+
static getTextBitmapHeight(canvas, context, lines, font, fontSize, lineHeightPercent) {
|
|
846
|
+
const width = canvas.width;
|
|
847
|
+
const height = canvas.height;
|
|
848
|
+
context.clearRect(0, 0, width, height);
|
|
849
|
+
const textY = CanvasUtils.drawLines(context, lines, font, fontSize, lineHeightPercent, "left", "top", fontSize * .5, fontSize * .5);
|
|
850
|
+
const imageData = context.getImageData(0, 0, width, height);
|
|
851
|
+
let textHeight = 0;
|
|
852
|
+
yLoop: for (let y = 0; y < height; y++) {
|
|
853
|
+
for (let x = 0; x < width; x++) {
|
|
854
|
+
const index = (x + y * width) * 4;
|
|
855
|
+
if (imageData.data[index + 3] > 0) {
|
|
856
|
+
textHeight = y + 1;
|
|
857
|
+
continue yLoop;
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
return Math.max(textHeight, textY + fontSize);
|
|
862
|
+
}
|
|
863
|
+
static halveValidateFontSize(startSize, callback) {
|
|
864
|
+
let fontSize = startSize;
|
|
865
|
+
let lastFontSize = 0;
|
|
866
|
+
let direction;
|
|
867
|
+
for (let i = 0; i < 20; i++) {
|
|
868
|
+
direction = callback(fontSize);
|
|
869
|
+
const tempSize = fontSize;
|
|
870
|
+
if (direction < 0) {
|
|
871
|
+
fontSize = fontSize - (Math.abs(fontSize - lastFontSize) / 2);
|
|
872
|
+
}
|
|
873
|
+
else {
|
|
874
|
+
fontSize = fontSize + (Math.abs(fontSize - lastFontSize) / 2);
|
|
875
|
+
}
|
|
876
|
+
lastFontSize = tempSize;
|
|
877
|
+
if (Math.abs(fontSize - lastFontSize) < 0.1) {
|
|
878
|
+
break;
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
fontSize = Math.floor(fontSize);
|
|
882
|
+
return fontSize;
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
class FileUtils {
|
|
887
|
+
static getExtension(file) {
|
|
888
|
+
return file ? file.name.substr(file.name.lastIndexOf(".")).toLowerCase() : null;
|
|
889
|
+
}
|
|
890
|
+
static getName(file) {
|
|
891
|
+
return file ? file.name.substr(0, file.name.lastIndexOf(".")) : null;
|
|
892
|
+
}
|
|
893
|
+
static toFile(blob, fileName) {
|
|
894
|
+
const data = blob;
|
|
895
|
+
data.lastModifiedDate = new Date();
|
|
896
|
+
data.name = fileName.split(/\\|\//g).pop();
|
|
897
|
+
return data;
|
|
898
|
+
}
|
|
899
|
+
static dataToBlob(data) {
|
|
900
|
+
const parts = data.split(",");
|
|
901
|
+
const byteString = atob(parts[1]);
|
|
902
|
+
const mimeString = parts[0].split(":")[1].split(";")[0];
|
|
903
|
+
const ab = new ArrayBuffer(byteString.length);
|
|
904
|
+
const ia = new Uint8Array(ab);
|
|
905
|
+
for (let i = 0; i < byteString.length; i++) {
|
|
906
|
+
ia[i] = byteString.charCodeAt(i);
|
|
907
|
+
}
|
|
908
|
+
return new Blob([ab], { type: mimeString });
|
|
909
|
+
}
|
|
910
|
+
static saveBlob(blob, fileName) {
|
|
911
|
+
if (typeof saveAs == "undefined") {
|
|
912
|
+
throw Error("FileSaver library is not loaded. Please load it: https://www.npmjs.com/package/file-saver");
|
|
913
|
+
}
|
|
914
|
+
saveAs(blob, fileName);
|
|
915
|
+
}
|
|
916
|
+
static saveJson(json, fileName) {
|
|
917
|
+
if (!ObjectUtils.isObject(json))
|
|
918
|
+
return;
|
|
919
|
+
FileUtils.saveBlob(new Blob([JSON.stringify(json, null, 4)]), fileName);
|
|
920
|
+
}
|
|
921
|
+
static readFileAsText(file) {
|
|
922
|
+
return FileUtils.readFile(
|
|
923
|
+
// @dynamic
|
|
924
|
+
reader => reader.readAsText(file));
|
|
925
|
+
}
|
|
926
|
+
static readFileAsBinaryString(file) {
|
|
927
|
+
return FileUtils.readFile(
|
|
928
|
+
// @dynamic
|
|
929
|
+
reader => reader.readAsBinaryString(file));
|
|
930
|
+
}
|
|
931
|
+
static readFileAsDataURL(file) {
|
|
932
|
+
return FileUtils.readFile(
|
|
933
|
+
// @dynamic
|
|
934
|
+
reader => reader.readAsDataURL(file));
|
|
935
|
+
}
|
|
936
|
+
static readDataFromUrl(http, url) {
|
|
937
|
+
return new Promise(
|
|
938
|
+
// @dynamic
|
|
939
|
+
(resolve, reject) => {
|
|
940
|
+
if (!url) {
|
|
941
|
+
reject({
|
|
942
|
+
message: "The url is not specified"
|
|
943
|
+
});
|
|
944
|
+
return;
|
|
945
|
+
}
|
|
946
|
+
if ((/^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)$/g).test(url)) {
|
|
947
|
+
resolve(url);
|
|
948
|
+
return;
|
|
949
|
+
}
|
|
950
|
+
first()(http.get(url, {
|
|
951
|
+
responseType: "blob"
|
|
952
|
+
})).subscribe((blob) => {
|
|
953
|
+
FileUtils.readFileAsDataURL(blob).then(resolve, reject);
|
|
954
|
+
}, reason => {
|
|
955
|
+
if (reason.status > 0)
|
|
956
|
+
reject(reason);
|
|
957
|
+
else
|
|
958
|
+
resolve(url);
|
|
959
|
+
});
|
|
960
|
+
});
|
|
961
|
+
}
|
|
962
|
+
static readFile(callback) {
|
|
963
|
+
return new Promise(
|
|
964
|
+
// @dynamic
|
|
965
|
+
(resolve, reject) => {
|
|
966
|
+
const reader = new FileReader();
|
|
967
|
+
reader.onload = (event) => resolve(event.target.result);
|
|
968
|
+
reader.onerror = reject;
|
|
969
|
+
callback(reader);
|
|
970
|
+
});
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
class GenericValue extends Subject {
|
|
975
|
+
constructor(value = null) {
|
|
976
|
+
super();
|
|
977
|
+
this._value = value;
|
|
978
|
+
}
|
|
979
|
+
get value() {
|
|
980
|
+
return this._value;
|
|
981
|
+
}
|
|
982
|
+
set value(value) {
|
|
983
|
+
if (value == this._value)
|
|
984
|
+
return;
|
|
985
|
+
this._value = value;
|
|
986
|
+
this.next(value);
|
|
987
|
+
}
|
|
988
|
+
setJustValue(value) {
|
|
989
|
+
this._value = value;
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
class FileSystemEntry {
|
|
994
|
+
constructor(label, meta, image, data, parent, openCb) {
|
|
995
|
+
this.label = label;
|
|
996
|
+
this.meta = meta;
|
|
997
|
+
this.image = image;
|
|
998
|
+
this.data = data;
|
|
999
|
+
this.parent = parent;
|
|
1000
|
+
this.openCb = openCb;
|
|
1001
|
+
this.path = !parent ? [this] : parent.path.concat([this]);
|
|
1002
|
+
this.level = this.path.length - 1;
|
|
1003
|
+
this.classes = this.path
|
|
1004
|
+
.filter(t => typeof t.data === "string" && t.data.length > 0).map(t => t.data)
|
|
1005
|
+
.concat([`level-${this.level}`]);
|
|
1006
|
+
}
|
|
1007
|
+
open() {
|
|
1008
|
+
this.result = this.result || this.openCb(this.data, this);
|
|
1009
|
+
this.result.then(res => {
|
|
1010
|
+
if (Array.isArray(res))
|
|
1011
|
+
return;
|
|
1012
|
+
this.result = null;
|
|
1013
|
+
});
|
|
1014
|
+
return this.result;
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
class Rect {
|
|
1019
|
+
constructor(x, y, width, height, rotation = 0) {
|
|
1020
|
+
this.x = x;
|
|
1021
|
+
this.y = y;
|
|
1022
|
+
this.width = width;
|
|
1023
|
+
this.height = height;
|
|
1024
|
+
this.rotation = rotation;
|
|
1025
|
+
}
|
|
1026
|
+
get center() {
|
|
1027
|
+
return new Point(this.x, this.y);
|
|
1028
|
+
}
|
|
1029
|
+
get left() {
|
|
1030
|
+
return this.x - this.width * .5;
|
|
1031
|
+
}
|
|
1032
|
+
get right() {
|
|
1033
|
+
return this.x + this.width * .5;
|
|
1034
|
+
}
|
|
1035
|
+
get bottom() {
|
|
1036
|
+
return this.y - this.height * .5;
|
|
1037
|
+
}
|
|
1038
|
+
get top() {
|
|
1039
|
+
return this.y + this.height * .5;
|
|
1040
|
+
}
|
|
1041
|
+
distance(p) {
|
|
1042
|
+
p = p.rotateAround(this.center, -this.rotation);
|
|
1043
|
+
const x = Math.max(this.left - p.x, 0, p.x - this.right);
|
|
1044
|
+
const y = Math.max(this.bottom - p.y, 0, p.y - this.top);
|
|
1045
|
+
return Math.sqrt(x * x + y * y);
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
class Circle {
|
|
1049
|
+
constructor(x, y, radius) {
|
|
1050
|
+
this.x = x;
|
|
1051
|
+
this.y = y;
|
|
1052
|
+
this.radius = radius;
|
|
1053
|
+
}
|
|
1054
|
+
get center() {
|
|
1055
|
+
return new Point(this.x, this.y);
|
|
1056
|
+
}
|
|
1057
|
+
get left() {
|
|
1058
|
+
return new Point(this.x - this.radius, this.y);
|
|
1059
|
+
}
|
|
1060
|
+
get right() {
|
|
1061
|
+
return new Point(this.x + this.radius, this.y);
|
|
1062
|
+
}
|
|
1063
|
+
get top() {
|
|
1064
|
+
return new Point(this.x, this.y + this.radius);
|
|
1065
|
+
}
|
|
1066
|
+
get bottom() {
|
|
1067
|
+
return new Point(this.x, this.y - this.radius);
|
|
1068
|
+
}
|
|
1069
|
+
get rect() {
|
|
1070
|
+
return new Rect(this.x, this.y, this.radius * 2, this.radius * 2);
|
|
1071
|
+
}
|
|
1072
|
+
distance(p) {
|
|
1073
|
+
return this.center.distance(p) - this.radius;
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
1076
|
+
class Point {
|
|
1077
|
+
constructor(x, y) {
|
|
1078
|
+
this.x = x;
|
|
1079
|
+
this.y = y;
|
|
1080
|
+
}
|
|
1081
|
+
get length() {
|
|
1082
|
+
return this.distance(Point.Zero);
|
|
1083
|
+
}
|
|
1084
|
+
get perpendicular() {
|
|
1085
|
+
return new Point(this.y, -this.x);
|
|
1086
|
+
}
|
|
1087
|
+
add(p) {
|
|
1088
|
+
return new Point(this.x + p.x, this.y + p.y);
|
|
1089
|
+
}
|
|
1090
|
+
subtract(p) {
|
|
1091
|
+
return new Point(this.x - p.x, this.y - p.y);
|
|
1092
|
+
}
|
|
1093
|
+
multiply(p) {
|
|
1094
|
+
if (p instanceof Point) {
|
|
1095
|
+
return new Point(this.x * p.x, this.y * p.y);
|
|
1096
|
+
}
|
|
1097
|
+
return new Point(this.x * p, this.y * p);
|
|
1098
|
+
}
|
|
1099
|
+
distance(b) {
|
|
1100
|
+
const x = b.x - this.x;
|
|
1101
|
+
const y = b.y - this.y;
|
|
1102
|
+
return Math.sqrt(x * x + y * y);
|
|
1103
|
+
}
|
|
1104
|
+
lerp(p, ratio) {
|
|
1105
|
+
const diff = p.subtract(this);
|
|
1106
|
+
return this.add(diff.multiply(ratio));
|
|
1107
|
+
}
|
|
1108
|
+
perpendicularTo(p, length) {
|
|
1109
|
+
const diff = p.perpendicular.subtract(this.perpendicular);
|
|
1110
|
+
const ratio = length / diff.length;
|
|
1111
|
+
const center = this.lerp(p, .5);
|
|
1112
|
+
return center.add(diff.multiply(ratio));
|
|
1113
|
+
}
|
|
1114
|
+
circleWith(a, b) {
|
|
1115
|
+
const yDelta_a = b.y - a.y;
|
|
1116
|
+
const xDelta_a = b.x - a.x;
|
|
1117
|
+
const yDelta_b = this.y - b.y;
|
|
1118
|
+
const xDelta_b = this.x - b.x;
|
|
1119
|
+
const aSlope = yDelta_a / xDelta_a;
|
|
1120
|
+
const bSlope = yDelta_b / xDelta_b;
|
|
1121
|
+
const x = (aSlope * bSlope * (a.y - this.y) + bSlope * (a.x + b.x) - aSlope * (b.x + this.x)) / (2 * (bSlope - aSlope));
|
|
1122
|
+
const y = -1 * (x - (a.x + b.x) / 2) / aSlope + (a.y + b.y) / 2;
|
|
1123
|
+
const center = new Point(x, y);
|
|
1124
|
+
return new Circle(center.x, center.y, center.distance(this));
|
|
1125
|
+
}
|
|
1126
|
+
tangents(c) {
|
|
1127
|
+
const pd = c.center.subtract(this);
|
|
1128
|
+
const a = Math.asin(c.radius / pd.length);
|
|
1129
|
+
const b = Math.atan2(pd.y, pd.x);
|
|
1130
|
+
// Tangent points
|
|
1131
|
+
let t = b - a;
|
|
1132
|
+
const t1 = new Point(c.x + c.radius * Math.sin(t), c.y + c.radius * -Math.cos(t));
|
|
1133
|
+
t = b + a;
|
|
1134
|
+
const t2 = new Point(c.x + c.radius * -Math.sin(t), c.y + c.radius * Math.cos(t));
|
|
1135
|
+
return [t1, t2];
|
|
1136
|
+
}
|
|
1137
|
+
angle(p) {
|
|
1138
|
+
const diff = p.subtract(this);
|
|
1139
|
+
return Math.atan2(diff.y, diff.x) * 180 / Math.PI;
|
|
1140
|
+
}
|
|
1141
|
+
rotateAround(p, angle) {
|
|
1142
|
+
const rotation = (p.angle(this) + angle) * Math.PI / 180;
|
|
1143
|
+
const distance = p.distance(this);
|
|
1144
|
+
const rotated = new Point(Math.cos(rotation) * distance, Math.sin(rotation) * distance);
|
|
1145
|
+
return p.add(rotated);
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
Point.Zero = new Point(0, 0);
|
|
1149
|
+
|
|
1150
|
+
class Initializer {
|
|
1151
|
+
constructor(callback, shouldInit = true) {
|
|
1152
|
+
this.callback = callback;
|
|
1153
|
+
this.shouldInit = shouldInit;
|
|
1154
|
+
this.initialized = !this.shouldInit;
|
|
1155
|
+
// @ts-ignore
|
|
1156
|
+
return Invokable.create(this);
|
|
1157
|
+
}
|
|
1158
|
+
get isInitialized() {
|
|
1159
|
+
return this.initialized;
|
|
1160
|
+
}
|
|
1161
|
+
[Invokable.call]() {
|
|
1162
|
+
if (this.initialized)
|
|
1163
|
+
return null;
|
|
1164
|
+
this.initialized = true;
|
|
1165
|
+
return this.callback();
|
|
1166
|
+
}
|
|
1167
|
+
}
|
|
1168
|
+
|
|
1169
|
+
class LoaderUtils {
|
|
1170
|
+
static loadScript(src, async = false) {
|
|
1171
|
+
this.scriptPromises[src] = this.scriptPromises[src] || new Promise((resolve, reject) => {
|
|
1172
|
+
// Load script
|
|
1173
|
+
const script = document.createElement("script");
|
|
1174
|
+
script.type = "text/javascript";
|
|
1175
|
+
script.src = src;
|
|
1176
|
+
script.async = async;
|
|
1177
|
+
if (script.readyState) {
|
|
1178
|
+
// Internet explorer
|
|
1179
|
+
script.onreadystatechange = () => {
|
|
1180
|
+
if (script.readyState === "loaded" || script.readyState === "complete") {
|
|
1181
|
+
script.onreadystatechange = null;
|
|
1182
|
+
resolve(script);
|
|
1183
|
+
}
|
|
1184
|
+
};
|
|
1185
|
+
}
|
|
1186
|
+
else {
|
|
1187
|
+
// Other browsers
|
|
1188
|
+
script.onload = () => resolve(script);
|
|
1189
|
+
}
|
|
1190
|
+
script.onerror = (error) => reject(error);
|
|
1191
|
+
document.body.appendChild(script);
|
|
1192
|
+
});
|
|
1193
|
+
return this.scriptPromises[src];
|
|
1194
|
+
}
|
|
1195
|
+
static loadStyle(src) {
|
|
1196
|
+
this.stylePromises[src] = this.stylePromises[src] || new Promise((resolve, reject) => {
|
|
1197
|
+
// Load script
|
|
1198
|
+
const link = document.createElement("link");
|
|
1199
|
+
link.rel = "stylesheet";
|
|
1200
|
+
link.type = "text/css";
|
|
1201
|
+
link.href = src;
|
|
1202
|
+
if (link.readyState) {
|
|
1203
|
+
// Internet explorer
|
|
1204
|
+
link.onreadystatechange = () => {
|
|
1205
|
+
if (link.readyState === "loaded" || link.readyState === "complete") {
|
|
1206
|
+
link.onreadystatechange = null;
|
|
1207
|
+
resolve(link);
|
|
1208
|
+
}
|
|
1209
|
+
};
|
|
1210
|
+
}
|
|
1211
|
+
else {
|
|
1212
|
+
// Other browsers
|
|
1213
|
+
link.onload = () => resolve(link);
|
|
1214
|
+
}
|
|
1215
|
+
link.onerror = (error) => reject(error);
|
|
1216
|
+
document.body.appendChild(link);
|
|
1217
|
+
});
|
|
1218
|
+
return this.stylePromises[src];
|
|
1219
|
+
}
|
|
1220
|
+
}
|
|
1221
|
+
LoaderUtils.scriptPromises = {};
|
|
1222
|
+
LoaderUtils.stylePromises = {};
|
|
1223
|
+
|
|
1224
|
+
class MathUtils {
|
|
1225
|
+
static equal(a, b, epsilon = null) {
|
|
1226
|
+
epsilon = ObjectUtils.isNumber(epsilon) ? epsilon : MathUtils.EPSILON;
|
|
1227
|
+
return Math.abs(a - b) < epsilon;
|
|
1228
|
+
}
|
|
1229
|
+
static clamp(value, min, max) {
|
|
1230
|
+
return Math.max(Math.min(value, max), min);
|
|
1231
|
+
}
|
|
1232
|
+
static round(value, precision = 2, divider = 1) {
|
|
1233
|
+
precision = Math.pow(10, precision);
|
|
1234
|
+
return Math.round(value * precision / divider) / precision;
|
|
1235
|
+
}
|
|
1236
|
+
static approxIndex(x, values, epsilon = null) {
|
|
1237
|
+
if (!Array.isArray(values) || values.length == 0) {
|
|
1238
|
+
return -1;
|
|
1239
|
+
}
|
|
1240
|
+
let s = 0;
|
|
1241
|
+
let e = values.length - 1;
|
|
1242
|
+
while (s <= e) {
|
|
1243
|
+
const i = Math.floor((s + e) / 2);
|
|
1244
|
+
const v = values[i];
|
|
1245
|
+
if (MathUtils.equal(v, x, epsilon)) {
|
|
1246
|
+
return i;
|
|
1247
|
+
}
|
|
1248
|
+
if (v < x) {
|
|
1249
|
+
s = i + 1;
|
|
1250
|
+
}
|
|
1251
|
+
else {
|
|
1252
|
+
e = i - 1;
|
|
1253
|
+
}
|
|
1254
|
+
}
|
|
1255
|
+
const m = Math.max(e, 0);
|
|
1256
|
+
const a = values[s];
|
|
1257
|
+
const b = values[m];
|
|
1258
|
+
return Math.abs(a - x) < Math.abs(b - x) ? s : m;
|
|
1259
|
+
}
|
|
1260
|
+
static approximate(x, values, epsilon = null) {
|
|
1261
|
+
var _a;
|
|
1262
|
+
const index = MathUtils.approxIndex(x, values, epsilon);
|
|
1263
|
+
return (_a = values[index]) !== null && _a !== void 0 ? _a : null;
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
MathUtils.EPSILON = 1e-9;
|
|
1267
|
+
|
|
1268
|
+
/**
|
|
1269
|
+
* Use this service to determine which is the current environment
|
|
1270
|
+
*/
|
|
1271
|
+
class UniversalService {
|
|
1272
|
+
constructor(platformId, dds) {
|
|
1273
|
+
this.platformId = platformId;
|
|
1274
|
+
this.dds = dds;
|
|
1275
|
+
const info = this.dds.getDeviceInfo();
|
|
1276
|
+
this.crawler = /(bot|google|baidu|bing|msn|duckduckbot|teoma|slurp|yandex|lighthouse|angular-universal|PTST)/gi.test(info.userAgent);
|
|
1277
|
+
}
|
|
1278
|
+
get isBrowser() {
|
|
1279
|
+
return isPlatformBrowser(this.platformId);
|
|
1280
|
+
}
|
|
1281
|
+
get isServer() {
|
|
1282
|
+
return isPlatformServer(this.platformId);
|
|
1283
|
+
}
|
|
1284
|
+
get deviceInfo() {
|
|
1285
|
+
return this.isServer
|
|
1286
|
+
? {
|
|
1287
|
+
userAgent: "angular-universal",
|
|
1288
|
+
os: "unknown",
|
|
1289
|
+
browser: "node",
|
|
1290
|
+
device: "node",
|
|
1291
|
+
os_version: "unknown",
|
|
1292
|
+
browser_version: "unknown",
|
|
1293
|
+
deviceType: "unknown",
|
|
1294
|
+
orientation: "landscape"
|
|
1295
|
+
}
|
|
1296
|
+
: this.dds.getDeviceInfo();
|
|
1297
|
+
}
|
|
1298
|
+
get browserName() {
|
|
1299
|
+
return this.dds.browser;
|
|
1300
|
+
}
|
|
1301
|
+
get browserVersion() {
|
|
1302
|
+
return this.dds.browser_version;
|
|
1303
|
+
}
|
|
1304
|
+
get isExplorer() {
|
|
1305
|
+
return this.dds.browser == "ie";
|
|
1306
|
+
}
|
|
1307
|
+
get isEdge() {
|
|
1308
|
+
return this.dds.browser == "ms-edge";
|
|
1309
|
+
}
|
|
1310
|
+
get isChrome() {
|
|
1311
|
+
return this.dds.browser == "chrome";
|
|
1312
|
+
}
|
|
1313
|
+
get isFirefox() {
|
|
1314
|
+
return this.dds.browser == "firefox";
|
|
1315
|
+
}
|
|
1316
|
+
get isSafari() {
|
|
1317
|
+
return this.dds.browser == "safari";
|
|
1318
|
+
}
|
|
1319
|
+
get isTablet() {
|
|
1320
|
+
return this.dds.isTablet();
|
|
1321
|
+
}
|
|
1322
|
+
get isMobile() {
|
|
1323
|
+
return this.dds.isMobile();
|
|
1324
|
+
}
|
|
1325
|
+
get isDesktop() {
|
|
1326
|
+
return this.dds.isDesktop();
|
|
1327
|
+
}
|
|
1328
|
+
get isCrawler() {
|
|
1329
|
+
return this.crawler;
|
|
1330
|
+
}
|
|
1331
|
+
}
|
|
1332
|
+
UniversalService.decorators = [
|
|
1333
|
+
{ type: Injectable }
|
|
1334
|
+
];
|
|
1335
|
+
UniversalService.ctorParameters = () => [
|
|
1336
|
+
{ type: String, decorators: [{ type: Inject, args: [PLATFORM_ID,] }] },
|
|
1337
|
+
{ type: DeviceDetectorService }
|
|
1338
|
+
];
|
|
1339
|
+
|
|
1340
|
+
const emptySnapshot = new ActivatedRouteSnapshot();
|
|
1341
|
+
const emptyData = { id: "" };
|
|
1342
|
+
const emptyParams = {};
|
|
1343
|
+
const emptySegments = [];
|
|
1344
|
+
const emptyComponents = [];
|
|
1345
|
+
class StateService extends BehaviorSubject {
|
|
1346
|
+
constructor(injector, zone, universal, router = null) {
|
|
1347
|
+
super(null);
|
|
1348
|
+
this.injector = injector;
|
|
1349
|
+
this.zone = zone;
|
|
1350
|
+
this.universal = universal;
|
|
1351
|
+
this.router = router;
|
|
1352
|
+
this.handleRouterEvent = (event) => {
|
|
1353
|
+
if (!(event instanceof NavigationEnd))
|
|
1354
|
+
return;
|
|
1355
|
+
const routerStateSnapshot = this.router.routerState.snapshot;
|
|
1356
|
+
let snapshot = routerStateSnapshot.root;
|
|
1357
|
+
let context = this.contexts.getContext("primary");
|
|
1358
|
+
let segments = snapshot.url;
|
|
1359
|
+
const components = [];
|
|
1360
|
+
const snapshots = [];
|
|
1361
|
+
while (snapshot) {
|
|
1362
|
+
snapshots.push(snapshot);
|
|
1363
|
+
segments = segments.concat(snapshot.url);
|
|
1364
|
+
if (context) {
|
|
1365
|
+
if (context.outlet && context.outlet.isActivated)
|
|
1366
|
+
components.push(context.outlet.component);
|
|
1367
|
+
context = context.children.getContext("primary");
|
|
1368
|
+
}
|
|
1369
|
+
snapshot = snapshot.firstChild;
|
|
1370
|
+
}
|
|
1371
|
+
this.comp = components[components.length - 1];
|
|
1372
|
+
this.shot = snapshots[snapshots.length - 1];
|
|
1373
|
+
this.stateInfo = {
|
|
1374
|
+
url: routerStateSnapshot.url,
|
|
1375
|
+
segments: segments,
|
|
1376
|
+
components: components
|
|
1377
|
+
};
|
|
1378
|
+
this.next(this.shot);
|
|
1379
|
+
};
|
|
1380
|
+
if (!this.router)
|
|
1381
|
+
return;
|
|
1382
|
+
this.globalExtras = {
|
|
1383
|
+
queryParamsHandling: "merge"
|
|
1384
|
+
};
|
|
1385
|
+
this.router.events.subscribe(this.handleRouterEvent);
|
|
1386
|
+
this.stateInfo = {
|
|
1387
|
+
url: "",
|
|
1388
|
+
segments: [],
|
|
1389
|
+
components: []
|
|
1390
|
+
};
|
|
1391
|
+
this.contexts = router.rootContexts;
|
|
1392
|
+
}
|
|
1393
|
+
static toPath(route, params) {
|
|
1394
|
+
let path = route.path || "";
|
|
1395
|
+
ObjectUtils.iterate(params, (value, key) => {
|
|
1396
|
+
path = path.replace(`:${key}`, `${value}`);
|
|
1397
|
+
});
|
|
1398
|
+
return path;
|
|
1399
|
+
}
|
|
1400
|
+
get component() {
|
|
1401
|
+
return this.comp;
|
|
1402
|
+
}
|
|
1403
|
+
get snapshot() {
|
|
1404
|
+
return this.shot || emptySnapshot;
|
|
1405
|
+
}
|
|
1406
|
+
get route() {
|
|
1407
|
+
return this.snapshot.routeConfig;
|
|
1408
|
+
}
|
|
1409
|
+
get data() {
|
|
1410
|
+
return this.snapshot.data || emptyData;
|
|
1411
|
+
}
|
|
1412
|
+
get params() {
|
|
1413
|
+
return this.snapshot.params || emptyParams;
|
|
1414
|
+
}
|
|
1415
|
+
get queryParams() {
|
|
1416
|
+
return this.snapshot.queryParams || emptyParams;
|
|
1417
|
+
}
|
|
1418
|
+
get url() {
|
|
1419
|
+
return this.stateInfo.url || "";
|
|
1420
|
+
}
|
|
1421
|
+
get urlSegments() {
|
|
1422
|
+
return this.stateInfo.segments || emptySegments;
|
|
1423
|
+
}
|
|
1424
|
+
get components() {
|
|
1425
|
+
return this.stateInfo.components || emptyComponents;
|
|
1426
|
+
}
|
|
1427
|
+
get routerConfig() {
|
|
1428
|
+
return this.router.config;
|
|
1429
|
+
}
|
|
1430
|
+
reload() {
|
|
1431
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1432
|
+
const routerStateSnapshot = this.router.routerState.snapshot;
|
|
1433
|
+
const resolvers = this.route.resolve || {};
|
|
1434
|
+
const keys = Object.keys(resolvers);
|
|
1435
|
+
for (const key of keys) {
|
|
1436
|
+
const resolver = this.injector.get(resolvers[key]);
|
|
1437
|
+
let resolved = resolver.resolve(this.snapshot, routerStateSnapshot);
|
|
1438
|
+
if (resolved instanceof Observable) {
|
|
1439
|
+
resolved = resolved.toPromise();
|
|
1440
|
+
}
|
|
1441
|
+
if (resolved instanceof Promise) {
|
|
1442
|
+
resolved = yield resolved;
|
|
1443
|
+
}
|
|
1444
|
+
this.data[key] = resolved;
|
|
1445
|
+
}
|
|
1446
|
+
});
|
|
1447
|
+
}
|
|
1448
|
+
navigateByUrl(url, navigationExtras = {}) {
|
|
1449
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1450
|
+
return this.navigate(url, navigationExtras);
|
|
1451
|
+
});
|
|
1452
|
+
}
|
|
1453
|
+
navigate(url, navigationExtras = {}) {
|
|
1454
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1455
|
+
if (!this.router)
|
|
1456
|
+
return false;
|
|
1457
|
+
const [tree, extras] = this.createUrlTree(url, navigationExtras);
|
|
1458
|
+
return this.zone.run(() => {
|
|
1459
|
+
return this.router.navigateByUrl(tree, extras);
|
|
1460
|
+
});
|
|
1461
|
+
});
|
|
1462
|
+
}
|
|
1463
|
+
open(url, target = "_blank", navigationExtras = {}) {
|
|
1464
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1465
|
+
if (!this.router)
|
|
1466
|
+
return false;
|
|
1467
|
+
const [tree, extras] = this.createUrlTree(url, navigationExtras);
|
|
1468
|
+
return this.zone.run(() => {
|
|
1469
|
+
return this.openInNewWindow(tree, target) || this.router.navigateByUrl(tree, extras);
|
|
1470
|
+
});
|
|
1471
|
+
});
|
|
1472
|
+
}
|
|
1473
|
+
subscribeImmediately(next, error, complete) {
|
|
1474
|
+
return this.pipe(skipWhile(v => v == null)).subscribe(next, error, complete);
|
|
1475
|
+
}
|
|
1476
|
+
openInNewWindow(tree, target) {
|
|
1477
|
+
if (!this.universal.isBrowser)
|
|
1478
|
+
return false;
|
|
1479
|
+
const baseUrl = window.location.href.replace(this.router.url, "");
|
|
1480
|
+
try {
|
|
1481
|
+
const serialized = this.router.serializeUrl(tree);
|
|
1482
|
+
const separator = serialized.startsWith("/") ? "" : "/";
|
|
1483
|
+
window.open(baseUrl + separator + serialized, target);
|
|
1484
|
+
return true;
|
|
1485
|
+
}
|
|
1486
|
+
catch (e) {
|
|
1487
|
+
console.log(`Can't open new window: ${e}`);
|
|
1488
|
+
return false;
|
|
1489
|
+
}
|
|
1490
|
+
}
|
|
1491
|
+
createUrlTree(url, extras) {
|
|
1492
|
+
if (!this.router)
|
|
1493
|
+
return null;
|
|
1494
|
+
extras = Object.assign(extras, this.globalExtras, extras || {});
|
|
1495
|
+
if (ObjectUtils.isArray(url)) {
|
|
1496
|
+
return [this.router.createUrlTree(url, extras), extras];
|
|
1497
|
+
}
|
|
1498
|
+
if (ObjectUtils.isString(url)) {
|
|
1499
|
+
return [this.router.parseUrl(url), extras];
|
|
1500
|
+
}
|
|
1501
|
+
return [url, extras];
|
|
1502
|
+
}
|
|
1503
|
+
}
|
|
1504
|
+
StateService.decorators = [
|
|
1505
|
+
{ type: Injectable }
|
|
1506
|
+
];
|
|
1507
|
+
StateService.ctorParameters = () => [
|
|
1508
|
+
{ type: Injector },
|
|
1509
|
+
{ type: NgZone },
|
|
1510
|
+
{ type: UniversalService },
|
|
1511
|
+
{ type: Router, decorators: [{ type: Optional }] }
|
|
1512
|
+
];
|
|
1513
|
+
|
|
1514
|
+
class AuthGuard {
|
|
1515
|
+
constructor(injector, state, auth) {
|
|
1516
|
+
this.injector = injector;
|
|
1517
|
+
this.state = state;
|
|
1518
|
+
this.auth = auth;
|
|
1519
|
+
}
|
|
1520
|
+
static guardAuthenticated(auth) {
|
|
1521
|
+
return Promise.resolve(auth.isAuthenticated);
|
|
1522
|
+
}
|
|
1523
|
+
static guardNotAuthenticated(auth) {
|
|
1524
|
+
return Promise.resolve(!auth.isAuthenticated);
|
|
1525
|
+
}
|
|
1526
|
+
static guardNothing() {
|
|
1527
|
+
return Promise.resolve(true);
|
|
1528
|
+
}
|
|
1529
|
+
static guardAuthField(auth, expression = `auth.isAuthenticated`) {
|
|
1530
|
+
// @dynamic
|
|
1531
|
+
const lambda = () => {
|
|
1532
|
+
return Promise.resolve(ObjectUtils.evaluate(expression, { auth }));
|
|
1533
|
+
};
|
|
1534
|
+
return lambda;
|
|
1535
|
+
}
|
|
1536
|
+
static guardStateField(state, expression = `state.data`) {
|
|
1537
|
+
// @dynamic
|
|
1538
|
+
const lambda = () => {
|
|
1539
|
+
return Promise.resolve(ObjectUtils.evaluate(expression, { state }));
|
|
1540
|
+
};
|
|
1541
|
+
return lambda;
|
|
1542
|
+
}
|
|
1543
|
+
static guardAuthStateField(auth, state, expression = `auth.isAuthenticated`) {
|
|
1544
|
+
// @dynamic
|
|
1545
|
+
const lambda = () => {
|
|
1546
|
+
return Promise.resolve(ObjectUtils.evaluate(expression, { auth, state }));
|
|
1547
|
+
};
|
|
1548
|
+
return lambda;
|
|
1549
|
+
}
|
|
1550
|
+
static wildRouteMatch(segments) {
|
|
1551
|
+
return { consumed: segments };
|
|
1552
|
+
}
|
|
1553
|
+
static noRouteMatch() {
|
|
1554
|
+
return null;
|
|
1555
|
+
}
|
|
1556
|
+
checkRouteMenu(route) {
|
|
1557
|
+
if (!route.data || !route.data.name)
|
|
1558
|
+
return Promise.resolve(false);
|
|
1559
|
+
return this.checkRoute(route);
|
|
1560
|
+
}
|
|
1561
|
+
checkRoute(route, next) {
|
|
1562
|
+
const routeData = route.data || {};
|
|
1563
|
+
if (!routeData.guards)
|
|
1564
|
+
return Promise.resolve(!route.canActivate || this.auth.isAuthenticated);
|
|
1565
|
+
return new Promise(resolve => {
|
|
1566
|
+
const guards = routeData.guards.map(g => {
|
|
1567
|
+
const guard = ReflectUtils.resolve(g, this.injector);
|
|
1568
|
+
return guard(this.auth, route, next);
|
|
1569
|
+
});
|
|
1570
|
+
Promise.all(guards).then(results => {
|
|
1571
|
+
resolve(results.indexOf(false) < 0);
|
|
1572
|
+
});
|
|
1573
|
+
});
|
|
1574
|
+
}
|
|
1575
|
+
canActivate(next, state) {
|
|
1576
|
+
const route = next.routeConfig;
|
|
1577
|
+
return new Promise(resolve => {
|
|
1578
|
+
this.auth.checkAuthenticated().then(() => {
|
|
1579
|
+
this.checkRoute(route, next).then(hasRights => {
|
|
1580
|
+
resolve(hasRights);
|
|
1581
|
+
if (!hasRights) {
|
|
1582
|
+
this.getReturnState(route).then(returnState => {
|
|
1583
|
+
if (!returnState)
|
|
1584
|
+
return;
|
|
1585
|
+
this.state.navigate(returnState, { queryParams: next.queryParams });
|
|
1586
|
+
});
|
|
1587
|
+
}
|
|
1588
|
+
});
|
|
1589
|
+
});
|
|
1590
|
+
});
|
|
1591
|
+
}
|
|
1592
|
+
getConfig(route, config, path) {
|
|
1593
|
+
if (!config)
|
|
1594
|
+
return null;
|
|
1595
|
+
const match = config.findIndex(t => t == route);
|
|
1596
|
+
if (match >= 0)
|
|
1597
|
+
return config;
|
|
1598
|
+
for (const subConfig of config) {
|
|
1599
|
+
if (subConfig.path)
|
|
1600
|
+
path.push(subConfig.path);
|
|
1601
|
+
const loadedChildren = (subConfig["_loadedConfig"] || { routes: null }).routes;
|
|
1602
|
+
const match = this.getConfig(route, subConfig.children || loadedChildren, path);
|
|
1603
|
+
if (!match) {
|
|
1604
|
+
if (subConfig.path)
|
|
1605
|
+
path.length -= 1;
|
|
1606
|
+
continue;
|
|
1607
|
+
}
|
|
1608
|
+
return match;
|
|
1609
|
+
}
|
|
1610
|
+
return null;
|
|
1611
|
+
}
|
|
1612
|
+
getReturnState(route) {
|
|
1613
|
+
if (!route)
|
|
1614
|
+
return Promise.resolve(null);
|
|
1615
|
+
if (ObjectUtils.isObject(route.data) && ObjectUtils.isArray(route.data.returnState)) {
|
|
1616
|
+
return Promise.resolve(route.data.returnState);
|
|
1617
|
+
}
|
|
1618
|
+
const path = [];
|
|
1619
|
+
const config = this.getConfig(route, this.state.routerConfig, path);
|
|
1620
|
+
return new Promise(resolve => {
|
|
1621
|
+
this.getReturnStateRecursive(config).then(rs => {
|
|
1622
|
+
if (!ObjectUtils.isArray(rs)) {
|
|
1623
|
+
resolve(rs);
|
|
1624
|
+
return;
|
|
1625
|
+
}
|
|
1626
|
+
resolve(path.concat(rs));
|
|
1627
|
+
});
|
|
1628
|
+
});
|
|
1629
|
+
}
|
|
1630
|
+
getReturnStateRecursive(config, c = 0) {
|
|
1631
|
+
if (!config || c >= config.length)
|
|
1632
|
+
return Promise.resolve(null);
|
|
1633
|
+
return new Promise(resolve => {
|
|
1634
|
+
const route = config[c];
|
|
1635
|
+
const check = !route.component ? Promise.resolve(false) : this.checkRoute(route);
|
|
1636
|
+
check.then(res => {
|
|
1637
|
+
if (res) {
|
|
1638
|
+
resolve([route.path]);
|
|
1639
|
+
return;
|
|
1640
|
+
}
|
|
1641
|
+
this.getReturnStateRecursive(config, c + 1).then(resolve);
|
|
1642
|
+
});
|
|
1643
|
+
});
|
|
1644
|
+
}
|
|
1645
|
+
}
|
|
1646
|
+
AuthGuard.decorators = [
|
|
1647
|
+
{ type: Injectable }
|
|
1648
|
+
];
|
|
1649
|
+
AuthGuard.ctorParameters = () => [
|
|
1650
|
+
{ type: Injector, decorators: [{ type: Inject, args: [Injector,] }] },
|
|
1651
|
+
{ type: StateService, decorators: [{ type: Inject, args: [StateService,] }] },
|
|
1652
|
+
{ type: undefined, decorators: [{ type: Inject, args: [AUTH_SERVICE,] }] }
|
|
1653
|
+
];
|
|
1654
|
+
__decorate([
|
|
1655
|
+
FactoryDependencies(AUTH_SERVICE)
|
|
1656
|
+
], AuthGuard, "guardAuthField", null);
|
|
1657
|
+
__decorate([
|
|
1658
|
+
FactoryDependencies(StateService)
|
|
1659
|
+
], AuthGuard, "guardStateField", null);
|
|
1660
|
+
__decorate([
|
|
1661
|
+
FactoryDependencies(AUTH_SERVICE, StateService)
|
|
1662
|
+
], AuthGuard, "guardAuthStateField", null);
|
|
1663
|
+
|
|
1664
|
+
class TimerUtils {
|
|
1665
|
+
static createTimeout(func, time) {
|
|
1666
|
+
// @dynamic
|
|
1667
|
+
const run = (timer) => {
|
|
1668
|
+
timer.clear();
|
|
1669
|
+
timer.id = setTimeout(() => {
|
|
1670
|
+
timer.id = null;
|
|
1671
|
+
timer.func();
|
|
1672
|
+
}, timer.time);
|
|
1673
|
+
};
|
|
1674
|
+
// @dynamic
|
|
1675
|
+
const clear = (timer) => {
|
|
1676
|
+
if (!timer.id)
|
|
1677
|
+
return;
|
|
1678
|
+
clearTimeout(timer.id);
|
|
1679
|
+
timer.id = null;
|
|
1680
|
+
};
|
|
1681
|
+
return TimerUtils.createTimer(run, clear, func, time);
|
|
1682
|
+
}
|
|
1683
|
+
static createInterval(func, time) {
|
|
1684
|
+
// @dynamic
|
|
1685
|
+
const run = (timer) => {
|
|
1686
|
+
timer.clear();
|
|
1687
|
+
timer.id = setInterval(timer.func, timer.time);
|
|
1688
|
+
};
|
|
1689
|
+
// @dynamic
|
|
1690
|
+
const clear = (timer) => {
|
|
1691
|
+
if (!timer.id)
|
|
1692
|
+
return;
|
|
1693
|
+
clearInterval(timer.id);
|
|
1694
|
+
timer.id = null;
|
|
1695
|
+
};
|
|
1696
|
+
return TimerUtils.createTimer(run, clear, func, time);
|
|
1697
|
+
}
|
|
1698
|
+
static createTimer(run, clear, func, time) {
|
|
1699
|
+
const timer = {};
|
|
1700
|
+
const setParams = (func, time) => {
|
|
1701
|
+
timer.func = !ObjectUtils.isFunction(func) ? (() => { }) : func;
|
|
1702
|
+
timer.time = !ObjectUtils.isNumber(time) ? 100 : time;
|
|
1703
|
+
};
|
|
1704
|
+
timer.run = () => run(timer);
|
|
1705
|
+
timer.clear = () => clear(timer);
|
|
1706
|
+
timer.set = (func, time) => {
|
|
1707
|
+
setParams(func, time);
|
|
1708
|
+
timer.run();
|
|
1709
|
+
};
|
|
1710
|
+
setParams(func, time);
|
|
1711
|
+
return timer;
|
|
1712
|
+
}
|
|
1713
|
+
}
|
|
1714
|
+
|
|
1715
|
+
class ObservableUtils {
|
|
1716
|
+
static toSearch(search) {
|
|
1717
|
+
return mergeMap(
|
|
1718
|
+
// @dynamic
|
|
1719
|
+
(token) => search.getSearchResults(token))(Observable.create(
|
|
1720
|
+
// @dynamic
|
|
1721
|
+
(observer) => {
|
|
1722
|
+
observer.next(search.search);
|
|
1723
|
+
}));
|
|
1724
|
+
}
|
|
1725
|
+
static multiSubscription(...subscriptions) {
|
|
1726
|
+
// @dynamic
|
|
1727
|
+
const lambda = () => {
|
|
1728
|
+
subscriptions.forEach(s => {
|
|
1729
|
+
s.unsubscribe();
|
|
1730
|
+
});
|
|
1731
|
+
};
|
|
1732
|
+
return new Subscription(lambda);
|
|
1733
|
+
}
|
|
1734
|
+
static subscribe(...subscribers) {
|
|
1735
|
+
const subscriptions = [];
|
|
1736
|
+
subscribers.forEach(info => {
|
|
1737
|
+
let alreadyCalled = false;
|
|
1738
|
+
const timer = info.timeout > 0 ? TimerUtils.createTimeout() : 0;
|
|
1739
|
+
const cb = timer ? function () {
|
|
1740
|
+
const args = Array.from(arguments);
|
|
1741
|
+
timer.set(() => {
|
|
1742
|
+
info.cb.apply(null, args);
|
|
1743
|
+
}, info.timeout);
|
|
1744
|
+
} : info.cb;
|
|
1745
|
+
info.subjects.forEach(subject => {
|
|
1746
|
+
const ss = subject.subscribe((value) => {
|
|
1747
|
+
alreadyCalled = true;
|
|
1748
|
+
cb.call(null, subject, value);
|
|
1749
|
+
});
|
|
1750
|
+
subscriptions.push(ss);
|
|
1751
|
+
});
|
|
1752
|
+
if (alreadyCalled)
|
|
1753
|
+
return;
|
|
1754
|
+
cb();
|
|
1755
|
+
});
|
|
1756
|
+
return ObservableUtils.multiSubscription(...subscriptions);
|
|
1757
|
+
}
|
|
1758
|
+
static fromFunction(callbackFunc) {
|
|
1759
|
+
let subject;
|
|
1760
|
+
return new Observable((subscriber) => {
|
|
1761
|
+
if (!subject) {
|
|
1762
|
+
subject = new Subject();
|
|
1763
|
+
try {
|
|
1764
|
+
subject = from(callbackFunc());
|
|
1765
|
+
}
|
|
1766
|
+
catch (err) {
|
|
1767
|
+
subject.error(err);
|
|
1768
|
+
}
|
|
1769
|
+
}
|
|
1770
|
+
return subject.subscribe(subscriber);
|
|
1771
|
+
});
|
|
1772
|
+
}
|
|
1773
|
+
}
|
|
1774
|
+
|
|
1775
|
+
class StringUtils {
|
|
1776
|
+
static concat(separator, ...strings) {
|
|
1777
|
+
return strings.filter(
|
|
1778
|
+
// @dynamic
|
|
1779
|
+
str => !!str).join(separator);
|
|
1780
|
+
}
|
|
1781
|
+
static startsWith(str, ...starts) {
|
|
1782
|
+
for (let i = 0; i < starts.length; i++) {
|
|
1783
|
+
if (str.startsWith(starts[i]))
|
|
1784
|
+
return true;
|
|
1785
|
+
}
|
|
1786
|
+
return false;
|
|
1787
|
+
}
|
|
1788
|
+
static has(str, ...parts) {
|
|
1789
|
+
for (let i = 0; i < parts.length; i++) {
|
|
1790
|
+
if (str.indexOf(parts[i]) >= 0)
|
|
1791
|
+
return true;
|
|
1792
|
+
}
|
|
1793
|
+
return false;
|
|
1794
|
+
}
|
|
1795
|
+
static lcFirst(str) {
|
|
1796
|
+
return str ? str.charAt(0).toLowerCase() + str.substring(1) : "";
|
|
1797
|
+
}
|
|
1798
|
+
static ucFirst(str) {
|
|
1799
|
+
return str ? str.charAt(0).toUpperCase() + str.substring(1) : "";
|
|
1800
|
+
}
|
|
1801
|
+
}
|
|
1802
|
+
|
|
1803
|
+
class ArrayUtils {
|
|
1804
|
+
static has(arr, ...items) {
|
|
1805
|
+
if (!ObjectUtils.isArray(arr) || !ObjectUtils.isArray(items))
|
|
1806
|
+
return false;
|
|
1807
|
+
for (let i = 0; i < items.length; i++) {
|
|
1808
|
+
if (arr.indexOf(items[i]) >= 0)
|
|
1809
|
+
return true;
|
|
1810
|
+
}
|
|
1811
|
+
return false;
|
|
1812
|
+
}
|
|
1813
|
+
static match(arr, str) {
|
|
1814
|
+
if (!ObjectUtils.isArray(arr) || !ObjectUtils.isString(str))
|
|
1815
|
+
return false;
|
|
1816
|
+
for (let i = 0; i < arr.length; i++) {
|
|
1817
|
+
if (arr[i] instanceof RegExp) {
|
|
1818
|
+
const regex = arr[i];
|
|
1819
|
+
if (regex.test(str))
|
|
1820
|
+
return true;
|
|
1821
|
+
}
|
|
1822
|
+
}
|
|
1823
|
+
return false;
|
|
1824
|
+
}
|
|
1825
|
+
static any(arr, cb) {
|
|
1826
|
+
if (!ObjectUtils.isArray(arr) || !ObjectUtils.isFunction(cb))
|
|
1827
|
+
return false;
|
|
1828
|
+
for (let i = 0; i < arr.length; i++) {
|
|
1829
|
+
if (cb(arr[i]))
|
|
1830
|
+
return true;
|
|
1831
|
+
}
|
|
1832
|
+
return false;
|
|
1833
|
+
}
|
|
1834
|
+
static move(arr, oldIndex, newIndex) {
|
|
1835
|
+
if (!ObjectUtils.isArray(arr))
|
|
1836
|
+
return [];
|
|
1837
|
+
const length = arr.length;
|
|
1838
|
+
while (oldIndex < 0) {
|
|
1839
|
+
oldIndex += length;
|
|
1840
|
+
}
|
|
1841
|
+
while (newIndex < 0) {
|
|
1842
|
+
newIndex += length;
|
|
1843
|
+
}
|
|
1844
|
+
if (newIndex >= length) {
|
|
1845
|
+
let k = newIndex - length + 1;
|
|
1846
|
+
while (k--) {
|
|
1847
|
+
arr.push(undefined);
|
|
1848
|
+
}
|
|
1849
|
+
}
|
|
1850
|
+
arr.splice(newIndex, 0, arr.splice(oldIndex, 1)[0]);
|
|
1851
|
+
return arr;
|
|
1852
|
+
}
|
|
1853
|
+
static reversed(arr) {
|
|
1854
|
+
const result = [];
|
|
1855
|
+
if (!ObjectUtils.isArray(arr))
|
|
1856
|
+
return result;
|
|
1857
|
+
for (let i = arr.length - 1; i >= 0; i--) {
|
|
1858
|
+
result.push(arr[i]);
|
|
1859
|
+
}
|
|
1860
|
+
return result;
|
|
1861
|
+
}
|
|
1862
|
+
static min(arr, cb) {
|
|
1863
|
+
if (!ObjectUtils.isArray(arr))
|
|
1864
|
+
return null;
|
|
1865
|
+
let min = Number.MAX_SAFE_INTEGER;
|
|
1866
|
+
let result = null;
|
|
1867
|
+
for (let i = 0; i < arr.length; i++) {
|
|
1868
|
+
const current = cb(arr[i], i);
|
|
1869
|
+
if (current < min || result === null) {
|
|
1870
|
+
min = current;
|
|
1871
|
+
result = arr[i];
|
|
1872
|
+
}
|
|
1873
|
+
}
|
|
1874
|
+
return result;
|
|
1875
|
+
}
|
|
1876
|
+
static max(arr, cb) {
|
|
1877
|
+
if (!ObjectUtils.isArray(arr))
|
|
1878
|
+
return null;
|
|
1879
|
+
let max = Number.MIN_SAFE_INTEGER;
|
|
1880
|
+
let result = null;
|
|
1881
|
+
for (let i = 0; i < arr.length; i++) {
|
|
1882
|
+
const current = cb(arr[i], i);
|
|
1883
|
+
if (current > max || result === null) {
|
|
1884
|
+
max = current;
|
|
1885
|
+
result = arr[i];
|
|
1886
|
+
}
|
|
1887
|
+
}
|
|
1888
|
+
return result;
|
|
1889
|
+
}
|
|
1890
|
+
static chunk(arr, size) {
|
|
1891
|
+
if (!ObjectUtils.isArray(arr))
|
|
1892
|
+
return [];
|
|
1893
|
+
size = Math.max(1, size);
|
|
1894
|
+
const result = [];
|
|
1895
|
+
for (let i = 0; i < arr.length; i += size) {
|
|
1896
|
+
result.push(arr.slice(i, i + size));
|
|
1897
|
+
}
|
|
1898
|
+
return result;
|
|
1899
|
+
}
|
|
1900
|
+
static unique(arr) {
|
|
1901
|
+
if (!ObjectUtils.isArray(arr))
|
|
1902
|
+
return [];
|
|
1903
|
+
return arr.filter((value, index, self) => {
|
|
1904
|
+
return self.indexOf(value) === index;
|
|
1905
|
+
});
|
|
1906
|
+
}
|
|
1907
|
+
}
|
|
1908
|
+
|
|
1909
|
+
class SetUtils {
|
|
1910
|
+
static equals(set, obj) {
|
|
1911
|
+
if (!ObjectUtils.isSet(set) || !ObjectUtils.isSet(obj))
|
|
1912
|
+
return false;
|
|
1913
|
+
if (set.size != obj.size)
|
|
1914
|
+
return false;
|
|
1915
|
+
for (const item in set) {
|
|
1916
|
+
if (!obj.has(item))
|
|
1917
|
+
return false;
|
|
1918
|
+
}
|
|
1919
|
+
return true;
|
|
1920
|
+
}
|
|
1921
|
+
static addArray(set, items) {
|
|
1922
|
+
if (!ObjectUtils.isSet(set) || !ObjectUtils.isArray(items))
|
|
1923
|
+
return;
|
|
1924
|
+
items.forEach(i => set.add(i));
|
|
1925
|
+
}
|
|
1926
|
+
}
|
|
1927
|
+
|
|
1928
|
+
class UniqueUtils {
|
|
1929
|
+
static uuid() {
|
|
1930
|
+
if (typeof window !== "undefined" && typeof window.crypto !== "undefined" && typeof window.crypto.getRandomValues !== "undefined") {
|
|
1931
|
+
const buf = new Uint16Array(8);
|
|
1932
|
+
window.crypto.getRandomValues(buf);
|
|
1933
|
+
return (this.pad4(buf[0]) + this.pad4(buf[1]) + "-" + this.pad4(buf[2]) + "-" + this.pad4(buf[3]) + "-" + this.pad4(buf[4]) + "-" + this.pad4(buf[5]) + this.pad4(buf[6]) + this.pad4(buf[7]));
|
|
1934
|
+
}
|
|
1935
|
+
return this.random4() + this.random4() + "-" + this.random4() + "-" + this.random4() + "-" +
|
|
1936
|
+
this.random4() + "-" + this.random4() + this.random4() + this.random4();
|
|
1937
|
+
}
|
|
1938
|
+
static pad4(num) {
|
|
1939
|
+
let ret = num.toString(16);
|
|
1940
|
+
while (ret.length < 4) {
|
|
1941
|
+
ret = "0" + ret;
|
|
1942
|
+
}
|
|
1943
|
+
return ret;
|
|
1944
|
+
}
|
|
1945
|
+
static random4() {
|
|
1946
|
+
return Math.floor((1 + Math.random()) * 0x10000)
|
|
1947
|
+
.toString(16)
|
|
1948
|
+
.substring(1);
|
|
1949
|
+
}
|
|
1950
|
+
}
|
|
1951
|
+
|
|
1952
|
+
class Vector {
|
|
1953
|
+
constructor(x, y, z) {
|
|
1954
|
+
this.x = x;
|
|
1955
|
+
this.y = y;
|
|
1956
|
+
this.z = z;
|
|
1957
|
+
}
|
|
1958
|
+
get negative() {
|
|
1959
|
+
return new Vector(-this.x, -this.y, -this.z);
|
|
1960
|
+
}
|
|
1961
|
+
get length() {
|
|
1962
|
+
return Math.sqrt(this.dot(this));
|
|
1963
|
+
}
|
|
1964
|
+
get unit() {
|
|
1965
|
+
return this.divide(this.length);
|
|
1966
|
+
}
|
|
1967
|
+
get min() {
|
|
1968
|
+
return Math.min(Math.min(this.x, this.y), this.z);
|
|
1969
|
+
}
|
|
1970
|
+
get max() {
|
|
1971
|
+
return Math.max(Math.max(this.x, this.y), this.z);
|
|
1972
|
+
}
|
|
1973
|
+
get angles() {
|
|
1974
|
+
return {
|
|
1975
|
+
theta: Math.atan2(this.z, this.x),
|
|
1976
|
+
phi: Math.asin(this.y / this.length)
|
|
1977
|
+
};
|
|
1978
|
+
}
|
|
1979
|
+
add(v) {
|
|
1980
|
+
if (v instanceof Vector)
|
|
1981
|
+
return new Vector(this.x + v.x, this.y + v.y, this.z + v.z);
|
|
1982
|
+
else
|
|
1983
|
+
return new Vector(this.x + v, this.y + v, this.z + v);
|
|
1984
|
+
}
|
|
1985
|
+
subtract(v) {
|
|
1986
|
+
if (v instanceof Vector)
|
|
1987
|
+
return new Vector(this.x - v.x, this.y - v.y, this.z - v.z);
|
|
1988
|
+
else
|
|
1989
|
+
return new Vector(this.x - v, this.y - v, this.z - v);
|
|
1990
|
+
}
|
|
1991
|
+
multiply(v) {
|
|
1992
|
+
if (v instanceof Vector)
|
|
1993
|
+
return new Vector(this.x * v.x, this.y * v.y, this.z * v.z);
|
|
1994
|
+
else
|
|
1995
|
+
return new Vector(this.x * v, this.y * v, this.z * v);
|
|
1996
|
+
}
|
|
1997
|
+
divide(v) {
|
|
1998
|
+
if (v instanceof Vector)
|
|
1999
|
+
return new Vector(this.x / v.x, this.y / v.y, this.z / v.z);
|
|
2000
|
+
else
|
|
2001
|
+
return new Vector(this.x / v, this.y / v, this.z / v);
|
|
2002
|
+
}
|
|
2003
|
+
equals(v) {
|
|
2004
|
+
return this.x == v.x && this.y == v.y && this.z == v.z;
|
|
2005
|
+
}
|
|
2006
|
+
dot(v) {
|
|
2007
|
+
return this.x * v.x + this.y * v.y + this.z * v.z;
|
|
2008
|
+
}
|
|
2009
|
+
cross(v) {
|
|
2010
|
+
return new Vector(this.y * v.z - this.z * v.y, this.z * v.x - this.x * v.z, this.x * v.y - this.y * v.x);
|
|
2011
|
+
}
|
|
2012
|
+
angleTo(v) {
|
|
2013
|
+
return Math.acos(this.dot(v) / (this.length * v.length));
|
|
2014
|
+
}
|
|
2015
|
+
toArray(n) {
|
|
2016
|
+
return [this.x, this.y, this.z].slice(0, n || 3);
|
|
2017
|
+
}
|
|
2018
|
+
clone() {
|
|
2019
|
+
return new Vector(this.x, this.y, this.z);
|
|
2020
|
+
}
|
|
2021
|
+
init(x, y, z) {
|
|
2022
|
+
this.x = x;
|
|
2023
|
+
this.y = y;
|
|
2024
|
+
this.z = z;
|
|
2025
|
+
return this;
|
|
2026
|
+
}
|
|
2027
|
+
}
|
|
2028
|
+
|
|
2029
|
+
const emptyGuards = [];
|
|
2030
|
+
class AclService {
|
|
2031
|
+
constructor(injector, state, auth) {
|
|
2032
|
+
this.injector = injector;
|
|
2033
|
+
this.state = state;
|
|
2034
|
+
this.auth = auth;
|
|
2035
|
+
this.components = [];
|
|
2036
|
+
this.auth.userChanged.subscribe(() => {
|
|
2037
|
+
this.components.forEach(t => t.dirty = true);
|
|
2038
|
+
const info = this.getStateInfo();
|
|
2039
|
+
const check = info && info.guard instanceof AuthGuard ? info.guard.checkRoute(info.route) : Promise.resolve(true);
|
|
2040
|
+
check.then(result => {
|
|
2041
|
+
if (result) {
|
|
2042
|
+
if (!info || !info.dirty)
|
|
2043
|
+
return;
|
|
2044
|
+
info.dirty = false;
|
|
2045
|
+
const component = info.component;
|
|
2046
|
+
if (!info.component)
|
|
2047
|
+
return;
|
|
2048
|
+
if (info.first) {
|
|
2049
|
+
if (ObjectUtils.isFunction(component.onUserInitialized)) {
|
|
2050
|
+
component.onUserInitialized();
|
|
2051
|
+
}
|
|
2052
|
+
info.first = false;
|
|
2053
|
+
return;
|
|
2054
|
+
}
|
|
2055
|
+
if (ObjectUtils.isFunction(component.onUserChanged)) {
|
|
2056
|
+
component.onUserChanged();
|
|
2057
|
+
}
|
|
2058
|
+
return;
|
|
2059
|
+
}
|
|
2060
|
+
info.guard.getReturnState(info.route).then(returnState => {
|
|
2061
|
+
if (!returnState)
|
|
2062
|
+
return;
|
|
2063
|
+
this.state.navigate(returnState);
|
|
2064
|
+
});
|
|
2065
|
+
});
|
|
2066
|
+
});
|
|
2067
|
+
this.state.subscribe(() => {
|
|
2068
|
+
const info = this.getStateInfo();
|
|
2069
|
+
if (!(info === null || info === void 0 ? void 0 : info.component))
|
|
2070
|
+
return;
|
|
2071
|
+
const component = info.component;
|
|
2072
|
+
if (ObjectUtils.isFunction(component.onUserInitialized)) {
|
|
2073
|
+
component.onUserInitialized();
|
|
2074
|
+
}
|
|
2075
|
+
});
|
|
2076
|
+
}
|
|
2077
|
+
getStateInfo() {
|
|
2078
|
+
const route = this.state.route;
|
|
2079
|
+
if (!route)
|
|
2080
|
+
return null;
|
|
2081
|
+
let info = this.components.find(t => t.route == this.state.route);
|
|
2082
|
+
if (!info) {
|
|
2083
|
+
const guardType = (route.canActivate || emptyGuards)[0];
|
|
2084
|
+
info = {
|
|
2085
|
+
route: this.state.route,
|
|
2086
|
+
guard: guardType ? this.injector.get(guardType) : null,
|
|
2087
|
+
dirty: true,
|
|
2088
|
+
first: true
|
|
2089
|
+
};
|
|
2090
|
+
this.components.push(info);
|
|
2091
|
+
}
|
|
2092
|
+
info.component = this.state.component;
|
|
2093
|
+
return info;
|
|
2094
|
+
}
|
|
2095
|
+
}
|
|
2096
|
+
AclService.decorators = [
|
|
2097
|
+
{ type: Injectable }
|
|
2098
|
+
];
|
|
2099
|
+
AclService.ctorParameters = () => [
|
|
2100
|
+
{ type: Injector },
|
|
2101
|
+
{ type: StateService },
|
|
2102
|
+
{ type: undefined, decorators: [{ type: Inject, args: [AUTH_SERVICE,] }] }
|
|
2103
|
+
];
|
|
2104
|
+
|
|
2105
|
+
class BaseHttpClient extends HttpClient {
|
|
2106
|
+
constructor(handler) {
|
|
2107
|
+
super(handler);
|
|
2108
|
+
this.requestHeaders = {};
|
|
2109
|
+
this.requestParams = {};
|
|
2110
|
+
this.extraRequestParams = {
|
|
2111
|
+
language: "en"
|
|
2112
|
+
};
|
|
2113
|
+
}
|
|
2114
|
+
makeHeaders(headers, withCredentials = true) {
|
|
2115
|
+
headers = Object.assign({}, this.requestHeaders, headers);
|
|
2116
|
+
const authHeader = headers["Authorization"] || "";
|
|
2117
|
+
if (!withCredentials && !authHeader.startsWith("Bearer")) {
|
|
2118
|
+
delete headers["Authorization"];
|
|
2119
|
+
}
|
|
2120
|
+
return new HttpHeaders(headers);
|
|
2121
|
+
}
|
|
2122
|
+
makeParams(params) {
|
|
2123
|
+
params = Object.assign({}, this.extraRequestParams, this.requestParams, params);
|
|
2124
|
+
return new HttpParams({
|
|
2125
|
+
encoder: new HttpUrlEncodingCodec(),
|
|
2126
|
+
fromObject: Object.keys(params || {}).reduce((result, key) => {
|
|
2127
|
+
const value = params[key];
|
|
2128
|
+
result[key] = ObjectUtils.isObject(value) ? JSON.stringify(value) : (ObjectUtils.isNullOrUndefined(value) ? "" : value.toString());
|
|
2129
|
+
return result;
|
|
2130
|
+
}, {})
|
|
2131
|
+
});
|
|
2132
|
+
}
|
|
2133
|
+
setExtraRequestParam(name, value) {
|
|
2134
|
+
if (typeof value == "undefined") {
|
|
2135
|
+
delete this.extraRequestParams[name];
|
|
2136
|
+
return;
|
|
2137
|
+
}
|
|
2138
|
+
this.extraRequestParams[name] = value;
|
|
2139
|
+
}
|
|
2140
|
+
}
|
|
2141
|
+
BaseHttpClient.decorators = [
|
|
2142
|
+
{ type: Injectable }
|
|
2143
|
+
];
|
|
2144
|
+
BaseHttpClient.ctorParameters = () => [
|
|
2145
|
+
{ type: HttpHandler }
|
|
2146
|
+
];
|
|
2147
|
+
|
|
2148
|
+
/**
|
|
2149
|
+
* Use this service instead of Storage to avoid Angular Universal breaks on server environment
|
|
2150
|
+
*/
|
|
2151
|
+
class StorageService {
|
|
2152
|
+
constructor(universal) {
|
|
2153
|
+
this.universal = universal;
|
|
2154
|
+
}
|
|
2155
|
+
get(key, defaultValue, mode = StorageMode.Local) {
|
|
2156
|
+
if (!this.universal.isBrowser)
|
|
2157
|
+
return defaultValue;
|
|
2158
|
+
const storage = mode == StorageMode.Local ? localStorage : sessionStorage;
|
|
2159
|
+
const item = storage.getItem(key);
|
|
2160
|
+
if (!item)
|
|
2161
|
+
return defaultValue;
|
|
2162
|
+
try {
|
|
2163
|
+
return JSON.parse(item);
|
|
2164
|
+
}
|
|
2165
|
+
catch (e) {
|
|
2166
|
+
return item;
|
|
2167
|
+
}
|
|
2168
|
+
}
|
|
2169
|
+
set(key, value, mode = StorageMode.Local) {
|
|
2170
|
+
if (!this.universal.isBrowser)
|
|
2171
|
+
return;
|
|
2172
|
+
const storage = mode == StorageMode.Local ? localStorage : sessionStorage;
|
|
2173
|
+
if (typeof value == "string") {
|
|
2174
|
+
storage.setItem(key, value);
|
|
2175
|
+
return;
|
|
2176
|
+
}
|
|
2177
|
+
storage.setItem(key, JSON.stringify(value));
|
|
2178
|
+
}
|
|
2179
|
+
remove(key, mode = StorageMode.Local) {
|
|
2180
|
+
if (!this.universal.isBrowser)
|
|
2181
|
+
return;
|
|
2182
|
+
const storage = mode == StorageMode.Local ? localStorage : sessionStorage;
|
|
2183
|
+
storage.removeItem(key);
|
|
2184
|
+
}
|
|
2185
|
+
}
|
|
2186
|
+
StorageService.decorators = [
|
|
2187
|
+
{ type: Injectable }
|
|
2188
|
+
];
|
|
2189
|
+
StorageService.ctorParameters = () => [
|
|
2190
|
+
{ type: UniversalService }
|
|
2191
|
+
];
|
|
2192
|
+
|
|
2193
|
+
class BaseHttpService {
|
|
2194
|
+
constructor(client, storage, language, toaster, configs, request = null) {
|
|
2195
|
+
this.client = client;
|
|
2196
|
+
this.storage = storage;
|
|
2197
|
+
this.language = language;
|
|
2198
|
+
this.toaster = toaster;
|
|
2199
|
+
this.configs = configs;
|
|
2200
|
+
this.request = request;
|
|
2201
|
+
this.requestHeaders = {};
|
|
2202
|
+
this.requestParams = {};
|
|
2203
|
+
this.cache = {};
|
|
2204
|
+
}
|
|
2205
|
+
get name() {
|
|
2206
|
+
return "base";
|
|
2207
|
+
}
|
|
2208
|
+
get withCredentials() {
|
|
2209
|
+
return true;
|
|
2210
|
+
}
|
|
2211
|
+
static retryFailedRequests() {
|
|
2212
|
+
BaseHttpService.failedRequests.forEach(r => r());
|
|
2213
|
+
BaseHttpService.failedRequests = [];
|
|
2214
|
+
}
|
|
2215
|
+
get universal() {
|
|
2216
|
+
return this.storage.universal;
|
|
2217
|
+
}
|
|
2218
|
+
url(url) {
|
|
2219
|
+
return url;
|
|
2220
|
+
}
|
|
2221
|
+
createUrl(url, params) {
|
|
2222
|
+
const httpParams = this.client.makeParams(params);
|
|
2223
|
+
const query = httpParams.keys().map(key => {
|
|
2224
|
+
return `${key}=${httpParams.get(key)}`;
|
|
2225
|
+
}).join("&");
|
|
2226
|
+
return `${this.url(url)}?${query}`;
|
|
2227
|
+
}
|
|
2228
|
+
makeListParams(page, itemsPerPage, orderBy = null, orderDescending = null, filter = null) {
|
|
2229
|
+
const params = {
|
|
2230
|
+
page: (page - 1),
|
|
2231
|
+
limit: itemsPerPage
|
|
2232
|
+
};
|
|
2233
|
+
if (!ObjectUtils.isNullOrUndefined(orderBy) && !ObjectUtils.isNullOrUndefined(orderDescending)) {
|
|
2234
|
+
params.sort = `${orderDescending ? "-" : ""}${orderBy}`;
|
|
2235
|
+
}
|
|
2236
|
+
if (!ObjectUtils.isNullOrUndefined(filter)) {
|
|
2237
|
+
params.filter = filter;
|
|
2238
|
+
}
|
|
2239
|
+
return params;
|
|
2240
|
+
}
|
|
2241
|
+
getPromise(url, options, body) {
|
|
2242
|
+
options = this.makeOptions(options, "GET", body);
|
|
2243
|
+
return this.toPromise(url, options);
|
|
2244
|
+
}
|
|
2245
|
+
deletePromise(url, options, body) {
|
|
2246
|
+
options = this.makeOptions(options, "DELETE", body);
|
|
2247
|
+
return this.toPromise(url, options);
|
|
2248
|
+
}
|
|
2249
|
+
postPromise(url, body, options) {
|
|
2250
|
+
options = this.makeOptions(options, "POST", body);
|
|
2251
|
+
return this.toPromise(url, options);
|
|
2252
|
+
}
|
|
2253
|
+
putPromise(url, body, options) {
|
|
2254
|
+
options = this.makeOptions(options, "PUT", body);
|
|
2255
|
+
return this.toPromise(url, options);
|
|
2256
|
+
}
|
|
2257
|
+
patchPromise(url, body, options) {
|
|
2258
|
+
options = this.makeOptions(options, "PATCH", body);
|
|
2259
|
+
return this.toPromise(url, options);
|
|
2260
|
+
}
|
|
2261
|
+
uploadPromise(url, body, listener, options) {
|
|
2262
|
+
const headers = {};
|
|
2263
|
+
if (body instanceof Blob) {
|
|
2264
|
+
headers["Content-Type"] = "application/octet-stream";
|
|
2265
|
+
}
|
|
2266
|
+
options = this.makeOptions(Object.assign({
|
|
2267
|
+
headers: headers,
|
|
2268
|
+
reportProgress: true
|
|
2269
|
+
}, options), "POST", body);
|
|
2270
|
+
return this.toPromise(url, options, listener);
|
|
2271
|
+
}
|
|
2272
|
+
listPromise(url, params) {
|
|
2273
|
+
return new Promise(resolve => {
|
|
2274
|
+
this.getPromise(url, { params: params }).then(data => {
|
|
2275
|
+
var _a, _b;
|
|
2276
|
+
if (ObjectUtils.isArray(data)) {
|
|
2277
|
+
resolve({
|
|
2278
|
+
total: data.length,
|
|
2279
|
+
items: data,
|
|
2280
|
+
meta: {}
|
|
2281
|
+
});
|
|
2282
|
+
return;
|
|
2283
|
+
}
|
|
2284
|
+
resolve({
|
|
2285
|
+
total: ((_a = data.meta) === null || _a === void 0 ? void 0 : _a.total) || (data === null || data === void 0 ? void 0 : data.total) || ((_b = data.items) === null || _b === void 0 ? void 0 : _b.length) || 0,
|
|
2286
|
+
items: data.items || [],
|
|
2287
|
+
meta: data.meta || {}
|
|
2288
|
+
});
|
|
2289
|
+
}, response => {
|
|
2290
|
+
if (response.status == 0 || response.status == 301) {
|
|
2291
|
+
resolve({
|
|
2292
|
+
total: 1,
|
|
2293
|
+
items: [{
|
|
2294
|
+
id: null,
|
|
2295
|
+
label: "Not implemented."
|
|
2296
|
+
}],
|
|
2297
|
+
meta: {}
|
|
2298
|
+
});
|
|
2299
|
+
return true;
|
|
2300
|
+
}
|
|
2301
|
+
resolve({
|
|
2302
|
+
total: 0,
|
|
2303
|
+
items: [],
|
|
2304
|
+
meta: {}
|
|
2305
|
+
});
|
|
2306
|
+
return false;
|
|
2307
|
+
});
|
|
2308
|
+
});
|
|
2309
|
+
}
|
|
2310
|
+
handleUnauthorizedError(absoluteUrl, options, reject) {
|
|
2311
|
+
reject();
|
|
2312
|
+
if (BaseHttpService.failedRequests.length > 1) {
|
|
2313
|
+
return;
|
|
2314
|
+
}
|
|
2315
|
+
if (this.universal.isServer)
|
|
2316
|
+
return;
|
|
2317
|
+
console.log("User auth error", absoluteUrl, options);
|
|
2318
|
+
}
|
|
2319
|
+
toastWarning(message, issueContext, reason, options) {
|
|
2320
|
+
this.toaster.warning(message, { issueContext, reason, options });
|
|
2321
|
+
}
|
|
2322
|
+
toastError(message, issueContext, reason, options) {
|
|
2323
|
+
this.toaster.warning(message, { issueContext, reason, options });
|
|
2324
|
+
}
|
|
2325
|
+
toPromise(url, options, listener) {
|
|
2326
|
+
const issueContext = { url: "" };
|
|
2327
|
+
return new HttpPromise(response => {
|
|
2328
|
+
if (!response) {
|
|
2329
|
+
if (this.universal.isServer)
|
|
2330
|
+
return;
|
|
2331
|
+
console.log("You may not need a reject Handler for this request!", this.name, url, options);
|
|
2332
|
+
return;
|
|
2333
|
+
}
|
|
2334
|
+
const reason = response.error || {};
|
|
2335
|
+
if (response.status == 0 || response.status == 301) {
|
|
2336
|
+
this.toastWarning(`${url} endpoint is not implemented! Click here, to quickly create an issue.`, issueContext, reason, options);
|
|
2337
|
+
return;
|
|
2338
|
+
}
|
|
2339
|
+
const regex = /((E11000 duplicate key error collection: (.)+\.)|(_1 dup key:(.)+))/g;
|
|
2340
|
+
if (reason.message && regex.test(reason.message)) {
|
|
2341
|
+
this.toastError("message.duplicate-key.error." + reason.message.replace(regex, "").replace(" index: ", "-"), issueContext, reason, options);
|
|
2342
|
+
return;
|
|
2343
|
+
}
|
|
2344
|
+
this.toastWarning(`${url} endpoint error is not handled properly! Click here, to quickly create an issue.`, issueContext, reason, options);
|
|
2345
|
+
}, (resolve, reject) => {
|
|
2346
|
+
this.absoluteUrl(url, options).then(absoluteUrl => {
|
|
2347
|
+
issueContext.url = absoluteUrl;
|
|
2348
|
+
const request = this.client.request(options.method, absoluteUrl, options);
|
|
2349
|
+
const finalRequest = ObjectUtils.isNumber(options.timeout) && options.timeout > 0
|
|
2350
|
+
? request.pipe(timeout(options.timeout)) : request;
|
|
2351
|
+
finalRequest.subscribe((event) => {
|
|
2352
|
+
if (options.reportProgress && event.type === HttpEventType.UploadProgress) {
|
|
2353
|
+
const progress = {
|
|
2354
|
+
percentage: MathUtils.round(event.loaded / event.total, 2, 0.01),
|
|
2355
|
+
loaded: event.loaded,
|
|
2356
|
+
total: event.total
|
|
2357
|
+
};
|
|
2358
|
+
if (listener) {
|
|
2359
|
+
listener(progress);
|
|
2360
|
+
}
|
|
2361
|
+
return;
|
|
2362
|
+
}
|
|
2363
|
+
resolve(this.parseResponse(event, url, options));
|
|
2364
|
+
const headers = options.headers;
|
|
2365
|
+
const authKey = "Authorization";
|
|
2366
|
+
// If we use token auth
|
|
2367
|
+
if (this.client.renewTokenFunc && headers.has(authKey)) {
|
|
2368
|
+
const currentTime = new Date().getTime();
|
|
2369
|
+
const userTokenTime = this.storage.get("userTokenTime") || currentTime;
|
|
2370
|
+
// And the last request was a long long time ago
|
|
2371
|
+
if (currentTime - 600000 > userTokenTime) {
|
|
2372
|
+
this.client.renewTokenFunc();
|
|
2373
|
+
}
|
|
2374
|
+
}
|
|
2375
|
+
}, (response) => {
|
|
2376
|
+
if (response instanceof TimeoutError || response.status == 0 || response.status == 301) {
|
|
2377
|
+
reject(response);
|
|
2378
|
+
return;
|
|
2379
|
+
}
|
|
2380
|
+
const headers = options.headers;
|
|
2381
|
+
const authKey = "Authorization";
|
|
2382
|
+
// If an authorization header exists and we still have an Unauthorized response prompt the user to log in again
|
|
2383
|
+
if (headers.has(authKey) && response.status == 401) {
|
|
2384
|
+
const pushed = this.pushFailedRequest(url, options, () => {
|
|
2385
|
+
options.headers = this.makeHeaders(options.originalHeaders);
|
|
2386
|
+
this.toPromise(url, options, listener).then(resolve, reject);
|
|
2387
|
+
});
|
|
2388
|
+
if (pushed)
|
|
2389
|
+
this.handleUnauthorizedError(absoluteUrl, options, () => reject(response));
|
|
2390
|
+
return;
|
|
2391
|
+
}
|
|
2392
|
+
reject(response);
|
|
2393
|
+
});
|
|
2394
|
+
});
|
|
2395
|
+
});
|
|
2396
|
+
}
|
|
2397
|
+
pushFailedRequest(url, options, req) {
|
|
2398
|
+
if (url.indexOf("tokens") >= 0)
|
|
2399
|
+
return false;
|
|
2400
|
+
BaseHttpService.failedRequests.push(req);
|
|
2401
|
+
return true;
|
|
2402
|
+
}
|
|
2403
|
+
checkHeaders(headers) {
|
|
2404
|
+
if (!headers || !headers.cookie || !headers.referer || !headers.host) {
|
|
2405
|
+
return false;
|
|
2406
|
+
}
|
|
2407
|
+
return headers.referer.indexOf(headers.host) >= 0;
|
|
2408
|
+
}
|
|
2409
|
+
makeOptions(options, method = "GET", body) {
|
|
2410
|
+
// Set base options
|
|
2411
|
+
options = options ? Object.assign({}, options) : {};
|
|
2412
|
+
options.method = method;
|
|
2413
|
+
options.observe = options.observe || "body";
|
|
2414
|
+
options.originalHeaders = options.originalHeaders || options.headers || {};
|
|
2415
|
+
options.withCredentials = ObjectUtils.isBoolean(options.withCredentials) ? options.withCredentials : this.withCredentials;
|
|
2416
|
+
options.body = body || {};
|
|
2417
|
+
// Set cookies from server side request
|
|
2418
|
+
const headers = !this.request ? null : this.request.headers;
|
|
2419
|
+
if (this.checkHeaders(headers)) {
|
|
2420
|
+
options.headers["Cookie"] = headers.cookie;
|
|
2421
|
+
}
|
|
2422
|
+
options.headers = this.makeHeaders(options);
|
|
2423
|
+
options.params = this.makeParams(options);
|
|
2424
|
+
return options;
|
|
2425
|
+
}
|
|
2426
|
+
makeHeaders(options) {
|
|
2427
|
+
return this.client.makeHeaders(Object.assign({}, this.requestHeaders, (options === null || options === void 0 ? void 0 : options.headers) || {}));
|
|
2428
|
+
}
|
|
2429
|
+
makeParams(options) {
|
|
2430
|
+
return this.client.makeParams(Object.assign({}, this.requestParams, (options === null || options === void 0 ? void 0 : options.params) || {}));
|
|
2431
|
+
}
|
|
2432
|
+
parseResponse(response, url, options) {
|
|
2433
|
+
return response;
|
|
2434
|
+
}
|
|
2435
|
+
parseUrl(url) {
|
|
2436
|
+
return this.url(url).replace(/(?:((?!:).\/)\/)/g, "$1");
|
|
2437
|
+
}
|
|
2438
|
+
absoluteUrl(url, options) {
|
|
2439
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2440
|
+
const absoluteUrl = this.parseUrl(url);
|
|
2441
|
+
if (url == "api-docs") {
|
|
2442
|
+
return absoluteUrl.replace("/api", "");
|
|
2443
|
+
}
|
|
2444
|
+
return absoluteUrl;
|
|
2445
|
+
});
|
|
2446
|
+
}
|
|
2447
|
+
expressRequestUrl(url) {
|
|
2448
|
+
const req = this.request;
|
|
2449
|
+
if (!req || !url || url.startsWith("http") || url.startsWith("//"))
|
|
2450
|
+
return url;
|
|
2451
|
+
const separator = url.startsWith("/") ? "" : "/";
|
|
2452
|
+
return `${req.protocol}://${req.get("host")}${separator}${url}`;
|
|
2453
|
+
}
|
|
2454
|
+
}
|
|
2455
|
+
BaseHttpService.failedRequests = [];
|
|
2456
|
+
BaseHttpService.decorators = [
|
|
2457
|
+
{ type: Injectable }
|
|
2458
|
+
];
|
|
2459
|
+
BaseHttpService.ctorParameters = () => [
|
|
2460
|
+
{ type: BaseHttpClient, decorators: [{ type: Inject, args: [BaseHttpClient,] }] },
|
|
2461
|
+
{ type: StorageService, decorators: [{ type: Inject, args: [StorageService,] }] },
|
|
2462
|
+
{ type: undefined, decorators: [{ type: Inject, args: [LANGUAGE_SERVICE,] }] },
|
|
2463
|
+
{ type: undefined, decorators: [{ type: Inject, args: [TOASTER_SERVICE,] }] },
|
|
2464
|
+
{ type: undefined, decorators: [{ type: Inject, args: [CONFIG_SERVICE,] }] },
|
|
2465
|
+
{ type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [EXPRESS_REQUEST,] }] }
|
|
2466
|
+
];
|
|
2467
|
+
|
|
2468
|
+
class ApiService extends BaseHttpService {
|
|
2469
|
+
get name() {
|
|
2470
|
+
return "api";
|
|
2471
|
+
}
|
|
2472
|
+
url(url) {
|
|
2473
|
+
return this.expressRequestUrl(`/api/${url}`);
|
|
2474
|
+
}
|
|
2475
|
+
get(url, options, body) {
|
|
2476
|
+
return this.getPromise(url, options, body);
|
|
2477
|
+
}
|
|
2478
|
+
delete(url, options, body) {
|
|
2479
|
+
return this.deletePromise(url, options, body);
|
|
2480
|
+
}
|
|
2481
|
+
post(url, body, options) {
|
|
2482
|
+
return this.postPromise(url, body, options);
|
|
2483
|
+
}
|
|
2484
|
+
put(url, body, options) {
|
|
2485
|
+
return this.putPromise(url, body, options);
|
|
2486
|
+
}
|
|
2487
|
+
patch(url, body, options) {
|
|
2488
|
+
return this.patchPromise(url, body, options);
|
|
2489
|
+
}
|
|
2490
|
+
upload(url, body, listener, options) {
|
|
2491
|
+
return this.uploadPromise(url, body, listener, options);
|
|
2492
|
+
}
|
|
2493
|
+
list(url, params) {
|
|
2494
|
+
return this.listPromise(url, params);
|
|
2495
|
+
}
|
|
2496
|
+
}
|
|
2497
|
+
ApiService.decorators = [
|
|
2498
|
+
{ type: Injectable }
|
|
2499
|
+
];
|
|
2500
|
+
|
|
2501
|
+
class StaticAuthService {
|
|
2502
|
+
constructor() {
|
|
2503
|
+
this.isAuthenticated = true;
|
|
2504
|
+
this.userChanged = new EventEmitter();
|
|
2505
|
+
}
|
|
2506
|
+
checkAuthenticated() {
|
|
2507
|
+
return Promise.resolve(this.isAuthenticated);
|
|
2508
|
+
}
|
|
2509
|
+
getReturnState(route) {
|
|
2510
|
+
return null;
|
|
2511
|
+
}
|
|
2512
|
+
}
|
|
2513
|
+
|
|
2514
|
+
const JSON5 = require("json5");
|
|
2515
|
+
class ConfigService {
|
|
2516
|
+
constructor(http, universal, injector, rootElement, baseConfig = null, scriptParams = null) {
|
|
2517
|
+
this.http = http;
|
|
2518
|
+
this.universal = universal;
|
|
2519
|
+
this.injector = injector;
|
|
2520
|
+
this.rootElement = rootElement;
|
|
2521
|
+
for (const key in []) {
|
|
2522
|
+
Object.defineProperty(Array.prototype, key, {
|
|
2523
|
+
enumerable: false
|
|
2524
|
+
});
|
|
2525
|
+
}
|
|
2526
|
+
let baseUrl = "";
|
|
2527
|
+
if (this.universal.isBrowser) {
|
|
2528
|
+
const currentScript = document.currentScript;
|
|
2529
|
+
if (!!currentScript) {
|
|
2530
|
+
const scriptSrc = currentScript.src;
|
|
2531
|
+
const srcParts = scriptSrc.split(".js");
|
|
2532
|
+
baseUrl = scriptSrc.substr(0, srcParts[0].lastIndexOf("/") + 1);
|
|
2533
|
+
}
|
|
2534
|
+
}
|
|
2535
|
+
this.baseConfig = baseConfig || {};
|
|
2536
|
+
this.loadedConfig = Object.assign(!baseUrl ? {} : { baseUrl, baseDomain: this.parseDomain(baseUrl) }, this.baseConfig);
|
|
2537
|
+
this.scriptParameters = scriptParams || {};
|
|
2538
|
+
this.loaderFunc = () => {
|
|
2539
|
+
this.loader = this.loader || new Promise((resolve, reject) => {
|
|
2540
|
+
this.loadJson().then(config => {
|
|
2541
|
+
this.loadedConfig = config = Object.assign(this.loadedConfig, config);
|
|
2542
|
+
this.prepareConfig(config).then(c => {
|
|
2543
|
+
this.loadedConfig = c;
|
|
2544
|
+
c.baseUrl = c.baseUrl || "/";
|
|
2545
|
+
resolve(c);
|
|
2546
|
+
});
|
|
2547
|
+
}, reject);
|
|
2548
|
+
});
|
|
2549
|
+
return this.loader;
|
|
2550
|
+
};
|
|
2551
|
+
this.initService();
|
|
2552
|
+
}
|
|
2553
|
+
get load() {
|
|
2554
|
+
return this.loaderFunc;
|
|
2555
|
+
}
|
|
2556
|
+
get config() {
|
|
2557
|
+
return this.loadedConfig;
|
|
2558
|
+
}
|
|
2559
|
+
get configUrl() {
|
|
2560
|
+
return `${this.loadedConfig.baseUrl}config/config.json`;
|
|
2561
|
+
}
|
|
2562
|
+
parseDomain(baseUrl) {
|
|
2563
|
+
try {
|
|
2564
|
+
const url = new URL(baseUrl);
|
|
2565
|
+
const port = url.port && url.port !== "443" && url.port !== "80" ? `:${url.port}` : ``;
|
|
2566
|
+
return `${url.protocol}//${url.hostname}${port}/`;
|
|
2567
|
+
}
|
|
2568
|
+
catch (_a) {
|
|
2569
|
+
return "/";
|
|
2570
|
+
}
|
|
2571
|
+
}
|
|
2572
|
+
initService() {
|
|
2573
|
+
}
|
|
2574
|
+
loadJson() {
|
|
2575
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2576
|
+
if (this.universal.isServer) {
|
|
2577
|
+
return Promise.resolve(this.loadedConfig);
|
|
2578
|
+
}
|
|
2579
|
+
const configUrl = this.configUrl;
|
|
2580
|
+
try {
|
|
2581
|
+
const config5 = yield this.http.get(isDevMode() ? `${configUrl}5` : configUrl, { responseType: "text" }).toPromise();
|
|
2582
|
+
return JSON5.parse(config5);
|
|
2583
|
+
}
|
|
2584
|
+
catch (e) {
|
|
2585
|
+
try {
|
|
2586
|
+
const config = yield this.http.get(configUrl).toPromise();
|
|
2587
|
+
console.log(`Can't parse json5 config: ${e}`);
|
|
2588
|
+
return config;
|
|
2589
|
+
}
|
|
2590
|
+
catch (e) {
|
|
2591
|
+
throw new Error(`Config file not found at: ${configUrl}`);
|
|
2592
|
+
}
|
|
2593
|
+
}
|
|
2594
|
+
});
|
|
2595
|
+
}
|
|
2596
|
+
prepareConfig(config) {
|
|
2597
|
+
return Promise.resolve(config);
|
|
2598
|
+
}
|
|
2599
|
+
prepareUrl(url, ending) {
|
|
2600
|
+
var _a;
|
|
2601
|
+
const project = !this.loadedConfig ? "" : this.loadedConfig.project;
|
|
2602
|
+
const needsProtocol = (_a = url === null || url === void 0 ? void 0 : url.startsWith("//")) !== null && _a !== void 0 ? _a : false;
|
|
2603
|
+
url = !needsProtocol && (url === null || url === void 0 ? void 0 : url.startsWith("/")) ? this.loadedConfig.baseDomain + url.substr(1) : url || "";
|
|
2604
|
+
url = `${url.replace(/\/+$/, "")}${ending}`.replace("[project]", project);
|
|
2605
|
+
return this.universal.isServer && needsProtocol ? `http:${url}` : url;
|
|
2606
|
+
}
|
|
2607
|
+
getConfigValue(key) {
|
|
2608
|
+
return this.loadedConfig[key];
|
|
2609
|
+
}
|
|
2610
|
+
getQueryParameter(name, url) {
|
|
2611
|
+
url = url || (this.universal.isBrowser ? window.location.href : "");
|
|
2612
|
+
name = name.replace(/[\[\]]/g, "\\$&");
|
|
2613
|
+
const regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"), results = regex.exec(url);
|
|
2614
|
+
if (!results)
|
|
2615
|
+
return null;
|
|
2616
|
+
if (!results[2])
|
|
2617
|
+
return "";
|
|
2618
|
+
return decodeURIComponent(results[2].replace(/\+/g, " "));
|
|
2619
|
+
}
|
|
2620
|
+
}
|
|
2621
|
+
ConfigService.decorators = [
|
|
2622
|
+
{ type: Injectable }
|
|
2623
|
+
];
|
|
2624
|
+
ConfigService.ctorParameters = () => [
|
|
2625
|
+
{ type: HttpClient },
|
|
2626
|
+
{ type: UniversalService },
|
|
2627
|
+
{ type: Injector },
|
|
2628
|
+
{ type: undefined, decorators: [{ type: Inject, args: [ROOT_ELEMENT,] }] },
|
|
2629
|
+
{ type: IConfiguration, decorators: [{ type: Optional }, { type: Inject, args: [BASE_CONFIG,] }] },
|
|
2630
|
+
{ type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [SCRIPT_PARAMS,] }] }
|
|
2631
|
+
];
|
|
2632
|
+
|
|
2633
|
+
class ErrorHandlerService extends ErrorHandler {
|
|
2634
|
+
constructor(injector) {
|
|
2635
|
+
super();
|
|
2636
|
+
this.injector = injector;
|
|
2637
|
+
this.errorMap = {};
|
|
2638
|
+
}
|
|
2639
|
+
handleError(error) {
|
|
2640
|
+
try {
|
|
2641
|
+
this.universal = this.universal || this.injector.get(UniversalService);
|
|
2642
|
+
}
|
|
2643
|
+
catch (e) {
|
|
2644
|
+
return;
|
|
2645
|
+
}
|
|
2646
|
+
const date = new Date();
|
|
2647
|
+
try {
|
|
2648
|
+
this.errorCb = this.errorCb || this.injector.get(ERROR_HANDLER);
|
|
2649
|
+
this.errorCb(`[${date}]: ${error.message}\n${error.stack}`);
|
|
2650
|
+
}
|
|
2651
|
+
catch (e) {
|
|
2652
|
+
if (this.universal.isServer) {
|
|
2653
|
+
console.error(`[${date}]: ${error.message}\n${error.stack}`);
|
|
2654
|
+
return;
|
|
2655
|
+
}
|
|
2656
|
+
}
|
|
2657
|
+
if (this.universal.isServer)
|
|
2658
|
+
return;
|
|
2659
|
+
const key = typeof btoa !== "undefined" ? btoa(unescape(encodeURIComponent(`${error.message} ${error.stack}`))) : error.message;
|
|
2660
|
+
if (this.errorMap[key] && this.errorMap[key].getTime() > date.getTime() - 5000)
|
|
2661
|
+
return;
|
|
2662
|
+
this.errorMap[key] = date;
|
|
2663
|
+
try {
|
|
2664
|
+
this.toaster = this.toaster || this.injector.get(TOASTER_SERVICE);
|
|
2665
|
+
this.toaster.error(`[${date}]: ${error.message}\n${error.stack}`);
|
|
2666
|
+
}
|
|
2667
|
+
catch (e) {
|
|
2668
|
+
}
|
|
2669
|
+
console.error(`[${date}]: ${error.message}\n${error.stack}`);
|
|
2670
|
+
}
|
|
2671
|
+
}
|
|
2672
|
+
ErrorHandlerService.decorators = [
|
|
2673
|
+
{ type: Injectable }
|
|
2674
|
+
];
|
|
2675
|
+
ErrorHandlerService.ctorParameters = () => [
|
|
2676
|
+
{ type: Injector }
|
|
2677
|
+
];
|
|
2678
|
+
|
|
2679
|
+
class EventsService {
|
|
2680
|
+
constructor() {
|
|
2681
|
+
this.eventForwarded = new EventEmitter();
|
|
2682
|
+
this.stickyUpdated = new EventEmitter();
|
|
2683
|
+
this.languageChanged = new EventEmitter();
|
|
2684
|
+
this.sticky = false;
|
|
2685
|
+
}
|
|
2686
|
+
get isSticky() {
|
|
2687
|
+
return this.sticky;
|
|
2688
|
+
}
|
|
2689
|
+
event(e) {
|
|
2690
|
+
this.eventForwarded.emit(e);
|
|
2691
|
+
}
|
|
2692
|
+
updateSticky(sticky) {
|
|
2693
|
+
this.sticky = sticky;
|
|
2694
|
+
this.stickyUpdated.emit(sticky);
|
|
2695
|
+
}
|
|
2696
|
+
}
|
|
2697
|
+
EventsService.decorators = [
|
|
2698
|
+
{ type: Injectable }
|
|
2699
|
+
];
|
|
2700
|
+
EventsService.ctorParameters = () => [];
|
|
2701
|
+
|
|
2702
|
+
class FormatterService {
|
|
2703
|
+
constructor(language) {
|
|
2704
|
+
this.language = language;
|
|
2705
|
+
}
|
|
2706
|
+
get defaultPrecision() {
|
|
2707
|
+
return 2;
|
|
2708
|
+
}
|
|
2709
|
+
get defaultNumberFormat() {
|
|
2710
|
+
return `num + ' mm'`;
|
|
2711
|
+
}
|
|
2712
|
+
get defaultDivider() {
|
|
2713
|
+
return 1;
|
|
2714
|
+
}
|
|
2715
|
+
roundNumber(value, precision, divider) {
|
|
2716
|
+
return MathUtils.round(value, this.getPrecision(precision), divider || this.defaultDivider);
|
|
2717
|
+
}
|
|
2718
|
+
formatNumber(value, format, precision, divider) {
|
|
2719
|
+
precision = this.getPrecision(precision);
|
|
2720
|
+
divider = divider || this.defaultDivider;
|
|
2721
|
+
const num = ObjectUtils.isNumber(value) ? value : parseFloat(value) || 0;
|
|
2722
|
+
const str = (num / divider).toLocaleString(this.language.currentLanguage, {
|
|
2723
|
+
minimumFractionDigits: precision,
|
|
2724
|
+
maximumFractionDigits: precision,
|
|
2725
|
+
useGrouping: false
|
|
2726
|
+
});
|
|
2727
|
+
return ObjectUtils.evaluate(format || this.defaultNumberFormat, { num: str });
|
|
2728
|
+
}
|
|
2729
|
+
formatMillimeter(value, precision, divider) {
|
|
2730
|
+
return this.formatNumber(value, `num + ' mm'`, precision, divider);
|
|
2731
|
+
}
|
|
2732
|
+
getPrecision(precision) {
|
|
2733
|
+
return ObjectUtils.isNumber(precision) ? precision : this.defaultPrecision;
|
|
2734
|
+
}
|
|
2735
|
+
}
|
|
2736
|
+
FormatterService.decorators = [
|
|
2737
|
+
{ type: Injectable }
|
|
2738
|
+
];
|
|
2739
|
+
FormatterService.ctorParameters = () => [
|
|
2740
|
+
{ type: undefined, decorators: [{ type: Inject, args: [LANGUAGE_SERVICE,] }] }
|
|
2741
|
+
];
|
|
2742
|
+
|
|
2743
|
+
class GlobalTemplateService {
|
|
2744
|
+
constructor() {
|
|
2745
|
+
this.templatesUpdated = new EventEmitter();
|
|
2746
|
+
this.globalTemplates = {};
|
|
2747
|
+
this.componentModifiers = {};
|
|
2748
|
+
}
|
|
2749
|
+
get(id, component) {
|
|
2750
|
+
const template = this.globalTemplates[id];
|
|
2751
|
+
if (!template)
|
|
2752
|
+
return undefined;
|
|
2753
|
+
const modifier = this.componentModifiers[id];
|
|
2754
|
+
if (ObjectUtils.isFunction(modifier) && component) {
|
|
2755
|
+
modifier(component);
|
|
2756
|
+
}
|
|
2757
|
+
return template;
|
|
2758
|
+
}
|
|
2759
|
+
add(id, template) {
|
|
2760
|
+
this.globalTemplates[id] = template;
|
|
2761
|
+
this.templatesUpdated.emit();
|
|
2762
|
+
}
|
|
2763
|
+
remove(id) {
|
|
2764
|
+
delete this.globalTemplates[id];
|
|
2765
|
+
this.templatesUpdated.emit();
|
|
2766
|
+
}
|
|
2767
|
+
addComponentModifier(id, modifier) {
|
|
2768
|
+
this.componentModifiers[id] = modifier;
|
|
2769
|
+
}
|
|
2770
|
+
}
|
|
2771
|
+
GlobalTemplateService.decorators = [
|
|
2772
|
+
{ type: Injectable }
|
|
2773
|
+
];
|
|
2774
|
+
GlobalTemplateService.ctorParameters = () => [];
|
|
2775
|
+
|
|
2776
|
+
class IconService {
|
|
2777
|
+
constructor() {
|
|
2778
|
+
this.iconsLoaded = new EventEmitter();
|
|
2779
|
+
this.disabled = false;
|
|
2780
|
+
}
|
|
2781
|
+
get isDisabled() {
|
|
2782
|
+
return this.disabled;
|
|
2783
|
+
}
|
|
2784
|
+
set isDisabled(value) {
|
|
2785
|
+
this.disabled = value;
|
|
2786
|
+
this.iconsLoaded.emit();
|
|
2787
|
+
}
|
|
2788
|
+
getIcon(icon, activeIcon, active) {
|
|
2789
|
+
icon = typeof icons == "undefined" ? icon : (icons[icon] || icon);
|
|
2790
|
+
activeIcon = typeof icons == "undefined" ? activeIcon : (icons[activeIcon] || icon);
|
|
2791
|
+
return Promise.resolve(active ? activeIcon : icon);
|
|
2792
|
+
}
|
|
2793
|
+
}
|
|
2794
|
+
IconService.decorators = [
|
|
2795
|
+
{ type: Injectable }
|
|
2796
|
+
];
|
|
2797
|
+
IconService.ctorParameters = () => [];
|
|
2798
|
+
|
|
2799
|
+
class StaticLanguageService {
|
|
2800
|
+
constructor(events, storage, configs, promises, client) {
|
|
2801
|
+
this.events = events;
|
|
2802
|
+
this.storage = storage;
|
|
2803
|
+
this.configs = configs;
|
|
2804
|
+
this.promises = promises;
|
|
2805
|
+
this.client = client;
|
|
2806
|
+
this.editLang = null;
|
|
2807
|
+
this.currentLang = null;
|
|
2808
|
+
this.disableTrans = false;
|
|
2809
|
+
this.languageList = [];
|
|
2810
|
+
this.translations = {
|
|
2811
|
+
none: {}
|
|
2812
|
+
};
|
|
2813
|
+
this.initService();
|
|
2814
|
+
}
|
|
2815
|
+
get defaultLanguage() {
|
|
2816
|
+
return this.configs.getQueryParameter("lang") || this.storage.get("language", this.getDefaultLanguage());
|
|
2817
|
+
}
|
|
2818
|
+
get dictionary() {
|
|
2819
|
+
return this.translations[this.currentLanguage] || {};
|
|
2820
|
+
}
|
|
2821
|
+
set dictionary(value) {
|
|
2822
|
+
this.translations[this.currentLanguage] = value;
|
|
2823
|
+
}
|
|
2824
|
+
get languages() {
|
|
2825
|
+
return this.languageList;
|
|
2826
|
+
}
|
|
2827
|
+
get currentLanguage() {
|
|
2828
|
+
return this.currentLang || this.defaultLanguage;
|
|
2829
|
+
}
|
|
2830
|
+
set currentLanguage(lang) {
|
|
2831
|
+
this.currentLang = lang;
|
|
2832
|
+
this.events.languageChanged.emit(lang);
|
|
2833
|
+
}
|
|
2834
|
+
get editLanguage() {
|
|
2835
|
+
return this.editLang || this.currentLanguage;
|
|
2836
|
+
}
|
|
2837
|
+
set editLanguage(lang) {
|
|
2838
|
+
this.editLang = lang || this.currentLanguage;
|
|
2839
|
+
}
|
|
2840
|
+
get disableTranslations() {
|
|
2841
|
+
return this.disableTrans;
|
|
2842
|
+
}
|
|
2843
|
+
set disableTranslations(value) {
|
|
2844
|
+
this.disableTrans = value;
|
|
2845
|
+
this.events.languageChanged.emit(this.currentLang);
|
|
2846
|
+
}
|
|
2847
|
+
get httpClient() {
|
|
2848
|
+
return this.client;
|
|
2849
|
+
}
|
|
2850
|
+
get config() {
|
|
2851
|
+
return this.configs.config;
|
|
2852
|
+
}
|
|
2853
|
+
get universal() {
|
|
2854
|
+
return this.storage.universal;
|
|
2855
|
+
}
|
|
2856
|
+
initService() {
|
|
2857
|
+
}
|
|
2858
|
+
replaceLanguages(languages) {
|
|
2859
|
+
languages = Array.isArray(languages) && languages.length > 0 ? languages : this.languageList;
|
|
2860
|
+
this.languageList = Array.from(new Set(languages));
|
|
2861
|
+
this.languageList.forEach(lang => {
|
|
2862
|
+
this.translations[lang] = this.translations[lang] || {};
|
|
2863
|
+
});
|
|
2864
|
+
}
|
|
2865
|
+
addLanguages(languages) {
|
|
2866
|
+
if (!Array.isArray(languages) || languages.length == 0)
|
|
2867
|
+
return;
|
|
2868
|
+
this.replaceLanguages(this.languageList.concat(languages));
|
|
2869
|
+
}
|
|
2870
|
+
getTranslationSync(key, params = null) {
|
|
2871
|
+
const lowerKey = (key || "").toLocaleLowerCase();
|
|
2872
|
+
const translation = this.dictionary[lowerKey] || lowerKey;
|
|
2873
|
+
return this.interpolate(translation == lowerKey ? key : translation, params);
|
|
2874
|
+
}
|
|
2875
|
+
getTranslation(key, params) {
|
|
2876
|
+
if (!ObjectUtils.isString(key) || !key.length) {
|
|
2877
|
+
throw new Error(`Parameter "key" required`);
|
|
2878
|
+
}
|
|
2879
|
+
const translation = ObjectUtils.getValue(this.dictionary, key, key) || key;
|
|
2880
|
+
return this.promises.resolve(this.interpolate(translation, params));
|
|
2881
|
+
}
|
|
2882
|
+
getTranslations(...keys) {
|
|
2883
|
+
return this.promises.create(resolve => {
|
|
2884
|
+
this.promises.all(keys.map(key => this.getTranslation(key))).then(translations => {
|
|
2885
|
+
resolve(keys.reduce((result, key, i) => {
|
|
2886
|
+
result[key] = translations[i];
|
|
2887
|
+
return result;
|
|
2888
|
+
}, {}));
|
|
2889
|
+
});
|
|
2890
|
+
});
|
|
2891
|
+
}
|
|
2892
|
+
getTranslationFromObject(translations, params, lang) {
|
|
2893
|
+
lang = lang || this.currentLanguage;
|
|
2894
|
+
return this.interpolate(translations ? (translations[lang] || "") : "");
|
|
2895
|
+
}
|
|
2896
|
+
getTranslationFromArray(translations, params, lang) {
|
|
2897
|
+
lang = lang || this.currentLanguage;
|
|
2898
|
+
const translation = translations ? translations.find(t => t.lang == lang) : null;
|
|
2899
|
+
return this.interpolate(translation ? translation.translation : "", params);
|
|
2900
|
+
}
|
|
2901
|
+
interpolate(expr, params) {
|
|
2902
|
+
if (typeof expr === "string") {
|
|
2903
|
+
return this.interpolateString(expr, params);
|
|
2904
|
+
}
|
|
2905
|
+
if (typeof expr === "function") {
|
|
2906
|
+
return expr(params);
|
|
2907
|
+
}
|
|
2908
|
+
return expr;
|
|
2909
|
+
}
|
|
2910
|
+
interpolateString(expr, params) {
|
|
2911
|
+
if (!expr || !params)
|
|
2912
|
+
return expr;
|
|
2913
|
+
return expr.replace(/{{\s?([^{}\s]*)\s?}}/g, (substring, b) => {
|
|
2914
|
+
const r = ObjectUtils.getValue(params, b);
|
|
2915
|
+
return ObjectUtils.isDefined(r) ? r : substring;
|
|
2916
|
+
});
|
|
2917
|
+
}
|
|
2918
|
+
getDefaultLanguage() {
|
|
2919
|
+
if (!this.universal.isBrowser || typeof window.navigator === "undefined") {
|
|
2920
|
+
return "de";
|
|
2921
|
+
}
|
|
2922
|
+
let browserLang = (window.navigator.languages ? window.navigator.languages[0] : null)
|
|
2923
|
+
|| window.navigator.language || window.navigator["browserLanguage"] || window.navigator["userLanguage"] || null;
|
|
2924
|
+
if (!browserLang)
|
|
2925
|
+
return browserLang;
|
|
2926
|
+
["-", "_"].forEach(splitter => {
|
|
2927
|
+
if (browserLang.indexOf(splitter) >= 0) {
|
|
2928
|
+
browserLang = browserLang.split(splitter)[0];
|
|
2929
|
+
}
|
|
2930
|
+
});
|
|
2931
|
+
return browserLang;
|
|
2932
|
+
}
|
|
2933
|
+
}
|
|
2934
|
+
StaticLanguageService.decorators = [
|
|
2935
|
+
{ type: Injectable }
|
|
2936
|
+
];
|
|
2937
|
+
StaticLanguageService.ctorParameters = () => [
|
|
2938
|
+
{ type: EventsService, decorators: [{ type: Inject, args: [EventsService,] }] },
|
|
2939
|
+
{ type: StorageService, decorators: [{ type: Inject, args: [StorageService,] }] },
|
|
2940
|
+
{ type: undefined, decorators: [{ type: Inject, args: [CONFIG_SERVICE,] }] },
|
|
2941
|
+
{ type: undefined, decorators: [{ type: Inject, args: [PROMISE_SERVICE,] }] },
|
|
2942
|
+
{ type: BaseHttpClient, decorators: [{ type: Inject, args: [BaseHttpClient,] }] }
|
|
2943
|
+
];
|
|
2944
|
+
|
|
2945
|
+
class LanguageService extends StaticLanguageService {
|
|
2946
|
+
get currentLanguage() {
|
|
2947
|
+
return this.currentLang || this.defaultLanguage;
|
|
2948
|
+
}
|
|
2949
|
+
set currentLanguage(lang) {
|
|
2950
|
+
this.useLanguage(lang).then(() => {
|
|
2951
|
+
this.events.languageChanged.emit(lang);
|
|
2952
|
+
});
|
|
2953
|
+
}
|
|
2954
|
+
get settings() {
|
|
2955
|
+
const settings = this.languageSettings.value;
|
|
2956
|
+
return !settings ? {} : settings.settings[this.currentLanguage] || {};
|
|
2957
|
+
}
|
|
2958
|
+
get $settings() {
|
|
2959
|
+
this.loadSettings().then(s => this.languageSettings.next(s));
|
|
2960
|
+
return combineLatest([this.languageSettings, this.events.languageChanged]).pipe(map(([settings, lang]) => {
|
|
2961
|
+
return !settings ? {} : settings.settings[lang] || {};
|
|
2962
|
+
}));
|
|
2963
|
+
}
|
|
2964
|
+
initService() {
|
|
2965
|
+
this.client.setExtraRequestParam("language", "de");
|
|
2966
|
+
this.translationRequests = {};
|
|
2967
|
+
this.languageSettings = new BehaviorSubject(null);
|
|
2968
|
+
if (this.universal.isServer)
|
|
2969
|
+
return;
|
|
2970
|
+
window["setLanguage"] = (lang) => {
|
|
2971
|
+
this.currentLanguage = lang;
|
|
2972
|
+
};
|
|
2973
|
+
}
|
|
2974
|
+
initFromSettings() {
|
|
2975
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2976
|
+
const defaultLanguage = this.defaultLanguage;
|
|
2977
|
+
const settings = yield this.loadSettings();
|
|
2978
|
+
this.languageSettings.next(settings);
|
|
2979
|
+
const devLanguages = settings.devLanguages || [];
|
|
2980
|
+
this.languageList = (settings.languages || []).filter(lang => {
|
|
2981
|
+
return devLanguages.indexOf(lang) < 0;
|
|
2982
|
+
});
|
|
2983
|
+
const lang = this.languages.indexOf(defaultLanguage) < 0 ? settings.defaultLanguage : defaultLanguage;
|
|
2984
|
+
yield this.useLanguage(lang);
|
|
2985
|
+
this.events.languageChanged.emit(lang);
|
|
2986
|
+
});
|
|
2987
|
+
}
|
|
2988
|
+
getTranslation(key, params = null) {
|
|
2989
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2990
|
+
if (!key)
|
|
2991
|
+
return "";
|
|
2992
|
+
try {
|
|
2993
|
+
const lowerKey = key.toLocaleLowerCase();
|
|
2994
|
+
const dict = yield this.loadDictionary();
|
|
2995
|
+
if (lowerKey in dict) {
|
|
2996
|
+
return this.interpolate(dict[lowerKey], params);
|
|
2997
|
+
}
|
|
2998
|
+
return this.interpolate(key, params);
|
|
2999
|
+
}
|
|
3000
|
+
catch (reason) {
|
|
3001
|
+
console.log("ERROR IN TRANSLATIONS", reason);
|
|
3002
|
+
return key;
|
|
3003
|
+
}
|
|
3004
|
+
});
|
|
3005
|
+
}
|
|
3006
|
+
useLanguage(lang) {
|
|
3007
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
3008
|
+
lang = this.languages.indexOf(lang) < 0 ? this.languages[0] : lang;
|
|
3009
|
+
this.client.setExtraRequestParam("language", lang);
|
|
3010
|
+
if (lang == this.currentLang)
|
|
3011
|
+
return this.dictionary;
|
|
3012
|
+
this.storage.set("language", lang);
|
|
3013
|
+
this.currentLang = lang;
|
|
3014
|
+
const dict = yield this.loadDictionary();
|
|
3015
|
+
this.translations[lang] = dict;
|
|
3016
|
+
return dict;
|
|
3017
|
+
});
|
|
3018
|
+
}
|
|
3019
|
+
loadDictionary() {
|
|
3020
|
+
const lang = this.currentLanguage;
|
|
3021
|
+
this.translationRequests[lang] = this.translationRequests[lang] || new Promise(resolve => {
|
|
3022
|
+
this.httpClient.get(`${this.config.translationUrl}${lang}`).toPromise().then(response => {
|
|
3023
|
+
response = response || {};
|
|
3024
|
+
resolve(Object.keys(response).reduce((result, key) => {
|
|
3025
|
+
result[key.toLocaleLowerCase()] = response[key];
|
|
3026
|
+
return result;
|
|
3027
|
+
}, {}));
|
|
3028
|
+
}, () => {
|
|
3029
|
+
resolve({});
|
|
3030
|
+
});
|
|
3031
|
+
});
|
|
3032
|
+
return this.translationRequests[lang];
|
|
3033
|
+
}
|
|
3034
|
+
loadSettings() {
|
|
3035
|
+
this.settingsPromise = this.settingsPromise || this.client.get(`${this.config.translationUrl}languageSettings`).toPromise()
|
|
3036
|
+
.then((settings) => {
|
|
3037
|
+
return settings;
|
|
3038
|
+
}, () => {
|
|
3039
|
+
return {
|
|
3040
|
+
languages: ["de", "en", "hu"],
|
|
3041
|
+
devLanguages: [],
|
|
3042
|
+
defaultLanguage: "de",
|
|
3043
|
+
settings: {
|
|
3044
|
+
de: {},
|
|
3045
|
+
hu: {},
|
|
3046
|
+
end: {}
|
|
3047
|
+
}
|
|
3048
|
+
};
|
|
3049
|
+
});
|
|
3050
|
+
return this.settingsPromise;
|
|
3051
|
+
}
|
|
3052
|
+
}
|
|
3053
|
+
LanguageService.decorators = [
|
|
3054
|
+
{ type: Injectable }
|
|
3055
|
+
];
|
|
3056
|
+
|
|
3057
|
+
class OpenApiService {
|
|
3058
|
+
constructor(api) {
|
|
3059
|
+
this.api = api;
|
|
3060
|
+
}
|
|
3061
|
+
getSchemas() {
|
|
3062
|
+
this.schemasPromise = this.schemasPromise || new Promise((resolve => {
|
|
3063
|
+
this.api.get("api-docs").then(res => {
|
|
3064
|
+
var _a;
|
|
3065
|
+
const schemas = ((_a = res.components) === null || _a === void 0 ? void 0 : _a.schemas) || res.definitions || {};
|
|
3066
|
+
Object.values(schemas).forEach(schema => {
|
|
3067
|
+
Object.keys(schema.properties || {}).forEach(p => {
|
|
3068
|
+
schema.properties[p].id = p;
|
|
3069
|
+
});
|
|
3070
|
+
});
|
|
3071
|
+
resolve(schemas);
|
|
3072
|
+
}, () => {
|
|
3073
|
+
resolve({});
|
|
3074
|
+
});
|
|
3075
|
+
}));
|
|
3076
|
+
return this.schemasPromise;
|
|
3077
|
+
}
|
|
3078
|
+
getSchema(name) {
|
|
3079
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
3080
|
+
const schemas = yield this.getSchemas();
|
|
3081
|
+
const schema = schemas[name];
|
|
3082
|
+
if (!schema)
|
|
3083
|
+
return null;
|
|
3084
|
+
return schemas[name];
|
|
3085
|
+
});
|
|
3086
|
+
}
|
|
3087
|
+
}
|
|
3088
|
+
OpenApiService.decorators = [
|
|
3089
|
+
{ type: Injectable }
|
|
3090
|
+
];
|
|
3091
|
+
OpenApiService.ctorParameters = () => [
|
|
3092
|
+
{ type: undefined, decorators: [{ type: Inject, args: [API_SERVICE,] }] }
|
|
3093
|
+
];
|
|
3094
|
+
|
|
3095
|
+
class ConsoleToasterService {
|
|
3096
|
+
constructor(language) {
|
|
3097
|
+
this.language = language;
|
|
3098
|
+
}
|
|
3099
|
+
error(message, params, title) {
|
|
3100
|
+
this.translateMessage(message, params, str => console.log(str, title, "background: #BD362F; color: #ffffff"));
|
|
3101
|
+
}
|
|
3102
|
+
info(message, params, title) {
|
|
3103
|
+
this.translateMessage(message, params, str => console.log(str, title, "background: #2F96B4; color: #ffffff"));
|
|
3104
|
+
}
|
|
3105
|
+
success(message, params, title) {
|
|
3106
|
+
this.translateMessage(message, params, str => console.log(str, title, "background: #51A351; color: #ffffff"));
|
|
3107
|
+
}
|
|
3108
|
+
warning(message, params, title) {
|
|
3109
|
+
this.translateMessage(message, params, str => console.log(str, title, "background: #F89406; color: #ffffff"));
|
|
3110
|
+
}
|
|
3111
|
+
translateMessage(message, params, callback) {
|
|
3112
|
+
this.language.getTranslation(message, params).then(callback);
|
|
3113
|
+
}
|
|
3114
|
+
}
|
|
3115
|
+
ConsoleToasterService.decorators = [
|
|
3116
|
+
{ type: Injectable }
|
|
3117
|
+
];
|
|
3118
|
+
ConsoleToasterService.ctorParameters = () => [
|
|
3119
|
+
{ type: undefined, decorators: [{ type: Inject, args: [LANGUAGE_SERVICE,] }] }
|
|
3120
|
+
];
|
|
3121
|
+
|
|
3122
|
+
class TranslatedUrlSerializer extends DefaultUrlSerializer {
|
|
3123
|
+
constructor(language) {
|
|
3124
|
+
super();
|
|
3125
|
+
this.language = language;
|
|
3126
|
+
this.cache = {};
|
|
3127
|
+
}
|
|
3128
|
+
serialize(tree) {
|
|
3129
|
+
const copy = new UrlTree();
|
|
3130
|
+
const dictionary = this.getDictionary(true);
|
|
3131
|
+
copy.root = this.modifyTreeRecursive(tree.root, segment => {
|
|
3132
|
+
segment.path = dictionary[segment.path] || segment.path;
|
|
3133
|
+
});
|
|
3134
|
+
copy.queryParams = tree.queryParams;
|
|
3135
|
+
return super.serialize(copy);
|
|
3136
|
+
}
|
|
3137
|
+
parse(url) {
|
|
3138
|
+
const tree = super.parse(url);
|
|
3139
|
+
const dictionary = this.getDictionary(false);
|
|
3140
|
+
tree.root = this.modifyTreeRecursive(tree.root, segment => {
|
|
3141
|
+
segment.path = dictionary[segment.path] || segment.path;
|
|
3142
|
+
});
|
|
3143
|
+
return tree;
|
|
3144
|
+
}
|
|
3145
|
+
getDictionary(serialize) {
|
|
3146
|
+
const method = serialize ? `serialize` : `parse`;
|
|
3147
|
+
const key = `${this.language.currentLanguage}-${method}`;
|
|
3148
|
+
if (!this.cache[key]) {
|
|
3149
|
+
const dict = this.language.dictionary;
|
|
3150
|
+
this.cache[key] = Object.keys(dict).reduce((res, key) => {
|
|
3151
|
+
if (!key.startsWith("route."))
|
|
3152
|
+
return res;
|
|
3153
|
+
const value = dict[key];
|
|
3154
|
+
key = key.replace("route.", "");
|
|
3155
|
+
res[serialize ? key : value] = serialize ? value : key;
|
|
3156
|
+
return res;
|
|
3157
|
+
}, {});
|
|
3158
|
+
}
|
|
3159
|
+
return this.cache[key];
|
|
3160
|
+
}
|
|
3161
|
+
modifyTreeRecursive(segmentGroup, cb) {
|
|
3162
|
+
if (!segmentGroup)
|
|
3163
|
+
return null;
|
|
3164
|
+
const childrenArr = [];
|
|
3165
|
+
const children = Object.keys(segmentGroup.children || {}).reduce((res, key) => {
|
|
3166
|
+
const child = this.modifyTreeRecursive(segmentGroup.children[key], cb);
|
|
3167
|
+
childrenArr.push(child);
|
|
3168
|
+
res[key] = child;
|
|
3169
|
+
return res;
|
|
3170
|
+
}, {});
|
|
3171
|
+
const newGroup = new UrlSegmentGroup(segmentGroup.segments.map(s => {
|
|
3172
|
+
s = new UrlSegment(s.path, Object.assign({}, s.parameters));
|
|
3173
|
+
cb(s);
|
|
3174
|
+
return s;
|
|
3175
|
+
}), children);
|
|
3176
|
+
childrenArr.forEach(c => {
|
|
3177
|
+
c.parent = newGroup;
|
|
3178
|
+
});
|
|
3179
|
+
return newGroup;
|
|
3180
|
+
}
|
|
3181
|
+
}
|
|
3182
|
+
TranslatedUrlSerializer.decorators = [
|
|
3183
|
+
{ type: Injectable }
|
|
3184
|
+
];
|
|
3185
|
+
TranslatedUrlSerializer.ctorParameters = () => [
|
|
3186
|
+
{ type: undefined, decorators: [{ type: Inject, args: [LANGUAGE_SERVICE,] }] }
|
|
3187
|
+
];
|
|
3188
|
+
|
|
3189
|
+
class PromiseService {
|
|
3190
|
+
constructor(zone) {
|
|
3191
|
+
this.zone = zone;
|
|
3192
|
+
this.promiseCount = 0;
|
|
3193
|
+
this.promiseChanged = new EventEmitter();
|
|
3194
|
+
}
|
|
3195
|
+
get count() {
|
|
3196
|
+
return this.promiseCount;
|
|
3197
|
+
}
|
|
3198
|
+
get onChanged() {
|
|
3199
|
+
return this.promiseChanged;
|
|
3200
|
+
}
|
|
3201
|
+
create(executor) {
|
|
3202
|
+
return this.add(this.zone.runOutsideAngular(() => new Promise(executor)));
|
|
3203
|
+
}
|
|
3204
|
+
all(promises) {
|
|
3205
|
+
return this.add(this.zone.runOutsideAngular(() => Promise.all(promises)));
|
|
3206
|
+
}
|
|
3207
|
+
resolve(value) {
|
|
3208
|
+
return this.add(this.zone.runOutsideAngular(() => Promise.resolve(value)));
|
|
3209
|
+
}
|
|
3210
|
+
reject(value) {
|
|
3211
|
+
return this.add(this.zone.runOutsideAngular(() => Promise.reject(value)));
|
|
3212
|
+
}
|
|
3213
|
+
promiseFinished() {
|
|
3214
|
+
if (this.promiseCount == 0)
|
|
3215
|
+
return;
|
|
3216
|
+
this.promiseCount--;
|
|
3217
|
+
this.promiseChanged.emit(this.promiseCount);
|
|
3218
|
+
}
|
|
3219
|
+
add(promise) {
|
|
3220
|
+
this.promiseCount++;
|
|
3221
|
+
this.promiseChanged.emit(this.promiseCount);
|
|
3222
|
+
return new Promise((resolve, reject) => {
|
|
3223
|
+
promise.then(v => {
|
|
3224
|
+
resolve(v);
|
|
3225
|
+
this.promiseFinished();
|
|
3226
|
+
}, r => {
|
|
3227
|
+
reject(r);
|
|
3228
|
+
this.promiseFinished();
|
|
3229
|
+
});
|
|
3230
|
+
});
|
|
3231
|
+
}
|
|
3232
|
+
}
|
|
3233
|
+
PromiseService.decorators = [
|
|
3234
|
+
{ type: Injectable }
|
|
3235
|
+
];
|
|
3236
|
+
PromiseService.ctorParameters = () => [
|
|
3237
|
+
{ type: NgZone, decorators: [{ type: Inject, args: [NgZone,] }] }
|
|
3238
|
+
];
|
|
3239
|
+
|
|
3240
|
+
function emptyRemove$1() {
|
|
3241
|
+
}
|
|
3242
|
+
function isWindow(el) {
|
|
3243
|
+
return typeof window !== "undefined" && el === window;
|
|
3244
|
+
}
|
|
3245
|
+
class ResizeEventPlugin extends ɵangular_packages_platform_browser_platform_browser_g {
|
|
3246
|
+
constructor(doc, universal) {
|
|
3247
|
+
super(doc);
|
|
3248
|
+
this.universal = universal;
|
|
3249
|
+
}
|
|
3250
|
+
supports(eventName) {
|
|
3251
|
+
return eventName === ResizeEventPlugin.EVENT_NAME;
|
|
3252
|
+
}
|
|
3253
|
+
addEventListener(element, eventName, handler) {
|
|
3254
|
+
const zone = this.manager.getZone();
|
|
3255
|
+
return zone.runOutsideAngular(() => {
|
|
3256
|
+
if (this.universal.isServer)
|
|
3257
|
+
return emptyRemove$1;
|
|
3258
|
+
const cb = el => {
|
|
3259
|
+
zone.run(() => handler(el));
|
|
3260
|
+
};
|
|
3261
|
+
if (isWindow(element)) {
|
|
3262
|
+
element.addEventListener(eventName, cb);
|
|
3263
|
+
}
|
|
3264
|
+
else {
|
|
3265
|
+
addListener(element, cb);
|
|
3266
|
+
}
|
|
3267
|
+
return () => {
|
|
3268
|
+
try {
|
|
3269
|
+
if (isWindow(element)) {
|
|
3270
|
+
element.removeEventListener(eventName, cb);
|
|
3271
|
+
}
|
|
3272
|
+
else {
|
|
3273
|
+
removeListener(element, cb);
|
|
3274
|
+
}
|
|
3275
|
+
}
|
|
3276
|
+
catch (e) {
|
|
3277
|
+
}
|
|
3278
|
+
};
|
|
3279
|
+
});
|
|
3280
|
+
}
|
|
3281
|
+
}
|
|
3282
|
+
ResizeEventPlugin.EVENT_NAME = "resize";
|
|
3283
|
+
ResizeEventPlugin.decorators = [
|
|
3284
|
+
{ type: Injectable }
|
|
3285
|
+
];
|
|
3286
|
+
ResizeEventPlugin.ctorParameters = () => [
|
|
3287
|
+
{ type: undefined, decorators: [{ type: Inject, args: [DOCUMENT,] }] },
|
|
3288
|
+
{ type: UniversalService }
|
|
3289
|
+
];
|
|
3290
|
+
|
|
3291
|
+
function emptyRemove() {
|
|
3292
|
+
}
|
|
3293
|
+
class ScrollEventPlugin extends ɵangular_packages_platform_browser_platform_browser_g {
|
|
3294
|
+
constructor(doc, universal) {
|
|
3295
|
+
super(doc);
|
|
3296
|
+
this.universal = universal;
|
|
3297
|
+
}
|
|
3298
|
+
supports(eventName) {
|
|
3299
|
+
return eventName === ScrollEventPlugin.EVENT_NAME;
|
|
3300
|
+
}
|
|
3301
|
+
addEventListener(element, eventName, handler) {
|
|
3302
|
+
const zone = this.manager.getZone();
|
|
3303
|
+
return zone.runOutsideAngular(() => {
|
|
3304
|
+
if (this.universal.isServer)
|
|
3305
|
+
return emptyRemove;
|
|
3306
|
+
const callback = (e) => {
|
|
3307
|
+
zone.run(() => handler(e));
|
|
3308
|
+
};
|
|
3309
|
+
element.addEventListener(eventName, callback);
|
|
3310
|
+
return () => element.removeEventListener(eventName, callback);
|
|
3311
|
+
});
|
|
3312
|
+
}
|
|
3313
|
+
}
|
|
3314
|
+
ScrollEventPlugin.EVENT_NAME = "scroll";
|
|
3315
|
+
ScrollEventPlugin.decorators = [
|
|
3316
|
+
{ type: Injectable }
|
|
3317
|
+
];
|
|
3318
|
+
ScrollEventPlugin.ctorParameters = () => [
|
|
3319
|
+
{ type: undefined, decorators: [{ type: Inject, args: [DOCUMENT,] }] },
|
|
3320
|
+
{ type: UniversalService }
|
|
3321
|
+
];
|
|
3322
|
+
|
|
3323
|
+
class ChunkPipe {
|
|
3324
|
+
transform(items, count) {
|
|
3325
|
+
const result = [];
|
|
3326
|
+
let subResult = null;
|
|
3327
|
+
items.forEach((item, index) => {
|
|
3328
|
+
if (index % count == 0) {
|
|
3329
|
+
subResult = [];
|
|
3330
|
+
result.push(subResult);
|
|
3331
|
+
}
|
|
3332
|
+
subResult.push(item);
|
|
3333
|
+
});
|
|
3334
|
+
return result;
|
|
3335
|
+
}
|
|
3336
|
+
}
|
|
3337
|
+
ChunkPipe.decorators = [
|
|
3338
|
+
{ type: Pipe, args: [{
|
|
3339
|
+
name: "chunk"
|
|
3340
|
+
},] }
|
|
3341
|
+
];
|
|
3342
|
+
|
|
3343
|
+
const emptyEntries = [];
|
|
3344
|
+
class EntriesPipe {
|
|
3345
|
+
transform(value) {
|
|
3346
|
+
if (!value)
|
|
3347
|
+
return emptyEntries;
|
|
3348
|
+
const entries = [];
|
|
3349
|
+
ObjectUtils.iterate(value, (val, key) => {
|
|
3350
|
+
entries.push({
|
|
3351
|
+
key: key,
|
|
3352
|
+
value: val,
|
|
3353
|
+
index: entries.length
|
|
3354
|
+
});
|
|
3355
|
+
});
|
|
3356
|
+
return entries;
|
|
3357
|
+
}
|
|
3358
|
+
}
|
|
3359
|
+
EntriesPipe.decorators = [
|
|
3360
|
+
{ type: Pipe, args: [{
|
|
3361
|
+
name: "entries"
|
|
3362
|
+
},] }
|
|
3363
|
+
];
|
|
3364
|
+
|
|
3365
|
+
class ExtraItemPropertiesPipe {
|
|
3366
|
+
transform(items, properties, params = {}) {
|
|
3367
|
+
const keys = Object.keys(properties);
|
|
3368
|
+
keys.forEach(key => {
|
|
3369
|
+
const value = properties[key];
|
|
3370
|
+
properties[key] = ObjectUtils.isFunction(value) ? value : (item, index, params) => {
|
|
3371
|
+
return ObjectUtils.evaluate(value, {
|
|
3372
|
+
item: item,
|
|
3373
|
+
index: index,
|
|
3374
|
+
params: params
|
|
3375
|
+
});
|
|
3376
|
+
};
|
|
3377
|
+
});
|
|
3378
|
+
return (items || []).map((item, index) => keys.reduce((result, key) => {
|
|
3379
|
+
result[key] = properties[key](item, index, params);
|
|
3380
|
+
return result;
|
|
3381
|
+
}, Object.assign({}, item)));
|
|
3382
|
+
}
|
|
3383
|
+
}
|
|
3384
|
+
ExtraItemPropertiesPipe.decorators = [
|
|
3385
|
+
{ type: Pipe, args: [{
|
|
3386
|
+
name: "extraItemProperties"
|
|
3387
|
+
},] }
|
|
3388
|
+
];
|
|
3389
|
+
|
|
3390
|
+
function defaultFilter$1() {
|
|
3391
|
+
return true;
|
|
3392
|
+
}
|
|
3393
|
+
class FilterPipe {
|
|
3394
|
+
transform(values, filter = defaultFilter$1, params = {}) {
|
|
3395
|
+
const isObject = ObjectUtils.isObject(values);
|
|
3396
|
+
if (!isObject && !ObjectUtils.isArray(values))
|
|
3397
|
+
return [];
|
|
3398
|
+
const filterFunc = ObjectUtils.isFunction(filter) ? filter : (value, key, params) => {
|
|
3399
|
+
return ObjectUtils.evaluate(filter, {
|
|
3400
|
+
value: value,
|
|
3401
|
+
key: key,
|
|
3402
|
+
item: value,
|
|
3403
|
+
index: key,
|
|
3404
|
+
params: params
|
|
3405
|
+
});
|
|
3406
|
+
};
|
|
3407
|
+
if (isObject) {
|
|
3408
|
+
return Object.keys(values).filter(key => {
|
|
3409
|
+
return filterFunc(values[key], key, params);
|
|
3410
|
+
}).reduce((result, key) => {
|
|
3411
|
+
result[key] = values[key];
|
|
3412
|
+
return result;
|
|
3413
|
+
}, {});
|
|
3414
|
+
}
|
|
3415
|
+
return values.filter((value, key) => {
|
|
3416
|
+
return filterFunc(value, key, params);
|
|
3417
|
+
});
|
|
3418
|
+
}
|
|
3419
|
+
}
|
|
3420
|
+
FilterPipe.decorators = [
|
|
3421
|
+
{ type: Pipe, args: [{
|
|
3422
|
+
name: "filter"
|
|
3423
|
+
},] }
|
|
3424
|
+
];
|
|
3425
|
+
|
|
3426
|
+
function defaultFilter() {
|
|
3427
|
+
return true;
|
|
3428
|
+
}
|
|
3429
|
+
class FindPipe {
|
|
3430
|
+
transform(values, filter = defaultFilter, params = {}) {
|
|
3431
|
+
if (!ObjectUtils.isArray(values))
|
|
3432
|
+
return [];
|
|
3433
|
+
const filterFunc = ObjectUtils.isFunction(filter) ? filter : (value, index, params) => {
|
|
3434
|
+
return ObjectUtils.evaluate(filter, {
|
|
3435
|
+
value: value,
|
|
3436
|
+
index: index,
|
|
3437
|
+
params: params
|
|
3438
|
+
});
|
|
3439
|
+
};
|
|
3440
|
+
return values.find((value, index) => filterFunc(value, index, params));
|
|
3441
|
+
}
|
|
3442
|
+
}
|
|
3443
|
+
FindPipe.decorators = [
|
|
3444
|
+
{ type: Pipe, args: [{
|
|
3445
|
+
name: "find"
|
|
3446
|
+
},] }
|
|
3447
|
+
];
|
|
3448
|
+
|
|
3449
|
+
class FormatNumberPipe {
|
|
3450
|
+
constructor(formatter) {
|
|
3451
|
+
this.formatter = formatter;
|
|
3452
|
+
}
|
|
3453
|
+
transform(value, format, precision, divider) {
|
|
3454
|
+
return this.formatter.formatNumber(value, format, precision, divider);
|
|
3455
|
+
}
|
|
3456
|
+
}
|
|
3457
|
+
FormatNumberPipe.decorators = [
|
|
3458
|
+
{ type: Pipe, args: [{
|
|
3459
|
+
name: "formatNumber"
|
|
3460
|
+
},] }
|
|
3461
|
+
];
|
|
3462
|
+
FormatNumberPipe.ctorParameters = () => [
|
|
3463
|
+
{ type: FormatterService }
|
|
3464
|
+
];
|
|
3465
|
+
|
|
3466
|
+
class GetOffsetPipe {
|
|
3467
|
+
transform(value, offset) {
|
|
3468
|
+
return value ? (ObjectUtils.isNullOrUndefined(offset) ? value : value[offset]) : null;
|
|
3469
|
+
}
|
|
3470
|
+
}
|
|
3471
|
+
GetOffsetPipe.decorators = [
|
|
3472
|
+
{ type: Pipe, args: [{
|
|
3473
|
+
name: "getOffset"
|
|
3474
|
+
},] }
|
|
3475
|
+
];
|
|
3476
|
+
|
|
3477
|
+
class GetTypePipe {
|
|
3478
|
+
transform(value) {
|
|
3479
|
+
return typeof value;
|
|
3480
|
+
}
|
|
3481
|
+
}
|
|
3482
|
+
GetTypePipe.decorators = [
|
|
3483
|
+
{ type: Pipe, args: [{
|
|
3484
|
+
name: "getType"
|
|
3485
|
+
},] }
|
|
3486
|
+
];
|
|
3487
|
+
|
|
3488
|
+
class GlobalTemplatePipe {
|
|
3489
|
+
constructor(globalTemplates) {
|
|
3490
|
+
this.globalTemplates = globalTemplates;
|
|
3491
|
+
this.cachedTemplateId = null;
|
|
3492
|
+
this.cachedTemplate = null;
|
|
3493
|
+
}
|
|
3494
|
+
ngOnInit() {
|
|
3495
|
+
this.templatesUpdated = this.globalTemplates.templatesUpdated.subscribe(() => {
|
|
3496
|
+
this.cachedTemplate = null;
|
|
3497
|
+
});
|
|
3498
|
+
}
|
|
3499
|
+
ngOnDestroy() {
|
|
3500
|
+
if (this.templatesUpdated)
|
|
3501
|
+
this.templatesUpdated.unsubscribe();
|
|
3502
|
+
}
|
|
3503
|
+
transform(templateId, component) {
|
|
3504
|
+
if (!templateId)
|
|
3505
|
+
return null;
|
|
3506
|
+
if (this.cachedTemplate === null || this.cachedTemplateId !== templateId) {
|
|
3507
|
+
this.cachedTemplateId = templateId;
|
|
3508
|
+
this.cachedTemplate = this.globalTemplates.get(templateId, component);
|
|
3509
|
+
}
|
|
3510
|
+
return this.cachedTemplate;
|
|
3511
|
+
}
|
|
3512
|
+
}
|
|
3513
|
+
GlobalTemplatePipe.decorators = [
|
|
3514
|
+
{ type: Pipe, args: [{
|
|
3515
|
+
pure: false,
|
|
3516
|
+
name: "globalTemplate"
|
|
3517
|
+
},] }
|
|
3518
|
+
];
|
|
3519
|
+
GlobalTemplatePipe.ctorParameters = () => [
|
|
3520
|
+
{ type: undefined, decorators: [{ type: Inject, args: [GLOBAL_TEMPLATES,] }] }
|
|
3521
|
+
];
|
|
3522
|
+
|
|
3523
|
+
class GroupByPipe {
|
|
3524
|
+
transform(records, column, map = null) {
|
|
3525
|
+
const groups = (records || []).reduce((result, item) => {
|
|
3526
|
+
const key = ObjectUtils.getValue(item, column) || "";
|
|
3527
|
+
const col = map ? (map[key] || "") : key;
|
|
3528
|
+
const group = result[col] || [];
|
|
3529
|
+
group.push(item);
|
|
3530
|
+
result[col] = group;
|
|
3531
|
+
return result;
|
|
3532
|
+
}, {});
|
|
3533
|
+
return Object.keys(groups).map(key => {
|
|
3534
|
+
return { group: key, items: groups[key] };
|
|
3535
|
+
});
|
|
3536
|
+
}
|
|
3537
|
+
}
|
|
3538
|
+
GroupByPipe.decorators = [
|
|
3539
|
+
{ type: Pipe, args: [{
|
|
3540
|
+
name: "groupBy"
|
|
3541
|
+
},] }
|
|
3542
|
+
];
|
|
3543
|
+
|
|
3544
|
+
class IsTypePipe {
|
|
3545
|
+
transform(value, type) {
|
|
3546
|
+
return (typeof value) === type;
|
|
3547
|
+
}
|
|
3548
|
+
}
|
|
3549
|
+
IsTypePipe.decorators = [
|
|
3550
|
+
{ type: Pipe, args: [{
|
|
3551
|
+
name: "isType"
|
|
3552
|
+
},] }
|
|
3553
|
+
];
|
|
3554
|
+
|
|
3555
|
+
class JoinPipe {
|
|
3556
|
+
transform(value, separator = ", ") {
|
|
3557
|
+
return (ObjectUtils.isArray(value))
|
|
3558
|
+
? value.join(separator)
|
|
3559
|
+
: "";
|
|
3560
|
+
}
|
|
3561
|
+
}
|
|
3562
|
+
JoinPipe.decorators = [
|
|
3563
|
+
{ type: Pipe, args: [{
|
|
3564
|
+
name: "join"
|
|
3565
|
+
},] }
|
|
3566
|
+
];
|
|
3567
|
+
|
|
3568
|
+
const emptyKeys = [];
|
|
3569
|
+
class KeysPipe {
|
|
3570
|
+
transform(value) {
|
|
3571
|
+
if (!value)
|
|
3572
|
+
return emptyKeys;
|
|
3573
|
+
return ObjectUtils.isArray(value)
|
|
3574
|
+
? Array.from(value.keys())
|
|
3575
|
+
: Object.keys(value);
|
|
3576
|
+
}
|
|
3577
|
+
}
|
|
3578
|
+
KeysPipe.decorators = [
|
|
3579
|
+
{ type: Pipe, args: [{
|
|
3580
|
+
name: "keys"
|
|
3581
|
+
},] }
|
|
3582
|
+
];
|
|
3583
|
+
|
|
3584
|
+
function defaultMapper(item) {
|
|
3585
|
+
return item;
|
|
3586
|
+
}
|
|
3587
|
+
class MapPipe {
|
|
3588
|
+
transform(values, mapper = defaultMapper, params = {}) {
|
|
3589
|
+
if (!ObjectUtils.isArray(values))
|
|
3590
|
+
return [];
|
|
3591
|
+
const mapperFunc = ObjectUtils.isFunction(mapper) ? mapper : (value, index, params) => {
|
|
3592
|
+
return ObjectUtils.evaluate(mapper, {
|
|
3593
|
+
value: value,
|
|
3594
|
+
index: index,
|
|
3595
|
+
params: params
|
|
3596
|
+
});
|
|
3597
|
+
};
|
|
3598
|
+
return values.map((value, index) => mapperFunc(value, index, params));
|
|
3599
|
+
}
|
|
3600
|
+
}
|
|
3601
|
+
MapPipe.decorators = [
|
|
3602
|
+
{ type: Pipe, args: [{
|
|
3603
|
+
name: "map"
|
|
3604
|
+
},] }
|
|
3605
|
+
];
|
|
3606
|
+
|
|
3607
|
+
class MaxPipe {
|
|
3608
|
+
transform(value, selector = null, params = {}) {
|
|
3609
|
+
selector = selector || (item => item);
|
|
3610
|
+
const maxSelector = ObjectUtils.isFunction(value) ? value : (item, index, params) => {
|
|
3611
|
+
return ObjectUtils.evaluate(selector, {
|
|
3612
|
+
item: item,
|
|
3613
|
+
index: index,
|
|
3614
|
+
params: params
|
|
3615
|
+
});
|
|
3616
|
+
};
|
|
3617
|
+
return ArrayUtils.max(value, (item, index) => maxSelector(item, index, params));
|
|
3618
|
+
}
|
|
3619
|
+
}
|
|
3620
|
+
MaxPipe.decorators = [
|
|
3621
|
+
{ type: Pipe, args: [{
|
|
3622
|
+
name: "max"
|
|
3623
|
+
},] }
|
|
3624
|
+
];
|
|
3625
|
+
|
|
3626
|
+
class MinPipe {
|
|
3627
|
+
transform(value, selector = null, params = {}) {
|
|
3628
|
+
selector = selector || (item => item);
|
|
3629
|
+
const minSelector = ObjectUtils.isFunction(value) ? value : (item, index, params) => {
|
|
3630
|
+
return ObjectUtils.evaluate(selector, {
|
|
3631
|
+
item: item,
|
|
3632
|
+
index: index,
|
|
3633
|
+
params: params
|
|
3634
|
+
});
|
|
3635
|
+
};
|
|
3636
|
+
return ArrayUtils.min(value, (item, index) => minSelector(item, index, params));
|
|
3637
|
+
}
|
|
3638
|
+
}
|
|
3639
|
+
MinPipe.decorators = [
|
|
3640
|
+
{ type: Pipe, args: [{
|
|
3641
|
+
name: "min"
|
|
3642
|
+
},] }
|
|
3643
|
+
];
|
|
3644
|
+
|
|
3645
|
+
class PopPipe {
|
|
3646
|
+
transform(value) {
|
|
3647
|
+
return !Array.isArray(value) ? null : Array.from(value).pop();
|
|
3648
|
+
}
|
|
3649
|
+
}
|
|
3650
|
+
PopPipe.decorators = [
|
|
3651
|
+
{ type: Pipe, args: [{
|
|
3652
|
+
name: "pop"
|
|
3653
|
+
},] }
|
|
3654
|
+
];
|
|
3655
|
+
|
|
3656
|
+
function defaultReducer(result) {
|
|
3657
|
+
return result;
|
|
3658
|
+
}
|
|
3659
|
+
class ReducePipe {
|
|
3660
|
+
transform(values, source, reducer = defaultReducer, params = {}) {
|
|
3661
|
+
if (!ObjectUtils.isArray(values))
|
|
3662
|
+
return [];
|
|
3663
|
+
const mapperFunc = ObjectUtils.isFunction(reducer) ? reducer : (result, value, index, params) => {
|
|
3664
|
+
return ObjectUtils.evaluate(reducer, {
|
|
3665
|
+
result: result,
|
|
3666
|
+
value: value,
|
|
3667
|
+
index: index,
|
|
3668
|
+
params: params
|
|
3669
|
+
});
|
|
3670
|
+
};
|
|
3671
|
+
return values.reduce((result, value, index) => mapperFunc(result, value, index, params), source);
|
|
3672
|
+
}
|
|
3673
|
+
}
|
|
3674
|
+
ReducePipe.decorators = [
|
|
3675
|
+
{ type: Pipe, args: [{
|
|
3676
|
+
name: "reduce"
|
|
3677
|
+
},] }
|
|
3678
|
+
];
|
|
3679
|
+
|
|
3680
|
+
const empty = {};
|
|
3681
|
+
class RemapPipe {
|
|
3682
|
+
transform(map, source, defaultValue = "key") {
|
|
3683
|
+
if (!map)
|
|
3684
|
+
return empty;
|
|
3685
|
+
if (!source)
|
|
3686
|
+
return map;
|
|
3687
|
+
const remapped = ObjectUtils.filter({ map: ObjectUtils.copy(map) }, (value, key, target) => {
|
|
3688
|
+
if (ObjectUtils.isArray(value) && value.every(ObjectUtils.isString)) {
|
|
3689
|
+
target[key] = value.reduce((result, k) => {
|
|
3690
|
+
result[k] = ObjectUtils.getValue(source, k, ObjectUtils.evaluate(defaultValue, { key: k, map: map, source: source }));
|
|
3691
|
+
return result;
|
|
3692
|
+
}, {});
|
|
3693
|
+
return false;
|
|
3694
|
+
}
|
|
3695
|
+
return true;
|
|
3696
|
+
});
|
|
3697
|
+
return remapped.map;
|
|
3698
|
+
}
|
|
3699
|
+
}
|
|
3700
|
+
RemapPipe.decorators = [
|
|
3701
|
+
{ type: Pipe, args: [{
|
|
3702
|
+
name: "remap"
|
|
3703
|
+
},] }
|
|
3704
|
+
];
|
|
3705
|
+
|
|
3706
|
+
class ReplacePipe {
|
|
3707
|
+
transform(value, from, to) {
|
|
3708
|
+
return value ? value.replace(from, to) : value;
|
|
3709
|
+
}
|
|
3710
|
+
}
|
|
3711
|
+
ReplacePipe.decorators = [
|
|
3712
|
+
{ type: Pipe, args: [{
|
|
3713
|
+
name: "replace"
|
|
3714
|
+
},] }
|
|
3715
|
+
];
|
|
3716
|
+
|
|
3717
|
+
const emptyArray = [];
|
|
3718
|
+
class ReversePipe {
|
|
3719
|
+
transform(value) {
|
|
3720
|
+
if (!ObjectUtils.isArray(value))
|
|
3721
|
+
return emptyArray;
|
|
3722
|
+
const result = [];
|
|
3723
|
+
for (let i = value.length - 1; i >= 0; i--) {
|
|
3724
|
+
result.push(value[i]);
|
|
3725
|
+
}
|
|
3726
|
+
return result;
|
|
3727
|
+
}
|
|
3728
|
+
}
|
|
3729
|
+
ReversePipe.decorators = [
|
|
3730
|
+
{ type: Pipe, args: [{
|
|
3731
|
+
name: "reverse"
|
|
3732
|
+
},] }
|
|
3733
|
+
];
|
|
3734
|
+
|
|
3735
|
+
class RoundPipe {
|
|
3736
|
+
constructor(formatter) {
|
|
3737
|
+
this.formatter = formatter;
|
|
3738
|
+
}
|
|
3739
|
+
transform(value, precision = 2, divider = 1) {
|
|
3740
|
+
return this.formatter.roundNumber(value, precision, divider);
|
|
3741
|
+
}
|
|
3742
|
+
}
|
|
3743
|
+
RoundPipe.decorators = [
|
|
3744
|
+
{ type: Pipe, args: [{
|
|
3745
|
+
name: "round"
|
|
3746
|
+
},] }
|
|
3747
|
+
];
|
|
3748
|
+
RoundPipe.ctorParameters = () => [
|
|
3749
|
+
{ type: FormatterService }
|
|
3750
|
+
];
|
|
3751
|
+
|
|
3752
|
+
class SafeHtmlPipe {
|
|
3753
|
+
constructor(sanitizer) {
|
|
3754
|
+
this.sanitizer = sanitizer;
|
|
3755
|
+
}
|
|
3756
|
+
transform(value, type = "html") {
|
|
3757
|
+
switch (type) {
|
|
3758
|
+
case "html":
|
|
3759
|
+
return this.sanitizer.bypassSecurityTrustHtml(value);
|
|
3760
|
+
case "style":
|
|
3761
|
+
return this.sanitizer.bypassSecurityTrustStyle(value);
|
|
3762
|
+
case "script":
|
|
3763
|
+
return this.sanitizer.bypassSecurityTrustScript(value);
|
|
3764
|
+
case "url":
|
|
3765
|
+
return this.sanitizer.bypassSecurityTrustUrl(value);
|
|
3766
|
+
case "resourceUrl":
|
|
3767
|
+
return this.sanitizer.bypassSecurityTrustResourceUrl(value);
|
|
3768
|
+
default:
|
|
3769
|
+
throw new Error(`SafePipe unable to bypass security for invalid type: ${type}`);
|
|
3770
|
+
}
|
|
3771
|
+
}
|
|
3772
|
+
}
|
|
3773
|
+
SafeHtmlPipe.decorators = [
|
|
3774
|
+
{ type: Pipe, args: [{
|
|
3775
|
+
name: "safe"
|
|
3776
|
+
},] }
|
|
3777
|
+
];
|
|
3778
|
+
SafeHtmlPipe.ctorParameters = () => [
|
|
3779
|
+
{ type: DomSanitizer }
|
|
3780
|
+
];
|
|
3781
|
+
|
|
3782
|
+
class ShiftPipe {
|
|
3783
|
+
transform(value) {
|
|
3784
|
+
return !Array.isArray(value) ? null : Array.from(value).shift();
|
|
3785
|
+
}
|
|
3786
|
+
}
|
|
3787
|
+
ShiftPipe.decorators = [
|
|
3788
|
+
{ type: Pipe, args: [{
|
|
3789
|
+
name: "shift"
|
|
3790
|
+
},] }
|
|
3791
|
+
];
|
|
3792
|
+
|
|
3793
|
+
class SplitPipe {
|
|
3794
|
+
transform(value, separator = ".") {
|
|
3795
|
+
return `${value}`.split(separator);
|
|
3796
|
+
}
|
|
3797
|
+
}
|
|
3798
|
+
SplitPipe.decorators = [
|
|
3799
|
+
{ type: Pipe, args: [{
|
|
3800
|
+
name: "split"
|
|
3801
|
+
},] }
|
|
3802
|
+
];
|
|
3803
|
+
|
|
3804
|
+
class TranslatePipe {
|
|
3805
|
+
constructor(cdr, language) {
|
|
3806
|
+
this.cdr = cdr;
|
|
3807
|
+
this.language = language;
|
|
3808
|
+
}
|
|
3809
|
+
get currentLang() {
|
|
3810
|
+
return this.language.currentLanguage;
|
|
3811
|
+
}
|
|
3812
|
+
transform(query, ...args) {
|
|
3813
|
+
if (!query)
|
|
3814
|
+
return "";
|
|
3815
|
+
let dirty = false;
|
|
3816
|
+
const lang = this.currentLang;
|
|
3817
|
+
if (this.lang !== lang) {
|
|
3818
|
+
this.lang = lang;
|
|
3819
|
+
dirty = true;
|
|
3820
|
+
}
|
|
3821
|
+
const disabled = this.language.disableTranslations;
|
|
3822
|
+
if (this.disabled !== disabled) {
|
|
3823
|
+
this.disabled = disabled;
|
|
3824
|
+
dirty = true;
|
|
3825
|
+
}
|
|
3826
|
+
if (!ObjectUtils.equals(this.query, query)) {
|
|
3827
|
+
this.query = query;
|
|
3828
|
+
dirty = true;
|
|
3829
|
+
}
|
|
3830
|
+
if (!ObjectUtils.equals(this.args, args)) {
|
|
3831
|
+
this.args = args;
|
|
3832
|
+
this.params = null;
|
|
3833
|
+
if (ObjectUtils.isDefined(args[0]) && args.length) {
|
|
3834
|
+
if (typeof args[0] === "string" && args[0].length) {
|
|
3835
|
+
const validArgs = args[0]
|
|
3836
|
+
.replace(/(\')?([a-zA-Z0-9_]+)(\')?(\s)?:/g, `"$2":`)
|
|
3837
|
+
.replace(/:(\s)?(\')(.*?)(\')/g, `:"$3"`);
|
|
3838
|
+
try {
|
|
3839
|
+
this.params = JSON.parse(validArgs);
|
|
3840
|
+
}
|
|
3841
|
+
catch (e) {
|
|
3842
|
+
throw new SyntaxError(`Wrong parameter in TranslatePipe. Expected a valid Object, received: ${args[0]}`);
|
|
3843
|
+
}
|
|
3844
|
+
}
|
|
3845
|
+
else if (typeof args[0] === "object" && !Array.isArray(args[0])) {
|
|
3846
|
+
this.params = args[0];
|
|
3847
|
+
}
|
|
3848
|
+
}
|
|
3849
|
+
dirty = true;
|
|
3850
|
+
}
|
|
3851
|
+
if (dirty) {
|
|
3852
|
+
if (typeof query === "object") {
|
|
3853
|
+
this.lastValue = Array.isArray(query) ? this.language.getTranslationFromArray(query, this.params, lang) : this.language.getTranslationFromObject(query, this.params, lang);
|
|
3854
|
+
return this.lastValue;
|
|
3855
|
+
}
|
|
3856
|
+
if (this.disabled) {
|
|
3857
|
+
this.lastValue = query;
|
|
3858
|
+
return this.lastValue;
|
|
3859
|
+
}
|
|
3860
|
+
this.language.getTranslation(query, this.params).then(value => {
|
|
3861
|
+
this.lastValue = value;
|
|
3862
|
+
if (!this.cdr["destroyed"]) {
|
|
3863
|
+
this.cdr.detectChanges();
|
|
3864
|
+
}
|
|
3865
|
+
});
|
|
3866
|
+
}
|
|
3867
|
+
return this.lastValue;
|
|
3868
|
+
}
|
|
3869
|
+
}
|
|
3870
|
+
TranslatePipe.decorators = [
|
|
3871
|
+
{ type: Injectable },
|
|
3872
|
+
{ type: Pipe, args: [{
|
|
3873
|
+
name: "translate",
|
|
3874
|
+
pure: false
|
|
3875
|
+
},] }
|
|
3876
|
+
];
|
|
3877
|
+
TranslatePipe.ctorParameters = () => [
|
|
3878
|
+
{ type: ChangeDetectorRef },
|
|
3879
|
+
{ type: undefined, decorators: [{ type: Inject, args: [LANGUAGE_SERVICE,] }] }
|
|
3880
|
+
];
|
|
3881
|
+
|
|
3882
|
+
const emptyValues = [];
|
|
3883
|
+
class ValuesPipe {
|
|
3884
|
+
transform(value) {
|
|
3885
|
+
if (!value)
|
|
3886
|
+
return emptyValues;
|
|
3887
|
+
return ObjectUtils.isArray(value)
|
|
3888
|
+
? value
|
|
3889
|
+
: Object.keys(value).map(key => value[key]);
|
|
3890
|
+
}
|
|
3891
|
+
}
|
|
3892
|
+
ValuesPipe.decorators = [
|
|
3893
|
+
{ type: Pipe, args: [{
|
|
3894
|
+
name: "values"
|
|
3895
|
+
},] }
|
|
3896
|
+
];
|
|
3897
|
+
|
|
3898
|
+
class AsyncMethodBase {
|
|
3899
|
+
constructor(toaster) {
|
|
3900
|
+
this.toaster = toaster;
|
|
3901
|
+
this.onSuccess = new EventEmitter();
|
|
3902
|
+
this.onError = new EventEmitter();
|
|
3903
|
+
}
|
|
3904
|
+
get isDisabled() {
|
|
3905
|
+
return this.disabled;
|
|
3906
|
+
}
|
|
3907
|
+
get isLoading() {
|
|
3908
|
+
return this.loading;
|
|
3909
|
+
}
|
|
3910
|
+
click() {
|
|
3911
|
+
if (this.disabled)
|
|
3912
|
+
return;
|
|
3913
|
+
this.callMethod();
|
|
3914
|
+
}
|
|
3915
|
+
callMethod() {
|
|
3916
|
+
if (this.loading)
|
|
3917
|
+
return true;
|
|
3918
|
+
this.loading = true;
|
|
3919
|
+
const method = this.getMethod();
|
|
3920
|
+
const result = !method ? null : method(this.context);
|
|
3921
|
+
if (!(result instanceof Promise)) {
|
|
3922
|
+
this.loading = false;
|
|
3923
|
+
return false;
|
|
3924
|
+
}
|
|
3925
|
+
result.then(result => {
|
|
3926
|
+
this.loading = false;
|
|
3927
|
+
if (result) {
|
|
3928
|
+
this.onSuccess.emit(result);
|
|
3929
|
+
this.toaster.success(result.message, result.context);
|
|
3930
|
+
}
|
|
3931
|
+
}, reason => {
|
|
3932
|
+
if (!reason || !reason.message)
|
|
3933
|
+
throw new Error("Reason must implement IAsyncMessage interface");
|
|
3934
|
+
this.loading = false;
|
|
3935
|
+
this.onError.emit(reason);
|
|
3936
|
+
this.toaster.error(reason.message, reason.context);
|
|
3937
|
+
});
|
|
3938
|
+
return true;
|
|
3939
|
+
}
|
|
3940
|
+
}
|
|
3941
|
+
AsyncMethodBase.propDecorators = {
|
|
3942
|
+
disabled: [{ type: Input }],
|
|
3943
|
+
context: [{ type: Input }],
|
|
3944
|
+
onSuccess: [{ type: Output }],
|
|
3945
|
+
onError: [{ type: Output }],
|
|
3946
|
+
isDisabled: [{ type: HostBinding, args: ["class.disabled",] }],
|
|
3947
|
+
isLoading: [{ type: HostBinding, args: ["class.loading",] }],
|
|
3948
|
+
click: [{ type: HostListener, args: ["click",] }]
|
|
3949
|
+
};
|
|
3950
|
+
|
|
3951
|
+
class AsyncMethodDirective extends AsyncMethodBase {
|
|
3952
|
+
constructor(toaster) {
|
|
3953
|
+
super(toaster);
|
|
3954
|
+
}
|
|
3955
|
+
getMethod() {
|
|
3956
|
+
return this.method;
|
|
3957
|
+
}
|
|
3958
|
+
}
|
|
3959
|
+
AsyncMethodDirective.decorators = [
|
|
3960
|
+
{ type: Directive, args: [{
|
|
3961
|
+
selector: "[async-method]",
|
|
3962
|
+
exportAs: "async-method"
|
|
3963
|
+
},] }
|
|
3964
|
+
];
|
|
3965
|
+
AsyncMethodDirective.ctorParameters = () => [
|
|
3966
|
+
{ type: undefined, decorators: [{ type: Inject, args: [TOASTER_SERVICE,] }] }
|
|
3967
|
+
];
|
|
3968
|
+
AsyncMethodDirective.propDecorators = {
|
|
3969
|
+
method: [{ type: Input, args: ["async-method",] }]
|
|
3970
|
+
};
|
|
3971
|
+
|
|
3972
|
+
const defaultClass = "default-image";
|
|
3973
|
+
const loadingClass = "loading-image";
|
|
3974
|
+
class BackgroundDirective {
|
|
3975
|
+
constructor(http, element, renderer, universal) {
|
|
3976
|
+
this.http = http;
|
|
3977
|
+
this.element = element;
|
|
3978
|
+
this.renderer = renderer;
|
|
3979
|
+
this.universal = universal;
|
|
3980
|
+
}
|
|
3981
|
+
ngOnChanges(changes) {
|
|
3982
|
+
if (this.universal.isServer) {
|
|
3983
|
+
this.setBackground(this.background);
|
|
3984
|
+
return;
|
|
3985
|
+
}
|
|
3986
|
+
this.renderer.removeClass(this.element.nativeElement, defaultClass);
|
|
3987
|
+
this.renderer.addClass(this.element.nativeElement, loadingClass);
|
|
3988
|
+
FileUtils.readDataFromUrl(this.http, this.background).then(url => {
|
|
3989
|
+
this.setBackground(url);
|
|
3990
|
+
}, () => {
|
|
3991
|
+
this.renderer.removeClass(this.element.nativeElement, loadingClass);
|
|
3992
|
+
this.renderer.addClass(this.element.nativeElement, defaultClass);
|
|
3993
|
+
});
|
|
3994
|
+
}
|
|
3995
|
+
setBackground(url) {
|
|
3996
|
+
this.renderer.removeClass(this.element.nativeElement, loadingClass);
|
|
3997
|
+
this.renderer.setStyle(this.element.nativeElement, "background-image", `url('${url}')`);
|
|
3998
|
+
if (!this.backgroundSize)
|
|
3999
|
+
return;
|
|
4000
|
+
this.renderer.setStyle(this.element.nativeElement, "background-size", this.backgroundSize);
|
|
4001
|
+
}
|
|
4002
|
+
}
|
|
4003
|
+
BackgroundDirective.decorators = [
|
|
4004
|
+
{ type: Directive, args: [{
|
|
4005
|
+
selector: "[background]"
|
|
4006
|
+
},] }
|
|
4007
|
+
];
|
|
4008
|
+
BackgroundDirective.ctorParameters = () => [
|
|
4009
|
+
{ type: HttpClient },
|
|
4010
|
+
{ type: ElementRef },
|
|
4011
|
+
{ type: Renderer2 },
|
|
4012
|
+
{ type: UniversalService }
|
|
4013
|
+
];
|
|
4014
|
+
BackgroundDirective.propDecorators = {
|
|
4015
|
+
background: [{ type: Input }],
|
|
4016
|
+
backgroundSize: [{ type: Input }]
|
|
4017
|
+
};
|
|
4018
|
+
|
|
4019
|
+
class DynamicTableTemplateDirective {
|
|
4020
|
+
constructor(ref) {
|
|
4021
|
+
this.ref = ref;
|
|
4022
|
+
}
|
|
4023
|
+
}
|
|
4024
|
+
DynamicTableTemplateDirective.decorators = [
|
|
4025
|
+
{ type: Directive, args: [{
|
|
4026
|
+
selector: "ng-template[column]"
|
|
4027
|
+
},] }
|
|
4028
|
+
];
|
|
4029
|
+
DynamicTableTemplateDirective.ctorParameters = () => [
|
|
4030
|
+
{ type: TemplateRef }
|
|
4031
|
+
];
|
|
4032
|
+
DynamicTableTemplateDirective.propDecorators = {
|
|
4033
|
+
column: [{ type: Input }],
|
|
4034
|
+
pure: [{ type: Input }]
|
|
4035
|
+
};
|
|
4036
|
+
|
|
4037
|
+
class GlobalTemplateDirective {
|
|
4038
|
+
constructor(globalTemplates, template) {
|
|
4039
|
+
this.globalTemplates = globalTemplates;
|
|
4040
|
+
this.template = template;
|
|
4041
|
+
}
|
|
4042
|
+
ngOnInit() {
|
|
4043
|
+
this.globalTemplates.add(this.id, this.template);
|
|
4044
|
+
}
|
|
4045
|
+
ngOnDestroy() {
|
|
4046
|
+
this.globalTemplates.remove(this.id);
|
|
4047
|
+
}
|
|
4048
|
+
}
|
|
4049
|
+
GlobalTemplateDirective.decorators = [
|
|
4050
|
+
{ type: Directive, args: [{
|
|
4051
|
+
selector: "[globalTemplate]"
|
|
4052
|
+
},] }
|
|
4053
|
+
];
|
|
4054
|
+
GlobalTemplateDirective.ctorParameters = () => [
|
|
4055
|
+
{ type: undefined, decorators: [{ type: Inject, args: [GLOBAL_TEMPLATES,] }] },
|
|
4056
|
+
{ type: TemplateRef }
|
|
4057
|
+
];
|
|
4058
|
+
GlobalTemplateDirective.propDecorators = {
|
|
4059
|
+
id: [{ type: Input, args: ["globalTemplate",] }]
|
|
4060
|
+
};
|
|
4061
|
+
|
|
4062
|
+
class IconDirective {
|
|
4063
|
+
constructor(element, renderer, icons) {
|
|
4064
|
+
this.element = element;
|
|
4065
|
+
this.renderer = renderer;
|
|
4066
|
+
this.icons = icons;
|
|
4067
|
+
this.renderer.addClass(this.element.nativeElement, "svg-icon");
|
|
4068
|
+
this.activeChange = new EventEmitter();
|
|
4069
|
+
}
|
|
4070
|
+
get isActive() {
|
|
4071
|
+
return this.active;
|
|
4072
|
+
}
|
|
4073
|
+
ngOnInit() {
|
|
4074
|
+
this.iconsLoaded = this.icons.iconsLoaded.subscribe(() => this.changeIcon());
|
|
4075
|
+
}
|
|
4076
|
+
ngOnDestroy() {
|
|
4077
|
+
if (this.iconsLoaded)
|
|
4078
|
+
this.iconsLoaded.unsubscribe();
|
|
4079
|
+
}
|
|
4080
|
+
ngOnChanges(changes) {
|
|
4081
|
+
if (changes.icon) {
|
|
4082
|
+
this.renderer.removeClass(this.element.nativeElement, `svg-icon-${changes.icon.previousValue}`);
|
|
4083
|
+
this.renderer.addClass(this.element.nativeElement, `svg-icon-${changes.icon.currentValue}`);
|
|
4084
|
+
}
|
|
4085
|
+
this.changeIcon();
|
|
4086
|
+
}
|
|
4087
|
+
click() {
|
|
4088
|
+
this.active = !this.active;
|
|
4089
|
+
this.activeChange.emit(this.active);
|
|
4090
|
+
this.changeIcon();
|
|
4091
|
+
}
|
|
4092
|
+
changeIcon() {
|
|
4093
|
+
this.icons.getIcon(this.icon, this.activeIcon || `${this.icon}-active`, this.active).then(icon => {
|
|
4094
|
+
if (this.icons.isDisabled)
|
|
4095
|
+
return;
|
|
4096
|
+
this.element.nativeElement.innerHTML = icon;
|
|
4097
|
+
});
|
|
4098
|
+
}
|
|
4099
|
+
}
|
|
4100
|
+
IconDirective.decorators = [
|
|
4101
|
+
{ type: Directive, args: [{
|
|
4102
|
+
selector: "[icon]"
|
|
4103
|
+
},] }
|
|
4104
|
+
];
|
|
4105
|
+
IconDirective.ctorParameters = () => [
|
|
4106
|
+
{ type: ElementRef },
|
|
4107
|
+
{ type: Renderer2 },
|
|
4108
|
+
{ type: undefined, decorators: [{ type: Inject, args: [ICON_SERVICE,] }] }
|
|
4109
|
+
];
|
|
4110
|
+
IconDirective.propDecorators = {
|
|
4111
|
+
icon: [{ type: Input }],
|
|
4112
|
+
activeIcon: [{ type: Input }],
|
|
4113
|
+
active: [{ type: Input }],
|
|
4114
|
+
activeChange: [{ type: Output }],
|
|
4115
|
+
isActive: [{ type: HostBinding, args: ["class.active",] }],
|
|
4116
|
+
click: [{ type: HostListener, args: ["click",] }]
|
|
4117
|
+
};
|
|
4118
|
+
|
|
4119
|
+
class NgxTemplateOutletDirective {
|
|
4120
|
+
constructor(_viewContainerRef) {
|
|
4121
|
+
this._viewContainerRef = _viewContainerRef;
|
|
4122
|
+
}
|
|
4123
|
+
static hasContextShapeChanged(ctxChange) {
|
|
4124
|
+
const prevCtxKeys = Object.keys(ctxChange.previousValue || {});
|
|
4125
|
+
const currCtxKeys = Object.keys(ctxChange.currentValue || {});
|
|
4126
|
+
if (prevCtxKeys.length === currCtxKeys.length) {
|
|
4127
|
+
for (const propName of currCtxKeys) {
|
|
4128
|
+
if (prevCtxKeys.indexOf(propName) === -1) {
|
|
4129
|
+
return true;
|
|
4130
|
+
}
|
|
4131
|
+
}
|
|
4132
|
+
return false;
|
|
4133
|
+
}
|
|
4134
|
+
else {
|
|
4135
|
+
return true;
|
|
4136
|
+
}
|
|
4137
|
+
}
|
|
4138
|
+
ngOnChanges(changes) {
|
|
4139
|
+
const recreateView = this.shouldRecreateView(changes);
|
|
4140
|
+
if (recreateView) {
|
|
4141
|
+
if (this.viewRef)
|
|
4142
|
+
this._viewContainerRef.remove(this._viewContainerRef.indexOf(this.viewRef));
|
|
4143
|
+
if (this.ngxTemplateOutlet)
|
|
4144
|
+
this.viewRef = this._viewContainerRef.createEmbeddedView(this.ngxTemplateOutlet, {});
|
|
4145
|
+
}
|
|
4146
|
+
this.ngDoCheck();
|
|
4147
|
+
}
|
|
4148
|
+
ngDoCheck() {
|
|
4149
|
+
if (!this.viewRef)
|
|
4150
|
+
return;
|
|
4151
|
+
const context = this.viewRef.context;
|
|
4152
|
+
this.updateExistingContext(this.context, context);
|
|
4153
|
+
this.updateExistingContext(this.additionalContext, context);
|
|
4154
|
+
context.$implicit = context;
|
|
4155
|
+
}
|
|
4156
|
+
shouldRecreateView(changes) {
|
|
4157
|
+
const ctxChange = changes["context"];
|
|
4158
|
+
const aCtxChange = changes["additionalContext"];
|
|
4159
|
+
return !!changes["ngxTemplateOutlet"]
|
|
4160
|
+
|| (ctxChange && NgxTemplateOutletDirective.hasContextShapeChanged(ctxChange))
|
|
4161
|
+
|| (aCtxChange && NgxTemplateOutletDirective.hasContextShapeChanged(aCtxChange));
|
|
4162
|
+
}
|
|
4163
|
+
updateExistingContext(ctx, context) {
|
|
4164
|
+
if (!ctx)
|
|
4165
|
+
return;
|
|
4166
|
+
let ctxProto = Object.getPrototypeOf(ctx);
|
|
4167
|
+
if (ctxProto == Object.prototype) {
|
|
4168
|
+
ctxProto = ctx;
|
|
4169
|
+
}
|
|
4170
|
+
const props = Object.getOwnPropertyNames(ctxProto);
|
|
4171
|
+
for (const propName of props) {
|
|
4172
|
+
const desc = Object.getOwnPropertyDescriptor(ctxProto, propName);
|
|
4173
|
+
// Copy if its a getter and it is not $implicit
|
|
4174
|
+
if (desc.get && propName !== "$implicit") {
|
|
4175
|
+
Object.defineProperty(context, propName, desc);
|
|
4176
|
+
continue;
|
|
4177
|
+
}
|
|
4178
|
+
const func = ObjectUtils.isFunction(desc.value) ? desc.value.bind(ctx) : null;
|
|
4179
|
+
if (func && func !== ctxProto.constructor) {
|
|
4180
|
+
context[propName] = func;
|
|
4181
|
+
}
|
|
4182
|
+
}
|
|
4183
|
+
for (const propName of Object.keys(ctx)) {
|
|
4184
|
+
const desc = Object.getOwnPropertyDescriptor(ctxProto, propName);
|
|
4185
|
+
if (desc && desc.get && !desc.set)
|
|
4186
|
+
continue;
|
|
4187
|
+
context[propName] = ctx[propName];
|
|
4188
|
+
}
|
|
4189
|
+
}
|
|
4190
|
+
}
|
|
4191
|
+
NgxTemplateOutletDirective.decorators = [
|
|
4192
|
+
{ type: Directive, args: [{
|
|
4193
|
+
selector: "[ngxTemplateOutlet]"
|
|
4194
|
+
},] }
|
|
4195
|
+
];
|
|
4196
|
+
NgxTemplateOutletDirective.ctorParameters = () => [
|
|
4197
|
+
{ type: ViewContainerRef }
|
|
4198
|
+
];
|
|
4199
|
+
NgxTemplateOutletDirective.propDecorators = {
|
|
4200
|
+
context: [{ type: Input }],
|
|
4201
|
+
additionalContext: [{ type: Input }],
|
|
4202
|
+
ngxTemplateOutlet: [{ type: Input }]
|
|
4203
|
+
};
|
|
4204
|
+
|
|
4205
|
+
class PaginationDirective {
|
|
4206
|
+
constructor(zone) {
|
|
4207
|
+
this.zone = zone;
|
|
4208
|
+
this.pageChange = new EventEmitter();
|
|
4209
|
+
this.onRefresh = new EventEmitter();
|
|
4210
|
+
this.updateTimer = TimerUtils.createTimeout(() => this.loadData(), this.updateTime);
|
|
4211
|
+
}
|
|
4212
|
+
get total() {
|
|
4213
|
+
return this.data ? this.data.total : 0;
|
|
4214
|
+
}
|
|
4215
|
+
get items() {
|
|
4216
|
+
return this.data ? this.data.items : [];
|
|
4217
|
+
}
|
|
4218
|
+
ngOnChanges(changes) {
|
|
4219
|
+
if (!changes.loader && !changes.itemsPerPage && !changes.page)
|
|
4220
|
+
return;
|
|
4221
|
+
this.page = isNaN(this.page) || this.page < 1 ? 1 : this.page;
|
|
4222
|
+
this.itemsPerPage = isNaN(this.itemsPerPage) || this.itemsPerPage < 1 ? 20 : this.itemsPerPage;
|
|
4223
|
+
this.updateTimer.time = isNaN(this.updateTime) || this.updateTime < 0 ? 100 : this.updateTime;
|
|
4224
|
+
this.waitFor = this.waitFor || Promise.resolve(true);
|
|
4225
|
+
this.refresh();
|
|
4226
|
+
}
|
|
4227
|
+
refresh() {
|
|
4228
|
+
this.waitFor.then(() => {
|
|
4229
|
+
this.updateTimer.run();
|
|
4230
|
+
});
|
|
4231
|
+
}
|
|
4232
|
+
paginate(page) {
|
|
4233
|
+
this.page = page;
|
|
4234
|
+
this.pageChange.emit(page);
|
|
4235
|
+
this.refresh();
|
|
4236
|
+
}
|
|
4237
|
+
loadData() {
|
|
4238
|
+
if (!this.loader)
|
|
4239
|
+
return;
|
|
4240
|
+
this.loader(this.page, this.itemsPerPage).then(data => {
|
|
4241
|
+
this.maxPage = !data || data.total <= 0 ? 1 : Math.floor((data.total - 1) / this.itemsPerPage) + 1;
|
|
4242
|
+
this.data = data;
|
|
4243
|
+
const baseIndex = (this.page - 1) * this.itemsPerPage;
|
|
4244
|
+
const items = (data.items || []);
|
|
4245
|
+
data.items = items.map((item, index) => {
|
|
4246
|
+
const ix = baseIndex + index;
|
|
4247
|
+
return item instanceof PaginationItemContext
|
|
4248
|
+
? item
|
|
4249
|
+
: new PaginationItemContext(item, items, items.length, index, ix);
|
|
4250
|
+
});
|
|
4251
|
+
if (this.page > this.maxPage) {
|
|
4252
|
+
this.paginate(this.maxPage);
|
|
4253
|
+
return;
|
|
4254
|
+
}
|
|
4255
|
+
this.zone.run(() => this.onRefresh.emit(this));
|
|
4256
|
+
});
|
|
4257
|
+
}
|
|
4258
|
+
}
|
|
4259
|
+
PaginationDirective.decorators = [
|
|
4260
|
+
{ type: Directive, args: [{
|
|
4261
|
+
selector: "[pagination]",
|
|
4262
|
+
exportAs: "pagination"
|
|
4263
|
+
},] }
|
|
4264
|
+
];
|
|
4265
|
+
PaginationDirective.ctorParameters = () => [
|
|
4266
|
+
{ type: NgZone }
|
|
4267
|
+
];
|
|
4268
|
+
PaginationDirective.propDecorators = {
|
|
4269
|
+
loader: [{ type: Input, args: ["pagination",] }],
|
|
4270
|
+
page: [{ type: Input }],
|
|
4271
|
+
itemsPerPage: [{ type: Input }],
|
|
4272
|
+
updateTime: [{ type: Input }],
|
|
4273
|
+
waitFor: [{ type: Input }],
|
|
4274
|
+
pageChange: [{ type: Output }],
|
|
4275
|
+
onRefresh: [{ type: Output }]
|
|
4276
|
+
};
|
|
4277
|
+
|
|
4278
|
+
class PaginationItemDirective {
|
|
4279
|
+
constructor(pagination, viewContainer, templateRef) {
|
|
4280
|
+
this.pagination = pagination;
|
|
4281
|
+
this.viewContainer = viewContainer;
|
|
4282
|
+
this.templateRef = templateRef;
|
|
4283
|
+
}
|
|
4284
|
+
ngOnInit() {
|
|
4285
|
+
this.onRefresh = this.pagination.onRefresh.subscribe(() => this.renderView());
|
|
4286
|
+
}
|
|
4287
|
+
ngOnDestroy() {
|
|
4288
|
+
this.onRefresh.unsubscribe();
|
|
4289
|
+
}
|
|
4290
|
+
renderView() {
|
|
4291
|
+
this.viewContainer.clear();
|
|
4292
|
+
this.pagination.items.forEach((item) => {
|
|
4293
|
+
item.$implicit = item;
|
|
4294
|
+
this.viewContainer.createEmbeddedView(this.templateRef, item);
|
|
4295
|
+
});
|
|
4296
|
+
}
|
|
4297
|
+
}
|
|
4298
|
+
PaginationItemDirective.decorators = [
|
|
4299
|
+
{ type: Directive, args: [{
|
|
4300
|
+
selector: "[paginationItem]"
|
|
4301
|
+
},] }
|
|
4302
|
+
];
|
|
4303
|
+
PaginationItemDirective.ctorParameters = () => [
|
|
4304
|
+
{ type: PaginationDirective },
|
|
4305
|
+
{ type: ViewContainerRef },
|
|
4306
|
+
{ type: TemplateRef }
|
|
4307
|
+
];
|
|
4308
|
+
|
|
4309
|
+
class ResourceIfDirective {
|
|
4310
|
+
constructor(http, viewContainer, templateRef, universal) {
|
|
4311
|
+
this.http = http;
|
|
4312
|
+
this.viewContainer = viewContainer;
|
|
4313
|
+
this.templateRef = templateRef;
|
|
4314
|
+
this.universal = universal;
|
|
4315
|
+
this.context = new ResourceIfContext();
|
|
4316
|
+
}
|
|
4317
|
+
set resourceIf(resource) {
|
|
4318
|
+
this.resource = resource;
|
|
4319
|
+
this.renderView();
|
|
4320
|
+
}
|
|
4321
|
+
get resourceIf() {
|
|
4322
|
+
return this.resource;
|
|
4323
|
+
}
|
|
4324
|
+
get url() {
|
|
4325
|
+
return this.context.url;
|
|
4326
|
+
}
|
|
4327
|
+
renderView() {
|
|
4328
|
+
this.context = new ResourceIfContext();
|
|
4329
|
+
this.context.resource = this.resource;
|
|
4330
|
+
this.viewContainer.clear();
|
|
4331
|
+
if (this.universal.isBrowser && this.resource) {
|
|
4332
|
+
FileUtils.readDataFromUrl(this.http, this.resource).then(url => {
|
|
4333
|
+
this.context.url = url;
|
|
4334
|
+
this.viewContainer.createEmbeddedView(this.templateRef, this.context);
|
|
4335
|
+
}, console.log);
|
|
4336
|
+
}
|
|
4337
|
+
}
|
|
4338
|
+
}
|
|
4339
|
+
ResourceIfDirective.decorators = [
|
|
4340
|
+
{ type: Directive, args: [{
|
|
4341
|
+
selector: "[resourceIf]",
|
|
4342
|
+
exportAs: "resourceIf"
|
|
4343
|
+
},] }
|
|
4344
|
+
];
|
|
4345
|
+
ResourceIfDirective.ctorParameters = () => [
|
|
4346
|
+
{ type: HttpClient },
|
|
4347
|
+
{ type: ViewContainerRef },
|
|
4348
|
+
{ type: TemplateRef },
|
|
4349
|
+
{ type: UniversalService }
|
|
4350
|
+
];
|
|
4351
|
+
ResourceIfDirective.propDecorators = {
|
|
4352
|
+
resourceIf: [{ type: Input }]
|
|
4353
|
+
};
|
|
4354
|
+
|
|
4355
|
+
class StickyDirective {
|
|
4356
|
+
constructor(cdr, events, element) {
|
|
4357
|
+
this.cdr = cdr;
|
|
4358
|
+
this.events = events;
|
|
4359
|
+
this.element = element;
|
|
4360
|
+
this.parentElement = this.element.nativeElement.parentElement;
|
|
4361
|
+
this.updateTimer = TimerUtils.createTimeout(() => {
|
|
4362
|
+
this.isUpdating = false;
|
|
4363
|
+
this.cdr.detectChanges();
|
|
4364
|
+
this.events.updateSticky(this.isSticky);
|
|
4365
|
+
}, 10);
|
|
4366
|
+
}
|
|
4367
|
+
ngOnInit() {
|
|
4368
|
+
this.eventForwarded = this.events.eventForwarded.subscribe((e) => {
|
|
4369
|
+
if (e && e.type === "scroll")
|
|
4370
|
+
this.updateSticky();
|
|
4371
|
+
});
|
|
4372
|
+
}
|
|
4373
|
+
ngOnDestroy() {
|
|
4374
|
+
this.eventForwarded.unsubscribe();
|
|
4375
|
+
}
|
|
4376
|
+
updateSticky() {
|
|
4377
|
+
const distanceToTop = this.parentElement.getBoundingClientRect().top;
|
|
4378
|
+
this.isSticky = distanceToTop < 1;
|
|
4379
|
+
this.isUpdating = true;
|
|
4380
|
+
this.cdr.detectChanges();
|
|
4381
|
+
this.updateTimer.run();
|
|
4382
|
+
}
|
|
4383
|
+
}
|
|
4384
|
+
StickyDirective.decorators = [
|
|
4385
|
+
{ type: Directive, args: [{
|
|
4386
|
+
selector: "[sticky]"
|
|
4387
|
+
},] }
|
|
4388
|
+
];
|
|
4389
|
+
StickyDirective.ctorParameters = () => [
|
|
4390
|
+
{ type: ChangeDetectorRef },
|
|
4391
|
+
{ type: EventsService },
|
|
4392
|
+
{ type: ElementRef }
|
|
4393
|
+
];
|
|
4394
|
+
StickyDirective.propDecorators = {
|
|
4395
|
+
isSticky: [{ type: HostBinding, args: ["class.sticky",] }],
|
|
4396
|
+
isUpdating: [{ type: HostBinding, args: ["class.sticky-update",] }],
|
|
4397
|
+
updateSticky: [{ type: HostListener, args: ["window:resize",] }, { type: HostListener, args: ["window:scroll",] }]
|
|
4398
|
+
};
|
|
4399
|
+
|
|
4400
|
+
class UnorderedListItemDirective {
|
|
4401
|
+
constructor(elementRef, renderer, viewContainer) {
|
|
4402
|
+
this.elementRef = elementRef;
|
|
4403
|
+
this.renderer = renderer;
|
|
4404
|
+
this.viewContainer = viewContainer;
|
|
4405
|
+
}
|
|
4406
|
+
get elem() {
|
|
4407
|
+
return this.elementRef.nativeElement;
|
|
4408
|
+
}
|
|
4409
|
+
ngOnChanges(changes) {
|
|
4410
|
+
if (!this.templates || !this.defaultTemplates || !this.item)
|
|
4411
|
+
return;
|
|
4412
|
+
const promise = this.item.value instanceof Promise ? this.item.value : Promise.resolve(this.item.value);
|
|
4413
|
+
promise.then(value => {
|
|
4414
|
+
this.item.value = value;
|
|
4415
|
+
this.path = ObjectUtils.isNullOrUndefined(this.path) ? "" : this.path.toString();
|
|
4416
|
+
this.isArray = ObjectUtils.isArray(this.data);
|
|
4417
|
+
this.isObject = ObjectUtils.isObject(this.data);
|
|
4418
|
+
this.valueIsArray = ObjectUtils.isArray(this.item.value);
|
|
4419
|
+
this.valueIsObject = ObjectUtils.isObject(this.item.value);
|
|
4420
|
+
this.valueType = ObjectUtils.getType(this.item.value);
|
|
4421
|
+
const context = this;
|
|
4422
|
+
const template = this.templates.find(t => t.type == this.type && ObjectUtils.evaluate(t.selector, context)) || this.defaultTemplates[this.type];
|
|
4423
|
+
// Set view
|
|
4424
|
+
this.viewContainer.clear();
|
|
4425
|
+
this.viewContainer.createEmbeddedView(template, context);
|
|
4426
|
+
// Set classes
|
|
4427
|
+
if (this.type !== "item")
|
|
4428
|
+
return;
|
|
4429
|
+
this.item.classList = [];
|
|
4430
|
+
this.isClass("is-array", this.valueIsArray);
|
|
4431
|
+
this.isClass("is-object", this.valueIsObject);
|
|
4432
|
+
this.isClass("is-value", !this.valueIsObject && !this.valueIsArray);
|
|
4433
|
+
this.isClass(`type-${this.valueType}`);
|
|
4434
|
+
this.isClass(`path-${this.path.replace(/\./g, "-")}`);
|
|
4435
|
+
this.isClass(`key-${this.item.key}`);
|
|
4436
|
+
}, reason => {
|
|
4437
|
+
console.log("Can't handle promise rejection", reason);
|
|
4438
|
+
});
|
|
4439
|
+
}
|
|
4440
|
+
isClass(className, value = true) {
|
|
4441
|
+
if (!value)
|
|
4442
|
+
return;
|
|
4443
|
+
this.item.classList.push(className);
|
|
4444
|
+
}
|
|
4445
|
+
}
|
|
4446
|
+
UnorderedListItemDirective.decorators = [
|
|
4447
|
+
{ type: Directive, args: [{
|
|
4448
|
+
selector: "[unorderedListItem]"
|
|
4449
|
+
},] }
|
|
4450
|
+
];
|
|
4451
|
+
UnorderedListItemDirective.ctorParameters = () => [
|
|
4452
|
+
{ type: ElementRef },
|
|
4453
|
+
{ type: Renderer2 },
|
|
4454
|
+
{ type: ViewContainerRef }
|
|
4455
|
+
];
|
|
4456
|
+
UnorderedListItemDirective.propDecorators = {
|
|
4457
|
+
item: [{ type: Input, args: ["unorderedListItem",] }],
|
|
4458
|
+
type: [{ type: Input }],
|
|
4459
|
+
data: [{ type: Input }],
|
|
4460
|
+
keyPrefix: [{ type: Input }],
|
|
4461
|
+
listStyle: [{ type: Input }],
|
|
4462
|
+
path: [{ type: Input }],
|
|
4463
|
+
level: [{ type: Input }],
|
|
4464
|
+
templates: [{ type: Input }],
|
|
4465
|
+
defaultTemplates: [{ type: Input }]
|
|
4466
|
+
};
|
|
4467
|
+
|
|
4468
|
+
class UnorderedListTemplateDirective extends UnorederedListTemplate {
|
|
4469
|
+
constructor(elementRef, templateRef) {
|
|
4470
|
+
super();
|
|
4471
|
+
this.elementRef = elementRef;
|
|
4472
|
+
this.templateRef = templateRef;
|
|
4473
|
+
}
|
|
4474
|
+
createEmbeddedView(context) {
|
|
4475
|
+
return this.templateRef.createEmbeddedView(context);
|
|
4476
|
+
}
|
|
4477
|
+
}
|
|
4478
|
+
UnorderedListTemplateDirective.decorators = [
|
|
4479
|
+
{ type: Directive, args: [{
|
|
4480
|
+
selector: "ng-template[type][selector]"
|
|
4481
|
+
},] }
|
|
4482
|
+
];
|
|
4483
|
+
UnorderedListTemplateDirective.ctorParameters = () => [
|
|
4484
|
+
{ type: ElementRef },
|
|
4485
|
+
{ type: TemplateRef }
|
|
4486
|
+
];
|
|
4487
|
+
UnorderedListTemplateDirective.propDecorators = {
|
|
4488
|
+
type: [{ type: Input }],
|
|
4489
|
+
selector: [{ type: Input }]
|
|
4490
|
+
};
|
|
4491
|
+
|
|
4492
|
+
class UnorderedListComponent {
|
|
4493
|
+
constructor(cdr) {
|
|
4494
|
+
this.cdr = cdr;
|
|
4495
|
+
this.keyPrefix = "";
|
|
4496
|
+
this.listStyle = "table";
|
|
4497
|
+
this.path = "";
|
|
4498
|
+
this.level = 0;
|
|
4499
|
+
}
|
|
4500
|
+
ngOnChanges(changes) {
|
|
4501
|
+
this.isArray = ObjectUtils.isArray(this.data);
|
|
4502
|
+
this.isObject = ObjectUtils.isObject(this.data);
|
|
4503
|
+
}
|
|
4504
|
+
ngAfterContentInit() {
|
|
4505
|
+
const templates = this.templateDirectives.toArray();
|
|
4506
|
+
this.templates = this.templates ? this.templates.concat(templates) : templates;
|
|
4507
|
+
this.cdr.detectChanges();
|
|
4508
|
+
}
|
|
4509
|
+
ngAfterViewInit() {
|
|
4510
|
+
this.defaultTemplates = {
|
|
4511
|
+
key: this.defaultKeyTemplate,
|
|
4512
|
+
value: this.defaultValueTemplate,
|
|
4513
|
+
item: this.defaultItemTemplate
|
|
4514
|
+
};
|
|
4515
|
+
this.cdr.detectChanges();
|
|
4516
|
+
}
|
|
4517
|
+
}
|
|
4518
|
+
UnorderedListComponent.decorators = [
|
|
4519
|
+
{ type: Component, args: [{
|
|
4520
|
+
selector: "unordered-list",
|
|
4521
|
+
template: "<ng-template let-keyPrefix=\"keyPrefix\" let-key=\"item.key\" let-isArray=\"isArray\" #defaultKeyTemplate>\r\n {{ (keyPrefix ? keyPrefix + key : key) | translate }}:\r\n</ng-template>\r\n<ng-template let-keyPrefix=\"keyPrefix\" let-listStyle=\"listStyle\" let-val=\"item.value\" let-path=\"path\"\r\n let-templates=\"templates\" let-isObject=\"valueIsObject\" let-isArray=\"valueIsArray\" #defaultValueTemplate>\r\n <ng-template #value>\r\n <span [innerHTML]=\"val\"></span>\r\n </ng-template>\r\n <unordered-list [data]=\"val\"\r\n [keyPrefix]=\"keyPrefix\"\r\n [listStyle]=\"listStyle\"\r\n [path]=\"path\"\r\n [level]=\"level + 1\"\r\n [templates]=\"templates\"\r\n *ngIf=\"(isObject || isArray); else value\"></unordered-list>\r\n</ng-template>\r\n<ng-template let-item=\"item\" let-data=\"data\" let-keyPrefix=\"keyPrefix\" let-listStyle=\"listStyle\" let-path=\"path\" let-level=\"level\" let-templates=\"templates\" #defaultItemTemplate>\r\n <ng-template #itemKey>\r\n <ng-container [unorderedListItem]=\"item\"\r\n type=\"key\"\r\n [data]=\"data\"\r\n [keyPrefix]=\"keyPrefix\"\r\n [listStyle]=\"listStyle\"\r\n [path]=\"path\"\r\n [level]=\"level\"\r\n [templates]=\"templates\"\r\n [defaultTemplates]=\"defaultTemplates\"></ng-container>\r\n </ng-template>\r\n <ng-template #itemValue>\r\n <ng-container [unorderedListItem]=\"item\"\r\n type=\"value\"\r\n [data]=\"data\"\r\n [keyPrefix]=\"keyPrefix\"\r\n [listStyle]=\"listStyle\"\r\n [path]=\"path\"\r\n [level]=\"level\"\r\n [templates]=\"templates\"\r\n [defaultTemplates]=\"defaultTemplates\"></ng-container>\r\n </ng-template>\r\n <ng-container *ngIf=\"!isArray\">\r\n <th *ngIf=\"listStyle == 'table'; else itemKey\">\r\n <ng-container [ngTemplateOutlet]=\"itemKey\"></ng-container>\r\n </th>\r\n </ng-container>\r\n <td *ngIf=\"listStyle == 'table'; else itemValue\">\r\n <ng-container [ngTemplateOutlet]=\"itemValue\"></ng-container>\r\n </td>\r\n</ng-template>\r\n<ng-template #value>\r\n <span [innerHTML]=\"data\"></span>\r\n</ng-template>\r\n<ng-container *ngIf=\"(isObject || isArray); else value\" [ngSwitch]=\"listStyle\">\r\n <ul [ngClass]=\"'level-' + level\" *ngSwitchCase=\"'list'\">\r\n <li *ngFor=\"let item of data | entries\" [ngClass]=\"item.classList\">\r\n <ng-container [unorderedListItem]=\"item\"\r\n type=\"item\"\r\n [data]=\"data\"\r\n [keyPrefix]=\"keyPrefix\"\r\n [listStyle]=\"listStyle\"\r\n [path]=\"path ? path + '.' + item.key : item.key\"\r\n [level]=\"level\"\r\n [templates]=\"templates\"\r\n [defaultTemplates]=\"defaultTemplates\"></ng-container>\r\n </li>\r\n </ul>\r\n <table [ngClass]=\"'level-' + level\" *ngSwitchDefault>\r\n <tr *ngFor=\"let item of data | entries\" [ngClass]=\"item.classList\">\r\n <ng-container [unorderedListItem]=\"item\"\r\n type=\"item\"\r\n [data]=\"data\"\r\n [keyPrefix]=\"keyPrefix\"\r\n [listStyle]=\"listStyle\"\r\n [path]=\"path ? path + '.' + item.key : item.key\"\r\n [level]=\"level\"\r\n [templates]=\"templates\"\r\n [defaultTemplates]=\"defaultTemplates\"></ng-container>\r\n </tr>\r\n </table>\r\n</ng-container>\r\n"
|
|
4522
|
+
},] }
|
|
4523
|
+
];
|
|
4524
|
+
UnorderedListComponent.ctorParameters = () => [
|
|
4525
|
+
{ type: ChangeDetectorRef }
|
|
4526
|
+
];
|
|
4527
|
+
UnorderedListComponent.propDecorators = {
|
|
4528
|
+
data: [{ type: Input }],
|
|
4529
|
+
keyPrefix: [{ type: Input }],
|
|
4530
|
+
listStyle: [{ type: Input }],
|
|
4531
|
+
path: [{ type: Input }],
|
|
4532
|
+
level: [{ type: Input }],
|
|
4533
|
+
templates: [{ type: Input }],
|
|
4534
|
+
templateDirectives: [{ type: ContentChildren, args: [UnorderedListTemplateDirective,] }],
|
|
4535
|
+
defaultKeyTemplate: [{ type: ViewChild, args: ["defaultKeyTemplate",] }],
|
|
4536
|
+
defaultValueTemplate: [{ type: ViewChild, args: ["defaultValueTemplate",] }],
|
|
4537
|
+
defaultItemTemplate: [{ type: ViewChild, args: ["defaultItemTemplate",] }]
|
|
4538
|
+
};
|
|
4539
|
+
|
|
4540
|
+
class DynamicTableComponent {
|
|
4541
|
+
constructor() {
|
|
4542
|
+
this.loadData = (page, itemsPerPage) => {
|
|
4543
|
+
const orderBy = this.orders[this.orderBy];
|
|
4544
|
+
return this.dataLoader(page, itemsPerPage, orderBy, this.orderDescending, this.filter);
|
|
4545
|
+
};
|
|
4546
|
+
this.dataLoader = this.loadLocalData;
|
|
4547
|
+
this.placeholder = "";
|
|
4548
|
+
this.tableId = UniqueUtils.uuid();
|
|
4549
|
+
this.templates = {};
|
|
4550
|
+
this.filter = "";
|
|
4551
|
+
this.orders = {};
|
|
4552
|
+
}
|
|
4553
|
+
get items() {
|
|
4554
|
+
return !this.pagination ? [] : this.pagination.items;
|
|
4555
|
+
}
|
|
4556
|
+
static compare(orderBy, a, b) {
|
|
4557
|
+
a = a.item ? a.item[orderBy] : null;
|
|
4558
|
+
b = b.item ? b.item[orderBy] : null;
|
|
4559
|
+
return ObjectUtils.compare(a, b);
|
|
4560
|
+
}
|
|
4561
|
+
ngAfterContentInit() {
|
|
4562
|
+
this.templates = this.templateDirectives.reduce((result, directive) => {
|
|
4563
|
+
if (ObjectUtils.isArray(directive.column)) {
|
|
4564
|
+
directive.column.forEach(column => {
|
|
4565
|
+
result[column] = directive;
|
|
4566
|
+
});
|
|
4567
|
+
return result;
|
|
4568
|
+
}
|
|
4569
|
+
if (!ObjectUtils.isString(directive.column) || directive.column.length == 0)
|
|
4570
|
+
return result;
|
|
4571
|
+
result[directive.column] = directive;
|
|
4572
|
+
return result;
|
|
4573
|
+
}, {});
|
|
4574
|
+
}
|
|
4575
|
+
ngAfterViewInit() {
|
|
4576
|
+
this.rowTemplate = this.rowTemplate || this.defaultRowTemplate;
|
|
4577
|
+
this.filterTemplate = this.filterTemplate || this.defaultFilterTemplate;
|
|
4578
|
+
}
|
|
4579
|
+
ngOnChanges(changes) {
|
|
4580
|
+
if (changes.columns) {
|
|
4581
|
+
const columns = changes.columns.currentValue || [];
|
|
4582
|
+
this.orders = ObjectUtils.isArray(columns) ? columns.reduce((result, column) => {
|
|
4583
|
+
result[column] = column;
|
|
4584
|
+
return result;
|
|
4585
|
+
}, {}) : columns;
|
|
4586
|
+
this.cols = Object.keys(this.orders);
|
|
4587
|
+
this.orderBy = this.orderBy in this.orders ? this.orderBy : this.columns[0];
|
|
4588
|
+
}
|
|
4589
|
+
if (changes.orderBy && this.orders) {
|
|
4590
|
+
this.orderBy = this.orderBy in this.orders ? this.orderBy : this.columns[0];
|
|
4591
|
+
}
|
|
4592
|
+
if (!changes.data && !changes.parallelData && !changes.itemsPerPage && !changes.orderBy && !changes.orderDescending)
|
|
4593
|
+
return;
|
|
4594
|
+
this.refresh();
|
|
4595
|
+
}
|
|
4596
|
+
refresh() {
|
|
4597
|
+
if (!this.pagination)
|
|
4598
|
+
return;
|
|
4599
|
+
this.pagination.refresh();
|
|
4600
|
+
}
|
|
4601
|
+
setFilter(filter) {
|
|
4602
|
+
this.filter = filter;
|
|
4603
|
+
this.refresh();
|
|
4604
|
+
}
|
|
4605
|
+
setOrder(column) {
|
|
4606
|
+
this.orderDescending = column == this.orderBy && !this.orderDescending;
|
|
4607
|
+
this.orderBy = column;
|
|
4608
|
+
this.refresh();
|
|
4609
|
+
}
|
|
4610
|
+
loadLocalData(page, rowsPerPage, orderBy, orderDescending, filter) {
|
|
4611
|
+
if (!this.data) {
|
|
4612
|
+
return Promise.resolve({
|
|
4613
|
+
total: 0,
|
|
4614
|
+
items: []
|
|
4615
|
+
});
|
|
4616
|
+
}
|
|
4617
|
+
const compare = orderDescending
|
|
4618
|
+
? (a, b) => DynamicTableComponent.compare(orderBy, b, a)
|
|
4619
|
+
: (a, b) => DynamicTableComponent.compare(orderBy, a, b);
|
|
4620
|
+
const from = (page - 1) * rowsPerPage;
|
|
4621
|
+
const dataLength = this.data.length;
|
|
4622
|
+
const length = Math.min(rowsPerPage, dataLength - from);
|
|
4623
|
+
const parallelData = this.parallelData || [];
|
|
4624
|
+
let data = this.data.map((item, ix) => {
|
|
4625
|
+
return new PaginationItemContext(item, parallelData[ix] || {}, dataLength, ix, ix);
|
|
4626
|
+
});
|
|
4627
|
+
if (ObjectUtils.isString(filter) && filter.length > 0) {
|
|
4628
|
+
const filterRx = new RegExp(filter, "gi");
|
|
4629
|
+
data = data.filter(c => c.filter(filterRx));
|
|
4630
|
+
}
|
|
4631
|
+
const items = orderBy ? data.sort(compare).splice(from, length) : data.splice(from, length);
|
|
4632
|
+
items.forEach((context, ix) => {
|
|
4633
|
+
context.index = from + ix;
|
|
4634
|
+
});
|
|
4635
|
+
return Promise.resolve({
|
|
4636
|
+
total: dataLength,
|
|
4637
|
+
items: items
|
|
4638
|
+
});
|
|
4639
|
+
}
|
|
4640
|
+
}
|
|
4641
|
+
DynamicTableComponent.decorators = [
|
|
4642
|
+
{ type: Component, args: [{
|
|
4643
|
+
selector: "dynamic-table",
|
|
4644
|
+
template: "<div class=\"dynamic-table\" #pagination=\"pagination\" [pagination]=\"loadData\" [itemsPerPage]=\"itemsPerPage\" [updateTime]=\"updateTime\">\r\n <ng-template #defaultFilterTemplate let-table>\r\n <div class=\"table-search\" *ngIf=\"table.showFilter\">\r\n <label *ngIf=\"label\" [attr.for]=\"tableId\">{{ label | translate }}</label>\r\n <input type=\"text\"\r\n class=\"form-control\"\r\n [attr.id]=\"tableId\"\r\n [placeholder]=\"placeholder | translate\"\r\n [ngModel]=\"table.filter\"\r\n (ngModelChange)=\"table.setFilter($event)\"/>\r\n </div>\r\n </ng-template>\r\n <ng-container [ngxTemplateOutlet]=\"filterTemplate || defaultFilterTemplate\" [context]=\"this\"></ng-container>\r\n <pagination-menu [maxSize]=\"maxPages\" [directionLinks]=\"directionLinks\" [boundaryLinks]=\"boundaryLinks\"></pagination-menu>\r\n <div class=\"table-responsive\">\r\n\r\n <ng-template #columnTemplate let-context let-column=\"column\" let-template=\"template\">\r\n <ng-template #defaultTemplate let-column=\"column\" let-item=\"item\">\r\n <span>{{ item[column] == undefined || item[column] == null ? '-' : item[column] }}</span>\r\n </ng-template>\r\n <ng-template #pureTemplate>\r\n <ng-container [ngxTemplateOutlet]=\"template.ref\" [context]=\"context\"></ng-container>\r\n </ng-template>\r\n <td [ngClass]=\"'column-' + column\" *ngIf=\"!template || !template.pure; else pureTemplate\">\r\n <ng-container [ngxTemplateOutlet]=\"!template ? defaultTemplate : template.ref\" [context]=\"context\"></ng-container>\r\n </td>\r\n </ng-template>\r\n\r\n <ng-template #columnsTemplate let-context>\r\n <ng-container *ngFor=\"let column of cols\"\r\n [ngxTemplateOutlet]=\"columnTemplate\"\r\n [context]=\"context\"\r\n [additionalContext]=\"{\r\n template: templates[column],\r\n column: column\r\n }\"></ng-container>\r\n </ng-template>\r\n\r\n <ng-template #defaultRowTemplate let-context>\r\n <tr>\r\n <ng-container [ngxTemplateOutlet]=\"columnsTemplate\" [context]=\"context\"></ng-container>\r\n </tr>\r\n </ng-template>\r\n\r\n <ng-template #defaultWrapperTemplate>\r\n <table class=\"table table-striped\">\r\n <thead>\r\n <tr>\r\n <th *ngFor=\"let column of cols\" [ngClass]=\"'column-' + column\">\r\n <a *ngIf=\"orders[column]\" (click)=\"setOrder(column)\">\r\n <span>{{ 'label.' + column | translate }}</span>\r\n <i *ngIf=\"orderBy == column\"\r\n [icon]=\"orderDescending ? 'sort-desc' : 'sort-asc'\"\r\n [ngClass]=\"orderBy == column ? (orderDescending ? 'sort-desc': 'sort-asc') : ''\"></i>\r\n </a>\r\n <span *ngIf=\"!orders[column]\">{{ 'label.' + column | translate }}</span>\r\n </th>\r\n </tr>\r\n </thead>\r\n <tbody>\r\n <ng-container *paginationItem=\"let context\"\r\n [ngxTemplateOutlet]=\"rowTemplate\"\r\n [context]=\"context\"\r\n [additionalContext]=\"this\"></ng-container>\r\n </tbody>\r\n </table>\r\n </ng-template>\r\n\r\n <ng-container [ngxTemplateOutlet]=\"wrapperTemplate || defaultWrapperTemplate\"\r\n [context]=\"this\"></ng-container>\r\n </div>\r\n <pagination-menu [maxSize]=\"maxPages\" [directionLinks]=\"directionLinks\" [boundaryLinks]=\"boundaryLinks\"></pagination-menu>\r\n</div>\r\n"
|
|
4645
|
+
},] }
|
|
4646
|
+
];
|
|
4647
|
+
DynamicTableComponent.ctorParameters = () => [];
|
|
4648
|
+
DynamicTableComponent.propDecorators = {
|
|
4649
|
+
label: [{ type: Input }],
|
|
4650
|
+
placeholder: [{ type: Input }],
|
|
4651
|
+
dataLoader: [{ type: Input }],
|
|
4652
|
+
data: [{ type: Input }],
|
|
4653
|
+
parallelData: [{ type: Input }],
|
|
4654
|
+
columns: [{ type: Input }],
|
|
4655
|
+
showFilter: [{ type: Input }],
|
|
4656
|
+
itemsPerPage: [{ type: Input }],
|
|
4657
|
+
updateTime: [{ type: Input }],
|
|
4658
|
+
maxPages: [{ type: Input }],
|
|
4659
|
+
directionLinks: [{ type: Input }],
|
|
4660
|
+
boundaryLinks: [{ type: Input }],
|
|
4661
|
+
orderBy: [{ type: Input }],
|
|
4662
|
+
orderDescending: [{ type: Input }],
|
|
4663
|
+
rowTemplate: [{ type: ContentChild, args: ["rowTemplate", { static: true },] }],
|
|
4664
|
+
wrapperTemplate: [{ type: ContentChild, args: ["wrapperTemplate", { static: true },] }],
|
|
4665
|
+
filterTemplate: [{ type: ContentChild, args: ["filterTemplate", { static: true },] }],
|
|
4666
|
+
columnsTemplate: [{ type: ViewChild, args: ["columnsTemplate", { static: true },] }],
|
|
4667
|
+
defaultRowTemplate: [{ type: ViewChild, args: ["defaultRowTemplate", { static: true },] }],
|
|
4668
|
+
defaultWrapperTemplate: [{ type: ViewChild, args: ["defaultWrapperTemplate", { static: true },] }],
|
|
4669
|
+
defaultFilterTemplate: [{ type: ViewChild, args: ["defaultFilterTemplate", { static: true },] }],
|
|
4670
|
+
pagination: [{ type: ViewChild, args: ["pagination",] }],
|
|
4671
|
+
templateDirectives: [{ type: ContentChildren, args: [DynamicTableTemplateDirective,] }]
|
|
4672
|
+
};
|
|
4673
|
+
|
|
4674
|
+
class PaginationMenuComponent {
|
|
4675
|
+
constructor(state, pagination, icons) {
|
|
4676
|
+
this.state = state;
|
|
4677
|
+
this.pagination = pagination;
|
|
4678
|
+
this.icons = icons;
|
|
4679
|
+
this.maxSize = 5;
|
|
4680
|
+
this.directionLinks = true;
|
|
4681
|
+
this.boundaryLinks = true;
|
|
4682
|
+
this.firstLabel = `<<`;
|
|
4683
|
+
this.prevLabel = `<`;
|
|
4684
|
+
this.nextLabel = `>`;
|
|
4685
|
+
this.lastLabel = `>>`;
|
|
4686
|
+
}
|
|
4687
|
+
get hasPrev() {
|
|
4688
|
+
return this.pagination.page > 1;
|
|
4689
|
+
}
|
|
4690
|
+
get hasNext() {
|
|
4691
|
+
return this.pagination.page < this.pagination.maxPage;
|
|
4692
|
+
}
|
|
4693
|
+
ngOnInit() {
|
|
4694
|
+
this.onRefresh = this.pagination.onRefresh.subscribe(() => this.setPages());
|
|
4695
|
+
this.setIcon("firstLabel", "first-page");
|
|
4696
|
+
this.setIcon("prevLabel", "prev-page");
|
|
4697
|
+
this.setIcon("nextLabel", "next-page");
|
|
4698
|
+
this.setIcon("lastLabel", "last-page");
|
|
4699
|
+
}
|
|
4700
|
+
ngOnDestroy() {
|
|
4701
|
+
if (!this.onRefresh)
|
|
4702
|
+
return;
|
|
4703
|
+
this.onRefresh.unsubscribe();
|
|
4704
|
+
}
|
|
4705
|
+
ngOnChanges(changes) {
|
|
4706
|
+
this.maxSize = isNaN(this.maxSize) || this.maxSize <= 0 ? 5 : this.maxSize;
|
|
4707
|
+
this.directionLinks = ObjectUtils.isBoolean(this.directionLinks) ? this.directionLinks : true;
|
|
4708
|
+
this.boundaryLinks = ObjectUtils.isBoolean(this.boundaryLinks) ? this.boundaryLinks : true;
|
|
4709
|
+
this.setPages();
|
|
4710
|
+
}
|
|
4711
|
+
paginate(page) {
|
|
4712
|
+
if (this.pagination.page == page || this.pagination.maxPage < page || page < 1)
|
|
4713
|
+
return;
|
|
4714
|
+
if (!this.urlParam) {
|
|
4715
|
+
this.pagination.paginate(page);
|
|
4716
|
+
return;
|
|
4717
|
+
}
|
|
4718
|
+
const params = Object.assign({}, this.state.params);
|
|
4719
|
+
params[this.urlParam] = page.toString();
|
|
4720
|
+
const path = StateService.toPath(this.state.route, params);
|
|
4721
|
+
this.state.navigateByUrl(path);
|
|
4722
|
+
}
|
|
4723
|
+
setIcon(labelName, icon) {
|
|
4724
|
+
this.icons.getIcon(icon, icon, false).then(i => {
|
|
4725
|
+
if (i == icon)
|
|
4726
|
+
return;
|
|
4727
|
+
this[labelName] = i;
|
|
4728
|
+
});
|
|
4729
|
+
}
|
|
4730
|
+
setPages() {
|
|
4731
|
+
if (!this.pagination)
|
|
4732
|
+
return;
|
|
4733
|
+
const totalPages = this.pagination.maxPage;
|
|
4734
|
+
let startPage = Math.max(this.pagination.page - Math.floor(this.maxSize / 2), 1);
|
|
4735
|
+
let endPage = startPage + this.maxSize - 1;
|
|
4736
|
+
if (endPage > totalPages) {
|
|
4737
|
+
endPage = totalPages;
|
|
4738
|
+
startPage = Math.max(endPage - this.maxSize + 1, 1);
|
|
4739
|
+
}
|
|
4740
|
+
const pages = [];
|
|
4741
|
+
for (let num = startPage; num <= endPage; num++) {
|
|
4742
|
+
pages.push(num);
|
|
4743
|
+
}
|
|
4744
|
+
this.pages = pages;
|
|
4745
|
+
}
|
|
4746
|
+
}
|
|
4747
|
+
PaginationMenuComponent.decorators = [
|
|
4748
|
+
{ type: Component, args: [{
|
|
4749
|
+
selector: "pagination-menu",
|
|
4750
|
+
template: "<div class=\"pagination-menu\" *ngIf=\"pagination.total > pagination.itemsPerPage\">\r\n <ul class=\"pagination\">\r\n <li class=\"page-item\" [ngClass]=\"{disabled: !hasPrev}\" *ngIf=\"boundaryLinks\">\r\n <a class=\"page-link\" (click)=\"paginate(1)\" [innerHTML]=\"firstLabel | safe\"></a>\r\n </li>\r\n <li class=\"page-item\" [ngClass]=\"{disabled: !hasPrev}\" *ngIf=\"directionLinks\">\r\n <a class=\"page-link\" (click)=\"paginate(pagination.page - 1)\" [innerHTML]=\"prevLabel | safe\"></a>\r\n </li>\r\n <li class=\"page-item\" [ngClass]=\"{active: pagination.page == page}\" *ngFor=\"let page of pages\">\r\n <a class=\"page-link\" [ngClass]=\"{active: pagination.page == page}\" (click)=\"paginate(page)\">{{ page }}</a>\r\n </li>\r\n <li class=\"page-item\" [ngClass]=\"{disabled: !hasNext}\" *ngIf=\"directionLinks\">\r\n <a class=\"page-link\" (click)=\"paginate(pagination.page + 1)\" [innerHTML]=\"nextLabel | safe\"></a>\r\n </li>\r\n <li class=\"page-item\" [ngClass]=\"{disabled: !hasNext}\" *ngIf=\"boundaryLinks\">\r\n <a class=\"page-link\" (click)=\"paginate(pagination.maxPage)\" [innerHTML]=\"lastLabel | safe\"></a>\r\n </li>\r\n </ul>\r\n</div>\r\n"
|
|
4751
|
+
},] }
|
|
4752
|
+
];
|
|
4753
|
+
PaginationMenuComponent.ctorParameters = () => [
|
|
4754
|
+
{ type: StateService },
|
|
4755
|
+
{ type: PaginationDirective },
|
|
4756
|
+
{ type: undefined, decorators: [{ type: Inject, args: [ICON_SERVICE,] }] }
|
|
4757
|
+
];
|
|
4758
|
+
PaginationMenuComponent.propDecorators = {
|
|
4759
|
+
maxSize: [{ type: Input }],
|
|
4760
|
+
urlParam: [{ type: Input }],
|
|
4761
|
+
directionLinks: [{ type: Input }],
|
|
4762
|
+
boundaryLinks: [{ type: Input }]
|
|
4763
|
+
};
|
|
4764
|
+
|
|
4765
|
+
class StickyClassDirective {
|
|
4766
|
+
constructor(events, element, renderer) {
|
|
4767
|
+
this.events = events;
|
|
4768
|
+
this.element = element;
|
|
4769
|
+
this.renderer = renderer;
|
|
4770
|
+
}
|
|
4771
|
+
ngOnInit() {
|
|
4772
|
+
this.stickyUpdated = this.events.stickyUpdated.subscribe(() => {
|
|
4773
|
+
if (this.events.isSticky) {
|
|
4774
|
+
this.renderer.addClass(this.element.nativeElement, this.stickyClass || "sticky-sibling");
|
|
4775
|
+
return;
|
|
4776
|
+
}
|
|
4777
|
+
this.renderer.removeClass(this.element.nativeElement, this.stickyClass || "sticky-sibling");
|
|
4778
|
+
});
|
|
4779
|
+
}
|
|
4780
|
+
ngOnDestroy() {
|
|
4781
|
+
this.stickyUpdated.unsubscribe();
|
|
4782
|
+
}
|
|
4783
|
+
}
|
|
4784
|
+
StickyClassDirective.decorators = [
|
|
4785
|
+
{ type: Directive, args: [{
|
|
4786
|
+
selector: "[stickyClass]"
|
|
4787
|
+
},] }
|
|
4788
|
+
];
|
|
4789
|
+
StickyClassDirective.ctorParameters = () => [
|
|
4790
|
+
{ type: EventsService },
|
|
4791
|
+
{ type: ElementRef },
|
|
4792
|
+
{ type: Renderer2 }
|
|
4793
|
+
];
|
|
4794
|
+
StickyClassDirective.propDecorators = {
|
|
4795
|
+
stickyClass: [{ type: Input }]
|
|
4796
|
+
};
|
|
4797
|
+
|
|
4798
|
+
// --- Pipes ---
|
|
4799
|
+
const pipes = [
|
|
4800
|
+
ChunkPipe,
|
|
4801
|
+
EntriesPipe,
|
|
4802
|
+
ExtraItemPropertiesPipe,
|
|
4803
|
+
FilterPipe,
|
|
4804
|
+
FindPipe,
|
|
4805
|
+
FormatNumberPipe,
|
|
4806
|
+
GetOffsetPipe,
|
|
4807
|
+
GetTypePipe,
|
|
4808
|
+
GlobalTemplatePipe,
|
|
4809
|
+
GroupByPipe,
|
|
4810
|
+
IsTypePipe,
|
|
4811
|
+
JoinPipe,
|
|
4812
|
+
KeysPipe,
|
|
4813
|
+
MapPipe,
|
|
4814
|
+
MaxPipe,
|
|
4815
|
+
MinPipe,
|
|
4816
|
+
PopPipe,
|
|
4817
|
+
ReducePipe,
|
|
4818
|
+
RemapPipe,
|
|
4819
|
+
ReplacePipe,
|
|
4820
|
+
ReversePipe,
|
|
4821
|
+
RoundPipe,
|
|
4822
|
+
SafeHtmlPipe,
|
|
4823
|
+
ShiftPipe,
|
|
4824
|
+
SplitPipe,
|
|
4825
|
+
TranslatePipe,
|
|
4826
|
+
ValuesPipe
|
|
4827
|
+
];
|
|
4828
|
+
// --- Directives ---
|
|
4829
|
+
const directives = [
|
|
4830
|
+
AsyncMethodDirective,
|
|
4831
|
+
BackgroundDirective,
|
|
4832
|
+
DynamicTableTemplateDirective,
|
|
4833
|
+
GlobalTemplateDirective,
|
|
4834
|
+
IconDirective,
|
|
4835
|
+
NgxTemplateOutletDirective,
|
|
4836
|
+
PaginationDirective,
|
|
4837
|
+
PaginationItemDirective,
|
|
4838
|
+
ResourceIfDirective,
|
|
4839
|
+
StickyDirective,
|
|
4840
|
+
StickyClassDirective,
|
|
4841
|
+
UnorderedListItemDirective,
|
|
4842
|
+
UnorderedListTemplateDirective
|
|
4843
|
+
];
|
|
4844
|
+
// --- Components ---
|
|
4845
|
+
const components = [
|
|
4846
|
+
DynamicTableComponent,
|
|
4847
|
+
PaginationMenuComponent,
|
|
4848
|
+
UnorderedListComponent
|
|
4849
|
+
];
|
|
4850
|
+
const providers = [
|
|
4851
|
+
...pipes,
|
|
4852
|
+
BaseHttpClient,
|
|
4853
|
+
BaseHttpService,
|
|
4854
|
+
AuthGuard,
|
|
4855
|
+
AclService,
|
|
4856
|
+
ApiService,
|
|
4857
|
+
StaticAuthService,
|
|
4858
|
+
ConfigService,
|
|
4859
|
+
ErrorHandlerService,
|
|
4860
|
+
EventsService,
|
|
4861
|
+
FormatterService,
|
|
4862
|
+
GlobalTemplateService,
|
|
4863
|
+
IconService,
|
|
4864
|
+
LanguageService,
|
|
4865
|
+
OpenApiService,
|
|
4866
|
+
PromiseService,
|
|
4867
|
+
StateService,
|
|
4868
|
+
StaticLanguageService,
|
|
4869
|
+
StorageService,
|
|
4870
|
+
ConsoleToasterService,
|
|
4871
|
+
TranslatedUrlSerializer,
|
|
4872
|
+
UniversalService,
|
|
4873
|
+
DeviceDetectorService,
|
|
4874
|
+
{
|
|
4875
|
+
provide: EVENT_MANAGER_PLUGINS,
|
|
4876
|
+
useClass: ResizeEventPlugin,
|
|
4877
|
+
multi: true
|
|
4878
|
+
},
|
|
4879
|
+
{
|
|
4880
|
+
provide: EVENT_MANAGER_PLUGINS,
|
|
4881
|
+
useClass: ScrollEventPlugin,
|
|
4882
|
+
multi: true
|
|
4883
|
+
},
|
|
4884
|
+
{
|
|
4885
|
+
provide: UrlSerializer,
|
|
4886
|
+
useExisting: TranslatedUrlSerializer
|
|
4887
|
+
},
|
|
4888
|
+
{
|
|
4889
|
+
provide: ErrorHandler,
|
|
4890
|
+
useExisting: ErrorHandlerService
|
|
4891
|
+
}
|
|
4892
|
+
];
|
|
4893
|
+
function loadConfig(config) {
|
|
4894
|
+
return config.load;
|
|
4895
|
+
}
|
|
4896
|
+
class NgxUtilsModule {
|
|
4897
|
+
static forRoot(config) {
|
|
4898
|
+
return {
|
|
4899
|
+
ngModule: NgxUtilsModule,
|
|
4900
|
+
providers: [
|
|
4901
|
+
...providers,
|
|
4902
|
+
{
|
|
4903
|
+
provide: API_SERVICE,
|
|
4904
|
+
useExisting: (!config ? null : config.apiService) || ApiService
|
|
4905
|
+
},
|
|
4906
|
+
{
|
|
4907
|
+
provide: AUTH_SERVICE,
|
|
4908
|
+
useExisting: (!config ? null : config.authService) || StaticAuthService
|
|
4909
|
+
},
|
|
4910
|
+
{
|
|
4911
|
+
provide: ICON_SERVICE,
|
|
4912
|
+
useExisting: (!config ? null : config.iconService) || IconService
|
|
4913
|
+
},
|
|
4914
|
+
{
|
|
4915
|
+
provide: LANGUAGE_SERVICE,
|
|
4916
|
+
useExisting: (!config ? null : config.languageService) || StaticLanguageService
|
|
4917
|
+
},
|
|
4918
|
+
{
|
|
4919
|
+
provide: TOASTER_SERVICE,
|
|
4920
|
+
useExisting: (!config ? null : config.toasterService) || ConsoleToasterService
|
|
4921
|
+
},
|
|
4922
|
+
{
|
|
4923
|
+
provide: PROMISE_SERVICE,
|
|
4924
|
+
useExisting: (!config ? null : config.promiseService) || PromiseService
|
|
4925
|
+
},
|
|
4926
|
+
{
|
|
4927
|
+
provide: CONFIG_SERVICE,
|
|
4928
|
+
useExisting: (!config ? null : config.configService) || ConfigService
|
|
4929
|
+
},
|
|
4930
|
+
{
|
|
4931
|
+
provide: GLOBAL_TEMPLATES,
|
|
4932
|
+
useExisting: (!config ? null : config.globalTemplates) || GlobalTemplateService
|
|
4933
|
+
},
|
|
4934
|
+
{
|
|
4935
|
+
provide: ROOT_ELEMENT,
|
|
4936
|
+
useValue: null
|
|
4937
|
+
},
|
|
4938
|
+
{
|
|
4939
|
+
provide: APP_INITIALIZER,
|
|
4940
|
+
useFactory: (!config ? null : config.initializeApp) || loadConfig,
|
|
4941
|
+
multi: true,
|
|
4942
|
+
deps: [(!config ? null : config.initializeApp) ? Injector : CONFIG_SERVICE]
|
|
4943
|
+
}
|
|
4944
|
+
]
|
|
4945
|
+
};
|
|
4946
|
+
}
|
|
4947
|
+
}
|
|
4948
|
+
NgxUtilsModule.decorators = [
|
|
4949
|
+
{ type: NgModule, args: [{
|
|
4950
|
+
declarations: [
|
|
4951
|
+
...pipes,
|
|
4952
|
+
...directives,
|
|
4953
|
+
...components
|
|
4954
|
+
],
|
|
4955
|
+
imports: [
|
|
4956
|
+
CommonModule,
|
|
4957
|
+
FormsModule
|
|
4958
|
+
],
|
|
4959
|
+
exports: [
|
|
4960
|
+
...pipes,
|
|
4961
|
+
...directives,
|
|
4962
|
+
...components,
|
|
4963
|
+
FormsModule
|
|
4964
|
+
],
|
|
4965
|
+
providers: pipes
|
|
4966
|
+
},] }
|
|
4967
|
+
];
|
|
4968
|
+
|
|
4969
|
+
/**
|
|
4970
|
+
* Generated bundle index. Do not edit.
|
|
4971
|
+
*/
|
|
4972
|
+
|
|
4973
|
+
export { API_SERVICE, AUTH_SERVICE, AclService, AjaxRequestHandler, ApiService, ArrayUtils, AsyncMethodBase, AsyncMethodDirective, AuthGuard, BASE_CONFIG, BackgroundDirective, BaseHttpClient, BaseHttpService, CONFIG_SERVICE, CanvasColor, CanvasUtils, ChunkPipe, Circle, ConfigService, ConsoleToasterService, DateUtils, DynamicTableComponent, DynamicTableTemplateDirective, ERROR_HANDLER, EXPRESS_REQUEST, EntriesPipe, ErrorHandlerService, EventsService, ExtraItemPropertiesPipe, FactoryDependencies, FileSystemEntry, FileUtils, FilterPipe, FindPipe, FormatNumberPipe, FormatterService, GLOBAL_TEMPLATES, GenericValue, GetOffsetPipe, GetTypePipe, GlobalTemplateDirective, GlobalTemplatePipe, GlobalTemplateService, GroupByPipe, HttpPromise, ICON_SERVICE, IConfiguration, IconDirective, IconService, Initializer, IsTypePipe, JoinPipe, KeysPipe, LANGUAGE_SERVICE, LanguageService, LoaderUtils, MapPipe, MathUtils, MaxPipe, MinPipe, NgxTemplateOutletDirective, NgxUtilsModule, ObjectUtils, ObservableUtils, OpenApiService, PROMISE_SERVICE, PaginationDirective, PaginationItemContext, PaginationItemDirective, PaginationMenuComponent, Point, PopPipe, PromiseService, ROOT_ELEMENT, Rect, ReducePipe, ReflectUtils, RemapPipe, ReplacePipe, ResizeEventPlugin, ResourceIfContext, ResourceIfDirective, ReversePipe, RoundPipe, SCRIPT_PARAMS, SafeHtmlPipe, ScrollEventPlugin, SetUtils, ShiftPipe, SplitPipe, StateService, StaticAuthService, StaticLanguageService, StickyDirective, StorageMode, StorageService, StringUtils, TOASTER_SERVICE, TimerUtils, TranslatePipe, TranslatedUrlSerializer, UniqueUtils, UniversalService, UnorderedListComponent, UnorderedListItemDirective, UnorderedListTemplateDirective, UnorederedListTemplate, ValuedPromise, ValuesPipe, Vector, pipes as ɵa, directives as ɵb, components as ɵc, providers as ɵd, loadConfig as ɵe, StickyClassDirective as ɵf };
|
|
4974
|
+
//# sourceMappingURL=stemy-ngx-utils.js.map
|