Browse Source

refactor(account): add inprogress variable to tenant-box

add validateOnSubmit directive to forms
pull/2146/head
mehmet-erim 7 years ago
parent
commit
d7207eb578
  1. 2
      npm/ng-packs/packages/account/src/lib/components/login/login.component.html
  2. 2
      npm/ng-packs/packages/account/src/lib/components/register/register.component.html
  3. 6
      npm/ng-packs/packages/account/src/lib/components/tenant-box/tenant-box.component.html
  4. 43
      npm/ng-packs/packages/account/src/lib/components/tenant-box/tenant-box.component.ts

2
npm/ng-packs/packages/account/src/lib/components/login/login.component.html

@ -5,7 +5,7 @@
{{ 'AbpAccount::AreYouANewUser' | abpLocalization }} {{ 'AbpAccount::AreYouANewUser' | abpLocalization }}
<a class="text-decoration-none" routerLink="/account/register">{{ 'AbpAccount::Register' | abpLocalization }}</a> <a class="text-decoration-none" routerLink="/account/register">{{ 'AbpAccount::Register' | abpLocalization }}</a>
</strong> </strong>
<form [formGroup]="form" (ngSubmit)="onSubmit()" novalidate class="mt-4"> <form [formGroup]="form" (ngSubmit)="onSubmit()" validateOnSubmit class="mt-4">
<div class="form-group"> <div class="form-group">
<label for="login-input-user-name-or-email-address">{{ <label for="login-input-user-name-or-email-address">{{
'AbpAccount::UserNameOrEmailAddress' | abpLocalization 'AbpAccount::UserNameOrEmailAddress' | abpLocalization

2
npm/ng-packs/packages/account/src/lib/components/register/register.component.html

@ -5,7 +5,7 @@
{{ 'AbpAccount::AlreadyRegistered' | abpLocalization }} {{ 'AbpAccount::AlreadyRegistered' | abpLocalization }}
<a class="text-decoration-none" routerLink="/account/login">{{ 'AbpAccount::Login' | abpLocalization }}</a> <a class="text-decoration-none" routerLink="/account/login">{{ 'AbpAccount::Login' | abpLocalization }}</a>
</strong> </strong>
<form [formGroup]="form" (ngSubmit)="onSubmit()" novalidate class="mt-4"> <form [formGroup]="form" (ngSubmit)="onSubmit()" validateOnSubmit class="mt-4">
<div class="form-group"> <div class="form-group">
<label for="input-user-name">{{ 'AbpAccount::UserName' | abpLocalization }}</label <label for="input-user-name">{{ 'AbpAccount::UserName' | abpLocalization }}</label
><span> * </span ><span> * </span

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

@ -25,7 +25,7 @@
</div> </div>
</div> </div>
<abp-modal [(visible)]="isModalVisible" size="md"> <abp-modal size="md" [(visible)]="isModalVisible" [busy]="inProgress">
<ng-template #abpHeader> <ng-template #abpHeader>
<h5>Switch Tenant</h5> <h5>Switch Tenant</h5>
</ng-template> </ng-template>
@ -44,8 +44,8 @@
<button #abpClose type="button" class="btn btn-secondary"> <button #abpClose type="button" class="btn btn-secondary">
{{ 'AbpTenantManagement::Cancel' | abpLocalization }} {{ 'AbpTenantManagement::Cancel' | abpLocalization }}
</button> </button>
<button type="button" class="btn btn-primary" (click)="save()"> <abp-button buttonType="button" buttonClass="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> </abp-button>
</ng-template> </ng-template>
</abp-modal> </abp-modal>

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

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

Loading…
Cancel
Save