1 import { Component, OnInit } from '@angular/core';
2 import { FormControl, Validators } from '@angular/forms';
3 import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
4 import { CephfsSubvolumeGroupService } from '~/app/shared/api/cephfs-subvolume-group.service';
5 import { ActionLabelsI18n, URLVerbs } from '~/app/shared/constants/app.constants';
6 import { CdFormGroup } from '~/app/shared/forms/cd-form-group';
7 import { FinishedTask } from '~/app/shared/models/finished-task';
8 import { TaskWrapperService } from '~/app/shared/services/task-wrapper.service';
9 import { Pool } from '../../pool/pool';
10 import { FormatterService } from '~/app/shared/services/formatter.service';
11 import { CdTableColumn } from '~/app/shared/models/cd-table-column';
12 import _ from 'lodash';
13 import { CdValidators } from '~/app/shared/forms/cd-validators';
14 import { CdForm } from '~/app/shared/forms/cd-form';
15 import { DimlessBinaryPipe } from '~/app/shared/pipes/dimless-binary.pipe';
16 import { OctalToHumanReadablePipe } from '~/app/shared/pipes/octal-to-human-readable.pipe';
19 selector: 'cd-cephfs-subvolumegroup-form',
20 templateUrl: './cephfs-subvolumegroup-form.component.html',
21 styleUrls: ['./cephfs-subvolumegroup-form.component.scss']
23 export class CephfsSubvolumegroupFormComponent extends CdForm implements OnInit {
25 subvolumegroupName: string;
27 isEdit: boolean = false;
29 subvolumegroupForm: CdFormGroup;
36 columns: CdTableColumn[];
37 scopePermissions: Array<any> = [];
39 owner: ['read', 'write', 'execute'],
40 group: ['read', 'execute'],
41 others: ['read', 'execute']
43 scopes: string[] = ['owner', 'group', 'others'];
46 public activeModal: NgbActiveModal,
47 private actionLabels: ActionLabelsI18n,
48 private taskWrapper: TaskWrapperService,
49 private cephfsSubvolumeGroupService: CephfsSubvolumeGroupService,
50 private formatter: FormatterService,
51 private dimlessBinary: DimlessBinaryPipe,
52 private octalToHumanReadable: OctalToHumanReadablePipe
55 this.resource = $localize`subvolume group`;
59 this.action = this.actionLabels.CREATE;
68 name: $localize`Read`,
70 cellClass: 'text-center'
74 name: $localize`Write`,
76 cellClass: 'text-center'
80 name: $localize`Execute`,
82 cellClass: 'text-center'
86 this.dataPools = this.pools.filter((pool) => pool.type === 'data');
89 this.isEdit ? this.populateForm() : this.loadingReady();
93 this.subvolumegroupForm = new CdFormGroup({
94 volumeName: new FormControl({ value: this.fsName, disabled: true }),
95 subvolumegroupName: new FormControl('', {
96 validators: [Validators.required, Validators.pattern(/^[.A-Za-z0-9_-]+$/)],
99 this.cephfsSubvolumeGroupService.exists,
100 this.cephfsSubvolumeGroupService,
107 pool: new FormControl(this.dataPools[0]?.pool, {
108 validators: [Validators.required]
110 size: new FormControl(null, {
113 uid: new FormControl(null),
114 gid: new FormControl(null),
115 mode: new FormControl({})
120 this.action = this.actionLabels.EDIT;
121 this.cephfsSubvolumeGroupService
122 .info(this.fsName, this.subvolumegroupName)
123 .subscribe((resp: any) => {
124 // Disabled these fields since its not editable
125 this.subvolumegroupForm.get('subvolumegroupName').disable();
127 this.subvolumegroupForm.get('subvolumegroupName').setValue(this.subvolumegroupName);
128 if (resp.bytes_quota !== 'infinite') {
129 this.subvolumegroupForm
131 .setValue(this.dimlessBinary.transform(resp.bytes_quota));
133 this.subvolumegroupForm.get('uid').setValue(resp.uid);
134 this.subvolumegroupForm.get('gid').setValue(resp.gid);
135 this.initialMode = this.octalToHumanReadable.transform(resp.mode, true);
142 const subvolumegroupName = this.subvolumegroupForm.getValue('subvolumegroupName');
143 const pool = this.subvolumegroupForm.getValue('pool');
144 const size = this.formatter.toBytes(this.subvolumegroupForm.getValue('size')) || 0;
145 const uid = this.subvolumegroupForm.getValue('uid');
146 const gid = this.subvolumegroupForm.getValue('gid');
147 const mode = this.formatter.toOctalPermission(this.subvolumegroupForm.getValue('mode'));
149 const editSize = size === 0 ? 'infinite' : size;
151 .wrapTaskAroundCall({
152 task: new FinishedTask('cephfs/subvolume/group/' + URLVerbs.EDIT, {
153 subvolumegroupName: subvolumegroupName
155 call: this.cephfsSubvolumeGroupService.create(
167 this.subvolumegroupForm.setErrors({ cdSubmitButton: true });
170 this.activeModal.close();
175 .wrapTaskAroundCall({
176 task: new FinishedTask('cephfs/subvolume/group/' + URLVerbs.CREATE, {
177 subvolumegroupName: subvolumegroupName
179 call: this.cephfsSubvolumeGroupService.create(
191 this.subvolumegroupForm.setErrors({ cdSubmitButton: true });
194 this.activeModal.close();