Skip to content

Commit

Permalink
Same Tweaks at space level
Browse files Browse the repository at this point in the history
- Show edit quota on space level quota details page
- Ensure we return from edit stepper from org's space quota list, org level quota page and space level quota page
- Apply permissions to edit quota
  • Loading branch information
richard-cox committed Aug 1, 2019
1 parent 8e3f176 commit 3c2ca17
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Component } from '@angular/core';
import { ActivatedRoute } from '@angular/router';

import { QUOTA_FROM_LIST } from '../../../shared/components/list/list-types/cf-quotas/cf-quotas-list-config.service';
import { ActiveRouteCfOrgSpace } from '../cf-page.types';
import { getActiveRouteCfOrgSpaceProvider } from '../cf.helpers';
import { QUOTA_SPACE_GUID } from '../space-quota-definition/space-quota-definition.component';

@Component({
selector: 'app-edit-space-quota',
Expand All @@ -21,6 +23,15 @@ export class EditSpaceQuotaComponent {
const cfId = activeRouteCfOrgSpace.cfGuid;
const orgId = activeRouteCfOrgSpace.orgGuid;
const spaceQuotaId = activatedRoute.snapshot.params.quotaId;
this.cfSpaceQuotaUrl = `/cloud-foundry/${cfId}/organizations/${orgId}/space-quota-definitions/${spaceQuotaId}`;
const spaceGuid = activatedRoute.snapshot.queryParams[QUOTA_SPACE_GUID];
const fromList = activatedRoute.snapshot.queryParams[QUOTA_FROM_LIST];

if (spaceGuid) {
this.cfSpaceQuotaUrl = `/cloud-foundry/${cfId}/organizations/${orgId}/spaces/${spaceGuid}/space-quota`;
} else if (fromList) {
this.cfSpaceQuotaUrl = `/cloud-foundry/${cfId}/organizations/${orgId}/space-quota-definitions`;
} else {
this.cfSpaceQuotaUrl = `/cloud-foundry/${cfId}/organizations/${orgId}/space-quota-definitions/${spaceQuotaId}`;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
<app-page-header [breadcrumbs]="breadcrumbs$ | async" *ngIf="quotaGuid">
<app-page-header [breadcrumbs]="breadcrumbs$ | async" *ngIf="isOrg">
<h1>{{ (quotaDefinition$ | async)?.entity?.name }}</h1>
<div class="page-header-right" *ngIf="canEditQuota$ | async">
<button mat-icon-button name="edit" [routerLink]="editLink" matTooltip="Edit">
<!-- Show edit button in top blue bar -->
<button mat-icon-button name="edit" [routerLink]="editLink$ | async" [queryParams]="editParams" matTooltip="Edit">
<mat-icon>edit</mat-icon>
</button>
</div>
</app-page-header>

<app-page-sub-nav *ngIf="!isOrg">
<!-- Show edit button inline with header-->
<ng-container *ngIf="canEditQuota$ | async">
<button mat-icon-button name="edit" [routerLink]="editLink$ | async" [queryParams]="editParams" matTooltip="Edit">
<mat-icon>edit</mat-icon>
</button>
</ng-container>
</app-page-sub-nav>

<div class="quota-definition-base space-quota-definition-page" *ngIf="quotaDefinition$ | async as quotaDefinition">
<app-loading-page [isLoading]="detailsLoading$" text="Retrieving details">
<div class="quota-definition-base__name-sub-text">Name</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Component } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { Store } from '@ngrx/store';
import { Observable, of, Subscription } from 'rxjs';
import { filter, first, map, switchMap, tap } from 'rxjs/operators';
import { filter, first, map, switchMap } from 'rxjs/operators';

import { GetSpaceQuotaDefinition } from '../../../../../store/src/actions/quota-definitions.actions';
import { AppState } from '../../../../../store/src/app-state';
Expand All @@ -18,6 +18,8 @@ import { ActiveRouteCfOrgSpace } from '../cf-page.types';
import { getActiveRouteCfOrgSpaceProvider } from '../cf.helpers';
import { QuotaDefinitionBaseComponent } from '../quota-definition-base/quota-definition-base.component';

export const QUOTA_SPACE_GUID = 'space';

@Component({
selector: 'app-space-quota-definition',
styleUrls: ['../quota-definition-base/quota-definition-base.component.scss', './space-quota-definition.component.scss'],
Expand All @@ -33,10 +35,12 @@ export class SpaceQuotaDefinitionComponent extends QuotaDefinitionBaseComponent
orgGuid: string;
spaceGuid: string;
quotaGuid: string;
editLink: string[];
editLink$: Observable<string[]>;
editParams: object;
detailsLoading$: Observable<boolean>;
spaceSubscriber: Subscription;
public canEditQuota$: Observable<boolean>;
public isOrg = false;

constructor(
protected entityServiceFactory: EntityServiceFactory,
Expand All @@ -47,17 +51,10 @@ export class SpaceQuotaDefinitionComponent extends QuotaDefinitionBaseComponent
) {
super(entityServiceFactory, store, activeRouteCfOrgSpace, activatedRoute);
this.setupQuotaDefinitionObservable();
this.editLink = [
'/cloud-foundry',
this.cfGuid,
'organizations',
this.orgGuid,
'space-quota-definitions',
this.quotaGuid,
'edit-space-quota'
];
const { cfGuid, orgGuid } = activeRouteCfOrgSpace;
this.canEditQuota$ = currentUserPermissionsService.can(CurrentUserPermissions.SPACE_QUOTA_EDIT, cfGuid, orgGuid).pipe(tap(console.log));
const { cfGuid, orgGuid, spaceGuid } = activeRouteCfOrgSpace;
this.canEditQuota$ = currentUserPermissionsService.can(CurrentUserPermissions.SPACE_QUOTA_EDIT, cfGuid, orgGuid);
this.isOrg = !spaceGuid;
this.editParams = { [QUOTA_SPACE_GUID]: spaceGuid };
}

setupQuotaDefinitionObservable() {
Expand All @@ -80,6 +77,18 @@ export class SpaceQuotaDefinitionComponent extends QuotaDefinitionBaseComponent
filter(definition => !!definition),
map(definition => definition.entityRequestInfo.fetching)
);

this.editLink$ = quotaGuid$.pipe(
map(quotaGuid => [
'/cloud-foundry',
this.cfGuid,
'organizations',
this.orgGuid,
'space-quota-definitions',
quotaGuid,
'edit-space-quota'
])
);
}

protected getBreadcrumbs(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { ConfirmationDialogService } from '../../../confirmation-dialog.service'
import { ITableColumn } from '../../list-table/table.types';
import { IListAction, ListViewTypes } from '../../list.component.types';
import { BaseCfListConfig } from '../base-cf/base-cf-list-config';
import { QUOTA_FROM_LIST } from '../cf-quotas/cf-quotas-list-config.service';
import { TableCellQuotaComponent } from '../cf-quotas/table-cell-quota/table-cell-quota.component';
import { CfOrgSpaceQuotasDataSourceService } from './cf-space-quotas-data-source.service';

Expand Down Expand Up @@ -111,7 +112,10 @@ export class CfSpaceQuotasListConfigService extends BaseCfListConfig<APIResource
'space-quota-definitions',
item.metadata.guid,
'edit-space-quota'
]
],
query: {
[QUOTA_FROM_LIST]: true
}
})
);
}
Expand Down

0 comments on commit 3c2ca17

Please sign in to comment.