Browse Source

fix: circular dependency warnings

pull/3821/head
mehmet-erim 7 years ago
parent
commit
43e9cd2977
  1. 12
      npm/ng-packs/packages/core/src/lib/services/localization.service.ts
  2. 56
      npm/ng-packs/packages/core/src/lib/states/config.state.ts
  3. 29
      npm/ng-packs/packages/core/src/lib/states/session.state.ts
  4. 4
      npm/ng-packs/packages/theme-shared/src/lib/components/confirmation/confirmation.component.html
  5. 16
      npm/ng-packs/packages/theme-shared/src/lib/components/confirmation/confirmation.component.ts
  6. 10
      npm/ng-packs/packages/theme-shared/src/lib/components/toast-container/toast-container.component.ts
  7. 17
      npm/ng-packs/packages/theme-shared/src/lib/services/confirmation.service.ts
  8. 2
      npm/ng-packs/packages/theme-shared/src/lib/services/toaster.service.ts
  9. 8
      npm/ng-packs/packages/theme-shared/src/lib/theme-shared.module.ts

12
npm/ng-packs/packages/core/src/lib/services/localization.service.ts

@ -1,10 +1,11 @@
import { Injectable, NgZone, Optional, SkipSelf } from '@angular/core'; import { Injectable, NgZone, Optional, SkipSelf } from '@angular/core';
import { ActivatedRouteSnapshot, Router } from '@angular/router'; import { ActivatedRouteSnapshot, Router } from '@angular/router';
import { Store } from '@ngxs/store'; import { Store, Actions, ofActionSuccessful } from '@ngxs/store';
import { noop, Observable } from 'rxjs'; import { noop, Observable } from 'rxjs';
import { ConfigState } from '../states/config.state'; import { ConfigState } from '../states/config.state';
import { registerLocale } from '../utils/initial-utils'; import { registerLocale } from '../utils/initial-utils';
import { Config } from '../models/config'; import { Config } from '../models/config';
import { SetLanguage } from '../actions/session.actions';
type ShouldReuseRoute = (future: ActivatedRouteSnapshot, curr: ActivatedRouteSnapshot) => boolean; type ShouldReuseRoute = (future: ActivatedRouteSnapshot, curr: ActivatedRouteSnapshot) => boolean;
@ -18,6 +19,7 @@ export class LocalizationService {
} }
constructor( constructor(
private actions: Actions,
private store: Store, private store: Store,
private router: Router, private router: Router,
private ngZone: NgZone, private ngZone: NgZone,
@ -26,6 +28,14 @@ export class LocalizationService {
otherInstance: LocalizationService, otherInstance: LocalizationService,
) { ) {
if (otherInstance) throw new Error('LocalizationService should have only one instance.'); if (otherInstance) throw new Error('LocalizationService should have only one instance.');
this.listenToSetLanguage();
}
private listenToSetLanguage() {
this.actions
.pipe(ofActionSuccessful(SetLanguage))
.subscribe(({ payload }) => this.registerLocale(payload));
} }
setRouteReuse(reuse: ShouldReuseRoute) { setRouteReuse(reuse: ShouldReuseRoute) {

56
npm/ng-packs/packages/core/src/lib/states/config.state.ts

@ -1,7 +1,8 @@
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { Action, createSelector, Selector, State, StateContext, Store } from '@ngxs/store'; import { Action, createSelector, Selector, State, StateContext, Store } from '@ngxs/store';
import { of } from 'rxjs'; import { of, throwError } from 'rxjs';
import { switchMap, tap } from 'rxjs/operators'; import { catchError, switchMap, tap } from 'rxjs/operators';
import snq from 'snq'; import snq from 'snq';
import { import {
AddRoute, AddRoute,
@ -9,10 +10,11 @@ import {
PatchRouteByName, PatchRouteByName,
SetEnvironment, SetEnvironment,
} from '../actions/config.actions'; } from '../actions/config.actions';
import { RestOccurError } from '../actions/rest.actions';
import { SetLanguage } from '../actions/session.actions'; import { SetLanguage } from '../actions/session.actions';
import { ApplicationConfiguration } from '../models/application-configuration';
import { ABP } from '../models/common'; import { ABP } from '../models/common';
import { Config } from '../models/config'; import { Config } from '../models/config';
import { ApplicationConfigurationService } from '../services/application-configuration.service';
import { organizeRoutes } from '../utils/route-utils'; import { organizeRoutes } from '../utils/route-utils';
import { SessionState } from './session.state'; import { SessionState } from './session.state';
@ -195,31 +197,37 @@ export class ConfigState {
return selector; return selector;
} }
constructor( constructor(private http: HttpClient, private store: Store) {}
private appConfigurationService: ApplicationConfigurationService,
private store: Store,
) {}
@Action(GetAppConfiguration) @Action(GetAppConfiguration)
addData({ patchState, dispatch }: StateContext<Config.State>) { addData({ patchState, dispatch }: StateContext<Config.State>) {
return this.appConfigurationService.getConfiguration().pipe( const apiName = this.store.selectSnapshot(ConfigState.getDeep('environment.application.name'));
tap(configuration => const api = this.store.selectSnapshot(ConfigState.getApiUrl(apiName));
patchState({ return this.http
...configuration, .get<ApplicationConfiguration.Response>(`${api}/api/abp/application-configuration`)
.pipe(
tap(configuration =>
patchState({
...configuration,
}),
),
switchMap(configuration => {
let defaultLang: string =
configuration.setting.values['Abp.Localization.DefaultLanguage'];
if (defaultLang.includes(';')) {
defaultLang = defaultLang.split(';')[0];
}
return this.store.selectSnapshot(SessionState.getLanguage)
? of(null)
: dispatch(new SetLanguage(defaultLang));
}), }),
), catchError(err => {
switchMap(configuration => { dispatch(new RestOccurError(new HttpErrorResponse({ status: 0, error: err })));
let defaultLang: string = configuration.setting.values['Abp.Localization.DefaultLanguage']; return throwError(err);
}),
if (defaultLang.includes(';')) { );
defaultLang = defaultLang.split(';')[0];
}
return this.store.selectSnapshot(SessionState.getLanguage)
? of(null)
: dispatch(new SetLanguage(defaultLang));
}),
);
} }
@Action(PatchRouteByName) @Action(PatchRouteByName)

29
npm/ng-packs/packages/core/src/lib/states/session.state.ts

@ -1,26 +1,24 @@
import { Injectable } from '@angular/core';
import { import {
Action, Action,
Actions,
ofActionSuccessful,
Selector, Selector,
State, State,
StateContext, StateContext,
Store, Store,
NgxsOnInit,
Actions,
ofActionSuccessful,
} from '@ngxs/store'; } from '@ngxs/store';
import { from, fromEvent } from 'rxjs'; import { OAuthService } from 'angular-oauth2-oidc';
import { switchMap, take } from 'rxjs/operators'; import { fromEvent } from 'rxjs';
import { take } from 'rxjs/operators';
import { GetAppConfiguration } from '../actions/config.actions'; import { GetAppConfiguration } from '../actions/config.actions';
import { import {
SetLanguage,
SetTenant,
ModifyOpenedTabCount, ModifyOpenedTabCount,
SetLanguage,
SetRemember, SetRemember,
SetTenant,
} from '../actions/session.actions'; } from '../actions/session.actions';
import { ABP, Session } from '../models'; import { ABP, Session } from '../models';
import { LocalizationService } from '../services/localization.service';
import { OAuthService } from 'angular-oauth2-oidc';
import { Injectable } from '@angular/core';
@State<Session.State>({ @State<Session.State>({
name: 'SessionState', name: 'SessionState',
@ -43,12 +41,7 @@ export class SessionState {
return sessionDetail; return sessionDetail;
} }
constructor( constructor(private oAuthService: OAuthService, private store: Store, private actions: Actions) {
private localizationService: LocalizationService,
private oAuthService: OAuthService,
private store: Store,
private actions: Actions,
) {
actions actions
.pipe(ofActionSuccessful(GetAppConfiguration)) .pipe(ofActionSuccessful(GetAppConfiguration))
.pipe(take(1)) .pipe(take(1))
@ -81,9 +74,7 @@ export class SessionState {
language: payload, language: payload,
}); });
return dispatch(new GetAppConfiguration()).pipe( return dispatch(new GetAppConfiguration());
switchMap(() => from(this.localizationService.registerLocale(payload))),
);
} }
@Action(SetTenant) @Action(SetTenant)

4
npm/ng-packs/packages/theme-shared/src/lib/components/confirmation/confirmation.component.html

@ -20,14 +20,14 @@
<button <button
id="cancel" id="cancel"
class="confirmation-button confirmation-button--reject" class="confirmation-button confirmation-button--reject"
[innerHTML]="data.options?.cancelText || 'AbpUi::Cancel'" [innerHTML]="data.options?.cancelText || 'AbpUi::Cancel' | abpLocalization"
*ngIf="!data?.options?.hideCancelBtn" *ngIf="!data?.options?.hideCancelBtn"
(click)="close(reject)" (click)="close(reject)"
></button> ></button>
<button <button
id="confirm" id="confirm"
class="confirmation-button confirmation-button--approve" class="confirmation-button confirmation-button--approve"
[innerHTML]="data.options?.yesText || 'AbpUi::Yes'" [innerHTML]="data.options?.yesText || 'AbpUi::Yes' | abpLocalization"
*ngIf="!data?.options?.hideYesBtn" *ngIf="!data?.options?.hideYesBtn"
(click)="close(confirm)" (click)="close(confirm)"
></button> ></button>

16
npm/ng-packs/packages/theme-shared/src/lib/components/confirmation/confirmation.component.ts

@ -1,13 +1,13 @@
import { Component } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { ReplaySubject } from 'rxjs';
import { Confirmation } from '../../models/confirmation'; import { Confirmation } from '../../models/confirmation';
import { ConfirmationService } from '../../services/confirmation.service';
@Component({ @Component({
selector: 'abp-confirmation', selector: 'abp-confirmation',
templateUrl: './confirmation.component.html', templateUrl: './confirmation.component.html',
styleUrls: ['./confirmation.component.scss'], styleUrls: ['./confirmation.component.scss'],
}) })
export class ConfirmationComponent { export class ConfirmationComponent implements OnInit {
confirm = Confirmation.Status.confirm; confirm = Confirmation.Status.confirm;
reject = Confirmation.Status.reject; reject = Confirmation.Status.reject;
dismiss = Confirmation.Status.dismiss; dismiss = Confirmation.Status.dismiss;
@ -16,6 +16,10 @@ export class ConfirmationComponent {
data: Confirmation.DialogData; data: Confirmation.DialogData;
confirmation$: ReplaySubject<Confirmation.DialogData>;
clear: (status: Confirmation.Status) => void;
get iconClass(): string { get iconClass(): string {
switch (this.data.severity) { switch (this.data.severity) {
case 'info': case 'info':
@ -31,14 +35,14 @@ export class ConfirmationComponent {
} }
} }
constructor(private confirmationService: ConfirmationService) { ngOnInit() {
this.confirmationService.confirmation$.subscribe(confirmation => { this.confirmation$.subscribe(confirmation => {
this.data = confirmation; this.data = confirmation;
this.visible = !!confirmation; this.visible = !!confirmation;
}); });
} }
close(status: Confirmation.Status) { close(status: Confirmation.Status) {
this.confirmationService.clear(status); this.clear(status);
} }
} }

10
npm/ng-packs/packages/theme-shared/src/lib/components/toast-container/toast-container.component.ts

@ -1,7 +1,7 @@
import { Component, Input, OnInit } from '@angular/core'; import { Component, Input, OnInit } from '@angular/core';
import { Toaster } from '../../models/toaster';
import { toastInOut } from '../../animations/toast.animations'; import { toastInOut } from '../../animations/toast.animations';
import { ToasterService } from '../../services/toaster.service'; import { Toaster } from '../../models/toaster';
import { ReplaySubject } from 'rxjs';
@Component({ @Component({
selector: 'abp-toast-container', selector: 'abp-toast-container',
@ -10,6 +10,8 @@ import { ToasterService } from '../../services/toaster.service';
animations: [toastInOut], animations: [toastInOut],
}) })
export class ToastContainerComponent implements OnInit { export class ToastContainerComponent implements OnInit {
toasts$: ReplaySubject<Toaster.Toast[]>;
toasts = [] as Toaster.Toast[]; toasts = [] as Toaster.Toast[];
@Input() @Input()
@ -27,10 +29,8 @@ export class ToastContainerComponent implements OnInit {
@Input() @Input()
toastKey: string; toastKey: string;
constructor(private toastService: ToasterService) {}
ngOnInit() { ngOnInit() {
this.toastService.toasts$.subscribe(toasts => { this.toasts$.subscribe(toasts => {
this.toasts = this.toastKey this.toasts = this.toastKey
? toasts.filter(t => { ? toasts.filter(t => {
return t.options && t.options.containerKey !== this.toastKey; return t.options && t.options.containerKey !== this.toastKey;

17
npm/ng-packs/packages/theme-shared/src/lib/services/confirmation.service.ts

@ -15,13 +15,14 @@ export class ConfirmationService {
constructor(private contentProjectionService: ContentProjectionService) {} constructor(private contentProjectionService: ContentProjectionService) {}
private setContainer() { private setContainer() {
setTimeout(() => { this.containerComponentRef = this.contentProjectionService.projectContent(
this.containerComponentRef = this.contentProjectionService.projectContent( PROJECTION_STRATEGY.AppendComponentToBody(ConfirmationComponent, {
PROJECTION_STRATEGY.AppendComponentToBody(ConfirmationComponent), confirmation$: this.confirmation$,
); clear: this.clear,
}),
);
this.containerComponentRef.changeDetectorRef.detectChanges(); this.containerComponentRef.changeDetectorRef.detectChanges();
}, 0);
} }
info( info(
@ -75,10 +76,10 @@ export class ConfirmationService {
return this.status$; return this.status$;
} }
clear(status: Confirmation.Status = Confirmation.Status.dismiss) { clear = (status: Confirmation.Status = Confirmation.Status.dismiss) => {
this.confirmation$.next(); this.confirmation$.next();
this.status$.next(status); this.status$.next(status);
} };
private listenToEscape() { private listenToEscape() {
fromEvent(document, 'keyup') fromEvent(document, 'keyup')

2
npm/ng-packs/packages/theme-shared/src/lib/services/toaster.service.ts

@ -21,7 +21,7 @@ export class ToasterService {
private setContainer() { private setContainer() {
this.containerComponentRef = this.contentProjectionService.projectContent( this.containerComponentRef = this.contentProjectionService.projectContent(
PROJECTION_STRATEGY.AppendComponentToBody(ToastContainerComponent), PROJECTION_STRATEGY.AppendComponentToBody(ToastContainerComponent, { toasts$: this.toasts$ }),
); );
this.containerComponentRef.changeDetectorRef.detectChanges(); this.containerComponentRef.changeDetectorRef.detectChanges();

8
npm/ng-packs/packages/theme-shared/src/lib/theme-shared.module.ts

@ -92,8 +92,6 @@ export function appendScript(injector: Injector) {
], ],
}) })
export class ThemeSharedModule { export class ThemeSharedModule {
constructor(private errorHandler: ErrorHandler) {}
static forRoot(options = {} as RootParams): ModuleWithProviders { static forRoot(options = {} as RootParams): ModuleWithProviders {
return { return {
ngModule: ThemeSharedModule, ngModule: ThemeSharedModule,
@ -104,6 +102,12 @@ export class ThemeSharedModule {
deps: [THEME_SHARED_APPEND_CONTENT], deps: [THEME_SHARED_APPEND_CONTENT],
useFactory: noop, useFactory: noop,
}, },
{
provide: APP_INITIALIZER,
multi: true,
deps: [ErrorHandler],
useFactory: noop,
},
{ provide: HTTP_ERROR_CONFIG, useValue: options.httpErrorConfig }, { provide: HTTP_ERROR_CONFIG, useValue: options.httpErrorConfig },
{ {
provide: 'HTTP_ERROR_CONFIG', provide: 'HTTP_ERROR_CONFIG',

Loading…
Cancel
Save