@mosa-ng/core 17.0.0 → 19.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/fesm2022/mosa-ng-core.mjs +1448 -0
- package/fesm2022/mosa-ng-core.mjs.map +1 -0
- package/index.d.ts +5 -0
- package/lib/constants/local-storage.constant.d.ts +2 -0
- package/lib/enums/browser.enum.d.ts +9 -0
- package/lib/enums/content-position.enum.d.ts +11 -0
- package/lib/enums/i18n-supported.enum.d.ts +10 -0
- package/lib/enums/theme.enum.d.ts +4 -0
- package/{src/lib/models/api-options.model.ts → lib/models/api-options.model.d.ts} +2 -6
- package/{src/lib/models/dictionary-item.model.ts → lib/models/dictionary-item.model.d.ts} +1 -2
- package/lib/models/key-map.model.d.ts +3 -0
- package/{src/lib/models/logger/log-event.model.ts → lib/models/logger/log-event.model.d.ts} +0 -1
- package/{src/lib/models/logger/log-message-data.model.ts → lib/models/logger/log-message-data.model.d.ts} +0 -1
- package/{src/lib/models/logger/log.model.ts → lib/models/logger/log.model.d.ts} +0 -1
- package/{src/lib/models/logger/logger-config.model.ts → lib/models/logger/logger-config.model.d.ts} +0 -1
- package/{src/lib/models/logger/logger-default-config.model.ts → lib/models/logger/logger-default-config.model.d.ts} +0 -1
- package/lib/models/mosa-duration.model.d.ts +1 -0
- package/{src/lib/models/sieve/sieve-filter.model.ts → lib/models/sieve/sieve-filter.model.d.ts} +0 -1
- package/lib/models/sieve/sieve-operator.model.d.ts +69 -0
- package/{src/lib/models/sieve/sieve-options.model.ts → lib/models/sieve/sieve-options.model.d.ts} +0 -1
- package/{src/lib/mosa-core.module.ts → lib/mosa-core.module.d.ts} +10 -47
- package/lib/pipes/dictionary-item-pipe/dictionary-item-pipe.module.d.ts +8 -0
- package/lib/pipes/dictionary-item-pipe/dictionary-item.pipe.d.ts +8 -0
- package/lib/pipes/find-in-array/find-in-array-pipe.module.d.ts +8 -0
- package/lib/pipes/find-in-array/find-in-array.pipe.d.ts +7 -0
- package/lib/pipes/join/join-pipe.module.d.ts +8 -0
- package/lib/pipes/join/join.pipe.d.ts +13 -0
- package/lib/pipes/mosa-date-pipe/mosa-date-pipe.module.d.ts +8 -0
- package/lib/pipes/mosa-date-pipe/mosa-date.pipe.d.ts +18 -0
- package/lib/pipes/mosa-duration-pipe/mosa-duration-pipe.module.d.ts +8 -0
- package/lib/pipes/mosa-duration-pipe/mosa-duration.pipe.d.ts +27 -0
- package/lib/services/api.service.d.ts +110 -0
- package/lib/services/core-logger.service.d.ts +80 -0
- package/lib/services/guards/can-deactivate.guard.d.ts +11 -0
- package/lib/services/mosa-socket.service.d.ts +11 -0
- package/lib/services/translation/assets-i18n-loader.service.d.ts +16 -0
- package/lib/services/translation/custom-translate-loader.service.d.ts +9 -0
- package/lib/services/translation/translate-collector.service.d.ts +15 -0
- package/lib/utils/commons.util.d.ts +47 -0
- package/lib/utils/dictionary.util.d.ts +70 -0
- package/{src/lib/utils/item.util.ts → lib/utils/item.util.d.ts} +1 -1
- package/lib/utils/promise.util.d.ts +2 -0
- package/lib/utils/prototypes.util.d.ts +80 -0
- package/lib/utils/sieve.util.d.ts +71 -0
- package/{src/lib/utils/size.util.ts → lib/utils/size.util.d.ts} +1 -1
- package/package.json +21 -10
- package/public-api.d.ts +1 -0
- package/.eslintrc.json +0 -31
- package/ng-package.json +0 -10
- package/src/lib/constants/local-storage.constant.ts +0 -4
- package/src/lib/enums/browser.enum.ts +0 -9
- package/src/lib/enums/content-position.enum.ts +0 -11
- package/src/lib/enums/i18n-supported.enum.ts +0 -10
- package/src/lib/enums/theme.enum.ts +0 -4
- package/src/lib/models/key-map.model.ts +0 -3
- package/src/lib/models/mosa-duration.model.ts +0 -1
- package/src/lib/models/sieve/sieve-operator.model.ts +0 -69
- package/src/lib/pipes/dictionary-item-pipe/dictionary-item-pipe.module.ts +0 -15
- package/src/lib/pipes/dictionary-item-pipe/dictionary-item.pipe.ts +0 -14
- package/src/lib/pipes/find-in-array/find-in-array-pipe.module.ts +0 -17
- package/src/lib/pipes/find-in-array/find-in-array.pipe.spec.ts +0 -8
- package/src/lib/pipes/find-in-array/find-in-array.pipe.ts +0 -34
- package/src/lib/pipes/join/join-pipe.module.ts +0 -17
- package/src/lib/pipes/join/join.pipe.spec.ts +0 -8
- package/src/lib/pipes/join/join.pipe.ts +0 -20
- package/src/lib/pipes/mosa-date-pipe/mosa-date-pipe.module.ts +0 -14
- package/src/lib/pipes/mosa-date-pipe/mosa-date.pipe.ts +0 -102
- package/src/lib/pipes/mosa-duration-pipe/mosa-duration-pipe.module.ts +0 -13
- package/src/lib/pipes/mosa-duration-pipe/mosa-duration.pipe.ts +0 -106
- package/src/lib/services/api.service.ts +0 -270
- package/src/lib/services/core-logger.service.ts +0 -219
- package/src/lib/services/guards/can-deactivate.guard.ts +0 -18
- package/src/lib/services/mosa-socket.service.ts +0 -46
- package/src/lib/services/translation/assets-i18n-loader.service.ts +0 -67
- package/src/lib/services/translation/custom-translate-loader.service.ts +0 -27
- package/src/lib/services/translation/translate-collector.service.ts +0 -60
- package/src/lib/utils/commons.util.ts +0 -100
- package/src/lib/utils/dictionary.util.ts +0 -140
- package/src/lib/utils/promise.util.ts +0 -3
- package/src/lib/utils/prototypes.util.ts +0 -167
- package/src/lib/utils/sieve.util.ts +0 -169
- package/src/public-api.ts +0 -1
- package/tsconfig.lib.json +0 -16
- package/tsconfig.lib.prod.json +0 -10
- package/tsconfig.spec.json +0 -14
- /package/{src/lib/models/logger/log-type.model.ts → lib/models/logger/log-type.model.d.ts} +0 -0
- /package/{src/lib/models/logger/logger-base-config.model.ts → lib/models/logger/logger-base-config.model.d.ts} +0 -0
- /package/{src/lib/models/sieve/sieve-response.model.ts → lib/models/sieve/sieve-response.model.d.ts} +0 -0
- /package/{src/lib/models/sieve/sieve-sort.model.ts → lib/models/sieve/sieve-sort.model.d.ts} +0 -0
- /package/{src/lib/models/token-settings.model.ts → lib/models/token-settings.model.d.ts} +0 -0
- /package/{src/lib/models/transform-matrix.model.ts → lib/models/transform-matrix.model.d.ts} +0 -0
package/.eslintrc.json
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../.eslintrc.json",
|
|
3
|
-
"parserOptions": {
|
|
4
|
-
"project": "**/tsconfig.json"
|
|
5
|
-
},
|
|
6
|
-
"overrides": [
|
|
7
|
-
{
|
|
8
|
-
"files": [
|
|
9
|
-
"*.ts"
|
|
10
|
-
],
|
|
11
|
-
"rules": {
|
|
12
|
-
"@angular-eslint/component-selector": [
|
|
13
|
-
"error",
|
|
14
|
-
{
|
|
15
|
-
"type": "element",
|
|
16
|
-
"prefix": "mosa",
|
|
17
|
-
"style": "kebab-case"
|
|
18
|
-
}
|
|
19
|
-
],
|
|
20
|
-
"@angular-eslint/directive-selector": [
|
|
21
|
-
"error",
|
|
22
|
-
{
|
|
23
|
-
"type": "attribute",
|
|
24
|
-
"prefix": "mosa",
|
|
25
|
-
"style": "camelCase"
|
|
26
|
-
}
|
|
27
|
-
]
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
]
|
|
31
|
-
}
|
package/ng-package.json
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { I18nSupported } from '../enums/i18n-supported.enum';
|
|
2
|
-
|
|
3
|
-
export const MOSA_MERGED_TRANSLATION = (lang: string): string => `mosa_${ lang }_merged_${ location.host }`;
|
|
4
|
-
export const MOSA_FALLBACK_TRANSLATION = `mosa_${ I18nSupported.enUS }_merged_${ location.host }`;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export enum ContentPosition {
|
|
2
|
-
top = 'top',
|
|
3
|
-
topLeft = 'top-left',
|
|
4
|
-
topRight = 'top-right',
|
|
5
|
-
bottom = 'bottom',
|
|
6
|
-
bottomLeft = 'bottom-left',
|
|
7
|
-
bottomRight = 'bottom-right',
|
|
8
|
-
center = 'center',
|
|
9
|
-
centerLeft = 'center-left',
|
|
10
|
-
centerRight = 'center-right',
|
|
11
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type MosaDurationFormat = 'auto' | 'days' | 'hours' | 'minutes' | 'seconds';
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Sieve operator for filtering
|
|
3
|
-
* @see https://github.com/Biarity/Sieve#operators
|
|
4
|
-
*/
|
|
5
|
-
export type SieveOperator =
|
|
6
|
-
/**
|
|
7
|
-
* Equals
|
|
8
|
-
*/
|
|
9
|
-
'==' |
|
|
10
|
-
/**
|
|
11
|
-
* Not equals
|
|
12
|
-
*/
|
|
13
|
-
'!=' |
|
|
14
|
-
/**
|
|
15
|
-
* Greater than
|
|
16
|
-
*/
|
|
17
|
-
'>' |
|
|
18
|
-
/**
|
|
19
|
-
* Less than
|
|
20
|
-
*/
|
|
21
|
-
'<' |
|
|
22
|
-
/**
|
|
23
|
-
* Greater than or equal to
|
|
24
|
-
*/
|
|
25
|
-
'>=' |
|
|
26
|
-
/**
|
|
27
|
-
* Less than or equal to
|
|
28
|
-
*/
|
|
29
|
-
'<=' |
|
|
30
|
-
/**
|
|
31
|
-
* Contains
|
|
32
|
-
*/
|
|
33
|
-
'@=' |
|
|
34
|
-
/**
|
|
35
|
-
* Starts with
|
|
36
|
-
*/
|
|
37
|
-
'_=' |
|
|
38
|
-
/**
|
|
39
|
-
* Does not Contains
|
|
40
|
-
*/
|
|
41
|
-
'!@=' |
|
|
42
|
-
/**
|
|
43
|
-
* Does not Starts with
|
|
44
|
-
*/
|
|
45
|
-
'!_=' |
|
|
46
|
-
/**
|
|
47
|
-
* Case-insensitive string Contains
|
|
48
|
-
*/
|
|
49
|
-
'@=*' |
|
|
50
|
-
/**
|
|
51
|
-
* Case-insensitive string Starts with
|
|
52
|
-
*/
|
|
53
|
-
'_=*' |
|
|
54
|
-
/**
|
|
55
|
-
* Case-insensitive string Equals
|
|
56
|
-
*/
|
|
57
|
-
'==*' |
|
|
58
|
-
/**
|
|
59
|
-
* Case-insensitive string Not equals
|
|
60
|
-
*/
|
|
61
|
-
'!=*' |
|
|
62
|
-
/**
|
|
63
|
-
* Case-insensitive string does not Contains
|
|
64
|
-
*/
|
|
65
|
-
'!@=*' |
|
|
66
|
-
/**
|
|
67
|
-
* Case-insensitive string does not Starts with
|
|
68
|
-
*/
|
|
69
|
-
'!_=*';
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { CommonModule } from '@angular/common';
|
|
2
|
-
import { NgModule } from '@angular/core';
|
|
3
|
-
import { DictionaryItemPipe } from './dictionary-item.pipe';
|
|
4
|
-
|
|
5
|
-
@NgModule({
|
|
6
|
-
declarations: [ DictionaryItemPipe ],
|
|
7
|
-
imports: [
|
|
8
|
-
CommonModule,
|
|
9
|
-
],
|
|
10
|
-
exports: [
|
|
11
|
-
DictionaryItemPipe,
|
|
12
|
-
],
|
|
13
|
-
})
|
|
14
|
-
export class DictionaryItemPipeModule {
|
|
15
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { Pipe, PipeTransform } from '@angular/core';
|
|
2
|
-
import { Dictionary } from '../../utils/dictionary.util';
|
|
3
|
-
|
|
4
|
-
@Pipe({
|
|
5
|
-
name: 'dictionaryItem',
|
|
6
|
-
})
|
|
7
|
-
export class DictionaryItemPipe implements PipeTransform {
|
|
8
|
-
|
|
9
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
10
|
-
public transform(key: any, dictionary: Dictionary<any, any>): string {
|
|
11
|
-
return dictionary.get(key)?.value;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { CommonModule } from '@angular/common';
|
|
2
|
-
import { NgModule } from '@angular/core';
|
|
3
|
-
import { FindInArrayPipe } from './find-in-array.pipe';
|
|
4
|
-
|
|
5
|
-
@NgModule({
|
|
6
|
-
declarations: [
|
|
7
|
-
FindInArrayPipe,
|
|
8
|
-
],
|
|
9
|
-
imports: [
|
|
10
|
-
CommonModule,
|
|
11
|
-
],
|
|
12
|
-
exports: [
|
|
13
|
-
FindInArrayPipe,
|
|
14
|
-
],
|
|
15
|
-
})
|
|
16
|
-
export class FindInArrayPipeModule {
|
|
17
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { Pipe, PipeTransform } from '@angular/core';
|
|
2
|
-
|
|
3
|
-
@Pipe({
|
|
4
|
-
name: 'findInArray',
|
|
5
|
-
})
|
|
6
|
-
export class FindInArrayPipe implements PipeTransform {
|
|
7
|
-
|
|
8
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
9
|
-
public transform<T>(searchValue: any, array: T[], searchKey: keyof T, returnElements?: (keyof T)[]): any {
|
|
10
|
-
// Return if array is empty or null
|
|
11
|
-
if (!array || !array.length) {
|
|
12
|
-
return null;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
16
|
-
const foundItem: T = array.find((val: T): boolean => (searchKey ? val[ searchKey as keyof T ] : val) === searchValue);
|
|
17
|
-
if (!foundItem) {
|
|
18
|
-
return null;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// Return whole item
|
|
22
|
-
if (!returnElements) {
|
|
23
|
-
return foundItem;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (returnElements.length === 1) {
|
|
27
|
-
return foundItem[ returnElements[ 0 ] ];
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// Return given values to the keys
|
|
31
|
-
return returnElements.map((val: keyof T) => foundItem[ val as keyof T ]);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { CommonModule } from '@angular/common';
|
|
2
|
-
import { NgModule } from '@angular/core';
|
|
3
|
-
import { JoinPipe } from './join.pipe';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
@NgModule({
|
|
7
|
-
declarations: [
|
|
8
|
-
JoinPipe,
|
|
9
|
-
],
|
|
10
|
-
exports: [
|
|
11
|
-
JoinPipe,
|
|
12
|
-
],
|
|
13
|
-
imports: [
|
|
14
|
-
CommonModule,
|
|
15
|
-
],
|
|
16
|
-
})
|
|
17
|
-
export class JoinPipeModule { }
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { Pipe, PipeTransform } from '@angular/core';
|
|
2
|
-
|
|
3
|
-
@Pipe({
|
|
4
|
-
name: 'join',
|
|
5
|
-
})
|
|
6
|
-
export class JoinPipe implements PipeTransform {
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Join array by separator
|
|
10
|
-
* @param array
|
|
11
|
-
* @param returnField
|
|
12
|
-
* @param separator
|
|
13
|
-
*/
|
|
14
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
15
|
-
public transform(array: any[], returnField: any, separator: string = ', '): string {
|
|
16
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
17
|
-
return array.map((val: any): string => returnField ? val[ returnField ] : val).join(separator);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { CommonModule, DatePipe } from '@angular/common';
|
|
2
|
-
import { NgModule } from '@angular/core';
|
|
3
|
-
import { MosaDatePipe } from './mosa-date.pipe';
|
|
4
|
-
|
|
5
|
-
@NgModule({
|
|
6
|
-
declarations: [ MosaDatePipe ],
|
|
7
|
-
imports: [
|
|
8
|
-
CommonModule,
|
|
9
|
-
],
|
|
10
|
-
exports: [ MosaDatePipe ],
|
|
11
|
-
providers: [ DatePipe ],
|
|
12
|
-
})
|
|
13
|
-
export class MosaDatePipeModule {
|
|
14
|
-
}
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import { DatePipe } from '@angular/common';
|
|
2
|
-
import { Pipe, PipeTransform } from '@angular/core';
|
|
3
|
-
import { TranslateService } from '@ngx-translate/core';
|
|
4
|
-
import { BehaviorSubject, Observable } from 'rxjs';
|
|
5
|
-
import { map } from 'rxjs/operators';
|
|
6
|
-
|
|
7
|
-
@Pipe({
|
|
8
|
-
name: 'mosaDate',
|
|
9
|
-
})
|
|
10
|
-
export class MosaDatePipe implements PipeTransform {
|
|
11
|
-
|
|
12
|
-
private readonly store$: BehaviorSubject<number>;
|
|
13
|
-
private templates: Record<string, string>;
|
|
14
|
-
|
|
15
|
-
constructor(
|
|
16
|
-
private readonly myTranslateService: TranslateService,
|
|
17
|
-
private readonly myDatePipe: DatePipe,
|
|
18
|
-
) {
|
|
19
|
-
this.store$ = new BehaviorSubject<number>(null);
|
|
20
|
-
this.updateTemplates();
|
|
21
|
-
setInterval((): void => {
|
|
22
|
-
this.store$.next(new Date().getTime());
|
|
23
|
-
}, 10);
|
|
24
|
-
this.myTranslateService.onLangChange.subscribe((): void => {
|
|
25
|
-
this.updateTemplates();
|
|
26
|
-
this.store$.next(new Date().getTime());
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
public transform(date: string | Date, mode: 'full' | 'timeSince' | 'date' = 'timeSince'): Observable<string> {
|
|
31
|
-
return this.store$.pipe(map((currentDate: number): string => this.calcDate(currentDate, date, mode)));
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
private calcDate(currentDate: number, date: string | Date, mode: 'full' | 'timeSince' | 'date'): string {
|
|
35
|
-
let parsed: number;
|
|
36
|
-
if (date instanceof Date) {
|
|
37
|
-
parsed = new Date(date.toString()).getTime();
|
|
38
|
-
} else {
|
|
39
|
-
parsed = new Date(date).getTime();
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (!currentDate) {
|
|
43
|
-
currentDate = new Date().getTime();
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const convertedDate = this.myDatePipe.transform(parsed, 'dd. MMM. yyyy hh:mm aaa');
|
|
47
|
-
if (mode === 'full' || mode === 'timeSince') {
|
|
48
|
-
const seconds = ((currentDate - parsed) * .001) >> 0;
|
|
49
|
-
const minutes = seconds / 60;
|
|
50
|
-
const hours = minutes / 60;
|
|
51
|
-
const days = hours / 24;
|
|
52
|
-
const years = days / 365;
|
|
53
|
-
|
|
54
|
-
const timeSince: string = this.templates[ 'prefix' ] + (
|
|
55
|
-
seconds < 60 && this.template('seconds', seconds) ||
|
|
56
|
-
seconds < 120 && this.template('minute', 1) ||
|
|
57
|
-
minutes < 60 && this.template('minutes', minutes) ||
|
|
58
|
-
minutes < 120 && this.template('hour', 1) ||
|
|
59
|
-
hours < 24 && this.template('hours', hours) ||
|
|
60
|
-
hours < 42 && this.template('day', 1) ||
|
|
61
|
-
days < 30 && this.template('days', days) ||
|
|
62
|
-
days < 45 && this.template('month', 1) ||
|
|
63
|
-
days < 365 && this.template('months', days / 30) ||
|
|
64
|
-
years < 1.5 && this.template('year', 1) ||
|
|
65
|
-
this.template('years', years)
|
|
66
|
-
) + this.templates[ 'prefix' ];
|
|
67
|
-
|
|
68
|
-
if (mode === 'timeSince') {
|
|
69
|
-
return timeSince;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (mode === 'full') {
|
|
73
|
-
return `${convertedDate} (${timeSince})`;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return convertedDate;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
private template(key: string, val: number): string {
|
|
81
|
-
return this.templates[ key ] && this.templates[ key ].replace(/%d/i, String(Math.abs(Math.round(val))));
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
private updateTemplates(): void {
|
|
85
|
-
this.templates = {
|
|
86
|
-
prefix: this.myTranslateService.instant('mosa.pipes.timeSince.prefix'),
|
|
87
|
-
suffix: this.myTranslateService.instant('mosa.pipes.timeSince.suffix'),
|
|
88
|
-
seconds: this.myTranslateService.instant('mosa.pipes.timeSince.seconds'),
|
|
89
|
-
minute: this.myTranslateService.instant('mosa.pipes.timeSince.minute'),
|
|
90
|
-
minutes: this.myTranslateService.instant('mosa.pipes.timeSince.minutes'),
|
|
91
|
-
hour: this.myTranslateService.instant('mosa.pipes.timeSince.hour'),
|
|
92
|
-
hours: this.myTranslateService.instant('mosa.pipes.timeSince.hours'),
|
|
93
|
-
day: this.myTranslateService.instant('mosa.pipes.timeSince.day'),
|
|
94
|
-
days: this.myTranslateService.instant('mosa.pipes.timeSince.days'),
|
|
95
|
-
month: this.myTranslateService.instant('mosa.pipes.timeSince.month'),
|
|
96
|
-
months: this.myTranslateService.instant('mosa.pipes.timeSince.months'),
|
|
97
|
-
year: this.myTranslateService.instant('mosa.pipes.timeSince.year'),
|
|
98
|
-
years: this.myTranslateService.instant('mosa.pipes.timeSince.years'),
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { CommonModule } from '@angular/common';
|
|
2
|
-
import { NgModule } from '@angular/core';
|
|
3
|
-
import { MosaDurationPipe } from './mosa-duration.pipe';
|
|
4
|
-
|
|
5
|
-
@NgModule({
|
|
6
|
-
declarations: [ MosaDurationPipe ],
|
|
7
|
-
imports: [
|
|
8
|
-
CommonModule,
|
|
9
|
-
],
|
|
10
|
-
exports: [ MosaDurationPipe ],
|
|
11
|
-
})
|
|
12
|
-
export class MosaDurationPipeModule {
|
|
13
|
-
}
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import { Pipe, PipeTransform } from '@angular/core';
|
|
2
|
-
import { TranslateService } from '@ngx-translate/core';
|
|
3
|
-
import { BehaviorSubject, Observable } from 'rxjs';
|
|
4
|
-
import { map } from 'rxjs/operators';
|
|
5
|
-
import { MosaDurationFormat } from '../../models/mosa-duration.model';
|
|
6
|
-
|
|
7
|
-
@Pipe({
|
|
8
|
-
name: 'mosaDuration',
|
|
9
|
-
})
|
|
10
|
-
export class MosaDurationPipe implements PipeTransform {
|
|
11
|
-
|
|
12
|
-
private readonly store$: BehaviorSubject<number>;
|
|
13
|
-
private readonly interval: NodeJS.Timeout;
|
|
14
|
-
|
|
15
|
-
constructor(
|
|
16
|
-
private readonly myTranslateService: TranslateService,
|
|
17
|
-
) {
|
|
18
|
-
this.store$ = new BehaviorSubject<number>(new Date().getTime());
|
|
19
|
-
this.interval = setInterval(() => {
|
|
20
|
-
this.store$.next(new Date().getTime());
|
|
21
|
-
}, 1000);
|
|
22
|
-
this.myTranslateService.onLangChange.subscribe((): void => {
|
|
23
|
-
this.store$.next(new Date().getTime());
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Converts a timestamp to a duration in the given format
|
|
29
|
-
* @param millis
|
|
30
|
-
* @param format
|
|
31
|
-
* @returns
|
|
32
|
-
* auto: 15000 -> 15 seconds
|
|
33
|
-
* seconds: 15000 -> 15 seconds
|
|
34
|
-
* minutes: 60000 -> 1 minute
|
|
35
|
-
* hours: 7200000 -> 2 hours
|
|
36
|
-
* days: 172800000 -> 2 days
|
|
37
|
-
*/
|
|
38
|
-
public transform(millis: number, format: MosaDurationFormat = 'auto'): Observable<string> {
|
|
39
|
-
return this.store$.pipe(
|
|
40
|
-
map((currentDate: number): string => {
|
|
41
|
-
if (!millis) {
|
|
42
|
-
clearInterval(this.interval);
|
|
43
|
-
return null;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (millis - currentDate < 0) {
|
|
47
|
-
clearInterval(this.interval);
|
|
48
|
-
return null;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return this.calcDuration(currentDate, millis, format);
|
|
52
|
-
}),
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
private getTranslation(num: number, format: MosaDurationFormat): string {
|
|
58
|
-
if (num === 1) {
|
|
59
|
-
return `${ num.toFixed(0) } ${ this.myTranslateService.instant(`mosa.commons.dateTime[${ format }].label`) }`;
|
|
60
|
-
}
|
|
61
|
-
return `${ num.toFixed(0) } ${ this.myTranslateService.instant(`mosa.commons.dateTime[${ format }].plural.label`) }`;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
private calcDuration(currentDate: number, millis: number, format: MosaDurationFormat): string {
|
|
66
|
-
millis = millis - currentDate;
|
|
67
|
-
|
|
68
|
-
const seconds: number = millis / 1000;
|
|
69
|
-
if (format === 'seconds') {
|
|
70
|
-
return this.getTranslation(seconds, 'seconds');
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const minutes: number = seconds / 60;
|
|
74
|
-
if (format === 'minutes') {
|
|
75
|
-
return this.getTranslation(minutes, 'minutes');
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const hours: number = minutes / 60;
|
|
79
|
-
if (format === 'hours') {
|
|
80
|
-
return this.getTranslation(hours, 'hours');
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const days: number = hours / 24;
|
|
84
|
-
if (format === 'days') {
|
|
85
|
-
return this.getTranslation(days, 'days');
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if (format === 'auto') {
|
|
89
|
-
if (seconds < 60) {
|
|
90
|
-
return this.getTranslation(seconds, 'seconds');
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
if (minutes < 60) {
|
|
94
|
-
return this.getTranslation(minutes, 'minutes');
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (hours < 24) {
|
|
98
|
-
return this.getTranslation(hours, 'hours');
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
return this.getTranslation(days, 'days');
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
return null;
|
|
105
|
-
}
|
|
106
|
-
}
|