1 import { Component, OnInit } from '@angular/core';
2 import { FormControl, Validators } from '@angular/forms';
3 import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
4 import { CephfsSubvolumeService } from '~/app/shared/api/cephfs-subvolume.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';
16 selector: 'cd-cephfs-subvolume-form',
17 templateUrl: './cephfs-subvolume-form.component.html',
18 styleUrls: ['./cephfs-subvolume-form.component.scss']
20 export class CephfsSubvolumeFormComponent implements OnInit {
24 subvolumeForm: CdFormGroup;
31 columns: CdTableColumn[];
32 scopePermissions: Array<any> = [];
33 scopes: string[] = ['owner', 'group', 'others'];
36 public activeModal: NgbActiveModal,
37 private actionLabels: ActionLabelsI18n,
38 private taskWrapper: TaskWrapperService,
39 private cephFsSubvolumeService: CephfsSubvolumeService,
40 private formatter: FormatterService
42 this.action = this.actionLabels.CREATE;
43 this.resource = $localize`Subvolume`;
55 name: $localize`Read`,
57 cellClass: 'text-center'
61 name: $localize`Write`,
63 cellClass: 'text-center'
67 name: $localize`Execute`,
69 cellClass: 'text-center'
73 this.dataPools = this.pools.filter((pool) => pool.type === 'data');
78 this.subvolumeForm = new CdFormGroup({
79 volumeName: new FormControl({ value: this.fsName, disabled: true }),
80 subvolumeName: new FormControl('', {
81 validators: [Validators.required],
84 this.cephFsSubvolumeService.exists,
85 this.cephFsSubvolumeService,
92 pool: new FormControl(this.dataPools[0]?.pool, {
93 validators: [Validators.required]
95 size: new FormControl(null, {
98 uid: new FormControl(null),
99 gid: new FormControl(null),
100 mode: new FormControl({}),
101 isolatedNamespace: new FormControl(false)
106 const subVolumeName = this.subvolumeForm.getValue('subvolumeName');
107 const pool = this.subvolumeForm.getValue('pool');
108 const size = this.formatter.toBytes(this.subvolumeForm.getValue('size'));
109 const uid = this.subvolumeForm.getValue('uid');
110 const gid = this.subvolumeForm.getValue('gid');
111 const mode = this.formatter.toOctalPermission(this.subvolumeForm.getValue('mode'));
112 const isolatedNamespace = this.subvolumeForm.getValue('isolatedNamespace');
114 .wrapTaskAroundCall({
115 task: new FinishedTask('cephfs/subvolume/' + URLVerbs.CREATE, {
116 subVolumeName: subVolumeName
118 call: this.cephFsSubvolumeService.create(
131 this.subvolumeForm.setErrors({ cdSubmitButton: true });
134 this.activeModal.close();