1 import { Component, EventEmitter, Output } from '@angular/core';
2 import { FormControl, Validators } from '@angular/forms';
3 import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
4 import { RgwMultisiteService } from '~/app/shared/api/rgw-multisite.service';
5 import { RgwRealmService } from '~/app/shared/api/rgw-realm.service';
6 import { RgwZoneService } from '~/app/shared/api/rgw-zone.service';
7 import { RgwZonegroupService } from '~/app/shared/api/rgw-zonegroup.service';
8 import { ActionLabelsI18n } from '~/app/shared/constants/app.constants';
9 import { CdFormGroup } from '~/app/shared/forms/cd-form-group';
10 import { ModalService } from '~/app/shared/services/modal.service';
11 import { NotificationService } from '~/app/shared/services/notification.service';
12 import { RgwRealm, RgwZonegroup, RgwZone, SystemKey } from '../models/rgw-multisite';
13 import { NotificationType } from '~/app/shared/enum/notification-type.enum';
14 import { Subscription } from 'rxjs';
17 selector: 'cd-create-rgw-service-entities',
18 templateUrl: './create-rgw-service-entities.component.html',
19 styleUrls: ['./create-rgw-service-entities.component.scss']
21 export class CreateRgwServiceEntitiesComponent {
22 public sub = new Subscription();
23 createMultisiteEntitiesForm: CdFormGroup;
25 zonegroup: RgwZonegroup;
29 submitAction = new EventEmitter();
32 public activeModal: NgbActiveModal,
33 public actionLabels: ActionLabelsI18n,
34 public rgwMultisiteService: RgwMultisiteService,
35 public rgwZoneService: RgwZoneService,
36 public notificationService: NotificationService,
37 public rgwZonegroupService: RgwZonegroupService,
38 public rgwRealmService: RgwRealmService,
39 public modalService: ModalService
45 this.createMultisiteEntitiesForm = new CdFormGroup({
46 realmName: new FormControl(null, {
47 validators: [Validators.required]
49 zonegroupName: new FormControl(null, {
50 validators: [Validators.required]
52 zoneName: new FormControl(null, {
53 validators: [Validators.required]
59 const values = this.createMultisiteEntitiesForm.value;
60 this.realm = new RgwRealm();
61 this.realm.name = values['realmName'];
62 this.zonegroup = new RgwZonegroup();
63 this.zonegroup.name = values['zonegroupName'];
64 this.zonegroup.endpoints = '';
65 this.zone = new RgwZone();
66 this.zone.name = values['zoneName'];
67 this.zone.endpoints = '';
68 this.zone.system_key = new SystemKey();
69 this.zone.system_key.access_key = '';
70 this.zone.system_key.secret_key = '';
72 .create(this.realm, true)
75 this.rgwZonegroupService
76 .create(this.realm, this.zonegroup, true, true)
80 .create(this.zone, this.zonegroup, true, true, this.zone.endpoints)
83 this.notificationService.show(
84 NotificationType.success,
85 $localize`Realm/Zonegroup/Zone created successfully`
87 this.submitAction.emit();
88 this.activeModal.close();
91 this.notificationService.show(
92 NotificationType.error,
93 $localize`Realm/Zonegroup/Zone creation failed`