Browse Source

Feature/state services (#1945)

* 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

* style: change vscode color settings

* test(core): add config-state service test

* test(core): add profile-state, session-state service tests

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

* test(identity): add identity-state service test

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

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

* test(theme-basic): add layout-state service test

* fix(core): change decorator parameters

* fix(core): add missing service methods
pull/1969/head
Yasin Aydın 7 years ago
committed by Mehmet Erim
parent
commit
d839655149
  1. 16
      npm/ng-packs/.vscode/settings.json
  2. 36
      npm/ng-packs/packages/core/src/lib/services/config-state.service.ts
  3. 4
      npm/ng-packs/packages/core/src/lib/services/session-state.service.ts
  4. 52
      npm/ng-packs/packages/core/src/lib/states/config.state.ts
  5. 6
      npm/ng-packs/packages/core/src/lib/states/profile.state.ts
  6. 6
      npm/ng-packs/packages/core/src/lib/states/session.state.ts
  7. 21
      npm/ng-packs/packages/core/src/lib/tests/config-state.service.spec.ts
  8. 21
      npm/ng-packs/packages/core/src/lib/tests/profile-state.service.spec.ts
  9. 21
      npm/ng-packs/packages/core/src/lib/tests/session-state.service.spec.ts
  10. 22
      npm/ng-packs/packages/feature-management/src/lib/tests/feature-management-state.service.spec.ts
  11. 21
      npm/ng-packs/packages/identity/src/lib/tests/identity-state.service.spec.ts
  12. 21
      npm/ng-packs/packages/permission-management/src/lib/tests/permission-management-state.service.spec.ts
  13. 21
      npm/ng-packs/packages/tenant-management/src/lib/tests/tenant-management-state.service.spec.ts
  14. 21
      npm/ng-packs/packages/theme-basic/src/lib/tests/layout-state.service.spec.ts

16
npm/ng-packs/.vscode/settings.json

@ -5,18 +5,18 @@
"tslint.rulesDirectory": "../node_modules/codelyzer", "tslint.rulesDirectory": "../node_modules/codelyzer",
"typescript.tsdk": "../node_modules/typescript/lib", "typescript.tsdk": "../node_modules/typescript/lib",
"workbench.colorCustomizations": { "workbench.colorCustomizations": {
"activityBar.background": "#90164b", "activityBar.background": "#258ecd",
"activityBar.foreground": "#e7e7e7", "activityBar.foreground": "#e7e7e7",
"activityBar.inactiveForeground": "#e7e7e799", "activityBar.inactiveForeground": "#e7e7e799",
"activityBarBadge.background": "#0e1c04", "activityBarBadge.background": "#f0aed7",
"activityBarBadge.foreground": "#e7e7e7", "activityBarBadge.foreground": "#15202b",
"titleBar.activeBackground": "#640f34", "titleBar.activeBackground": "#1d70a2",
"titleBar.inactiveBackground": "#640f3499", "titleBar.inactiveBackground": "#1d70a299",
"titleBar.activeForeground": "#e7e7e7", "titleBar.activeForeground": "#e7e7e7",
"titleBar.inactiveForeground": "#e7e7e799", "titleBar.inactiveForeground": "#e7e7e799",
"statusBar.background": "#640f34", "statusBar.background": "#1d70a2",
"statusBarItem.hoverBackground": "#90164b", "statusBarItem.hoverBackground": "#258ecd",
"statusBar.foreground": "#e7e7e7" "statusBar.foreground": "#e7e7e7"
}, },
"peacock.color": "#640f34" "peacock.color": "#1D70A2"
} }

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

