Browse Source

refactor(core): rename actions and service functions

pull/1612/head
TheDiaval 7 years ago
parent
commit
33a450bb62
  1. 2
      npm/ng-packs/packages/core/src/lib/actions/config.actions.ts
  2. 4
      npm/ng-packs/packages/core/src/lib/actions/loader.actions.ts
  3. 6
      npm/ng-packs/packages/core/src/lib/actions/profile.actions.ts
  4. 4
      npm/ng-packs/packages/core/src/lib/actions/session.actions.ts
  5. 6
      npm/ng-packs/packages/core/src/lib/interceptors/api.interceptor.ts
  6. 10
      npm/ng-packs/packages/core/src/lib/states/config.state.ts
  7. 12
      npm/ng-packs/packages/core/src/lib/states/profile.state.ts
  8. 10
      npm/ng-packs/packages/core/src/lib/states/session.state.ts
  9. 4
      npm/ng-packs/packages/core/src/lib/utils/initial-utils.ts

2
npm/ng-packs/packages/core/src/lib/actions/config.actions.ts

@ -5,6 +5,6 @@ export class PatchRouteByName {
constructor(public name: string, public newValue: Partial<ABP.Route>) {} constructor(public name: string, public newValue: Partial<ABP.Route>) {}
} }
export class ConfigGetAppConfiguration { export class GetAppConfiguration {
static readonly type = '[Config] Get App Configuration'; static readonly type = '[Config] Get App Configuration';
} }

4
npm/ng-packs/packages/core/src/lib/actions/loader.actions.ts

@ -1,11 +1,11 @@
import { HttpRequest } from '@angular/common/http'; import { HttpRequest } from '@angular/common/http';
export class LoaderStart { export class StartLoader {
static readonly type = '[Loader] Start'; static readonly type = '[Loader] Start';
constructor(public payload: HttpRequest<any>) {} constructor(public payload: HttpRequest<any>) {}
} }
export class LoaderStop { export class StopLoader {
static readonly type = '[Loader] Stop'; static readonly type = '[Loader] Stop';
constructor(public payload: HttpRequest<any>) {} constructor(public payload: HttpRequest<any>) {}
} }

6
npm/ng-packs/packages/core/src/lib/actions/profile.actions.ts

@ -1,15 +1,15 @@
import { Profile } from '../models'; import { Profile } from '../models';
export class ProfileGet { export class GetProfile {
static readonly type = '[Profile] Get'; static readonly type = '[Profile] Get';
} }
export class ProfileUpdate { export class UpdateProfile {
static readonly type = '[Profile] Update'; static readonly type = '[Profile] Update';
constructor(public payload: Profile.Response) {} constructor(public payload: Profile.Response) {}
} }
export class ProfileChangePassword { export class ChangePassword {
static readonly type = '[Profile] Change Password'; static readonly type = '[Profile] Change Password';
constructor(public payload: Profile.ChangePasswordRequest) {} constructor(public payload: Profile.ChangePasswordRequest) {}
} }

4
npm/ng-packs/packages/core/src/lib/actions/session.actions.ts

@ -1,10 +1,10 @@
import { ABP } from '../models'; import { ABP } from '../models';
export class SessionSetLanguage { export class SetLanguage {
static readonly type = '[Session] Set Language'; static readonly type = '[Session] Set Language';
constructor(public payload: string) {} constructor(public payload: string) {}
} }
export class SessionSetTenant { export class SetTenant {
static readonly type = '[Session] Set Tenant'; static readonly type = '[Session] Set Tenant';
constructor(public payload: ABP.BasicItem) {} constructor(public payload: ABP.BasicItem) {}
} }

6
npm/ng-packs/packages/core/src/lib/interceptors/api.interceptor.ts

@ -3,7 +3,7 @@ import { HttpInterceptor, HttpHandler, HttpRequest } from '@angular/common/http'
import { OAuthService } from 'angular-oauth2-oidc'; import { OAuthService } from 'angular-oauth2-oidc';
import { Store } from '@ngxs/store'; import { Store } from '@ngxs/store';
import { SessionState } from '../states'; import { SessionState } from '../states';
import { LoaderStart, LoaderStop } from '../actions/loader.actions'; import { StartLoader, StopLoader } from '../actions/loader.actions';
import { finalize } from 'rxjs/operators'; import { finalize } from 'rxjs/operators';
@Injectable() @Injectable()
@ -11,7 +11,7 @@ export class ApiInterceptor implements HttpInterceptor {
constructor(private oAuthService: OAuthService, private store: Store) {} constructor(private oAuthService: OAuthService, private store: Store) {}
intercept(request: HttpRequest<any>, next: HttpHandler) { intercept(request: HttpRequest<any>, next: HttpHandler) {
this.store.dispatch(new LoaderStart(request)); this.store.dispatch(new StartLoader(request));
const headers = {} as any; const headers = {} as any;
@ -36,6 +36,6 @@ export class ApiInterceptor implements HttpInterceptor {
setHeaders: headers, setHeaders: headers,
}), }),
) )
.pipe(finalize(() => this.store.dispatch(new LoaderStop(request)))); .pipe(finalize(() => this.store.dispatch(new StopLoader(request))));
} }
} }

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

