mirror of https://github.com/abpframework/abp.git
10 changed files with 3 additions and 239 deletions
@ -1,17 +0,0 @@ |
|||||
import { FeatureManagement } from '../models'; |
|
||||
|
|
||||
/** |
|
||||
* @deprecated To be deleted in v4.0. |
|
||||
*/ |
|
||||
export class GetFeatures { |
|
||||
static readonly type = '[FeatureManagement] Get Features'; |
|
||||
constructor(public payload: FeatureManagement.Provider) {} |
|
||||
} |
|
||||
|
|
||||
/** |
|
||||
* @deprecated To be deleted in v4.0. |
|
||||
*/ |
|
||||
export class UpdateFeatures { |
|
||||
static readonly type = '[FeatureManagement] Update Features'; |
|
||||
constructor(public payload: FeatureManagement.Provider & FeatureManagement.Features) {} |
|
||||
} |
|
||||
@ -1 +0,0 @@ |
|||||
export * from './feature-management.actions'; |
|
||||
@ -1,22 +1,16 @@ |
|||||
import { CoreModule } from '@abp/ng.core'; |
import { CoreModule } from '@abp/ng.core'; |
||||
import { ThemeSharedModule } from '@abp/ng.theme.shared'; |
import { ThemeSharedModule } from '@abp/ng.theme.shared'; |
||||
import { NgModule } from '@angular/core'; |
import { NgModule } from '@angular/core'; |
||||
import { NgxsModule } from '@ngxs/store'; |
|
||||
import { NgbNavModule } from '@ng-bootstrap/ng-bootstrap'; |
import { NgbNavModule } from '@ng-bootstrap/ng-bootstrap'; |
||||
import { FreeTextInputDirective } from './directives/free-text-input.directive'; |
import { NgxsModule } from '@ngxs/store'; |
||||
import { FeatureManagementComponent } from './components/feature-management/feature-management.component'; |
import { FeatureManagementComponent } from './components/feature-management/feature-management.component'; |
||||
import { FeatureManagementState } from './states/feature-management.state'; |
import { FreeTextInputDirective } from './directives/free-text-input.directive'; |
||||
|
|
||||
const exported = [FeatureManagementComponent, FreeTextInputDirective]; |
const exported = [FeatureManagementComponent, FreeTextInputDirective]; |
||||
|
|
||||
@NgModule({ |
@NgModule({ |
||||
declarations: [...exported], |
declarations: [...exported], |
||||
imports: [ |
imports: [CoreModule, ThemeSharedModule, NgbNavModule, NgxsModule.forFeature([])], |
||||
CoreModule, |
|
||||
ThemeSharedModule, |
|
||||
NgbNavModule, |
|
||||
NgxsModule.forFeature([FeatureManagementState]), |
|
||||
], |
|
||||
exports: [...exported], |
exports: [...exported], |
||||
}) |
}) |
||||
export class FeatureManagementModule {} |
export class FeatureManagementModule {} |
||||
|
|||||
@ -1,23 +0,0 @@ |
|||||
import { Injectable } from '@angular/core'; |
|
||||
import { Store } from '@ngxs/store'; |
|
||||
import { GetFeatures, UpdateFeatures } from '../actions/feature-management.actions'; |
|
||||
import { FeatureManagementState } from '../states/feature-management.state'; |
|
||||
|
|
||||
@Injectable({ |
|
||||
providedIn: 'root', |
|
||||
}) |
|
||||
export class FeatureManagementStateService { |
|
||||
constructor(private store: Store) {} |
|
||||
|
|
||||
getFeatures() { |
|
||||
return this.store.selectSnapshot(FeatureManagementState.getFeatures); |
|
||||
} |
|
||||
|
|
||||
dispatchGetFeatures(...args: ConstructorParameters<typeof GetFeatures>) { |
|
||||
return this.store.dispatch(new GetFeatures(...args)); |
|
||||
} |
|
||||
|
|
||||
dispatchUpdateFeatures(...args: ConstructorParameters<typeof UpdateFeatures>) { |
|
||||
return this.store.dispatch(new UpdateFeatures(...args)); |
|
||||
} |
|
||||
} |
|
||||
@ -1,42 +0,0 @@ |
|||||
import { Injectable } from '@angular/core'; |
|
||||
import { RestService, Rest } from '@abp/ng.core'; |
|
||||
import { Store } from '@ngxs/store'; |
|
||||
import { Observable } from 'rxjs'; |
|
||||
import { FeatureManagement } from '../models'; |
|
||||
|
|
||||
@Injectable({ |
|
||||
providedIn: 'root', |
|
||||
}) |
|
||||
/** |
|
||||
* @deprecated Use FeaturesService instead. To be deleted in v4.0. |
|
||||
*/ |
|
||||
export class FeatureManagementService { |
|
||||
apiName = 'FeatureManagement'; |
|
||||
|
|
||||
constructor(private rest: RestService, private store: Store) {} |
|
||||
|
|
||||
getFeatures(params: FeatureManagement.Provider): Observable<FeatureManagement.Features> { |
|
||||
const request: Rest.Request<null> = { |
|
||||
method: 'GET', |
|
||||
url: '/api/feature-management/features', |
|
||||
params, |
|
||||
}; |
|
||||
return this.rest.request<FeatureManagement.Provider, FeatureManagement.Features>(request, { |
|
||||
apiName: this.apiName, |
|
||||
}); |
|
||||
} |
|
||||
|
|
||||
updateFeatures({ |
|
||||
features, |
|
||||
providerKey, |
|
||||
providerName, |
|
||||
}: FeatureManagement.Provider & FeatureManagement.Features): Observable<null> { |
|
||||
const request: Rest.Request<FeatureManagement.Features> = { |
|
||||
method: 'PUT', |
|
||||
url: '/api/feature-management/features', |
|
||||
body: { features }, |
|
||||
params: { providerKey, providerName }, |
|
||||
}; |
|
||||
return this.rest.request<FeatureManagement.Features, null>(request, { apiName: this.apiName }); |
|
||||
} |
|
||||
} |
|
||||
@ -1,2 +0,0 @@ |
|||||
export * from './feature-management.service'; |
|
||||
export * from './feature-management-state.service'; |
|
||||
@ -1,39 +0,0 @@ |
|||||
import { Action, Selector, State, StateContext } from '@ngxs/store'; |
|
||||
import { tap } from 'rxjs/operators'; |
|
||||
import { GetFeatures, UpdateFeatures } from '../actions/feature-management.actions'; |
|
||||
import { FeatureManagement } from '../models/feature-management'; |
|
||||
import { FeatureManagementService } from '../services/feature-management.service'; |
|
||||
import { Injectable } from '@angular/core'; |
|
||||
|
|
||||
/** |
|
||||
* @deprecated To be deleted in v4.0. |
|
||||
*/ |
|
||||
@State<FeatureManagement.State>({ |
|
||||
name: 'FeatureManagementState', |
|
||||
defaults: { features: {} } as FeatureManagement.State, |
|
||||
}) |
|
||||
@Injectable() |
|
||||
export class FeatureManagementState { |
|
||||
@Selector() |
|
||||
static getFeatures({ features }: FeatureManagement.State) { |
|
||||
return features || []; |
|
||||
} |
|
||||
|
|
||||
constructor(private featureManagementService: FeatureManagementService) {} |
|
||||
|
|
||||
@Action(GetFeatures) |
|
||||
getFeatures({ patchState }: StateContext<FeatureManagement.State>, { payload }: GetFeatures) { |
|
||||
return this.featureManagementService.getFeatures(payload).pipe( |
|
||||
tap(({ features = [] }) => |
|
||||
patchState({ |
|
||||
features, |
|
||||
}), |
|
||||
), |
|
||||
); |
|
||||
} |
|
||||
|
|
||||
@Action(UpdateFeatures) |
|
||||
updateFeatures(_, { payload }: UpdateFeatures) { |
|
||||
return this.featureManagementService.updateFeatures(payload); |
|
||||
} |
|
||||
} |
|
||||
@ -1 +0,0 @@ |
|||||
export * from './feature-management.state'; |
|
||||
@ -1,61 +0,0 @@ |
|||||
import { createServiceFactory, SpectatorService, SpyObject } from '@ngneat/spectator/jest'; |
|
||||
import { Store } from '@ngxs/store'; |
|
||||
import { FeatureManagementStateService } from '../services/feature-management-state.service'; |
|
||||
import { FeatureManagementState } from '../states'; |
|
||||
import * as FeatureManagementActions from '../actions'; |
|
||||
|
|
||||
describe('FeatureManagementStateService', () => { |
|
||||
let service: FeatureManagementStateService; |
|
||||
let spectator: SpectatorService<FeatureManagementStateService>; |
|
||||
let store: SpyObject<Store>; |
|
||||
|
|
||||
const createService = createServiceFactory({ |
|
||||
service: FeatureManagementStateService, |
|
||||
mocks: [Store], |
|
||||
}); |
|
||||
beforeEach(() => { |
|
||||
spectator = createService(); |
|
||||
service = spectator.service; |
|
||||
store = spectator.inject(Store); |
|
||||
}); |
|
||||
|
|
||||
test('should have the all FeatureManagementState static methods', () => { |
|
||||
const reg = /(?<=static )(.*)(?=\()/gm; |
|
||||
FeatureManagementState.toString() |
|
||||
.match(reg) |
|
||||
.forEach(fnName => { |
|
||||
expect(service[fnName]).toBeTruthy(); |
|
||||
|
|
||||
const spy = jest.spyOn(store, 'selectSnapshot'); |
|
||||
spy.mockClear(); |
|
||||
|
|
||||
const isDynamicSelector = FeatureManagementState[fnName].name !== 'memoized'; |
|
||||
|
|
||||
if (isDynamicSelector) { |
|
||||
FeatureManagementState[fnName] = jest.fn((...args) => args); |
|
||||
service[fnName]('test', 0, {}); |
|
||||
expect(FeatureManagementState[fnName]).toHaveBeenCalledWith('test', 0, {}); |
|
||||
} else { |
|
||||
service[fnName](); |
|
||||
expect(spy).toHaveBeenCalledWith(FeatureManagementState[fnName]); |
|
||||
} |
|
||||
}); |
|
||||
}); |
|
||||
|
|
||||
test('should have a dispatch method for every FeatureManagementState action', () => { |
|
||||
const reg = /(?<=dispatch)(\w+)(?=\()/gm; |
|
||||
FeatureManagementStateService.toString() |
|
||||
.match(reg) |
|
||||
.forEach(fnName => { |
|
||||
expect(FeatureManagementActions[fnName]).toBeTruthy(); |
|
||||
|
|
||||
const spy = jest.spyOn(store, 'dispatch'); |
|
||||
spy.mockClear(); |
|
||||
|
|
||||
const params = Array.from(new Array(FeatureManagementActions[fnName].length)); |
|
||||
|
|
||||
service[`dispatch${fnName}`](...params); |
|
||||
expect(spy).toHaveBeenCalledWith(new FeatureManagementActions[fnName](...params)); |
|
||||
}); |
|
||||
}); |
|
||||
}); |
|
||||
Loading…
Reference in new issue