Browse Source

fix: some bugs

pull/1834/head
mehmet-erim 6 years ago
parent
commit
45ebb59a49
  1. 3
      npm/ng-packs/packages/core/src/lib/services/application-configuration.service.ts
  2. 13
      npm/ng-packs/packages/core/src/lib/services/localization.service.ts
  3. 7
      npm/ng-packs/packages/core/src/lib/services/rest.service.ts
  4. 35
      npm/ng-packs/packages/core/src/lib/states/config.state.ts
  5. 3
      npm/ng-packs/packages/core/src/lib/utils/initial-utils.ts
  6. 3
      npm/ng-packs/packages/setting-management/src/lib/components/setting-management.component.html
  7. 6
      npm/ng-packs/packages/setting-management/src/lib/components/setting-management.component.ts

3
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({

13
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<string> {
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));
}
}

7
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<T, R>(request: HttpRequest<T> | Rest.Request<T>, config: Rest.Config = {}, api?: string): Observable<R> {
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<T>(method, url, { observe, ...options } as any).pipe(
observe === Rest.Observe.Body ? take(1) : null,

35
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<Config.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<ABP.FullRoute>,
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}`,
}));
}

3
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);

3
npm/ng-packs/packages/setting-management/src/lib/components/setting-management.component.html

@ -13,9 +13,6 @@
<div id="SettingManagementWrapper">
<div class="card">
<div class="card-body">
<div *ngIf="!settings.length" class="text-center">
<i class="fa fa-spinner fa-spin"></i>
</div>
<div class="row">
<div class="col-3">
<ul class="nav flex-column nav-pills" id="nav-tab" role="tablist">

6
npm/ng-packs/packages/setting-management/src/lib/components/setting-management.component.ts

@ -18,10 +18,10 @@ export class SettingManagementComponent implements OnInit {
constructor(private router: Router, private store: Store) {}
ngOnInit() {
this.settings = SETTING_TABS.filter(setting =>
this.store.selectSnapshot(ConfigState.getGrantedPolicy(setting.requiredPolicy)),
).sort((a, b) => a.order - b.order);
if (this.settings.length) {
this.settings = SETTING_TABS.filter(setting =>
this.store.selectSnapshot(ConfigState.getGrantedPolicy(setting.requiredPolicy)),
).sort((a, b) => a.order - b.order);
this.selected = this.settings[0];
}
}

Loading…
Cancel
Save