]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/inventory/inventory-devices/inventory-devices.component.ts
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / cluster / inventory / inventory-devices / inventory-devices.component.ts
index 76a196c50a894539a9ab8e721e3c08aeca483aa5..fa778d5b4f29bbb49e0c5195cb728df0c2fbdb40 100644 (file)
@@ -7,26 +7,28 @@ import {
   Output,
   ViewChild
 } from '@angular/core';
-import { I18n } from '@ngx-translate/i18n-polyfill';
 
-import * as _ from 'lodash';
-import { BsModalService } from 'ngx-bootstrap/modal';
+import _ from 'lodash';
 import { Subscription } from 'rxjs';
 
-import { OrchestratorService } from '../../../../shared/api/orchestrator.service';
-import { FormModalComponent } from '../../../../shared/components/form-modal/form-modal.component';
-import { TableComponent } from '../../../../shared/datatable/table/table.component';
-import { CellTemplate } from '../../../../shared/enum/cell-template.enum';
-import { Icons } from '../../../../shared/enum/icons.enum';
-import { NotificationType } from '../../../../shared/enum/notification-type.enum';
-import { CdTableAction } from '../../../../shared/models/cd-table-action';
-import { CdTableColumn } from '../../../../shared/models/cd-table-column';
-import { CdTableColumnFiltersChange } from '../../../../shared/models/cd-table-column-filters-change';
-import { CdTableSelection } from '../../../../shared/models/cd-table-selection';
-import { Permission } from '../../../../shared/models/permissions';
-import { DimlessBinaryPipe } from '../../../../shared/pipes/dimless-binary.pipe';
-import { AuthStorageService } from '../../../../shared/services/auth-storage.service';
-import { NotificationService } from '../../../../shared/services/notification.service';
+import { HostService } from '~/app/shared/api/host.service';
+import { OrchestratorService } from '~/app/shared/api/orchestrator.service';
+import { FormModalComponent } from '~/app/shared/components/form-modal/form-modal.component';
+import { TableComponent } from '~/app/shared/datatable/table/table.component';
+import { CellTemplate } from '~/app/shared/enum/cell-template.enum';
+import { Icons } from '~/app/shared/enum/icons.enum';
+import { NotificationType } from '~/app/shared/enum/notification-type.enum';
+import { CdTableAction } from '~/app/shared/models/cd-table-action';
+import { CdTableColumn } from '~/app/shared/models/cd-table-column';
+import { CdTableColumnFiltersChange } from '~/app/shared/models/cd-table-column-filters-change';
+import { CdTableSelection } from '~/app/shared/models/cd-table-selection';
+import { OrchestratorFeature } from '~/app/shared/models/orchestrator.enum';
+import { OrchestratorStatus } from '~/app/shared/models/orchestrator.interface';
+import { Permission } from '~/app/shared/models/permissions';
+import { DimlessBinaryPipe } from '~/app/shared/pipes/dimless-binary.pipe';
+import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
+import { ModalService } from '~/app/shared/services/modal.service';
+import { NotificationService } from '~/app/shared/services/notification.service';
 import { InventoryDevice } from './inventory-device.model';
 
 @Component({
@@ -68,13 +70,19 @@ export class InventoryDevicesComponent implements OnInit, OnDestroy {
   tableActions: CdTableAction[];
   fetchInventorySub: Subscription;
 
+  @Input() orchStatus: OrchestratorStatus = undefined;
+
+  actionOrchFeatures = {
+    identify: [OrchestratorFeature.DEVICE_BLINK_LIGHT]
+  };
+
   constructor(
     private authStorageService: AuthStorageService,
     private dimlessBinary: DimlessBinaryPipe,
-    private i18n: I18n,
-    private modalService: BsModalService,
+    private modalService: ModalService,
     private notificationService: NotificationService,
-    private orchService: OrchestratorService
+    private orchService: OrchestratorService,
+    private hostService: HostService
   ) {}
 
   ngOnInit() {
@@ -84,25 +92,25 @@ export class InventoryDevicesComponent implements OnInit, OnDestroy {
         permission: 'update',
         icon: Icons.show,
         click: () => this.identifyDevice(),
-        name: this.i18n('Identify'),
-        disable: () => !this.selection.hasSingleSelection,
+        name: $localize`Identify`,
+        disable: (selection: CdTableSelection) => this.getDisable('identify', selection),
         canBePrimary: (selection: CdTableSelection) => !selection.hasSingleSelection,
         visible: () => _.isString(this.selectionType)
       }
     ];
     const columns = [
       {
-        name: this.i18n('Hostname'),
+        name: $localize`Hostname`,
         prop: 'hostname',
         flexGrow: 1
       },
       {
-        name: this.i18n('Device path'),
+        name: $localize`Device path`,
         prop: 'path',
         flexGrow: 1
       },
       {
-        name: this.i18n('Type'),
+        name: $localize`Type`,
         prop: 'human_readable_type',
         flexGrow: 1,
         cellTransformation: CellTemplate.badge,
@@ -114,30 +122,30 @@ export class InventoryDevicesComponent implements OnInit, OnDestroy {
         }
       },
       {
-        name: this.i18n('Available'),
+        name: $localize`Available`,
         prop: 'available',
         flexGrow: 1,
         cellClass: 'text-center',
         cellTransformation: CellTemplate.checkIcon
       },
       {
-        name: this.i18n('Vendor'),
+        name: $localize`Vendor`,
         prop: 'sys_api.vendor',
         flexGrow: 1
       },
       {
-        name: this.i18n('Model'),
+        name: $localize`Model`,
         prop: 'sys_api.model',
         flexGrow: 1
       },
       {
-        name: this.i18n('Size'),
+        name: $localize`Size`,
         prop: 'sys_api.size',
         flexGrow: 1,
         pipe: this.dimlessBinary
       },
       {
-        name: this.i18n('OSDs'),
+        name: $localize`OSDs`,
         prop: 'osd_ids',
         flexGrow: 1,
         cellTransformation: CellTemplate.badge,
@@ -177,6 +185,16 @@ export class InventoryDevicesComponent implements OnInit, OnDestroy {
     this.filterChange.emit(event);
   }
 
+  getDisable(action: 'identify', selection: CdTableSelection): boolean | string {
+    if (!selection.hasSingleSelection) {
+      return true;
+    }
+    return this.orchService.getTableActionDisableDesc(
+      this.orchStatus,
+      this.actionOrchFeatures[action]
+    );
+  }
+
   updateSelection(selection: CdTableSelection) {
     this.selection = selection;
   }
@@ -186,38 +204,33 @@ export class InventoryDevicesComponent implements OnInit, OnDestroy {
     const hostname = selected.hostname;
     const device = selected.path || selected.device_id;
     this.modalService.show(FormModalComponent, {
-      initialState: {
-        titleText: this.i18n(`Identify device {{device}}`, { device }),
-        message: this.i18n('Please enter the duration how long to blink the LED.'),
-        fields: [
-          {
-            type: 'select',
-            name: 'duration',
-            value: 300,
-            required: true,
-            typeConfig: {
-              options: [
-                { text: this.i18n('1 minute'), value: 60 },
-                { text: this.i18n('2 minutes'), value: 120 },
-                { text: this.i18n('5 minutes'), value: 300 },
-                { text: this.i18n('10 minutes'), value: 600 },
-                { text: this.i18n('15 minutes'), value: 900 }
-              ]
-            }
+      titleText: $localize`Identify device ${device}`,
+      message: $localize`Please enter the duration how long to blink the LED.`,
+      fields: [
+        {
+          type: 'select',
+          name: 'duration',
+          value: 300,
+          required: true,
+          typeConfig: {
+            options: [
+              { text: $localize`1 minute`, value: 60 },
+              { text: $localize`2 minutes`, value: 120 },
+              { text: $localize`5 minutes`, value: 300 },
+              { text: $localize`10 minutes`, value: 600 },
+              { text: $localize`15 minutes`, value: 900 }
+            ]
           }
-        ],
-        submitButtonText: this.i18n('Execute'),
-        onSubmit: (values: any) => {
-          this.orchService.identifyDevice(hostname, device, values.duration).subscribe(() => {
-            this.notificationService.show(
-              NotificationType.success,
-              this.i18n(`Identifying '{{device}}' started on host '{{hostname}}'`, {
-                hostname,
-                device
-              })
-            );
-          });
         }
+      ],
+      submitButtonText: $localize`Execute`,
+      onSubmit: (values: any) => {
+        this.hostService.identifyDevice(hostname, device, values.duration).subscribe(() => {
+          this.notificationService.show(
+            NotificationType.success,
+            $localize`Identifying '${device}' started on host '${hostname}'`
+          );
+        });
       }
     });
   }