Browse Source

feat: implement environment.service

pull/6156/head
mehmet-erim 5 years ago
parent
commit
f8ece40eee
  1. 8
      npm/ng-packs/packages/account/src/lib/guards/manage-profile.guard.ts
  2. 11
      npm/ng-packs/packages/core/src/lib/handlers/oauth-configuration.handler.ts
  3. 1
      npm/ng-packs/packages/core/src/public-api.ts
  4. 7
      npm/ng-packs/packages/tenant-management/src/lib/components/tenants/tenants.component.ts
  5. 9
      npm/ng-packs/packages/theme-basic/src/lib/components/logo/logo.component.ts

8
npm/ng-packs/packages/account/src/lib/guards/manage-profile.guard.ts

@ -1,13 +1,13 @@
import { EnvironmentService } from '@abp/ng.core';
import { Injectable } from '@angular/core';
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { ConfigStateService } from '@abp/ng.core';
import { ActivatedRouteSnapshot, CanActivate, RouterStateSnapshot } from '@angular/router';
@Injectable()
export class ManageProfileGuard implements CanActivate {
constructor(private configState: ConfigStateService) {}
constructor(private environment: EnvironmentService) {}
canActivate(_: ActivatedRouteSnapshot, __: RouterStateSnapshot) {
const env = this.configState.getEnvironment();
const env = this.environment.getEnvironment();
if (env.oAuthConfig.responseType === 'code') {
window.location.href = `${env.oAuthConfig.issuer}/Account/Manage?returnUrl=${window.location.href}`;
return false;

11
npm/ng-packs/packages/core/src/lib/handlers/oauth-configuration.handler.ts

@ -1,10 +1,9 @@
import { Inject, Injectable } from '@angular/core';
import { Actions, ofActionSuccessful } from '@ngxs/store';
import { OAuthService } from 'angular-oauth2-oidc';
import compare from 'just-compare';
import { filter, map } from 'rxjs/operators';
import { SetEnvironment } from '../actions/config.actions';
import { ABP } from '../models/common';
import { EnvironmentService } from '../services/environment.service';
import { CORE_OPTIONS } from '../tokens/options.token';
@Injectable({
@ -12,18 +11,18 @@ import { CORE_OPTIONS } from '../tokens/options.token';
})
export class OAuthConfigurationHandler {
constructor(
private actions: Actions,
private oAuthService: OAuthService,
private environmentService: EnvironmentService,
@Inject(CORE_OPTIONS) private options: ABP.Root,
) {
this.listenToSetEnvironment();
}
private listenToSetEnvironment() {
this.actions
.pipe(ofActionSuccessful(SetEnvironment))
this.environmentService
.onUpdate$(state => state)
.pipe(
map(({ environment }: SetEnvironment) => environment.oAuthConfig),
map(environment => environment.oAuthConfig),
filter(config => !compare(config, this.options.environment.oAuthConfig)),
)
.subscribe(config => {

1
npm/ng-packs/packages/core/src/public-api.ts

@ -15,7 +15,6 @@ export * from './lib/guards';
export * from './lib/interceptors';
export * from './lib/models';
export * from './lib/pipes';
export * from './lib/plugins';
export * from './lib/services';
export * from './lib/states';
export * from './lib/strategies';

7
npm/ng-packs/packages/tenant-management/src/lib/components/tenants/tenants.component.ts

@ -1,7 +1,7 @@
import { ABP, ListService, PagedResultDto } from '@abp/ng.core';
import { ListService, PagedResultDto } from '@abp/ng.core';
import { eFeatureManagementComponents } from '@abp/ng.feature-management';
import { Confirmation, ConfirmationService, getPasswordValidators } from '@abp/ng.theme.shared';
import { Component, OnInit, TemplateRef, ViewChild } from '@angular/core';
import { Component, Injector, OnInit, TemplateRef, ViewChild } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { Select, Store } from '@ngxs/store';
import { Observable } from 'rxjs';
@ -101,6 +101,7 @@ export class TenantsComponent implements OnInit {
constructor(
public readonly list: ListService<GetTenantsInput>,
private injector: Injector,
private confirmationService: ConfirmationService,
private tenantService: TenantManagementService,
private fb: FormBuilder,
@ -115,7 +116,7 @@ export class TenantsComponent implements OnInit {
const tenantForm = this.fb.group({
name: [this.selected.name || '', [Validators.required, Validators.maxLength(256)]],
adminEmailAddress: [null, [Validators.required, Validators.maxLength(256), Validators.email]],
adminPassword: [null, [Validators.required, ...getPasswordValidators(this.store)]],
adminPassword: [null, [Validators.required, ...getPasswordValidators(this.injector)]],
});
if (this.hasSelectedTenant) {

9
npm/ng-packs/packages/theme-basic/src/lib/components/logo/logo.component.ts

@ -1,6 +1,5 @@
import { Config, ConfigState } from '@abp/ng.core';
import { ApplicationInfo, EnvironmentService } from '@abp/ng.core';
import { Component } from '@angular/core';
import { Store } from '@ngxs/store';
@Component({
selector: 'abp-logo',
@ -21,9 +20,9 @@ import { Store } from '@ngxs/store';
`,
})
export class LogoComponent {
get appInfo(): Config.Application {
return this.store.selectSnapshot(ConfigState.getApplicationInfo);
get appInfo(): ApplicationInfo {
return this.environment.getEnvironment().application;
}
constructor(private store: Store) {}
constructor(private environment: EnvironmentService) {}
}

Loading…
Cancel
Save