Skip to content

Commit

Permalink
mgr/dashboard: Use pipe instead of calling function within template w…
Browse files Browse the repository at this point in the history
…herever possible

https://tracker.ceph.com/issues/48181

Signed-off-by: Volker Theile <[email protected]>
  • Loading branch information
votdev committed Nov 25, 2020
1 parent 71f36e8 commit 24a2495
Show file tree
Hide file tree
Showing 29 changed files with 123 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { RouterModule, Routes } from '@angular/router';

import { TreeModule } from '@circlon/angular-tree-component';
import { NgbNavModule, NgbPopoverModule, NgbTooltipModule } from '@ng-bootstrap/ng-bootstrap';
import { NgxPipeFunctionModule } from 'ngx-pipe-function';

import { ActionLabels, URLVerbs } from '~/app/shared/constants/app.constants';
import { FeatureTogglesGuardService } from '~/app/shared/services/feature-toggles-guard.service';
Expand Down Expand Up @@ -45,6 +46,7 @@ import { RbdTrashRestoreModalComponent } from './rbd-trash-restore-modal/rbd-tra
NgbNavModule,
NgbPopoverModule,
NgbTooltipModule,
NgxPipeFunctionModule,
SharedModule,
RouterModule,
TreeModule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
</cd-table>

<ng-template #configurationSourceTpl
let-row="row"
let-value="value">

<div [ngSwitch]="value">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ import { NgxDatatableModule } from '@swimlane/ngx-datatable';
import { ChartsModule } from 'ng2-charts';

import { ComponentsModule } from '~/app/shared/components/components.module';
import { TableComponent } from '~/app/shared/datatable/table/table.component';
import { RbdConfigurationEntry } from '~/app/shared/models/configuration';
import { PipesModule } from '~/app/shared/pipes/pipes.module';
import { FormatterService } from '~/app/shared/services/formatter.service';
import { RbdConfigurationService } from '~/app/shared/services/rbd-configuration.service';
import { SharedModule } from '~/app/shared/shared.module';
import { configureTestBed } from '~/testing/unit-test-helper';
import { RbdConfigurationListComponent } from './rbd-configuration-list.component';

