Browse Source

feature(account): add tenant search by name

pull/1573/head
TheDiaval 7 years ago
parent
commit
6302871f43
  1. 42
      npm/ng-packs/packages/account/src/lib/components/tenant-box/tenant-box.component.html
  2. 53
      npm/ng-packs/packages/account/src/lib/components/tenant-box/tenant-box.component.ts
  3. 2
      npm/ng-packs/packages/account/src/lib/models/index.ts
  4. 4
      npm/ng-packs/packages/account/src/lib/models/tenant.ts

42
npm/ng-packs/packages/account/src/lib/components/tenant-box/tenant-box.component.html

@ -12,33 +12,27 @@
>) >)
</div> </div>
<ng-template #modalContent let-modal> <abp-modal *ngIf="isModalVisible" [(visible)]="isModalVisible">
<div class="modal-header"> <ng-template #abpHeader>
<h5 class="modal-title" id="modal-basic-title"> <h5>Switch Tenant</h5>
SwitchTenant </ng-template>
</h5> <ng-template #abpBody>
<button type="button" class="close" aria-label="Close" (click)="modal.dismiss()"> <form>
<span aria-hidden="true">&times;</span>
</button>
</div>
<form [formGroup]="form" (ngSubmit)="save()">
<div class="modal-body">
<div class="mt-2"> <div class="mt-2">
<div class="form-group"> <div class="form-group">
<label for="name">{{ 'AbpUiMultiTenancy::Name' | abpLocalization }}</label> <label for="name">{{ 'AbpUiMultiTenancy::Name' | abpLocalization }}</label>
<input type="text" id="name" class="form-control" formControlName="name" /> <input type="text" id="name" name="tenant" class="form-control" [(ngModel)]="selected.name" />
</div> </div>
<p>{{ 'AbpUiMultiTenancy::SwitchTenantHint' | abpLocalization }}</p> <p>{{ 'AbpUiMultiTenancy::SwitchTenantHint' | abpLocalization }}</p>
</div> </div>
</div> </form>
</ng-template>
<div class="modal-footer"> <ng-template #abpFooter>
<button type="button" class="btn btn-secondary" data-dismiss="modal" (click)="modal.close()"> <button #abpClose type="button" class="btn btn-secondary">
{{ 'AbpTenantManagement::Cancel' | abpLocalization }} {{ 'AbpTenantManagement::Cancel' | abpLocalization }}
</button> </button>
<button type="submit" class="btn btn-primary"> <button type="button" class="btn btn-primary" (click)="save()">
<i class="fa fa-check mr-1"></i> <span>{{ 'AbpTenantManagement::Save' | abpLocalization }}</span> <i class="fa fa-check mr-1"></i> <span>{{ 'AbpTenantManagement::Save' | abpLocalization }}</span>
</button> </button>
</div> </ng-template>
</form> </abp-modal>
</ng-template>

53
npm/ng-packs/packages/account/src/lib/components/tenant-box/tenant-box.component.ts

@ -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));
}
});
} }
} }

2
npm/ng-packs/packages/account/src/lib/models/index.ts

@ -1 +1,3 @@
export * from './options'; export * from './options';
export * from './user';
export * from './tenant';

4
npm/ng-packs/packages/account/src/lib/models/tenant.ts

@ -0,0 +1,4 @@
export interface Tenant {
success: boolean;
tenantId: string;
}
Loading…
Cancel
Save