refactor(tenant-management): get api calls move to corresponding components

pull/2285/head
mehmet-erim 6 years ago
parent e02f5fe5af
commit a1cc204075

@ -60,7 +60,12 @@
<th>{{ 'AbpTenantManagement::Actions' | abpLocalization }}</th>
<th pResizableColumn (click)="sortOrderIcon.sort('name')">
{{ 'AbpTenantManagement::TenantName' | abpLocalization }}
<abp-sort-order-icon #sortOrderIcon key="name" [(selectedKey)]="sortKey" [(order)]="sortOrder">
<abp-sort-order-icon
#sortOrderIcon
key="name"
[(selectedKey)]="sortKey"
[(order)]="sortOrder"
>
</abp-sort-order-icon>
</th>
</tr>
@ -148,34 +153,32 @@
<ng-template #connectionStringModalTemplate>
<form [formGroup]="defaultConnectionStringForm" (ngSubmit)="save()" validateOnSubmit>
<label class="mt-2">
<div class="form-group">
<div class="custom-checkbox custom-control mb-2">
<input
id="useSharedDatabase"
type="checkbox"
class="custom-control-input"
formControlName="useSharedDatabase"
autofocus
(ngModelChange)="onSharedDatabaseChange($event)"
/>
<label for="useSharedDatabase" class="custom-control-label">{{
'AbpTenantManagement::DisplayName:UseSharedDatabase' | abpLocalization
}}</label>
</div>
</div>
<label class="form-group" *ngIf="!useSharedDatabase">
<label for="defaultConnectionString">{{
'AbpTenantManagement::DisplayName:DefaultConnectionString' | abpLocalization
}}</label>
<div class="form-group">
<div class="custom-checkbox custom-control mb-2">
<input
type="text"
id="defaultConnectionString"
class="form-control"
formControlName="defaultConnectionString"
id="useSharedDatabase"
type="checkbox"
class="custom-control-input"
formControlName="useSharedDatabase"
autofocus
(ngModelChange)="onSharedDatabaseChange($event)"
/>
</label>
</label>
<label for="useSharedDatabase" class="custom-control-label">{{
'AbpTenantManagement::DisplayName:UseSharedDatabase' | abpLocalization
}}</label>
</div>
</div>
<div class="form-group" *ngIf="!useSharedDatabase">
<label for="defaultConnectionString">{{
'AbpTenantManagement::DisplayName:DefaultConnectionString' | abpLocalization
}}</label>
<input
type="text"
id="defaultConnectionString"
class="form-control"
formControlName="defaultConnectionString"
/>
</div>
</form>
</ng-template>

@ -83,7 +83,11 @@ export class TenantsComponent implements OnInit {
this.defaultConnectionStringForm.invalid
) {
return true;
} else if (this.selectedModalContent.type === 'saveTenant' && this.tenantForm && this.tenantForm.invalid) {
} else if (
this.selectedModalContent.type === 'saveTenant' &&
this.tenantForm &&
this.tenantForm.invalid
) {
return true;
} else {
return false;
@ -143,7 +147,11 @@ export class TenantsComponent implements OnInit {
this._useSharedDatabase = fetchedConnectionString ? false : true;
this.defaultConnectionString = fetchedConnectionString ? fetchedConnectionString : '';
this.createDefaultConnectionStringForm();
this.openModal('AbpTenantManagement::ConnectionStrings', this.connectionStringModalTemplate, 'saveConnStr');
this.openModal(
'AbpTenantManagement::ConnectionStrings',
this.connectionStringModalTemplate,
'saveConnStr',
);
});
}
@ -187,7 +195,10 @@ export class TenantsComponent implements OnInit {
});
} else {
this.tenantService
.updateDefaultConnectionString({ id: this.selected.id, defaultConnectionString: this.connectionString })
.updateDefaultConnectionString({
id: this.selected.id,
defaultConnectionString: this.connectionString,
})
.pipe(
take(1),
finalize(() => (this.modalBusy = false)),
@ -211,17 +222,22 @@ export class TenantsComponent implements OnInit {
.pipe(finalize(() => (this.modalBusy = false)))
.subscribe(() => {
this.isModalVisible = false;
this.get();
});
}
delete(id: string, name: string) {
this.confirmationService
.warn('AbpTenantManagement::TenantDeletionConfirmationMessage', 'AbpTenantManagement::AreYouSure', {
messageLocalizationParams: [name],
})
.warn(
'AbpTenantManagement::TenantDeletionConfirmationMessage',
'AbpTenantManagement::AreYouSure',
{
messageLocalizationParams: [name],
},
)
.subscribe((status: Toaster.Status) => {
if (status === Toaster.Status.confirm) {
this.store.dispatch(new DeleteTenant(id));
this.store.dispatch(new DeleteTenant(id)).subscribe(() => this.get());
}
});
}
@ -244,7 +260,9 @@ export class TenantsComponent implements OnInit {
onSharedDatabaseChange(value: boolean) {
if (!value) {
setTimeout(() => {
const defaultConnectionString = document.getElementById('defaultConnectionString') as HTMLInputElement;
const defaultConnectionString = document.getElementById(
'defaultConnectionString',
) as HTMLInputElement;
if (defaultConnectionString) {
defaultConnectionString.focus();
}

@ -51,19 +51,17 @@ export class TenantManagementState {
}
@Action(DeleteTenant)
delete({ dispatch }: StateContext<TenantManagement.State>, { payload }: DeleteTenant) {
return this.tenantManagementService.deleteTenant(payload).pipe(switchMap(() => dispatch(new GetTenants())));
delete(_, { payload }: DeleteTenant) {
return this.tenantManagementService.deleteTenant(payload);
}
@Action(CreateTenant)
add({ dispatch }: StateContext<TenantManagement.State>, { payload }: CreateTenant) {
return this.tenantManagementService.createTenant(payload).pipe(switchMap(() => dispatch(new GetTenants())));
add(_, { payload }: CreateTenant) {
return this.tenantManagementService.createTenant(payload);
}
@Action(UpdateTenant)
update({ dispatch, getState }: StateContext<TenantManagement.State>, { payload }: UpdateTenant) {
return this.tenantManagementService
.updateTenant({ ...getState().selectedItem, ...payload })
.pipe(switchMap(() => dispatch(new GetTenants())));
update({ getState }: StateContext<TenantManagement.State>, { payload }: UpdateTenant) {
return this.tenantManagementService.updateTenant({ ...getState().selectedItem, ...payload });
}
}

Loading…
Cancel
Save