File

src/app/ceph/block/rbd-trash-purge-modal/rbd-trash-purge-modal.component.ts

Implements

OnInit

Metadata

selector cd-rbd-trash-purge-modal
styleUrls ./rbd-trash-purge-modal.component.scss
templateUrl ./rbd-trash-purge-modal.component.html

Index

Properties
Methods

Constructor

constructor(authStorageService: AuthStorageService, rbdService: RbdService, modalRef: BsModalRef, fb: CdFormBuilder, poolService: PoolService, taskWrapper: TaskWrapperService)
Parameters :
Name Type Optional
authStorageService AuthStorageService No
rbdService RbdService No
modalRef BsModalRef No
fb CdFormBuilder No
poolService PoolService No
taskWrapper TaskWrapperService No

Methods

createForm
createForm()
Returns : void
ngOnInit
ngOnInit()
Returns : void
purge
purge()
Returns : void

Properties

Public modalRef
Type : BsModalRef
poolPermission
Type : Permission
pools
Type : any[]
purgeForm
Type : CdFormGroup
import { Component, OnInit } from '@angular/core';

import { BsModalRef } from 'ngx-bootstrap/modal';

import { PoolService } from '../../../shared/api/pool.service';
import { RbdService } from '../../../shared/api/rbd.service';
import { CdFormBuilder } from '../../../shared/forms/cd-form-builder';
import { CdFormGroup } from '../../../shared/forms/cd-form-group';
import { FinishedTask } from '../../../shared/models/finished-task';
import { Permission } from '../../../shared/models/permissions';
import { AuthStorageService } from '../../../shared/services/auth-storage.service';
import { TaskWrapperService } from '../../../shared/services/task-wrapper.service';

@Component({
  selector: 'cd-rbd-trash-purge-modal',
  templateUrl: './rbd-trash-purge-modal.component.html',
  styleUrls: ['./rbd-trash-purge-modal.component.scss']
})
export class RbdTrashPurgeModalComponent implements OnInit {
  poolPermission: Permission;
  purgeForm: CdFormGroup;
  pools: any[];

  constructor(
    private authStorageService: AuthStorageService,
    private rbdService: RbdService,
    public modalRef: BsModalRef,
    private fb: CdFormBuilder,
    private poolService: PoolService,
    private taskWrapper: TaskWrapperService
  ) {
    this.poolPermission = this.authStorageService.getPermissions().pool;
  }

  createForm() {
    this.purgeForm = this.fb.group({
      poolName: ''
    });
  }

  ngOnInit() {
    if (this.poolPermission.read) {
      this.poolService.list(['pool_name', 'application_metadata']).then((resp) => {
        this.pools = resp
          .filter((pool) => pool.application_metadata.includes('rbd'))
          .map((pool) => pool.pool_name);
      });
    }

    this.createForm();
  }

  purge() {
    const poolName = this.purgeForm.getValue('poolName') || '';
    this.taskWrapper
      .wrapTaskAroundCall({
        task: new FinishedTask('rbd/trash/purge', {
          pool_name: poolName
        }),
        call: this.rbdService.purgeTrash(poolName)
      })
      .subscribe(
        undefined,
        () => {
          this.purgeForm.setErrors({ cdSubmitButton: true });
        },
        () => {
          this.modalRef.hide();
        }
      );
  }
}
<cd-modal>
  <ng-container i18n
                class="modal-title">Purge Trash</ng-container>

  <ng-container class="modal-content">
    <form name="purgeForm"
          class="form"
          #formDir="ngForm"
          [formGroup]="purgeForm"
          novalidate>
      <div class="modal-body">
        <p>
          <ng-container i18n>To purge, select one or All images and click</ng-container>&nbsp;
          <kbd i18n>Purge Trash</kbd>.&nbsp;
        </p>

        <div class="form-group">
          <label class="center-block"
                 i18n>Pool:</label>
          <input class="form-control"
                 type="text"
                 placeholder="Pool name..."
                 i18n-placeholder
                 formControlName="poolName"
                 *ngIf="!poolPermission.read">
          <select class="form-control"
                  formControlName="poolName"
                  *ngIf="poolPermission.read">
            <option value=""
                    i18n>All</option>
            <option *ngFor="let pool of pools"
                    [value]="pool">{{ pool }}</option>
          </select>
        </div>
      </div>

      <div class="modal-footer">
        <div class="button-group text-right">
          <cd-submit-button [form]="purgeForm"
                            (submitAction)="purge()"
                            i18n>Purge Trash</cd-submit-button>
          <cd-back-button [back]="modalRef.hide"
                          name="Cancel"
                          i18n-name>
          </cd-back-button>
        </div>
      </div>
    </form>
  </ng-container>
</cd-modal>

./rbd-trash-purge-modal.component.scss

Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""