@acorex/core 6.5.12 → 6.5.14
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/karma.conf.js +32 -0
- package/ng-package.json +10 -0
- package/package.json +13 -33
- package/src/lib/classes/base-page.class.ts +29 -0
- package/src/lib/classes/color.class.ts +61 -0
- package/src/lib/classes/datetime.class.ts +373 -0
- package/src/lib/classes/menu.class.ts +37 -0
- package/{lib/classes/navigator.class.d.ts → src/lib/classes/navigator.class.ts} +1 -1
- package/{lib/classes/popup.class.d.ts → src/lib/classes/popup.class.ts} +2 -0
- package/src/lib/classes/promise.class.ts +25 -0
- package/src/lib/classes/select.class.ts +7 -0
- package/src/lib/core.module.ts +21 -0
- package/src/lib/error/error.module.ts +13 -0
- package/src/lib/error/error.service.ts +23 -0
- package/src/lib/error/index.ts +3 -0
- package/{lib/events/keyboard.d.ts → src/lib/events/keyboard.ts} +3 -0
- package/{lib/http/http-error.class.d.ts → src/lib/http/http-error.class.ts} +2 -2
- package/{lib/http/http-events.interceptor.d.ts → src/lib/http/http-events.interceptor.ts} +7 -3
- package/{lib/http/http-request.class.d.ts → src/lib/http/http-request.class.ts} +5 -5
- package/src/lib/http/http-result.class.ts +34 -0
- package/src/lib/http/http.module.ts +25 -0
- package/src/lib/http/http.service.ts +159 -0
- package/{esm2020 → src}/lib/locale/en.json +6 -6
- package/{esm2020 → src}/lib/locale/fa.json +7 -7
- package/src/lib/pipe/datetime.pipe.ts +20 -0
- package/src/lib/pipe/htmlToText.pipe.ts +18 -0
- package/src/lib/platform/index.ts +1 -0
- package/src/lib/platform/platform.service.ts +211 -0
- package/src/lib/services/config.ts +36 -0
- package/src/lib/services/event.service.ts +31 -0
- package/src/lib/services/navigator.service.ts +8 -0
- package/src/lib/services/storage.service.ts +11 -0
- package/src/lib/translator/translator.module.ts +19 -0
- package/src/lib/translator/translator.pipe.ts +22 -0
- package/src/lib/translator/translator.service.ts +19 -0
- package/src/lib/translator/translator.ts +31 -0
- package/src/lib/utils/array/array-util.ts +140 -0
- package/src/lib/utils/html/html-util.ts +264 -0
- package/src/lib/utils/html/html.module.ts +11 -0
- package/src/lib/utils/math/math-util.ts +5 -0
- package/src/lib/utils/object/object-util.ts +87 -0
- package/src/lib/utils/render/on-demand-preload-strategy.service.ts +25 -0
- package/src/lib/utils/render/render.service.ts +110 -0
- package/src/lib/utils/render/rendering.module.ts +25 -0
- package/src/lib/utils/scroll/scroll.directive.ts +35 -0
- package/src/lib/utils/scroll/scroll.module.ts +11 -0
- package/src/lib/utils/separator/separator.module.ts +11 -0
- package/src/lib/utils/separator/separator.pipe.ts +27 -0
- package/{public-api.d.ts → src/public-api.ts} +10 -0
- package/src/test.ts +28 -0
- package/tsconfig.lib.json +25 -0
- package/tsconfig.lib.prod.json +6 -0
- package/tsconfig.spec.json +18 -0
- package/tslint.json +17 -0
- package/acorex-core.d.ts +0 -5
- package/esm2020/acorex-core.mjs +0 -5
- package/esm2020/lib/classes/base-page.class.mjs +0 -28
- package/esm2020/lib/classes/color.class.mjs +0 -49
- package/esm2020/lib/classes/datetime.class.mjs +0 -314
- package/esm2020/lib/classes/menu.class.mjs +0 -27
- package/esm2020/lib/classes/navigator.class.mjs +0 -2
- package/esm2020/lib/classes/popup.class.mjs +0 -2
- package/esm2020/lib/classes/promise.class.mjs +0 -19
- package/esm2020/lib/classes/sectionlist.class.mjs +0 -2
- package/esm2020/lib/classes/select.class.mjs +0 -3
- package/esm2020/lib/core.module.mjs +0 -27
- package/esm2020/lib/error/error.class.mjs +0 -2
- package/esm2020/lib/error/error.module.mjs +0 -19
- package/esm2020/lib/error/error.service.mjs +0 -21
- package/esm2020/lib/events/keyboard.mjs +0 -2
- package/esm2020/lib/http/http-error.class.mjs +0 -2
- package/esm2020/lib/http/http-events.interceptor.mjs +0 -3
- package/esm2020/lib/http/http-request.class.mjs +0 -2
- package/esm2020/lib/http/http-result.class.mjs +0 -21
- package/esm2020/lib/http/http.module.mjs +0 -37
- package/esm2020/lib/http/http.service.mjs +0 -145
- package/esm2020/lib/pipe/datetime.pipe.mjs +0 -25
- package/esm2020/lib/pipe/htmlToText.pipe.mjs +0 -25
- package/esm2020/lib/platform/index.mjs +0 -2
- package/esm2020/lib/platform/platform.service.mjs +0 -138
- package/esm2020/lib/services/config.mjs +0 -29
- package/esm2020/lib/services/event.service.mjs +0 -36
- package/esm2020/lib/services/navigator.service.mjs +0 -10
- package/esm2020/lib/services/storage.service.mjs +0 -16
- package/esm2020/lib/translator/translator.mjs +0 -26
- package/esm2020/lib/translator/translator.module.mjs +0 -25
- package/esm2020/lib/translator/translator.pipe.mjs +0 -24
- package/esm2020/lib/translator/translator.service.mjs +0 -21
- package/esm2020/lib/utils/array/array-util.mjs +0 -133
- package/esm2020/lib/utils/html/html-util.mjs +0 -192
- package/esm2020/lib/utils/html/html.module.mjs +0 -19
- package/esm2020/lib/utils/math/math-util.mjs +0 -6
- package/esm2020/lib/utils/object/object-util.mjs +0 -83
- package/esm2020/lib/utils/render/on-demand-preload-strategy.service.mjs +0 -20
- package/esm2020/lib/utils/render/render.service.mjs +0 -103
- package/esm2020/lib/utils/render/rendering.module.mjs +0 -35
- package/esm2020/lib/utils/scroll/scroll.directive.mjs +0 -54
- package/esm2020/lib/utils/scroll/scroll.module.mjs +0 -19
- package/esm2020/lib/utils/separator/separator.module.mjs +0 -19
- package/esm2020/lib/utils/separator/separator.pipe.mjs +0 -33
- package/esm2020/public-api.mjs +0 -44
- package/fesm2015/acorex-core.mjs +0 -2262
- package/fesm2015/acorex-core.mjs.map +0 -1
- package/fesm2020/acorex-core.mjs +0 -2258
- package/fesm2020/acorex-core.mjs.map +0 -1
- package/lib/classes/base-page.class.d.ts +0 -13
- package/lib/classes/color.class.d.ts +0 -17
- package/lib/classes/datetime.class.d.ts +0 -63
- package/lib/classes/menu.class.d.ts +0 -34
- package/lib/classes/promise.class.d.ts +0 -7
- package/lib/classes/select.class.d.ts +0 -7
- package/lib/core.module.d.ts +0 -9
- package/lib/error/error.module.d.ts +0 -7
- package/lib/error/error.service.d.ts +0 -13
- package/lib/http/http-result.class.d.ts +0 -11
- package/lib/http/http.module.d.ts +0 -10
- package/lib/http/http.service.d.ts +0 -23
- package/lib/pipe/datetime.pipe.d.ts +0 -8
- package/lib/pipe/htmlToText.pipe.d.ts +0 -7
- package/lib/platform/index.d.ts +0 -1
- package/lib/platform/platform.service.d.ts +0 -25
- package/lib/services/config.d.ts +0 -9
- package/lib/services/event.service.d.ts +0 -9
- package/lib/services/navigator.service.d.ts +0 -8
- package/lib/services/storage.service.d.ts +0 -7
- package/lib/translator/translator.d.ts +0 -9
- package/lib/translator/translator.module.d.ts +0 -8
- package/lib/translator/translator.pipe.d.ts +0 -8
- package/lib/translator/translator.service.d.ts +0 -8
- package/lib/utils/array/array-util.d.ts +0 -6
- package/lib/utils/html/html-util.d.ts +0 -62
- package/lib/utils/html/html.module.d.ts +0 -8
- package/lib/utils/math/math-util.d.ts +0 -3
- package/lib/utils/object/object-util.d.ts +0 -7
- package/lib/utils/render/on-demand-preload-strategy.service.d.ts +0 -10
- package/lib/utils/render/render.service.d.ts +0 -18
- package/lib/utils/render/rendering.module.d.ts +0 -8
- package/lib/utils/scroll/scroll.directive.d.ts +0 -18
- package/lib/utils/scroll/scroll.module.d.ts +0 -8
- package/lib/utils/separator/separator.module.d.ts +0 -8
- package/lib/utils/separator/separator.pipe.d.ts +0 -8
- /package/{lib/classes/sectionlist.class.d.ts → src/lib/classes/sectionlist.class.ts} +0 -0
- /package/{lib/error/error.class.d.ts → src/lib/error/error.class.ts} +0 -0
package/karma.conf.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
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-istanbul-reporter'),
|
|
13
|
+
require('@angular-devkit/build-angular/plugins/karma')
|
|
14
|
+
],
|
|
15
|
+
client: {
|
|
16
|
+
clearContext: false // leave Jasmine Spec Runner output visible in browser
|
|
17
|
+
},
|
|
18
|
+
coverageIstanbulReporter: {
|
|
19
|
+
dir: require('path').join(__dirname, '../../../coverage/acorex/core'),
|
|
20
|
+
reports: ['html', 'lcovonly', 'text-summary'],
|
|
21
|
+
fixWebpackSourcePaths: true
|
|
22
|
+
},
|
|
23
|
+
reporters: ['progress', 'kjhtml'],
|
|
24
|
+
port: 9876,
|
|
25
|
+
colors: true,
|
|
26
|
+
logLevel: config.LOG_INFO,
|
|
27
|
+
autoWatch: true,
|
|
28
|
+
browsers: ['Chrome'],
|
|
29
|
+
singleRun: false,
|
|
30
|
+
restartOnFileChange: true
|
|
31
|
+
});
|
|
32
|
+
};
|
package/ng-package.json
ADDED
package/package.json
CHANGED
|
@@ -1,33 +1,13 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@acorex/core",
|
|
3
|
-
"version": "6.5.
|
|
4
|
-
"peerDependencies": {
|
|
5
|
-
"@angular/common": "^13.3.8",
|
|
6
|
-
"@angular/core": "^13.3.8",
|
|
7
|
-
"rxjs": "~6.5.4"
|
|
8
|
-
},
|
|
9
|
-
"dependencies": {
|
|
10
|
-
"jalali-moment": "3.3.3",
|
|
11
|
-
"tslib": "^2.0.0"
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
"es2020": "fesm2020/acorex-core.mjs",
|
|
15
|
-
"esm2020": "esm2020/acorex-core.mjs",
|
|
16
|
-
"fesm2020": "fesm2020/acorex-core.mjs",
|
|
17
|
-
"fesm2015": "fesm2015/acorex-core.mjs",
|
|
18
|
-
"typings": "acorex-core.d.ts",
|
|
19
|
-
"exports": {
|
|
20
|
-
"./package.json": {
|
|
21
|
-
"default": "./package.json"
|
|
22
|
-
},
|
|
23
|
-
".": {
|
|
24
|
-
"types": "./acorex-core.d.ts",
|
|
25
|
-
"esm2020": "./esm2020/acorex-core.mjs",
|
|
26
|
-
"es2020": "./fesm2020/acorex-core.mjs",
|
|
27
|
-
"es2015": "./fesm2015/acorex-core.mjs",
|
|
28
|
-
"node": "./fesm2015/acorex-core.mjs",
|
|
29
|
-
"default": "./fesm2020/acorex-core.mjs"
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
"sideEffects": false
|
|
33
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@acorex/core",
|
|
3
|
+
"version": "6.5.14",
|
|
4
|
+
"peerDependencies": {
|
|
5
|
+
"@angular/common": "^13.3.8",
|
|
6
|
+
"@angular/core": "^13.3.8",
|
|
7
|
+
"rxjs": "~6.5.4"
|
|
8
|
+
},
|
|
9
|
+
"dependencies": {
|
|
10
|
+
"jalali-moment": "3.3.3",
|
|
11
|
+
"tslib": "^2.0.0"
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { EventEmitter, Injectable } from '@angular/core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @deprecated Use AXBasePageComponent from @acorex/components
|
|
5
|
+
*/
|
|
6
|
+
// TODO: Add Angular decorator.
|
|
7
|
+
@Injectable()
|
|
8
|
+
export abstract class AXBasePageComponent {
|
|
9
|
+
|
|
10
|
+
onClosed: EventEmitter<any> = new EventEmitter<any>();
|
|
11
|
+
|
|
12
|
+
close(data?: any) {
|
|
13
|
+
this.onClosed.emit({
|
|
14
|
+
component: this,
|
|
15
|
+
data: data
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
onClosing(e: any): void | Promise<void> {
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
ngOnDestroy() {
|
|
23
|
+
this.onClosed.unsubscribe();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
export interface AXColor {
|
|
2
|
+
id?: string;
|
|
3
|
+
color?: string;
|
|
4
|
+
code: string;
|
|
5
|
+
selected?: boolean;
|
|
6
|
+
active?: boolean;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export class AXColorUtil {
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
static hex2Rgb(hexColor: string) {
|
|
13
|
+
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hexColor);
|
|
14
|
+
return result ? {
|
|
15
|
+
r: parseInt(result[1], 16),
|
|
16
|
+
g: parseInt(result[2], 16),
|
|
17
|
+
b: parseInt(result[3], 16)
|
|
18
|
+
} : null;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
static rgb2Hex(r: number, g: number, b: number, a: number = 255): string {
|
|
22
|
+
let alpha;
|
|
23
|
+
let hex = (r | 1 << 8).toString(16).slice(1) +
|
|
24
|
+
(g | 1 << 8).toString(16).slice(1) +
|
|
25
|
+
(b | 1 << 8).toString(16).slice(1);
|
|
26
|
+
if (a !== 255) {
|
|
27
|
+
alpha = a;
|
|
28
|
+
} else {
|
|
29
|
+
alpha = 1;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
alpha = Math.round(alpha * 100) / 100;
|
|
33
|
+
alpha = Math.round(alpha * 255);
|
|
34
|
+
const hexAlpha = (alpha + 0x10000).toString(16).substr(-2).toUpperCase();
|
|
35
|
+
return '#' + hex + (alpha == 255 ? '' : hexAlpha);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
static illuminance(hexColor: string) {
|
|
39
|
+
const rgbColor = AXColorUtil.hex2Rgb(hexColor);
|
|
40
|
+
if (!rgbColor) {
|
|
41
|
+
return -1;
|
|
42
|
+
}
|
|
43
|
+
const r = rgbColor.r;
|
|
44
|
+
const g = rgbColor.g;
|
|
45
|
+
const b = rgbColor.b;
|
|
46
|
+
const a = [r, g, b].map(v => {
|
|
47
|
+
v /= 255;
|
|
48
|
+
return (v <= 0.03928) ?
|
|
49
|
+
v / 12.92 :
|
|
50
|
+
Math.pow(((v + 0.055) / 1.055), 2.4);
|
|
51
|
+
});
|
|
52
|
+
return a[0] * 0.2126 + a[1] * 0.7152 + a[2] * 0.0722;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
static contrastToWhite(hexColor: string) {
|
|
56
|
+
const whiteIlluminance = 1;
|
|
57
|
+
const illuminance = AXColorUtil.illuminance(hexColor);
|
|
58
|
+
return whiteIlluminance / illuminance;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
}
|
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
import moment from 'jalali-moment';
|
|
2
|
+
import { AXConfig } from '../services/config';
|
|
3
|
+
// const moment = moment_;
|
|
4
|
+
|
|
5
|
+
export type TimeUnit = 'second' | 'minute' | 'minutes' | 'hour' | 'hours' | 'day' | 'days' | 'month' | 'year' | 'week';
|
|
6
|
+
|
|
7
|
+
export type TimeDuration = 'seconds' | 'minutes' | 'hours' | 'days' | 'weeks' | 'month' | 'years';
|
|
8
|
+
|
|
9
|
+
export type TimeStep = 'Y' | 'M' | 'D' | 'YM' | 'YMD' | 'YMDh' | 'YMDhm' | 'YMDhms' | 'h' | 'm' | 's';
|
|
10
|
+
|
|
11
|
+
export type AXCalendarType = 'jalali' | 'gregorian';
|
|
12
|
+
|
|
13
|
+
export class AXDateTime {
|
|
14
|
+
static convert(value: any, type: AXCalendarType = AXConfig.get('dateTime.type') || 'gregorian'): AXDateTime {
|
|
15
|
+
let date: AXDateTime;
|
|
16
|
+
if (typeof value === 'string' || value instanceof String) {
|
|
17
|
+
date = new AXDateTime(value as string, type);
|
|
18
|
+
} else if (value instanceof Date) {
|
|
19
|
+
date = new AXDateTime(value as Date, type);
|
|
20
|
+
} else if (value instanceof AXDateTime) {
|
|
21
|
+
date = value;
|
|
22
|
+
}
|
|
23
|
+
return date;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
private _date: Date;
|
|
27
|
+
get date(): Date {
|
|
28
|
+
return this._date;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
private resolveUnit(unit: TimeUnit): any {
|
|
32
|
+
return this.type === 'jalali' ? 'j' + unit : unit;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
private _moment: moment.Moment;
|
|
36
|
+
|
|
37
|
+
// private get _moment(): moment_.Moment {
|
|
38
|
+
// const m = moment(this.date);
|
|
39
|
+
// if (this.type === 'jalali') {
|
|
40
|
+
// m.locale('fa');
|
|
41
|
+
// }
|
|
42
|
+
// return m;
|
|
43
|
+
// }
|
|
44
|
+
|
|
45
|
+
constructor(value: Date | string = new Date(), public type: AXCalendarType = AXConfig.get('dateTime.type') || 'gregorian') {
|
|
46
|
+
if (value instanceof Date) {
|
|
47
|
+
this._date = value as Date;
|
|
48
|
+
} else {
|
|
49
|
+
this._date = new Date(value);
|
|
50
|
+
}
|
|
51
|
+
this._moment = moment(this.date);
|
|
52
|
+
if (this.type === 'jalali') {
|
|
53
|
+
this._moment.locale('fa');
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
clone(): AXDateTime {
|
|
58
|
+
return new AXDateTime(this.date, this.type);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
get dayInMonth(): number {
|
|
62
|
+
return this._moment.date();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
get dayOfYear(): number {
|
|
66
|
+
return this._moment.dayOfYear();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
get dayInWeek(): number {
|
|
70
|
+
return this._moment.day();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
get hour(): number {
|
|
74
|
+
return this._moment.hour();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
get minute(): number {
|
|
78
|
+
return this._moment.minute();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
get second(): number {
|
|
82
|
+
return this._moment.second();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
get year(): number {
|
|
86
|
+
return this._moment.year();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
get monthOfYear(): number {
|
|
90
|
+
return this._moment.month();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
get month(): AXCalendarMonth {
|
|
94
|
+
return new AXCalendarMonth(this);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
get firstDayOfWeek(): AXDateTime {
|
|
98
|
+
const a = moment(this.date);
|
|
99
|
+
if (this.type === 'jalali') {
|
|
100
|
+
this._moment.locale('fa');
|
|
101
|
+
}
|
|
102
|
+
return new AXDateTime(a.startOf('w').toDate(), this.type);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
get endDayOfWeek(): AXDateTime {
|
|
106
|
+
const a = moment(this.date);
|
|
107
|
+
if (this.type === 'jalali') {
|
|
108
|
+
this._moment.locale('fa');
|
|
109
|
+
}
|
|
110
|
+
return new AXDateTime(moment(this.date).endOf('w').toDate(), this.type);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
convertStringToJalali(date: string, format: string) {
|
|
114
|
+
return moment(date).locale('fa').format('YYYY/M/D');
|
|
115
|
+
}
|
|
116
|
+
convertStringToGregorian(date: string, format: string) {
|
|
117
|
+
return new Date(moment.from(date, 'fa', 'YYYY/MM/DD').format('YYYY/MM/DD'));
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
add(unit: TimeUnit = 'day', amount: number): AXDateTime {
|
|
121
|
+
return new AXDateTime(moment(this.date).add(amount, this.resolveUnit(unit)).toDate(), this.type);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
addDay(amount: number): AXDateTime {
|
|
125
|
+
return new AXDateTime(moment(this.date).add(amount, 'd').toDate(), this.type);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
addMonth(amount: number): AXDateTime {
|
|
129
|
+
return new AXDateTime(moment(this.date).add(amount, 'months').toDate(), this.type);
|
|
130
|
+
}
|
|
131
|
+
addHour(amount: number) {
|
|
132
|
+
return new AXDateTime(moment(this.date).add(amount, 'hours').toDate(), this.type);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
set(unit: TimeUnit = 'day', value: number): AXDateTime {
|
|
136
|
+
return new AXDateTime(this._moment.set(unit, value).toDate(), this.type);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
duration(end: AXDateTime, unit: TimeDuration = 'days'): number {
|
|
140
|
+
const duration = moment.duration(this._moment.diff(end._moment));
|
|
141
|
+
return Math.round(duration.as(unit));
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
startOf(unit: TimeUnit = 'day'): AXDateTime {
|
|
145
|
+
return new AXDateTime(moment(this.date).startOf(this.resolveUnit(unit)).toDate(), this.type);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
endOf(unit: TimeUnit = 'day'): AXDateTime {
|
|
149
|
+
return new AXDateTime(moment(this.date).endOf(this.resolveUnit(unit)).toDate(), this.type);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
format(format: string = AXConfig.get('dateTime.shortDateFormat') || (this.type === 'gregorian' ? 'DD-MM-YYYY' : 'YYYY-MM-DD')): string {
|
|
153
|
+
if (format === 'P') {
|
|
154
|
+
return this._moment.fromNow();
|
|
155
|
+
}
|
|
156
|
+
return this._moment.format(format);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
toString(): string {
|
|
160
|
+
return this.format();
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
equal(value: AXDateTime, unit: TimeUnit = 'day') {
|
|
164
|
+
if (!value) {
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
return this._moment.isSame(moment(value.date), this.resolveUnit(unit));
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
convertToJalaliDate(value) {
|
|
171
|
+
const options: any = {
|
|
172
|
+
numberingSystem: 'latn',
|
|
173
|
+
year: 'numeric',
|
|
174
|
+
month: '2-digit',
|
|
175
|
+
day: '2-digit',
|
|
176
|
+
hour: '2-digit',
|
|
177
|
+
minute: '2-digit',
|
|
178
|
+
second: '2-digit'
|
|
179
|
+
};
|
|
180
|
+
const jDate = new Date(value).toLocaleDateString('fa-IR', options);
|
|
181
|
+
const item: any = {};
|
|
182
|
+
item.year = jDate.slice(0, 4);
|
|
183
|
+
item.month = jDate.slice(5, 7);
|
|
184
|
+
item.day = jDate.slice(8, 10);
|
|
185
|
+
item.hour = jDate.slice(13, 15);
|
|
186
|
+
item.minutes = jDate.slice(16, 18);
|
|
187
|
+
item.seconds = jDate.slice(19, 21);
|
|
188
|
+
return item;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
toJalaliString(value) {
|
|
192
|
+
const date = this.convertToJalaliDate(value);
|
|
193
|
+
let str = '';
|
|
194
|
+
str = date.year + '-' + date.month + '-' + date.day + 'T' + date.hour + ':' + date.minutes + ':' + date.seconds;
|
|
195
|
+
return str;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
convertToGregorianDate(value) {
|
|
199
|
+
// TODO: check this fucking type
|
|
200
|
+
const options: any = {
|
|
201
|
+
numberingSystem: 'latn',
|
|
202
|
+
year: 'numeric',
|
|
203
|
+
month: '2-digit',
|
|
204
|
+
day: '2-digit',
|
|
205
|
+
hour: '2-digit',
|
|
206
|
+
minute: '2-digit',
|
|
207
|
+
second: '2-digit'
|
|
208
|
+
};
|
|
209
|
+
const date = new Date(value).toLocaleString('en-us', options);
|
|
210
|
+
const item: any = {};
|
|
211
|
+
item.year = date.slice(6, 10);
|
|
212
|
+
item.month = date.slice(0, 2);
|
|
213
|
+
item.day = date.slice(3, 5);
|
|
214
|
+
item.hour = date.slice(12, 14);
|
|
215
|
+
item.minutes = date.slice(15, 17);
|
|
216
|
+
item.seconds = date.slice(18, 20);
|
|
217
|
+
return item;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
toGregorianString(value) {
|
|
221
|
+
const date = this.convertToGregorianDate(value);
|
|
222
|
+
let str = '';
|
|
223
|
+
str = date.year + '-' + date.month + '-' + date.day + 'T' + date.hour + ':' + date.minutes + ':' + date.seconds;
|
|
224
|
+
return str;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
compaireNew(value: AXDateTime, unit: TimeStep = 'YMD', type = 'jalali') {
|
|
228
|
+
const range = [0, 0];
|
|
229
|
+
let str1;
|
|
230
|
+
let str2;
|
|
231
|
+
if (type === 'jalali') {
|
|
232
|
+
str1 = this.toJalaliString(this.date);
|
|
233
|
+
str2 = this.toJalaliString(value.date ? value.date : value);
|
|
234
|
+
} else {
|
|
235
|
+
str1 = this.toGregorianString(this.date);
|
|
236
|
+
str2 = this.toGregorianString(value.date ? value.date : value);
|
|
237
|
+
}
|
|
238
|
+
switch (unit) {
|
|
239
|
+
case 'YMDhms':
|
|
240
|
+
range[0] = 0;
|
|
241
|
+
range[1] = 19;
|
|
242
|
+
break;
|
|
243
|
+
case 'YMDhm':
|
|
244
|
+
range[0] = 0;
|
|
245
|
+
range[1] = 16;
|
|
246
|
+
break;
|
|
247
|
+
case 'YMDh':
|
|
248
|
+
range[0] = 0;
|
|
249
|
+
range[1] = 13;
|
|
250
|
+
break;
|
|
251
|
+
case 'YMD':
|
|
252
|
+
range[0] = 0;
|
|
253
|
+
range[1] = 10;
|
|
254
|
+
break;
|
|
255
|
+
|
|
256
|
+
case 'YM':
|
|
257
|
+
range[0] = 0;
|
|
258
|
+
range[1] = 7;
|
|
259
|
+
break;
|
|
260
|
+
|
|
261
|
+
case 'h':
|
|
262
|
+
range[0] = 11;
|
|
263
|
+
range[1] = 13;
|
|
264
|
+
break;
|
|
265
|
+
|
|
266
|
+
case 'm':
|
|
267
|
+
range[0] = 14;
|
|
268
|
+
range[1] = 16;
|
|
269
|
+
break;
|
|
270
|
+
|
|
271
|
+
case 's':
|
|
272
|
+
range[0] = 17;
|
|
273
|
+
range[1] = 19;
|
|
274
|
+
break;
|
|
275
|
+
case 'D':
|
|
276
|
+
range[0] = 8;
|
|
277
|
+
range[1] = 10;
|
|
278
|
+
break;
|
|
279
|
+
|
|
280
|
+
case 'M':
|
|
281
|
+
range[0] = 5;
|
|
282
|
+
range[1] = 7;
|
|
283
|
+
break;
|
|
284
|
+
|
|
285
|
+
case 'Y':
|
|
286
|
+
range[0] = 0;
|
|
287
|
+
range[1] = 4;
|
|
288
|
+
break;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
if (str1.slice(range[0], range[1]) === str2.slice(range[0], range[1])) {
|
|
292
|
+
return 0;
|
|
293
|
+
} else if (str1.slice(range[0], range[1]) > str2.slice(range[0], range[1])) {
|
|
294
|
+
return 1;
|
|
295
|
+
} else {
|
|
296
|
+
return -1;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
compaire(value: AXDateTime, unit: TimeUnit = 'day') {
|
|
301
|
+
if (this._moment.isSame(moment(value.date), this.resolveUnit(unit))) {
|
|
302
|
+
return 0;
|
|
303
|
+
} else if (this._moment.isAfter(moment(value.date), this.resolveUnit(unit))) {
|
|
304
|
+
return 1;
|
|
305
|
+
} else {
|
|
306
|
+
return -1;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
toISOString() {
|
|
311
|
+
return this._date.toISOString();
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
export class AXCalendarMonth {
|
|
316
|
+
private _moment: moment.Moment;
|
|
317
|
+
|
|
318
|
+
private _range: AXDateTimeRange;
|
|
319
|
+
public get range(): AXDateTimeRange {
|
|
320
|
+
return this._range;
|
|
321
|
+
}
|
|
322
|
+
public set range(v: AXDateTimeRange) {
|
|
323
|
+
this._range = v;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
constructor(date: AXDateTime) {
|
|
327
|
+
this._moment = moment(date.date);
|
|
328
|
+
this.index = date.date.getMonth();
|
|
329
|
+
this.name = this._moment.format('MMMM');
|
|
330
|
+
this.range = new AXDateTimeRange(
|
|
331
|
+
new AXDateTime(this._moment.startOf('month').toDate(), date.type),
|
|
332
|
+
new AXDateTime(this._moment.endOf('month').toDate(), date.type)
|
|
333
|
+
);
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
private readonly index: number;
|
|
337
|
+
private readonly name: string;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
export class AXDateTimeRange {
|
|
341
|
+
constructor(public startTime: AXDateTime, public endTime: AXDateTime) { }
|
|
342
|
+
|
|
343
|
+
duration(unit: TimeDuration = 'days'): number {
|
|
344
|
+
const duration = moment.duration(moment(this.startTime.date).diff(moment(this.endTime.date)));
|
|
345
|
+
return duration.as(unit);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
enumurate(unit: TimeUnit = 'day', type: AXCalendarType = AXConfig.get('dateTime.type') || 'jalali'): AXDateTime[] {
|
|
349
|
+
const result: AXDateTime[] = [];
|
|
350
|
+
for (let index = 0; this.startTime.add(unit, index).compaireNew(this.endTime, this.getViewCompaire(unit), type) <= 0; index++) {
|
|
351
|
+
result.push(this.startTime.add(unit, index));
|
|
352
|
+
}
|
|
353
|
+
return result;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
includes(value: AXDateTime, unit: TimeUnit = 'day', type = 'jalali'): boolean {
|
|
357
|
+
return (
|
|
358
|
+
value.compaireNew(this.startTime, this.getViewCompaire(unit), type) >= 0 &&
|
|
359
|
+
value.compaireNew(this.endTime, this.getViewCompaire(unit), type) <= 0
|
|
360
|
+
);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
getViewCompaire(view) {
|
|
364
|
+
switch (view) {
|
|
365
|
+
case 'day':
|
|
366
|
+
return 'YMD';
|
|
367
|
+
case 'month':
|
|
368
|
+
return 'YM';
|
|
369
|
+
case 'year':
|
|
370
|
+
return 'Y';
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export class AXBaseMenuItem {
|
|
2
|
+
uid?: string = new Date().getTime().toString();
|
|
3
|
+
id?: string;
|
|
4
|
+
name?: string;
|
|
5
|
+
text?: string;
|
|
6
|
+
tooltip?: string;
|
|
7
|
+
tooltipPlacement?: 'top' | 'right' | 'bottom' | 'left';
|
|
8
|
+
icon?: string;
|
|
9
|
+
visible?: boolean = true;
|
|
10
|
+
disable?: boolean = false;
|
|
11
|
+
selected?: boolean = false;
|
|
12
|
+
groupName?: string;
|
|
13
|
+
data?: any;
|
|
14
|
+
style?: string = 'ax light';
|
|
15
|
+
orderIndex?: number = 0;
|
|
16
|
+
endIcon?: string;
|
|
17
|
+
startIcon?: string;
|
|
18
|
+
onClick?: (e?: any) => void;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export class AXMenuItem extends AXBaseMenuItem {
|
|
22
|
+
items?: AXMenuItem[];
|
|
23
|
+
parentId?: string;
|
|
24
|
+
divider?: boolean = false;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export class AXButtonItem extends AXBaseMenuItem {
|
|
28
|
+
dropdown?: boolean = false;
|
|
29
|
+
submitBehavior?: boolean = false;
|
|
30
|
+
cancelBehavior?: boolean = false;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export class AXCheckItem {
|
|
34
|
+
text?: string;
|
|
35
|
+
value?: any;
|
|
36
|
+
selected?: boolean;
|
|
37
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export class AXPromise<T> {
|
|
2
|
+
|
|
3
|
+
private _executor: (then?: (e?: T) => void) => void;
|
|
4
|
+
private thenAction?: (e?: T) => void;
|
|
5
|
+
|
|
6
|
+
static resolve<T>(value: T): AXPromise<T> {
|
|
7
|
+
const r = new AXPromise<T>(z => {
|
|
8
|
+
z(value);
|
|
9
|
+
}).then(() => { });
|
|
10
|
+
return r;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
constructor(executor: (then?: (e?: T) => void) => void) {
|
|
14
|
+
this._executor = executor;
|
|
15
|
+
setTimeout(() => {
|
|
16
|
+
this._executor(this.thenAction);
|
|
17
|
+
}, 50);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
then(action?: (e?: T) => void): AXPromise<T> {
|
|
22
|
+
this.thenAction = action;
|
|
23
|
+
return this;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { NgModule } from '@angular/core';
|
|
2
|
+
import { AXDateTimePipe } from './pipe/datetime.pipe';
|
|
3
|
+
import { AXEventService } from './services/event.service';
|
|
4
|
+
import { AXStorageService } from './services/storage.service';
|
|
5
|
+
import { AXScrollModule } from './utils/scroll/scroll.module';
|
|
6
|
+
import { AXTranslatorModule } from './translator/translator.module';
|
|
7
|
+
|
|
8
|
+
const PIPES = [AXDateTimePipe];
|
|
9
|
+
const MODULES = [AXScrollModule, AXTranslatorModule];
|
|
10
|
+
const SERVICES = [AXEventService,
|
|
11
|
+
AXStorageService
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@NgModule({
|
|
16
|
+
declarations: [...PIPES],
|
|
17
|
+
imports: [...MODULES],
|
|
18
|
+
exports: [...PIPES],
|
|
19
|
+
providers: [...SERVICES]
|
|
20
|
+
})
|
|
21
|
+
export class AXCoreModule { }
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { NgModule } from '@angular/core';
|
|
2
|
+
import { CommonModule } from '@angular/common';
|
|
3
|
+
import { AXErrorService } from './error.service';
|
|
4
|
+
|
|
5
|
+
@NgModule({
|
|
6
|
+
declarations: [],
|
|
7
|
+
imports: [CommonModule],
|
|
8
|
+
exports: [],
|
|
9
|
+
providers: [AXErrorService],
|
|
10
|
+
})
|
|
11
|
+
export class AXErrorModule {
|
|
12
|
+
|
|
13
|
+
}
|