Feature/state services (#1939)

* feat(core): add profile-state service

* feat(core): add session-state service

* feat(feature-management): add feature-management-state service

* feat(identity): add identity-state service

* feat(permission-management): add permission-management-state service

* feat(tenant-management): add tenant-management-state service

* feat(theme-basic): add layout-state service
pull/1940/head
Yasin Aydın 6 years ago committed by Mehmet Erim
parent bbd0c2e385
commit 3cc0e0f9c2

@ -5,7 +5,7 @@ import { ConfigState } from '../states';
@Injectable({
providedIn: 'root',
})
export class ConfigService {
export class ConfigStateService {
constructor(private store: Store) {}
getAll() {

@ -1,6 +1,8 @@
export * from './application-configuration.service';
export * from './config.service';
export * from './config-state.service';
export * from './lazy-load.service';
export * from './localization.service';
export * from './profile.service';
export * from './rest.service';
export * from './profile-state.service';
export * from './session-state.service';

@ -0,0 +1,14 @@
import { Injectable } from '@angular/core';
import { Store } from '@ngxs/store';
import { ProfileState } from '../states';
@Injectable({
providedIn: 'root',
})
export class ProfileStateService {
constructor(private store: Store) {}
getProfile() {
return this.store.selectSnapshot(ProfileState.getProfile);
}
}

@ -0,0 +1,16 @@
import { Injectable } from '@angular/core';
import { Store } from '@ngxs/store';
import { SessionState } from '../states';
@Injectable()
export class SessionStateService {
constructor(private store: Store) {}
getLanguage() {
return this.store.selectSnapshot(SessionState.getLanguage);
}
getTenant() {
return this.store.selectSnapshot(SessionState.getTenant);
}
}

@ -17,7 +17,7 @@ export class ProfileState {
constructor(private profileService: ProfileService) {}
@Action(GetProfile)
profileGet({ patchState }: StateContext<Profile.State>) {
getProfile({ patchState }: StateContext<Profile.State>) {
return this.profileService.get().pipe(
tap(profile =>
patchState({
@ -28,7 +28,7 @@ export class ProfileState {
}
@Action(UpdateProfile)
profileUpdate({ patchState }: StateContext<Profile.State>, { payload }: UpdateProfile) {
updateProfile({ patchState }: StateContext<Profile.State>, { payload }: UpdateProfile) {
return this.profileService.update(payload).pipe(
tap(profile =>
patchState({

@ -2,7 +2,7 @@ import { createServiceFactory, SpectatorService, SpyObject } from '@ngneat/spect
import { Store } from '@ngxs/store';
import { ReplaySubject, timer, Subject, of } from 'rxjs';
import { Config } from '../models/config';
import { ApplicationConfigurationService, ConfigService } from '../services';
import { ApplicationConfigurationService, ConfigStateService } from '../services';
import { ConfigState } from '../states';
import { SetLanguage, PatchRouteByName } from '../actions';
@ -110,14 +110,14 @@ export const CONFIG_STATE_DATA = {
} as Config.State;
describe('ConfigState', () => {
let spectator: SpectatorService<ConfigService>;
let spectator: SpectatorService<ConfigStateService>;
let store: SpyObject<Store>;
let service: ConfigService;
let service: ConfigStateService;
let state: ConfigState;
let appConfigService: SpyObject<ApplicationConfigurationService>;
const createService = createServiceFactory({
service: ConfigService,
service: ConfigStateService,
mocks: [ApplicationConfigurationService, Store],
});

@ -42,7 +42,7 @@ describe('ProfileState', () => {
const spy = jest.spyOn(profileService, 'get');
spy.mockReturnValue(of(mockData as any));
state.profileGet({ patchState } as any).subscribe();
state.getProfile({ patchState } as any).subscribe();
expect(patchedData).toEqual({ profile: mockData });
});
@ -54,7 +54,7 @@ describe('ProfileState', () => {
const spy = jest.spyOn(profileService, 'update');
spy.mockReturnValue(of(mockData as any));
state.profileUpdate({ patchState } as any, { payload: mockData as any }).subscribe();
state.updateProfile({ patchState } as any, { payload: mockData as any }).subscribe();
expect(patchedData).toEqual({ profile: mockData });
});

@ -0,0 +1,14 @@
import { Injectable } from '@angular/core';
import { Store } from '@ngxs/store';
import { FeatureManagementState } from '../states';
@Injectable({
providedIn: 'root',
})
export class FeatureManagementStateService {
constructor(private store: Store) {}
getFeatures() {
return this.store.selectSnapshot(FeatureManagementState.getFeatures);
}
}

@ -1 +1,2 @@
export * from './feature-management.service';
export * from './feature-management-state.service';

@ -0,0 +1,23 @@
import { Injectable } from '@angular/core';
import { Store } from '@ngxs/store';
import { IdentityState } from '../states/identity.state';
@Injectable({
providedIn: 'root',
})
export class IdentityStateService {
constructor(private store: Store) {}
getRoles() {
return this.store.selectSnapshot(IdentityState.getRoles);
}
getRolesTotalCount() {
return this.store.selectSnapshot(IdentityState.getRolesTotalCount);
}
getUsers() {
return this.store.selectSnapshot(IdentityState.getUsers);
}
getUsersTotalCount() {
return this.store.selectSnapshot(IdentityState.getUsersTotalCount);
}
}

@ -0,0 +1,2 @@
export * from './identity.service';
export * from './identity-state.service';

@ -1 +1,2 @@
export * from './permission-management.service';
export * from './permission-management-state.service';

@ -0,0 +1,17 @@
import { Injectable } from '@angular/core';
import { Store } from '@ngxs/store';
import { PermissionManagementState } from '../states/permission-management.state';
@Injectable({
providedIn: 'root',
})
export class PermissionManagementStateService {
constructor(private store: Store) {}
getPermissionGroups() {
return this.store.selectSnapshot(PermissionManagementState.getPermissionGroups);
}
getEntityDisplayName() {
return this.store.selectSnapshot(PermissionManagementState.getPermissionGroups);
}
}

@ -1 +1,2 @@
export * from './tenant-management.service';
export * from './tenant-management-state.service';

@ -0,0 +1,18 @@
import { Injectable } from '@angular/core';
import { Store } from '@ngxs/store';
import { TenantManagementState } from '../states/tenant-management.state';
@Injectable({
providedIn: 'root',
})
export class TenantManagementStateService {
constructor(private store: Store) {}
getTenants() {
return this.store.selectSnapshot(TenantManagementState.get);
}
getTenantsTotalCount() {
return this.store.selectSnapshot(TenantManagementState.getTenantsTotalCount);
}
}

@ -0,0 +1,2 @@
export * from './initial.service';
export * from './layout-state.service';

@ -0,0 +1,12 @@
import { Injectable } from '@angular/core';
import { Store } from '@ngxs/store';
import { LayoutState } from '../states/layout.state';
@Injectable()
export class LayoutStateService {
constructor(private store: Store) {}
getNavigationElements() {
return this.store.selectSnapshot(LayoutState.getNavigationElements);
}
}
Loading…
Cancel
Save