@acorex/core 5.1.2 → 5.1.6
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/README.md +2 -23
- package/karma.conf.js +32 -0
- package/ng-package.json +10 -0
- package/package.json +13 -38
- 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/src/lib/classes/navigator.class.ts +5 -0
- package/src/lib/classes/popup.class.ts +14 -0
- package/src/lib/classes/promise.class.ts +25 -0
- package/src/lib/classes/sectionlist.class.ts +8 -0
- package/src/lib/classes/select.class.ts +7 -0
- package/src/lib/core.module.ts +21 -0
- package/src/lib/error/error.class.ts +4 -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/src/lib/events/keyboard.ts +5 -0
- package/src/lib/http/http-error.class.ts +7 -0
- package/src/lib/http/http-events.interceptor.ts +14 -0
- package/src/lib/http/http-request.class.ts +14 -0
- 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/src/lib/locale/en.json +255 -0
- package/src/lib/locale/fa.json +244 -0
- 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/src/public-api.ts +53 -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/config/ax-preset.js +0 -182
- package/esm2020/acorex-core.mjs +0 -5
- package/esm2020/lib/config/configs.mjs +0 -29
- package/esm2020/lib/core.module.mjs +0 -18
- package/esm2020/lib/dateTime/datetime.class.mjs +0 -295
- package/esm2020/lib/dateTime/datetime.module.mjs +0 -33
- package/esm2020/lib/dateTime/datetime.pipe.mjs +0 -26
- package/esm2020/lib/dateTime/georgian.calendar.mjs +0 -189
- package/esm2020/lib/dateTime/index.mjs +0 -6
- package/esm2020/lib/dateTime/jalali.calendar.mjs +0 -359
- package/esm2020/lib/events/event.service.mjs +0 -36
- package/esm2020/lib/events/index.mjs +0 -2
- package/esm2020/lib/hotkeys/hotkeys.service.mjs +0 -37
- package/esm2020/lib/hotkeys/index.mjs +0 -2
- package/esm2020/lib/platform/index.mjs +0 -2
- package/esm2020/lib/platform/platform.service.mjs +0 -138
- package/esm2020/lib/translation/index.mjs +0 -4
- package/esm2020/lib/translation/translation.module.mjs +0 -18
- package/esm2020/lib/translation/translator.mjs +0 -42
- package/esm2020/lib/translation/translator.pipe.mjs +0 -15
- package/esm2020/lib/utils/drawing-util.mjs +0 -27
- package/esm2020/lib/utils/index.mjs +0 -5
- package/esm2020/lib/utils/object-util.mjs +0 -39
- package/esm2020/lib/utils/safe.pipe.mjs +0 -30
- package/esm2020/lib/utils/string-util.mjs +0 -19
- package/esm2020/public-api.mjs +0 -13
- package/fesm2015/acorex-core.mjs +0 -1332
- package/fesm2015/acorex-core.mjs.map +0 -1
- package/fesm2020/acorex-core.mjs +0 -1329
- package/fesm2020/acorex-core.mjs.map +0 -1
- package/lib/config/configs.d.ts +0 -9
- package/lib/core.module.d.ts +0 -7
- package/lib/dateTime/datetime.class.d.ts +0 -100
- package/lib/dateTime/datetime.module.d.ts +0 -8
- package/lib/dateTime/datetime.pipe.d.ts +0 -8
- package/lib/dateTime/georgian.calendar.d.ts +0 -20
- package/lib/dateTime/index.d.ts +0 -5
- package/lib/dateTime/jalali.calendar.d.ts +0 -35
- package/lib/events/event.service.d.ts +0 -9
- package/lib/events/index.d.ts +0 -1
- package/lib/hotkeys/hotkeys.service.d.ts +0 -17
- package/lib/hotkeys/index.d.ts +0 -1
- package/lib/platform/index.d.ts +0 -1
- package/lib/platform/platform.service.d.ts +0 -25
- package/lib/translation/index.d.ts +0 -3
- package/lib/translation/translation.module.d.ts +0 -7
- package/lib/translation/translator.d.ts +0 -11
- package/lib/translation/translator.pipe.d.ts +0 -7
- package/lib/utils/drawing-util.d.ts +0 -17
- package/lib/utils/index.d.ts +0 -4
- package/lib/utils/object-util.d.ts +0 -4
- package/lib/utils/safe.pipe.d.ts +0 -10
- package/lib/utils/string-util.d.ts +0 -6
- package/public-api.d.ts +0 -12
package/README.md
CHANGED
|
@@ -1,24 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
### ACoreX Core
|
|
2
|
+
This library have classes,interfacess,events,pipes,directive,validation & ...
|
|
2
3
|
|
|
3
|
-
This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 12.2.0.
|
|
4
|
-
|
|
5
|
-
## Code scaffolding
|
|
6
|
-
|
|
7
|
-
Run `ng generate component component-name --project core` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module --project core`.
|
|
8
|
-
> Note: Don't forget to add `--project core` or else it will be added to the default project in your `angular.json` file.
|
|
9
|
-
|
|
10
|
-
## Build
|
|
11
|
-
|
|
12
|
-
Run `ng build core` to build the project. The build artifacts will be stored in the `dist/` directory.
|
|
13
|
-
|
|
14
|
-
## Publishing
|
|
15
|
-
|
|
16
|
-
After building your library with `ng build core`, go to the dist folder `cd dist/core` and run `npm publish`.
|
|
17
|
-
|
|
18
|
-
## Running unit tests
|
|
19
|
-
|
|
20
|
-
Run `ng test core` to execute the unit tests via [Karma](https://karma-runner.github.io).
|
|
21
|
-
|
|
22
|
-
## Further help
|
|
23
|
-
|
|
24
|
-
To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page.
|
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,38 +1,13 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@acorex/core",
|
|
3
|
-
"version": "5.1.
|
|
4
|
-
"peerDependencies": {
|
|
5
|
-
"@angular/common": "^13.3.
|
|
6
|
-
"@angular/core": "^13.3.
|
|
7
|
-
"
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
},
|
|
15
|
-
"dependencies": {
|
|
16
|
-
"tslib": "^2.3.1"
|
|
17
|
-
},
|
|
18
|
-
"module": "fesm2015/acorex-core.mjs",
|
|
19
|
-
"es2020": "fesm2020/acorex-core.mjs",
|
|
20
|
-
"esm2020": "esm2020/acorex-core.mjs",
|
|
21
|
-
"fesm2020": "fesm2020/acorex-core.mjs",
|
|
22
|
-
"fesm2015": "fesm2015/acorex-core.mjs",
|
|
23
|
-
"typings": "acorex-core.d.ts",
|
|
24
|
-
"exports": {
|
|
25
|
-
"./package.json": {
|
|
26
|
-
"default": "./package.json"
|
|
27
|
-
},
|
|
28
|
-
".": {
|
|
29
|
-
"types": "./acorex-core.d.ts",
|
|
30
|
-
"esm2020": "./esm2020/acorex-core.mjs",
|
|
31
|
-
"es2020": "./fesm2020/acorex-core.mjs",
|
|
32
|
-
"es2015": "./fesm2015/acorex-core.mjs",
|
|
33
|
-
"node": "./fesm2015/acorex-core.mjs",
|
|
34
|
-
"default": "./fesm2020/acorex-core.mjs"
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
"sideEffects": false
|
|
38
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@acorex/core",
|
|
3
|
+
"version": "5.1.6",
|
|
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
|
+
}
|