Expand All @@ -29,10 +28,10 @@ describe('RbdConfigurationListComponent', () => {
ComponentsModule,
NgbDropdownModule,
ChartsModule,
PipesModule,
SharedModule,
NgbTooltipModule
],
declarations: [RbdConfigurationListComponent, TableComponent],
declarations: [RbdConfigurationListComponent],
providers: [FormatterService, RbdConfigurationService]
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@
</ng-template>

<ng-template #deleteTpl
let-expiresAt>
let-expiresAt="expiresAt"
let-isExpired="isExpired">
<p class="text-danger"
*ngIf="!isExpired(expiresAt)">
*ngIf="!isExpired">
<strong>
<ng-container i18n>This image is protected until {{ expiresAt | cdDate }}.</ng-container>
</strong>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { RouterTestingModule } from '@angular/router/testing';

import { NgbNavModule } from '@ng-bootstrap/ng-bootstrap';
import moment from 'moment';
import { NgxPipeFunctionModule } from 'ngx-pipe-function';
import { ToastrModule } from 'ngx-toastr';
import { of } from 'rxjs';

Expand Down Expand Up @@ -34,6 +35,7 @@ describe('RbdTrashListComponent', () => {
RouterTestingModule,
SharedModule,
NgbNavModule,
NgxPipeFunctionModule,
ToastrModule.forRoot()
],
providers: [TaskListService]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,14 @@ export class RbdTrashListComponent implements OnInit {
const namespace = this.selection.first().namespace;
const imageId = this.selection.first().id;
const expiresAt = this.selection.first().deferment_end_time;
const isExpired = moment().isAfter(expiresAt);
const imageIdSpec = new ImageSpec(poolName, namespace, imageId);

this.modalRef = this.modalService.show(CriticalConfirmationModalComponent, {
itemDescription: 'RBD',
itemNames: [imageIdSpec],
bodyTemplate: this.deleteTpl,
bodyContext: { $implicit: expiresAt },
bodyContext: { expiresAt, isExpired },
submitActionObservable: () =>
this.taskWrapper.wrapTaskAroundCall({
task: new FinishedTask('rbd/trash/remove', {
Expand All @@ -218,10 +219,6 @@ export class RbdTrashListComponent implements OnInit {
});
}

isExpired(expiresAt: string): boolean {
return moment().isAfter(expiresAt);
}

purgeModal() {
this.modalService.show(RbdTrashPurgeModalComponent);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,10 @@ describe('CephfsDirectoriesComponent', () => {
});

it('should test all quota table actions permission combinations', () => {
const permissionHelper: PermissionHelper = new PermissionHelper(component.permission);
const permissionHelper: PermissionHelper = new PermissionHelper(component.permission, {
single: { dirValue: 0 },
multiple: [{ dirValue: 0 }, {}]
});
const tableActions = permissionHelper.setPermissionsAndGetActions(
component.quota.tableActions
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
NgbTooltipModule,
NgbTypeaheadModule
} from '@ng-bootstrap/ng-bootstrap';
import { NgxPipeFunctionModule } from 'ngx-pipe-function';

import { SharedModule } from '~/app/shared/shared.module';
import { PerformanceCounterModule } from '../performance-counter/performance-counter.module';
Expand Down Expand Up @@ -70,7 +71,8 @@ import { TelemetryComponent } from './telemetry/telemetry.component';
CephSharedModule,
NgbDatepickerModule,
NgbPopoverModule,
NgbDropdownModule
NgbDropdownModule,
NgxPipeFunctionModule
],
declarations: [
HostsComponent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@
<div [ngbNavOutlet]="nav"></div>

<ng-template #markOsdConfirmationTpl
let-markActionDescription="markActionDescription">
<ng-container i18n><strong>OSD(s) {{ getSelectedOsdIds() | join }}</strong> will be marked
let-markActionDescription="markActionDescription"
let-osdIds="osdIds">
<ng-container i18n><strong>OSD(s) {{ osdIds | join }}</strong> will be marked
<strong>{{ markActionDescription }}</strong> if you proceed.</ng-container>
</ng-template>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ describe('OsdListComponent', () => {
const tableActionElement = fixture.debugElement.query(By.directive(TableActionsComponent));
const toClassName = TestBed.inject(TableActionsComponent).toClassName;
const getActionClasses = (action: CdTableAction) =>
tableActionElement.query(By.css(`[ngbDropdownItem].${toClassName(action.name)}`)).classes;
tableActionElement.query(By.css(`[ngbDropdownItem].${toClassName(action)}`)).classes;

component.tableActions.forEach((action) => {
if (action.name === 'Create') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,10 @@ export class OsdListComponent extends ListWithDetails implements OnInit {
*/
getSelectedOsdIds(): number[] {
const osdIds = this.osds.map((osd) => osd.id);
return this.selection.selected.map((row) => row.id).filter((id) => osdIds.includes(id));
return this.selection.selected
.map((row) => row.id)
.filter((id) => osdIds.includes(id))
.sort();
}

getSelectedOsds(): any[] {
Expand Down Expand Up @@ -483,12 +486,14 @@ export class OsdListComponent extends ListWithDetails implements OnInit {
}

showConfirmationModal(markAction: string, onSubmit: (id: number) => Observable<any>) {
const osdIds = this.getSelectedOsdIds();
this.bsModalRef = this.modalService.show(ConfirmationModalComponent, {
titleText: $localize`Mark OSD ${markAction}`,
buttonText: $localize`Mark ${markAction}`,
bodyTpl: this.markOsdConfirmationTpl,
bodyContext: {
markActionDescription: markAction
markActionDescription: markAction,
osdIds
},
onSubmit: () => {
observableForkJoin(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<ng-template #statusTpl
let-row="row">
<span class="badge"
[ngClass]="getStatusClass(row.status)">
[ngClass]="row | pipeFunction:getStatusClass">
{{ row.status_desc }}
</span>
</ng-template>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { HttpClientTestingModule } from '@angular/common/http/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';

import _ from 'lodash';
import { NgxPipeFunctionModule } from 'ngx-pipe-function';
import { of } from 'rxjs';

import { CephModule } from '~/app/ceph/ceph.module';
Expand Down Expand Up @@ -77,7 +78,7 @@ describe('ServiceDaemonListComponent', () => {
};

configureTestBed({
imports: [HttpClientTestingModule, CephModule, CoreModule, SharedModule]
imports: [HttpClientTestingModule, CephModule, CoreModule, NgxPipeFunctionModule, SharedModule]
});

beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,14 @@ export class ServiceDaemonListComponent implements OnInit, OnChanges, AfterViewI
}
}

getStatusClass(status: number) {
getStatusClass(row: Daemon): string {
return _.get(
{
'-1': 'badge-danger',
'0': 'badge-warning',
'1': 'badge-success'
},
status,
row.status,
'badge-dark'
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';

import { NgbNavModule } from '@ng-bootstrap/ng-bootstrap';
import { NgxPipeFunctionModule } from 'ngx-pipe-function';

import { CdTableSelection } from '~/app/shared/models/cd-table-selection';
import { SummaryService } from '~/app/shared/services/summary.service';
Expand All @@ -16,7 +17,13 @@ describe('ServiceDetailsComponent', () => {
let fixture: ComponentFixture<ServiceDetailsComponent>;

configureTestBed({
imports: [HttpClientTestingModule, RouterTestingModule, SharedModule, NgbNavModule],
imports: [
HttpClientTestingModule,
RouterTestingModule,
SharedModule,
NgbNavModule,
NgxPipeFunctionModule
],
declarations: [ServiceDetailsComponent, ServiceDaemonListComponent],
providers: [{ provide: SummaryService, useValue: { subscribeOnce: jest.fn() } }]
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ export class PoolFormComponent extends CdForm implements OnInit {
return (ecpControl.valid || ecpControl.disabled) && ecp ? pgs / (ecp.k + ecp.m) : 0;
}

private alignPgs(pgs = this.form.getValue('pgNum')) {
alignPgs(pgs = this.form.getValue('pgNum')) {
this.setPgs(Math.round(this.calculatePgPower(pgs < 1 ? 1 : pgs)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,10 +414,10 @@
<div class="col-12">
<button type="button"
class="btn btn-light float-right tc_addCapButton"
[disabled]="hasAllCapabilities()"
[disabled]="capabilities | pipeFunction:hasAllCapabilities"
i18n-ngbTooltip
ngbTooltip="All capabilities are already added."
[disableTooltip]="!hasAllCapabilities()"
[disableTooltip]="!(capabilities | pipeFunction:hasAllCapabilities)"
triggers="pointerenter:pointerleave"
(click)="showCapabilityModal()">
<i [ngClass]="[icons.add]"></i>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Router } from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing';

import { NgbTooltipModule } from '@ng-bootstrap/ng-bootstrap';
import { NgxPipeFunctionModule } from 'ngx-pipe-function';
import { ToastrModule } from 'ngx-toastr';
import { of as observableOf } from 'rxjs';

Expand Down Expand Up @@ -32,7 +33,8 @@ describe('RgwUserFormComponent', () => {
RouterTestingModule,
SharedModule,
ToastrModule.forRoot(),
NgbTooltipModule
NgbTooltipModule,
NgxPipeFunctionModule
]
});

Expand Down Expand Up @@ -322,7 +324,7 @@ describe('RgwUserFormComponent', () => {

fixture.detectChanges();

expect(component.hasAllCapabilities()).toBeTruthy();
expect(component.hasAllCapabilities(component.capabilities)).toBeTruthy();
const capabilityButton = fixture.debugElement.nativeElement.querySelector('.tc_addCapButton');
expect(capabilityButton.disabled).toBeTruthy();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ export class RgwUserFormComponent extends CdForm implements OnInit {
// Add
// Create an observable to add the capability when the form is submitted.
this.submitObservables.push(this.rgwUserService.addCapability(uid, cap.type, cap.perm));
this.capabilities.push(cap);
this.capabilities = [...this.capabilities, cap]; // Notify Angular CD
}
// Mark the form as dirty to be able to submit it.
this.userForm.markAsDirty();
Expand All @@ -398,12 +398,13 @@ export class RgwUserFormComponent extends CdForm implements OnInit {
);
// Remove the capability to update the UI.
this.capabilities.splice(index, 1);
this.capabilities = [...this.capabilities]; // Notify Angular CD
// Mark the form as dirty to be able to submit it.
this.userForm.markAsDirty();
}

hasAllCapabilities() {
return !_.difference(RgwUserCapabilities.getAll(), _.map(this.capabilities, 'type')).length;
hasAllCapabilities(capabilities: RgwUserCapability[]) {
return !_.difference(RgwUserCapabilities.getAll(), _.map(capabilities, 'type')).length;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { RouterModule, Routes } from '@angular/router';

import { NgbNavModule, NgbTooltipModule } from '@ng-bootstrap/ng-bootstrap';
import { NgxPipeFunctionModule } from 'ngx-pipe-function';

import { ActionLabels, URLVerbs } from '~/app/shared/constants/app.constants';
import { AuthGuardService } from '~/app/shared/services/auth-guard.service';
Expand Down Expand Up @@ -32,7 +33,8 @@ import { RgwUserSwiftKeyModalComponent } from './rgw-user-swift-key-modal/rgw-us
PerformanceCounterModule,
NgbNavModule,
RouterModule,
NgbTooltipModule
NgbTooltipModule,
NgxPipeFunctionModule
],
exports: [
Rgw501Component,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { RouterModule, Routes } from '@angular/router';

import { NgbNavModule, NgbPopoverModule } from '@ng-bootstrap/ng-bootstrap';
import { NgxPipeFunctionModule } from 'ngx-pipe-function';

import { ActionLabels, URLVerbs } from '~/app/shared/constants/app.constants';
import { SharedModule } from '~/app/shared/shared.module';
Expand All @@ -26,6 +27,7 @@ import { UserTabsComponent } from './user-tabs/user-tabs.component';
SharedModule,
NgbNavModule,
NgbPopoverModule,
NgxPipeFunctionModule,
RouterModule
],
declarations: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { RouterModule } from '@angular/router';

import { NgbDropdownModule, NgbTooltipModule } from '@ng-bootstrap/ng-bootstrap';
import { NgxDatatableModule } from '@swimlane/ngx-datatable';
import { NgxPipeFunctionModule } from 'ngx-pipe-function';

import { ComponentsModule } from '../components/components.module';
import { PipesModule } from '../pipes/pipes.module';
Expand All @@ -16,6 +17,7 @@ import { TableComponent } from './table/table.component';
imports: [
CommonModule,
NgxDatatableModule,
NgxPipeFunctionModule,
FormsModule,
NgbDropdownModule,
NgbTooltipModule,
Expand Down
Loading

0 comments on commit 24a2495

Please sign in to comment.