Skip to content

Commit ce45a06

Browse files
authored
Merge pull request #13 from iyilm4z/master
Migrate account's tenant change component and role's listing, creation and edition components
2 parents 9dded8a + 2841083 commit ce45a06

14 files changed

+460
-316
lines changed

angular/src/account/account.module.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@ import { ServiceProxyModule } from '@shared/service-proxies/service-proxy.module
1515
import { SharedModule } from '@shared/shared.module';
1616

1717
import { AccountComponent } from './account.component';
18-
import { TenantChangeComponent } from './tenant/tenant-change.component';
19-
import { TenantChangeModalComponent } from './tenant/tenant-change-modal.component';
2018
import { LoginComponent } from './login/login.component';
2119
import { RegisterComponent } from './register/register.component';
2220
import { AccountLanguagesComponent } from './layout/account-languages.component';
2321

2422
import { LoginService } from './login/login.service';
2523

24+
// tenants
25+
import { TenantChangeComponent } from './tenant/tenant-change.component';
26+
import { TenantChangeDialogComponent } from './tenant/tenant-change-dialog.component';
27+
2628
@NgModule({
2729
imports: [
2830
CommonModule,
@@ -37,14 +39,19 @@ import { LoginService } from './login/login.service';
3739
],
3840
declarations: [
3941
AccountComponent,
40-
TenantChangeComponent,
41-
TenantChangeModalComponent,
4242
LoginComponent,
4343
RegisterComponent,
44-
AccountLanguagesComponent
44+
AccountLanguagesComponent,
45+
// tenant
46+
TenantChangeComponent,
47+
TenantChangeDialogComponent,
4548
],
4649
providers: [
4750
LoginService
51+
],
52+
entryComponents: [
53+
// tenant
54+
TenantChangeDialogComponent
4855
]
4956
})
5057
export class AccountModule {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<form autocomplete="off"
2+
#changeTenantForm="ngForm"
3+
(ngSubmit)="save()">
4+
<h1 mat-dialog-title >{{ "ChangeTenant" | localize }}</h1>
5+
<mat-dialog-content>
6+
<mat-form-field>
7+
<input
8+
matInput
9+
name="tenancyName"
10+
[placeholder]="'TenancyName' | localize"
11+
[(ngModel)]="tenancyName"
12+
maxlength="64"/>
13+
</mat-form-field>
14+
<span class="help-block">{{ "LeaveEmptyToSwitchToHost" | localize }}</span>
15+
</mat-dialog-content>
16+
<div mat-dialog-actions
17+
align="end">
18+
<button mat-button
19+
type="button"
20+
[disabled]="saving"
21+
(click)="close()">{{ "Cancel" | localize }}</button>
22+
<button mat-flat-button
23+
type="submit"
24+
flex="15"
25+
color="primary"
26+
[disabled]="!changeTenantForm.form.valid || saving">{{ "Save" | localize }}</button>
27+
</div>
28+
</form>
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import { Component, Injector } from '@angular/core';
2+
import { MatDialogRef } from '@angular/material';
3+
import { finalize } from 'rxjs/operators';
4+
import { AppComponentBase } from '@shared/app-component-base';
5+
import { AccountServiceProxy } from '@shared/service-proxies/service-proxies';
6+
import { AppTenantAvailabilityState } from '@shared/AppEnums';
7+
import {
8+
IsTenantAvailableInput,
9+
IsTenantAvailableOutput
10+
} from '@shared/service-proxies/service-proxies';
11+
12+
@Component({
13+
templateUrl: './tenant-change-dialog.component.html',
14+
styles: [
15+
`
16+
mat-form-field {
17+
width: 100%;
18+
}
19+
`
20+
]
21+
})
22+
export class TenantChangeDialogComponent extends AppComponentBase {
23+
saving = false;
24+
tenancyName = '';
25+
26+
constructor(
27+
injector: Injector,
28+
private _accountService: AccountServiceProxy,
29+
private _dialogRef: MatDialogRef<TenantChangeDialogComponent>
30+
) {
31+
super(injector);
32+
}
33+
34+
save(): void {
35+
if (!this.tenancyName) {
36+
abp.multiTenancy.setTenantIdCookie(undefined);
37+
this.close(true);
38+
location.reload();
39+
return;
40+
}
41+
42+
const input = new IsTenantAvailableInput();
43+
input.tenancyName = this.tenancyName;
44+
45+
this.saving = true;
46+
this._accountService
47+
.isTenantAvailable(input)
48+
.pipe(
49+
finalize(() => {
50+
this.saving = false;
51+
})
52+
)
53+
.subscribe((result: IsTenantAvailableOutput) => {
54+
switch (result.state) {
55+
case AppTenantAvailabilityState.Available:
56+
abp.multiTenancy.setTenantIdCookie(result.tenantId);
57+
this.close(true);
58+
location.reload();
59+
return;
60+
case AppTenantAvailabilityState.InActive:
61+
this.message.warn(this.l('TenantIsNotActive', this.tenancyName));
62+
break;
63+
case AppTenantAvailabilityState.NotFound:
64+
this.message.warn(
65+
this.l('ThereIsNoTenantDefinedWithName{0}', this.tenancyName)
66+
);
67+
break;
68+
}
69+
});
70+
}
71+
72+
close(result?: any): void {
73+
this._dialogRef.close(result);
74+
}
75+
}

angular/src/account/tenant/tenant-change-modal.component.html

Lines changed: 0 additions & 36 deletions
This file was deleted.

angular/src/account/tenant/tenant-change-modal.component.ts

Lines changed: 0 additions & 76 deletions
This file was deleted.
Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1-
<div *ngIf="isMultiTenancyEnabled" class="card tenant-change-component" style="margin-bottom: 3px;">
2-
<div class="body text-center">
3-
<span>
4-
{{ "CurrentTenant" | localize }}: <span *ngIf="tenancyName" title="{{name}}"><strong>{{tenancyName}}</strong></span> <span *ngIf="!tenancyName">{{ "NotSelected" | localize }}</span> (<a href="javascript:void();" (click)="showChangeModal()">{{ "Change" | localize }}</a>)
5-
<tenantChangeModal #tenantChangeModal></tenantChangeModal>
6-
</span>
7-
</div>
8-
</div>
1+
<div
2+
*ngIf="isMultiTenancyEnabled"
3+
class="card tenant-change-component"
4+
style="margin-bottom: 3px;">
5+
<div class="body text-center">
6+
<span>
7+
{{ "CurrentTenant" | localize }}:
8+
<span *ngIf="tenancyName" title="{{ name }}">
9+
<strong>{{ tenancyName }}</strong>
10+
</span>
11+
<span *ngIf="!tenancyName">{{ "NotSelected" | localize }}</span>
12+
(<a href="javascript:;" (click)="showChangeModal()">{{ "Change" | localize }}</a>)
13+
</span>
14+
</div>
15+
</div>
Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,38 @@
1-
import { Component, OnInit, Injector, ViewChild } from '@angular/core';
2-
import { AccountServiceProxy } from '@shared/service-proxies/service-proxies'
3-
import { TenantChangeModalComponent } from './tenant-change-modal.component'
1+
import { Component, OnInit, Injector } from '@angular/core';
2+
import { MatDialog } from '@angular/material';
43
import { AppComponentBase } from '@shared/app-component-base';
4+
import { TenantChangeDialogComponent } from './tenant-change-dialog.component';
55

66
@Component({
7-
selector: 'tenant-change',
8-
templateUrl: './tenant-change.component.html'
7+
selector: 'tenant-change',
8+
templateUrl: './tenant-change.component.html'
99
})
1010
export class TenantChangeComponent extends AppComponentBase implements OnInit {
11-
12-
@ViewChild('tenantChangeModal') tenantChangeModal: TenantChangeModalComponent;
11+
tenancyName = '';
12+
name = '';
1313

14-
tenancyName: string;
15-
name: string;
14+
constructor(injector: Injector, private _dialog: MatDialog) {
15+
super(injector);
16+
}
1617

17-
constructor(
18-
injector: Injector,
19-
private _accountService: AccountServiceProxy
20-
) {
21-
super(injector);
18+
ngOnInit() {
19+
if (this.appSession.tenant) {
20+
this.tenancyName = this.appSession.tenant.tenancyName;
21+
this.name = this.appSession.tenant.name;
2222
}
23+
}
2324

24-
ngOnInit() {
25-
26-
if (this.appSession.tenant) {
27-
this.tenancyName = this.appSession.tenant.tenancyName;
28-
this.name = this.appSession.tenant.name;
29-
}
30-
}
31-
32-
get isMultiTenancyEnabled(): boolean {
33-
return abp.multiTenancy.isEnabled;
34-
}
25+
get isMultiTenancyEnabled(): boolean {
26+
return abp.multiTenancy.isEnabled;
27+
}
3528

36-
showChangeModal(): void{
37-
this.tenantChangeModal.show(this.tenancyName);
38-
}
39-
}
29+
showChangeModal(): void {
30+
this._dialog.open(TenantChangeDialogComponent, {
31+
width: '500px',
32+
height: '240px',
33+
position: {
34+
top: '50px'
35+
}
36+
});
37+
}
38+
}

angular/src/app/app.module.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ import { CreateTenantDialogComponent } from './tenants/create-tenant/create-tena
3131
import { EditTenantDialogComponent } from './tenants/edit-tenant/edit-tenant-dialog.component';
3232
// roles
3333
import { RolesComponent } from '@app/roles/roles.component';
34-
import { CreateOrEditRoleDialogComponent } from '@app/roles/create-or-edit-role-dialog.component';
34+
import { CreateRoleDialogComponent } from './roles/create-role/create-role-dialog.component';
35+
import { EditRoleDialogComponent } from './roles/edit-role/edit-role-dialog.component';
3536

3637
@NgModule({
3738
declarations: [
@@ -49,10 +50,11 @@ import { CreateOrEditRoleDialogComponent } from '@app/roles/create-or-edit-role-
4950
SideBarUserAreaComponent,
5051
SideBarNavComponent,
5152
SideBarFooterComponent,
52-
RightSideBarComponent,
53+
RightSideBarComponent,
5354
// roles
5455
RolesComponent,
55-
CreateOrEditRoleDialogComponent
56+
CreateRoleDialogComponent,
57+
EditRoleDialogComponent
5658
],
5759
imports: [
5860
CommonModule,
@@ -72,10 +74,9 @@ import { CreateOrEditRoleDialogComponent } from '@app/roles/create-or-edit-role-
7274
entryComponents: [
7375
CreateTenantDialogComponent,
7476
EditTenantDialogComponent,
75-
7677
// roles
77-
RolesComponent,
78-
CreateOrEditRoleDialogComponent
78+
CreateRoleDialogComponent,
79+
EditRoleDialogComponent
7980
]
8081
})
8182
export class AppModule { }

0 commit comments

Comments
 (0)