From 45ebb59a4908ef8db9e454da7ef4cae285a41845 Mon Sep 17 00:00:00 2001 From: mehmet-erim Date: Wed, 2 Oct 2019 13:59:33 +0300 Subject: [PATCH] fix: some bugs --- .../application-configuration.service.ts | 3 +- .../src/lib/services/localization.service.ts | 13 +++---- .../core/src/lib/services/rest.service.ts | 7 ++-- .../core/src/lib/states/config.state.ts | 35 ++++++++++--------- .../core/src/lib/utils/initial-utils.ts | 3 +- .../setting-management.component.html | 3 -- .../setting-management.component.ts | 6 ++-- 7 files changed, 32 insertions(+), 38 deletions(-) diff --git a/npm/ng-packs/packages/core/src/lib/services/application-configuration.service.ts b/npm/ng-packs/packages/core/src/lib/services/application-configuration.service.ts index d0a653e1e0..5081f94068 100644 --- a/npm/ng-packs/packages/core/src/lib/services/application-configuration.service.ts +++ b/npm/ng-packs/packages/core/src/lib/services/application-configuration.service.ts @@ -1,6 +1,7 @@ import { Injectable } from '@angular/core'; import { Observable } from 'rxjs'; -import { ApplicationConfiguration, Rest } from '../models'; +import { Rest } from '../models/rest'; +import { ApplicationConfiguration } from '../models/application-configuration'; import { RestService } from './rest.service'; @Injectable({ diff --git a/npm/ng-packs/packages/core/src/lib/services/localization.service.ts b/npm/ng-packs/packages/core/src/lib/services/localization.service.ts index 2af99ee227..a26f1af06f 100644 --- a/npm/ng-packs/packages/core/src/lib/services/localization.service.ts +++ b/npm/ng-packs/packages/core/src/lib/services/localization.service.ts @@ -1,9 +1,7 @@ -import { Injectable, Optional, SkipSelf, NgZone } from '@angular/core'; +import { Injectable, NgZone, Optional, SkipSelf } from '@angular/core'; import { ActivatedRouteSnapshot, Router } from '@angular/router'; -import { Actions, Store } from '@ngxs/store'; +import { Store } from '@ngxs/store'; import { noop, Observable } from 'rxjs'; -import { ConfigState } from '../states/config.state'; -import { SessionState } from '../states/session.state'; import { registerLocale } from '../utils/initial-utils'; type ShouldReuseRoute = (future: ActivatedRouteSnapshot, curr: ActivatedRouteSnapshot) => boolean; @@ -11,14 +9,13 @@ type ShouldReuseRoute = (future: ActivatedRouteSnapshot, curr: ActivatedRouteSna @Injectable({ providedIn: 'root' }) export class LocalizationService { get currentLang(): string { - return this.store.selectSnapshot(SessionState.getLanguage); + return this.store.selectSnapshot(state => state.SessionState.getLanguage); } constructor( private store: Store, private router: Router, private ngZone: NgZone, - private actions: Actions, @Optional() @SkipSelf() otherInstance: LocalizationService, @@ -45,10 +42,10 @@ export class LocalizationService { } get(keys: string, ...interpolateParams: string[]): Observable { - return this.store.select(ConfigState.getCopy(keys, ...interpolateParams)); + return this.store.select(state => state.ConfigState.getCopy(keys, ...interpolateParams)); } instant(keys: string, ...interpolateParams: string[]): string { - return this.store.selectSnapshot(ConfigState.getCopy(keys, ...interpolateParams)); + return this.store.selectSnapshot(state => state.ConfigState.getCopy(keys, ...interpolateParams)); } } diff --git a/npm/ng-packs/packages/core/src/lib/services/rest.service.ts b/npm/ng-packs/packages/core/src/lib/services/rest.service.ts index 7ff1a42af0..5f402f896b 100644 --- a/npm/ng-packs/packages/core/src/lib/services/rest.service.ts +++ b/npm/ng-packs/packages/core/src/lib/services/rest.service.ts @@ -1,11 +1,10 @@ import { HttpClient, HttpRequest } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { Store } from '@ngxs/store'; -import { NEVER, Observable, throwError } from 'rxjs'; +import { Observable, throwError } from 'rxjs'; import { catchError, take } from 'rxjs/operators'; +import { RestOccurError } from '../actions/rest.actions'; import { Rest } from '../models/rest'; -import { ConfigState } from '../states'; -import { RestOccurError } from '../actions'; @Injectable({ providedIn: 'root', @@ -21,7 +20,7 @@ export class RestService { request(request: HttpRequest | Rest.Request, config: Rest.Config = {}, api?: string): Observable { const { observe = Rest.Observe.Body, skipHandleError } = config; - const url = api || this.store.selectSnapshot(ConfigState.getApiUrl()) + request.url; + const url = api || this.store.selectSnapshot(state => state.ConfigState).environment.apis.default.url + request.url; const { method, ...options } = request; return this.http.request(method, url, { observe, ...options } as any).pipe( observe === Rest.Observe.Body ? take(1) : null, diff --git a/npm/ng-packs/packages/core/src/lib/states/config.state.ts b/npm/ng-packs/packages/core/src/lib/states/config.state.ts index 4f43a0bf65..29799a502b 100644 --- a/npm/ng-packs/packages/core/src/lib/states/config.state.ts +++ b/npm/ng-packs/packages/core/src/lib/states/config.state.ts @@ -1,17 +1,18 @@ import { State, Selector, createSelector, Action, StateContext, Store } from '@ngxs/store'; -import { Config, ABP } from '../models'; +import { Config } from '../models/config'; +import { ABP } from '../models/common'; import { GetAppConfiguration, PatchRouteByName } from '../actions/config.actions'; import { ApplicationConfigurationService } from '../services/application-configuration.service'; import { tap, switchMap } from 'rxjs/operators'; import snq from 'snq'; -import { SetLanguage } from '../actions'; +import { SetLanguage } from '../actions/session.actions'; import { SessionState } from './session.state'; import { of } from 'rxjs'; import { setChildRoute, sortRoutes, organizeRoutes } from '../utils/route-utils'; @State({ name: 'ConfigState', - defaults: {} as Config.State + defaults: {} as Config.State, }) export class ConfigState { @Selector() @@ -29,7 +30,7 @@ export class ConfigState { [ConfigState], (state: Config.State) => { return state[key]; - } + }, ); return selector; @@ -54,7 +55,7 @@ export class ConfigState { return undefined; }, state); - } + }, ); return selector; @@ -72,7 +73,7 @@ export class ConfigState { return route; } }); - } + }, ); return selector; @@ -83,7 +84,7 @@ export class ConfigState { [ConfigState], (state: Config.State): string => { return state.environment.apis[key || 'default'].url; - } + }, ); return selector; @@ -94,7 +95,7 @@ export class ConfigState { [ConfigState], (state: Config.State) => { return snq(() => state.setting.values[key]); - } + }, ); return selector; @@ -106,7 +107,7 @@ export class ConfigState { (state: Config.State): boolean => { if (!key) return true; return snq(() => state.auth.grantedPolicies[key], false); - } + }, ); return selector; @@ -131,7 +132,7 @@ export class ConfigState { localization: { defaultResourceName: 'MyProjectName' } - }` + }`, ); } @@ -154,7 +155,7 @@ export class ConfigState { } return copy || key; - } + }, ); return selector; @@ -167,8 +168,8 @@ export class ConfigState { return this.appConfigurationService.getConfiguration().pipe( tap(configuration => patchState({ - ...configuration - }) + ...configuration, + }), ), switchMap(configuration => { let defaultLang: string = configuration.setting.values['Abp.Localization.DefaultLanguage']; @@ -178,7 +179,7 @@ export class ConfigState { } return this.store.selectSnapshot(SessionState.getLanguage) ? of(null) : dispatch(new SetLanguage(defaultLang)); - }) + }), ); } @@ -191,7 +192,7 @@ export class ConfigState { routes = patchRouteDeep(routes, name, newValue); return patchState({ - routes + routes, }); } } @@ -200,7 +201,7 @@ function patchRouteDeep( routes: ABP.FullRoute[], name: string, newValue: Partial, - parentUrl: string = null + parentUrl: string = null, ): ABP.FullRoute[] { routes = routes.map(route => { if (route.name === name) { @@ -211,7 +212,7 @@ function patchRouteDeep( if (newValue.children && newValue.children.length) { newValue.children = newValue.children.map(child => ({ ...child, - url: `${parentUrl}/${route.path}/${child.path}` + url: `${parentUrl}/${route.path}/${child.path}`, })); } diff --git a/npm/ng-packs/packages/core/src/lib/utils/initial-utils.ts b/npm/ng-packs/packages/core/src/lib/utils/initial-utils.ts index dc4ae36065..d1e703165e 100644 --- a/npm/ng-packs/packages/core/src/lib/utils/initial-utils.ts +++ b/npm/ng-packs/packages/core/src/lib/utils/initial-utils.ts @@ -3,7 +3,6 @@ import { Injector } from '@angular/core'; import { Store } from '@ngxs/store'; import { GetAppConfiguration } from '../actions/config.actions'; import differentLocales from '../constants/different-locales'; -import { SessionState } from '../states/session.state'; export function getInitialData(injector: Injector) { const fn = () => { @@ -19,7 +18,7 @@ export function localeInitializer(injector: Injector) { const fn = () => { const store: Store = injector.get(Store); - const lang = store.selectSnapshot(SessionState.getLanguage) || 'en'; + const lang = store.selectSnapshot(state => state.SessionState.getLanguage) || 'en'; return new Promise((resolve, reject) => { registerLocale(lang).then(() => resolve(), reject); diff --git a/npm/ng-packs/packages/setting-management/src/lib/components/setting-management.component.html b/npm/ng-packs/packages/setting-management/src/lib/components/setting-management.component.html index 030a020418..58659ff50b 100644 --- a/npm/ng-packs/packages/setting-management/src/lib/components/setting-management.component.html +++ b/npm/ng-packs/packages/setting-management/src/lib/components/setting-management.component.html @@ -13,9 +13,6 @@
-
- -