@ -12,15 +12,39 @@ export class ConfigStateService {
return this.store.selectSnapshot(ConfigState.getAll); return this.store.selectSnapshot(ConfigState.getAll);
} }
getOne(key: string) { getApplicationInfo() {
return this.store.selectSnapshot(ConfigState.getOne(key)); return this.store.selectSnapshot(ConfigState.getApplicationInfo);
} }
getDeep(keys: string[] | string) { getOne(...args: Parameters<typeof ConfigState.getOne>) {
return this.store.selectSnapshot(ConfigState.getDeep(keys)); return this.store.selectSnapshot(ConfigState.getOne(...args));
} }
getSetting(key: string) { getDeep(...args: Parameters<typeof ConfigState.getDeep>) {
return this.store.selectSnapshot(ConfigState.getSetting(key)); return this.store.selectSnapshot(ConfigState.getDeep(...args));
}
getRoute(...args: Parameters<typeof ConfigState.getRoute>) {
return this.store.selectSnapshot(ConfigState.getRoute(...args));
}
getApiUrl(...args: Parameters<typeof ConfigState.getApiUrl>) {
return this.store.selectSnapshot(ConfigState.getApiUrl(...args));
}
getSetting(...args: Parameters<typeof ConfigState.getSetting>) {
return this.store.selectSnapshot(ConfigState.getSetting(...args));
}
getSettings(...args: Parameters<typeof ConfigState.getSettings>) {
return this.store.selectSnapshot(ConfigState.getSettings(...args));
}
getGrantedPolicy(...args: Parameters<typeof ConfigState.getGrantedPolicy>) {
return this.store.selectSnapshot(ConfigState.getGrantedPolicy(...args));
}
getLocalization(...args: Parameters<typeof ConfigState.getLocalization>) {
return this.store.selectSnapshot(ConfigState.getLocalization(...args));
} }
} }

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

