@acorex/core 7.0.20 → 7.0.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/config/index.d.ts +5 -0
- package/config/public-api.d.ts +1 -0
- package/config/src/configs.d.ts +9 -0
- package/dateTime/index.d.ts +5 -0
- package/dateTime/{public-api.ts → public-api.d.ts} +1 -1
- package/dateTime/src/datetime.class.d.ts +100 -0
- package/dateTime/src/datetime.module.d.ts +8 -0
- package/dateTime/src/datetime.pipe.d.ts +8 -0
- package/dateTime/src/georgian.calendar.d.ts +20 -0
- package/dateTime/src/jalali.calendar.d.ts +35 -0
- package/esm2020/acorex-core.mjs +5 -0
- package/esm2020/config/acorex-core-config.mjs +5 -0
- package/esm2020/config/public-api.mjs +2 -0
- package/esm2020/config/src/configs.mjs +32 -0
- package/esm2020/dateTime/acorex-core-dateTime.mjs +5 -0
- package/esm2020/dateTime/public-api.mjs +6 -0
- package/esm2020/dateTime/src/datetime.class.mjs +288 -0
- package/esm2020/dateTime/src/datetime.module.mjs +39 -0
- package/esm2020/dateTime/src/datetime.pipe.mjs +26 -0
- package/esm2020/dateTime/src/georgian.calendar.mjs +189 -0
- package/esm2020/dateTime/src/jalali.calendar.mjs +359 -0
- package/esm2020/events/acorex-core-events.mjs +5 -0
- package/esm2020/events/public-api.mjs +2 -0
- package/esm2020/events/src/event.service.mjs +36 -0
- package/esm2020/file/acorex-core-file.mjs +5 -0
- package/esm2020/file/public-api.mjs +5 -0
- package/esm2020/file/src/file-download-ref.class.mjs +12 -0
- package/esm2020/file/src/file-download-result.class.mjs +47 -0
- package/esm2020/file/src/file-upload-ref.class.mjs +12 -0
- package/esm2020/file/src/file.service.mjs +101 -0
- package/esm2020/http/acorex-core-http.mjs +5 -0
- package/esm2020/http/public-api.mjs +6 -0
- package/esm2020/http/src/http-error.class.mjs +2 -0
- package/esm2020/http/src/http-events.interceptor.mjs +3 -0
- package/esm2020/http/src/http-request.class.mjs +2 -0
- package/esm2020/http/src/http-result.class.mjs +21 -0
- package/esm2020/http/src/http.module.mjs +29 -0
- package/esm2020/http/src/http.service.mjs +148 -0
- package/esm2020/image/acorex-core-image.mjs +5 -0
- package/esm2020/image/public-api.mjs +2 -0
- package/esm2020/image/src/image.service.mjs +43 -0
- package/esm2020/pipes/acorex-core-pipes.mjs +5 -0
- package/esm2020/pipes/public-api.mjs +3 -0
- package/esm2020/pipes/src/pipes.module.mjs +19 -0
- package/esm2020/pipes/src/safe.pipe.mjs +30 -0
- package/esm2020/platform/acorex-core-platform.mjs +5 -0
- package/esm2020/platform/public-api.mjs +2 -0
- package/esm2020/platform/src/platform.service.mjs +153 -0
- package/esm2020/public-api.mjs +5 -0
- package/esm2020/translation/acorex-core-translation.mjs +5 -0
- package/esm2020/translation/public-api.mjs +4 -0
- package/esm2020/translation/src/translation.module.mjs +18 -0
- package/esm2020/translation/src/translator.mjs +43 -0
- package/esm2020/translation/src/translator.pipe.mjs +15 -0
- package/esm2020/utils/acorex-core-utils.mjs +5 -0
- package/esm2020/utils/public-api.mjs +5 -0
- package/esm2020/utils/src/color-util.mjs +71 -0
- package/esm2020/utils/src/drawing-util.mjs +27 -0
- package/esm2020/utils/src/object-util.mjs +39 -0
- package/esm2020/utils/src/string-util.mjs +19 -0
- package/events/index.d.ts +5 -0
- package/events/public-api.d.ts +1 -0
- package/events/src/event.service.d.ts +9 -0
- package/fesm2015/acorex-core-config.mjs +40 -0
- package/fesm2015/acorex-core-config.mjs.map +1 -0
- package/fesm2015/acorex-core-dateTime.mjs +899 -0
- package/fesm2015/acorex-core-dateTime.mjs.map +1 -0
- package/fesm2015/acorex-core-events.mjs +44 -0
- package/fesm2015/acorex-core-events.mjs.map +1 -0
- package/fesm2015/acorex-core-file.mjs +177 -0
- package/fesm2015/acorex-core-file.mjs.map +1 -0
- package/fesm2015/acorex-core-http.mjs +203 -0
- package/fesm2015/acorex-core-http.mjs.map +1 -0
- package/fesm2015/acorex-core-image.mjs +54 -0
- package/fesm2015/acorex-core-image.mjs.map +1 -0
- package/fesm2015/acorex-core-pipes.mjs +54 -0
- package/fesm2015/acorex-core-pipes.mjs.map +1 -0
- package/fesm2015/acorex-core-platform.mjs +161 -0
- package/fesm2015/acorex-core-platform.mjs.map +1 -0
- package/fesm2015/acorex-core-translation.mjs +81 -0
- package/fesm2015/acorex-core-translation.mjs.map +1 -0
- package/fesm2015/acorex-core-utils.mjs +164 -0
- package/fesm2015/acorex-core-utils.mjs.map +1 -0
- package/fesm2015/acorex-core.mjs +12 -0
- package/fesm2015/acorex-core.mjs.map +1 -0
- package/fesm2020/acorex-core-config.mjs +40 -0
- package/fesm2020/acorex-core-config.mjs.map +1 -0
- package/fesm2020/acorex-core-dateTime.mjs +899 -0
- package/fesm2020/acorex-core-dateTime.mjs.map +1 -0
- package/fesm2020/acorex-core-events.mjs +44 -0
- package/fesm2020/acorex-core-events.mjs.map +1 -0
- package/fesm2020/acorex-core-file.mjs +177 -0
- package/fesm2020/acorex-core-file.mjs.map +1 -0
- package/fesm2020/acorex-core-http.mjs +202 -0
- package/fesm2020/acorex-core-http.mjs.map +1 -0
- package/fesm2020/acorex-core-image.mjs +51 -0
- package/fesm2020/acorex-core-image.mjs.map +1 -0
- package/fesm2020/acorex-core-pipes.mjs +54 -0
- package/fesm2020/acorex-core-pipes.mjs.map +1 -0
- package/fesm2020/acorex-core-platform.mjs +161 -0
- package/fesm2020/acorex-core-platform.mjs.map +1 -0
- package/fesm2020/acorex-core-translation.mjs +80 -0
- package/fesm2020/acorex-core-translation.mjs.map +1 -0
- package/fesm2020/acorex-core-utils.mjs +164 -0
- package/fesm2020/acorex-core-utils.mjs.map +1 -0
- package/fesm2020/acorex-core.mjs +12 -0
- package/fesm2020/acorex-core.mjs.map +1 -0
- package/file/index.d.ts +5 -0
- package/file/public-api.d.ts +4 -0
- package/file/src/file-download-ref.class.d.ts +6 -0
- package/file/src/file-download-result.class.d.ts +8 -0
- package/file/src/file-upload-ref.class.d.ts +5 -0
- package/file/src/file.service.d.ts +18 -0
- package/http/index.d.ts +5 -0
- package/http/{public-api.ts → public-api.d.ts} +1 -1
- package/http/src/{http-error.class.ts → http-error.class.d.ts} +2 -2
- package/http/src/{http-events.interceptor.ts → http-events.interceptor.d.ts} +3 -7
- package/http/src/{http-request.class.ts → http-request.class.d.ts} +5 -5
- package/http/src/http-result.class.d.ts +11 -0
- package/http/src/http.module.d.ts +8 -0
- package/http/src/http.service.d.ts +23 -0
- package/image/index.d.ts +5 -0
- package/image/public-api.d.ts +1 -0
- package/image/src/image.service.d.ts +12 -0
- package/index.d.ts +5 -0
- package/package.json +115 -16
- package/pipes/index.d.ts +5 -0
- package/pipes/public-api.d.ts +2 -0
- package/pipes/src/pipes.module.d.ts +8 -0
- package/pipes/src/safe.pipe.d.ts +10 -0
- package/platform/index.d.ts +5 -0
- package/platform/public-api.d.ts +1 -0
- package/platform/src/platform.service.d.ts +26 -0
- package/public-api.d.ts +1 -0
- package/translation/index.d.ts +5 -0
- package/translation/{public-api.ts → public-api.d.ts} +1 -1
- package/translation/src/translation.module.d.ts +7 -0
- package/translation/src/translator.d.ts +11 -0
- package/translation/src/translator.pipe.d.ts +7 -0
- package/utils/index.d.ts +5 -0
- package/utils/{public-api.ts → public-api.d.ts} +1 -1
- package/utils/src/color-util.d.ts +20 -0
- package/utils/src/drawing-util.d.ts +17 -0
- package/utils/src/object-util.d.ts +4 -0
- package/utils/src/string-util.d.ts +6 -0
- package/config/ax-preset.js +0 -186
- package/config/index.ts +0 -1
- package/config/ng-package.json +0 -6
- package/config/public-api.ts +0 -1
- package/config/src/configs.ts +0 -37
- package/dateTime/index.ts +0 -1
- package/dateTime/ng-package.json +0 -6
- package/dateTime/src/datetime.class.ts +0 -449
- package/dateTime/src/datetime.module.ts +0 -35
- package/dateTime/src/datetime.pipe.ts +0 -21
- package/dateTime/src/georgian.calendar.ts +0 -205
- package/dateTime/src/jalali.calendar.ts +0 -416
- package/events/index.ts +0 -1
- package/events/ng-package.json +0 -6
- package/events/public-api.ts +0 -1
- package/events/src/event.service.ts +0 -31
- package/file/index.ts +0 -1
- package/file/ng-package.json +0 -7
- package/file/public-api.ts +0 -4
- package/file/src/file-download-ref.class.ts +0 -16
- package/file/src/file-download-result.class.ts +0 -56
- package/file/src/file-upload-ref.class.ts +0 -14
- package/file/src/file.service.ts +0 -104
- package/http/index.ts +0 -1
- package/http/ng-package.json +0 -6
- package/http/src/http-result.class.ts +0 -34
- package/http/src/http.module.ts +0 -25
- package/http/src/http.service.ts +0 -161
- package/image/index.ts +0 -1
- package/image/ng-package.json +0 -7
- package/image/public-api.ts +0 -1
- package/image/src/image.service.ts +0 -42
- package/index.ts +0 -1
- package/karma.conf.js +0 -44
- package/ng-package.json +0 -7
- package/pipes/index.ts +0 -1
- package/pipes/ng-package.json +0 -6
- package/pipes/public-api.ts +0 -2
- package/pipes/src/pipes.module.ts +0 -11
- package/pipes/src/safe.pipe.ts +0 -24
- package/platform/index.ts +0 -1
- package/platform/ng-package.json +0 -6
- package/platform/public-api.ts +0 -1
- package/platform/src/platform.service.ts +0 -223
- package/public-api.ts +0 -4
- package/test.ts +0 -27
- package/translation/index.ts +0 -1
- package/translation/ng-package.json +0 -6
- package/translation/src/translation.module.ts +0 -12
- package/translation/src/translator.pipe.ts +0 -9
- package/translation/src/translator.ts +0 -49
- package/tsconfig.lib.json +0 -15
- package/tsconfig.lib.prod.json +0 -10
- package/tsconfig.spec.json +0 -17
- package/utils/index.ts +0 -1
- package/utils/ng-package.json +0 -6
- package/utils/src/color-util.ts +0 -83
- package/utils/src/drawing-util.ts +0 -43
- package/utils/src/object-util.ts +0 -82
- package/utils/src/string-util.ts +0 -25
@@ -1,31 +0,0 @@
|
|
1
|
-
import { Injectable } from '@angular/core';
|
2
|
-
|
3
|
-
@Injectable({ providedIn: 'root' })
|
4
|
-
export class AXEventService {
|
5
|
-
private list: any[] = [];
|
6
|
-
|
7
|
-
public broadcast(key: string, options?: any): void {
|
8
|
-
const d = this.list.find(c => c.key === key);
|
9
|
-
if (d) {
|
10
|
-
d.events.forEach((c:any) => {
|
11
|
-
c(options);
|
12
|
-
});
|
13
|
-
}
|
14
|
-
}
|
15
|
-
|
16
|
-
public on(key: string, callback: (options?: any) => void) {
|
17
|
-
let d = this.list.find(c => c.key === key);
|
18
|
-
if (!d) {
|
19
|
-
d = { key, events: [] };
|
20
|
-
this.list.push(d);
|
21
|
-
}
|
22
|
-
d.events.push(callback);
|
23
|
-
}
|
24
|
-
|
25
|
-
public destroy(key: string, callback: (options?: any) => void): void {
|
26
|
-
const d = this.list.find(c => c.key === key);
|
27
|
-
if (d) {
|
28
|
-
d.events = [];
|
29
|
-
}
|
30
|
-
}
|
31
|
-
}
|
package/file/index.ts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
export * from './public-api';
|
package/file/ng-package.json
DELETED
package/file/public-api.ts
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
import { AXFileDownloadResult } from "./file-download-result.class";
|
2
|
-
|
3
|
-
export class AXFileDownloadRef extends Promise<AXFileDownloadResult>
|
4
|
-
{
|
5
|
-
public abortMethod: () => void;
|
6
|
-
constructor(executor: (resolve: (value?: PromiseLike<AXFileDownloadResult>) => void, reject: (reason?: any) => void) => void) {
|
7
|
-
super(executor);
|
8
|
-
|
9
|
-
}
|
10
|
-
//abort the operation
|
11
|
-
public abort() {
|
12
|
-
if (this.abortMethod) {
|
13
|
-
this.abortMethod();
|
14
|
-
}
|
15
|
-
}
|
16
|
-
}
|
@@ -1,56 +0,0 @@
|
|
1
|
-
export class AXFileDownloadResult {
|
2
|
-
|
3
|
-
_response: Blob;
|
4
|
-
|
5
|
-
constructor(response: Blob) {
|
6
|
-
this._response = response;
|
7
|
-
}
|
8
|
-
|
9
|
-
save(filename?: string): Promise<void> {
|
10
|
-
this._defaultBrowserDownload(filename);
|
11
|
-
return Promise.resolve();
|
12
|
-
// else {
|
13
|
-
// return new Promise((resolve, reject) => {
|
14
|
-
// const button = document.createElement("button");
|
15
|
-
// button.addEventListener('click', async () => {
|
16
|
-
// debugger
|
17
|
-
// button.remove();
|
18
|
-
// const opts = {
|
19
|
-
// types: [{
|
20
|
-
// description: 'Save File',
|
21
|
-
// suggestedName: filename
|
22
|
-
// // accept: {'text/plain': ['.txt']},
|
23
|
-
// }],
|
24
|
-
// };
|
25
|
-
// const result = await window['showSaveFilePicker'](opts);
|
26
|
-
// console.log(result);
|
27
|
-
|
28
|
-
// resolve();
|
29
|
-
// });
|
30
|
-
// button.click();
|
31
|
-
// });
|
32
|
-
|
33
|
-
// }
|
34
|
-
}
|
35
|
-
|
36
|
-
|
37
|
-
blob() {
|
38
|
-
return this._response;
|
39
|
-
}
|
40
|
-
|
41
|
-
base64(): Promise<string> {
|
42
|
-
return new Promise((resolve, reject) => {
|
43
|
-
var reader = new window.FileReader();
|
44
|
-
reader.onloadend = () => resolve(reader.result as string);
|
45
|
-
reader.onerror = (e) => reject(e);
|
46
|
-
reader.readAsDataURL(this._response);
|
47
|
-
})
|
48
|
-
}
|
49
|
-
|
50
|
-
private _defaultBrowserDownload(filename: string = 'download') {
|
51
|
-
const link = document.createElement("a");
|
52
|
-
link.href = URL.createObjectURL(this._response);
|
53
|
-
link.download = filename;
|
54
|
-
link.click();
|
55
|
-
}
|
56
|
-
}
|
@@ -1,14 +0,0 @@
|
|
1
|
-
export class AXFileUploadRef<T = any> extends Promise<T>
|
2
|
-
{
|
3
|
-
public abortMethod: () => void;
|
4
|
-
constructor(executor: (resolve: (value?: PromiseLike<T>) => void, reject: (reason?: any) => void) => void) {
|
5
|
-
super(executor);
|
6
|
-
|
7
|
-
}
|
8
|
-
//abort the operation
|
9
|
-
public abort() {
|
10
|
-
if (this.abortMethod) {
|
11
|
-
this.abortMethod();
|
12
|
-
}
|
13
|
-
}
|
14
|
-
}
|
package/file/src/file.service.ts
DELETED
@@ -1,104 +0,0 @@
|
|
1
|
-
import { HttpClient, HttpContext, HttpHeaders, HttpParams } from '@angular/common/http';
|
2
|
-
import { Injectable } from '@angular/core';
|
3
|
-
import { Observable, Subscription } from 'rxjs';
|
4
|
-
import { AXFileDownloadRef } from './file-download-ref.class';
|
5
|
-
import { AXFileDownloadResult } from './file-download-result.class';
|
6
|
-
import { AXFileUploadRef } from './file-upload-ref.class';
|
7
|
-
|
8
|
-
|
9
|
-
@Injectable({ providedIn: 'root' })
|
10
|
-
export class AXFileService {
|
11
|
-
constructor(private _httpClient: HttpClient) { }
|
12
|
-
|
13
|
-
public download(request: string | Observable<Blob>): AXFileDownloadRef {
|
14
|
-
let s: Subscription;
|
15
|
-
const promiseFunc = (resolve, reject) => {
|
16
|
-
//TODO: add custome http request
|
17
|
-
//const headers = new HttpHeaders().set('authorization','Bearer '+token);
|
18
|
-
let b: Observable<Blob>;
|
19
|
-
if (typeof request === 'string') {
|
20
|
-
b = this._httpClient.get(request, { responseType: 'blob' });
|
21
|
-
}
|
22
|
-
else if (b instanceof Observable<Blob>) {
|
23
|
-
b = request;
|
24
|
-
}
|
25
|
-
s = b?.subscribe({
|
26
|
-
next: (v) => resolve(new AXFileDownloadResult(v)),
|
27
|
-
error: (e) => reject(e)
|
28
|
-
})
|
29
|
-
};
|
30
|
-
|
31
|
-
const a = new AXFileDownloadRef(promiseFunc);
|
32
|
-
a.abort = () => {
|
33
|
-
s?.unsubscribe();
|
34
|
-
};
|
35
|
-
|
36
|
-
return a;
|
37
|
-
}
|
38
|
-
|
39
|
-
public upload<T = any>(url: string, files: File[]): AXFileUploadRef<T> {
|
40
|
-
let s: Subscription;
|
41
|
-
let formData = new FormData();
|
42
|
-
files.forEach(f => {
|
43
|
-
formData.append("files", f);
|
44
|
-
})
|
45
|
-
const promiseFunc = (resolve, reject) => {
|
46
|
-
let b: Observable<T>;
|
47
|
-
b = this._httpClient.post<T>(url, formData);
|
48
|
-
|
49
|
-
s = b?.subscribe({
|
50
|
-
next: (v) => resolve(v),
|
51
|
-
error: (e) => reject(e)
|
52
|
-
})
|
53
|
-
};
|
54
|
-
|
55
|
-
const a = new AXFileUploadRef(promiseFunc);
|
56
|
-
a.abort = () => {
|
57
|
-
s?.unsubscribe();
|
58
|
-
};
|
59
|
-
return a;
|
60
|
-
}
|
61
|
-
|
62
|
-
public choose(options?: { accept?: string, multiple?: boolean }): Promise<File[]> {
|
63
|
-
return new Promise<File[]>((resolve, reject) => {
|
64
|
-
options = Object.assign({ multiple: false }, options);
|
65
|
-
const input = document.createElement("input");
|
66
|
-
input.style.display = 'none';
|
67
|
-
document.body.appendChild(input);
|
68
|
-
input.type = 'file';
|
69
|
-
input.accept = options.accept;
|
70
|
-
input.multiple = options.multiple;
|
71
|
-
//
|
72
|
-
const onError = (e) => {
|
73
|
-
reject(e);
|
74
|
-
document.body.removeChild(input)
|
75
|
-
input.remove();
|
76
|
-
input.removeEventListener('change', onChange);
|
77
|
-
input.removeEventListener('error', onError);
|
78
|
-
}
|
79
|
-
//
|
80
|
-
const onChange = () => {
|
81
|
-
resolve(Array.from(input.files));
|
82
|
-
document.body.removeChild(input)
|
83
|
-
input.remove();
|
84
|
-
input.removeEventListener('change', onChange);
|
85
|
-
input.removeEventListener('error', onError);
|
86
|
-
}
|
87
|
-
//
|
88
|
-
input.addEventListener('change', onChange);
|
89
|
-
input.addEventListener('error', onError);
|
90
|
-
input.click();
|
91
|
-
});
|
92
|
-
}
|
93
|
-
|
94
|
-
blobToBase64 = (blob: Blob) => new Promise<string>((resolve, reject) => {
|
95
|
-
const reader = new FileReader;
|
96
|
-
reader.onerror = reject;
|
97
|
-
reader.onload = () => {
|
98
|
-
resolve(reader.result as string);
|
99
|
-
};
|
100
|
-
reader.readAsDataURL(blob);
|
101
|
-
});
|
102
|
-
}
|
103
|
-
|
104
|
-
|
package/http/index.ts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
export * from './public-api'
|
package/http/ng-package.json
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
import { IHttpError } from './http-error.class';
|
2
|
-
|
3
|
-
export class HttpResult<T> {
|
4
|
-
private _executor: (result: (e?: T) => void, error: (e?: IHttpError) => void, complete: () => void) => void;
|
5
|
-
constructor(
|
6
|
-
executor: (
|
7
|
-
result: (e?: T) => void,
|
8
|
-
error: (e?: IHttpError) => void,
|
9
|
-
complete: () => void
|
10
|
-
) => void
|
11
|
-
) {
|
12
|
-
this._executor = executor;
|
13
|
-
setTimeout(() => {
|
14
|
-
this._executor(this.resultAction, this.errorAction, this.completeAction);
|
15
|
-
}, 50);
|
16
|
-
}
|
17
|
-
|
18
|
-
private resultAction: (e?: T) => void;
|
19
|
-
private errorAction: (e?: IHttpError) => void;
|
20
|
-
private completeAction: () => void;
|
21
|
-
|
22
|
-
result(action: (e?: T) => void): HttpResult<T> {
|
23
|
-
this.resultAction = action;
|
24
|
-
return this;
|
25
|
-
}
|
26
|
-
error(action: (e?: IHttpError) => void): HttpResult<T> {
|
27
|
-
this.errorAction = action;
|
28
|
-
return this;
|
29
|
-
}
|
30
|
-
complete(action: () => void): HttpResult<T> {
|
31
|
-
this.completeAction = action;
|
32
|
-
return this;
|
33
|
-
}
|
34
|
-
}
|
package/http/src/http.module.ts
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
import { NgModule, ModuleWithProviders } from '@angular/core';
|
2
|
-
import { CommonModule } from '@angular/common';
|
3
|
-
import { HttpClientModule } from '@angular/common/http';
|
4
|
-
import { AXHttpService } from './http.service';
|
5
|
-
|
6
|
-
|
7
|
-
@NgModule({
|
8
|
-
declarations: [],
|
9
|
-
imports: [
|
10
|
-
CommonModule,
|
11
|
-
HttpClientModule
|
12
|
-
],
|
13
|
-
exports: [HttpClientModule],
|
14
|
-
providers: [
|
15
|
-
AXHttpService
|
16
|
-
]
|
17
|
-
})
|
18
|
-
export class AXHttpModule {
|
19
|
-
// static forRoot(): ModuleWithProviders {
|
20
|
-
// return {
|
21
|
-
// ngModule: AXHttpModule,
|
22
|
-
// providers: [AXHttpService]
|
23
|
-
// };
|
24
|
-
// }
|
25
|
-
}
|
package/http/src/http.service.ts
DELETED
@@ -1,161 +0,0 @@
|
|
1
|
-
import { Injectable, Injector, InjectFlags } from '@angular/core';
|
2
|
-
import { HttpClient, HttpHeaders, HttpParams, HttpErrorResponse } from '@angular/common/http';
|
3
|
-
import { HttpResult } from './http-result.class';
|
4
|
-
import { IHttpError } from './http-error.class';
|
5
|
-
import { AXHttpRequestOptions } from './http-request.class';
|
6
|
-
import {
|
7
|
-
AX_HTTP_EVENT_INTERCEPTOR, AXHttpEventInterceptor
|
8
|
-
} from './http-events.interceptor';
|
9
|
-
// import { catchError, retry, retryWhen, mergeMap, delay, switchMap, scan, takeWhile, flatMap } from 'rxjs/operators';
|
10
|
-
// import { of, concat, throwError } from 'rxjs';
|
11
|
-
|
12
|
-
|
13
|
-
@Injectable({ providedIn: 'root' })
|
14
|
-
export class AXHttpService {
|
15
|
-
|
16
|
-
private interceptor: AXHttpEventInterceptor;
|
17
|
-
constructor(private http: HttpClient, private injector: Injector) {
|
18
|
-
this.interceptor = this.injector.get(AX_HTTP_EVENT_INTERCEPTOR);
|
19
|
-
}
|
20
|
-
|
21
|
-
|
22
|
-
get<T>(url: string, config: AXHttpRequestOptions = {}): HttpResult<T> {
|
23
|
-
config.url = url;
|
24
|
-
config.method = "get";
|
25
|
-
return this.request(config);
|
26
|
-
}
|
27
|
-
|
28
|
-
post<T>(url: string, config: AXHttpRequestOptions = {}): HttpResult<T> {
|
29
|
-
config.url = url;
|
30
|
-
config.method = "post";
|
31
|
-
return this.request(config);
|
32
|
-
}
|
33
|
-
|
34
|
-
delete<T>(url: string, config: AXHttpRequestOptions = {}): HttpResult<T> {
|
35
|
-
config.url = url;
|
36
|
-
config.method = "delete";
|
37
|
-
return this.request(config);
|
38
|
-
}
|
39
|
-
|
40
|
-
put<T>(url: string, config: AXHttpRequestOptions = {}): HttpResult<T> {
|
41
|
-
config.url = url;
|
42
|
-
config.method = "put";
|
43
|
-
return this.request(config);
|
44
|
-
}
|
45
|
-
|
46
|
-
|
47
|
-
request<T>(config: AXHttpRequestOptions): HttpResult<T> {
|
48
|
-
return new HttpResult<T>((result?, error?, complete?) => {
|
49
|
-
this.handleBegin(config).then(c => {
|
50
|
-
this.http
|
51
|
-
//TODO: check ts error
|
52
|
-
//@ts-ignore
|
53
|
-
.request<T>(config.method, config.url, this.mapOptions(config))
|
54
|
-
//.pipe(this.retry)
|
55
|
-
.subscribe(data => {
|
56
|
-
this.handleResult(data, result, complete, config);
|
57
|
-
}, c => {
|
58
|
-
this.handleError(c, error, complete, config);
|
59
|
-
});
|
60
|
-
});
|
61
|
-
})
|
62
|
-
}
|
63
|
-
|
64
|
-
|
65
|
-
private handleResult(data, result, complete, config: AXHttpRequestOptions) {
|
66
|
-
if (this.interceptor) {
|
67
|
-
this.interceptor.success(config, data).then(c => {
|
68
|
-
if (result)
|
69
|
-
result(c);
|
70
|
-
this.handleComplete(complete, config);
|
71
|
-
});
|
72
|
-
}
|
73
|
-
else {
|
74
|
-
//
|
75
|
-
if (result)
|
76
|
-
result(data);
|
77
|
-
this.handleComplete(complete, config);
|
78
|
-
}
|
79
|
-
}
|
80
|
-
|
81
|
-
private handleBegin(config: AXHttpRequestOptions): Promise<AXHttpRequestOptions> {
|
82
|
-
return new Promise((resolve) => {
|
83
|
-
if (!config.headers)
|
84
|
-
config.headers = {};
|
85
|
-
if (!config.params)
|
86
|
-
config.params = {};
|
87
|
-
//
|
88
|
-
if (this.interceptor) {
|
89
|
-
this.interceptor.begin(config).then(c => {
|
90
|
-
resolve(c);
|
91
|
-
});
|
92
|
-
}
|
93
|
-
else {
|
94
|
-
resolve(config)
|
95
|
-
}
|
96
|
-
})
|
97
|
-
}
|
98
|
-
|
99
|
-
private handleComplete(complete: Function, config: AXHttpRequestOptions) {
|
100
|
-
if (complete)
|
101
|
-
complete();
|
102
|
-
if (this.interceptor)
|
103
|
-
this.interceptor.complete(config);
|
104
|
-
}
|
105
|
-
|
106
|
-
private handleError(c: HttpErrorResponse, error: Function, complete: Function, config: AXHttpRequestOptions) {
|
107
|
-
let r: IHttpError = {
|
108
|
-
message: c.message,
|
109
|
-
status: c.status,
|
110
|
-
code: c.status?.toString(),
|
111
|
-
handled: false,
|
112
|
-
error: c.error
|
113
|
-
}
|
114
|
-
if (error) {
|
115
|
-
error(r);
|
116
|
-
}
|
117
|
-
if (!r.handled) {
|
118
|
-
if (this.interceptor)
|
119
|
-
this.interceptor.error(config, r);
|
120
|
-
}
|
121
|
-
this.handleComplete(complete, config);
|
122
|
-
}
|
123
|
-
|
124
|
-
private mapOptions(options: AXHttpRequestOptions) {
|
125
|
-
let headers = new HttpHeaders();
|
126
|
-
|
127
|
-
for (const key in options.headers) {
|
128
|
-
if (options.headers.hasOwnProperty(key)) {
|
129
|
-
const value = options.headers[key];
|
130
|
-
headers = headers.set(key, value)
|
131
|
-
}
|
132
|
-
}
|
133
|
-
let params = new HttpParams();
|
134
|
-
for (const key in options.params) {
|
135
|
-
if (options.params.hasOwnProperty(key)) {
|
136
|
-
const value = options.params[key];
|
137
|
-
params = params.set(key, value);
|
138
|
-
}
|
139
|
-
}
|
140
|
-
return {
|
141
|
-
headers: headers,
|
142
|
-
params: params,
|
143
|
-
body: options.body,
|
144
|
-
responseType: options.responseType || 'json'
|
145
|
-
};
|
146
|
-
// if (options.method == "get") {
|
147
|
-
// return {
|
148
|
-
// headers: headers,
|
149
|
-
// params: params
|
150
|
-
// };
|
151
|
-
// }
|
152
|
-
// else {
|
153
|
-
// return {
|
154
|
-
// headers: headers,
|
155
|
-
// params: params,
|
156
|
-
// body: options.body
|
157
|
-
// };
|
158
|
-
// }
|
159
|
-
}
|
160
|
-
|
161
|
-
}
|
package/image/index.ts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
export * from './public-api';
|
package/image/ng-package.json
DELETED
package/image/public-api.ts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
export * from './src/image.service';
|
@@ -1,42 +0,0 @@
|
|
1
|
-
import { Injectable } from '@angular/core';
|
2
|
-
|
3
|
-
@Injectable({ providedIn: 'root' })
|
4
|
-
export class AXImageService {
|
5
|
-
constructor() { }
|
6
|
-
|
7
|
-
|
8
|
-
async resize(options: { maxSize: number, source: HTMLImageElement | File, type?: 'image/png' | 'image/jpeg' | 'image/webp', quality?: number }): Promise<Blob> {
|
9
|
-
options = Object.assign({ type: 'image/png', quality: 1 }, options);
|
10
|
-
|
11
|
-
let image: HTMLImageElement;
|
12
|
-
if (options.source instanceof File) {
|
13
|
-
var a = new Image()
|
14
|
-
a.src = URL.createObjectURL(options.source);
|
15
|
-
await new Promise<Event>((res) => a.onload = res);
|
16
|
-
image = a;
|
17
|
-
}
|
18
|
-
else {
|
19
|
-
image = options.source;
|
20
|
-
}
|
21
|
-
|
22
|
-
// Resize the image
|
23
|
-
var canvas = document.createElement('canvas'),
|
24
|
-
width = image.width,
|
25
|
-
height = image.height;
|
26
|
-
if (width > height) {
|
27
|
-
if (width > options.maxSize) {
|
28
|
-
height *= options.maxSize / width;
|
29
|
-
width = options.maxSize;
|
30
|
-
}
|
31
|
-
} else {
|
32
|
-
if (height > options.maxSize) {
|
33
|
-
width *= options.maxSize / height;
|
34
|
-
height = options.maxSize;
|
35
|
-
}
|
36
|
-
}
|
37
|
-
canvas.width = width;
|
38
|
-
canvas.height = height;
|
39
|
-
canvas.getContext('2d').drawImage(image, 0, 0, width, height);
|
40
|
-
return new Promise((resolve) => canvas.toBlob(resolve, options.type, options.quality));
|
41
|
-
}
|
42
|
-
}
|
package/index.ts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
export * from './public-api'
|
package/karma.conf.js
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
// Karma configuration file, see link for more information
|
2
|
-
// https://karma-runner.github.io/1.0/config/configuration-file.html
|
3
|
-
|
4
|
-
module.exports = function (config) {
|
5
|
-
config.set({
|
6
|
-
basePath: '',
|
7
|
-
frameworks: ['jasmine', '@angular-devkit/build-angular'],
|
8
|
-
plugins: [
|
9
|
-
require('karma-jasmine'),
|
10
|
-
require('karma-chrome-launcher'),
|
11
|
-
require('karma-jasmine-html-reporter'),
|
12
|
-
require('karma-coverage'),
|
13
|
-
require('@angular-devkit/build-angular/plugins/karma')
|
14
|
-
],
|
15
|
-
client: {
|
16
|
-
jasmine: {
|
17
|
-
// you can add configuration options for Jasmine here
|
18
|
-
// the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html
|
19
|
-
// for example, you can disable the random execution with `random: false`
|
20
|
-
// or set a specific seed with `seed: 4321`
|
21
|
-
},
|
22
|
-
clearContext: false // leave Jasmine Spec Runner output visible in browser
|
23
|
-
},
|
24
|
-
jasmineHtmlReporter: {
|
25
|
-
suppressAll: true // removes the duplicated traces
|
26
|
-
},
|
27
|
-
coverageReporter: {
|
28
|
-
dir: require('path').join(__dirname, '../../../coverage/acorex/core'),
|
29
|
-
subdir: '.',
|
30
|
-
reporters: [
|
31
|
-
{ type: 'html' },
|
32
|
-
{ type: 'text-summary' }
|
33
|
-
]
|
34
|
-
},
|
35
|
-
reporters: ['progress', 'kjhtml'],
|
36
|
-
port: 9876,
|
37
|
-
colors: true,
|
38
|
-
logLevel: config.LOG_INFO,
|
39
|
-
autoWatch: true,
|
40
|
-
browsers: ['Chrome'],
|
41
|
-
singleRun: false,
|
42
|
-
restartOnFileChange: true
|
43
|
-
});
|
44
|
-
};
|
package/ng-package.json
DELETED
package/pipes/index.ts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
export * from './public-api'
|
package/pipes/ng-package.json
DELETED
package/pipes/public-api.ts
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
import { NgModule } from '@angular/core';
|
2
|
-
import { CommonModule } from '@angular/common';
|
3
|
-
import { AXSafePipe } from './safe.pipe';
|
4
|
-
|
5
|
-
@NgModule({
|
6
|
-
declarations: [AXSafePipe],
|
7
|
-
imports: [CommonModule],
|
8
|
-
exports: [AXSafePipe],
|
9
|
-
providers: [],
|
10
|
-
})
|
11
|
-
export class AXPipesModule {}
|
package/pipes/src/safe.pipe.ts
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
import { Pipe, PipeTransform } from '@angular/core';
|
2
|
-
import { DomSanitizer, SafeHtml, SafeStyle, SafeScript, SafeUrl, SafeResourceUrl } from '@angular/platform-browser';
|
3
|
-
|
4
|
-
@Pipe({
|
5
|
-
name: 'safe',
|
6
|
-
pure: true
|
7
|
-
})
|
8
|
-
export class AXSafePipe implements PipeTransform {
|
9
|
-
|
10
|
-
constructor(protected sanitizer: DomSanitizer) { }
|
11
|
-
|
12
|
-
public transform(value: any, type: string): SafeHtml | SafeStyle | SafeScript | SafeUrl | SafeResourceUrl {
|
13
|
-
if (value == null || value == undefined || value == '')
|
14
|
-
return '';
|
15
|
-
switch (type) {
|
16
|
-
case 'html': return this.sanitizer.bypassSecurityTrustHtml(value);
|
17
|
-
case 'style': return this.sanitizer.bypassSecurityTrustStyle(value);
|
18
|
-
case 'script': return this.sanitizer.bypassSecurityTrustScript(value);
|
19
|
-
case 'url': return this.sanitizer.bypassSecurityTrustUrl(value);
|
20
|
-
case 'resourceUrl': return this.sanitizer.bypassSecurityTrustResourceUrl(value);
|
21
|
-
default: throw new Error(`Invalid safe type specified: ${type}`);
|
22
|
-
}
|
23
|
-
}
|
24
|
-
}
|
package/platform/index.ts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
export * from './public-api'
|
package/platform/ng-package.json
DELETED
package/platform/public-api.ts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
export * from './src/platform.service';
|