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 { Component, TemplateRef, ViewChild } from '@angular/core'; |
||||
import { FormBuilder, FormGroup } from '@angular/forms'; |
import { Store } from '@ngxs/store'; |
||||
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; |
import { throwError } from 'rxjs'; |
||||
import { ABP } from '@abp/ng.core'; |
import { catchError, take } from 'rxjs/operators'; |
||||
|
import snq from 'snq'; |
||||
|
import { AccountService } from '../../services/account.service'; |
||||
|
|
||||
@Component({ |
@Component({ |
||||
selector: 'abp-tenant-box', |
selector: 'abp-tenant-box', |
||||
templateUrl: './tenant-box.component.html', |
templateUrl: './tenant-box.component.html', |
||||
}) |
}) |
||||
export class TenantBoxComponent { |
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 }) |
@ViewChild('modalContent', { static: false }) |
||||
modalContent: TemplateRef<any>; |
modalContent: TemplateRef<any>; |
||||
|
|
||||
createForm() { |
|
||||
this.form = this.fb.group({ |
|
||||
name: [this.selected.name], |
|
||||
}); |
|
||||
} |
|
||||
|
|
||||
openModal() { |
|
||||
this.createForm(); |
|
||||
this.modalService.open(this.modalContent); |
|
||||
} |
|
||||
|
|
||||
onSwitch() { |
onSwitch() { |
||||
this.selected = {} as ABP.BasicItem; |
this.isModalVisible = true; |
||||
this.openModal(); |
|
||||
} |
} |
||||
|
|
||||
save() { |
save() { |
||||
this.selected = this.form.value; |
this.selected.name = this.selected.name ? this.selected.name : ''; |
||||
this.modalService.dismissAll(); |
|
||||
|
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 './options'; |
||||
|
export * from './user'; |
||||
|
export * from './tenant'; |
||||
|
|||||
@ -0,0 +1,4 @@ |
|||||
|
export interface Tenant { |
||||
|
success: boolean; |
||||
|
tenantId: string; |
||||
|
} |
||||
Loading…
Reference in new issue