summaryrefslogtreecommitdiffstats
path: root/src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/osd/osd-pg-scrub-modal/osd-pg-scrub-modal.component.ts
blob: 7e76c99c5b8fdb1b006593ff0d462be8e7cc2cbe (plain)
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
import { Component, ViewChild } from '@angular/core';

import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
import { forkJoin as observableForkJoin } from 'rxjs';

import { ConfigOptionComponent } from '~/app/shared/components/config-option/config-option.component';
import { ActionLabelsI18n } from '~/app/shared/constants/app.constants';
import { NotificationType } from '~/app/shared/enum/notification-type.enum';
import { CdFormGroup } from '~/app/shared/forms/cd-form-group';
import { Permissions } from '~/app/shared/models/permissions';
import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
import { NotificationService } from '~/app/shared/services/notification.service';
import { OsdPgScrubModalOptions } from './osd-pg-scrub-modal.options';

@Component({
  selector: 'cd-osd-pg-scrub-modal',
  templateUrl: './osd-pg-scrub-modal.component.html',
  styleUrls: ['./osd-pg-scrub-modal.component.scss']
})
export class OsdPgScrubModalComponent {
  osdPgScrubForm: CdFormGroup;
  action: string;
  resource: string;
  permissions: Permissions;

  @ViewChild('basicOptionsValues', { static: true })
  basicOptionsValues: ConfigOptionComponent;
  basicOptions: Array<string> = OsdPgScrubModalOptions.basicOptions;

  @ViewChild('advancedOptionsValues')
  advancedOptionsValues: ConfigOptionComponent;
  advancedOptions: Array<string> = OsdPgScrubModalOptions.advancedOptions;

  advancedEnabled = false;

  constructor(
    public activeModal: NgbActiveModal,
    private authStorageService: AuthStorageService,
    private notificationService: NotificationService,
    public actionLabels: ActionLabelsI18n
  ) {
    this.osdPgScrubForm = new CdFormGroup({});
    this.resource = $localize`PG scrub options`;
    this.action = this.actionLabels.EDIT;
    this.permissions = this.authStorageService.getPermissions();
  }

  submitAction() {
    const observables = [this.basicOptionsValues.saveValues()];

    if (this.advancedOptionsValues) {
      observables.push(this.advancedOptionsValues.saveValues());
    }

    observableForkJoin(observables).subscribe(
      () => {
        this.notificationService.show(
          NotificationType.success,
          $localize`Updated PG scrub options`
        );
        this.activeModal.close();
      },
      () => {
        this.activeModal.close();
      }
    );
  }
}