This repository has been archived by the owner on Mar 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(select account) - use ngrx for selected account (#607)
- Loading branch information
Showing
55 changed files
with
1,071 additions
and
313 deletions.
There are no files selected for viewing
107 changes: 107 additions & 0 deletions
107
src/app/account/account-container/account-details.container.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import { | ||
Component, | ||
OnInit | ||
} from '@angular/core'; | ||
import { State } from '../../reducers/index'; | ||
import { Store } from '@ngrx/store'; | ||
import * as configurationAction from '../../reducers/configuration/redux/configurations.actions'; | ||
import * as resourceLimitAction from '../../reducers/resource-limit/redux/resource-limits.actions'; | ||
import * as resourceCountAction from '../../reducers/resource-count/redux/resource-counts.actions'; | ||
import * as fromAccounts from '../../reducers/accounts/redux/accounts.reducers'; | ||
import * as fromConfigurations from '../../reducers/configuration/redux/configurations.reducers'; | ||
import * as fromResourceLimits from '../../reducers/resource-limit/redux/resource-limits.reducers'; | ||
import * as fromResourceCounts from '../../reducers/resource-count/redux/resource-counts.reducers'; | ||
import { WithUnsubscribe } from '../../utils/mixins/with-unsubscribe'; | ||
import { AuthService } from '../../shared/services/auth.service'; | ||
import { Account } from '../../shared/models/account.model'; | ||
|
||
@Component({ | ||
selector: 'cs-account-page-container', | ||
template: ` | ||
<cs-account-detail | ||
[account]="account$ | async" | ||
></cs-account-detail> | ||
<cs-account-settings | ||
*ngIf="isAdmin()" | ||
[account]="account$ | async" | ||
[configurations]="configurations$ | async" | ||
(onConfigurationEdit)="onConfigurationEdit($event)" | ||
> | ||
</cs-account-settings> | ||
<cs-account-limits | ||
[limits]="limits$ | async" | ||
[isAdmin]="isAdmin()" | ||
(onLimitsEdit)="onLimitsEdit($event)" | ||
></cs-account-limits> | ||
<cs-account-statistics | ||
*ngIf="isAdmin()" | ||
[stats]="stats$ | async" | ||
(onStatsUpdate)="onStatsUpdate($event)" | ||
></cs-account-statistics>` | ||
}) | ||
export class AccountDetailsContainerComponent extends WithUnsubscribe() implements OnInit { | ||
|
||
readonly account$ = this.store.select(fromAccounts.getSelectedAccount); | ||
readonly configurations$ = this.store.select(fromConfigurations.selectAll); | ||
readonly limits$ = this.store.select(fromResourceLimits.selectAll); | ||
readonly stats$ = this.store.select(fromResourceCounts.selectAll); | ||
|
||
public account: Account; | ||
|
||
|
||
constructor( | ||
private store: Store<State>, | ||
private authService: AuthService | ||
) { | ||
super(); | ||
} | ||
|
||
public onConfigurationEdit(configuration) { | ||
this.store.dispatch(new configurationAction.UpdateConfigurationRequest({ | ||
configuration, | ||
account: this.account | ||
})); | ||
} | ||
|
||
public onLimitsEdit(limits) { | ||
this.store.dispatch(new resourceLimitAction.UpdateResourceLimitsRequest({ | ||
limits, | ||
account: this.account | ||
})); | ||
} | ||
|
||
public onStatsUpdate(stats) { | ||
this.store.dispatch(new resourceCountAction.LoadResourceCountsRequest({ | ||
account: this.account.name, | ||
domainid: this.account.domainid | ||
})); | ||
} | ||
|
||
public ngOnInit() { | ||
this.account$ | ||
.takeUntil(this.unsubscribe$) | ||
.subscribe(account => { | ||
if (account) { | ||
this.account = account; | ||
this.store.dispatch(new resourceLimitAction.LoadResourceLimitsRequest({ | ||
account: account.name, | ||
domainid: account.domainid | ||
})); | ||
|
||
if (this.isAdmin()) { | ||
this.store.dispatch(new configurationAction.LoadConfigurationsRequest({ accountid: account.id })); | ||
this.store.dispatch(new resourceCountAction.LoadResourceCountsRequest({ | ||
account: account.name, | ||
domainid: account.domainid | ||
})); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
|
||
public isAdmin() { | ||
return this.authService.isAdmin(); | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
src/app/account/account-container/account-sidebar.container.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { | ||
Component, | ||
OnInit | ||
} from '@angular/core'; | ||
import { State } from '../../reducers/index'; | ||
import { Store } from '@ngrx/store'; | ||
import * as accountEvent from '../../reducers/accounts/redux/accounts.actions'; | ||
import { ActivatedRoute } from '@angular/router'; | ||
import * as fromAccounts from '../../reducers/accounts/redux/accounts.reducers'; | ||
|
||
@Component({ | ||
selector: 'cs-account-page-container', | ||
template: ` | ||
<cs-account-sidebar | ||
[entity]="account$ | async" | ||
(onAccountChanged)="onAccountChange($event)" | ||
></cs-account-sidebar>` | ||
}) | ||
export class AccountSidebarContainerComponent implements OnInit { | ||
|
||
readonly account$ = this.store.select(fromAccounts.getSelectedAccount); | ||
|
||
|
||
constructor( | ||
private store: Store<State>, | ||
private activatedRoute: ActivatedRoute | ||
) { } | ||
|
||
public onAccountChange(id) { | ||
this.store.dispatch(new accountEvent.LoadAccountsRequest()); | ||
} | ||
|
||
public ngOnInit() { | ||
const params = this.activatedRoute.snapshot.params; | ||
this.store.dispatch(new accountEvent.LoadSelectedAccount(params['id'])); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 6 additions & 31 deletions
37
src/app/account/account-sidebar/account-details/account-details.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.