@ -2,7 +2,9 @@ import { Injectable } from '@angular/core';
import { Store } from '@ngxs/store'; import { Store } from '@ngxs/store';
import { SessionState } from '../states'; import { SessionState } from '../states';
@Injectable() @Injectable({
providedIn: 'root',
})
export class SessionStateService { export class SessionStateService {
constructor(private store: Store) {} constructor(private store: Store) {}

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

@ -130,58 +130,6 @@ export class ConfigState {
return selector; return selector;
} }
/**
*
* @deprecated, Use getLocalization instead. To be delete in v1
*/
static getCopy(key: string, ...interpolateParams: string[]) {
if (!key) key = '';
const keys = key.split('::') as string[];
const selector = createSelector(
[ConfigState],
(state: Config.State) => {
if (!state.localization) return key;
const { defaultResourceName } = state.environment.localization;
if (keys[0] === '') {
if (!defaultResourceName) {
throw new Error(
`Please check your environment. May you forget set defaultResourceName?
Here is the example:
{ production: false,
localization: {
defaultResourceName: 'MyProjectName'
}
}`,
);
}
keys[0] = snq(() => defaultResourceName);
}
let copy = (keys as any).reduce((acc, val) => {
if (acc) {
return acc[val];
}
return undefined;
}, state.localization.values);
interpolateParams = interpolateParams.filter(params => params != null);
if (copy && interpolateParams && interpolateParams.length) {
interpolateParams.forEach(param => {
copy = copy.replace(/[\'\"]?\{[\d]+\}[\'\"]?/, param);
});
}
return copy || key;
},
);
return selector;
}
static getLocalization(key: string | Config.LocalizationWithDefault, ...interpolateParams: string[]) { static getLocalization(key: string | Config.LocalizationWithDefault, ...interpolateParams: string[]) {
let defaultValue: string; let defaultValue: string;

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

@ -1,8 +1,8 @@
import { State, Action, StateContext, Selector } from '@ngxs/store'; import { Action, Selector, State, StateContext } from '@ngxs/store';
import { GetProfile, ChangePassword, UpdateProfile } from '../actions/profile.actions'; import { tap } from 'rxjs/operators';
import { ChangePassword, GetProfile, 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';
@State<Profile.State>({ @State<Profile.State>({
name: 'ProfileState', name: 'ProfileState',

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

@ -1,10 +1,10 @@
import { Action, Selector, State, StateContext } from '@ngxs/store'; import { Action, Selector, State, StateContext } from '@ngxs/store';
import { from } from 'rxjs';
import { switchMap } from 'rxjs/operators';
import { GetAppConfiguration } from '../actions/config.actions';
import { SetLanguage, SetTenant } from '../actions/session.actions'; import { SetLanguage, SetTenant } from '../actions/session.actions';
import { ABP, Session } from '../models'; import { ABP, Session } from '../models';
import { GetAppConfiguration } from '../actions/config.actions';
import { LocalizationService } from '../services/localization.service'; import { LocalizationService } from '../services/localization.service';
import { from, combineLatest } from 'rxjs';
import { switchMap } from 'rxjs/operators';
@State<Session.State>({ @State<Session.State>({
name: 'SessionState', name: 'SessionState',

21
npm/ng-packs/packages/core/src/lib/tests/config-state.service.spec.ts

@ -0,0 +1,21 @@
import { createServiceFactory, SpectatorService } from '@ngneat/spectator/jest';
import { ConfigStateService } from '../services/config-state.service';
import { ConfigState } from '../states';
import { Store } from '@ngxs/store';
describe('ConfigStateService', () => {
let service: ConfigStateService;
let spectator: SpectatorService<ConfigStateService>;
const createService = createServiceFactory({ service: ConfigStateService, mocks: [Store] });
beforeEach(() => {
spectator = createService();
service = spectator.service;
});
test('should have the all ConfigState static methods', () => {
const reg = /(?<=static )(.*)(?=\()/gm;
ConfigState.toString()
.match(reg)
.forEach(fnName => {
expect(service[fnName]).toBeTruthy();
});
});
});

21
npm/ng-packs/packages/core/src/lib/tests/profile-state.service.spec.ts

@ -0,0 +1,21 @@
import { createServiceFactory, SpectatorService } from '@ngneat/spectator/jest';
import { ProfileStateService } from '../services/profile-state.service';
import { ProfileState } from '../states/profile.state';
import { Store } from '@ngxs/store';
describe('ProfileStateService', () => {
let service: ProfileStateService;
let spectator: SpectatorService<ProfileStateService>;
const createService = createServiceFactory({ service: ProfileStateService, mocks: [Store] });
beforeEach(() => {
spectator = createService();
service = spectator.service;
});
test('should have the all ProfileState static methods', () => {
const reg = /(?<=static )(.*)(?=\()/gm;
ProfileState.toString()
.match(reg)
.forEach(fnName => {
expect(service[fnName]).toBeTruthy();
});
});
});

21
npm/ng-packs/packages/core/src/lib/tests/session-state.service.spec.ts

@ -0,0 +1,21 @@
import { createServiceFactory, SpectatorService } from '@ngneat/spectator/jest';
import { SessionStateService } from '../services/session-state.service';
import { SessionState } from '../states/session.state';
import { Store } from '@ngxs/store';
describe('SessionStateService', () => {
let service: SessionStateService;
let spectator: SpectatorService<SessionStateService>;
const createService = createServiceFactory({ service: SessionStateService, mocks: [Store] });
beforeEach(() => {
spectator = createService();
service = spectator.service;
});
test('should have the all SessionState static methods', () => {
const reg = /(?<=static )(.*)(?=\()/gm;
SessionState.toString()
.match(reg)
.forEach(fnName => {
expect(service[fnName]).toBeTruthy();
});
});
});

22
npm/ng-packs/packages/feature-management/src/lib/tests/feature-management-state.service.spec.ts

@ -0,0 +1,22 @@
import { createServiceFactory, SpectatorService } from '@ngneat/spectator/jest';
import { Store } from '@ngxs/store';
import { FeatureManagementStateService } from '../services/feature-management-state.service';
import { FeatureManagementState } from '../states';
describe('FeatureManagementStateService', () => {
let service: FeatureManagementStateService;
let spectator: SpectatorService<FeatureManagementStateService>;
const createService = createServiceFactory({ service: FeatureManagementStateService, mocks: [Store] });
beforeEach(() => {
spectator = createService();
service = spectator.service;
});
test('should have the all FeatureManagementState static methods', () => {
const reg = /(?<=static )(.*)(?=\()/gm;
FeatureManagementState.toString()
.match(reg)
.forEach(fnName => {
expect(service[fnName]).toBeTruthy();
});
});
});

21
npm/ng-packs/packages/identity/src/lib/tests/identity-state.service.spec.ts

@ -0,0 +1,21 @@
import { createServiceFactory, SpectatorService } from '@ngneat/spectator/jest';
import { IdentityStateService } from '../services/identity-state.service';
import { IdentityState } from '../states/identity.state';
import { Store } from '@ngxs/store';
describe('IdentityStateService', () => {
let service: IdentityStateService;
let spectator: SpectatorService<IdentityStateService>;
const createService = createServiceFactory({ service: IdentityStateService, mocks: [Store] });
beforeEach(() => {
spectator = createService();
service = spectator.service;
});
test('should have the all IdentityState static methods', () => {
const reg = /(?<=static )(.*)(?=\()/gm;
IdentityState.toString()
.match(reg)
.forEach(fnName => {
expect(service[fnName]).toBeTruthy();
});
});
});

21
npm/ng-packs/packages/permission-management/src/lib/tests/permission-management-state.service.spec.ts

@ -0,0 +1,21 @@
import { createServiceFactory, SpectatorService } from '@ngneat/spectator/jest';
import { PermissionManagementStateService } from '../services/permission-management-state.service';
import { PermissionManagementState } from '../states/permission-management.state';
import { Store } from '@ngxs/store';
describe('PermissionManagementStateService', () => {
let service: PermissionManagementStateService;
let spectator: SpectatorService<PermissionManagementStateService>;
const createService = createServiceFactory({ service: PermissionManagementStateService, mocks: [Store] });
beforeEach(() => {
spectator = createService();
service = spectator.service;
});
test('should have the all PermissionManagementState static methods', () => {
const reg = /(?<=static )(.*)(?=\()/gm;
PermissionManagementState.toString()
.match(reg)
.forEach(fnName => {
expect(service[fnName]).toBeTruthy();
});
});
});

21
npm/ng-packs/packages/tenant-management/src/lib/tests/tenant-management-state.service.spec.ts

@ -0,0 +1,21 @@
import { createServiceFactory, SpectatorService } from '@ngneat/spectator/jest';
import { TenantManagementStateService } from '../services/tenant-management-state.service';
import { TenantManagementState } from '../states/tenant-management.state';
import { Store } from '@ngxs/store';
describe('TenantManagementStateService', () => {
let service: TenantManagementStateService;
let spectator: SpectatorService<TenantManagementStateService>;
const createService = createServiceFactory({ service: TenantManagementStateService, mocks: [Store] });
beforeEach(() => {
spectator = createService();
service = spectator.service;
});
test('should have the all TenantManagementState static methods', () => {
const reg = /(?<=static )(.*)(?=\()/gm;
TenantManagementState.toString()
.match(reg)
.forEach(fnName => {
expect(service[fnName]).toBeTruthy();
});
});
});

21
npm/ng-packs/packages/theme-basic/src/lib/tests/layout-state.service.spec.ts

@ -0,0 +1,21 @@
import { createServiceFactory, SpectatorService } from '@ngneat/spectator/jest';
import { LayoutStateService } from '../services/layout-state.service';
import { LayoutState } from '../states/layout.state';
import { Store } from '@ngxs/store';
describe('LayoutStateService', () => {
let service: LayoutStateService;
let spectator: SpectatorService<LayoutStateService>;
const createService = createServiceFactory({ service: LayoutStateService, mocks: [Store] });
beforeEach(() => {
spectator = createService();
service = spectator.service;
});
test('should have the all LayoutState static methods', () => {
const reg = /(?<=static )(.*)(?=\()/gm;
LayoutState.toString()
.match(reg)
.forEach(fnName => {
expect(service[fnName]).toBeTruthy();
});
});
});
Loading…
Cancel
Save