mirror of https://github.com/abpframework/abp.git
4 changed files with 56 additions and 45 deletions
@ -1,40 +1,51 @@ |
|||
import { ABP, SessionSetTenantId } from '@abp/ng.core'; |
|||
import { ToasterService } from '@abp/ng.theme.shared'; |
|||
import { Component, TemplateRef, ViewChild } from '@angular/core'; |
|||
import { FormBuilder, FormGroup } from '@angular/forms'; |
|||
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; |
|||
import { ABP } from '@abp/ng.core'; |
|||
import { Store } from '@ngxs/store'; |
|||
import { throwError } from 'rxjs'; |
|||
import { catchError, take } from 'rxjs/operators'; |
|||
import snq from 'snq'; |
|||
import { AccountService } from '../../services/account.service'; |
|||
|
|||
@Component({ |
|||
selector: 'abp-tenant-box', |
|||
templateUrl: './tenant-box.component.html', |
|||
}) |
|||
export class TenantBoxComponent { |
|||
constructor(private modalService: NgbModal, private fb: FormBuilder) {} |
|||
constructor(private store: Store, private toasterService: ToasterService, private accountService: AccountService) {} |
|||
|
|||
form: FormGroup; |
|||
selected = {} as ABP.BasicItem; |
|||
|
|||
selected: ABP.BasicItem; |
|||
isModalVisible: boolean; |
|||
|
|||
@ViewChild('modalContent', { static: false }) |
|||
modalContent: TemplateRef<any>; |
|||
|
|||
createForm() { |
|||
this.form = this.fb.group({ |
|||
name: [this.selected.name], |
|||
}); |
|||
} |
|||
|
|||
openModal() { |
|||
this.createForm(); |
|||
this.modalService.open(this.modalContent); |
|||
} |
|||
|
|||
onSwitch() { |
|||
this.selected = {} as ABP.BasicItem; |
|||
this.openModal(); |
|||
this.isModalVisible = true; |
|||
} |
|||
|
|||
save() { |
|||
this.selected = this.form.value; |
|||
this.modalService.dismissAll(); |
|||
this.selected.name = this.selected.name ? this.selected.name : ''; |
|||
|
|||
this.accountService |
|||
.findTenant(this.selected.name) |
|||
.pipe( |
|||
take(1), |
|||
catchError(err => { |
|||
this.toasterService.error(snq(() => err.error.error_description, 'An error occured.'), 'Error'); |
|||
return throwError(err); |
|||
}), |
|||
) |
|||
.subscribe(({ success, tenantId }) => { |
|||
if (success) { |
|||
this.store.dispatch(new SessionSetTenantId(tenantId)); |
|||
this.isModalVisible = false; |
|||
} else { |
|||
this.toasterService.error(`Given tenant is not available: ${this.selected.name}`, 'Error'); |
|||
this.selected = {} as ABP.BasicItem; |
|||
this.store.dispatch(new SessionSetTenantId(null)); |
|||
} |
|||
}); |
|||
} |
|||
} |
|||
|
|||
@ -1 +1,3 @@ |
|||
export * from './options'; |
|||
export * from './user'; |
|||
export * from './tenant'; |
|||
|
|||
@ -0,0 +1,4 @@ |
|||
export interface Tenant { |
|||
success: boolean; |
|||
tenantId: string; |
|||
} |
|||
Loading…
Reference in new issue