From: Pooja Date: Fri, 30 Aug 2019 14:13:20 +0000 (+0200) Subject: mgr/dashboard Adds multiple selection to osd table X-Git-Tag: v15.1.0~1485^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=fb179b2dc19020a18073fe796e60a5c8117478bb;p=ceph-ci.git mgr/dashboard Adds multiple selection to osd table Fixes: https://tracker.ceph.com/issues/38091 Signed-off-by: Pooja --- diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-configuration-list/rbd-configuration-list.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-configuration-list/rbd-configuration-list.component.spec.ts index 8743cf35809..e0cc67d9785 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-configuration-list/rbd-configuration-list.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-configuration-list/rbd-configuration-list.component.spec.ts @@ -6,11 +6,12 @@ import { NgxDatatableModule } from '@swimlane/ngx-datatable'; import { ChartsModule } from 'ng2-charts'; import { AlertModule } from 'ngx-bootstrap/alert'; import { BsDropdownModule } from 'ngx-bootstrap/dropdown'; +import { PopoverModule } from 'ngx-bootstrap/popover'; import { configureTestBed, i18nProviders } from '../../../../testing/unit-test-helper'; -import { ErrorPanelComponent } from '../../../shared/components/error-panel/error-panel.component'; -import { SparklineComponent } from '../../../shared/components/sparkline/sparkline.component'; import { TableComponent } from '../../../shared/datatable/table/table.component'; + +import { ComponentsModule } from '../../../shared/components/components.module'; import { RbdConfigurationEntry } from '../../../shared/models/configuration'; import { PipesModule } from '../../../shared/pipes/pipes.module'; import { FormatterService } from '../../../shared/services/formatter.service'; @@ -26,17 +27,14 @@ describe('RbdConfigurationListComponent', () => { FormsModule, NgxDatatableModule, RouterTestingModule, + ComponentsModule, AlertModule, BsDropdownModule.forRoot(), ChartsModule, - PipesModule - ], - declarations: [ - RbdConfigurationListComponent, - TableComponent, - ErrorPanelComponent, - SparklineComponent + PipesModule, + PopoverModule ], + declarations: [RbdConfigurationListComponent, TableComponent], providers: [FormatterService, RbdConfigurationService, i18nProviders] }); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/osd/osd-list/osd-list.component.html b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/osd/osd-list/osd-list.component.html index 19f79533f10..7b2dcd69b31 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/osd/osd-list/osd-list.component.html +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/osd/osd-list/osd-list.component.html @@ -1,12 +1,14 @@ + +
- OSD {{ selection.first().id }} will be marked + OSD(s) {{ getSelectedIds() | list }} will be marked {{ markActionDescription }} if you proceed. @@ -66,8 +68,8 @@ let-actionDescription="actionDescription">
- The OSD is not safe to destroy! + The {selection.hasSingleSelection, select, 1 {OSD is} 0 {OSDs are}} not safe to destroy!
- OSD {{ selection.first().id }} will be + OSD {{ getSelectedIds() | list }} will be {{ actionDescription }} if you proceed. diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/osd/osd-list/osd-list.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/osd/osd-list/osd-list.component.ts index 610bcd3b4af..a1cd929f0f4 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/osd/osd-list/osd-list.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/osd/osd-list/osd-list.component.ts @@ -1,8 +1,9 @@ import { Component, OnInit, TemplateRef, ViewChild } from '@angular/core'; import { I18n } from '@ngx-translate/i18n-polyfill'; +import * as _ from 'lodash'; import { BsModalRef, BsModalService } from 'ngx-bootstrap/modal'; -import { Observable } from 'rxjs'; +import { forkJoin as observableForkJoin, Observable } from 'rxjs'; import { OsdService } from '../../../../shared/api/osd.service'; import { ConfirmationModalComponent } from '../../../../shared/components/confirmation-modal/confirmation-modal.component'; @@ -51,8 +52,8 @@ export class OsdListComponent implements OnInit { clusterWideActions: CdTableAction[]; icons = Icons; - osds = []; selection = new CdTableSelection(); + osds = []; protected static collectStates(osd) { return [osd['in'] ? 'in' : 'out', osd['up'] ? 'up' : 'down']; @@ -86,7 +87,7 @@ export class OsdListComponent implements OnInit { name: this.actionLabels.REWEIGHT, permission: 'update', click: () => this.reweight(), - disable: () => !this.hasOsdSelected, + disable: () => !this.hasOsdSelected || !this.selection.hasSingleSelection, icon: Icons.reweight }, { @@ -206,11 +207,17 @@ export class OsdListComponent implements OnInit { ]; } + getSelectedIds() { + return this.selection.selected.map((row) => row.id); + } + get hasOsdSelected() { + const validOsds = []; if (this.selection.hasSelection) { - const osdId = this.selection.first().id; - const osd = this.osds.filter((o) => o.id === osdId).pop(); - return !!osd; + for (const osdId of this.getSelectedIds()) { + validOsds.push(this.osds.filter((o) => o.id === osdId).pop()); + } + return validOsds.length > 0; } return false; } @@ -228,23 +235,27 @@ export class OsdListComponent implements OnInit { return true; } - const osdId = this.selection.first().id; - const osd = this.osds.filter((o) => o.id === osdId).pop(); + const validOsds = []; + if (this.selection.hasSelection) { + for (const osdId of this.getSelectedIds()) { + validOsds.push(this.osds.filter((o) => o.id === osdId).pop()); + } + } - if (!osd) { + if (validOsds.length === 0) { // `osd` is undefined if the selected OSD has been removed. return true; } switch (state) { case 'in': - return osd.in === 1; + return validOsds.some((osd) => osd.in === 1); case 'out': - return osd.in !== 1; + return validOsds.some((osd) => osd.in !== 1); case 'down': - return osd.up !== 1; + return validOsds.some((osd) => osd.up !== 1); case 'up': - return osd.up === 1; + return validOsds.some((osd) => osd.up === 1); } } @@ -267,7 +278,7 @@ export class OsdListComponent implements OnInit { } const initialState = { - selected: this.tableComponent.selection.selected, + selected: this.getSelectedIds(), deep: deep }; @@ -288,9 +299,11 @@ export class OsdListComponent implements OnInit { markActionDescription: markAction }, onSubmit: () => { - onSubmit - .call(this.osdService, this.selection.first().id) - .subscribe(() => this.bsModalRef.hide()); + observableForkJoin( + this.getSelectedIds().map((osd: any) => { + onSubmit.call(this.osdService, osd).subscribe(() => this.bsModalRef.hide()); + }) + ); } } }); @@ -312,7 +325,7 @@ export class OsdListComponent implements OnInit { templateItemDescription: string, action: (id: number) => Observable ): void { - this.osdService.safeToDestroy(this.selection.first().id).subscribe((result) => { + this.osdService.safeToDestroy(JSON.stringify(this.getSelectedIds())).subscribe((result) => { const modalRef = this.modalService.show(CriticalConfirmationModalComponent, { initialState: { actionDescription: actionDescription, @@ -323,9 +336,11 @@ export class OsdListComponent implements OnInit { actionDescription: templateItemDescription }, submitAction: () => { - action - .call(this.osdService, this.selection.first().id) - .subscribe(() => modalRef.hide()); + observableForkJoin( + this.getSelectedIds().map((osd: any) => { + action.call(this.osdService, osd).subscribe(() => modalRef.hide()); + }) + ); } } }); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/osd/osd-reweight-modal/osd-reweight-modal.component.html b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/osd/osd-reweight-modal/osd-reweight-modal.component.html index d4cfce7e715..ecdbc5c012d 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/osd/osd-reweight-modal/osd-reweight-modal.component.html +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/osd/osd-reweight-modal/osd-reweight-modal.component.html @@ -1,6 +1,6 @@ Reweight OSD + i18n>Reweight OSD: {{ osdId }}
diff --git a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/osd/osd-scrub-modal/osd-scrub-modal.component.html b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/osd/osd-scrub-modal/osd-scrub-modal.component.html index 1000f5fb34e..f02a04afd0d 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/osd/osd-scrub-modal/osd-scrub-modal.component.html +++ b/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/osd/osd-scrub-modal/osd-scrub-modal.component.html @@ -8,10 +8,8 @@ [formGroup]="scrubForm" novalidate>