|
|
|
@ -3,31 +3,27 @@ import { ToasterService } from '@abp/ng.theme.shared';
|
|
|
|
|
import { Component, OnInit } from '@angular/core';
|
|
|
|
|
import { Store } from '@ngxs/store';
|
|
|
|
|
import { throwError } from 'rxjs';
|
|
|
|
|
import { catchError, take } from 'rxjs/operators';
|
|
|
|
|
import { catchError, take, finalize } from 'rxjs/operators';
|
|
|
|
|
import snq from 'snq';
|
|
|
|
|
import { AccountService } from '../../services/account.service';
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'abp-tenant-box',
|
|
|
|
|
templateUrl: './tenant-box.component.html'
|
|
|
|
|
templateUrl: './tenant-box.component.html',
|
|
|
|
|
})
|
|
|
|
|
export class TenantBoxComponent implements OnInit {
|
|
|
|
|
constructor(
|
|
|
|
|
private store: Store,
|
|
|
|
|
private toasterService: ToasterService,
|
|
|
|
|
private accountService: AccountService
|
|
|
|
|
) {}
|
|
|
|
|
|
|
|
|
|
tenant = {} as ABP.BasicItem;
|
|
|
|
|
|
|
|
|
|
tenantName: string;
|
|
|
|
|
|
|
|
|
|
isModalVisible: boolean;
|
|
|
|
|
|
|
|
|
|
inProgress: boolean;
|
|
|
|
|
|
|
|
|
|
constructor(private store: Store, private toasterService: ToasterService, private accountService: AccountService) {}
|
|
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
|
this.tenant =
|
|
|
|
|
this.store.selectSnapshot(SessionState.getTenant) ||
|
|
|
|
|
({} as ABP.BasicItem);
|
|
|
|
|
this.tenant = this.store.selectSnapshot(SessionState.getTenant) || ({} as ABP.BasicItem);
|
|
|
|
|
this.tenantName = this.tenant.name || '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -36,38 +32,33 @@ export class TenantBoxComponent implements OnInit {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
save() {
|
|
|
|
|
if (this.tenant.name) {
|
|
|
|
|
if (this.tenant.name && !this.inProgress) {
|
|
|
|
|
this.inProgress = true;
|
|
|
|
|
this.accountService
|
|
|
|
|
.findTenant(this.tenant.name)
|
|
|
|
|
.pipe(
|
|
|
|
|
finalize(() => (this.inProgress = false)),
|
|
|
|
|
take(1),
|
|
|
|
|
catchError(err => {
|
|
|
|
|
this.toasterService.error(
|
|
|
|
|
snq(
|
|
|
|
|
() => err.error.error_description,
|
|
|
|
|
'AbpUi::DefaultErrorMessage'
|
|
|
|
|
),
|
|
|
|
|
'AbpUi::Error'
|
|
|
|
|
snq(() => err.error.error_description, 'AbpUi::DefaultErrorMessage'),
|
|
|
|
|
'AbpUi::Error',
|
|
|
|
|
);
|
|
|
|
|
return throwError(err);
|
|
|
|
|
})
|
|
|
|
|
}),
|
|
|
|
|
)
|
|
|
|
|
.subscribe(({ success, tenantId }) => {
|
|
|
|
|
if (success) {
|
|
|
|
|
this.tenant = {
|
|
|
|
|
id: tenantId,
|
|
|
|
|
name: this.tenant.name
|
|
|
|
|
name: this.tenant.name,
|
|
|
|
|
};
|
|
|
|
|
this.tenantName = this.tenant.name;
|
|
|
|
|
this.isModalVisible = false;
|
|
|
|
|
} else {
|
|
|
|
|
this.toasterService.error(
|
|
|
|
|
'AbpUiMultiTenancy::GivenTenantIsNotAvailable',
|
|
|
|
|
'AbpUi::Error',
|
|
|
|
|
{
|
|
|
|
|
messageLocalizationParams: [this.tenant.name]
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
this.toasterService.error('AbpUiMultiTenancy::GivenTenantIsNotAvailable', 'AbpUi::Error', {
|
|
|
|
|
messageLocalizationParams: [this.tenant.name],
|
|
|
|
|
});
|
|
|
|
|
this.tenant = {} as ABP.BasicItem;
|
|
|
|
|
}
|
|
|
|
|
this.store.dispatch(new SetTenant(success ? this.tenant : null));
|
|
|
|
|