Browse Source

feature(core): add state actions to state services

pull/2431/head
TheDiaval 7 years ago
parent
commit
0ae1d767d4
  1. 14
      npm/ng-packs/packages/core/src/lib/services/config-state.service.ts
  2. 14
      npm/ng-packs/packages/core/src/lib/services/profile-state.service.ts
  3. 10
      npm/ng-packs/packages/core/src/lib/services/session-state.service.ts

14
npm/ng-packs/packages/core/src/lib/services/config-state.service.ts

@ -1,6 +1,8 @@
import { Injectable } from '@angular/core';
import { Store } from '@ngxs/store';
import { ConfigState } from '../states';
import { GetAppConfiguration, PatchRouteByName, AddRoute } from '../actions/config.actions';
import { ABP } from '../models';
@Injectable({
providedIn: 'root',
@ -47,4 +49,16 @@ export class ConfigStateService {
getLocalization(...args: Parameters<typeof ConfigState.getLocalization>) {
return this.store.selectSnapshot(ConfigState.getLocalization(...args));
}
addData() {
return this.store.dispatch(new GetAppConfiguration());
}
patchRoute(name: string, newValue: Partial<ABP.Route>) {
return this.store.dispatch(new PatchRouteByName(name, newValue));
}
addRoute(payload: Omit<ABP.Route, 'children'>) {
return this.store.dispatch(new AddRoute(payload));
}
}

14
npm/ng-packs/packages/core/src/lib/services/profile-state.service.ts

@ -1,6 +1,8 @@
import { Injectable } from '@angular/core';
import { Store } from '@ngxs/store';
import { ProfileState } from '../states';
import { Profile } from '../models';
import { GetProfile, UpdateProfile, ChangePassword } from '../actions';
@Injectable({
providedIn: 'root',
@ -11,4 +13,16 @@ export class ProfileStateService {
getProfile() {
return this.store.selectSnapshot(ProfileState.getProfile);
}
fetchProfile() {
return this.store.dispatch(new GetProfile());
}
updateProfile(payload: Profile.Response) {
return this.store.dispatch(new UpdateProfile(payload));
}
changePassword(payload: Profile.ChangePasswordRequest) {
return this.store.dispatch(new ChangePassword(payload));
}
}

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

@ -1,6 +1,8 @@
import { Injectable } from '@angular/core';
import { Store } from '@ngxs/store';
import { SessionState } from '../states';
import { ABP } from '../models';
import { SetLanguage, SetTenant } from '../actions';
@Injectable({
providedIn: 'root',
@ -15,4 +17,12 @@ export class SessionStateService {
getTenant() {
return this.store.selectSnapshot(SessionState.getTenant);
}
setLanguage(payload: string) {
return this.store.dispatch(new SetLanguage(payload));
}
setTenant(payload: ABP.BasicItem) {
return this.store.dispatch(new SetTenant(payload));
}
}

Loading…
Cancel
Save