File

src/app/ceph/block/iscsi-target-iqn-settings-modal/iscsi-target-iqn-settings-modal.component.ts

Implements

OnInit

Metadata

selector cd-iscsi-target-iqn-settings-modal
styleUrls ./iscsi-target-iqn-settings-modal.component.scss
templateUrl ./iscsi-target-iqn-settings-modal.component.html

Index

Properties
Methods

Constructor

constructor(modalRef: BsModalRef, iscsiService: IscsiService)
Parameters :
Name Type Optional
modalRef BsModalRef No
iscsiService IscsiService No

Methods

isRadio
isRadio(control)
Parameters :
Name Optional
control No
Returns : boolean
ngOnInit
ngOnInit()
Returns : void
save
save()
Returns : void

Properties

helpText
Type : any
Public iscsiService
Type : IscsiService
Public modalRef
Type : BsModalRef
settingsForm
Type : CdFormGroup
target_controls
Type : FormControl
target_default_controls
Type : any
import { Component, OnInit } from '@angular/core';
import { FormControl } from '@angular/forms';

import * as _ from 'lodash';
import { BsModalRef } from 'ngx-bootstrap/modal';

import { IscsiService } from '../../../shared/api/iscsi.service';
import { CdFormGroup } from '../../../shared/forms/cd-form-group';

@Component({
  selector: 'cd-iscsi-target-iqn-settings-modal',
  templateUrl: './iscsi-target-iqn-settings-modal.component.html',
  styleUrls: ['./iscsi-target-iqn-settings-modal.component.scss']
})
export class IscsiTargetIqnSettingsModalComponent implements OnInit {
  target_controls: FormControl;
  target_default_controls: any;

  settingsForm: CdFormGroup;
  helpText: any;

  constructor(public modalRef: BsModalRef, public iscsiService: IscsiService) {}

  ngOnInit() {
    const fg = {};
    this.helpText = this.iscsiService.targetAdvancedSettings;

    _.forIn(this.target_default_controls, (_value, key) => {
      fg[key] = new FormControl(this.target_controls.value[key]);
    });

    this.settingsForm = new CdFormGroup(fg);
  }

  save() {
    const settings = {};
    _.forIn(this.settingsForm.controls, (control, key) => {
      if (!(control.value === '' || control.value === null)) {
        settings[key] = control.value;
      }
    });

    this.target_controls.setValue(settings);
    this.modalRef.hide();
  }

  isRadio(control) {
    return ['Yes', 'No'].indexOf(this.target_default_controls[control]) !== -1;
  }
}
<cd-modal>
  <ng-container class="modal-title"
                i18n>Advanced Settings</ng-container>

  <ng-container class="modal-content">
    <form name="settingsForm"
          class="form"
          #formDir="ngForm"
          [formGroup]="settingsForm"
          novalidate>
      <div class="modal-body">
        <p class="alert-warning"
           i18n>Changing these parameters from their default values is usually not necessary.</p>

        <div class="form-group row"
             *ngFor="let setting of settingsForm.controls | keyvalue"
             [ngClass]="{'has-error': settingsForm.showError(setting.key, formDir)}">
          <div class="col-sm-12">
            <label class="control-label"
                   for="{{ setting.key }}">{{ setting.key }}</label>
            <input class="form-control"
                   *ngIf="!isRadio(setting.key)"
                   type="number"
                   [formControlName]="setting.key">

            <ng-container *ngIf="isRadio(setting.key)">
              <br>
              <div class="radio radio-inline">
                <input type="radio"
                       [id]="setting.key + 'Yes'"
                       value="Yes"
                       [formControlName]="setting.key">
                <label [for]="setting.key + 'Yes'">Yes</label>
              </div>
              <div class="radio radio-inline">
                <input type="radio"
                       [id]="setting.key + 'No'"
                       value="No"
                       [formControlName]="setting.key">
                <label [for]="setting.key + 'No'">No</label>
              </div>
            </ng-container>

            <span class="help-block">{{ helpText[setting.key]?.help }}</span>
          </div>
        </div>
      </div>

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

./iscsi-target-iqn-settings-modal.component.scss

Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""