All files / src/app/ceph/block/rbd-snapshot-list rbd-snapshot-actions.model.ts

85.71% Statements 18/21
45.45% Branches 5/11
66.67% Functions 6/9
85% Lines 17/20

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90            6x                           27x   27x         27x         27x       60x     27x       60x     27x   4x           27x               27x         27x       4x 4x         27x                     6x  
import { I18n } from '@ngx-translate/i18n-polyfill';
 
import { ActionLabelsI18n } from '../../../shared/constants/app.constants';
import { CdTableAction } from '../../../shared/models/cd-table-action';
import { CdTableSelection } from '../../../shared/models/cd-table-selection';
 
export class RbdSnapshotActionsModel {
  i18n: I18n;
 
  create: CdTableAction;
  rename: CdTableAction;
  protect: CdTableAction;
  unprotect: CdTableAction;
  clone: CdTableAction;
  copy: CdTableAction;
  rollback: CdTableAction;
  deleteSnap: CdTableAction;
  ordering: CdTableAction[];
 
  constructor(i18n: I18n, actionLabels: ActionLabelsI18n) {
    this.i18n = i18n;
 
    this.create = {
      permission: 'create',
      icon: 'fa-plus',
      name: actionLabels.CREATE
    };
    this.rename = {
      permission: 'update',
      icon: 'fa-pencil',
      name: actionLabels.RENAME
    };
    this.protect = {
      permission: 'update',
      icon: 'fa-lock',
      visible: (selection: CdTableSelection) =>
        selection.hasSingleSelection && !selection.first().is_protected,
      name: actionLabels.PROTECT
    };
    this.unprotect = {
      permission: 'update',
      icon: 'fa-unlock',
      visible: (selection: CdTableSelection) =>
        selection.hasSingleSelection && selection.first().is_protected,
      name: actionLabels.UNPROTECT
    };
    this.clone = {
      permission: 'create',
      canBePrimary: (selection: CdTableSelection) => selection.hasSingleSelection,
      disable: (selection: CdTableSelection) =>
        !selection.hasSingleSelection || selection.first().cdExecuting,
      icon: 'fa-clone',
      name: actionLabels.CLONE
    };
    this.copy = {
      permission: 'create',
      canBePrimary: (selection: CdTableSelection) => selection.hasSingleSelection,
      disable: (selection: CdTableSelection) =>
        !selection.hasSingleSelection || selection.first().cdExecuting,
      icon: 'fa-copy',
      name: actionLabels.COPY
    };
    this.rollback = {
      permission: 'update',
      icon: 'fa-undo',
      name: actionLabels.ROLLBACK
    };
    this.deleteSnap = {
      permission: 'delete',
      icon: 'fa-times',
      disable: (selection: CdTableSelection) => {
        const first = selection.first();
        return !selection.hasSingleSelection || first.cdExecuting || first.is_protected;
      },
      name: actionLabels.DELETE
    };
 
    this.ordering = [
      this.create,
      this.rename,
      this.protect,
      this.unprotect,
      this.clone,
      this.copy,
      this.rollback,
      this.deleteSnap
    ];
  }
}