@ -1,10 +1,10 @@
import { State, Selector, createSelector, Action, StateContext, Store } from '@ngxs/store'; import { State, Selector, createSelector, Action, StateContext, Store } from '@ngxs/store';
import { Config, ABP } from '../models'; import { Config, ABP } from '../models';
import { ConfigGetAppConfiguration, PatchRouteByName } from '../actions/config.actions'; import { GetAppConfiguration, PatchRouteByName } from '../actions/config.actions';
import { ApplicationConfigurationService } from '../services/application-configuration.service'; import { ApplicationConfigurationService } from '../services/application-configuration.service';
import { tap, switchMap } from 'rxjs/operators'; import { tap, switchMap } from 'rxjs/operators';
import snq from 'snq'; import snq from 'snq';
import { SessionSetLanguage } from '../actions'; import { SetLanguage } from '../actions';
import { SessionState } from './session.state'; import { SessionState } from './session.state';
import { of } from 'rxjs'; import { of } from 'rxjs';
import { setChildRoute, sortRoutes, organizeRoutes } from '../utils/route-utils'; import { setChildRoute, sortRoutes, organizeRoutes } from '../utils/route-utils';
@ -161,7 +161,7 @@ export class ConfigState {
constructor(private appConfigurationService: ApplicationConfigurationService, private store: Store) {} constructor(private appConfigurationService: ApplicationConfigurationService, private store: Store) {}
@Action(ConfigGetAppConfiguration) @Action(GetAppConfiguration)
addData({ patchState, dispatch }: StateContext<Config.State>) { addData({ patchState, dispatch }: StateContext<Config.State>) {
return this.appConfigurationService.getConfiguration().pipe( return this.appConfigurationService.getConfiguration().pipe(
tap(configuration => tap(configuration =>
@ -172,9 +172,7 @@ export class ConfigState {
switchMap(configuration => switchMap(configuration =>
this.store.selectSnapshot(SessionState.getLanguage) this.store.selectSnapshot(SessionState.getLanguage)
? of(null) ? of(null)
: dispatch( : dispatch(new SetLanguage(snq(() => configuration.setting.values['Abp.Localization.DefaultLanguage']))),
new SessionSetLanguage(snq(() => configuration.setting.values['Abp.Localization.DefaultLanguage'])),
),
), ),
); );
} }

12
npm/ng-packs/packages/core/src/lib/states/profile.state.ts

@ -1,5 +1,5 @@
import { State, Action, StateContext, Selector } from '@ngxs/store'; import { State, Action, StateContext, Selector } from '@ngxs/store';
import { ProfileGet, ProfileChangePassword, ProfileUpdate } from '../actions/profile.actions'; import { GetProfile, ChangePassword, UpdateProfile } from '../actions/profile.actions';
import { Profile } from '../models/profile'; import { Profile } from '../models/profile';
import { ProfileService } from '../services/profile.service'; import { ProfileService } from '../services/profile.service';
import { tap } from 'rxjs/operators'; import { tap } from 'rxjs/operators';
@ -16,7 +16,7 @@ export class ProfileState {
constructor(private profileService: ProfileService) {} constructor(private profileService: ProfileService) {}
@Action(ProfileGet) @Action(GetProfile)
profileGet({ patchState }: StateContext<Profile.State>) { profileGet({ patchState }: StateContext<Profile.State>) {
return this.profileService.get().pipe( return this.profileService.get().pipe(
tap(profile => tap(profile =>
@ -27,8 +27,8 @@ export class ProfileState {
); );
} }
@Action(ProfileUpdate) @Action(UpdateProfile)
profileUpdate({ patchState }: StateContext<Profile.State>, { payload }: ProfileUpdate) { profileUpdate({ patchState }: StateContext<Profile.State>, { payload }: UpdateProfile) {
return this.profileService.update(payload).pipe( return this.profileService.update(payload).pipe(
tap(profile => tap(profile =>
patchState({ patchState({
@ -38,8 +38,8 @@ export class ProfileState {
); );
} }
@Action(ProfileChangePassword) @Action(ChangePassword)
changePassword(_, { payload }: ProfileChangePassword) { changePassword(_, { payload }: ChangePassword) {
return this.profileService.changePassword(payload, true); return this.profileService.changePassword(payload, true);
} }
} }

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

@ -1,5 +1,5 @@
import { Action, Selector, State, StateContext } from '@ngxs/store'; import { Action, Selector, State, StateContext } from '@ngxs/store';
import { SessionSetLanguage, SessionSetTenant } from '../actions/session.actions'; import { SetLanguage, SetTenant } from '../actions/session.actions';
import { ABP, Session } from '../models'; import { ABP, Session } from '../models';
@State<Session.State>({ @State<Session.State>({
@ -19,15 +19,15 @@ export class SessionState {
constructor() {} constructor() {}
@Action(SessionSetLanguage) @Action(SetLanguage)
sessionSetLanguage({ patchState }: StateContext<Session.State>, { payload }: SessionSetLanguage) { setLanguage({ patchState }: StateContext<Session.State>, { payload }: SetLanguage) {
patchState({ patchState({
language: payload, language: payload,
}); });
} }
@Action(SessionSetTenant) @Action(SetTenant)
sessionSetTenantId({ patchState }: StateContext<Session.State>, { payload }: SessionSetTenant) { setTenantId({ patchState }: StateContext<Session.State>, { payload }: SetTenant) {
patchState({ patchState({
tenant: payload, tenant: payload,
}); });

4
npm/ng-packs/packages/core/src/lib/utils/initial-utils.ts

@ -1,12 +1,12 @@
import { Injector } from '@angular/core'; import { Injector } from '@angular/core';
import { Store } from '@ngxs/store'; import { Store } from '@ngxs/store';
import { ConfigGetAppConfiguration } from '../actions/config.actions'; import { GetAppConfiguration } from '../actions/config.actions';
export function getInitialData(injector: Injector) { export function getInitialData(injector: Injector) {
const fn = function() { const fn = function() {
const store: Store = injector.get(Store); const store: Store = injector.get(Store);
return store.dispatch(new ConfigGetAppConfiguration()).toPromise(); return store.dispatch(new GetAppConfiguration()).toPromise();
}; };
return fn; return fn;

Loading…
Cancel
Save