1 import { Component, OnInit } from '@angular/core';
2 import { FormControl, Validators } from '@angular/forms';
3 import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
4 import { RgwRealmService } from '~/app/shared/api/rgw-realm.service';
5 import { ActionLabelsI18n } from '~/app/shared/constants/app.constants';
6 import { NotificationType } from '~/app/shared/enum/notification-type.enum';
7 import { CdFormGroup } from '~/app/shared/forms/cd-form-group';
8 import { CdValidators } from '~/app/shared/forms/cd-validators';
9 import { NotificationService } from '~/app/shared/services/notification.service';
10 import { RgwRealm } from '../models/rgw-multisite';
13 selector: 'cd-rgw-multisite-realm-form',
14 templateUrl: './rgw-multisite-realm-form.component.html',
15 styleUrls: ['./rgw-multisite-realm-form.component.scss']
17 export class RgwMultisiteRealmFormComponent implements OnInit {
19 multisiteRealmForm: CdFormGroup;
22 multisiteInfo: object[] = [];
24 realmList: RgwRealm[] = [];
28 public activeModal: NgbActiveModal,
29 public actionLabels: ActionLabelsI18n,
30 public rgwRealmService: RgwRealmService,
31 public notificationService: NotificationService
33 this.action = this.editing
34 ? this.actionLabels.EDIT + this.resource
35 : this.actionLabels.CREATE + this.resource;
40 this.multisiteRealmForm = new CdFormGroup({
41 realmName: new FormControl(null, {
44 CdValidators.custom('uniqueName', (realmName: string) => {
45 return this.realmNames && this.realmNames.indexOf(realmName) !== -1;
49 default_realm: new FormControl(false)
55 this.multisiteInfo[0] !== undefined && this.multisiteInfo[0].hasOwnProperty('realms')
56 ? this.multisiteInfo[0]['realms']
58 this.realmNames = this.realmList.map((realm) => {
64 const values = this.multisiteRealmForm.value;
65 this.realm = new RgwRealm();
66 this.realm.name = values['realmName'];
67 this.rgwRealmService.create(this.realm, values['default_realm']).subscribe(
69 this.notificationService.show(
70 NotificationType.success,
71 $localize`Realm: '${values['realmName']}' created successfully`
73 this.activeModal.close();
76 this.multisiteRealmForm.setErrors({ cdSubmitButton: true });