diff --git a/CHANGELOG.md b/CHANGELOG.md index baa913cd..8f84e6a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,23 @@ +## [4.13.2](https://github.com/onecx/onecx-portal-ui-libs/compare/v4.13.1...v4.13.2) (2024-04-02) + + +### Bug Fixes + +* ocx-time-ago-pipe ([#191](https://github.com/onecx/onecx-portal-ui-libs/issues/191)) ([27efc2f](https://github.com/onecx/onecx-portal-ui-libs/commit/27efc2fdb3cfeec079e73c32521ae12b5f9c0b7b)) + +## [4.13.1](https://github.com/onecx/onecx-portal-ui-libs/compare/v4.13.0...v4.13.1) (2024-03-28) + + +### Bug Fixes + +* update dependencies for semantic release ([#190](https://github.com/onecx/onecx-portal-ui-libs/issues/190)) ([6129eb9](https://github.com/onecx/onecx-portal-ui-libs/commit/6129eb905acf2e513747e7c5f9bf0d9a223e9df6)) +* update release.config.js ([59c1b41](https://github.com/onecx/onecx-portal-ui-libs/commit/59c1b41aaea64f3f42c6931fd083ecd38f4f6d58)) + + +### Chores + +* **release:** -v4.13.0 [skip ci] ([ccec05e](https://github.com/onecx/onecx-portal-ui-libs/commit/ccec05e1386c58d8d23414573fd951e83213f1d6)), closes [#189](https://github.com/onecx/onecx-portal-ui-libs/issues/189) [#188](https://github.com/onecx/onecx-portal-ui-libs/issues/188) [#190](https://github.com/onecx/onecx-portal-ui-libs/issues/190) + ## [4.13.0](https://github.com/onecx/onecx-portal-ui-libs/compare/v4.12.1...v4.13.0) (2024-03-27) diff --git a/libs/accelerator/package.json b/libs/accelerator/package.json index 0380f59e..460d5b93 100644 --- a/libs/accelerator/package.json +++ b/libs/accelerator/package.json @@ -1,6 +1,6 @@ { "name": "@onecx/accelerator", - "version": "4.13.0", + "version": "4.13.2", "peerDependencies": { "tslib": "^2.3.0", "rxjs": "7.8.1" diff --git a/libs/angular-accelerator/assets/i18n/de.json b/libs/angular-accelerator/assets/i18n/de.json index e6411f4e..45d2c599 100644 --- a/libs/angular-accelerator/assets/i18n/de.json +++ b/libs/angular-accelerator/assets/i18n/de.json @@ -126,5 +126,18 @@ "HORIZONTAL_BAR": "Zu horizontalem Balkendiagramm wechseln", "VERTICAL_BAR": "Zu vertikalem Balkendiagramm wechseln" } + }, + "OCX_TIMEAGO": { + "A_DAY_AGO": "vor einem Tag", + "A_FEW_SECONDS_AGO": "vor ein paar Sekunden", + "AN_HOUR_AGO": "vor einer Stunde", + "A_MINUTE_AGO": "vor einer Minute", + "A_MONAT_AGO": "vor einem Monat", + "A_YEAR_AGO": "vor einem Jahr", + "DAYS_AGO": "vor {{days}} Tagen", + "HOURS_AGO": "vor {{hours}} Stunden", + "MINUTES_AGO": "vor {{minutes}} Minuten", + "MONTHS_AGO": "vor {{months}} Monaten", + "YEARS_AGO": "vor {{years}} Jahren" } } \ No newline at end of file diff --git a/libs/angular-accelerator/assets/i18n/en.json b/libs/angular-accelerator/assets/i18n/en.json index 9bebbf8d..2b551acd 100644 --- a/libs/angular-accelerator/assets/i18n/en.json +++ b/libs/angular-accelerator/assets/i18n/en.json @@ -126,5 +126,18 @@ "HORIZONTAL_BAR": "Switch to horizontal bar chart", "VERTICAL_BAR": "Switch to vertical bar chart" } + }, + "OCX_TIMEAGO": { + "A_DAY_AGO": "a day ago", + "A_FEW_SECONDS_AGO": "a few seconds ago", + "AN_HOUR_AGO": "an hour ago", + "A_MINUTE_AGO": "a minute ago", + "A_MONTH_AGO": "a month ago", + "A_YEAR_AGO": "a year ago", + "DAYS_AGO": "{{days}} days ago", + "HOURS_AGO": "{{hours}} hours ago", + "MINUTES_AGO": "{{minutes}} minutes ago", + "MONTHS_AGO": "{{months}} months ago", + "YEARS_AGO": "{{years}} years ago" } } \ No newline at end of file diff --git a/libs/angular-accelerator/package.json b/libs/angular-accelerator/package.json index 73f0ce4d..eb2b738b 100644 --- a/libs/angular-accelerator/package.json +++ b/libs/angular-accelerator/package.json @@ -1,6 +1,6 @@ { "name": "@onecx/angular-accelerator", - "version": "4.13.0", + "version": "4.13.2", "peerDependencies": { "@angular/common": "^15.2.7", "@angular/core": "^15.2.7", @@ -14,8 +14,7 @@ "chart.js": "^4.4.0", "d3-scale-chromatic": "^3.0.0", "rxjs": "~7.8.0", - "primeng": "^15.2.1", - "ngx-timeago": "^2.0.0" + "primeng": "^15.2.1" }, "dependencies": {}, "exports": { diff --git a/libs/angular-accelerator/src/lib/angular-accelerator.module.ts b/libs/angular-accelerator/src/lib/angular-accelerator.module.ts index 86208608..d18977f2 100644 --- a/libs/angular-accelerator/src/lib/angular-accelerator.module.ts +++ b/libs/angular-accelerator/src/lib/angular-accelerator.module.ts @@ -1,5 +1,5 @@ import { CommonModule } from '@angular/common' -import { CUSTOM_ELEMENTS_SCHEMA, LOCALE_ID, NgModule, importProvidersFrom } from '@angular/core' +import { CUSTOM_ELEMENTS_SCHEMA, LOCALE_ID, NgModule } from '@angular/core' import { FormsModule, ReactiveFormsModule } from '@angular/forms' import { RouterModule } from '@angular/router' import { HttpClient } from '@angular/common/http' @@ -9,14 +9,6 @@ import { TranslateLoader, TranslateModule, } from '@ngx-translate/core' -import { - TimeagoClock, - TimeagoCustomFormatter, - TimeagoDefaultClock, - TimeagoFormatter, - TimeagoIntl, - TimeagoModule, -} from 'ngx-timeago' import { AppStateService, UserService } from '@onecx/angular-integration-interface' @@ -38,7 +30,6 @@ import { DynamicPipe } from './pipes/dynamic.pipe' import { IfPermissionDirective } from './directives/if-permission.directive' import { IfBreakpointDirective } from './directives/if-breakpoint.directive' import { OcxTimeAgoPipe } from './pipes/ocxtimeago.pipe' -import { OcxTimeagoIntl } from './utils/ocxtimeagointl.utils' import { createTranslateLoader } from './utils/create-translate-loader.utils' import { TranslationCacheService } from './services/translation-cache.service' import { SrcDirective } from './directives/src.directive' @@ -98,25 +89,6 @@ export class AngularAcceleratorMissingTranslationHandler implements MissingTrans }, deps: [UserService], }, - { - provide: TimeagoIntl, - useFactory: (userService: UserService) => { - return new OcxTimeagoIntl(userService) - }, - deps: [UserService], - }, - importProvidersFrom(TimeagoModule), - { - provide: TimeagoFormatter, - useFactory: (TimeagoIntl: TimeagoIntl) => { - return new TimeagoCustomFormatter(TimeagoIntl) - }, - deps: [TimeagoIntl], - }, - { - provide: TimeagoClock, - useClass: TimeagoDefaultClock, - }, ], exports: [ ColumnGroupSelectionComponent, diff --git a/libs/angular-accelerator/src/lib/pipes/ocxtimeago.pipe.ts b/libs/angular-accelerator/src/lib/pipes/ocxtimeago.pipe.ts index 996c7642..00856571 100644 --- a/libs/angular-accelerator/src/lib/pipes/ocxtimeago.pipe.ts +++ b/libs/angular-accelerator/src/lib/pipes/ocxtimeago.pipe.ts @@ -1,8 +1,88 @@ -import { Pipe } from '@angular/core' -import { TimeagoPipe } from 'ngx-timeago' +import { ChangeDetectorRef, NgZone, OnDestroy, Pipe, PipeTransform } from '@angular/core' +import { TranslatePipe, TranslateService } from '@ngx-translate/core' @Pipe({ name: 'timeago', }) // eslint-disable-next-line @angular-eslint/use-pipe-transform-interface -export class OcxTimeAgoPipe extends TimeagoPipe {} +export class OcxTimeAgoPipe extends TranslatePipe implements OnDestroy, PipeTransform { + private timer: number | undefined | null + constructor( + private changeDetectorRef: ChangeDetectorRef, + private ngZone: NgZone, + private translateService: TranslateService + ) { + super(translateService, changeDetectorRef) + } + override transform(value: string) { + this.removeTimer() + const d = new Date(value) + const now = new Date() + const seconds = Math.round(Math.abs((now.getTime() - d.getTime()) / 1000)) + const timeToUpdate = Number.isNaN(seconds) ? 1000 : this.getSecondsUntilUpdate(seconds) * 1000 + this.timer = this.ngZone.runOutsideAngular(() => { + if (typeof window !== 'undefined') { + return window.setTimeout(() => { + this.ngZone.run(() => this.changeDetectorRef.markForCheck()) + }, timeToUpdate) + } + return null + }) + const minutes = Math.round(Math.abs(seconds / 60)) + const hours = Math.round(Math.abs(minutes / 60)) + const days = Math.round(Math.abs(hours / 24)) + const months = Math.round(Math.abs(days / 30.416)) + const years = Math.round(Math.abs(days / 365)) + let translationKey = 'UNKNOWN' + if (Number.isNaN(seconds)) { + translationKey = 'NAN' + } else if (seconds <= 45) { + translationKey = 'A_FEW_SECONDS_AGO' + } else if (seconds <= 90) { + translationKey = 'A_MINUTE_AGO' + } else if (minutes <= 45) { + translationKey = 'MINUTES_AGO' + } else if (minutes <= 90) { + translationKey = 'AN_HOUR_AGO' + } else if (hours <= 22) { + translationKey = 'HOURS_AGO' + } else if (hours <= 36) { + translationKey = 'A_DAY_AGO' + } else if (days <= 25) { + translationKey = 'DAYS_AGO' + } else if (days <= 45) { + translationKey = 'A_MONTH_AGO' + } else if (days <= 345) { + translationKey = 'MONTHS_AGO' + } else if (days <= 545) { + translationKey = 'A_YEAR_AGO' + } else { + translationKey = 'YEARS_AGO' + } + return super.transform('OCX_TIMEAGO.' + translationKey, { minutes, hours, days, months, years }) + } + override ngOnDestroy(): void { + this.removeTimer() + super.ngOnDestroy() + } + private removeTimer() { + if (this.timer) { + window.clearTimeout(this.timer) + this.timer = null + } + } + private getSecondsUntilUpdate(seconds: number) { + const min = 60 + const hr = min * 60 + const day = hr * 24 + if (seconds < min) { + return 2 + } else if (seconds < hr) { + return 30 + } else if (seconds < day) { + return 300 + } else { + return 3600 + } + } +} diff --git a/libs/angular-accelerator/src/lib/utils/ocxtimeagointl.utils.ts b/libs/angular-accelerator/src/lib/utils/ocxtimeagointl.utils.ts deleted file mode 100644 index 0430419a..00000000 --- a/libs/angular-accelerator/src/lib/utils/ocxtimeagointl.utils.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { map } from 'rxjs' -import { IL10nsStrings, TimeagoIntl } from 'ngx-timeago' -import { strings as englishStrings } from 'ngx-timeago/language-strings/en' -import { strings as germanStrings } from 'ngx-timeago/language-strings/de' -import { UserService } from '@onecx/angular-integration-interface' - -export class OcxTimeagoIntl extends TimeagoIntl { - private LANG_TO_STRINGS: { [key: string]: IL10nsStrings } = { - en: englishStrings, - de: germanStrings, - } - private DEFAULT_LANG = 'en' - - constructor(protected userService: UserService) { - super() - this.strings = englishStrings - userService.lang$ - .pipe( - map((lang) => { - return this.getBestMatchLanguage(lang as string) - }) - ) - .subscribe((lang) => { - this.strings = this.LANG_TO_STRINGS[lang] - this.changes.next() - }) - } - - getBestMatchLanguage(lang: string) { - if (Object.keys(this.LANG_TO_STRINGS).includes(lang)) { - return lang - } else { - console.log(`${lang} is not supported. Using ${this.DEFAULT_LANG} as a fallback.`) - } - return this.DEFAULT_LANG - } -} diff --git a/libs/angular-integration-interface/package.json b/libs/angular-integration-interface/package.json index 42c02628..3a57decd 100644 --- a/libs/angular-integration-interface/package.json +++ b/libs/angular-integration-interface/package.json @@ -1,6 +1,6 @@ { "name": "@onecx/angular-integration-interface", - "version": "4.13.0", + "version": "4.13.2", "peerDependencies": { "@angular/core": "^15.2.7", "@onecx/integration-interface": "~4", diff --git a/libs/angular-remote-components/package.json b/libs/angular-remote-components/package.json index af30f184..1122645f 100644 --- a/libs/angular-remote-components/package.json +++ b/libs/angular-remote-components/package.json @@ -1,6 +1,6 @@ { "name": "@onecx/angular-remote-components", - "version": "4.13.0", + "version": "4.13.2", "peerDependencies": {}, "dependencies": {}, "publishConfig": { diff --git a/libs/angular-testing/package.json b/libs/angular-testing/package.json index f581a1c2..e598c24f 100644 --- a/libs/angular-testing/package.json +++ b/libs/angular-testing/package.json @@ -1,6 +1,6 @@ { "name": "@onecx/angular-testing", - "version": "4.13.0", + "version": "4.13.2", "peerDependencies": { "@angular/cdk": "^15.2.7", "primeng": "^15.2.1" diff --git a/libs/integration-interface/package.json b/libs/integration-interface/package.json index 181f9424..ac7344f7 100644 --- a/libs/integration-interface/package.json +++ b/libs/integration-interface/package.json @@ -1,6 +1,6 @@ { "name": "@onecx/integration-interface", - "version": "4.13.0", + "version": "4.13.2", "peerDependencies": { "tslib": "^2.3.0", "rxjs": "7.8.1", diff --git a/libs/keycloak-auth/package.json b/libs/keycloak-auth/package.json index 1c51496e..7e529998 100644 --- a/libs/keycloak-auth/package.json +++ b/libs/keycloak-auth/package.json @@ -1,6 +1,6 @@ { "name": "@onecx/keycloak-auth", - "version": "4.13.0", + "version": "4.13.2", "peerDependencies": { "@angular/common": ">=15.2.7", "@angular/core": ">=15.2.7", diff --git a/libs/portal-integration-angular/assets/i18n/de.json b/libs/portal-integration-angular/assets/i18n/de.json index 7d39801f..da1ce656 100644 --- a/libs/portal-integration-angular/assets/i18n/de.json +++ b/libs/portal-integration-angular/assets/i18n/de.json @@ -147,5 +147,18 @@ "HORIZONTAL_BAR": "Zu horizontalem Balkendiagramm wechseln", "VERTICAL_BAR": "Zu vertikalem Balkendiagramm wechseln" } + }, + "OCX_TIMEAGO": { + "A_DAY_AGO": "vor einem Tag", + "A_FEW_SECONDS_AGO": "vor ein paar Sekunden", + "AN_HOUR_AGO": "vor einer Stunde", + "A_MINUTE_AGO": "vor einer Minute", + "A_MONAT_AGO": "vor einem Monat", + "A_YEAR_AGO": "vor einem Jahr", + "DAYS_AGO": "vor {{days}} Tagen", + "HOURS_AGO": "vor {{hours}} Stunden", + "MINUTES_AGO": "vor {{minutes}} Minuten", + "MONTHS_AGO": "vor {{months}} Monaten", + "YEARS_AGO": "vor {{years}} Jahren" } } \ No newline at end of file diff --git a/libs/portal-integration-angular/assets/i18n/en.json b/libs/portal-integration-angular/assets/i18n/en.json index 0f28c018..f94a42ef 100644 --- a/libs/portal-integration-angular/assets/i18n/en.json +++ b/libs/portal-integration-angular/assets/i18n/en.json @@ -147,5 +147,18 @@ "HORIZONTAL_BAR": "Switch to horizontal bar chart", "VERTICAL_BAR": "Switch to vertical bar chart" } + }, + "OCX_TIMEAGO": { + "A_DAY_AGO": "a day ago", + "A_FEW_SECONDS_AGO": "a few seconds ago", + "AN_HOUR_AGO": "an hour ago", + "A_MINUTE_AGO": "a minute ago", + "A_MONTH_AGO": "a month ago", + "A_YEAR_AGO": "a year ago", + "DAYS_AGO": "{{days}} days ago", + "HOURS_AGO": "{{hours}} hours ago", + "MINUTES_AGO": "{{minutes}} minutes ago", + "MONTHS_AGO": "{{months}} months ago", + "YEARS_AGO": "{{years}} years ago" } } \ No newline at end of file diff --git a/libs/portal-integration-angular/package.json b/libs/portal-integration-angular/package.json index 263c2302..40fd5ea3 100644 --- a/libs/portal-integration-angular/package.json +++ b/libs/portal-integration-angular/package.json @@ -1,6 +1,6 @@ { "name": "@onecx/portal-integration-angular", - "version": "4.13.0", + "version": "4.13.2", "peerDependencies": { "@angular-architects/module-federation": "15.0.0", "@angular/common": "^15.2.7", diff --git a/libs/portal-layout-styles/package.json b/libs/portal-layout-styles/package.json index f192e0a0..2bbd32d1 100644 --- a/libs/portal-layout-styles/package.json +++ b/libs/portal-layout-styles/package.json @@ -1,6 +1,6 @@ { "name": "@onecx/portal-layout-styles", - "version": "4.13.0", + "version": "4.13.2", "peerDependencies": { "tslib": "^2.5.0" }, diff --git a/package-lock.json b/package-lock.json index a7848a6b..290fcb9d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -35,7 +35,6 @@ "keycloak-angular": "^13.0.0", "keycloak-js": "^18.0.0", "ngx-color": "^8.0.3", - "ngx-timeago": "^2.0.0", "primeflex": "^3.3.0", "primeicons": "^6.0.1", "primeng": "15.2.1", @@ -29739,18 +29738,6 @@ "@angular/core": ">=14.0.0-0" } }, - "node_modules/ngx-timeago": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ngx-timeago/-/ngx-timeago-2.0.0.tgz", - "integrity": "sha512-5kQZeTPCkegEcSooUu3W0BSOwvxEt1q6zjodwEOYoW/FxETC8Bk1zQF1QOPZLS+Nu3GLA+g1oPXMVBonM+CYQQ==", - "dependencies": { - "tslib": "^2.0.0" - }, - "peerDependencies": { - "@angular/core": ">=10.0.0", - "rxjs": ">=6.6.0" - } - }, "node_modules/ngx-translate-testing": { "version": "6.1.0", "dev": true, @@ -59739,14 +59726,6 @@ "tslib": "^2.3.0" } }, - "ngx-timeago": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ngx-timeago/-/ngx-timeago-2.0.0.tgz", - "integrity": "sha512-5kQZeTPCkegEcSooUu3W0BSOwvxEt1q6zjodwEOYoW/FxETC8Bk1zQF1QOPZLS+Nu3GLA+g1oPXMVBonM+CYQQ==", - "requires": { - "tslib": "^2.0.0" - } - }, "ngx-translate-testing": { "version": "6.1.0", "dev": true, diff --git a/package.json b/package.json index c9864dce..7d50472f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@onecx/onecx-portal-ui-libs", - "version": "4.12.1", + "version": "4.13.2", "license": "Apache-2.0", "scripts": { "sass": "npx sass libs/portal-integration-angular/assets/styles.scss libs/portal-integration-angular/assets/output.css", @@ -33,7 +33,6 @@ "keycloak-angular": "^13.0.0", "keycloak-js": "^18.0.0", "ngx-color": "^8.0.3", - "ngx-timeago": "^2.0.0", "primeflex": "^3.3.0", "primeicons": "^6.0.1", "primeng": "15.2.1", diff --git a/release.config.js b/release.config.js index 4341026e..bad72e69 100644 --- a/release.config.js +++ b/release.config.js @@ -26,7 +26,7 @@ module.exports = { [ '@semantic-release/exec', { - prepareCmd: `(VERSION=\${nextRelease.version} npx nx run-many -t release --verbose && VERSION=\${nextRelease.version} npx -p replace-json-property rjp ./package.json version \${nextRelease.version}) >> output.txt || cat output.txt`, + prepareCmd: `VERSION=\${nextRelease.version} npx nx run-many -t release --verbose && VERSION=\${nextRelease.version} npx -p replace-json-property rjp ./package.json version \${nextRelease.version}`, }, ], [