From 7a39d2e4aa44f39ade8cf8750e6433f459fea198 Mon Sep 17 00:00:00 2001 From: richard-loafle <44828666+richard-loafle@users.noreply.github.com> Date: Wed, 1 Apr 2020 17:18:28 +0900 Subject: [PATCH] bug fixed --- package-lock.json | 10 +-- package.json | 4 +- projects/i18n/package.json | 2 +- projects/i18n/src/lib/pipes/i18n.pipe.ts | 8 ++ projects/i18n/src/lib/utils/object.util.ts | 83 +++++++++++++++++++ projects/ui-authentication/package.json | 2 +- .../src/lib/authentication-ui.module.ts | 2 + .../src/lib/components/login.component.html | 35 ++------ .../src/lib/components/login.component.ts | 52 +++--------- 9 files changed, 120 insertions(+), 78 deletions(-) create mode 100644 projects/i18n/src/lib/utils/object.util.ts diff --git a/package-lock.json b/package-lock.json index 886844c..f77c624 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2272,8 +2272,9 @@ "dev": true }, "@ucap/ng-i18n": { - "version": "file:pack/ucap-ng-i18n-0.0.5.tgz", - "integrity": "sha512-P+MUurrVyLeRl4l7b4aLMG3/nPpZ54U1U2VQnAGb7OHNvZG/BJVzZqc2Z+YvnNXTe8PhMqkRfRysOZeu1AGj5A==" + "version": "file:pack/ucap-ng-i18n-0.0.6.tgz", + "integrity": "sha512-0vnoC3tAbXmcnsL1xy5Otswu75ZBht8wrI5Zz1mfSgYT/mnR9QoNkpCHiHfl/ILAJlKD0iBn+BBOrwTIprsJ/Q==", + "dev": true }, "@ucap/ng-logger": { "version": "file:pack/ucap-ng-logger-0.0.1.tgz", @@ -2401,9 +2402,8 @@ "dev": true }, "@ucap/ng-ui-authentication": { - "version": "file:pack/ucap-ng-ui-authentication-0.0.5.tgz", - "integrity": "sha512-NwsISychSVyCxVO3j13jNRtHbZpvKY2pb/WBATGPnkYrhaB4x7a+b4gXhWUCmO5QZoYrb2uBV4K9hXANr2Ergg==", - "dev": true + "version": "file:pack/ucap-ng-ui-authentication-0.0.8.tgz", + "integrity": "sha512-n6pV113DuSD5TV4jAwrY/JJlhcBtNLHEFTTxrQ8QhFIMz9hgbRC6x4R/LF8q9kzx0BWQcgxGdfgY1oN3YoqGtg==" }, "@ucap/ng-ui-organization": { "version": "file:pack/ucap-ng-ui-organization-0.0.1.tgz", diff --git a/package.json b/package.json index d14b70d..f059213 100644 --- a/package.json +++ b/package.json @@ -144,7 +144,7 @@ "@ucap/ng-api-prompt": "file:pack/ucap-ng-api-prompt-0.0.1.tgz", "@ucap/ng-api-public": "file:pack/ucap-ng-api-public-0.0.1.tgz", "@ucap/ng-core": "file:pack/ucap-ng-core-0.0.1.tgz", - "@ucap/ng-i18n": "file:pack/ucap-ng-i18n-0.0.5.tgz", + "@ucap/ng-i18n": "file:pack/ucap-ng-i18n-0.0.6.tgz", "@ucap/ng-logger": "file:pack/ucap-ng-logger-0.0.1.tgz", "@ucap/ng-native": "file:pack/ucap-ng-native-0.0.1.tgz", "@ucap/ng-native-browser": "file:pack/ucap-ng-native-browser-0.0.1.tgz", @@ -170,7 +170,7 @@ "@ucap/ng-store-group": "file:pack/ucap-ng-store-group-0.0.3.tgz", "@ucap/ng-store-organization": "file:pack/ucap-ng-store-organization-0.0.3.tgz", "@ucap/ng-ui": "file:pack/ucap-ng-ui-0.0.3.tgz", - "@ucap/ng-ui-authentication": "file:pack/ucap-ng-ui-authentication-0.0.5.tgz", + "@ucap/ng-ui-authentication": "file:pack/ucap-ng-ui-authentication-0.0.8.tgz", "@ucap/ng-ui-organization": "file:pack/ucap-ng-ui-organization-0.0.1.tgz", "@ucap/ng-ui-skin-default": "file:pack/ucap-ng-ui-skin-default-0.0.1.tgz", "@ucap/ng-web-storage": "file:pack/ucap-ng-web-storage-0.0.1.tgz", diff --git a/projects/i18n/package.json b/projects/i18n/package.json index 2e17658..12b2603 100644 --- a/projects/i18n/package.json +++ b/projects/i18n/package.json @@ -1,6 +1,6 @@ { "name": "@ucap/ng-i18n", - "version": "0.0.5", + "version": "0.0.6", "publishConfig": { "registry": "http://10.81.13.221:8081/nexus/repository/npm-ucap/" }, diff --git a/projects/i18n/src/lib/pipes/i18n.pipe.ts b/projects/i18n/src/lib/pipes/i18n.pipe.ts index 6fe9e01..5552c2f 100644 --- a/projects/i18n/src/lib/pipes/i18n.pipe.ts +++ b/projects/i18n/src/lib/pipes/i18n.pipe.ts @@ -13,6 +13,7 @@ import { StringMap, TOptions } from 'i18next'; import { I18nService } from '../services/i18n.service'; import { UCAP_I18N_NAMESPACE } from '../types/token'; +import { ObjectUtil } from '../utils/object.util'; @Pipe({ name: 'ucapI18n', pure: false }) export class I18nPipe implements PipeTransform, OnDestroy { @@ -36,6 +37,13 @@ export class I18nPipe implements PipeTransform, OnDestroy { key: string | string[], options?: TOptions ): string { + if ( + ObjectUtil.equals(key, this.lastKey) && + ObjectUtil.equals(options, this.lastOptions) + ) { + return this.value; + } + options = options || {}; if (!!this.ns) { diff --git a/projects/i18n/src/lib/utils/object.util.ts b/projects/i18n/src/lib/utils/object.util.ts new file mode 100644 index 0000000..ac3b91b --- /dev/null +++ b/projects/i18n/src/lib/utils/object.util.ts @@ -0,0 +1,83 @@ +export class ObjectUtil { + static equals(o1: any, o2: any): boolean { + if (o1 === o2) { + return true; + } + if (o1 === null || o2 === null) { + return false; + } + if (o1 !== o1 && o2 !== o2) { + return true; // NaN === NaN + } + + const t1 = typeof o1; + const t2 = typeof o2; + let length: number; + let key: any; + let keySet: any; + + if (t1 === t2 && t1 === 'object') { + if (Array.isArray(o1)) { + if (!Array.isArray(o2)) { + return false; + } + length = o1.length; + if (length === o2.length) { + for (key = 0; key < length; key++) { + if (!ObjectUtil.equals(o1[key], o2[key])) { + return false; + } + } + return true; + } + } else { + if (Array.isArray(o2)) { + return false; + } + keySet = Object.create(null); + for (key in o1) { + if (o1.hasOwnProperty(key)) { + if (!ObjectUtil.equals(o1[key], o2[key])) { + return false; + } + keySet[key] = true; + } + } + + for (key in o2) { + if (!(key in keySet) && typeof o2[key] !== 'undefined') { + return false; + } + } + return true; + } + } + return false; + } + + static isDefined(value: any): boolean { + return typeof value !== 'undefined' && value !== null; + } + + static isObject(item: any): boolean { + return item && typeof item === 'object' && !Array.isArray(item); + } + + static mergeDeep(target: any, source: any): any { + const output = Object.assign({}, target); + if (ObjectUtil.isObject(target) && ObjectUtil.isObject(source)) { + Object.keys(source).forEach((key: any) => { + if (ObjectUtil.isObject(source[key])) { + if (!(key in target)) { + Object.assign(output, { [key]: source[key] }); + } else { + output[key] = ObjectUtil.mergeDeep(target[key], source[key]); + } + } else { + Object.assign(output, { [key]: source[key] }); + } + }); + } + return output; + } +} diff --git a/projects/ui-authentication/package.json b/projects/ui-authentication/package.json index e4b4a11..5b52fd3 100644 --- a/projects/ui-authentication/package.json +++ b/projects/ui-authentication/package.json @@ -1,6 +1,6 @@ { "name": "@ucap/ng-ui-authentication", - "version": "0.0.5", + "version": "0.0.8", "publishConfig": { "registry": "http://10.81.13.221:8081/nexus/repository/npm-ucap/" }, diff --git a/projects/ui-authentication/src/lib/authentication-ui.module.ts b/projects/ui-authentication/src/lib/authentication-ui.module.ts index 795d687..7e96d21 100644 --- a/projects/ui-authentication/src/lib/authentication-ui.module.ts +++ b/projects/ui-authentication/src/lib/authentication-ui.module.ts @@ -9,6 +9,7 @@ import { MatCheckboxModule } from '@angular/material/checkbox'; import { MatFormFieldModule } from '@angular/material/form-field'; import { MatIconModule } from '@angular/material/icon'; import { MatInputModule } from '@angular/material/input'; +import { MatProgressSpinnerModule } from '@angular/material/progress-spinner'; import { MatSelectModule } from '@angular/material/select'; import { UiModule } from '@ucap/ng-ui'; @@ -46,6 +47,7 @@ export class AuthenticationUiRootModule {} MatFormFieldModule, MatIconModule, MatInputModule, + MatProgressSpinnerModule, MatSelectModule, I18nModule, diff --git a/projects/ui-authentication/src/lib/components/login.component.html b/projects/ui-authentication/src/lib/components/login.component.html index a27dfae..b41c02d 100644 --- a/projects/ui-authentication/src/lib/components/login.component.html +++ b/projects/ui-authentication/src/lib/components/login.component.html @@ -3,7 +3,7 @@