@stemy/ngx-utils 13.0.2 → 13.0.5

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